From 67739537e5af0e9fbbed9ed77e0f71ac2f285983 Mon Sep 17 00:00:00 2001 From: cx20 Date: Sat, 30 Nov 2024 02:29:16 +0900 Subject: [PATCH] Update three.js r170 to r171 --- examples/threejs/index.html | 4 +- examples/threejs/index.js | 4 +- examples/threejs_webgpu/index.html | 6 +- libs/three.js/r171/build/three.core.js | 36987 +++++++++++++ libs/three.js/r171/build/three.core.min.js | 6 + libs/three.js/r171/build/three.module.js | 17581 +++++++ libs/three.js/r171/build/three.module.min.js | 6 + libs/three.js/r171/build/three.tsl.js | 533 + libs/three.js/r171/build/three.tsl.min.js | 6 + libs/three.js/r171/build/three.webgpu.js | 43481 ++++++++++++++++ libs/three.js/r171/build/three.webgpu.min.js | 6 + .../examples/jsm/controls/OrbitControls.js | 1555 + .../examples/jsm/exporters/GLTFExporter.js | 3456 ++ .../jsm/libs/basis/basis_transcoder.js | 19 + .../jsm/libs/basis/basis_transcoder.wasm | Bin 0 -> 527333 bytes .../r171/examples/jsm/libs/dat.gui.module.js | 3575 ++ .../examples/jsm/libs/draco/draco_decoder.js | 34 + .../jsm/libs/draco/draco_decoder.wasm | Bin 0 -> 285747 bytes .../jsm/libs/draco/draco_wasm_wrapper.js | 117 + .../jsm/libs/draco/gltf/draco_decoder.js | 33 + .../jsm/libs/draco/gltf/draco_decoder.wasm | Bin 0 -> 192420 bytes .../jsm/libs/draco/gltf/draco_wasm_wrapper.js | 116 + .../examples/jsm/libs/ktx-parse.module.js | 1 + .../examples/jsm/libs/lil-gui.module.min.js | 8 + .../jsm/libs/meshopt_decoder.module.js | 178 + .../r171/examples/jsm/libs/zstddec.module.js | 1 + .../jsm/loaders/BasisTextureLoader.js | 790 + .../r171/examples/jsm/loaders/DRACOLoader.js | 615 + .../r171/examples/jsm/loaders/GLTFLoader.js | 4727 ++ .../jsm/loaders/HDRCubeTextureLoader.js | 115 + .../r171/examples/jsm/loaders/KTX2Loader.js | 1031 + .../r171/examples/jsm/loaders/RGBELoader.js | 450 + .../r171/examples/jsm/math/ColorSpaces.js | 76 + .../r171/examples/jsm/physics/AmmoPhysics.js | 306 + .../examples/jsm/physics/RapierPhysics.js | 240 + .../jsm/postprocessing/EffectComposer.js | 231 + .../examples/jsm/postprocessing/MaskPass.js | 101 + .../r171/examples/jsm/postprocessing/Pass.js | 95 + .../examples/jsm/postprocessing/RenderPass.js | 99 + .../examples/jsm/postprocessing/ShaderPass.js | 77 + .../jsm/postprocessing/UnrealBloomPass.js | 415 + .../r171/examples/jsm/shaders/CopyShader.js | 45 + .../jsm/shaders/LuminosityHighPassShader.js | 64 + .../examples/jsm/utils/BufferGeometryUtils.js | 1373 + .../examples/jsm/utils/WebGLTextureUtils.js | 99 + .../examples/jsm/utils/WebGPUTextureUtils.js | 64 + .../r171/examples/jsm/utils/WorkerPool.js | 102 + 47 files changed, 118821 insertions(+), 7 deletions(-) create mode 100644 libs/three.js/r171/build/three.core.js create mode 100644 libs/three.js/r171/build/three.core.min.js create mode 100644 libs/three.js/r171/build/three.module.js create mode 100644 libs/three.js/r171/build/three.module.min.js create mode 100644 libs/three.js/r171/build/three.tsl.js create mode 100644 libs/three.js/r171/build/three.tsl.min.js create mode 100644 libs/three.js/r171/build/three.webgpu.js create mode 100644 libs/three.js/r171/build/three.webgpu.min.js create mode 100644 libs/three.js/r171/examples/jsm/controls/OrbitControls.js create mode 100644 libs/three.js/r171/examples/jsm/exporters/GLTFExporter.js create mode 100644 libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.js create mode 100644 libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.wasm create mode 100644 libs/three.js/r171/examples/jsm/libs/dat.gui.module.js create mode 100644 libs/three.js/r171/examples/jsm/libs/draco/draco_decoder.js create mode 100644 libs/three.js/r171/examples/jsm/libs/draco/draco_decoder.wasm create mode 100644 libs/three.js/r171/examples/jsm/libs/draco/draco_wasm_wrapper.js create mode 100644 libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_decoder.js create mode 100644 libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_decoder.wasm create mode 100644 libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js create mode 100644 libs/three.js/r171/examples/jsm/libs/ktx-parse.module.js create mode 100644 libs/three.js/r171/examples/jsm/libs/lil-gui.module.min.js create mode 100644 libs/three.js/r171/examples/jsm/libs/meshopt_decoder.module.js create mode 100644 libs/three.js/r171/examples/jsm/libs/zstddec.module.js create mode 100644 libs/three.js/r171/examples/jsm/loaders/BasisTextureLoader.js create mode 100644 libs/three.js/r171/examples/jsm/loaders/DRACOLoader.js create mode 100644 libs/three.js/r171/examples/jsm/loaders/GLTFLoader.js create mode 100644 libs/three.js/r171/examples/jsm/loaders/HDRCubeTextureLoader.js create mode 100644 libs/three.js/r171/examples/jsm/loaders/KTX2Loader.js create mode 100644 libs/three.js/r171/examples/jsm/loaders/RGBELoader.js create mode 100644 libs/three.js/r171/examples/jsm/math/ColorSpaces.js create mode 100644 libs/three.js/r171/examples/jsm/physics/AmmoPhysics.js create mode 100644 libs/three.js/r171/examples/jsm/physics/RapierPhysics.js create mode 100644 libs/three.js/r171/examples/jsm/postprocessing/EffectComposer.js create mode 100644 libs/three.js/r171/examples/jsm/postprocessing/MaskPass.js create mode 100644 libs/three.js/r171/examples/jsm/postprocessing/Pass.js create mode 100644 libs/three.js/r171/examples/jsm/postprocessing/RenderPass.js create mode 100644 libs/three.js/r171/examples/jsm/postprocessing/ShaderPass.js create mode 100644 libs/three.js/r171/examples/jsm/postprocessing/UnrealBloomPass.js create mode 100644 libs/three.js/r171/examples/jsm/shaders/CopyShader.js create mode 100644 libs/three.js/r171/examples/jsm/shaders/LuminosityHighPassShader.js create mode 100644 libs/three.js/r171/examples/jsm/utils/BufferGeometryUtils.js create mode 100644 libs/three.js/r171/examples/jsm/utils/WebGLTextureUtils.js create mode 100644 libs/three.js/r171/examples/jsm/utils/WebGPUTextureUtils.js create mode 100644 libs/three.js/r171/examples/jsm/utils/WorkerPool.js diff --git a/examples/threejs/index.html b/examples/threejs/index.html index 83f33bbb8..a435cb109 100644 --- a/examples/threejs/index.html +++ b/examples/threejs/index.html @@ -19,8 +19,8 @@ diff --git a/examples/threejs/index.js b/examples/threejs/index.js index 9de137db1..b6fa33b3b 100644 --- a/examples/threejs/index.js +++ b/examples/threejs/index.js @@ -129,10 +129,10 @@ function init() { const loader = new GLTFLoader(manager); loader.setCrossOrigin( 'anonymous' ); - const dracoLoader = new DRACOLoader().setDecoderPath( '../../libs/three.js/r170/examples/jsm/libs/draco/gltf/' ); + const dracoLoader = new DRACOLoader().setDecoderPath( '../../libs/three.js/r171/examples/jsm/libs/draco/gltf/' ); loader.setDRACOLoader( dracoLoader ); - const ktx2Loader = new KTX2Loader().setTranscoderPath( '../../libs/three.js/r170/examples/jsm/libs/basis/' ); + const ktx2Loader = new KTX2Loader().setTranscoderPath( '../../libs/three.js/r171/examples/jsm/libs/basis/' ); ktx2Loader.detectSupport( renderer ); loader.setKTX2Loader( ktx2Loader ); loader.setMeshoptDecoder( MeshoptDecoder ); diff --git a/examples/threejs_webgpu/index.html b/examples/threejs_webgpu/index.html index 4a4903562..bb294afa1 100644 --- a/examples/threejs_webgpu/index.html +++ b/examples/threejs_webgpu/index.html @@ -19,9 +19,9 @@ diff --git a/libs/three.js/r171/build/three.core.js b/libs/three.js/r171/build/three.core.js new file mode 100644 index 000000000..44e9479ab --- /dev/null +++ b/libs/three.js/r171/build/three.core.js @@ -0,0 +1,36987 @@ +/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */ +const REVISION = '171'; + +const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 }; +const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 }; +const CullFaceNone = 0; +const CullFaceBack = 1; +const CullFaceFront = 2; +const CullFaceFrontBack = 3; +const BasicShadowMap = 0; +const PCFShadowMap = 1; +const PCFSoftShadowMap = 2; +const VSMShadowMap = 3; +const FrontSide = 0; +const BackSide = 1; +const DoubleSide = 2; +const NoBlending = 0; +const NormalBlending = 1; +const AdditiveBlending = 2; +const SubtractiveBlending = 3; +const MultiplyBlending = 4; +const CustomBlending = 5; +const AddEquation = 100; +const SubtractEquation = 101; +const ReverseSubtractEquation = 102; +const MinEquation = 103; +const MaxEquation = 104; +const ZeroFactor = 200; +const OneFactor = 201; +const SrcColorFactor = 202; +const OneMinusSrcColorFactor = 203; +const SrcAlphaFactor = 204; +const OneMinusSrcAlphaFactor = 205; +const DstAlphaFactor = 206; +const OneMinusDstAlphaFactor = 207; +const DstColorFactor = 208; +const OneMinusDstColorFactor = 209; +const SrcAlphaSaturateFactor = 210; +const ConstantColorFactor = 211; +const OneMinusConstantColorFactor = 212; +const ConstantAlphaFactor = 213; +const OneMinusConstantAlphaFactor = 214; +const NeverDepth = 0; +const AlwaysDepth = 1; +const LessDepth = 2; +const LessEqualDepth = 3; +const EqualDepth = 4; +const GreaterEqualDepth = 5; +const GreaterDepth = 6; +const NotEqualDepth = 7; +const MultiplyOperation = 0; +const MixOperation = 1; +const AddOperation = 2; +const NoToneMapping = 0; +const LinearToneMapping = 1; +const ReinhardToneMapping = 2; +const CineonToneMapping = 3; +const ACESFilmicToneMapping = 4; +const CustomToneMapping = 5; +const AgXToneMapping = 6; +const NeutralToneMapping = 7; +const AttachedBindMode = 'attached'; +const DetachedBindMode = 'detached'; + +const UVMapping = 300; +const CubeReflectionMapping = 301; +const CubeRefractionMapping = 302; +const EquirectangularReflectionMapping = 303; +const EquirectangularRefractionMapping = 304; +const CubeUVReflectionMapping = 306; +const RepeatWrapping = 1000; +const ClampToEdgeWrapping = 1001; +const MirroredRepeatWrapping = 1002; +const NearestFilter = 1003; +const NearestMipmapNearestFilter = 1004; +const NearestMipMapNearestFilter = 1004; +const NearestMipmapLinearFilter = 1005; +const NearestMipMapLinearFilter = 1005; +const LinearFilter = 1006; +const LinearMipmapNearestFilter = 1007; +const LinearMipMapNearestFilter = 1007; +const LinearMipmapLinearFilter = 1008; +const LinearMipMapLinearFilter = 1008; +const UnsignedByteType = 1009; +const ByteType = 1010; +const ShortType = 1011; +const UnsignedShortType = 1012; +const IntType = 1013; +const UnsignedIntType = 1014; +const FloatType = 1015; +const HalfFloatType = 1016; +const UnsignedShort4444Type = 1017; +const UnsignedShort5551Type = 1018; +const UnsignedInt248Type = 1020; +const UnsignedInt5999Type = 35902; +const AlphaFormat = 1021; +const RGBFormat = 1022; +const RGBAFormat = 1023; +const LuminanceFormat = 1024; +const LuminanceAlphaFormat = 1025; +const DepthFormat = 1026; +const DepthStencilFormat = 1027; +const RedFormat = 1028; +const RedIntegerFormat = 1029; +const RGFormat = 1030; +const RGIntegerFormat = 1031; +const RGBIntegerFormat = 1032; +const RGBAIntegerFormat = 1033; + +const RGB_S3TC_DXT1_Format = 33776; +const RGBA_S3TC_DXT1_Format = 33777; +const RGBA_S3TC_DXT3_Format = 33778; +const RGBA_S3TC_DXT5_Format = 33779; +const RGB_PVRTC_4BPPV1_Format = 35840; +const RGB_PVRTC_2BPPV1_Format = 35841; +const RGBA_PVRTC_4BPPV1_Format = 35842; +const RGBA_PVRTC_2BPPV1_Format = 35843; +const RGB_ETC1_Format = 36196; +const RGB_ETC2_Format = 37492; +const RGBA_ETC2_EAC_Format = 37496; +const RGBA_ASTC_4x4_Format = 37808; +const RGBA_ASTC_5x4_Format = 37809; +const RGBA_ASTC_5x5_Format = 37810; +const RGBA_ASTC_6x5_Format = 37811; +const RGBA_ASTC_6x6_Format = 37812; +const RGBA_ASTC_8x5_Format = 37813; +const RGBA_ASTC_8x6_Format = 37814; +const RGBA_ASTC_8x8_Format = 37815; +const RGBA_ASTC_10x5_Format = 37816; +const RGBA_ASTC_10x6_Format = 37817; +const RGBA_ASTC_10x8_Format = 37818; +const RGBA_ASTC_10x10_Format = 37819; +const RGBA_ASTC_12x10_Format = 37820; +const RGBA_ASTC_12x12_Format = 37821; +const RGBA_BPTC_Format = 36492; +const RGB_BPTC_SIGNED_Format = 36494; +const RGB_BPTC_UNSIGNED_Format = 36495; +const RED_RGTC1_Format = 36283; +const SIGNED_RED_RGTC1_Format = 36284; +const RED_GREEN_RGTC2_Format = 36285; +const SIGNED_RED_GREEN_RGTC2_Format = 36286; +const LoopOnce = 2200; +const LoopRepeat = 2201; +const LoopPingPong = 2202; +const InterpolateDiscrete = 2300; +const InterpolateLinear = 2301; +const InterpolateSmooth = 2302; +const ZeroCurvatureEnding = 2400; +const ZeroSlopeEnding = 2401; +const WrapAroundEnding = 2402; +const NormalAnimationBlendMode = 2500; +const AdditiveAnimationBlendMode = 2501; +const TrianglesDrawMode = 0; +const TriangleStripDrawMode = 1; +const TriangleFanDrawMode = 2; +const BasicDepthPacking = 3200; +const RGBADepthPacking = 3201; +const RGBDepthPacking = 3202; +const RGDepthPacking = 3203; +const TangentSpaceNormalMap = 0; +const ObjectSpaceNormalMap = 1; + +// Color space string identifiers, matching CSS Color Module Level 4 and WebGPU names where available. +const NoColorSpace = ''; +const SRGBColorSpace = 'srgb'; +const LinearSRGBColorSpace = 'srgb-linear'; + +const LinearTransfer = 'linear'; +const SRGBTransfer = 'srgb'; + +const ZeroStencilOp = 0; +const KeepStencilOp = 7680; +const ReplaceStencilOp = 7681; +const IncrementStencilOp = 7682; +const DecrementStencilOp = 7683; +const IncrementWrapStencilOp = 34055; +const DecrementWrapStencilOp = 34056; +const InvertStencilOp = 5386; + +const NeverStencilFunc = 512; +const LessStencilFunc = 513; +const EqualStencilFunc = 514; +const LessEqualStencilFunc = 515; +const GreaterStencilFunc = 516; +const NotEqualStencilFunc = 517; +const GreaterEqualStencilFunc = 518; +const AlwaysStencilFunc = 519; + +const NeverCompare = 512; +const LessCompare = 513; +const EqualCompare = 514; +const LessEqualCompare = 515; +const GreaterCompare = 516; +const NotEqualCompare = 517; +const GreaterEqualCompare = 518; +const AlwaysCompare = 519; + +const StaticDrawUsage = 35044; +const DynamicDrawUsage = 35048; +const StreamDrawUsage = 35040; +const StaticReadUsage = 35045; +const DynamicReadUsage = 35049; +const StreamReadUsage = 35041; +const StaticCopyUsage = 35046; +const DynamicCopyUsage = 35050; +const StreamCopyUsage = 35042; + +const GLSL1 = '100'; +const GLSL3 = '300 es'; + +const WebGLCoordinateSystem = 2000; +const WebGPUCoordinateSystem = 2001; + +/** + * https://github.com/mrdoob/eventdispatcher.js/ + */ + +class EventDispatcher { + + addEventListener( type, listener ) { + + if ( this._listeners === undefined ) this._listeners = {}; + + const listeners = this._listeners; + + if ( listeners[ type ] === undefined ) { + + listeners[ type ] = []; + + } + + if ( listeners[ type ].indexOf( listener ) === - 1 ) { + + listeners[ type ].push( listener ); + + } + + } + + hasEventListener( type, listener ) { + + if ( this._listeners === undefined ) return false; + + const listeners = this._listeners; + + return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1; + + } + + removeEventListener( type, listener ) { + + if ( this._listeners === undefined ) return; + + const listeners = this._listeners; + const listenerArray = listeners[ type ]; + + if ( listenerArray !== undefined ) { + + const index = listenerArray.indexOf( listener ); + + if ( index !== - 1 ) { + + listenerArray.splice( index, 1 ); + + } + + } + + } + + dispatchEvent( event ) { + + if ( this._listeners === undefined ) return; + + const listeners = this._listeners; + const listenerArray = listeners[ event.type ]; + + if ( listenerArray !== undefined ) { + + event.target = this; + + // Make a copy, in case listeners are removed while iterating. + const array = listenerArray.slice( 0 ); + + for ( let i = 0, l = array.length; i < l; i ++ ) { + + array[ i ].call( this, event ); + + } + + event.target = null; + + } + + } + +} + +const _lut = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff' ]; + +let _seed = 1234567; + + +const DEG2RAD = Math.PI / 180; +const RAD2DEG = 180 / Math.PI; + +// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136 +function generateUUID() { + + const d0 = Math.random() * 0xffffffff | 0; + const d1 = Math.random() * 0xffffffff | 0; + const d2 = Math.random() * 0xffffffff | 0; + const d3 = Math.random() * 0xffffffff | 0; + const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' + + _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' + + _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] + + _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ]; + + // .toLowerCase() here flattens concatenated strings to save heap memory space. + return uuid.toLowerCase(); + +} + +function clamp( value, min, max ) { + + return Math.max( min, Math.min( max, value ) ); + +} + +// compute euclidean modulo of m % n +// https://en.wikipedia.org/wiki/Modulo_operation +function euclideanModulo( n, m ) { + + return ( ( n % m ) + m ) % m; + +} + +// Linear mapping from range to range +function mapLinear( x, a1, a2, b1, b2 ) { + + return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 ); + +} + +// https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/ +function inverseLerp( x, y, value ) { + + if ( x !== y ) { + + return ( value - x ) / ( y - x ); + + } else { + + return 0; + + } + +} + +// https://en.wikipedia.org/wiki/Linear_interpolation +function lerp( x, y, t ) { + + return ( 1 - t ) * x + t * y; + +} + +// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ +function damp( x, y, lambda, dt ) { + + return lerp( x, y, 1 - Math.exp( - lambda * dt ) ); + +} + +// https://www.desmos.com/calculator/vcsjnyz7x4 +function pingpong( x, length = 1 ) { + + return length - Math.abs( euclideanModulo( x, length * 2 ) - length ); + +} + +// http://en.wikipedia.org/wiki/Smoothstep +function smoothstep( x, min, max ) { + + if ( x <= min ) return 0; + if ( x >= max ) return 1; + + x = ( x - min ) / ( max - min ); + + return x * x * ( 3 - 2 * x ); + +} + +function smootherstep( x, min, max ) { + + if ( x <= min ) return 0; + if ( x >= max ) return 1; + + x = ( x - min ) / ( max - min ); + + return x * x * x * ( x * ( x * 6 - 15 ) + 10 ); + +} + +// Random integer from interval +function randInt( low, high ) { + + return low + Math.floor( Math.random() * ( high - low + 1 ) ); + +} + +// Random float from interval +function randFloat( low, high ) { + + return low + Math.random() * ( high - low ); + +} + +// Random float from <-range/2, range/2> interval +function randFloatSpread( range ) { + + return range * ( 0.5 - Math.random() ); + +} + +// Deterministic pseudo-random float in the interval [ 0, 1 ] +function seededRandom( s ) { + + if ( s !== undefined ) _seed = s; + + // Mulberry32 generator + + let t = _seed += 0x6D2B79F5; + + t = Math.imul( t ^ t >>> 15, t | 1 ); + + t ^= t + Math.imul( t ^ t >>> 7, t | 61 ); + + return ( ( t ^ t >>> 14 ) >>> 0 ) / 4294967296; + +} + +function degToRad( degrees ) { + + return degrees * DEG2RAD; + +} + +function radToDeg( radians ) { + + return radians * RAD2DEG; + +} + +function isPowerOfTwo( value ) { + + return ( value & ( value - 1 ) ) === 0 && value !== 0; + +} + +function ceilPowerOfTwo( value ) { + + return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) ); + +} + +function floorPowerOfTwo( value ) { + + return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) ); + +} + +function setQuaternionFromProperEuler( q, a, b, c, order ) { + + // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles + + // rotations are applied to the axes in the order specified by 'order' + // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c' + // angles are in radians + + const cos = Math.cos; + const sin = Math.sin; + + const c2 = cos( b / 2 ); + const s2 = sin( b / 2 ); + + const c13 = cos( ( a + c ) / 2 ); + const s13 = sin( ( a + c ) / 2 ); + + const c1_3 = cos( ( a - c ) / 2 ); + const s1_3 = sin( ( a - c ) / 2 ); + + const c3_1 = cos( ( c - a ) / 2 ); + const s3_1 = sin( ( c - a ) / 2 ); + + switch ( order ) { + + case 'XYX': + q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 ); + break; + + case 'YZY': + q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 ); + break; + + case 'ZXZ': + q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 ); + break; + + case 'XZX': + q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 ); + break; + + case 'YXY': + q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 ); + break; + + case 'ZYZ': + q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 ); + break; + + default: + console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order ); + + } + +} + +function denormalize( value, array ) { + + switch ( array.constructor ) { + + case Float32Array: + + return value; + + case Uint32Array: + + return value / 4294967295.0; + + case Uint16Array: + + return value / 65535.0; + + case Uint8Array: + + return value / 255.0; + + case Int32Array: + + return Math.max( value / 2147483647.0, - 1.0 ); + + case Int16Array: + + return Math.max( value / 32767.0, - 1.0 ); + + case Int8Array: + + return Math.max( value / 127.0, - 1.0 ); + + default: + + throw new Error( 'Invalid component type.' ); + + } + +} + +function normalize( value, array ) { + + switch ( array.constructor ) { + + case Float32Array: + + return value; + + case Uint32Array: + + return Math.round( value * 4294967295.0 ); + + case Uint16Array: + + return Math.round( value * 65535.0 ); + + case Uint8Array: + + return Math.round( value * 255.0 ); + + case Int32Array: + + return Math.round( value * 2147483647.0 ); + + case Int16Array: + + return Math.round( value * 32767.0 ); + + case Int8Array: + + return Math.round( value * 127.0 ); + + default: + + throw new Error( 'Invalid component type.' ); + + } + +} + +const MathUtils = { + DEG2RAD: DEG2RAD, + RAD2DEG: RAD2DEG, + generateUUID: generateUUID, + clamp: clamp, + euclideanModulo: euclideanModulo, + mapLinear: mapLinear, + inverseLerp: inverseLerp, + lerp: lerp, + damp: damp, + pingpong: pingpong, + smoothstep: smoothstep, + smootherstep: smootherstep, + randInt: randInt, + randFloat: randFloat, + randFloatSpread: randFloatSpread, + seededRandom: seededRandom, + degToRad: degToRad, + radToDeg: radToDeg, + isPowerOfTwo: isPowerOfTwo, + ceilPowerOfTwo: ceilPowerOfTwo, + floorPowerOfTwo: floorPowerOfTwo, + setQuaternionFromProperEuler: setQuaternionFromProperEuler, + normalize: normalize, + denormalize: denormalize +}; + +class Vector2 { + + constructor( x = 0, y = 0 ) { + + Vector2.prototype.isVector2 = true; + + this.x = x; + this.y = y; + + } + + get width() { + + return this.x; + + } + + set width( value ) { + + this.x = value; + + } + + get height() { + + return this.y; + + } + + set height( value ) { + + this.y = value; + + } + + set( x, y ) { + + this.x = x; + this.y = y; + + return this; + + } + + setScalar( scalar ) { + + this.x = scalar; + this.y = scalar; + + return this; + + } + + setX( x ) { + + this.x = x; + + return this; + + } + + setY( y ) { + + this.y = y; + + return this; + + } + + setComponent( index, value ) { + + switch ( index ) { + + case 0: this.x = value; break; + case 1: this.y = value; break; + default: throw new Error( 'index is out of range: ' + index ); + + } + + return this; + + } + + getComponent( index ) { + + switch ( index ) { + + case 0: return this.x; + case 1: return this.y; + default: throw new Error( 'index is out of range: ' + index ); + + } + + } + + clone() { + + return new this.constructor( this.x, this.y ); + + } + + copy( v ) { + + this.x = v.x; + this.y = v.y; + + return this; + + } + + add( v ) { + + this.x += v.x; + this.y += v.y; + + return this; + + } + + addScalar( s ) { + + this.x += s; + this.y += s; + + return this; + + } + + addVectors( a, b ) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + + return this; + + } + + addScaledVector( v, s ) { + + this.x += v.x * s; + this.y += v.y * s; + + return this; + + } + + sub( v ) { + + this.x -= v.x; + this.y -= v.y; + + return this; + + } + + subScalar( s ) { + + this.x -= s; + this.y -= s; + + return this; + + } + + subVectors( a, b ) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + + return this; + + } + + multiply( v ) { + + this.x *= v.x; + this.y *= v.y; + + return this; + + } + + multiplyScalar( scalar ) { + + this.x *= scalar; + this.y *= scalar; + + return this; + + } + + divide( v ) { + + this.x /= v.x; + this.y /= v.y; + + return this; + + } + + divideScalar( scalar ) { + + return this.multiplyScalar( 1 / scalar ); + + } + + applyMatrix3( m ) { + + const x = this.x, y = this.y; + const e = m.elements; + + this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ]; + this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ]; + + return this; + + } + + min( v ) { + + this.x = Math.min( this.x, v.x ); + this.y = Math.min( this.y, v.y ); + + return this; + + } + + max( v ) { + + this.x = Math.max( this.x, v.x ); + this.y = Math.max( this.y, v.y ); + + return this; + + } + + clamp( min, max ) { + + // assumes min < max, componentwise + + this.x = clamp( this.x, min.x, max.x ); + this.y = clamp( this.y, min.y, max.y ); + + return this; + + } + + clampScalar( minVal, maxVal ) { + + this.x = clamp( this.x, minVal, maxVal ); + this.y = clamp( this.y, minVal, maxVal ); + + return this; + + } + + clampLength( min, max ) { + + const length = this.length(); + + return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) ); + + } + + floor() { + + this.x = Math.floor( this.x ); + this.y = Math.floor( this.y ); + + return this; + + } + + ceil() { + + this.x = Math.ceil( this.x ); + this.y = Math.ceil( this.y ); + + return this; + + } + + round() { + + this.x = Math.round( this.x ); + this.y = Math.round( this.y ); + + return this; + + } + + roundToZero() { + + this.x = Math.trunc( this.x ); + this.y = Math.trunc( this.y ); + + return this; + + } + + negate() { + + this.x = - this.x; + this.y = - this.y; + + return this; + + } + + dot( v ) { + + return this.x * v.x + this.y * v.y; + + } + + cross( v ) { + + return this.x * v.y - this.y * v.x; + + } + + lengthSq() { + + return this.x * this.x + this.y * this.y; + + } + + length() { + + return Math.sqrt( this.x * this.x + this.y * this.y ); + + } + + manhattanLength() { + + return Math.abs( this.x ) + Math.abs( this.y ); + + } + + normalize() { + + return this.divideScalar( this.length() || 1 ); + + } + + angle() { + + // computes the angle in radians with respect to the positive x-axis + + const angle = Math.atan2( - this.y, - this.x ) + Math.PI; + + return angle; + + } + + angleTo( v ) { + + const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() ); + + if ( denominator === 0 ) return Math.PI / 2; + + const theta = this.dot( v ) / denominator; + + // clamp, to handle numerical problems + + return Math.acos( clamp( theta, - 1, 1 ) ); + + } + + distanceTo( v ) { + + return Math.sqrt( this.distanceToSquared( v ) ); + + } + + distanceToSquared( v ) { + + const dx = this.x - v.x, dy = this.y - v.y; + return dx * dx + dy * dy; + + } + + manhattanDistanceTo( v ) { + + return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ); + + } + + setLength( length ) { + + return this.normalize().multiplyScalar( length ); + + } + + lerp( v, alpha ) { + + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + + return this; + + } + + lerpVectors( v1, v2, alpha ) { + + this.x = v1.x + ( v2.x - v1.x ) * alpha; + this.y = v1.y + ( v2.y - v1.y ) * alpha; + + return this; + + } + + equals( v ) { + + return ( ( v.x === this.x ) && ( v.y === this.y ) ); + + } + + fromArray( array, offset = 0 ) { + + this.x = array[ offset ]; + this.y = array[ offset + 1 ]; + + return this; + + } + + toArray( array = [], offset = 0 ) { + + array[ offset ] = this.x; + array[ offset + 1 ] = this.y; + + return array; + + } + + fromBufferAttribute( attribute, index ) { + + this.x = attribute.getX( index ); + this.y = attribute.getY( index ); + + return this; + + } + + rotateAround( center, angle ) { + + const c = Math.cos( angle ), s = Math.sin( angle ); + + const x = this.x - center.x; + const y = this.y - center.y; + + this.x = x * c - y * s + center.x; + this.y = x * s + y * c + center.y; + + return this; + + } + + random() { + + this.x = Math.random(); + this.y = Math.random(); + + return this; + + } + + *[ Symbol.iterator ]() { + + yield this.x; + yield this.y; + + } + +} + +class Matrix3 { + + constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) { + + Matrix3.prototype.isMatrix3 = true; + + this.elements = [ + + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + + ]; + + if ( n11 !== undefined ) { + + this.set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ); + + } + + } + + set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) { + + const te = this.elements; + + te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31; + te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32; + te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33; + + return this; + + } + + identity() { + + this.set( + + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + + ); + + return this; + + } + + copy( m ) { + + const te = this.elements; + const me = m.elements; + + te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; + te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; + te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ]; + + return this; + + } + + extractBasis( xAxis, yAxis, zAxis ) { + + xAxis.setFromMatrix3Column( this, 0 ); + yAxis.setFromMatrix3Column( this, 1 ); + zAxis.setFromMatrix3Column( this, 2 ); + + return this; + + } + + setFromMatrix4( m ) { + + const me = m.elements; + + this.set( + + me[ 0 ], me[ 4 ], me[ 8 ], + me[ 1 ], me[ 5 ], me[ 9 ], + me[ 2 ], me[ 6 ], me[ 10 ] + + ); + + return this; + + } + + multiply( m ) { + + return this.multiplyMatrices( this, m ); + + } + + premultiply( m ) { + + return this.multiplyMatrices( m, this ); + + } + + multiplyMatrices( a, b ) { + + const ae = a.elements; + const be = b.elements; + const te = this.elements; + + const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ]; + const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ]; + const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ]; + + const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ]; + const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ]; + const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ]; + + te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31; + te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32; + te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33; + + te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31; + te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32; + te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33; + + te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31; + te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32; + te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33; + + return this; + + } + + multiplyScalar( s ) { + + const te = this.elements; + + te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s; + te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s; + te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s; + + return this; + + } + + determinant() { + + const te = this.elements; + + const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ], + d = te[ 3 ], e = te[ 4 ], f = te[ 5 ], + g = te[ 6 ], h = te[ 7 ], i = te[ 8 ]; + + return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g; + + } + + invert() { + + const te = this.elements, + + n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], + n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ], + n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ], + + t11 = n33 * n22 - n32 * n23, + t12 = n32 * n13 - n33 * n12, + t13 = n23 * n12 - n22 * n13, + + det = n11 * t11 + n21 * t12 + n31 * t13; + + if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); + + const detInv = 1 / det; + + te[ 0 ] = t11 * detInv; + te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv; + te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv; + + te[ 3 ] = t12 * detInv; + te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv; + te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv; + + te[ 6 ] = t13 * detInv; + te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv; + te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv; + + return this; + + } + + transpose() { + + let tmp; + const m = this.elements; + + tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp; + tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp; + tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp; + + return this; + + } + + getNormalMatrix( matrix4 ) { + + return this.setFromMatrix4( matrix4 ).invert().transpose(); + + } + + transposeIntoArray( r ) { + + const m = this.elements; + + r[ 0 ] = m[ 0 ]; + r[ 1 ] = m[ 3 ]; + r[ 2 ] = m[ 6 ]; + r[ 3 ] = m[ 1 ]; + r[ 4 ] = m[ 4 ]; + r[ 5 ] = m[ 7 ]; + r[ 6 ] = m[ 2 ]; + r[ 7 ] = m[ 5 ]; + r[ 8 ] = m[ 8 ]; + + return this; + + } + + setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) { + + const c = Math.cos( rotation ); + const s = Math.sin( rotation ); + + this.set( + sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx, + - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty, + 0, 0, 1 + ); + + return this; + + } + + // + + scale( sx, sy ) { + + this.premultiply( _m3.makeScale( sx, sy ) ); + + return this; + + } + + rotate( theta ) { + + this.premultiply( _m3.makeRotation( - theta ) ); + + return this; + + } + + translate( tx, ty ) { + + this.premultiply( _m3.makeTranslation( tx, ty ) ); + + return this; + + } + + // for 2D Transforms + + makeTranslation( x, y ) { + + if ( x.isVector2 ) { + + this.set( + + 1, 0, x.x, + 0, 1, x.y, + 0, 0, 1 + + ); + + } else { + + this.set( + + 1, 0, x, + 0, 1, y, + 0, 0, 1 + + ); + + } + + return this; + + } + + makeRotation( theta ) { + + // counterclockwise + + const c = Math.cos( theta ); + const s = Math.sin( theta ); + + this.set( + + c, - s, 0, + s, c, 0, + 0, 0, 1 + + ); + + return this; + + } + + makeScale( x, y ) { + + this.set( + + x, 0, 0, + 0, y, 0, + 0, 0, 1 + + ); + + return this; + + } + + // + + equals( matrix ) { + + const te = this.elements; + const me = matrix.elements; + + for ( let i = 0; i < 9; i ++ ) { + + if ( te[ i ] !== me[ i ] ) return false; + + } + + return true; + + } + + fromArray( array, offset = 0 ) { + + for ( let i = 0; i < 9; i ++ ) { + + this.elements[ i ] = array[ i + offset ]; + + } + + return this; + + } + + toArray( array = [], offset = 0 ) { + + const te = this.elements; + + array[ offset ] = te[ 0 ]; + array[ offset + 1 ] = te[ 1 ]; + array[ offset + 2 ] = te[ 2 ]; + + array[ offset + 3 ] = te[ 3 ]; + array[ offset + 4 ] = te[ 4 ]; + array[ offset + 5 ] = te[ 5 ]; + + array[ offset + 6 ] = te[ 6 ]; + array[ offset + 7 ] = te[ 7 ]; + array[ offset + 8 ] = te[ 8 ]; + + return array; + + } + + clone() { + + return new this.constructor().fromArray( this.elements ); + + } + +} + +const _m3 = /*@__PURE__*/ new Matrix3(); + +function arrayNeedsUint32( array ) { + + // assumes larger values usually on last + + for ( let i = array.length - 1; i >= 0; -- i ) { + + if ( array[ i ] >= 65535 ) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565 + + } + + return false; + +} + +const TYPED_ARRAYS = { + Int8Array: Int8Array, + Uint8Array: Uint8Array, + Uint8ClampedArray: Uint8ClampedArray, + Int16Array: Int16Array, + Uint16Array: Uint16Array, + Int32Array: Int32Array, + Uint32Array: Uint32Array, + Float32Array: Float32Array, + Float64Array: Float64Array +}; + +function getTypedArray( type, buffer ) { + + return new TYPED_ARRAYS[ type ]( buffer ); + +} + +function createElementNS( name ) { + + return document.createElementNS( 'http://www.w3.org/1999/xhtml', name ); + +} + +function createCanvasElement() { + + const canvas = createElementNS( 'canvas' ); + canvas.style.display = 'block'; + return canvas; + +} + +const _cache = {}; + +function warnOnce( message ) { + + if ( message in _cache ) return; + + _cache[ message ] = true; + + console.warn( message ); + +} + +function probeAsync( gl, sync, interval ) { + + return new Promise( function ( resolve, reject ) { + + function probe() { + + switch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) { + + case gl.WAIT_FAILED: + reject(); + break; + + case gl.TIMEOUT_EXPIRED: + setTimeout( probe, interval ); + break; + + default: + resolve(); + + } + + } + + setTimeout( probe, interval ); + + } ); + +} + +function toNormalizedProjectionMatrix( projectionMatrix ) { + + const m = projectionMatrix.elements; + + // Convert [-1, 1] to [0, 1] projection matrix + m[ 2 ] = 0.5 * m[ 2 ] + 0.5 * m[ 3 ]; + m[ 6 ] = 0.5 * m[ 6 ] + 0.5 * m[ 7 ]; + m[ 10 ] = 0.5 * m[ 10 ] + 0.5 * m[ 11 ]; + m[ 14 ] = 0.5 * m[ 14 ] + 0.5 * m[ 15 ]; + +} + +function toReversedProjectionMatrix( projectionMatrix ) { + + const m = projectionMatrix.elements; + const isPerspectiveMatrix = m[ 11 ] === - 1; + + // Reverse [0, 1] projection matrix + if ( isPerspectiveMatrix ) { + + m[ 10 ] = - m[ 10 ] - 1; + m[ 14 ] = - m[ 14 ]; + + } else { + + m[ 10 ] = - m[ 10 ]; + m[ 14 ] = - m[ 14 ] + 1; + + } + +} + +const LINEAR_REC709_TO_XYZ = /*@__PURE__*/ new Matrix3().set( + 0.4123908, 0.3575843, 0.1804808, + 0.2126390, 0.7151687, 0.0721923, + 0.0193308, 0.1191948, 0.9505322 +); + +const XYZ_TO_LINEAR_REC709 = /*@__PURE__*/ new Matrix3().set( + 3.2409699, - 1.5373832, - 0.4986108, + - 0.9692436, 1.8759675, 0.0415551, + 0.0556301, - 0.2039770, 1.0569715 +); + +function createColorManagement() { + + const ColorManagement = { + + enabled: true, + + workingColorSpace: LinearSRGBColorSpace, + + /** + * Implementations of supported color spaces. + * + * Required: + * - primaries: chromaticity coordinates [ rx ry gx gy bx by ] + * - whitePoint: reference white [ x y ] + * - transfer: transfer function (pre-defined) + * - toXYZ: Matrix3 RGB to XYZ transform + * - fromXYZ: Matrix3 XYZ to RGB transform + * - luminanceCoefficients: RGB luminance coefficients + * + * Optional: + * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace } + * - workingColorSpaceConfig: { unpackColorSpace: ColorSpace } + * + * Reference: + * - https://www.russellcottrell.com/photo/matrixCalculator.htm + */ + spaces: {}, + + convert: function ( color, sourceColorSpace, targetColorSpace ) { + + if ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) { + + return color; + + } + + if ( this.spaces[ sourceColorSpace ].transfer === SRGBTransfer ) { + + color.r = SRGBToLinear( color.r ); + color.g = SRGBToLinear( color.g ); + color.b = SRGBToLinear( color.b ); + + } + + if ( this.spaces[ sourceColorSpace ].primaries !== this.spaces[ targetColorSpace ].primaries ) { + + color.applyMatrix3( this.spaces[ sourceColorSpace ].toXYZ ); + color.applyMatrix3( this.spaces[ targetColorSpace ].fromXYZ ); + + } + + if ( this.spaces[ targetColorSpace ].transfer === SRGBTransfer ) { + + color.r = LinearToSRGB( color.r ); + color.g = LinearToSRGB( color.g ); + color.b = LinearToSRGB( color.b ); + + } + + return color; + + }, + + fromWorkingColorSpace: function ( color, targetColorSpace ) { + + return this.convert( color, this.workingColorSpace, targetColorSpace ); + + }, + + toWorkingColorSpace: function ( color, sourceColorSpace ) { + + return this.convert( color, sourceColorSpace, this.workingColorSpace ); + + }, + + getPrimaries: function ( colorSpace ) { + + return this.spaces[ colorSpace ].primaries; + + }, + + getTransfer: function ( colorSpace ) { + + if ( colorSpace === NoColorSpace ) return LinearTransfer; + + return this.spaces[ colorSpace ].transfer; + + }, + + getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) { + + return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients ); + + }, + + define: function ( colorSpaces ) { + + Object.assign( this.spaces, colorSpaces ); + + }, + + // Internal APIs + + _getMatrix: function ( targetMatrix, sourceColorSpace, targetColorSpace ) { + + return targetMatrix + .copy( this.spaces[ sourceColorSpace ].toXYZ ) + .multiply( this.spaces[ targetColorSpace ].fromXYZ ); + + }, + + _getDrawingBufferColorSpace: function ( colorSpace ) { + + return this.spaces[ colorSpace ].outputColorSpaceConfig.drawingBufferColorSpace; + + }, + + _getUnpackColorSpace: function ( colorSpace = this.workingColorSpace ) { + + return this.spaces[ colorSpace ].workingColorSpaceConfig.unpackColorSpace; + + } + + }; + + /****************************************************************************** + * sRGB definitions + */ + + const REC709_PRIMARIES = [ 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 ]; + const REC709_LUMINANCE_COEFFICIENTS = [ 0.2126, 0.7152, 0.0722 ]; + const D65 = [ 0.3127, 0.3290 ]; + + ColorManagement.define( { + + [ LinearSRGBColorSpace ]: { + primaries: REC709_PRIMARIES, + whitePoint: D65, + transfer: LinearTransfer, + toXYZ: LINEAR_REC709_TO_XYZ, + fromXYZ: XYZ_TO_LINEAR_REC709, + luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS, + workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace }, + outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace } + }, + + [ SRGBColorSpace ]: { + primaries: REC709_PRIMARIES, + whitePoint: D65, + transfer: SRGBTransfer, + toXYZ: LINEAR_REC709_TO_XYZ, + fromXYZ: XYZ_TO_LINEAR_REC709, + luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS, + outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace } + }, + + } ); + + return ColorManagement; + +} + +const ColorManagement = /*@__PURE__*/ createColorManagement(); + +function SRGBToLinear( c ) { + + return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 ); + +} + +function LinearToSRGB( c ) { + + return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055; + +} + +let _canvas; + +class ImageUtils { + + static getDataURL( image ) { + + if ( /^data:/i.test( image.src ) ) { + + return image.src; + + } + + if ( typeof HTMLCanvasElement === 'undefined' ) { + + return image.src; + + } + + let canvas; + + if ( image instanceof HTMLCanvasElement ) { + + canvas = image; + + } else { + + if ( _canvas === undefined ) _canvas = createElementNS( 'canvas' ); + + _canvas.width = image.width; + _canvas.height = image.height; + + const context = _canvas.getContext( '2d' ); + + if ( image instanceof ImageData ) { + + context.putImageData( image, 0, 0 ); + + } else { + + context.drawImage( image, 0, 0, image.width, image.height ); + + } + + canvas = _canvas; + + } + + if ( canvas.width > 2048 || canvas.height > 2048 ) { + + console.warn( 'THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image ); + + return canvas.toDataURL( 'image/jpeg', 0.6 ); + + } else { + + return canvas.toDataURL( 'image/png' ); + + } + + } + + static sRGBToLinear( image ) { + + if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || + ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) || + ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) { + + const canvas = createElementNS( 'canvas' ); + + canvas.width = image.width; + canvas.height = image.height; + + const context = canvas.getContext( '2d' ); + context.drawImage( image, 0, 0, image.width, image.height ); + + const imageData = context.getImageData( 0, 0, image.width, image.height ); + const data = imageData.data; + + for ( let i = 0; i < data.length; i ++ ) { + + data[ i ] = SRGBToLinear( data[ i ] / 255 ) * 255; + + } + + context.putImageData( imageData, 0, 0 ); + + return canvas; + + } else if ( image.data ) { + + const data = image.data.slice( 0 ); + + for ( let i = 0; i < data.length; i ++ ) { + + if ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) { + + data[ i ] = Math.floor( SRGBToLinear( data[ i ] / 255 ) * 255 ); + + } else { + + // assuming float + + data[ i ] = SRGBToLinear( data[ i ] ); + + } + + } + + return { + data: data, + width: image.width, + height: image.height + }; + + } else { + + console.warn( 'THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.' ); + return image; + + } + + } + +} + +let _sourceId = 0; + +class Source { + + constructor( data = null ) { + + this.isSource = true; + + Object.defineProperty( this, 'id', { value: _sourceId ++ } ); + + this.uuid = generateUUID(); + + this.data = data; + this.dataReady = true; + + this.version = 0; + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + toJSON( meta ) { + + const isRootObject = ( meta === undefined || typeof meta === 'string' ); + + if ( ! isRootObject && meta.images[ this.uuid ] !== undefined ) { + + return meta.images[ this.uuid ]; + + } + + const output = { + uuid: this.uuid, + url: '' + }; + + const data = this.data; + + if ( data !== null ) { + + let url; + + if ( Array.isArray( data ) ) { + + // cube texture + + url = []; + + for ( let i = 0, l = data.length; i < l; i ++ ) { + + if ( data[ i ].isDataTexture ) { + + url.push( serializeImage( data[ i ].image ) ); + + } else { + + url.push( serializeImage( data[ i ] ) ); + + } + + } + + } else { + + // texture + + url = serializeImage( data ); + + } + + output.url = url; + + } + + if ( ! isRootObject ) { + + meta.images[ this.uuid ] = output; + + } + + return output; + + } + +} + +function serializeImage( image ) { + + if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || + ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) || + ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) { + + // default images + + return ImageUtils.getDataURL( image ); + + } else { + + if ( image.data ) { + + // images of DataTexture + + return { + data: Array.from( image.data ), + width: image.width, + height: image.height, + type: image.data.constructor.name + }; + + } else { + + console.warn( 'THREE.Texture: Unable to serialize Texture.' ); + return {}; + + } + + } + +} + +let _textureId = 0; + +class Texture extends EventDispatcher { + + constructor( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace ) { + + super(); + + this.isTexture = true; + + Object.defineProperty( this, 'id', { value: _textureId ++ } ); + + this.uuid = generateUUID(); + + this.name = ''; + + this.source = new Source( image ); + this.mipmaps = []; + + this.mapping = mapping; + this.channel = 0; + + this.wrapS = wrapS; + this.wrapT = wrapT; + + this.magFilter = magFilter; + this.minFilter = minFilter; + + this.anisotropy = anisotropy; + + this.format = format; + this.internalFormat = null; + this.type = type; + + this.offset = new Vector2( 0, 0 ); + this.repeat = new Vector2( 1, 1 ); + this.center = new Vector2( 0, 0 ); + this.rotation = 0; + + this.matrixAutoUpdate = true; + this.matrix = new Matrix3(); + + this.generateMipmaps = true; + this.premultiplyAlpha = false; + this.flipY = true; + this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml) + + this.colorSpace = colorSpace; + + this.userData = {}; + + this.version = 0; + this.onUpdate = null; + + this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not + this.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures) + + } + + get image() { + + return this.source.data; + + } + + set image( value = null ) { + + this.source.data = value; + + } + + updateMatrix() { + + this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( source ) { + + this.name = source.name; + + this.source = source.source; + this.mipmaps = source.mipmaps.slice( 0 ); + + this.mapping = source.mapping; + this.channel = source.channel; + + this.wrapS = source.wrapS; + this.wrapT = source.wrapT; + + this.magFilter = source.magFilter; + this.minFilter = source.minFilter; + + this.anisotropy = source.anisotropy; + + this.format = source.format; + this.internalFormat = source.internalFormat; + this.type = source.type; + + this.offset.copy( source.offset ); + this.repeat.copy( source.repeat ); + this.center.copy( source.center ); + this.rotation = source.rotation; + + this.matrixAutoUpdate = source.matrixAutoUpdate; + this.matrix.copy( source.matrix ); + + this.generateMipmaps = source.generateMipmaps; + this.premultiplyAlpha = source.premultiplyAlpha; + this.flipY = source.flipY; + this.unpackAlignment = source.unpackAlignment; + this.colorSpace = source.colorSpace; + + this.userData = JSON.parse( JSON.stringify( source.userData ) ); + + this.needsUpdate = true; + + return this; + + } + + toJSON( meta ) { + + const isRootObject = ( meta === undefined || typeof meta === 'string' ); + + if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) { + + return meta.textures[ this.uuid ]; + + } + + const output = { + + metadata: { + version: 4.6, + type: 'Texture', + generator: 'Texture.toJSON' + }, + + uuid: this.uuid, + name: this.name, + + image: this.source.toJSON( meta ).uuid, + + mapping: this.mapping, + channel: this.channel, + + repeat: [ this.repeat.x, this.repeat.y ], + offset: [ this.offset.x, this.offset.y ], + center: [ this.center.x, this.center.y ], + rotation: this.rotation, + + wrap: [ this.wrapS, this.wrapT ], + + format: this.format, + internalFormat: this.internalFormat, + type: this.type, + colorSpace: this.colorSpace, + + minFilter: this.minFilter, + magFilter: this.magFilter, + anisotropy: this.anisotropy, + + flipY: this.flipY, + + generateMipmaps: this.generateMipmaps, + premultiplyAlpha: this.premultiplyAlpha, + unpackAlignment: this.unpackAlignment + + }; + + if ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData; + + if ( ! isRootObject ) { + + meta.textures[ this.uuid ] = output; + + } + + return output; + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + transformUv( uv ) { + + if ( this.mapping !== UVMapping ) return uv; + + uv.applyMatrix3( this.matrix ); + + if ( uv.x < 0 || uv.x > 1 ) { + + switch ( this.wrapS ) { + + case RepeatWrapping: + + uv.x = uv.x - Math.floor( uv.x ); + break; + + case ClampToEdgeWrapping: + + uv.x = uv.x < 0 ? 0 : 1; + break; + + case MirroredRepeatWrapping: + + if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) { + + uv.x = Math.ceil( uv.x ) - uv.x; + + } else { + + uv.x = uv.x - Math.floor( uv.x ); + + } + + break; + + } + + } + + if ( uv.y < 0 || uv.y > 1 ) { + + switch ( this.wrapT ) { + + case RepeatWrapping: + + uv.y = uv.y - Math.floor( uv.y ); + break; + + case ClampToEdgeWrapping: + + uv.y = uv.y < 0 ? 0 : 1; + break; + + case MirroredRepeatWrapping: + + if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) { + + uv.y = Math.ceil( uv.y ) - uv.y; + + } else { + + uv.y = uv.y - Math.floor( uv.y ); + + } + + break; + + } + + } + + if ( this.flipY ) { + + uv.y = 1 - uv.y; + + } + + return uv; + + } + + set needsUpdate( value ) { + + if ( value === true ) { + + this.version ++; + this.source.needsUpdate = true; + + } + + } + + set needsPMREMUpdate( value ) { + + if ( value === true ) { + + this.pmremVersion ++; + + } + + } + +} + +Texture.DEFAULT_IMAGE = null; +Texture.DEFAULT_MAPPING = UVMapping; +Texture.DEFAULT_ANISOTROPY = 1; + +class Vector4 { + + constructor( x = 0, y = 0, z = 0, w = 1 ) { + + Vector4.prototype.isVector4 = true; + + this.x = x; + this.y = y; + this.z = z; + this.w = w; + + } + + get width() { + + return this.z; + + } + + set width( value ) { + + this.z = value; + + } + + get height() { + + return this.w; + + } + + set height( value ) { + + this.w = value; + + } + + set( x, y, z, w ) { + + this.x = x; + this.y = y; + this.z = z; + this.w = w; + + return this; + + } + + setScalar( scalar ) { + + this.x = scalar; + this.y = scalar; + this.z = scalar; + this.w = scalar; + + return this; + + } + + setX( x ) { + + this.x = x; + + return this; + + } + + setY( y ) { + + this.y = y; + + return this; + + } + + setZ( z ) { + + this.z = z; + + return this; + + } + + setW( w ) { + + this.w = w; + + return this; + + } + + setComponent( index, value ) { + + switch ( index ) { + + case 0: this.x = value; break; + case 1: this.y = value; break; + case 2: this.z = value; break; + case 3: this.w = value; break; + default: throw new Error( 'index is out of range: ' + index ); + + } + + return this; + + } + + getComponent( index ) { + + switch ( index ) { + + case 0: return this.x; + case 1: return this.y; + case 2: return this.z; + case 3: return this.w; + default: throw new Error( 'index is out of range: ' + index ); + + } + + } + + clone() { + + return new this.constructor( this.x, this.y, this.z, this.w ); + + } + + copy( v ) { + + this.x = v.x; + this.y = v.y; + this.z = v.z; + this.w = ( v.w !== undefined ) ? v.w : 1; + + return this; + + } + + add( v ) { + + this.x += v.x; + this.y += v.y; + this.z += v.z; + this.w += v.w; + + return this; + + } + + addScalar( s ) { + + this.x += s; + this.y += s; + this.z += s; + this.w += s; + + return this; + + } + + addVectors( a, b ) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + this.z = a.z + b.z; + this.w = a.w + b.w; + + return this; + + } + + addScaledVector( v, s ) { + + this.x += v.x * s; + this.y += v.y * s; + this.z += v.z * s; + this.w += v.w * s; + + return this; + + } + + sub( v ) { + + this.x -= v.x; + this.y -= v.y; + this.z -= v.z; + this.w -= v.w; + + return this; + + } + + subScalar( s ) { + + this.x -= s; + this.y -= s; + this.z -= s; + this.w -= s; + + return this; + + } + + subVectors( a, b ) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + this.z = a.z - b.z; + this.w = a.w - b.w; + + return this; + + } + + multiply( v ) { + + this.x *= v.x; + this.y *= v.y; + this.z *= v.z; + this.w *= v.w; + + return this; + + } + + multiplyScalar( scalar ) { + + this.x *= scalar; + this.y *= scalar; + this.z *= scalar; + this.w *= scalar; + + return this; + + } + + applyMatrix4( m ) { + + const x = this.x, y = this.y, z = this.z, w = this.w; + const e = m.elements; + + this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w; + this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w; + this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w; + this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w; + + return this; + + } + + divide( v ) { + + this.x /= v.x; + this.y /= v.y; + this.z /= v.z; + this.w /= v.w; + + return this; + + } + + divideScalar( scalar ) { + + return this.multiplyScalar( 1 / scalar ); + + } + + setAxisAngleFromQuaternion( q ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm + + // q is assumed to be normalized + + this.w = 2 * Math.acos( q.w ); + + const s = Math.sqrt( 1 - q.w * q.w ); + + if ( s < 0.0001 ) { + + this.x = 1; + this.y = 0; + this.z = 0; + + } else { + + this.x = q.x / s; + this.y = q.y / s; + this.z = q.z / s; + + } + + return this; + + } + + setAxisAngleFromRotationMatrix( m ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + let angle, x, y, z; // variables for result + const epsilon = 0.01, // margin to allow for rounding errors + epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees + + te = m.elements, + + m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ], + m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ], + m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ]; + + if ( ( Math.abs( m12 - m21 ) < epsilon ) && + ( Math.abs( m13 - m31 ) < epsilon ) && + ( Math.abs( m23 - m32 ) < epsilon ) ) { + + // singularity found + // first check for identity matrix which must have +1 for all terms + // in leading diagonal and zero in other terms + + if ( ( Math.abs( m12 + m21 ) < epsilon2 ) && + ( Math.abs( m13 + m31 ) < epsilon2 ) && + ( Math.abs( m23 + m32 ) < epsilon2 ) && + ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) { + + // this singularity is identity matrix so angle = 0 + + this.set( 1, 0, 0, 0 ); + + return this; // zero angle, arbitrary axis + + } + + // otherwise this singularity is angle = 180 + + angle = Math.PI; + + const xx = ( m11 + 1 ) / 2; + const yy = ( m22 + 1 ) / 2; + const zz = ( m33 + 1 ) / 2; + const xy = ( m12 + m21 ) / 4; + const xz = ( m13 + m31 ) / 4; + const yz = ( m23 + m32 ) / 4; + + if ( ( xx > yy ) && ( xx > zz ) ) { + + // m11 is the largest diagonal term + + if ( xx < epsilon ) { + + x = 0; + y = 0.707106781; + z = 0.707106781; + + } else { + + x = Math.sqrt( xx ); + y = xy / x; + z = xz / x; + + } + + } else if ( yy > zz ) { + + // m22 is the largest diagonal term + + if ( yy < epsilon ) { + + x = 0.707106781; + y = 0; + z = 0.707106781; + + } else { + + y = Math.sqrt( yy ); + x = xy / y; + z = yz / y; + + } + + } else { + + // m33 is the largest diagonal term so base result on this + + if ( zz < epsilon ) { + + x = 0.707106781; + y = 0.707106781; + z = 0; + + } else { + + z = Math.sqrt( zz ); + x = xz / z; + y = yz / z; + + } + + } + + this.set( x, y, z, angle ); + + return this; // return 180 deg rotation + + } + + // as we have reached here there are no singularities so we can handle normally + + let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) + + ( m13 - m31 ) * ( m13 - m31 ) + + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize + + if ( Math.abs( s ) < 0.001 ) s = 1; + + // prevent divide by zero, should not happen if matrix is orthogonal and should be + // caught by singularity test above, but I've left it in just in case + + this.x = ( m32 - m23 ) / s; + this.y = ( m13 - m31 ) / s; + this.z = ( m21 - m12 ) / s; + this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 ); + + return this; + + } + + setFromMatrixPosition( m ) { + + const e = m.elements; + + this.x = e[ 12 ]; + this.y = e[ 13 ]; + this.z = e[ 14 ]; + this.w = e[ 15 ]; + + return this; + + } + + min( v ) { + + this.x = Math.min( this.x, v.x ); + this.y = Math.min( this.y, v.y ); + this.z = Math.min( this.z, v.z ); + this.w = Math.min( this.w, v.w ); + + return this; + + } + + max( v ) { + + this.x = Math.max( this.x, v.x ); + this.y = Math.max( this.y, v.y ); + this.z = Math.max( this.z, v.z ); + this.w = Math.max( this.w, v.w ); + + return this; + + } + + clamp( min, max ) { + + // assumes min < max, componentwise + + this.x = clamp( this.x, min.x, max.x ); + this.y = clamp( this.y, min.y, max.y ); + this.z = clamp( this.z, min.z, max.z ); + this.w = clamp( this.w, min.w, max.w ); + + return this; + + } + + clampScalar( minVal, maxVal ) { + + this.x = clamp( this.x, minVal, maxVal ); + this.y = clamp( this.y, minVal, maxVal ); + this.z = clamp( this.z, minVal, maxVal ); + this.w = clamp( this.w, minVal, maxVal ); + + return this; + + } + + clampLength( min, max ) { + + const length = this.length(); + + return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) ); + + } + + floor() { + + this.x = Math.floor( this.x ); + this.y = Math.floor( this.y ); + this.z = Math.floor( this.z ); + this.w = Math.floor( this.w ); + + return this; + + } + + ceil() { + + this.x = Math.ceil( this.x ); + this.y = Math.ceil( this.y ); + this.z = Math.ceil( this.z ); + this.w = Math.ceil( this.w ); + + return this; + + } + + round() { + + this.x = Math.round( this.x ); + this.y = Math.round( this.y ); + this.z = Math.round( this.z ); + this.w = Math.round( this.w ); + + return this; + + } + + roundToZero() { + + this.x = Math.trunc( this.x ); + this.y = Math.trunc( this.y ); + this.z = Math.trunc( this.z ); + this.w = Math.trunc( this.w ); + + return this; + + } + + negate() { + + this.x = - this.x; + this.y = - this.y; + this.z = - this.z; + this.w = - this.w; + + return this; + + } + + dot( v ) { + + return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; + + } + + lengthSq() { + + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + + } + + length() { + + return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w ); + + } + + manhattanLength() { + + return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w ); + + } + + normalize() { + + return this.divideScalar( this.length() || 1 ); + + } + + setLength( length ) { + + return this.normalize().multiplyScalar( length ); + + } + + lerp( v, alpha ) { + + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + this.z += ( v.z - this.z ) * alpha; + this.w += ( v.w - this.w ) * alpha; + + return this; + + } + + lerpVectors( v1, v2, alpha ) { + + this.x = v1.x + ( v2.x - v1.x ) * alpha; + this.y = v1.y + ( v2.y - v1.y ) * alpha; + this.z = v1.z + ( v2.z - v1.z ) * alpha; + this.w = v1.w + ( v2.w - v1.w ) * alpha; + + return this; + + } + + equals( v ) { + + return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) ); + + } + + fromArray( array, offset = 0 ) { + + this.x = array[ offset ]; + this.y = array[ offset + 1 ]; + this.z = array[ offset + 2 ]; + this.w = array[ offset + 3 ]; + + return this; + + } + + toArray( array = [], offset = 0 ) { + + array[ offset ] = this.x; + array[ offset + 1 ] = this.y; + array[ offset + 2 ] = this.z; + array[ offset + 3 ] = this.w; + + return array; + + } + + fromBufferAttribute( attribute, index ) { + + this.x = attribute.getX( index ); + this.y = attribute.getY( index ); + this.z = attribute.getZ( index ); + this.w = attribute.getW( index ); + + return this; + + } + + random() { + + this.x = Math.random(); + this.y = Math.random(); + this.z = Math.random(); + this.w = Math.random(); + + return this; + + } + + *[ Symbol.iterator ]() { + + yield this.x; + yield this.y; + yield this.z; + yield this.w; + + } + +} + +/* + In options, we can specify: + * Texture parameters for an auto-generated target texture + * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers +*/ +class RenderTarget extends EventDispatcher { + + constructor( width = 1, height = 1, options = {} ) { + + super(); + + this.isRenderTarget = true; + + this.width = width; + this.height = height; + this.depth = 1; + + this.scissor = new Vector4( 0, 0, width, height ); + this.scissorTest = false; + + this.viewport = new Vector4( 0, 0, width, height ); + + const image = { width: width, height: height, depth: 1 }; + + options = Object.assign( { + generateMipmaps: false, + internalFormat: null, + minFilter: LinearFilter, + depthBuffer: true, + stencilBuffer: false, + resolveDepthBuffer: true, + resolveStencilBuffer: true, + depthTexture: null, + samples: 0, + count: 1 + }, options ); + + const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace ); + + texture.flipY = false; + texture.generateMipmaps = options.generateMipmaps; + texture.internalFormat = options.internalFormat; + + this.textures = []; + + const count = options.count; + for ( let i = 0; i < count; i ++ ) { + + this.textures[ i ] = texture.clone(); + this.textures[ i ].isRenderTargetTexture = true; + + } + + this.depthBuffer = options.depthBuffer; + this.stencilBuffer = options.stencilBuffer; + + this.resolveDepthBuffer = options.resolveDepthBuffer; + this.resolveStencilBuffer = options.resolveStencilBuffer; + + this.depthTexture = options.depthTexture; + + this.samples = options.samples; + + } + + get texture() { + + return this.textures[ 0 ]; + + } + + set texture( value ) { + + this.textures[ 0 ] = value; + + } + + setSize( width, height, depth = 1 ) { + + if ( this.width !== width || this.height !== height || this.depth !== depth ) { + + this.width = width; + this.height = height; + this.depth = depth; + + for ( let i = 0, il = this.textures.length; i < il; i ++ ) { + + this.textures[ i ].image.width = width; + this.textures[ i ].image.height = height; + this.textures[ i ].image.depth = depth; + + } + + this.dispose(); + + } + + this.viewport.set( 0, 0, width, height ); + this.scissor.set( 0, 0, width, height ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( source ) { + + this.width = source.width; + this.height = source.height; + this.depth = source.depth; + + this.scissor.copy( source.scissor ); + this.scissorTest = source.scissorTest; + + this.viewport.copy( source.viewport ); + + this.textures.length = 0; + + for ( let i = 0, il = source.textures.length; i < il; i ++ ) { + + this.textures[ i ] = source.textures[ i ].clone(); + this.textures[ i ].isRenderTargetTexture = true; + + } + + // ensure image object is not shared, see #20328 + + const image = Object.assign( {}, source.texture.image ); + this.texture.source = new Source( image ); + + this.depthBuffer = source.depthBuffer; + this.stencilBuffer = source.stencilBuffer; + + this.resolveDepthBuffer = source.resolveDepthBuffer; + this.resolveStencilBuffer = source.resolveStencilBuffer; + + if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone(); + + this.samples = source.samples; + + return this; + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + } + +} + +class WebGLRenderTarget extends RenderTarget { + + constructor( width = 1, height = 1, options = {} ) { + + super( width, height, options ); + + this.isWebGLRenderTarget = true; + + } + +} + +class DataArrayTexture extends Texture { + + constructor( data = null, width = 1, height = 1, depth = 1 ) { + + super( null ); + + this.isDataArrayTexture = true; + + this.image = { data, width, height, depth }; + + this.magFilter = NearestFilter; + this.minFilter = NearestFilter; + + this.wrapR = ClampToEdgeWrapping; + + this.generateMipmaps = false; + this.flipY = false; + this.unpackAlignment = 1; + + this.layerUpdates = new Set(); + + } + + addLayerUpdate( layerIndex ) { + + this.layerUpdates.add( layerIndex ); + + } + + clearLayerUpdates() { + + this.layerUpdates.clear(); + + } + +} + +class WebGLArrayRenderTarget extends WebGLRenderTarget { + + constructor( width = 1, height = 1, depth = 1, options = {} ) { + + super( width, height, options ); + + this.isWebGLArrayRenderTarget = true; + + this.depth = depth; + + this.texture = new DataArrayTexture( null, width, height, depth ); + + this.texture.isRenderTargetTexture = true; + + } + +} + +class Data3DTexture extends Texture { + + constructor( data = null, width = 1, height = 1, depth = 1 ) { + + // We're going to add .setXXX() methods for setting properties later. + // Users can still set in DataTexture3D directly. + // + // const texture = new THREE.DataTexture3D( data, width, height, depth ); + // texture.anisotropy = 16; + // + // See #14839 + + super( null ); + + this.isData3DTexture = true; + + this.image = { data, width, height, depth }; + + this.magFilter = NearestFilter; + this.minFilter = NearestFilter; + + this.wrapR = ClampToEdgeWrapping; + + this.generateMipmaps = false; + this.flipY = false; + this.unpackAlignment = 1; + + } + +} + +class WebGL3DRenderTarget extends WebGLRenderTarget { + + constructor( width = 1, height = 1, depth = 1, options = {} ) { + + super( width, height, options ); + + this.isWebGL3DRenderTarget = true; + + this.depth = depth; + + this.texture = new Data3DTexture( null, width, height, depth ); + + this.texture.isRenderTargetTexture = true; + + } + +} + +class Quaternion { + + constructor( x = 0, y = 0, z = 0, w = 1 ) { + + this.isQuaternion = true; + + this._x = x; + this._y = y; + this._z = z; + this._w = w; + + } + + static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) { + + // fuzz-free, array-based Quaternion SLERP operation + + let x0 = src0[ srcOffset0 + 0 ], + y0 = src0[ srcOffset0 + 1 ], + z0 = src0[ srcOffset0 + 2 ], + w0 = src0[ srcOffset0 + 3 ]; + + const x1 = src1[ srcOffset1 + 0 ], + y1 = src1[ srcOffset1 + 1 ], + z1 = src1[ srcOffset1 + 2 ], + w1 = src1[ srcOffset1 + 3 ]; + + if ( t === 0 ) { + + dst[ dstOffset + 0 ] = x0; + dst[ dstOffset + 1 ] = y0; + dst[ dstOffset + 2 ] = z0; + dst[ dstOffset + 3 ] = w0; + return; + + } + + if ( t === 1 ) { + + dst[ dstOffset + 0 ] = x1; + dst[ dstOffset + 1 ] = y1; + dst[ dstOffset + 2 ] = z1; + dst[ dstOffset + 3 ] = w1; + return; + + } + + if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) { + + let s = 1 - t; + const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, + dir = ( cos >= 0 ? 1 : - 1 ), + sqrSin = 1 - cos * cos; + + // Skip the Slerp for tiny steps to avoid numeric problems: + if ( sqrSin > Number.EPSILON ) { + + const sin = Math.sqrt( sqrSin ), + len = Math.atan2( sin, cos * dir ); + + s = Math.sin( s * len ) / sin; + t = Math.sin( t * len ) / sin; + + } + + const tDir = t * dir; + + x0 = x0 * s + x1 * tDir; + y0 = y0 * s + y1 * tDir; + z0 = z0 * s + z1 * tDir; + w0 = w0 * s + w1 * tDir; + + // Normalize in case we just did a lerp: + if ( s === 1 - t ) { + + const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 ); + + x0 *= f; + y0 *= f; + z0 *= f; + w0 *= f; + + } + + } + + dst[ dstOffset ] = x0; + dst[ dstOffset + 1 ] = y0; + dst[ dstOffset + 2 ] = z0; + dst[ dstOffset + 3 ] = w0; + + } + + static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) { + + const x0 = src0[ srcOffset0 ]; + const y0 = src0[ srcOffset0 + 1 ]; + const z0 = src0[ srcOffset0 + 2 ]; + const w0 = src0[ srcOffset0 + 3 ]; + + const x1 = src1[ srcOffset1 ]; + const y1 = src1[ srcOffset1 + 1 ]; + const z1 = src1[ srcOffset1 + 2 ]; + const w1 = src1[ srcOffset1 + 3 ]; + + dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1; + dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1; + dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1; + dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1; + + return dst; + + } + + get x() { + + return this._x; + + } + + set x( value ) { + + this._x = value; + this._onChangeCallback(); + + } + + get y() { + + return this._y; + + } + + set y( value ) { + + this._y = value; + this._onChangeCallback(); + + } + + get z() { + + return this._z; + + } + + set z( value ) { + + this._z = value; + this._onChangeCallback(); + + } + + get w() { + + return this._w; + + } + + set w( value ) { + + this._w = value; + this._onChangeCallback(); + + } + + set( x, y, z, w ) { + + this._x = x; + this._y = y; + this._z = z; + this._w = w; + + this._onChangeCallback(); + + return this; + + } + + clone() { + + return new this.constructor( this._x, this._y, this._z, this._w ); + + } + + copy( quaternion ) { + + this._x = quaternion.x; + this._y = quaternion.y; + this._z = quaternion.z; + this._w = quaternion.w; + + this._onChangeCallback(); + + return this; + + } + + setFromEuler( euler, update = true ) { + + const x = euler._x, y = euler._y, z = euler._z, order = euler._order; + + // http://www.mathworks.com/matlabcentral/fileexchange/ + // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/ + // content/SpinCalc.m + + const cos = Math.cos; + const sin = Math.sin; + + const c1 = cos( x / 2 ); + const c2 = cos( y / 2 ); + const c3 = cos( z / 2 ); + + const s1 = sin( x / 2 ); + const s2 = sin( y / 2 ); + const s3 = sin( z / 2 ); + + switch ( order ) { + + case 'XYZ': + this._x = s1 * c2 * c3 + c1 * s2 * s3; + this._y = c1 * s2 * c3 - s1 * c2 * s3; + this._z = c1 * c2 * s3 + s1 * s2 * c3; + this._w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case 'YXZ': + this._x = s1 * c2 * c3 + c1 * s2 * s3; + this._y = c1 * s2 * c3 - s1 * c2 * s3; + this._z = c1 * c2 * s3 - s1 * s2 * c3; + this._w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + case 'ZXY': + this._x = s1 * c2 * c3 - c1 * s2 * s3; + this._y = c1 * s2 * c3 + s1 * c2 * s3; + this._z = c1 * c2 * s3 + s1 * s2 * c3; + this._w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case 'ZYX': + this._x = s1 * c2 * c3 - c1 * s2 * s3; + this._y = c1 * s2 * c3 + s1 * c2 * s3; + this._z = c1 * c2 * s3 - s1 * s2 * c3; + this._w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + case 'YZX': + this._x = s1 * c2 * c3 + c1 * s2 * s3; + this._y = c1 * s2 * c3 + s1 * c2 * s3; + this._z = c1 * c2 * s3 - s1 * s2 * c3; + this._w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case 'XZY': + this._x = s1 * c2 * c3 - c1 * s2 * s3; + this._y = c1 * s2 * c3 - s1 * c2 * s3; + this._z = c1 * c2 * s3 + s1 * s2 * c3; + this._w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + default: + console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order ); + + } + + if ( update === true ) this._onChangeCallback(); + + return this; + + } + + setFromAxisAngle( axis, angle ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm + + // assumes axis is normalized + + const halfAngle = angle / 2, s = Math.sin( halfAngle ); + + this._x = axis.x * s; + this._y = axis.y * s; + this._z = axis.z * s; + this._w = Math.cos( halfAngle ); + + this._onChangeCallback(); + + return this; + + } + + setFromRotationMatrix( m ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + const te = m.elements, + + m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ], + m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ], + m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ], + + trace = m11 + m22 + m33; + + if ( trace > 0 ) { + + const s = 0.5 / Math.sqrt( trace + 1.0 ); + + this._w = 0.25 / s; + this._x = ( m32 - m23 ) * s; + this._y = ( m13 - m31 ) * s; + this._z = ( m21 - m12 ) * s; + + } else if ( m11 > m22 && m11 > m33 ) { + + const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 ); + + this._w = ( m32 - m23 ) / s; + this._x = 0.25 * s; + this._y = ( m12 + m21 ) / s; + this._z = ( m13 + m31 ) / s; + + } else if ( m22 > m33 ) { + + const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 ); + + this._w = ( m13 - m31 ) / s; + this._x = ( m12 + m21 ) / s; + this._y = 0.25 * s; + this._z = ( m23 + m32 ) / s; + + } else { + + const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 ); + + this._w = ( m21 - m12 ) / s; + this._x = ( m13 + m31 ) / s; + this._y = ( m23 + m32 ) / s; + this._z = 0.25 * s; + + } + + this._onChangeCallback(); + + return this; + + } + + setFromUnitVectors( vFrom, vTo ) { + + // assumes direction vectors vFrom and vTo are normalized + + let r = vFrom.dot( vTo ) + 1; + + if ( r < Number.EPSILON ) { + + // vFrom and vTo point in opposite directions + + r = 0; + + if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) { + + this._x = - vFrom.y; + this._y = vFrom.x; + this._z = 0; + this._w = r; + + } else { + + this._x = 0; + this._y = - vFrom.z; + this._z = vFrom.y; + this._w = r; + + } + + } else { + + // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3 + + this._x = vFrom.y * vTo.z - vFrom.z * vTo.y; + this._y = vFrom.z * vTo.x - vFrom.x * vTo.z; + this._z = vFrom.x * vTo.y - vFrom.y * vTo.x; + this._w = r; + + } + + return this.normalize(); + + } + + angleTo( q ) { + + return 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) ); + + } + + rotateTowards( q, step ) { + + const angle = this.angleTo( q ); + + if ( angle === 0 ) return this; + + const t = Math.min( 1, step / angle ); + + this.slerp( q, t ); + + return this; + + } + + identity() { + + return this.set( 0, 0, 0, 1 ); + + } + + invert() { + + // quaternion is assumed to have unit length + + return this.conjugate(); + + } + + conjugate() { + + this._x *= - 1; + this._y *= - 1; + this._z *= - 1; + + this._onChangeCallback(); + + return this; + + } + + dot( v ) { + + return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w; + + } + + lengthSq() { + + return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w; + + } + + length() { + + return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w ); + + } + + normalize() { + + let l = this.length(); + + if ( l === 0 ) { + + this._x = 0; + this._y = 0; + this._z = 0; + this._w = 1; + + } else { + + l = 1 / l; + + this._x = this._x * l; + this._y = this._y * l; + this._z = this._z * l; + this._w = this._w * l; + + } + + this._onChangeCallback(); + + return this; + + } + + multiply( q ) { + + return this.multiplyQuaternions( this, q ); + + } + + premultiply( q ) { + + return this.multiplyQuaternions( q, this ); + + } + + multiplyQuaternions( a, b ) { + + // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm + + const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w; + const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w; + + this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby; + this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz; + this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx; + this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz; + + this._onChangeCallback(); + + return this; + + } + + slerp( qb, t ) { + + if ( t === 0 ) return this; + if ( t === 1 ) return this.copy( qb ); + + const x = this._x, y = this._y, z = this._z, w = this._w; + + // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/ + + let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z; + + if ( cosHalfTheta < 0 ) { + + this._w = - qb._w; + this._x = - qb._x; + this._y = - qb._y; + this._z = - qb._z; + + cosHalfTheta = - cosHalfTheta; + + } else { + + this.copy( qb ); + + } + + if ( cosHalfTheta >= 1.0 ) { + + this._w = w; + this._x = x; + this._y = y; + this._z = z; + + return this; + + } + + const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta; + + if ( sqrSinHalfTheta <= Number.EPSILON ) { + + const s = 1 - t; + this._w = s * w + t * this._w; + this._x = s * x + t * this._x; + this._y = s * y + t * this._y; + this._z = s * z + t * this._z; + + this.normalize(); // normalize calls _onChangeCallback() + + return this; + + } + + const sinHalfTheta = Math.sqrt( sqrSinHalfTheta ); + const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta ); + const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta, + ratioB = Math.sin( t * halfTheta ) / sinHalfTheta; + + this._w = ( w * ratioA + this._w * ratioB ); + this._x = ( x * ratioA + this._x * ratioB ); + this._y = ( y * ratioA + this._y * ratioB ); + this._z = ( z * ratioA + this._z * ratioB ); + + this._onChangeCallback(); + + return this; + + } + + slerpQuaternions( qa, qb, t ) { + + return this.copy( qa ).slerp( qb, t ); + + } + + random() { + + // sets this quaternion to a uniform random unit quaternnion + + // Ken Shoemake + // Uniform random rotations + // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992. + + const theta1 = 2 * Math.PI * Math.random(); + const theta2 = 2 * Math.PI * Math.random(); + + const x0 = Math.random(); + const r1 = Math.sqrt( 1 - x0 ); + const r2 = Math.sqrt( x0 ); + + return this.set( + r1 * Math.sin( theta1 ), + r1 * Math.cos( theta1 ), + r2 * Math.sin( theta2 ), + r2 * Math.cos( theta2 ), + ); + + } + + equals( quaternion ) { + + return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w ); + + } + + fromArray( array, offset = 0 ) { + + this._x = array[ offset ]; + this._y = array[ offset + 1 ]; + this._z = array[ offset + 2 ]; + this._w = array[ offset + 3 ]; + + this._onChangeCallback(); + + return this; + + } + + toArray( array = [], offset = 0 ) { + + array[ offset ] = this._x; + array[ offset + 1 ] = this._y; + array[ offset + 2 ] = this._z; + array[ offset + 3 ] = this._w; + + return array; + + } + + fromBufferAttribute( attribute, index ) { + + this._x = attribute.getX( index ); + this._y = attribute.getY( index ); + this._z = attribute.getZ( index ); + this._w = attribute.getW( index ); + + this._onChangeCallback(); + + return this; + + } + + toJSON() { + + return this.toArray(); + + } + + _onChange( callback ) { + + this._onChangeCallback = callback; + + return this; + + } + + _onChangeCallback() {} + + *[ Symbol.iterator ]() { + + yield this._x; + yield this._y; + yield this._z; + yield this._w; + + } + +} + +class Vector3 { + + constructor( x = 0, y = 0, z = 0 ) { + + Vector3.prototype.isVector3 = true; + + this.x = x; + this.y = y; + this.z = z; + + } + + set( x, y, z ) { + + if ( z === undefined ) z = this.z; // sprite.scale.set(x,y) + + this.x = x; + this.y = y; + this.z = z; + + return this; + + } + + setScalar( scalar ) { + + this.x = scalar; + this.y = scalar; + this.z = scalar; + + return this; + + } + + setX( x ) { + + this.x = x; + + return this; + + } + + setY( y ) { + + this.y = y; + + return this; + + } + + setZ( z ) { + + this.z = z; + + return this; + + } + + setComponent( index, value ) { + + switch ( index ) { + + case 0: this.x = value; break; + case 1: this.y = value; break; + case 2: this.z = value; break; + default: throw new Error( 'index is out of range: ' + index ); + + } + + return this; + + } + + getComponent( index ) { + + switch ( index ) { + + case 0: return this.x; + case 1: return this.y; + case 2: return this.z; + default: throw new Error( 'index is out of range: ' + index ); + + } + + } + + clone() { + + return new this.constructor( this.x, this.y, this.z ); + + } + + copy( v ) { + + this.x = v.x; + this.y = v.y; + this.z = v.z; + + return this; + + } + + add( v ) { + + this.x += v.x; + this.y += v.y; + this.z += v.z; + + return this; + + } + + addScalar( s ) { + + this.x += s; + this.y += s; + this.z += s; + + return this; + + } + + addVectors( a, b ) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + this.z = a.z + b.z; + + return this; + + } + + addScaledVector( v, s ) { + + this.x += v.x * s; + this.y += v.y * s; + this.z += v.z * s; + + return this; + + } + + sub( v ) { + + this.x -= v.x; + this.y -= v.y; + this.z -= v.z; + + return this; + + } + + subScalar( s ) { + + this.x -= s; + this.y -= s; + this.z -= s; + + return this; + + } + + subVectors( a, b ) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + this.z = a.z - b.z; + + return this; + + } + + multiply( v ) { + + this.x *= v.x; + this.y *= v.y; + this.z *= v.z; + + return this; + + } + + multiplyScalar( scalar ) { + + this.x *= scalar; + this.y *= scalar; + this.z *= scalar; + + return this; + + } + + multiplyVectors( a, b ) { + + this.x = a.x * b.x; + this.y = a.y * b.y; + this.z = a.z * b.z; + + return this; + + } + + applyEuler( euler ) { + + return this.applyQuaternion( _quaternion$4.setFromEuler( euler ) ); + + } + + applyAxisAngle( axis, angle ) { + + return this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) ); + + } + + applyMatrix3( m ) { + + const x = this.x, y = this.y, z = this.z; + const e = m.elements; + + this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z; + this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z; + this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z; + + return this; + + } + + applyNormalMatrix( m ) { + + return this.applyMatrix3( m ).normalize(); + + } + + applyMatrix4( m ) { + + const x = this.x, y = this.y, z = this.z; + const e = m.elements; + + const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); + + this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w; + this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w; + this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w; + + return this; + + } + + applyQuaternion( q ) { + + // quaternion q is assumed to have unit length + + const vx = this.x, vy = this.y, vz = this.z; + const qx = q.x, qy = q.y, qz = q.z, qw = q.w; + + // t = 2 * cross( q.xyz, v ); + const tx = 2 * ( qy * vz - qz * vy ); + const ty = 2 * ( qz * vx - qx * vz ); + const tz = 2 * ( qx * vy - qy * vx ); + + // v + q.w * t + cross( q.xyz, t ); + this.x = vx + qw * tx + qy * tz - qz * ty; + this.y = vy + qw * ty + qz * tx - qx * tz; + this.z = vz + qw * tz + qx * ty - qy * tx; + + return this; + + } + + project( camera ) { + + return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix ); + + } + + unproject( camera ) { + + return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld ); + + } + + transformDirection( m ) { + + // input: THREE.Matrix4 affine matrix + // vector interpreted as a direction + + const x = this.x, y = this.y, z = this.z; + const e = m.elements; + + this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z; + this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z; + this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z; + + return this.normalize(); + + } + + divide( v ) { + + this.x /= v.x; + this.y /= v.y; + this.z /= v.z; + + return this; + + } + + divideScalar( scalar ) { + + return this.multiplyScalar( 1 / scalar ); + + } + + min( v ) { + + this.x = Math.min( this.x, v.x ); + this.y = Math.min( this.y, v.y ); + this.z = Math.min( this.z, v.z ); + + return this; + + } + + max( v ) { + + this.x = Math.max( this.x, v.x ); + this.y = Math.max( this.y, v.y ); + this.z = Math.max( this.z, v.z ); + + return this; + + } + + clamp( min, max ) { + + // assumes min < max, componentwise + + this.x = clamp( this.x, min.x, max.x ); + this.y = clamp( this.y, min.y, max.y ); + this.z = clamp( this.z, min.z, max.z ); + + return this; + + } + + clampScalar( minVal, maxVal ) { + + this.x = clamp( this.x, minVal, maxVal ); + this.y = clamp( this.y, minVal, maxVal ); + this.z = clamp( this.z, minVal, maxVal ); + + return this; + + } + + clampLength( min, max ) { + + const length = this.length(); + + return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) ); + + } + + floor() { + + this.x = Math.floor( this.x ); + this.y = Math.floor( this.y ); + this.z = Math.floor( this.z ); + + return this; + + } + + ceil() { + + this.x = Math.ceil( this.x ); + this.y = Math.ceil( this.y ); + this.z = Math.ceil( this.z ); + + return this; + + } + + round() { + + this.x = Math.round( this.x ); + this.y = Math.round( this.y ); + this.z = Math.round( this.z ); + + return this; + + } + + roundToZero() { + + this.x = Math.trunc( this.x ); + this.y = Math.trunc( this.y ); + this.z = Math.trunc( this.z ); + + return this; + + } + + negate() { + + this.x = - this.x; + this.y = - this.y; + this.z = - this.z; + + return this; + + } + + dot( v ) { + + return this.x * v.x + this.y * v.y + this.z * v.z; + + } + + // TODO lengthSquared? + + lengthSq() { + + return this.x * this.x + this.y * this.y + this.z * this.z; + + } + + length() { + + return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z ); + + } + + manhattanLength() { + + return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ); + + } + + normalize() { + + return this.divideScalar( this.length() || 1 ); + + } + + setLength( length ) { + + return this.normalize().multiplyScalar( length ); + + } + + lerp( v, alpha ) { + + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + this.z += ( v.z - this.z ) * alpha; + + return this; + + } + + lerpVectors( v1, v2, alpha ) { + + this.x = v1.x + ( v2.x - v1.x ) * alpha; + this.y = v1.y + ( v2.y - v1.y ) * alpha; + this.z = v1.z + ( v2.z - v1.z ) * alpha; + + return this; + + } + + cross( v ) { + + return this.crossVectors( this, v ); + + } + + crossVectors( a, b ) { + + const ax = a.x, ay = a.y, az = a.z; + const bx = b.x, by = b.y, bz = b.z; + + this.x = ay * bz - az * by; + this.y = az * bx - ax * bz; + this.z = ax * by - ay * bx; + + return this; + + } + + projectOnVector( v ) { + + const denominator = v.lengthSq(); + + if ( denominator === 0 ) return this.set( 0, 0, 0 ); + + const scalar = v.dot( this ) / denominator; + + return this.copy( v ).multiplyScalar( scalar ); + + } + + projectOnPlane( planeNormal ) { + + _vector$c.copy( this ).projectOnVector( planeNormal ); + + return this.sub( _vector$c ); + + } + + reflect( normal ) { + + // reflect incident vector off plane orthogonal to normal + // normal is assumed to have unit length + + return this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) ); + + } + + angleTo( v ) { + + const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() ); + + if ( denominator === 0 ) return Math.PI / 2; + + const theta = this.dot( v ) / denominator; + + // clamp, to handle numerical problems + + return Math.acos( clamp( theta, - 1, 1 ) ); + + } + + distanceTo( v ) { + + return Math.sqrt( this.distanceToSquared( v ) ); + + } + + distanceToSquared( v ) { + + const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z; + + return dx * dx + dy * dy + dz * dz; + + } + + manhattanDistanceTo( v ) { + + return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z ); + + } + + setFromSpherical( s ) { + + return this.setFromSphericalCoords( s.radius, s.phi, s.theta ); + + } + + setFromSphericalCoords( radius, phi, theta ) { + + const sinPhiRadius = Math.sin( phi ) * radius; + + this.x = sinPhiRadius * Math.sin( theta ); + this.y = Math.cos( phi ) * radius; + this.z = sinPhiRadius * Math.cos( theta ); + + return this; + + } + + setFromCylindrical( c ) { + + return this.setFromCylindricalCoords( c.radius, c.theta, c.y ); + + } + + setFromCylindricalCoords( radius, theta, y ) { + + this.x = radius * Math.sin( theta ); + this.y = y; + this.z = radius * Math.cos( theta ); + + return this; + + } + + setFromMatrixPosition( m ) { + + const e = m.elements; + + this.x = e[ 12 ]; + this.y = e[ 13 ]; + this.z = e[ 14 ]; + + return this; + + } + + setFromMatrixScale( m ) { + + const sx = this.setFromMatrixColumn( m, 0 ).length(); + const sy = this.setFromMatrixColumn( m, 1 ).length(); + const sz = this.setFromMatrixColumn( m, 2 ).length(); + + this.x = sx; + this.y = sy; + this.z = sz; + + return this; + + } + + setFromMatrixColumn( m, index ) { + + return this.fromArray( m.elements, index * 4 ); + + } + + setFromMatrix3Column( m, index ) { + + return this.fromArray( m.elements, index * 3 ); + + } + + setFromEuler( e ) { + + this.x = e._x; + this.y = e._y; + this.z = e._z; + + return this; + + } + + setFromColor( c ) { + + this.x = c.r; + this.y = c.g; + this.z = c.b; + + return this; + + } + + equals( v ) { + + return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) ); + + } + + fromArray( array, offset = 0 ) { + + this.x = array[ offset ]; + this.y = array[ offset + 1 ]; + this.z = array[ offset + 2 ]; + + return this; + + } + + toArray( array = [], offset = 0 ) { + + array[ offset ] = this.x; + array[ offset + 1 ] = this.y; + array[ offset + 2 ] = this.z; + + return array; + + } + + fromBufferAttribute( attribute, index ) { + + this.x = attribute.getX( index ); + this.y = attribute.getY( index ); + this.z = attribute.getZ( index ); + + return this; + + } + + random() { + + this.x = Math.random(); + this.y = Math.random(); + this.z = Math.random(); + + return this; + + } + + randomDirection() { + + // https://mathworld.wolfram.com/SpherePointPicking.html + + const theta = Math.random() * Math.PI * 2; + const u = Math.random() * 2 - 1; + const c = Math.sqrt( 1 - u * u ); + + this.x = c * Math.cos( theta ); + this.y = u; + this.z = c * Math.sin( theta ); + + return this; + + } + + *[ Symbol.iterator ]() { + + yield this.x; + yield this.y; + yield this.z; + + } + +} + +const _vector$c = /*@__PURE__*/ new Vector3(); +const _quaternion$4 = /*@__PURE__*/ new Quaternion(); + +class Box3 { + + constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) { + + this.isBox3 = true; + + this.min = min; + this.max = max; + + } + + set( min, max ) { + + this.min.copy( min ); + this.max.copy( max ); + + return this; + + } + + setFromArray( array ) { + + this.makeEmpty(); + + for ( let i = 0, il = array.length; i < il; i += 3 ) { + + this.expandByPoint( _vector$b.fromArray( array, i ) ); + + } + + return this; + + } + + setFromBufferAttribute( attribute ) { + + this.makeEmpty(); + + for ( let i = 0, il = attribute.count; i < il; i ++ ) { + + this.expandByPoint( _vector$b.fromBufferAttribute( attribute, i ) ); + + } + + return this; + + } + + setFromPoints( points ) { + + this.makeEmpty(); + + for ( let i = 0, il = points.length; i < il; i ++ ) { + + this.expandByPoint( points[ i ] ); + + } + + return this; + + } + + setFromCenterAndSize( center, size ) { + + const halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 ); + + this.min.copy( center ).sub( halfSize ); + this.max.copy( center ).add( halfSize ); + + return this; + + } + + setFromObject( object, precise = false ) { + + this.makeEmpty(); + + return this.expandByObject( object, precise ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( box ) { + + this.min.copy( box.min ); + this.max.copy( box.max ); + + return this; + + } + + makeEmpty() { + + this.min.x = this.min.y = this.min.z = + Infinity; + this.max.x = this.max.y = this.max.z = - Infinity; + + return this; + + } + + isEmpty() { + + // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes + + return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z ); + + } + + getCenter( target ) { + + return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 ); + + } + + getSize( target ) { + + return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min ); + + } + + expandByPoint( point ) { + + this.min.min( point ); + this.max.max( point ); + + return this; + + } + + expandByVector( vector ) { + + this.min.sub( vector ); + this.max.add( vector ); + + return this; + + } + + expandByScalar( scalar ) { + + this.min.addScalar( - scalar ); + this.max.addScalar( scalar ); + + return this; + + } + + expandByObject( object, precise = false ) { + + // Computes the world-axis-aligned bounding box of an object (including its children), + // accounting for both the object's, and children's, world transforms + + object.updateWorldMatrix( false, false ); + + const geometry = object.geometry; + + if ( geometry !== undefined ) { + + const positionAttribute = geometry.getAttribute( 'position' ); + + // precise AABB computation based on vertex data requires at least a position attribute. + // instancing isn't supported so far and uses the normal (conservative) code path. + + if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) { + + for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) { + + if ( object.isMesh === true ) { + + object.getVertexPosition( i, _vector$b ); + + } else { + + _vector$b.fromBufferAttribute( positionAttribute, i ); + + } + + _vector$b.applyMatrix4( object.matrixWorld ); + this.expandByPoint( _vector$b ); + + } + + } else { + + if ( object.boundingBox !== undefined ) { + + // object-level bounding box + + if ( object.boundingBox === null ) { + + object.computeBoundingBox(); + + } + + _box$4.copy( object.boundingBox ); + + + } else { + + // geometry-level bounding box + + if ( geometry.boundingBox === null ) { + + geometry.computeBoundingBox(); + + } + + _box$4.copy( geometry.boundingBox ); + + } + + _box$4.applyMatrix4( object.matrixWorld ); + + this.union( _box$4 ); + + } + + } + + const children = object.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + this.expandByObject( children[ i ], precise ); + + } + + return this; + + } + + containsPoint( point ) { + + return point.x >= this.min.x && point.x <= this.max.x && + point.y >= this.min.y && point.y <= this.max.y && + point.z >= this.min.z && point.z <= this.max.z; + + } + + containsBox( box ) { + + return this.min.x <= box.min.x && box.max.x <= this.max.x && + this.min.y <= box.min.y && box.max.y <= this.max.y && + this.min.z <= box.min.z && box.max.z <= this.max.z; + + } + + getParameter( point, target ) { + + // This can potentially have a divide by zero if the box + // has a size dimension of 0. + + return target.set( + ( point.x - this.min.x ) / ( this.max.x - this.min.x ), + ( point.y - this.min.y ) / ( this.max.y - this.min.y ), + ( point.z - this.min.z ) / ( this.max.z - this.min.z ) + ); + + } + + intersectsBox( box ) { + + // using 6 splitting planes to rule out intersections. + return box.max.x >= this.min.x && box.min.x <= this.max.x && + box.max.y >= this.min.y && box.min.y <= this.max.y && + box.max.z >= this.min.z && box.min.z <= this.max.z; + + } + + intersectsSphere( sphere ) { + + // Find the point on the AABB closest to the sphere center. + this.clampPoint( sphere.center, _vector$b ); + + // If that point is inside the sphere, the AABB and sphere intersect. + return _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius ); + + } + + intersectsPlane( plane ) { + + // We compute the minimum and maximum dot product values. If those values + // are on the same side (back or front) of the plane, then there is no intersection. + + let min, max; + + if ( plane.normal.x > 0 ) { + + min = plane.normal.x * this.min.x; + max = plane.normal.x * this.max.x; + + } else { + + min = plane.normal.x * this.max.x; + max = plane.normal.x * this.min.x; + + } + + if ( plane.normal.y > 0 ) { + + min += plane.normal.y * this.min.y; + max += plane.normal.y * this.max.y; + + } else { + + min += plane.normal.y * this.max.y; + max += plane.normal.y * this.min.y; + + } + + if ( plane.normal.z > 0 ) { + + min += plane.normal.z * this.min.z; + max += plane.normal.z * this.max.z; + + } else { + + min += plane.normal.z * this.max.z; + max += plane.normal.z * this.min.z; + + } + + return ( min <= - plane.constant && max >= - plane.constant ); + + } + + intersectsTriangle( triangle ) { + + if ( this.isEmpty() ) { + + return false; + + } + + // compute box center and extents + this.getCenter( _center ); + _extents.subVectors( this.max, _center ); + + // translate triangle to aabb origin + _v0$2.subVectors( triangle.a, _center ); + _v1$7.subVectors( triangle.b, _center ); + _v2$4.subVectors( triangle.c, _center ); + + // compute edge vectors for triangle + _f0.subVectors( _v1$7, _v0$2 ); + _f1.subVectors( _v2$4, _v1$7 ); + _f2.subVectors( _v0$2, _v2$4 ); + + // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb + // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation + // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned) + let axes = [ + 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y, + _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x, + - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0 + ]; + if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) { + + return false; + + } + + // test 3 face normals from the aabb + axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]; + if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) { + + return false; + + } + + // finally testing the face normal of the triangle + // use already existing triangle edge vectors here + _triangleNormal.crossVectors( _f0, _f1 ); + axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ]; + + return satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ); + + } + + clampPoint( point, target ) { + + return target.copy( point ).clamp( this.min, this.max ); + + } + + distanceToPoint( point ) { + + return this.clampPoint( point, _vector$b ).distanceTo( point ); + + } + + getBoundingSphere( target ) { + + if ( this.isEmpty() ) { + + target.makeEmpty(); + + } else { + + this.getCenter( target.center ); + + target.radius = this.getSize( _vector$b ).length() * 0.5; + + } + + return target; + + } + + intersect( box ) { + + this.min.max( box.min ); + this.max.min( box.max ); + + // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values. + if ( this.isEmpty() ) this.makeEmpty(); + + return this; + + } + + union( box ) { + + this.min.min( box.min ); + this.max.max( box.max ); + + return this; + + } + + applyMatrix4( matrix ) { + + // transform of empty box is an empty box. + if ( this.isEmpty() ) return this; + + // NOTE: I am using a binary pattern to specify all 2^3 combinations below + _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000 + _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001 + _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010 + _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011 + _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100 + _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101 + _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110 + _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111 + + this.setFromPoints( _points ); + + return this; + + } + + translate( offset ) { + + this.min.add( offset ); + this.max.add( offset ); + + return this; + + } + + equals( box ) { + + return box.min.equals( this.min ) && box.max.equals( this.max ); + + } + +} + +const _points = [ + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3(), + /*@__PURE__*/ new Vector3() +]; + +const _vector$b = /*@__PURE__*/ new Vector3(); + +const _box$4 = /*@__PURE__*/ new Box3(); + +// triangle centered vertices + +const _v0$2 = /*@__PURE__*/ new Vector3(); +const _v1$7 = /*@__PURE__*/ new Vector3(); +const _v2$4 = /*@__PURE__*/ new Vector3(); + +// triangle edge vectors + +const _f0 = /*@__PURE__*/ new Vector3(); +const _f1 = /*@__PURE__*/ new Vector3(); +const _f2 = /*@__PURE__*/ new Vector3(); + +const _center = /*@__PURE__*/ new Vector3(); +const _extents = /*@__PURE__*/ new Vector3(); +const _triangleNormal = /*@__PURE__*/ new Vector3(); +const _testAxis = /*@__PURE__*/ new Vector3(); + +function satForAxes( axes, v0, v1, v2, extents ) { + + for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) { + + _testAxis.fromArray( axes, i ); + // project the aabb onto the separating axis + const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z ); + // project all 3 vertices of the triangle onto the separating axis + const p0 = v0.dot( _testAxis ); + const p1 = v1.dot( _testAxis ); + const p2 = v2.dot( _testAxis ); + // actual test, basically see if either of the most extreme of the triangle points intersects r + if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) { + + // points of the projected triangle are outside the projected half-length of the aabb + // the axis is separating and we can exit + return false; + + } + + } + + return true; + +} + +const _box$3 = /*@__PURE__*/ new Box3(); +const _v1$6 = /*@__PURE__*/ new Vector3(); +const _v2$3 = /*@__PURE__*/ new Vector3(); + +class Sphere { + + constructor( center = new Vector3(), radius = - 1 ) { + + this.isSphere = true; + + this.center = center; + this.radius = radius; + + } + + set( center, radius ) { + + this.center.copy( center ); + this.radius = radius; + + return this; + + } + + setFromPoints( points, optionalCenter ) { + + const center = this.center; + + if ( optionalCenter !== undefined ) { + + center.copy( optionalCenter ); + + } else { + + _box$3.setFromPoints( points ).getCenter( center ); + + } + + let maxRadiusSq = 0; + + for ( let i = 0, il = points.length; i < il; i ++ ) { + + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) ); + + } + + this.radius = Math.sqrt( maxRadiusSq ); + + return this; + + } + + copy( sphere ) { + + this.center.copy( sphere.center ); + this.radius = sphere.radius; + + return this; + + } + + isEmpty() { + + return ( this.radius < 0 ); + + } + + makeEmpty() { + + this.center.set( 0, 0, 0 ); + this.radius = - 1; + + return this; + + } + + containsPoint( point ) { + + return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) ); + + } + + distanceToPoint( point ) { + + return ( point.distanceTo( this.center ) - this.radius ); + + } + + intersectsSphere( sphere ) { + + const radiusSum = this.radius + sphere.radius; + + return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum ); + + } + + intersectsBox( box ) { + + return box.intersectsSphere( this ); + + } + + intersectsPlane( plane ) { + + return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius; + + } + + clampPoint( point, target ) { + + const deltaLengthSq = this.center.distanceToSquared( point ); + + target.copy( point ); + + if ( deltaLengthSq > ( this.radius * this.radius ) ) { + + target.sub( this.center ).normalize(); + target.multiplyScalar( this.radius ).add( this.center ); + + } + + return target; + + } + + getBoundingBox( target ) { + + if ( this.isEmpty() ) { + + // Empty sphere produces empty bounding box + target.makeEmpty(); + return target; + + } + + target.set( this.center, this.center ); + target.expandByScalar( this.radius ); + + return target; + + } + + applyMatrix4( matrix ) { + + this.center.applyMatrix4( matrix ); + this.radius = this.radius * matrix.getMaxScaleOnAxis(); + + return this; + + } + + translate( offset ) { + + this.center.add( offset ); + + return this; + + } + + expandByPoint( point ) { + + if ( this.isEmpty() ) { + + this.center.copy( point ); + + this.radius = 0; + + return this; + + } + + _v1$6.subVectors( point, this.center ); + + const lengthSq = _v1$6.lengthSq(); + + if ( lengthSq > ( this.radius * this.radius ) ) { + + // calculate the minimal sphere + + const length = Math.sqrt( lengthSq ); + + const delta = ( length - this.radius ) * 0.5; + + this.center.addScaledVector( _v1$6, delta / length ); + + this.radius += delta; + + } + + return this; + + } + + union( sphere ) { + + if ( sphere.isEmpty() ) { + + return this; + + } + + if ( this.isEmpty() ) { + + this.copy( sphere ); + + return this; + + } + + if ( this.center.equals( sphere.center ) === true ) { + + this.radius = Math.max( this.radius, sphere.radius ); + + } else { + + _v2$3.subVectors( sphere.center, this.center ).setLength( sphere.radius ); + + this.expandByPoint( _v1$6.copy( sphere.center ).add( _v2$3 ) ); + + this.expandByPoint( _v1$6.copy( sphere.center ).sub( _v2$3 ) ); + + } + + return this; + + } + + equals( sphere ) { + + return sphere.center.equals( this.center ) && ( sphere.radius === this.radius ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +const _vector$a = /*@__PURE__*/ new Vector3(); +const _segCenter = /*@__PURE__*/ new Vector3(); +const _segDir = /*@__PURE__*/ new Vector3(); +const _diff = /*@__PURE__*/ new Vector3(); + +const _edge1 = /*@__PURE__*/ new Vector3(); +const _edge2 = /*@__PURE__*/ new Vector3(); +const _normal$1 = /*@__PURE__*/ new Vector3(); + +class Ray { + + constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) { + + this.origin = origin; + this.direction = direction; + + } + + set( origin, direction ) { + + this.origin.copy( origin ); + this.direction.copy( direction ); + + return this; + + } + + copy( ray ) { + + this.origin.copy( ray.origin ); + this.direction.copy( ray.direction ); + + return this; + + } + + at( t, target ) { + + return target.copy( this.origin ).addScaledVector( this.direction, t ); + + } + + lookAt( v ) { + + this.direction.copy( v ).sub( this.origin ).normalize(); + + return this; + + } + + recast( t ) { + + this.origin.copy( this.at( t, _vector$a ) ); + + return this; + + } + + closestPointToPoint( point, target ) { + + target.subVectors( point, this.origin ); + + const directionDistance = target.dot( this.direction ); + + if ( directionDistance < 0 ) { + + return target.copy( this.origin ); + + } + + return target.copy( this.origin ).addScaledVector( this.direction, directionDistance ); + + } + + distanceToPoint( point ) { + + return Math.sqrt( this.distanceSqToPoint( point ) ); + + } + + distanceSqToPoint( point ) { + + const directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction ); + + // point behind the ray + + if ( directionDistance < 0 ) { + + return this.origin.distanceToSquared( point ); + + } + + _vector$a.copy( this.origin ).addScaledVector( this.direction, directionDistance ); + + return _vector$a.distanceToSquared( point ); + + } + + distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) { + + // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h + // It returns the min distance between the ray and the segment + // defined by v0 and v1 + // It can also set two optional targets : + // - The closest point on the ray + // - The closest point on the segment + + _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 ); + _segDir.copy( v1 ).sub( v0 ).normalize(); + _diff.copy( this.origin ).sub( _segCenter ); + + const segExtent = v0.distanceTo( v1 ) * 0.5; + const a01 = - this.direction.dot( _segDir ); + const b0 = _diff.dot( this.direction ); + const b1 = - _diff.dot( _segDir ); + const c = _diff.lengthSq(); + const det = Math.abs( 1 - a01 * a01 ); + let s0, s1, sqrDist, extDet; + + if ( det > 0 ) { + + // The ray and segment are not parallel. + + s0 = a01 * b1 - b0; + s1 = a01 * b0 - b1; + extDet = segExtent * det; + + if ( s0 >= 0 ) { + + if ( s1 >= - extDet ) { + + if ( s1 <= extDet ) { + + // region 0 + // Minimum at interior points of ray and segment. + + const invDet = 1 / det; + s0 *= invDet; + s1 *= invDet; + sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c; + + } else { + + // region 1 + + s1 = segExtent; + s0 = Math.max( 0, - ( a01 * s1 + b0 ) ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + } else { + + // region 5 + + s1 = - segExtent; + s0 = Math.max( 0, - ( a01 * s1 + b0 ) ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + } else { + + if ( s1 <= - extDet ) { + + // region 4 + + s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) ); + s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } else if ( s1 <= extDet ) { + + // region 3 + + s0 = 0; + s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent ); + sqrDist = s1 * ( s1 + 2 * b1 ) + c; + + } else { + + // region 2 + + s0 = Math.max( 0, - ( a01 * segExtent + b0 ) ); + s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + } + + } else { + + // Ray and segment are parallel. + + s1 = ( a01 > 0 ) ? - segExtent : segExtent; + s0 = Math.max( 0, - ( a01 * s1 + b0 ) ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + if ( optionalPointOnRay ) { + + optionalPointOnRay.copy( this.origin ).addScaledVector( this.direction, s0 ); + + } + + if ( optionalPointOnSegment ) { + + optionalPointOnSegment.copy( _segCenter ).addScaledVector( _segDir, s1 ); + + } + + return sqrDist; + + } + + intersectSphere( sphere, target ) { + + _vector$a.subVectors( sphere.center, this.origin ); + const tca = _vector$a.dot( this.direction ); + const d2 = _vector$a.dot( _vector$a ) - tca * tca; + const radius2 = sphere.radius * sphere.radius; + + if ( d2 > radius2 ) return null; + + const thc = Math.sqrt( radius2 - d2 ); + + // t0 = first intersect point - entrance on front of sphere + const t0 = tca - thc; + + // t1 = second intersect point - exit point on back of sphere + const t1 = tca + thc; + + // test to see if t1 is behind the ray - if so, return null + if ( t1 < 0 ) return null; + + // test to see if t0 is behind the ray: + // if it is, the ray is inside the sphere, so return the second exit point scaled by t1, + // in order to always return an intersect point that is in front of the ray. + if ( t0 < 0 ) return this.at( t1, target ); + + // else t0 is in front of the ray, so return the first collision point scaled by t0 + return this.at( t0, target ); + + } + + intersectsSphere( sphere ) { + + return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius ); + + } + + distanceToPlane( plane ) { + + const denominator = plane.normal.dot( this.direction ); + + if ( denominator === 0 ) { + + // line is coplanar, return origin + if ( plane.distanceToPoint( this.origin ) === 0 ) { + + return 0; + + } + + // Null is preferable to undefined since undefined means.... it is undefined + + return null; + + } + + const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator; + + // Return if the ray never intersects the plane + + return t >= 0 ? t : null; + + } + + intersectPlane( plane, target ) { + + const t = this.distanceToPlane( plane ); + + if ( t === null ) { + + return null; + + } + + return this.at( t, target ); + + } + + intersectsPlane( plane ) { + + // check if the ray lies on the plane first + + const distToPoint = plane.distanceToPoint( this.origin ); + + if ( distToPoint === 0 ) { + + return true; + + } + + const denominator = plane.normal.dot( this.direction ); + + if ( denominator * distToPoint < 0 ) { + + return true; + + } + + // ray origin is behind the plane (and is pointing behind it) + + return false; + + } + + intersectBox( box, target ) { + + let tmin, tmax, tymin, tymax, tzmin, tzmax; + + const invdirx = 1 / this.direction.x, + invdiry = 1 / this.direction.y, + invdirz = 1 / this.direction.z; + + const origin = this.origin; + + if ( invdirx >= 0 ) { + + tmin = ( box.min.x - origin.x ) * invdirx; + tmax = ( box.max.x - origin.x ) * invdirx; + + } else { + + tmin = ( box.max.x - origin.x ) * invdirx; + tmax = ( box.min.x - origin.x ) * invdirx; + + } + + if ( invdiry >= 0 ) { + + tymin = ( box.min.y - origin.y ) * invdiry; + tymax = ( box.max.y - origin.y ) * invdiry; + + } else { + + tymin = ( box.max.y - origin.y ) * invdiry; + tymax = ( box.min.y - origin.y ) * invdiry; + + } + + if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null; + + if ( tymin > tmin || isNaN( tmin ) ) tmin = tymin; + + if ( tymax < tmax || isNaN( tmax ) ) tmax = tymax; + + if ( invdirz >= 0 ) { + + tzmin = ( box.min.z - origin.z ) * invdirz; + tzmax = ( box.max.z - origin.z ) * invdirz; + + } else { + + tzmin = ( box.max.z - origin.z ) * invdirz; + tzmax = ( box.min.z - origin.z ) * invdirz; + + } + + if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null; + + if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin; + + if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax; + + //return point closest to the ray (positive side) + + if ( tmax < 0 ) return null; + + return this.at( tmin >= 0 ? tmin : tmax, target ); + + } + + intersectsBox( box ) { + + return this.intersectBox( box, _vector$a ) !== null; + + } + + intersectTriangle( a, b, c, backfaceCulling, target ) { + + // Compute the offset origin, edges, and normal. + + // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h + + _edge1.subVectors( b, a ); + _edge2.subVectors( c, a ); + _normal$1.crossVectors( _edge1, _edge2 ); + + // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction, + // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by + // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2)) + // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q)) + // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N) + let DdN = this.direction.dot( _normal$1 ); + let sign; + + if ( DdN > 0 ) { + + if ( backfaceCulling ) return null; + sign = 1; + + } else if ( DdN < 0 ) { + + sign = - 1; + DdN = - DdN; + + } else { + + return null; + + } + + _diff.subVectors( this.origin, a ); + const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) ); + + // b1 < 0, no intersection + if ( DdQxE2 < 0 ) { + + return null; + + } + + const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) ); + + // b2 < 0, no intersection + if ( DdE1xQ < 0 ) { + + return null; + + } + + // b1+b2 > 1, no intersection + if ( DdQxE2 + DdE1xQ > DdN ) { + + return null; + + } + + // Line intersects triangle, check if ray does. + const QdN = - sign * _diff.dot( _normal$1 ); + + // t < 0, no intersection + if ( QdN < 0 ) { + + return null; + + } + + // Ray intersects triangle. + return this.at( QdN / DdN, target ); + + } + + applyMatrix4( matrix4 ) { + + this.origin.applyMatrix4( matrix4 ); + this.direction.transformDirection( matrix4 ); + + return this; + + } + + equals( ray ) { + + return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +class Matrix4 { + + constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { + + Matrix4.prototype.isMatrix4 = true; + + this.elements = [ + + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + + ]; + + if ( n11 !== undefined ) { + + this.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ); + + } + + } + + set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { + + const te = this.elements; + + te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14; + te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24; + te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34; + te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44; + + return this; + + } + + identity() { + + this.set( + + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + clone() { + + return new Matrix4().fromArray( this.elements ); + + } + + copy( m ) { + + const te = this.elements; + const me = m.elements; + + te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ]; + te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; + te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ]; + te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ]; + + return this; + + } + + copyPosition( m ) { + + const te = this.elements, me = m.elements; + + te[ 12 ] = me[ 12 ]; + te[ 13 ] = me[ 13 ]; + te[ 14 ] = me[ 14 ]; + + return this; + + } + + setFromMatrix3( m ) { + + const me = m.elements; + + this.set( + + me[ 0 ], me[ 3 ], me[ 6 ], 0, + me[ 1 ], me[ 4 ], me[ 7 ], 0, + me[ 2 ], me[ 5 ], me[ 8 ], 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + extractBasis( xAxis, yAxis, zAxis ) { + + xAxis.setFromMatrixColumn( this, 0 ); + yAxis.setFromMatrixColumn( this, 1 ); + zAxis.setFromMatrixColumn( this, 2 ); + + return this; + + } + + makeBasis( xAxis, yAxis, zAxis ) { + + this.set( + xAxis.x, yAxis.x, zAxis.x, 0, + xAxis.y, yAxis.y, zAxis.y, 0, + xAxis.z, yAxis.z, zAxis.z, 0, + 0, 0, 0, 1 + ); + + return this; + + } + + extractRotation( m ) { + + // this method does not support reflection matrices + + const te = this.elements; + const me = m.elements; + + const scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length(); + const scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length(); + const scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length(); + + te[ 0 ] = me[ 0 ] * scaleX; + te[ 1 ] = me[ 1 ] * scaleX; + te[ 2 ] = me[ 2 ] * scaleX; + te[ 3 ] = 0; + + te[ 4 ] = me[ 4 ] * scaleY; + te[ 5 ] = me[ 5 ] * scaleY; + te[ 6 ] = me[ 6 ] * scaleY; + te[ 7 ] = 0; + + te[ 8 ] = me[ 8 ] * scaleZ; + te[ 9 ] = me[ 9 ] * scaleZ; + te[ 10 ] = me[ 10 ] * scaleZ; + te[ 11 ] = 0; + + te[ 12 ] = 0; + te[ 13 ] = 0; + te[ 14 ] = 0; + te[ 15 ] = 1; + + return this; + + } + + makeRotationFromEuler( euler ) { + + const te = this.elements; + + const x = euler.x, y = euler.y, z = euler.z; + const a = Math.cos( x ), b = Math.sin( x ); + const c = Math.cos( y ), d = Math.sin( y ); + const e = Math.cos( z ), f = Math.sin( z ); + + if ( euler.order === 'XYZ' ) { + + const ae = a * e, af = a * f, be = b * e, bf = b * f; + + te[ 0 ] = c * e; + te[ 4 ] = - c * f; + te[ 8 ] = d; + + te[ 1 ] = af + be * d; + te[ 5 ] = ae - bf * d; + te[ 9 ] = - b * c; + + te[ 2 ] = bf - ae * d; + te[ 6 ] = be + af * d; + te[ 10 ] = a * c; + + } else if ( euler.order === 'YXZ' ) { + + const ce = c * e, cf = c * f, de = d * e, df = d * f; + + te[ 0 ] = ce + df * b; + te[ 4 ] = de * b - cf; + te[ 8 ] = a * d; + + te[ 1 ] = a * f; + te[ 5 ] = a * e; + te[ 9 ] = - b; + + te[ 2 ] = cf * b - de; + te[ 6 ] = df + ce * b; + te[ 10 ] = a * c; + + } else if ( euler.order === 'ZXY' ) { + + const ce = c * e, cf = c * f, de = d * e, df = d * f; + + te[ 0 ] = ce - df * b; + te[ 4 ] = - a * f; + te[ 8 ] = de + cf * b; + + te[ 1 ] = cf + de * b; + te[ 5 ] = a * e; + te[ 9 ] = df - ce * b; + + te[ 2 ] = - a * d; + te[ 6 ] = b; + te[ 10 ] = a * c; + + } else if ( euler.order === 'ZYX' ) { + + const ae = a * e, af = a * f, be = b * e, bf = b * f; + + te[ 0 ] = c * e; + te[ 4 ] = be * d - af; + te[ 8 ] = ae * d + bf; + + te[ 1 ] = c * f; + te[ 5 ] = bf * d + ae; + te[ 9 ] = af * d - be; + + te[ 2 ] = - d; + te[ 6 ] = b * c; + te[ 10 ] = a * c; + + } else if ( euler.order === 'YZX' ) { + + const ac = a * c, ad = a * d, bc = b * c, bd = b * d; + + te[ 0 ] = c * e; + te[ 4 ] = bd - ac * f; + te[ 8 ] = bc * f + ad; + + te[ 1 ] = f; + te[ 5 ] = a * e; + te[ 9 ] = - b * e; + + te[ 2 ] = - d * e; + te[ 6 ] = ad * f + bc; + te[ 10 ] = ac - bd * f; + + } else if ( euler.order === 'XZY' ) { + + const ac = a * c, ad = a * d, bc = b * c, bd = b * d; + + te[ 0 ] = c * e; + te[ 4 ] = - f; + te[ 8 ] = d * e; + + te[ 1 ] = ac * f + bd; + te[ 5 ] = a * e; + te[ 9 ] = ad * f - bc; + + te[ 2 ] = bc * f - ad; + te[ 6 ] = b * e; + te[ 10 ] = bd * f + ac; + + } + + // bottom row + te[ 3 ] = 0; + te[ 7 ] = 0; + te[ 11 ] = 0; + + // last column + te[ 12 ] = 0; + te[ 13 ] = 0; + te[ 14 ] = 0; + te[ 15 ] = 1; + + return this; + + } + + makeRotationFromQuaternion( q ) { + + return this.compose( _zero, q, _one ); + + } + + lookAt( eye, target, up ) { + + const te = this.elements; + + _z.subVectors( eye, target ); + + if ( _z.lengthSq() === 0 ) { + + // eye and target are in the same position + + _z.z = 1; + + } + + _z.normalize(); + _x.crossVectors( up, _z ); + + if ( _x.lengthSq() === 0 ) { + + // up and z are parallel + + if ( Math.abs( up.z ) === 1 ) { + + _z.x += 0.0001; + + } else { + + _z.z += 0.0001; + + } + + _z.normalize(); + _x.crossVectors( up, _z ); + + } + + _x.normalize(); + _y.crossVectors( _z, _x ); + + te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x; + te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y; + te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z; + + return this; + + } + + multiply( m ) { + + return this.multiplyMatrices( this, m ); + + } + + premultiply( m ) { + + return this.multiplyMatrices( m, this ); + + } + + multiplyMatrices( a, b ) { + + const ae = a.elements; + const be = b.elements; + const te = this.elements; + + const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ]; + const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ]; + const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ]; + const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ]; + + const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ]; + const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ]; + const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ]; + const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ]; + + te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; + te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; + te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; + te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; + + te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; + te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; + te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; + te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; + + te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; + te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; + te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; + te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; + + te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; + te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; + te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; + te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; + + return this; + + } + + multiplyScalar( s ) { + + const te = this.elements; + + te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s; + te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s; + te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s; + te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s; + + return this; + + } + + determinant() { + + const te = this.elements; + + const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ]; + const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ]; + const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ]; + const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ]; + + //TODO: make this more efficient + //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm ) + + return ( + n41 * ( + + n14 * n23 * n32 + - n13 * n24 * n32 + - n14 * n22 * n33 + + n12 * n24 * n33 + + n13 * n22 * n34 + - n12 * n23 * n34 + ) + + n42 * ( + + n11 * n23 * n34 + - n11 * n24 * n33 + + n14 * n21 * n33 + - n13 * n21 * n34 + + n13 * n24 * n31 + - n14 * n23 * n31 + ) + + n43 * ( + + n11 * n24 * n32 + - n11 * n22 * n34 + - n14 * n21 * n32 + + n12 * n21 * n34 + + n14 * n22 * n31 + - n12 * n24 * n31 + ) + + n44 * ( + - n13 * n22 * n31 + - n11 * n23 * n32 + + n11 * n22 * n33 + + n13 * n21 * n32 + - n12 * n21 * n33 + + n12 * n23 * n31 + ) + + ); + + } + + transpose() { + + const te = this.elements; + let tmp; + + tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp; + tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp; + tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp; + + tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp; + tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp; + tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp; + + return this; + + } + + setPosition( x, y, z ) { + + const te = this.elements; + + if ( x.isVector3 ) { + + te[ 12 ] = x.x; + te[ 13 ] = x.y; + te[ 14 ] = x.z; + + } else { + + te[ 12 ] = x; + te[ 13 ] = y; + te[ 14 ] = z; + + } + + return this; + + } + + invert() { + + // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm + const te = this.elements, + + n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ], + n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ], + n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ], + n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ], + + t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, + t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, + t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, + t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; + + const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; + + if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); + + const detInv = 1 / det; + + te[ 0 ] = t11 * detInv; + te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv; + te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv; + te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv; + + te[ 4 ] = t12 * detInv; + te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv; + te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv; + te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv; + + te[ 8 ] = t13 * detInv; + te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv; + te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv; + te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv; + + te[ 12 ] = t14 * detInv; + te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv; + te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv; + te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv; + + return this; + + } + + scale( v ) { + + const te = this.elements; + const x = v.x, y = v.y, z = v.z; + + te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z; + te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z; + te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z; + te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z; + + return this; + + } + + getMaxScaleOnAxis() { + + const te = this.elements; + + const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ]; + const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ]; + const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ]; + + return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) ); + + } + + makeTranslation( x, y, z ) { + + if ( x.isVector3 ) { + + this.set( + + 1, 0, 0, x.x, + 0, 1, 0, x.y, + 0, 0, 1, x.z, + 0, 0, 0, 1 + + ); + + } else { + + this.set( + + 1, 0, 0, x, + 0, 1, 0, y, + 0, 0, 1, z, + 0, 0, 0, 1 + + ); + + } + + return this; + + } + + makeRotationX( theta ) { + + const c = Math.cos( theta ), s = Math.sin( theta ); + + this.set( + + 1, 0, 0, 0, + 0, c, - s, 0, + 0, s, c, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + makeRotationY( theta ) { + + const c = Math.cos( theta ), s = Math.sin( theta ); + + this.set( + + c, 0, s, 0, + 0, 1, 0, 0, + - s, 0, c, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + makeRotationZ( theta ) { + + const c = Math.cos( theta ), s = Math.sin( theta ); + + this.set( + + c, - s, 0, 0, + s, c, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + makeRotationAxis( axis, angle ) { + + // Based on http://www.gamedev.net/reference/articles/article1199.asp + + const c = Math.cos( angle ); + const s = Math.sin( angle ); + const t = 1 - c; + const x = axis.x, y = axis.y, z = axis.z; + const tx = t * x, ty = t * y; + + this.set( + + tx * x + c, tx * y - s * z, tx * z + s * y, 0, + tx * y + s * z, ty * y + c, ty * z - s * x, 0, + tx * z - s * y, ty * z + s * x, t * z * z + c, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + makeScale( x, y, z ) { + + this.set( + + x, 0, 0, 0, + 0, y, 0, 0, + 0, 0, z, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + makeShear( xy, xz, yx, yz, zx, zy ) { + + this.set( + + 1, yx, zx, 0, + xy, 1, zy, 0, + xz, yz, 1, 0, + 0, 0, 0, 1 + + ); + + return this; + + } + + compose( position, quaternion, scale ) { + + const te = this.elements; + + const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w; + const x2 = x + x, y2 = y + y, z2 = z + z; + const xx = x * x2, xy = x * y2, xz = x * z2; + const yy = y * y2, yz = y * z2, zz = z * z2; + const wx = w * x2, wy = w * y2, wz = w * z2; + + const sx = scale.x, sy = scale.y, sz = scale.z; + + te[ 0 ] = ( 1 - ( yy + zz ) ) * sx; + te[ 1 ] = ( xy + wz ) * sx; + te[ 2 ] = ( xz - wy ) * sx; + te[ 3 ] = 0; + + te[ 4 ] = ( xy - wz ) * sy; + te[ 5 ] = ( 1 - ( xx + zz ) ) * sy; + te[ 6 ] = ( yz + wx ) * sy; + te[ 7 ] = 0; + + te[ 8 ] = ( xz + wy ) * sz; + te[ 9 ] = ( yz - wx ) * sz; + te[ 10 ] = ( 1 - ( xx + yy ) ) * sz; + te[ 11 ] = 0; + + te[ 12 ] = position.x; + te[ 13 ] = position.y; + te[ 14 ] = position.z; + te[ 15 ] = 1; + + return this; + + } + + decompose( position, quaternion, scale ) { + + const te = this.elements; + + let sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length(); + const sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length(); + const sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length(); + + // if determine is negative, we need to invert one scale + const det = this.determinant(); + if ( det < 0 ) sx = - sx; + + position.x = te[ 12 ]; + position.y = te[ 13 ]; + position.z = te[ 14 ]; + + // scale the rotation part + _m1$2.copy( this ); + + const invSX = 1 / sx; + const invSY = 1 / sy; + const invSZ = 1 / sz; + + _m1$2.elements[ 0 ] *= invSX; + _m1$2.elements[ 1 ] *= invSX; + _m1$2.elements[ 2 ] *= invSX; + + _m1$2.elements[ 4 ] *= invSY; + _m1$2.elements[ 5 ] *= invSY; + _m1$2.elements[ 6 ] *= invSY; + + _m1$2.elements[ 8 ] *= invSZ; + _m1$2.elements[ 9 ] *= invSZ; + _m1$2.elements[ 10 ] *= invSZ; + + quaternion.setFromRotationMatrix( _m1$2 ); + + scale.x = sx; + scale.y = sy; + scale.z = sz; + + return this; + + } + + makePerspective( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) { + + const te = this.elements; + const x = 2 * near / ( right - left ); + const y = 2 * near / ( top - bottom ); + + const a = ( right + left ) / ( right - left ); + const b = ( top + bottom ) / ( top - bottom ); + + let c, d; + + if ( coordinateSystem === WebGLCoordinateSystem ) { + + c = - ( far + near ) / ( far - near ); + d = ( - 2 * far * near ) / ( far - near ); + + } else if ( coordinateSystem === WebGPUCoordinateSystem ) { + + c = - far / ( far - near ); + d = ( - far * near ) / ( far - near ); + + } else { + + throw new Error( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem ); + + } + + te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0; + te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0; + te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d; + te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0; + + return this; + + } + + makeOrthographic( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) { + + const te = this.elements; + const w = 1.0 / ( right - left ); + const h = 1.0 / ( top - bottom ); + const p = 1.0 / ( far - near ); + + const x = ( right + left ) * w; + const y = ( top + bottom ) * h; + + let z, zInv; + + if ( coordinateSystem === WebGLCoordinateSystem ) { + + z = ( far + near ) * p; + zInv = - 2 * p; + + } else if ( coordinateSystem === WebGPUCoordinateSystem ) { + + z = near * p; + zInv = - 1 * p; + + } else { + + throw new Error( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem ); + + } + + te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x; + te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y; + te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = zInv; te[ 14 ] = - z; + te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1; + + return this; + + } + + equals( matrix ) { + + const te = this.elements; + const me = matrix.elements; + + for ( let i = 0; i < 16; i ++ ) { + + if ( te[ i ] !== me[ i ] ) return false; + + } + + return true; + + } + + fromArray( array, offset = 0 ) { + + for ( let i = 0; i < 16; i ++ ) { + + this.elements[ i ] = array[ i + offset ]; + + } + + return this; + + } + + toArray( array = [], offset = 0 ) { + + const te = this.elements; + + array[ offset ] = te[ 0 ]; + array[ offset + 1 ] = te[ 1 ]; + array[ offset + 2 ] = te[ 2 ]; + array[ offset + 3 ] = te[ 3 ]; + + array[ offset + 4 ] = te[ 4 ]; + array[ offset + 5 ] = te[ 5 ]; + array[ offset + 6 ] = te[ 6 ]; + array[ offset + 7 ] = te[ 7 ]; + + array[ offset + 8 ] = te[ 8 ]; + array[ offset + 9 ] = te[ 9 ]; + array[ offset + 10 ] = te[ 10 ]; + array[ offset + 11 ] = te[ 11 ]; + + array[ offset + 12 ] = te[ 12 ]; + array[ offset + 13 ] = te[ 13 ]; + array[ offset + 14 ] = te[ 14 ]; + array[ offset + 15 ] = te[ 15 ]; + + return array; + + } + +} + +const _v1$5 = /*@__PURE__*/ new Vector3(); +const _m1$2 = /*@__PURE__*/ new Matrix4(); +const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 ); +const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 ); +const _x = /*@__PURE__*/ new Vector3(); +const _y = /*@__PURE__*/ new Vector3(); +const _z = /*@__PURE__*/ new Vector3(); + +const _matrix$2 = /*@__PURE__*/ new Matrix4(); +const _quaternion$3 = /*@__PURE__*/ new Quaternion(); + +class Euler { + + constructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) { + + this.isEuler = true; + + this._x = x; + this._y = y; + this._z = z; + this._order = order; + + } + + get x() { + + return this._x; + + } + + set x( value ) { + + this._x = value; + this._onChangeCallback(); + + } + + get y() { + + return this._y; + + } + + set y( value ) { + + this._y = value; + this._onChangeCallback(); + + } + + get z() { + + return this._z; + + } + + set z( value ) { + + this._z = value; + this._onChangeCallback(); + + } + + get order() { + + return this._order; + + } + + set order( value ) { + + this._order = value; + this._onChangeCallback(); + + } + + set( x, y, z, order = this._order ) { + + this._x = x; + this._y = y; + this._z = z; + this._order = order; + + this._onChangeCallback(); + + return this; + + } + + clone() { + + return new this.constructor( this._x, this._y, this._z, this._order ); + + } + + copy( euler ) { + + this._x = euler._x; + this._y = euler._y; + this._z = euler._z; + this._order = euler._order; + + this._onChangeCallback(); + + return this; + + } + + setFromRotationMatrix( m, order = this._order, update = true ) { + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + const te = m.elements; + const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ]; + const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ]; + const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ]; + + switch ( order ) { + + case 'XYZ': + + this._y = Math.asin( clamp( m13, - 1, 1 ) ); + + if ( Math.abs( m13 ) < 0.9999999 ) { + + this._x = Math.atan2( - m23, m33 ); + this._z = Math.atan2( - m12, m11 ); + + } else { + + this._x = Math.atan2( m32, m22 ); + this._z = 0; + + } + + break; + + case 'YXZ': + + this._x = Math.asin( - clamp( m23, - 1, 1 ) ); + + if ( Math.abs( m23 ) < 0.9999999 ) { + + this._y = Math.atan2( m13, m33 ); + this._z = Math.atan2( m21, m22 ); + + } else { + + this._y = Math.atan2( - m31, m11 ); + this._z = 0; + + } + + break; + + case 'ZXY': + + this._x = Math.asin( clamp( m32, - 1, 1 ) ); + + if ( Math.abs( m32 ) < 0.9999999 ) { + + this._y = Math.atan2( - m31, m33 ); + this._z = Math.atan2( - m12, m22 ); + + } else { + + this._y = 0; + this._z = Math.atan2( m21, m11 ); + + } + + break; + + case 'ZYX': + + this._y = Math.asin( - clamp( m31, - 1, 1 ) ); + + if ( Math.abs( m31 ) < 0.9999999 ) { + + this._x = Math.atan2( m32, m33 ); + this._z = Math.atan2( m21, m11 ); + + } else { + + this._x = 0; + this._z = Math.atan2( - m12, m22 ); + + } + + break; + + case 'YZX': + + this._z = Math.asin( clamp( m21, - 1, 1 ) ); + + if ( Math.abs( m21 ) < 0.9999999 ) { + + this._x = Math.atan2( - m23, m22 ); + this._y = Math.atan2( - m31, m11 ); + + } else { + + this._x = 0; + this._y = Math.atan2( m13, m33 ); + + } + + break; + + case 'XZY': + + this._z = Math.asin( - clamp( m12, - 1, 1 ) ); + + if ( Math.abs( m12 ) < 0.9999999 ) { + + this._x = Math.atan2( m32, m22 ); + this._y = Math.atan2( m13, m11 ); + + } else { + + this._x = Math.atan2( - m23, m33 ); + this._y = 0; + + } + + break; + + default: + + console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order ); + + } + + this._order = order; + + if ( update === true ) this._onChangeCallback(); + + return this; + + } + + setFromQuaternion( q, order, update ) { + + _matrix$2.makeRotationFromQuaternion( q ); + + return this.setFromRotationMatrix( _matrix$2, order, update ); + + } + + setFromVector3( v, order = this._order ) { + + return this.set( v.x, v.y, v.z, order ); + + } + + reorder( newOrder ) { + + // WARNING: this discards revolution information -bhouston + + _quaternion$3.setFromEuler( this ); + + return this.setFromQuaternion( _quaternion$3, newOrder ); + + } + + equals( euler ) { + + return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order ); + + } + + fromArray( array ) { + + this._x = array[ 0 ]; + this._y = array[ 1 ]; + this._z = array[ 2 ]; + if ( array[ 3 ] !== undefined ) this._order = array[ 3 ]; + + this._onChangeCallback(); + + return this; + + } + + toArray( array = [], offset = 0 ) { + + array[ offset ] = this._x; + array[ offset + 1 ] = this._y; + array[ offset + 2 ] = this._z; + array[ offset + 3 ] = this._order; + + return array; + + } + + _onChange( callback ) { + + this._onChangeCallback = callback; + + return this; + + } + + _onChangeCallback() {} + + *[ Symbol.iterator ]() { + + yield this._x; + yield this._y; + yield this._z; + yield this._order; + + } + +} + +Euler.DEFAULT_ORDER = 'XYZ'; + +class Layers { + + constructor() { + + this.mask = 1 | 0; + + } + + set( channel ) { + + this.mask = ( 1 << channel | 0 ) >>> 0; + + } + + enable( channel ) { + + this.mask |= 1 << channel | 0; + + } + + enableAll() { + + this.mask = 0xffffffff | 0; + + } + + toggle( channel ) { + + this.mask ^= 1 << channel | 0; + + } + + disable( channel ) { + + this.mask &= ~ ( 1 << channel | 0 ); + + } + + disableAll() { + + this.mask = 0; + + } + + test( layers ) { + + return ( this.mask & layers.mask ) !== 0; + + } + + isEnabled( channel ) { + + return ( this.mask & ( 1 << channel | 0 ) ) !== 0; + + } + +} + +let _object3DId = 0; + +const _v1$4 = /*@__PURE__*/ new Vector3(); +const _q1 = /*@__PURE__*/ new Quaternion(); +const _m1$1 = /*@__PURE__*/ new Matrix4(); +const _target = /*@__PURE__*/ new Vector3(); + +const _position$3 = /*@__PURE__*/ new Vector3(); +const _scale$2 = /*@__PURE__*/ new Vector3(); +const _quaternion$2 = /*@__PURE__*/ new Quaternion(); + +const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 ); +const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 ); +const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 ); + +const _addedEvent = { type: 'added' }; +const _removedEvent = { type: 'removed' }; + +const _childaddedEvent = { type: 'childadded', child: null }; +const _childremovedEvent = { type: 'childremoved', child: null }; + +class Object3D extends EventDispatcher { + + constructor() { + + super(); + + this.isObject3D = true; + + Object.defineProperty( this, 'id', { value: _object3DId ++ } ); + + this.uuid = generateUUID(); + + this.name = ''; + this.type = 'Object3D'; + + this.parent = null; + this.children = []; + + this.up = Object3D.DEFAULT_UP.clone(); + + const position = new Vector3(); + const rotation = new Euler(); + const quaternion = new Quaternion(); + const scale = new Vector3( 1, 1, 1 ); + + function onRotationChange() { + + quaternion.setFromEuler( rotation, false ); + + } + + function onQuaternionChange() { + + rotation.setFromQuaternion( quaternion, undefined, false ); + + } + + rotation._onChange( onRotationChange ); + quaternion._onChange( onQuaternionChange ); + + Object.defineProperties( this, { + position: { + configurable: true, + enumerable: true, + value: position + }, + rotation: { + configurable: true, + enumerable: true, + value: rotation + }, + quaternion: { + configurable: true, + enumerable: true, + value: quaternion + }, + scale: { + configurable: true, + enumerable: true, + value: scale + }, + modelViewMatrix: { + value: new Matrix4() + }, + normalMatrix: { + value: new Matrix3() + } + } ); + + this.matrix = new Matrix4(); + this.matrixWorld = new Matrix4(); + + this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE; + + this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer + this.matrixWorldNeedsUpdate = false; + + this.layers = new Layers(); + this.visible = true; + + this.castShadow = false; + this.receiveShadow = false; + + this.frustumCulled = true; + this.renderOrder = 0; + + this.animations = []; + + this.userData = {}; + + } + + onBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {} + + onAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {} + + onBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {} + + onAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {} + + applyMatrix4( matrix ) { + + if ( this.matrixAutoUpdate ) this.updateMatrix(); + + this.matrix.premultiply( matrix ); + + this.matrix.decompose( this.position, this.quaternion, this.scale ); + + } + + applyQuaternion( q ) { + + this.quaternion.premultiply( q ); + + return this; + + } + + setRotationFromAxisAngle( axis, angle ) { + + // assumes axis is normalized + + this.quaternion.setFromAxisAngle( axis, angle ); + + } + + setRotationFromEuler( euler ) { + + this.quaternion.setFromEuler( euler, true ); + + } + + setRotationFromMatrix( m ) { + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + this.quaternion.setFromRotationMatrix( m ); + + } + + setRotationFromQuaternion( q ) { + + // assumes q is normalized + + this.quaternion.copy( q ); + + } + + rotateOnAxis( axis, angle ) { + + // rotate object on axis in object space + // axis is assumed to be normalized + + _q1.setFromAxisAngle( axis, angle ); + + this.quaternion.multiply( _q1 ); + + return this; + + } + + rotateOnWorldAxis( axis, angle ) { + + // rotate object on axis in world space + // axis is assumed to be normalized + // method assumes no rotated parent + + _q1.setFromAxisAngle( axis, angle ); + + this.quaternion.premultiply( _q1 ); + + return this; + + } + + rotateX( angle ) { + + return this.rotateOnAxis( _xAxis, angle ); + + } + + rotateY( angle ) { + + return this.rotateOnAxis( _yAxis, angle ); + + } + + rotateZ( angle ) { + + return this.rotateOnAxis( _zAxis, angle ); + + } + + translateOnAxis( axis, distance ) { + + // translate object by distance along axis in object space + // axis is assumed to be normalized + + _v1$4.copy( axis ).applyQuaternion( this.quaternion ); + + this.position.add( _v1$4.multiplyScalar( distance ) ); + + return this; + + } + + translateX( distance ) { + + return this.translateOnAxis( _xAxis, distance ); + + } + + translateY( distance ) { + + return this.translateOnAxis( _yAxis, distance ); + + } + + translateZ( distance ) { + + return this.translateOnAxis( _zAxis, distance ); + + } + + localToWorld( vector ) { + + this.updateWorldMatrix( true, false ); + + return vector.applyMatrix4( this.matrixWorld ); + + } + + worldToLocal( vector ) { + + this.updateWorldMatrix( true, false ); + + return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() ); + + } + + lookAt( x, y, z ) { + + // This method does not support objects having non-uniformly-scaled parent(s) + + if ( x.isVector3 ) { + + _target.copy( x ); + + } else { + + _target.set( x, y, z ); + + } + + const parent = this.parent; + + this.updateWorldMatrix( true, false ); + + _position$3.setFromMatrixPosition( this.matrixWorld ); + + if ( this.isCamera || this.isLight ) { + + _m1$1.lookAt( _position$3, _target, this.up ); + + } else { + + _m1$1.lookAt( _target, _position$3, this.up ); + + } + + this.quaternion.setFromRotationMatrix( _m1$1 ); + + if ( parent ) { + + _m1$1.extractRotation( parent.matrixWorld ); + _q1.setFromRotationMatrix( _m1$1 ); + this.quaternion.premultiply( _q1.invert() ); + + } + + } + + add( object ) { + + if ( arguments.length > 1 ) { + + for ( let i = 0; i < arguments.length; i ++ ) { + + this.add( arguments[ i ] ); + + } + + return this; + + } + + if ( object === this ) { + + console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object ); + return this; + + } + + if ( object && object.isObject3D ) { + + object.removeFromParent(); + object.parent = this; + this.children.push( object ); + + object.dispatchEvent( _addedEvent ); + + _childaddedEvent.child = object; + this.dispatchEvent( _childaddedEvent ); + _childaddedEvent.child = null; + + } else { + + console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object ); + + } + + return this; + + } + + remove( object ) { + + if ( arguments.length > 1 ) { + + for ( let i = 0; i < arguments.length; i ++ ) { + + this.remove( arguments[ i ] ); + + } + + return this; + + } + + const index = this.children.indexOf( object ); + + if ( index !== - 1 ) { + + object.parent = null; + this.children.splice( index, 1 ); + + object.dispatchEvent( _removedEvent ); + + _childremovedEvent.child = object; + this.dispatchEvent( _childremovedEvent ); + _childremovedEvent.child = null; + + } + + return this; + + } + + removeFromParent() { + + const parent = this.parent; + + if ( parent !== null ) { + + parent.remove( this ); + + } + + return this; + + } + + clear() { + + return this.remove( ... this.children ); + + } + + attach( object ) { + + // adds object as a child of this, while maintaining the object's world transform + + // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s) + + this.updateWorldMatrix( true, false ); + + _m1$1.copy( this.matrixWorld ).invert(); + + if ( object.parent !== null ) { + + object.parent.updateWorldMatrix( true, false ); + + _m1$1.multiply( object.parent.matrixWorld ); + + } + + object.applyMatrix4( _m1$1 ); + + object.removeFromParent(); + object.parent = this; + this.children.push( object ); + + object.updateWorldMatrix( false, true ); + + object.dispatchEvent( _addedEvent ); + + _childaddedEvent.child = object; + this.dispatchEvent( _childaddedEvent ); + _childaddedEvent.child = null; + + return this; + + } + + getObjectById( id ) { + + return this.getObjectByProperty( 'id', id ); + + } + + getObjectByName( name ) { + + return this.getObjectByProperty( 'name', name ); + + } + + getObjectByProperty( name, value ) { + + if ( this[ name ] === value ) return this; + + for ( let i = 0, l = this.children.length; i < l; i ++ ) { + + const child = this.children[ i ]; + const object = child.getObjectByProperty( name, value ); + + if ( object !== undefined ) { + + return object; + + } + + } + + return undefined; + + } + + getObjectsByProperty( name, value, result = [] ) { + + if ( this[ name ] === value ) result.push( this ); + + const children = this.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].getObjectsByProperty( name, value, result ); + + } + + return result; + + } + + getWorldPosition( target ) { + + this.updateWorldMatrix( true, false ); + + return target.setFromMatrixPosition( this.matrixWorld ); + + } + + getWorldQuaternion( target ) { + + this.updateWorldMatrix( true, false ); + + this.matrixWorld.decompose( _position$3, target, _scale$2 ); + + return target; + + } + + getWorldScale( target ) { + + this.updateWorldMatrix( true, false ); + + this.matrixWorld.decompose( _position$3, _quaternion$2, target ); + + return target; + + } + + getWorldDirection( target ) { + + this.updateWorldMatrix( true, false ); + + const e = this.matrixWorld.elements; + + return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize(); + + } + + raycast( /* raycaster, intersects */ ) {} + + traverse( callback ) { + + callback( this ); + + const children = this.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].traverse( callback ); + + } + + } + + traverseVisible( callback ) { + + if ( this.visible === false ) return; + + callback( this ); + + const children = this.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].traverseVisible( callback ); + + } + + } + + traverseAncestors( callback ) { + + const parent = this.parent; + + if ( parent !== null ) { + + callback( parent ); + + parent.traverseAncestors( callback ); + + } + + } + + updateMatrix() { + + this.matrix.compose( this.position, this.quaternion, this.scale ); + + this.matrixWorldNeedsUpdate = true; + + } + + updateMatrixWorld( force ) { + + if ( this.matrixAutoUpdate ) this.updateMatrix(); + + if ( this.matrixWorldNeedsUpdate || force ) { + + if ( this.matrixWorldAutoUpdate === true ) { + + if ( this.parent === null ) { + + this.matrixWorld.copy( this.matrix ); + + } else { + + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + + } + + } + + this.matrixWorldNeedsUpdate = false; + + force = true; + + } + + // make sure descendants are updated if required + + const children = this.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + const child = children[ i ]; + + child.updateMatrixWorld( force ); + + } + + } + + updateWorldMatrix( updateParents, updateChildren ) { + + const parent = this.parent; + + if ( updateParents === true && parent !== null ) { + + parent.updateWorldMatrix( true, false ); + + } + + if ( this.matrixAutoUpdate ) this.updateMatrix(); + + if ( this.matrixWorldAutoUpdate === true ) { + + if ( this.parent === null ) { + + this.matrixWorld.copy( this.matrix ); + + } else { + + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + + } + + } + + // make sure descendants are updated + + if ( updateChildren === true ) { + + const children = this.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + const child = children[ i ]; + + child.updateWorldMatrix( false, true ); + + } + + } + + } + + toJSON( meta ) { + + // meta is a string when called from JSON.stringify + const isRootObject = ( meta === undefined || typeof meta === 'string' ); + + const output = {}; + + // meta is a hash used to collect geometries, materials. + // not providing it implies that this is the root object + // being serialized. + if ( isRootObject ) { + + // initialize meta obj + meta = { + geometries: {}, + materials: {}, + textures: {}, + images: {}, + shapes: {}, + skeletons: {}, + animations: {}, + nodes: {} + }; + + output.metadata = { + version: 4.6, + type: 'Object', + generator: 'Object3D.toJSON' + }; + + } + + // standard Object3D serialization + + const object = {}; + + object.uuid = this.uuid; + object.type = this.type; + + if ( this.name !== '' ) object.name = this.name; + if ( this.castShadow === true ) object.castShadow = true; + if ( this.receiveShadow === true ) object.receiveShadow = true; + if ( this.visible === false ) object.visible = false; + if ( this.frustumCulled === false ) object.frustumCulled = false; + if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder; + if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData; + + object.layers = this.layers.mask; + object.matrix = this.matrix.toArray(); + object.up = this.up.toArray(); + + if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false; + + // object specific properties + + if ( this.isInstancedMesh ) { + + object.type = 'InstancedMesh'; + object.count = this.count; + object.instanceMatrix = this.instanceMatrix.toJSON(); + if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON(); + + } + + if ( this.isBatchedMesh ) { + + object.type = 'BatchedMesh'; + object.perObjectFrustumCulled = this.perObjectFrustumCulled; + object.sortObjects = this.sortObjects; + + object.drawRanges = this._drawRanges; + object.reservedRanges = this._reservedRanges; + + object.visibility = this._visibility; + object.active = this._active; + object.bounds = this._bounds.map( bound => ( { + boxInitialized: bound.boxInitialized, + boxMin: bound.box.min.toArray(), + boxMax: bound.box.max.toArray(), + + sphereInitialized: bound.sphereInitialized, + sphereRadius: bound.sphere.radius, + sphereCenter: bound.sphere.center.toArray() + } ) ); + + object.maxInstanceCount = this._maxInstanceCount; + object.maxVertexCount = this._maxVertexCount; + object.maxIndexCount = this._maxIndexCount; + + object.geometryInitialized = this._geometryInitialized; + object.geometryCount = this._geometryCount; + + object.matricesTexture = this._matricesTexture.toJSON( meta ); + + if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta ); + + if ( this.boundingSphere !== null ) { + + object.boundingSphere = { + center: object.boundingSphere.center.toArray(), + radius: object.boundingSphere.radius + }; + + } + + if ( this.boundingBox !== null ) { + + object.boundingBox = { + min: object.boundingBox.min.toArray(), + max: object.boundingBox.max.toArray() + }; + + } + + } + + // + + function serialize( library, element ) { + + if ( library[ element.uuid ] === undefined ) { + + library[ element.uuid ] = element.toJSON( meta ); + + } + + return element.uuid; + + } + + if ( this.isScene ) { + + if ( this.background ) { + + if ( this.background.isColor ) { + + object.background = this.background.toJSON(); + + } else if ( this.background.isTexture ) { + + object.background = this.background.toJSON( meta ).uuid; + + } + + } + + if ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) { + + object.environment = this.environment.toJSON( meta ).uuid; + + } + + } else if ( this.isMesh || this.isLine || this.isPoints ) { + + object.geometry = serialize( meta.geometries, this.geometry ); + + const parameters = this.geometry.parameters; + + if ( parameters !== undefined && parameters.shapes !== undefined ) { + + const shapes = parameters.shapes; + + if ( Array.isArray( shapes ) ) { + + for ( let i = 0, l = shapes.length; i < l; i ++ ) { + + const shape = shapes[ i ]; + + serialize( meta.shapes, shape ); + + } + + } else { + + serialize( meta.shapes, shapes ); + + } + + } + + } + + if ( this.isSkinnedMesh ) { + + object.bindMode = this.bindMode; + object.bindMatrix = this.bindMatrix.toArray(); + + if ( this.skeleton !== undefined ) { + + serialize( meta.skeletons, this.skeleton ); + + object.skeleton = this.skeleton.uuid; + + } + + } + + if ( this.material !== undefined ) { + + if ( Array.isArray( this.material ) ) { + + const uuids = []; + + for ( let i = 0, l = this.material.length; i < l; i ++ ) { + + uuids.push( serialize( meta.materials, this.material[ i ] ) ); + + } + + object.material = uuids; + + } else { + + object.material = serialize( meta.materials, this.material ); + + } + + } + + // + + if ( this.children.length > 0 ) { + + object.children = []; + + for ( let i = 0; i < this.children.length; i ++ ) { + + object.children.push( this.children[ i ].toJSON( meta ).object ); + + } + + } + + // + + if ( this.animations.length > 0 ) { + + object.animations = []; + + for ( let i = 0; i < this.animations.length; i ++ ) { + + const animation = this.animations[ i ]; + + object.animations.push( serialize( meta.animations, animation ) ); + + } + + } + + if ( isRootObject ) { + + const geometries = extractFromCache( meta.geometries ); + const materials = extractFromCache( meta.materials ); + const textures = extractFromCache( meta.textures ); + const images = extractFromCache( meta.images ); + const shapes = extractFromCache( meta.shapes ); + const skeletons = extractFromCache( meta.skeletons ); + const animations = extractFromCache( meta.animations ); + const nodes = extractFromCache( meta.nodes ); + + if ( geometries.length > 0 ) output.geometries = geometries; + if ( materials.length > 0 ) output.materials = materials; + if ( textures.length > 0 ) output.textures = textures; + if ( images.length > 0 ) output.images = images; + if ( shapes.length > 0 ) output.shapes = shapes; + if ( skeletons.length > 0 ) output.skeletons = skeletons; + if ( animations.length > 0 ) output.animations = animations; + if ( nodes.length > 0 ) output.nodes = nodes; + + } + + output.object = object; + + return output; + + // extract data from the cache hash + // remove metadata on each item + // and return as array + function extractFromCache( cache ) { + + const values = []; + for ( const key in cache ) { + + const data = cache[ key ]; + delete data.metadata; + values.push( data ); + + } + + return values; + + } + + } + + clone( recursive ) { + + return new this.constructor().copy( this, recursive ); + + } + + copy( source, recursive = true ) { + + this.name = source.name; + + this.up.copy( source.up ); + + this.position.copy( source.position ); + this.rotation.order = source.rotation.order; + this.quaternion.copy( source.quaternion ); + this.scale.copy( source.scale ); + + this.matrix.copy( source.matrix ); + this.matrixWorld.copy( source.matrixWorld ); + + this.matrixAutoUpdate = source.matrixAutoUpdate; + + this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate; + this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate; + + this.layers.mask = source.layers.mask; + this.visible = source.visible; + + this.castShadow = source.castShadow; + this.receiveShadow = source.receiveShadow; + + this.frustumCulled = source.frustumCulled; + this.renderOrder = source.renderOrder; + + this.animations = source.animations.slice(); + + this.userData = JSON.parse( JSON.stringify( source.userData ) ); + + if ( recursive === true ) { + + for ( let i = 0; i < source.children.length; i ++ ) { + + const child = source.children[ i ]; + this.add( child.clone() ); + + } + + } + + return this; + + } + +} + +Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 ); +Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true; +Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true; + +const _v0$1 = /*@__PURE__*/ new Vector3(); +const _v1$3 = /*@__PURE__*/ new Vector3(); +const _v2$2 = /*@__PURE__*/ new Vector3(); +const _v3$2 = /*@__PURE__*/ new Vector3(); + +const _vab = /*@__PURE__*/ new Vector3(); +const _vac = /*@__PURE__*/ new Vector3(); +const _vbc = /*@__PURE__*/ new Vector3(); +const _vap = /*@__PURE__*/ new Vector3(); +const _vbp = /*@__PURE__*/ new Vector3(); +const _vcp = /*@__PURE__*/ new Vector3(); + +const _v40 = /*@__PURE__*/ new Vector4(); +const _v41 = /*@__PURE__*/ new Vector4(); +const _v42 = /*@__PURE__*/ new Vector4(); + +class Triangle { + + constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) { + + this.a = a; + this.b = b; + this.c = c; + + } + + static getNormal( a, b, c, target ) { + + target.subVectors( c, b ); + _v0$1.subVectors( a, b ); + target.cross( _v0$1 ); + + const targetLengthSq = target.lengthSq(); + if ( targetLengthSq > 0 ) { + + return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) ); + + } + + return target.set( 0, 0, 0 ); + + } + + // static/instance method to calculate barycentric coordinates + // based on: http://www.blackpawn.com/texts/pointinpoly/default.html + static getBarycoord( point, a, b, c, target ) { + + _v0$1.subVectors( c, a ); + _v1$3.subVectors( b, a ); + _v2$2.subVectors( point, a ); + + const dot00 = _v0$1.dot( _v0$1 ); + const dot01 = _v0$1.dot( _v1$3 ); + const dot02 = _v0$1.dot( _v2$2 ); + const dot11 = _v1$3.dot( _v1$3 ); + const dot12 = _v1$3.dot( _v2$2 ); + + const denom = ( dot00 * dot11 - dot01 * dot01 ); + + // collinear or singular triangle + if ( denom === 0 ) { + + target.set( 0, 0, 0 ); + return null; + + } + + const invDenom = 1 / denom; + const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom; + const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom; + + // barycentric coordinates must always sum to 1 + return target.set( 1 - u - v, v, u ); + + } + + static containsPoint( point, a, b, c ) { + + // if the triangle is degenerate then we can't contain a point + if ( this.getBarycoord( point, a, b, c, _v3$2 ) === null ) { + + return false; + + } + + return ( _v3$2.x >= 0 ) && ( _v3$2.y >= 0 ) && ( ( _v3$2.x + _v3$2.y ) <= 1 ); + + } + + static getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) { + + if ( this.getBarycoord( point, p1, p2, p3, _v3$2 ) === null ) { + + target.x = 0; + target.y = 0; + if ( 'z' in target ) target.z = 0; + if ( 'w' in target ) target.w = 0; + return null; + + } + + target.setScalar( 0 ); + target.addScaledVector( v1, _v3$2.x ); + target.addScaledVector( v2, _v3$2.y ); + target.addScaledVector( v3, _v3$2.z ); + + return target; + + } + + static getInterpolatedAttribute( attr, i1, i2, i3, barycoord, target ) { + + _v40.setScalar( 0 ); + _v41.setScalar( 0 ); + _v42.setScalar( 0 ); + + _v40.fromBufferAttribute( attr, i1 ); + _v41.fromBufferAttribute( attr, i2 ); + _v42.fromBufferAttribute( attr, i3 ); + + target.setScalar( 0 ); + target.addScaledVector( _v40, barycoord.x ); + target.addScaledVector( _v41, barycoord.y ); + target.addScaledVector( _v42, barycoord.z ); + + return target; + + } + + static isFrontFacing( a, b, c, direction ) { + + _v0$1.subVectors( c, b ); + _v1$3.subVectors( a, b ); + + // strictly front facing + return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false; + + } + + set( a, b, c ) { + + this.a.copy( a ); + this.b.copy( b ); + this.c.copy( c ); + + return this; + + } + + setFromPointsAndIndices( points, i0, i1, i2 ) { + + this.a.copy( points[ i0 ] ); + this.b.copy( points[ i1 ] ); + this.c.copy( points[ i2 ] ); + + return this; + + } + + setFromAttributeAndIndices( attribute, i0, i1, i2 ) { + + this.a.fromBufferAttribute( attribute, i0 ); + this.b.fromBufferAttribute( attribute, i1 ); + this.c.fromBufferAttribute( attribute, i2 ); + + return this; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( triangle ) { + + this.a.copy( triangle.a ); + this.b.copy( triangle.b ); + this.c.copy( triangle.c ); + + return this; + + } + + getArea() { + + _v0$1.subVectors( this.c, this.b ); + _v1$3.subVectors( this.a, this.b ); + + return _v0$1.cross( _v1$3 ).length() * 0.5; + + } + + getMidpoint( target ) { + + return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 ); + + } + + getNormal( target ) { + + return Triangle.getNormal( this.a, this.b, this.c, target ); + + } + + getPlane( target ) { + + return target.setFromCoplanarPoints( this.a, this.b, this.c ); + + } + + getBarycoord( point, target ) { + + return Triangle.getBarycoord( point, this.a, this.b, this.c, target ); + + } + + getInterpolation( point, v1, v2, v3, target ) { + + return Triangle.getInterpolation( point, this.a, this.b, this.c, v1, v2, v3, target ); + + } + + containsPoint( point ) { + + return Triangle.containsPoint( point, this.a, this.b, this.c ); + + } + + isFrontFacing( direction ) { + + return Triangle.isFrontFacing( this.a, this.b, this.c, direction ); + + } + + intersectsBox( box ) { + + return box.intersectsTriangle( this ); + + } + + closestPointToPoint( p, target ) { + + const a = this.a, b = this.b, c = this.c; + let v, w; + + // algorithm thanks to Real-Time Collision Detection by Christer Ericson, + // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc., + // under the accompanying license; see chapter 5.1.5 for detailed explanation. + // basically, we're distinguishing which of the voronoi regions of the triangle + // the point lies in with the minimum amount of redundant computation. + + _vab.subVectors( b, a ); + _vac.subVectors( c, a ); + _vap.subVectors( p, a ); + const d1 = _vab.dot( _vap ); + const d2 = _vac.dot( _vap ); + if ( d1 <= 0 && d2 <= 0 ) { + + // vertex region of A; barycentric coords (1, 0, 0) + return target.copy( a ); + + } + + _vbp.subVectors( p, b ); + const d3 = _vab.dot( _vbp ); + const d4 = _vac.dot( _vbp ); + if ( d3 >= 0 && d4 <= d3 ) { + + // vertex region of B; barycentric coords (0, 1, 0) + return target.copy( b ); + + } + + const vc = d1 * d4 - d3 * d2; + if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) { + + v = d1 / ( d1 - d3 ); + // edge region of AB; barycentric coords (1-v, v, 0) + return target.copy( a ).addScaledVector( _vab, v ); + + } + + _vcp.subVectors( p, c ); + const d5 = _vab.dot( _vcp ); + const d6 = _vac.dot( _vcp ); + if ( d6 >= 0 && d5 <= d6 ) { + + // vertex region of C; barycentric coords (0, 0, 1) + return target.copy( c ); + + } + + const vb = d5 * d2 - d1 * d6; + if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) { + + w = d2 / ( d2 - d6 ); + // edge region of AC; barycentric coords (1-w, 0, w) + return target.copy( a ).addScaledVector( _vac, w ); + + } + + const va = d3 * d6 - d5 * d4; + if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) { + + _vbc.subVectors( c, b ); + w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) ); + // edge region of BC; barycentric coords (0, 1-w, w) + return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC + + } + + // face region + const denom = 1 / ( va + vb + vc ); + // u = va * denom + v = vb * denom; + w = vc * denom; + + return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w ); + + } + + equals( triangle ) { + + return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c ); + + } + +} + +const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF, + 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2, + 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50, + 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B, + 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B, + 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F, + 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3, + 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222, + 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700, + 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4, + 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00, + 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3, + 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA, + 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32, + 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3, + 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC, + 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD, + 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6, + 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9, + 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F, + 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE, + 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA, + 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0, + 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 }; + +const _hslA = { h: 0, s: 0, l: 0 }; +const _hslB = { h: 0, s: 0, l: 0 }; + +function hue2rgb( p, q, t ) { + + if ( t < 0 ) t += 1; + if ( t > 1 ) t -= 1; + if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t; + if ( t < 1 / 2 ) return q; + if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t ); + return p; + +} + +class Color { + + constructor( r, g, b ) { + + this.isColor = true; + + this.r = 1; + this.g = 1; + this.b = 1; + + return this.set( r, g, b ); + + } + + set( r, g, b ) { + + if ( g === undefined && b === undefined ) { + + // r is THREE.Color, hex or string + + const value = r; + + if ( value && value.isColor ) { + + this.copy( value ); + + } else if ( typeof value === 'number' ) { + + this.setHex( value ); + + } else if ( typeof value === 'string' ) { + + this.setStyle( value ); + + } + + } else { + + this.setRGB( r, g, b ); + + } + + return this; + + } + + setScalar( scalar ) { + + this.r = scalar; + this.g = scalar; + this.b = scalar; + + return this; + + } + + setHex( hex, colorSpace = SRGBColorSpace ) { + + hex = Math.floor( hex ); + + this.r = ( hex >> 16 & 255 ) / 255; + this.g = ( hex >> 8 & 255 ) / 255; + this.b = ( hex & 255 ) / 255; + + ColorManagement.toWorkingColorSpace( this, colorSpace ); + + return this; + + } + + setRGB( r, g, b, colorSpace = ColorManagement.workingColorSpace ) { + + this.r = r; + this.g = g; + this.b = b; + + ColorManagement.toWorkingColorSpace( this, colorSpace ); + + return this; + + } + + setHSL( h, s, l, colorSpace = ColorManagement.workingColorSpace ) { + + // h,s,l ranges are in 0.0 - 1.0 + h = euclideanModulo( h, 1 ); + s = clamp( s, 0, 1 ); + l = clamp( l, 0, 1 ); + + if ( s === 0 ) { + + this.r = this.g = this.b = l; + + } else { + + const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s ); + const q = ( 2 * l ) - p; + + this.r = hue2rgb( q, p, h + 1 / 3 ); + this.g = hue2rgb( q, p, h ); + this.b = hue2rgb( q, p, h - 1 / 3 ); + + } + + ColorManagement.toWorkingColorSpace( this, colorSpace ); + + return this; + + } + + setStyle( style, colorSpace = SRGBColorSpace ) { + + function handleAlpha( string ) { + + if ( string === undefined ) return; + + if ( parseFloat( string ) < 1 ) { + + console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' ); + + } + + } + + + let m; + + if ( m = /^(\w+)\(([^\)]*)\)/.exec( style ) ) { + + // rgb / hsl + + let color; + const name = m[ 1 ]; + const components = m[ 2 ]; + + switch ( name ) { + + case 'rgb': + case 'rgba': + + if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) { + + // rgb(255,0,0) rgba(255,0,0,0.5) + + handleAlpha( color[ 4 ] ); + + return this.setRGB( + Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255, + Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255, + Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255, + colorSpace + ); + + } + + if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) { + + // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5) + + handleAlpha( color[ 4 ] ); + + return this.setRGB( + Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100, + Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100, + Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100, + colorSpace + ); + + } + + break; + + case 'hsl': + case 'hsla': + + if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) { + + // hsl(120,50%,50%) hsla(120,50%,50%,0.5) + + handleAlpha( color[ 4 ] ); + + return this.setHSL( + parseFloat( color[ 1 ] ) / 360, + parseFloat( color[ 2 ] ) / 100, + parseFloat( color[ 3 ] ) / 100, + colorSpace + ); + + } + + break; + + default: + + console.warn( 'THREE.Color: Unknown color model ' + style ); + + } + + } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) { + + // hex color + + const hex = m[ 1 ]; + const size = hex.length; + + if ( size === 3 ) { + + // #ff0 + return this.setRGB( + parseInt( hex.charAt( 0 ), 16 ) / 15, + parseInt( hex.charAt( 1 ), 16 ) / 15, + parseInt( hex.charAt( 2 ), 16 ) / 15, + colorSpace + ); + + } else if ( size === 6 ) { + + // #ff0000 + return this.setHex( parseInt( hex, 16 ), colorSpace ); + + } else { + + console.warn( 'THREE.Color: Invalid hex color ' + style ); + + } + + } else if ( style && style.length > 0 ) { + + return this.setColorName( style, colorSpace ); + + } + + return this; + + } + + setColorName( style, colorSpace = SRGBColorSpace ) { + + // color keywords + const hex = _colorKeywords[ style.toLowerCase() ]; + + if ( hex !== undefined ) { + + // red + this.setHex( hex, colorSpace ); + + } else { + + // unknown color + console.warn( 'THREE.Color: Unknown color ' + style ); + + } + + return this; + + } + + clone() { + + return new this.constructor( this.r, this.g, this.b ); + + } + + copy( color ) { + + this.r = color.r; + this.g = color.g; + this.b = color.b; + + return this; + + } + + copySRGBToLinear( color ) { + + this.r = SRGBToLinear( color.r ); + this.g = SRGBToLinear( color.g ); + this.b = SRGBToLinear( color.b ); + + return this; + + } + + copyLinearToSRGB( color ) { + + this.r = LinearToSRGB( color.r ); + this.g = LinearToSRGB( color.g ); + this.b = LinearToSRGB( color.b ); + + return this; + + } + + convertSRGBToLinear() { + + this.copySRGBToLinear( this ); + + return this; + + } + + convertLinearToSRGB() { + + this.copyLinearToSRGB( this ); + + return this; + + } + + getHex( colorSpace = SRGBColorSpace ) { + + ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace ); + + return Math.round( clamp( _color.r * 255, 0, 255 ) ) * 65536 + Math.round( clamp( _color.g * 255, 0, 255 ) ) * 256 + Math.round( clamp( _color.b * 255, 0, 255 ) ); + + } + + getHexString( colorSpace = SRGBColorSpace ) { + + return ( '000000' + this.getHex( colorSpace ).toString( 16 ) ).slice( - 6 ); + + } + + getHSL( target, colorSpace = ColorManagement.workingColorSpace ) { + + // h,s,l ranges are in 0.0 - 1.0 + + ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace ); + + const r = _color.r, g = _color.g, b = _color.b; + + const max = Math.max( r, g, b ); + const min = Math.min( r, g, b ); + + let hue, saturation; + const lightness = ( min + max ) / 2.0; + + if ( min === max ) { + + hue = 0; + saturation = 0; + + } else { + + const delta = max - min; + + saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min ); + + switch ( max ) { + + case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break; + case g: hue = ( b - r ) / delta + 2; break; + case b: hue = ( r - g ) / delta + 4; break; + + } + + hue /= 6; + + } + + target.h = hue; + target.s = saturation; + target.l = lightness; + + return target; + + } + + getRGB( target, colorSpace = ColorManagement.workingColorSpace ) { + + ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace ); + + target.r = _color.r; + target.g = _color.g; + target.b = _color.b; + + return target; + + } + + getStyle( colorSpace = SRGBColorSpace ) { + + ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace ); + + const r = _color.r, g = _color.g, b = _color.b; + + if ( colorSpace !== SRGBColorSpace ) { + + // Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/). + return `color(${ colorSpace } ${ r.toFixed( 3 ) } ${ g.toFixed( 3 ) } ${ b.toFixed( 3 ) })`; + + } + + return `rgb(${ Math.round( r * 255 ) },${ Math.round( g * 255 ) },${ Math.round( b * 255 ) })`; + + } + + offsetHSL( h, s, l ) { + + this.getHSL( _hslA ); + + return this.setHSL( _hslA.h + h, _hslA.s + s, _hslA.l + l ); + + } + + add( color ) { + + this.r += color.r; + this.g += color.g; + this.b += color.b; + + return this; + + } + + addColors( color1, color2 ) { + + this.r = color1.r + color2.r; + this.g = color1.g + color2.g; + this.b = color1.b + color2.b; + + return this; + + } + + addScalar( s ) { + + this.r += s; + this.g += s; + this.b += s; + + return this; + + } + + sub( color ) { + + this.r = Math.max( 0, this.r - color.r ); + this.g = Math.max( 0, this.g - color.g ); + this.b = Math.max( 0, this.b - color.b ); + + return this; + + } + + multiply( color ) { + + this.r *= color.r; + this.g *= color.g; + this.b *= color.b; + + return this; + + } + + multiplyScalar( s ) { + + this.r *= s; + this.g *= s; + this.b *= s; + + return this; + + } + + lerp( color, alpha ) { + + this.r += ( color.r - this.r ) * alpha; + this.g += ( color.g - this.g ) * alpha; + this.b += ( color.b - this.b ) * alpha; + + return this; + + } + + lerpColors( color1, color2, alpha ) { + + this.r = color1.r + ( color2.r - color1.r ) * alpha; + this.g = color1.g + ( color2.g - color1.g ) * alpha; + this.b = color1.b + ( color2.b - color1.b ) * alpha; + + return this; + + } + + lerpHSL( color, alpha ) { + + this.getHSL( _hslA ); + color.getHSL( _hslB ); + + const h = lerp( _hslA.h, _hslB.h, alpha ); + const s = lerp( _hslA.s, _hslB.s, alpha ); + const l = lerp( _hslA.l, _hslB.l, alpha ); + + this.setHSL( h, s, l ); + + return this; + + } + + setFromVector3( v ) { + + this.r = v.x; + this.g = v.y; + this.b = v.z; + + return this; + + } + + applyMatrix3( m ) { + + const r = this.r, g = this.g, b = this.b; + const e = m.elements; + + this.r = e[ 0 ] * r + e[ 3 ] * g + e[ 6 ] * b; + this.g = e[ 1 ] * r + e[ 4 ] * g + e[ 7 ] * b; + this.b = e[ 2 ] * r + e[ 5 ] * g + e[ 8 ] * b; + + return this; + + } + + equals( c ) { + + return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b ); + + } + + fromArray( array, offset = 0 ) { + + this.r = array[ offset ]; + this.g = array[ offset + 1 ]; + this.b = array[ offset + 2 ]; + + return this; + + } + + toArray( array = [], offset = 0 ) { + + array[ offset ] = this.r; + array[ offset + 1 ] = this.g; + array[ offset + 2 ] = this.b; + + return array; + + } + + fromBufferAttribute( attribute, index ) { + + this.r = attribute.getX( index ); + this.g = attribute.getY( index ); + this.b = attribute.getZ( index ); + + return this; + + } + + toJSON() { + + return this.getHex(); + + } + + *[ Symbol.iterator ]() { + + yield this.r; + yield this.g; + yield this.b; + + } + +} + +const _color = /*@__PURE__*/ new Color(); + +Color.NAMES = _colorKeywords; + +let _materialId = 0; + +class Material extends EventDispatcher { + + constructor() { + + super(); + + this.isMaterial = true; + + Object.defineProperty( this, 'id', { value: _materialId ++ } ); + + this.uuid = generateUUID(); + + this.name = ''; + this.type = 'Material'; + + this.blending = NormalBlending; + this.side = FrontSide; + this.vertexColors = false; + + this.opacity = 1; + this.transparent = false; + this.alphaHash = false; + + this.blendSrc = SrcAlphaFactor; + this.blendDst = OneMinusSrcAlphaFactor; + this.blendEquation = AddEquation; + this.blendSrcAlpha = null; + this.blendDstAlpha = null; + this.blendEquationAlpha = null; + this.blendColor = new Color( 0, 0, 0 ); + this.blendAlpha = 0; + + this.depthFunc = LessEqualDepth; + this.depthTest = true; + this.depthWrite = true; + + this.stencilWriteMask = 0xff; + this.stencilFunc = AlwaysStencilFunc; + this.stencilRef = 0; + this.stencilFuncMask = 0xff; + this.stencilFail = KeepStencilOp; + this.stencilZFail = KeepStencilOp; + this.stencilZPass = KeepStencilOp; + this.stencilWrite = false; + + this.clippingPlanes = null; + this.clipIntersection = false; + this.clipShadows = false; + + this.shadowSide = null; + + this.colorWrite = true; + + this.precision = null; // override the renderer's default precision for this material + + this.polygonOffset = false; + this.polygonOffsetFactor = 0; + this.polygonOffsetUnits = 0; + + this.dithering = false; + + this.alphaToCoverage = false; + this.premultipliedAlpha = false; + this.forceSinglePass = false; + + this.visible = true; + + this.toneMapped = true; + + this.userData = {}; + + this.version = 0; + + this._alphaTest = 0; + + } + + get alphaTest() { + + return this._alphaTest; + + } + + set alphaTest( value ) { + + if ( this._alphaTest > 0 !== value > 0 ) { + + this.version ++; + + } + + this._alphaTest = value; + + } + + // onBeforeRender and onBeforeCompile only supported in WebGLRenderer + + onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {} + + onBeforeCompile( /* shaderobject, renderer */ ) {} + + customProgramCacheKey() { + + return this.onBeforeCompile.toString(); + + } + + setValues( values ) { + + if ( values === undefined ) return; + + for ( const key in values ) { + + const newValue = values[ key ]; + + if ( newValue === undefined ) { + + console.warn( `THREE.Material: parameter '${ key }' has value of undefined.` ); + continue; + + } + + const currentValue = this[ key ]; + + if ( currentValue === undefined ) { + + console.warn( `THREE.Material: '${ key }' is not a property of THREE.${ this.type }.` ); + continue; + + } + + if ( currentValue && currentValue.isColor ) { + + currentValue.set( newValue ); + + } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) { + + currentValue.copy( newValue ); + + } else { + + this[ key ] = newValue; + + } + + } + + } + + toJSON( meta ) { + + const isRootObject = ( meta === undefined || typeof meta === 'string' ); + + if ( isRootObject ) { + + meta = { + textures: {}, + images: {} + }; + + } + + const data = { + metadata: { + version: 4.6, + type: 'Material', + generator: 'Material.toJSON' + } + }; + + // standard Material serialization + data.uuid = this.uuid; + data.type = this.type; + + if ( this.name !== '' ) data.name = this.name; + + if ( this.color && this.color.isColor ) data.color = this.color.getHex(); + + if ( this.roughness !== undefined ) data.roughness = this.roughness; + if ( this.metalness !== undefined ) data.metalness = this.metalness; + + if ( this.sheen !== undefined ) data.sheen = this.sheen; + if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex(); + if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness; + if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex(); + if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity; + + if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex(); + if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity; + if ( this.specularColor && this.specularColor.isColor ) data.specularColor = this.specularColor.getHex(); + if ( this.shininess !== undefined ) data.shininess = this.shininess; + if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat; + if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness; + + if ( this.clearcoatMap && this.clearcoatMap.isTexture ) { + + data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid; + + } + + if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) { + + data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid; + + } + + if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) { + + data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid; + data.clearcoatNormalScale = this.clearcoatNormalScale.toArray(); + + } + + if ( this.dispersion !== undefined ) data.dispersion = this.dispersion; + + if ( this.iridescence !== undefined ) data.iridescence = this.iridescence; + if ( this.iridescenceIOR !== undefined ) data.iridescenceIOR = this.iridescenceIOR; + if ( this.iridescenceThicknessRange !== undefined ) data.iridescenceThicknessRange = this.iridescenceThicknessRange; + + if ( this.iridescenceMap && this.iridescenceMap.isTexture ) { + + data.iridescenceMap = this.iridescenceMap.toJSON( meta ).uuid; + + } + + if ( this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture ) { + + data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON( meta ).uuid; + + } + + if ( this.anisotropy !== undefined ) data.anisotropy = this.anisotropy; + if ( this.anisotropyRotation !== undefined ) data.anisotropyRotation = this.anisotropyRotation; + + if ( this.anisotropyMap && this.anisotropyMap.isTexture ) { + + data.anisotropyMap = this.anisotropyMap.toJSON( meta ).uuid; + + } + + if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid; + if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid; + if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid; + + if ( this.lightMap && this.lightMap.isTexture ) { + + data.lightMap = this.lightMap.toJSON( meta ).uuid; + data.lightMapIntensity = this.lightMapIntensity; + + } + + if ( this.aoMap && this.aoMap.isTexture ) { + + data.aoMap = this.aoMap.toJSON( meta ).uuid; + data.aoMapIntensity = this.aoMapIntensity; + + } + + if ( this.bumpMap && this.bumpMap.isTexture ) { + + data.bumpMap = this.bumpMap.toJSON( meta ).uuid; + data.bumpScale = this.bumpScale; + + } + + if ( this.normalMap && this.normalMap.isTexture ) { + + data.normalMap = this.normalMap.toJSON( meta ).uuid; + data.normalMapType = this.normalMapType; + data.normalScale = this.normalScale.toArray(); + + } + + if ( this.displacementMap && this.displacementMap.isTexture ) { + + data.displacementMap = this.displacementMap.toJSON( meta ).uuid; + data.displacementScale = this.displacementScale; + data.displacementBias = this.displacementBias; + + } + + if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid; + if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid; + + if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid; + if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid; + if ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid; + if ( this.specularColorMap && this.specularColorMap.isTexture ) data.specularColorMap = this.specularColorMap.toJSON( meta ).uuid; + + if ( this.envMap && this.envMap.isTexture ) { + + data.envMap = this.envMap.toJSON( meta ).uuid; + + if ( this.combine !== undefined ) data.combine = this.combine; + + } + + if ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray(); + if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity; + if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity; + if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio; + + if ( this.gradientMap && this.gradientMap.isTexture ) { + + data.gradientMap = this.gradientMap.toJSON( meta ).uuid; + + } + + if ( this.transmission !== undefined ) data.transmission = this.transmission; + if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid; + if ( this.thickness !== undefined ) data.thickness = this.thickness; + if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid; + if ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance; + if ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex(); + + if ( this.size !== undefined ) data.size = this.size; + if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide; + if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation; + + if ( this.blending !== NormalBlending ) data.blending = this.blending; + if ( this.side !== FrontSide ) data.side = this.side; + if ( this.vertexColors === true ) data.vertexColors = true; + + if ( this.opacity < 1 ) data.opacity = this.opacity; + if ( this.transparent === true ) data.transparent = true; + + if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc; + if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst; + if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation; + if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha; + if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha; + if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha; + if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex(); + if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha; + + if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc; + if ( this.depthTest === false ) data.depthTest = this.depthTest; + if ( this.depthWrite === false ) data.depthWrite = this.depthWrite; + if ( this.colorWrite === false ) data.colorWrite = this.colorWrite; + + if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask; + if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc; + if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef; + if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask; + if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail; + if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail; + if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass; + if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite; + + // rotation (SpriteMaterial) + if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation; + + if ( this.polygonOffset === true ) data.polygonOffset = true; + if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor; + if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits; + + if ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth; + if ( this.dashSize !== undefined ) data.dashSize = this.dashSize; + if ( this.gapSize !== undefined ) data.gapSize = this.gapSize; + if ( this.scale !== undefined ) data.scale = this.scale; + + if ( this.dithering === true ) data.dithering = true; + + if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest; + if ( this.alphaHash === true ) data.alphaHash = true; + if ( this.alphaToCoverage === true ) data.alphaToCoverage = true; + if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true; + if ( this.forceSinglePass === true ) data.forceSinglePass = true; + + if ( this.wireframe === true ) data.wireframe = true; + if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth; + if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap; + if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin; + + if ( this.flatShading === true ) data.flatShading = true; + + if ( this.visible === false ) data.visible = false; + + if ( this.toneMapped === false ) data.toneMapped = false; + + if ( this.fog === false ) data.fog = false; + + if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData; + + // TODO: Copied from Object3D.toJSON + + function extractFromCache( cache ) { + + const values = []; + + for ( const key in cache ) { + + const data = cache[ key ]; + delete data.metadata; + values.push( data ); + + } + + return values; + + } + + if ( isRootObject ) { + + const textures = extractFromCache( meta.textures ); + const images = extractFromCache( meta.images ); + + if ( textures.length > 0 ) data.textures = textures; + if ( images.length > 0 ) data.images = images; + + } + + return data; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( source ) { + + this.name = source.name; + + this.blending = source.blending; + this.side = source.side; + this.vertexColors = source.vertexColors; + + this.opacity = source.opacity; + this.transparent = source.transparent; + + this.blendSrc = source.blendSrc; + this.blendDst = source.blendDst; + this.blendEquation = source.blendEquation; + this.blendSrcAlpha = source.blendSrcAlpha; + this.blendDstAlpha = source.blendDstAlpha; + this.blendEquationAlpha = source.blendEquationAlpha; + this.blendColor.copy( source.blendColor ); + this.blendAlpha = source.blendAlpha; + + this.depthFunc = source.depthFunc; + this.depthTest = source.depthTest; + this.depthWrite = source.depthWrite; + + this.stencilWriteMask = source.stencilWriteMask; + this.stencilFunc = source.stencilFunc; + this.stencilRef = source.stencilRef; + this.stencilFuncMask = source.stencilFuncMask; + this.stencilFail = source.stencilFail; + this.stencilZFail = source.stencilZFail; + this.stencilZPass = source.stencilZPass; + this.stencilWrite = source.stencilWrite; + + const srcPlanes = source.clippingPlanes; + let dstPlanes = null; + + if ( srcPlanes !== null ) { + + const n = srcPlanes.length; + dstPlanes = new Array( n ); + + for ( let i = 0; i !== n; ++ i ) { + + dstPlanes[ i ] = srcPlanes[ i ].clone(); + + } + + } + + this.clippingPlanes = dstPlanes; + this.clipIntersection = source.clipIntersection; + this.clipShadows = source.clipShadows; + + this.shadowSide = source.shadowSide; + + this.colorWrite = source.colorWrite; + + this.precision = source.precision; + + this.polygonOffset = source.polygonOffset; + this.polygonOffsetFactor = source.polygonOffsetFactor; + this.polygonOffsetUnits = source.polygonOffsetUnits; + + this.dithering = source.dithering; + + this.alphaTest = source.alphaTest; + this.alphaHash = source.alphaHash; + this.alphaToCoverage = source.alphaToCoverage; + this.premultipliedAlpha = source.premultipliedAlpha; + this.forceSinglePass = source.forceSinglePass; + + this.visible = source.visible; + + this.toneMapped = source.toneMapped; + + this.userData = JSON.parse( JSON.stringify( source.userData ) ); + + return this; + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + onBuild( /* shaderobject, renderer */ ) { + + console.warn( 'Material: onBuild() has been removed.' ); // @deprecated, r166 + + } + +} + +class MeshBasicMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshBasicMaterial = true; + + this.type = 'MeshBasicMaterial'; + + this.color = new Color( 0xffffff ); // emissive + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.specularMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.envMapRotation = new Euler(); + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.specularMap = source.specularMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapRotation.copy( source.envMapRotation ); + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.fog = source.fog; + + return this; + + } + +} + +// Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf + +const _tables = /*@__PURE__*/ _generateTables(); + +function _generateTables() { + + // float32 to float16 helpers + + const buffer = new ArrayBuffer( 4 ); + const floatView = new Float32Array( buffer ); + const uint32View = new Uint32Array( buffer ); + + const baseTable = new Uint32Array( 512 ); + const shiftTable = new Uint32Array( 512 ); + + for ( let i = 0; i < 256; ++ i ) { + + const e = i - 127; + + // very small number (0, -0) + + if ( e < - 27 ) { + + baseTable[ i ] = 0x0000; + baseTable[ i | 0x100 ] = 0x8000; + shiftTable[ i ] = 24; + shiftTable[ i | 0x100 ] = 24; + + // small number (denorm) + + } else if ( e < - 14 ) { + + baseTable[ i ] = 0x0400 >> ( - e - 14 ); + baseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000; + shiftTable[ i ] = - e - 1; + shiftTable[ i | 0x100 ] = - e - 1; + + // normal number + + } else if ( e <= 15 ) { + + baseTable[ i ] = ( e + 15 ) << 10; + baseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000; + shiftTable[ i ] = 13; + shiftTable[ i | 0x100 ] = 13; + + // large number (Infinity, -Infinity) + + } else if ( e < 128 ) { + + baseTable[ i ] = 0x7c00; + baseTable[ i | 0x100 ] = 0xfc00; + shiftTable[ i ] = 24; + shiftTable[ i | 0x100 ] = 24; + + // stay (NaN, Infinity, -Infinity) + + } else { + + baseTable[ i ] = 0x7c00; + baseTable[ i | 0x100 ] = 0xfc00; + shiftTable[ i ] = 13; + shiftTable[ i | 0x100 ] = 13; + + } + + } + + // float16 to float32 helpers + + const mantissaTable = new Uint32Array( 2048 ); + const exponentTable = new Uint32Array( 64 ); + const offsetTable = new Uint32Array( 64 ); + + for ( let i = 1; i < 1024; ++ i ) { + + let m = i << 13; // zero pad mantissa bits + let e = 0; // zero exponent + + // normalized + while ( ( m & 0x00800000 ) === 0 ) { + + m <<= 1; + e -= 0x00800000; // decrement exponent + + } + + m &= ~ 0x00800000; // clear leading 1 bit + e += 0x38800000; // adjust bias + + mantissaTable[ i ] = m | e; + + } + + for ( let i = 1024; i < 2048; ++ i ) { + + mantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 ); + + } + + for ( let i = 1; i < 31; ++ i ) { + + exponentTable[ i ] = i << 23; + + } + + exponentTable[ 31 ] = 0x47800000; + exponentTable[ 32 ] = 0x80000000; + + for ( let i = 33; i < 63; ++ i ) { + + exponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 ); + + } + + exponentTable[ 63 ] = 0xc7800000; + + for ( let i = 1; i < 64; ++ i ) { + + if ( i !== 32 ) { + + offsetTable[ i ] = 1024; + + } + + } + + return { + floatView: floatView, + uint32View: uint32View, + baseTable: baseTable, + shiftTable: shiftTable, + mantissaTable: mantissaTable, + exponentTable: exponentTable, + offsetTable: offsetTable + }; + +} + +// float32 to float16 + +function toHalfFloat( val ) { + + if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' ); + + val = clamp( val, - 65504, 65504 ); + + _tables.floatView[ 0 ] = val; + const f = _tables.uint32View[ 0 ]; + const e = ( f >> 23 ) & 0x1ff; + return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] ); + +} + +// float16 to float32 + +function fromHalfFloat( val ) { + + const m = val >> 10; + _tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ]; + return _tables.floatView[ 0 ]; + +} + +const DataUtils = { + toHalfFloat: toHalfFloat, + fromHalfFloat: fromHalfFloat, +}; + +const _vector$9 = /*@__PURE__*/ new Vector3(); +const _vector2$1 = /*@__PURE__*/ new Vector2(); + +class BufferAttribute { + + constructor( array, itemSize, normalized = false ) { + + if ( Array.isArray( array ) ) { + + throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' ); + + } + + this.isBufferAttribute = true; + + this.name = ''; + + this.array = array; + this.itemSize = itemSize; + this.count = array !== undefined ? array.length / itemSize : 0; + this.normalized = normalized; + + this.usage = StaticDrawUsage; + this.updateRanges = []; + this.gpuType = FloatType; + + this.version = 0; + + } + + onUploadCallback() {} + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + setUsage( value ) { + + this.usage = value; + + return this; + + } + + addUpdateRange( start, count ) { + + this.updateRanges.push( { start, count } ); + + } + + clearUpdateRanges() { + + this.updateRanges.length = 0; + + } + + copy( source ) { + + this.name = source.name; + this.array = new source.array.constructor( source.array ); + this.itemSize = source.itemSize; + this.count = source.count; + this.normalized = source.normalized; + + this.usage = source.usage; + this.gpuType = source.gpuType; + + return this; + + } + + copyAt( index1, attribute, index2 ) { + + index1 *= this.itemSize; + index2 *= attribute.itemSize; + + for ( let i = 0, l = this.itemSize; i < l; i ++ ) { + + this.array[ index1 + i ] = attribute.array[ index2 + i ]; + + } + + return this; + + } + + copyArray( array ) { + + this.array.set( array ); + + return this; + + } + + applyMatrix3( m ) { + + if ( this.itemSize === 2 ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector2$1.fromBufferAttribute( this, i ); + _vector2$1.applyMatrix3( m ); + + this.setXY( i, _vector2$1.x, _vector2$1.y ); + + } + + } else if ( this.itemSize === 3 ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector$9.fromBufferAttribute( this, i ); + _vector$9.applyMatrix3( m ); + + this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z ); + + } + + } + + return this; + + } + + applyMatrix4( m ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector$9.fromBufferAttribute( this, i ); + + _vector$9.applyMatrix4( m ); + + this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z ); + + } + + return this; + + } + + applyNormalMatrix( m ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector$9.fromBufferAttribute( this, i ); + + _vector$9.applyNormalMatrix( m ); + + this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z ); + + } + + return this; + + } + + transformDirection( m ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector$9.fromBufferAttribute( this, i ); + + _vector$9.transformDirection( m ); + + this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z ); + + } + + return this; + + } + + set( value, offset = 0 ) { + + // Matching BufferAttribute constructor, do not normalize the array. + this.array.set( value, offset ); + + return this; + + } + + getComponent( index, component ) { + + let value = this.array[ index * this.itemSize + component ]; + + if ( this.normalized ) value = denormalize( value, this.array ); + + return value; + + } + + setComponent( index, component, value ) { + + if ( this.normalized ) value = normalize( value, this.array ); + + this.array[ index * this.itemSize + component ] = value; + + return this; + + } + + getX( index ) { + + let x = this.array[ index * this.itemSize ]; + + if ( this.normalized ) x = denormalize( x, this.array ); + + return x; + + } + + setX( index, x ) { + + if ( this.normalized ) x = normalize( x, this.array ); + + this.array[ index * this.itemSize ] = x; + + return this; + + } + + getY( index ) { + + let y = this.array[ index * this.itemSize + 1 ]; + + if ( this.normalized ) y = denormalize( y, this.array ); + + return y; + + } + + setY( index, y ) { + + if ( this.normalized ) y = normalize( y, this.array ); + + this.array[ index * this.itemSize + 1 ] = y; + + return this; + + } + + getZ( index ) { + + let z = this.array[ index * this.itemSize + 2 ]; + + if ( this.normalized ) z = denormalize( z, this.array ); + + return z; + + } + + setZ( index, z ) { + + if ( this.normalized ) z = normalize( z, this.array ); + + this.array[ index * this.itemSize + 2 ] = z; + + return this; + + } + + getW( index ) { + + let w = this.array[ index * this.itemSize + 3 ]; + + if ( this.normalized ) w = denormalize( w, this.array ); + + return w; + + } + + setW( index, w ) { + + if ( this.normalized ) w = normalize( w, this.array ); + + this.array[ index * this.itemSize + 3 ] = w; + + return this; + + } + + setXY( index, x, y ) { + + index *= this.itemSize; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + + } + + this.array[ index + 0 ] = x; + this.array[ index + 1 ] = y; + + return this; + + } + + setXYZ( index, x, y, z ) { + + index *= this.itemSize; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + z = normalize( z, this.array ); + + } + + this.array[ index + 0 ] = x; + this.array[ index + 1 ] = y; + this.array[ index + 2 ] = z; + + return this; + + } + + setXYZW( index, x, y, z, w ) { + + index *= this.itemSize; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + z = normalize( z, this.array ); + w = normalize( w, this.array ); + + } + + this.array[ index + 0 ] = x; + this.array[ index + 1 ] = y; + this.array[ index + 2 ] = z; + this.array[ index + 3 ] = w; + + return this; + + } + + onUpload( callback ) { + + this.onUploadCallback = callback; + + return this; + + } + + clone() { + + return new this.constructor( this.array, this.itemSize ).copy( this ); + + } + + toJSON() { + + const data = { + itemSize: this.itemSize, + type: this.array.constructor.name, + array: Array.from( this.array ), + normalized: this.normalized + }; + + if ( this.name !== '' ) data.name = this.name; + if ( this.usage !== StaticDrawUsage ) data.usage = this.usage; + + return data; + + } + +} + +// + +class Int8BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Int8Array( array ), itemSize, normalized ); + + } + +} + +class Uint8BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Uint8Array( array ), itemSize, normalized ); + + } + +} + +class Uint8ClampedBufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Uint8ClampedArray( array ), itemSize, normalized ); + + } + +} + +class Int16BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Int16Array( array ), itemSize, normalized ); + + } + +} + +class Uint16BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Uint16Array( array ), itemSize, normalized ); + + } + +} + +class Int32BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Int32Array( array ), itemSize, normalized ); + + } + +} + +class Uint32BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Uint32Array( array ), itemSize, normalized ); + + } + +} + +class Float16BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Uint16Array( array ), itemSize, normalized ); + + this.isFloat16BufferAttribute = true; + + } + + getX( index ) { + + let x = fromHalfFloat( this.array[ index * this.itemSize ] ); + + if ( this.normalized ) x = denormalize( x, this.array ); + + return x; + + } + + setX( index, x ) { + + if ( this.normalized ) x = normalize( x, this.array ); + + this.array[ index * this.itemSize ] = toHalfFloat( x ); + + return this; + + } + + getY( index ) { + + let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] ); + + if ( this.normalized ) y = denormalize( y, this.array ); + + return y; + + } + + setY( index, y ) { + + if ( this.normalized ) y = normalize( y, this.array ); + + this.array[ index * this.itemSize + 1 ] = toHalfFloat( y ); + + return this; + + } + + getZ( index ) { + + let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] ); + + if ( this.normalized ) z = denormalize( z, this.array ); + + return z; + + } + + setZ( index, z ) { + + if ( this.normalized ) z = normalize( z, this.array ); + + this.array[ index * this.itemSize + 2 ] = toHalfFloat( z ); + + return this; + + } + + getW( index ) { + + let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] ); + + if ( this.normalized ) w = denormalize( w, this.array ); + + return w; + + } + + setW( index, w ) { + + if ( this.normalized ) w = normalize( w, this.array ); + + this.array[ index * this.itemSize + 3 ] = toHalfFloat( w ); + + return this; + + } + + setXY( index, x, y ) { + + index *= this.itemSize; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + + } + + this.array[ index + 0 ] = toHalfFloat( x ); + this.array[ index + 1 ] = toHalfFloat( y ); + + return this; + + } + + setXYZ( index, x, y, z ) { + + index *= this.itemSize; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + z = normalize( z, this.array ); + + } + + this.array[ index + 0 ] = toHalfFloat( x ); + this.array[ index + 1 ] = toHalfFloat( y ); + this.array[ index + 2 ] = toHalfFloat( z ); + + return this; + + } + + setXYZW( index, x, y, z, w ) { + + index *= this.itemSize; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + z = normalize( z, this.array ); + w = normalize( w, this.array ); + + } + + this.array[ index + 0 ] = toHalfFloat( x ); + this.array[ index + 1 ] = toHalfFloat( y ); + this.array[ index + 2 ] = toHalfFloat( z ); + this.array[ index + 3 ] = toHalfFloat( w ); + + return this; + + } + +} + + +class Float32BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { + + super( new Float32Array( array ), itemSize, normalized ); + + } + +} + +let _id$1 = 0; + +const _m1 = /*@__PURE__*/ new Matrix4(); +const _obj = /*@__PURE__*/ new Object3D(); +const _offset = /*@__PURE__*/ new Vector3(); +const _box$2 = /*@__PURE__*/ new Box3(); +const _boxMorphTargets = /*@__PURE__*/ new Box3(); +const _vector$8 = /*@__PURE__*/ new Vector3(); + +class BufferGeometry extends EventDispatcher { + + constructor() { + + super(); + + this.isBufferGeometry = true; + + Object.defineProperty( this, 'id', { value: _id$1 ++ } ); + + this.uuid = generateUUID(); + + this.name = ''; + this.type = 'BufferGeometry'; + + this.index = null; + this.indirect = null; + this.attributes = {}; + + this.morphAttributes = {}; + this.morphTargetsRelative = false; + + this.groups = []; + + this.boundingBox = null; + this.boundingSphere = null; + + this.drawRange = { start: 0, count: Infinity }; + + this.userData = {}; + + } + + getIndex() { + + return this.index; + + } + + setIndex( index ) { + + if ( Array.isArray( index ) ) { + + this.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 ); + + } else { + + this.index = index; + + } + + return this; + + } + + setIndirect( indirect ) { + + this.indirect = indirect; + + return this; + + } + + getIndirect() { + + return this.indirect; + + } + + getAttribute( name ) { + + return this.attributes[ name ]; + + } + + setAttribute( name, attribute ) { + + this.attributes[ name ] = attribute; + + return this; + + } + + deleteAttribute( name ) { + + delete this.attributes[ name ]; + + return this; + + } + + hasAttribute( name ) { + + return this.attributes[ name ] !== undefined; + + } + + addGroup( start, count, materialIndex = 0 ) { + + this.groups.push( { + + start: start, + count: count, + materialIndex: materialIndex + + } ); + + } + + clearGroups() { + + this.groups = []; + + } + + setDrawRange( start, count ) { + + this.drawRange.start = start; + this.drawRange.count = count; + + } + + applyMatrix4( matrix ) { + + const position = this.attributes.position; + + if ( position !== undefined ) { + + position.applyMatrix4( matrix ); + + position.needsUpdate = true; + + } + + const normal = this.attributes.normal; + + if ( normal !== undefined ) { + + const normalMatrix = new Matrix3().getNormalMatrix( matrix ); + + normal.applyNormalMatrix( normalMatrix ); + + normal.needsUpdate = true; + + } + + const tangent = this.attributes.tangent; + + if ( tangent !== undefined ) { + + tangent.transformDirection( matrix ); + + tangent.needsUpdate = true; + + } + + if ( this.boundingBox !== null ) { + + this.computeBoundingBox(); + + } + + if ( this.boundingSphere !== null ) { + + this.computeBoundingSphere(); + + } + + return this; + + } + + applyQuaternion( q ) { + + _m1.makeRotationFromQuaternion( q ); + + this.applyMatrix4( _m1 ); + + return this; + + } + + rotateX( angle ) { + + // rotate geometry around world x-axis + + _m1.makeRotationX( angle ); + + this.applyMatrix4( _m1 ); + + return this; + + } + + rotateY( angle ) { + + // rotate geometry around world y-axis + + _m1.makeRotationY( angle ); + + this.applyMatrix4( _m1 ); + + return this; + + } + + rotateZ( angle ) { + + // rotate geometry around world z-axis + + _m1.makeRotationZ( angle ); + + this.applyMatrix4( _m1 ); + + return this; + + } + + translate( x, y, z ) { + + // translate geometry + + _m1.makeTranslation( x, y, z ); + + this.applyMatrix4( _m1 ); + + return this; + + } + + scale( x, y, z ) { + + // scale geometry + + _m1.makeScale( x, y, z ); + + this.applyMatrix4( _m1 ); + + return this; + + } + + lookAt( vector ) { + + _obj.lookAt( vector ); + + _obj.updateMatrix(); + + this.applyMatrix4( _obj.matrix ); + + return this; + + } + + center() { + + this.computeBoundingBox(); + + this.boundingBox.getCenter( _offset ).negate(); + + this.translate( _offset.x, _offset.y, _offset.z ); + + return this; + + } + + setFromPoints( points ) { + + const positionAttribute = this.getAttribute( 'position' ); + + if ( positionAttribute === undefined ) { + + const position = []; + + for ( let i = 0, l = points.length; i < l; i ++ ) { + + const point = points[ i ]; + position.push( point.x, point.y, point.z || 0 ); + + } + + this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) ); + + } else { + + const l = Math.min( points.length, positionAttribute.count ); // make sure data do not exceed buffer size + + for ( let i = 0; i < l; i ++ ) { + + const point = points[ i ]; + positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 ); + + } + + if ( points.length > positionAttribute.count ) { + + console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' ); + + } + + positionAttribute.needsUpdate = true; + + } + + return this; + + } + + computeBoundingBox() { + + if ( this.boundingBox === null ) { + + this.boundingBox = new Box3(); + + } + + const position = this.attributes.position; + const morphAttributesPosition = this.morphAttributes.position; + + if ( position && position.isGLBufferAttribute ) { + + console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this ); + + this.boundingBox.set( + new Vector3( - Infinity, - Infinity, - Infinity ), + new Vector3( + Infinity, + Infinity, + Infinity ) + ); + + return; + + } + + if ( position !== undefined ) { + + this.boundingBox.setFromBufferAttribute( position ); + + // process morph attributes if present + + if ( morphAttributesPosition ) { + + for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) { + + const morphAttribute = morphAttributesPosition[ i ]; + _box$2.setFromBufferAttribute( morphAttribute ); + + if ( this.morphTargetsRelative ) { + + _vector$8.addVectors( this.boundingBox.min, _box$2.min ); + this.boundingBox.expandByPoint( _vector$8 ); + + _vector$8.addVectors( this.boundingBox.max, _box$2.max ); + this.boundingBox.expandByPoint( _vector$8 ); + + } else { + + this.boundingBox.expandByPoint( _box$2.min ); + this.boundingBox.expandByPoint( _box$2.max ); + + } + + } + + } + + } else { + + this.boundingBox.makeEmpty(); + + } + + if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) { + + console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this ); + + } + + } + + computeBoundingSphere() { + + if ( this.boundingSphere === null ) { + + this.boundingSphere = new Sphere(); + + } + + const position = this.attributes.position; + const morphAttributesPosition = this.morphAttributes.position; + + if ( position && position.isGLBufferAttribute ) { + + console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this ); + + this.boundingSphere.set( new Vector3(), Infinity ); + + return; + + } + + if ( position ) { + + // first, find the center of the bounding sphere + + const center = this.boundingSphere.center; + + _box$2.setFromBufferAttribute( position ); + + // process morph attributes if present + + if ( morphAttributesPosition ) { + + for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) { + + const morphAttribute = morphAttributesPosition[ i ]; + _boxMorphTargets.setFromBufferAttribute( morphAttribute ); + + if ( this.morphTargetsRelative ) { + + _vector$8.addVectors( _box$2.min, _boxMorphTargets.min ); + _box$2.expandByPoint( _vector$8 ); + + _vector$8.addVectors( _box$2.max, _boxMorphTargets.max ); + _box$2.expandByPoint( _vector$8 ); + + } else { + + _box$2.expandByPoint( _boxMorphTargets.min ); + _box$2.expandByPoint( _boxMorphTargets.max ); + + } + + } + + } + + _box$2.getCenter( center ); + + // second, try to find a boundingSphere with a radius smaller than the + // boundingSphere of the boundingBox: sqrt(3) smaller in the best case + + let maxRadiusSq = 0; + + for ( let i = 0, il = position.count; i < il; i ++ ) { + + _vector$8.fromBufferAttribute( position, i ); + + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) ); + + } + + // process morph attributes if present + + if ( morphAttributesPosition ) { + + for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) { + + const morphAttribute = morphAttributesPosition[ i ]; + const morphTargetsRelative = this.morphTargetsRelative; + + for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) { + + _vector$8.fromBufferAttribute( morphAttribute, j ); + + if ( morphTargetsRelative ) { + + _offset.fromBufferAttribute( position, j ); + _vector$8.add( _offset ); + + } + + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) ); + + } + + } + + } + + this.boundingSphere.radius = Math.sqrt( maxRadiusSq ); + + if ( isNaN( this.boundingSphere.radius ) ) { + + console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this ); + + } + + } + + } + + computeTangents() { + + const index = this.index; + const attributes = this.attributes; + + // based on http://www.terathon.com/code/tangent.html + // (per vertex tangents) + + if ( index === null || + attributes.position === undefined || + attributes.normal === undefined || + attributes.uv === undefined ) { + + console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' ); + return; + + } + + const positionAttribute = attributes.position; + const normalAttribute = attributes.normal; + const uvAttribute = attributes.uv; + + if ( this.hasAttribute( 'tangent' ) === false ) { + + this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) ); + + } + + const tangentAttribute = this.getAttribute( 'tangent' ); + + const tan1 = [], tan2 = []; + + for ( let i = 0; i < positionAttribute.count; i ++ ) { + + tan1[ i ] = new Vector3(); + tan2[ i ] = new Vector3(); + + } + + const vA = new Vector3(), + vB = new Vector3(), + vC = new Vector3(), + + uvA = new Vector2(), + uvB = new Vector2(), + uvC = new Vector2(), + + sdir = new Vector3(), + tdir = new Vector3(); + + function handleTriangle( a, b, c ) { + + vA.fromBufferAttribute( positionAttribute, a ); + vB.fromBufferAttribute( positionAttribute, b ); + vC.fromBufferAttribute( positionAttribute, c ); + + uvA.fromBufferAttribute( uvAttribute, a ); + uvB.fromBufferAttribute( uvAttribute, b ); + uvC.fromBufferAttribute( uvAttribute, c ); + + vB.sub( vA ); + vC.sub( vA ); + + uvB.sub( uvA ); + uvC.sub( uvA ); + + const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y ); + + // silently ignore degenerate uv triangles having coincident or colinear vertices + + if ( ! isFinite( r ) ) return; + + sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r ); + tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r ); + + tan1[ a ].add( sdir ); + tan1[ b ].add( sdir ); + tan1[ c ].add( sdir ); + + tan2[ a ].add( tdir ); + tan2[ b ].add( tdir ); + tan2[ c ].add( tdir ); + + } + + let groups = this.groups; + + if ( groups.length === 0 ) { + + groups = [ { + start: 0, + count: index.count + } ]; + + } + + for ( let i = 0, il = groups.length; i < il; ++ i ) { + + const group = groups[ i ]; + + const start = group.start; + const count = group.count; + + for ( let j = start, jl = start + count; j < jl; j += 3 ) { + + handleTriangle( + index.getX( j + 0 ), + index.getX( j + 1 ), + index.getX( j + 2 ) + ); + + } + + } + + const tmp = new Vector3(), tmp2 = new Vector3(); + const n = new Vector3(), n2 = new Vector3(); + + function handleVertex( v ) { + + n.fromBufferAttribute( normalAttribute, v ); + n2.copy( n ); + + const t = tan1[ v ]; + + // Gram-Schmidt orthogonalize + + tmp.copy( t ); + tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize(); + + // Calculate handedness + + tmp2.crossVectors( n2, t ); + const test = tmp2.dot( tan2[ v ] ); + const w = ( test < 0.0 ) ? - 1.0 : 1.0; + + tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w ); + + } + + for ( let i = 0, il = groups.length; i < il; ++ i ) { + + const group = groups[ i ]; + + const start = group.start; + const count = group.count; + + for ( let j = start, jl = start + count; j < jl; j += 3 ) { + + handleVertex( index.getX( j + 0 ) ); + handleVertex( index.getX( j + 1 ) ); + handleVertex( index.getX( j + 2 ) ); + + } + + } + + } + + computeVertexNormals() { + + const index = this.index; + const positionAttribute = this.getAttribute( 'position' ); + + if ( positionAttribute !== undefined ) { + + let normalAttribute = this.getAttribute( 'normal' ); + + if ( normalAttribute === undefined ) { + + normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 ); + this.setAttribute( 'normal', normalAttribute ); + + } else { + + // reset existing normals to zero + + for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) { + + normalAttribute.setXYZ( i, 0, 0, 0 ); + + } + + } + + const pA = new Vector3(), pB = new Vector3(), pC = new Vector3(); + const nA = new Vector3(), nB = new Vector3(), nC = new Vector3(); + const cb = new Vector3(), ab = new Vector3(); + + // indexed elements + + if ( index ) { + + for ( let i = 0, il = index.count; i < il; i += 3 ) { + + const vA = index.getX( i + 0 ); + const vB = index.getX( i + 1 ); + const vC = index.getX( i + 2 ); + + pA.fromBufferAttribute( positionAttribute, vA ); + pB.fromBufferAttribute( positionAttribute, vB ); + pC.fromBufferAttribute( positionAttribute, vC ); + + cb.subVectors( pC, pB ); + ab.subVectors( pA, pB ); + cb.cross( ab ); + + nA.fromBufferAttribute( normalAttribute, vA ); + nB.fromBufferAttribute( normalAttribute, vB ); + nC.fromBufferAttribute( normalAttribute, vC ); + + nA.add( cb ); + nB.add( cb ); + nC.add( cb ); + + normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z ); + normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z ); + normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z ); + + } + + } else { + + // non-indexed elements (unconnected triangle soup) + + for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) { + + pA.fromBufferAttribute( positionAttribute, i + 0 ); + pB.fromBufferAttribute( positionAttribute, i + 1 ); + pC.fromBufferAttribute( positionAttribute, i + 2 ); + + cb.subVectors( pC, pB ); + ab.subVectors( pA, pB ); + cb.cross( ab ); + + normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z ); + normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z ); + normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z ); + + } + + } + + this.normalizeNormals(); + + normalAttribute.needsUpdate = true; + + } + + } + + normalizeNormals() { + + const normals = this.attributes.normal; + + for ( let i = 0, il = normals.count; i < il; i ++ ) { + + _vector$8.fromBufferAttribute( normals, i ); + + _vector$8.normalize(); + + normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z ); + + } + + } + + toNonIndexed() { + + function convertBufferAttribute( attribute, indices ) { + + const array = attribute.array; + const itemSize = attribute.itemSize; + const normalized = attribute.normalized; + + const array2 = new array.constructor( indices.length * itemSize ); + + let index = 0, index2 = 0; + + for ( let i = 0, l = indices.length; i < l; i ++ ) { + + if ( attribute.isInterleavedBufferAttribute ) { + + index = indices[ i ] * attribute.data.stride + attribute.offset; + + } else { + + index = indices[ i ] * itemSize; + + } + + for ( let j = 0; j < itemSize; j ++ ) { + + array2[ index2 ++ ] = array[ index ++ ]; + + } + + } + + return new BufferAttribute( array2, itemSize, normalized ); + + } + + // + + if ( this.index === null ) { + + console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' ); + return this; + + } + + const geometry2 = new BufferGeometry(); + + const indices = this.index.array; + const attributes = this.attributes; + + // attributes + + for ( const name in attributes ) { + + const attribute = attributes[ name ]; + + const newAttribute = convertBufferAttribute( attribute, indices ); + + geometry2.setAttribute( name, newAttribute ); + + } + + // morph attributes + + const morphAttributes = this.morphAttributes; + + for ( const name in morphAttributes ) { + + const morphArray = []; + const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes + + for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) { + + const attribute = morphAttribute[ i ]; + + const newAttribute = convertBufferAttribute( attribute, indices ); + + morphArray.push( newAttribute ); + + } + + geometry2.morphAttributes[ name ] = morphArray; + + } + + geometry2.morphTargetsRelative = this.morphTargetsRelative; + + // groups + + const groups = this.groups; + + for ( let i = 0, l = groups.length; i < l; i ++ ) { + + const group = groups[ i ]; + geometry2.addGroup( group.start, group.count, group.materialIndex ); + + } + + return geometry2; + + } + + toJSON() { + + const data = { + metadata: { + version: 4.6, + type: 'BufferGeometry', + generator: 'BufferGeometry.toJSON' + } + }; + + // standard BufferGeometry serialization + + data.uuid = this.uuid; + data.type = this.type; + if ( this.name !== '' ) data.name = this.name; + if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData; + + if ( this.parameters !== undefined ) { + + const parameters = this.parameters; + + for ( const key in parameters ) { + + if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ]; + + } + + return data; + + } + + // for simplicity the code assumes attributes are not shared across geometries, see #15811 + + data.data = { attributes: {} }; + + const index = this.index; + + if ( index !== null ) { + + data.data.index = { + type: index.array.constructor.name, + array: Array.prototype.slice.call( index.array ) + }; + + } + + const attributes = this.attributes; + + for ( const key in attributes ) { + + const attribute = attributes[ key ]; + + data.data.attributes[ key ] = attribute.toJSON( data.data ); + + } + + const morphAttributes = {}; + let hasMorphAttributes = false; + + for ( const key in this.morphAttributes ) { + + const attributeArray = this.morphAttributes[ key ]; + + const array = []; + + for ( let i = 0, il = attributeArray.length; i < il; i ++ ) { + + const attribute = attributeArray[ i ]; + + array.push( attribute.toJSON( data.data ) ); + + } + + if ( array.length > 0 ) { + + morphAttributes[ key ] = array; + + hasMorphAttributes = true; + + } + + } + + if ( hasMorphAttributes ) { + + data.data.morphAttributes = morphAttributes; + data.data.morphTargetsRelative = this.morphTargetsRelative; + + } + + const groups = this.groups; + + if ( groups.length > 0 ) { + + data.data.groups = JSON.parse( JSON.stringify( groups ) ); + + } + + const boundingSphere = this.boundingSphere; + + if ( boundingSphere !== null ) { + + data.data.boundingSphere = { + center: boundingSphere.center.toArray(), + radius: boundingSphere.radius + }; + + } + + return data; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( source ) { + + // reset + + this.index = null; + this.attributes = {}; + this.morphAttributes = {}; + this.groups = []; + this.boundingBox = null; + this.boundingSphere = null; + + // used for storing cloned, shared data + + const data = {}; + + // name + + this.name = source.name; + + // index + + const index = source.index; + + if ( index !== null ) { + + this.setIndex( index.clone( data ) ); + + } + + // attributes + + const attributes = source.attributes; + + for ( const name in attributes ) { + + const attribute = attributes[ name ]; + this.setAttribute( name, attribute.clone( data ) ); + + } + + // morph attributes + + const morphAttributes = source.morphAttributes; + + for ( const name in morphAttributes ) { + + const array = []; + const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes + + for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) { + + array.push( morphAttribute[ i ].clone( data ) ); + + } + + this.morphAttributes[ name ] = array; + + } + + this.morphTargetsRelative = source.morphTargetsRelative; + + // groups + + const groups = source.groups; + + for ( let i = 0, l = groups.length; i < l; i ++ ) { + + const group = groups[ i ]; + this.addGroup( group.start, group.count, group.materialIndex ); + + } + + // bounding box + + const boundingBox = source.boundingBox; + + if ( boundingBox !== null ) { + + this.boundingBox = boundingBox.clone(); + + } + + // bounding sphere + + const boundingSphere = source.boundingSphere; + + if ( boundingSphere !== null ) { + + this.boundingSphere = boundingSphere.clone(); + + } + + // draw range + + this.drawRange.start = source.drawRange.start; + this.drawRange.count = source.drawRange.count; + + // user data + + this.userData = source.userData; + + return this; + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + } + +} + +const _inverseMatrix$3 = /*@__PURE__*/ new Matrix4(); +const _ray$3 = /*@__PURE__*/ new Ray(); +const _sphere$6 = /*@__PURE__*/ new Sphere(); +const _sphereHitAt = /*@__PURE__*/ new Vector3(); + +const _vA$1 = /*@__PURE__*/ new Vector3(); +const _vB$1 = /*@__PURE__*/ new Vector3(); +const _vC$1 = /*@__PURE__*/ new Vector3(); + +const _tempA = /*@__PURE__*/ new Vector3(); +const _morphA = /*@__PURE__*/ new Vector3(); + +const _intersectionPoint = /*@__PURE__*/ new Vector3(); +const _intersectionPointWorld = /*@__PURE__*/ new Vector3(); + +class Mesh extends Object3D { + + constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) { + + super(); + + this.isMesh = true; + + this.type = 'Mesh'; + + this.geometry = geometry; + this.material = material; + + this.updateMorphTargets(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + if ( source.morphTargetInfluences !== undefined ) { + + this.morphTargetInfluences = source.morphTargetInfluences.slice(); + + } + + if ( source.morphTargetDictionary !== undefined ) { + + this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary ); + + } + + this.material = Array.isArray( source.material ) ? source.material.slice() : source.material; + this.geometry = source.geometry; + + return this; + + } + + updateMorphTargets() { + + const geometry = this.geometry; + + const morphAttributes = geometry.morphAttributes; + const keys = Object.keys( morphAttributes ); + + if ( keys.length > 0 ) { + + const morphAttribute = morphAttributes[ keys[ 0 ] ]; + + if ( morphAttribute !== undefined ) { + + this.morphTargetInfluences = []; + this.morphTargetDictionary = {}; + + for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) { + + const name = morphAttribute[ m ].name || String( m ); + + this.morphTargetInfluences.push( 0 ); + this.morphTargetDictionary[ name ] = m; + + } + + } + + } + + } + + getVertexPosition( index, target ) { + + const geometry = this.geometry; + const position = geometry.attributes.position; + const morphPosition = geometry.morphAttributes.position; + const morphTargetsRelative = geometry.morphTargetsRelative; + + target.fromBufferAttribute( position, index ); + + const morphInfluences = this.morphTargetInfluences; + + if ( morphPosition && morphInfluences ) { + + _morphA.set( 0, 0, 0 ); + + for ( let i = 0, il = morphPosition.length; i < il; i ++ ) { + + const influence = morphInfluences[ i ]; + const morphAttribute = morphPosition[ i ]; + + if ( influence === 0 ) continue; + + _tempA.fromBufferAttribute( morphAttribute, index ); + + if ( morphTargetsRelative ) { + + _morphA.addScaledVector( _tempA, influence ); + + } else { + + _morphA.addScaledVector( _tempA.sub( target ), influence ); + + } + + } + + target.add( _morphA ); + + } + + return target; + + } + + raycast( raycaster, intersects ) { + + const geometry = this.geometry; + const material = this.material; + const matrixWorld = this.matrixWorld; + + if ( material === undefined ) return; + + // test with bounding sphere in world space + + if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere(); + + _sphere$6.copy( geometry.boundingSphere ); + _sphere$6.applyMatrix4( matrixWorld ); + + // check distance from ray origin to bounding sphere + + _ray$3.copy( raycaster.ray ).recast( raycaster.near ); + + if ( _sphere$6.containsPoint( _ray$3.origin ) === false ) { + + if ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return; + + if ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return; + + } + + // convert ray to local space of mesh + + _inverseMatrix$3.copy( matrixWorld ).invert(); + _ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 ); + + // test with bounding box in local space + + if ( geometry.boundingBox !== null ) { + + if ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return; + + } + + // test for intersections with geometry + + this._computeIntersections( raycaster, intersects, _ray$3 ); + + } + + _computeIntersections( raycaster, intersects, rayLocalSpace ) { + + let intersection; + + const geometry = this.geometry; + const material = this.material; + + const index = geometry.index; + const position = geometry.attributes.position; + const uv = geometry.attributes.uv; + const uv1 = geometry.attributes.uv1; + const normal = geometry.attributes.normal; + const groups = geometry.groups; + const drawRange = geometry.drawRange; + + if ( index !== null ) { + + // indexed buffer geometry + + if ( Array.isArray( material ) ) { + + for ( let i = 0, il = groups.length; i < il; i ++ ) { + + const group = groups[ i ]; + const groupMaterial = material[ group.materialIndex ]; + + const start = Math.max( group.start, drawRange.start ); + const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) ); + + for ( let j = start, jl = end; j < jl; j += 3 ) { + + const a = index.getX( j ); + const b = index.getX( j + 1 ); + const c = index.getX( j + 2 ); + + intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics + intersection.face.materialIndex = group.materialIndex; + intersects.push( intersection ); + + } + + } + + } + + } else { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( index.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, il = end; i < il; i += 3 ) { + + const a = index.getX( i ); + const b = index.getX( i + 1 ); + const c = index.getX( i + 2 ); + + intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics + intersects.push( intersection ); + + } + + } + + } + + } else if ( position !== undefined ) { + + // non-indexed buffer geometry + + if ( Array.isArray( material ) ) { + + for ( let i = 0, il = groups.length; i < il; i ++ ) { + + const group = groups[ i ]; + const groupMaterial = material[ group.materialIndex ]; + + const start = Math.max( group.start, drawRange.start ); + const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) ); + + for ( let j = start, jl = end; j < jl; j += 3 ) { + + const a = j; + const b = j + 1; + const c = j + 2; + + intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics + intersection.face.materialIndex = group.materialIndex; + intersects.push( intersection ); + + } + + } + + } + + } else { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( position.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, il = end; i < il; i += 3 ) { + + const a = i; + const b = i + 1; + const c = i + 2; + + intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics + intersects.push( intersection ); + + } + + } + + } + + } + + } + +} + +function checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) { + + let intersect; + + if ( material.side === BackSide ) { + + intersect = ray.intersectTriangle( pC, pB, pA, true, point ); + + } else { + + intersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point ); + + } + + if ( intersect === null ) return null; + + _intersectionPointWorld.copy( point ); + _intersectionPointWorld.applyMatrix4( object.matrixWorld ); + + const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld ); + + if ( distance < raycaster.near || distance > raycaster.far ) return null; + + return { + distance: distance, + point: _intersectionPointWorld.clone(), + object: object + }; + +} + +function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) { + + object.getVertexPosition( a, _vA$1 ); + object.getVertexPosition( b, _vB$1 ); + object.getVertexPosition( c, _vC$1 ); + + const intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint ); + + if ( intersection ) { + + const barycoord = new Vector3(); + Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord ); + + if ( uv ) { + + intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() ); + + } + + if ( uv1 ) { + + intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() ); + + } + + if ( normal ) { + + intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() ); + + if ( intersection.normal.dot( ray.direction ) > 0 ) { + + intersection.normal.multiplyScalar( - 1 ); + + } + + } + + const face = { + a: a, + b: b, + c: c, + normal: new Vector3(), + materialIndex: 0 + }; + + Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal ); + + intersection.face = face; + intersection.barycoord = barycoord; + + } + + return intersection; + +} + +class BoxGeometry extends BufferGeometry { + + constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) { + + super(); + + this.type = 'BoxGeometry'; + + this.parameters = { + width: width, + height: height, + depth: depth, + widthSegments: widthSegments, + heightSegments: heightSegments, + depthSegments: depthSegments + }; + + const scope = this; + + // segments + + widthSegments = Math.floor( widthSegments ); + heightSegments = Math.floor( heightSegments ); + depthSegments = Math.floor( depthSegments ); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // helper variables + + let numberOfVertices = 0; + let groupStart = 0; + + // build each side of the box geometry + + buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px + buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx + buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py + buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny + buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz + buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) { + + const segmentWidth = width / gridX; + const segmentHeight = height / gridY; + + const widthHalf = width / 2; + const heightHalf = height / 2; + const depthHalf = depth / 2; + + const gridX1 = gridX + 1; + const gridY1 = gridY + 1; + + let vertexCounter = 0; + let groupCount = 0; + + const vector = new Vector3(); + + // generate vertices, normals and uvs + + for ( let iy = 0; iy < gridY1; iy ++ ) { + + const y = iy * segmentHeight - heightHalf; + + for ( let ix = 0; ix < gridX1; ix ++ ) { + + const x = ix * segmentWidth - widthHalf; + + // set values to correct vector component + + vector[ u ] = x * udir; + vector[ v ] = y * vdir; + vector[ w ] = depthHalf; + + // now apply vector to vertex buffer + + vertices.push( vector.x, vector.y, vector.z ); + + // set values to correct vector component + + vector[ u ] = 0; + vector[ v ] = 0; + vector[ w ] = depth > 0 ? 1 : - 1; + + // now apply vector to normal buffer + + normals.push( vector.x, vector.y, vector.z ); + + // uvs + + uvs.push( ix / gridX ); + uvs.push( 1 - ( iy / gridY ) ); + + // counters + + vertexCounter += 1; + + } + + } + + // indices + + // 1. you need three indices to draw a single face + // 2. a single segment consists of two faces + // 3. so we need to generate six (2*3) indices per segment + + for ( let iy = 0; iy < gridY; iy ++ ) { + + for ( let ix = 0; ix < gridX; ix ++ ) { + + const a = numberOfVertices + ix + gridX1 * iy; + const b = numberOfVertices + ix + gridX1 * ( iy + 1 ); + const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 ); + const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + // increase counter + + groupCount += 6; + + } + + } + + // add a group to the geometry. this will ensure multi material support + + scope.addGroup( groupStart, groupCount, materialIndex ); + + // calculate new start value for groups + + groupStart += groupCount; + + // update total number of vertices + + numberOfVertices += vertexCounter; + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments ); + + } + +} + +/** + * Uniform Utilities + */ + +function cloneUniforms( src ) { + + const dst = {}; + + for ( const u in src ) { + + dst[ u ] = {}; + + for ( const p in src[ u ] ) { + + const property = src[ u ][ p ]; + + if ( property && ( property.isColor || + property.isMatrix3 || property.isMatrix4 || + property.isVector2 || property.isVector3 || property.isVector4 || + property.isTexture || property.isQuaternion ) ) { + + if ( property.isRenderTargetTexture ) { + + console.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' ); + dst[ u ][ p ] = null; + + } else { + + dst[ u ][ p ] = property.clone(); + + } + + } else if ( Array.isArray( property ) ) { + + dst[ u ][ p ] = property.slice(); + + } else { + + dst[ u ][ p ] = property; + + } + + } + + } + + return dst; + +} + +function mergeUniforms( uniforms ) { + + const merged = {}; + + for ( let u = 0; u < uniforms.length; u ++ ) { + + const tmp = cloneUniforms( uniforms[ u ] ); + + for ( const p in tmp ) { + + merged[ p ] = tmp[ p ]; + + } + + } + + return merged; + +} + +function cloneUniformsGroups( src ) { + + const dst = []; + + for ( let u = 0; u < src.length; u ++ ) { + + dst.push( src[ u ].clone() ); + + } + + return dst; + +} + +function getUnlitUniformColorSpace( renderer ) { + + const currentRenderTarget = renderer.getRenderTarget(); + + if ( currentRenderTarget === null ) { + + // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398 + return renderer.outputColorSpace; + + } + + // https://github.com/mrdoob/three.js/issues/27868 + if ( currentRenderTarget.isXRRenderTarget === true ) { + + return currentRenderTarget.texture.colorSpace; + + } + + return ColorManagement.workingColorSpace; + +} + +// Legacy + +const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms }; + +var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"; + +var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}"; + +class ShaderMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isShaderMaterial = true; + + this.type = 'ShaderMaterial'; + + this.defines = {}; + this.uniforms = {}; + this.uniformsGroups = []; + + this.vertexShader = default_vertex; + this.fragmentShader = default_fragment; + + this.linewidth = 1; + + this.wireframe = false; + this.wireframeLinewidth = 1; + + this.fog = false; // set to use scene fog + this.lights = false; // set to use scene lights + this.clipping = false; // set to use user-defined clipping planes + + this.forceSinglePass = true; + + this.extensions = { + clipCullDistance: false, // set to use vertex shader clipping + multiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID + }; + + // When rendered geometry doesn't include these attributes but the material does, + // use these default values in WebGL. This avoids errors when buffer data is missing. + this.defaultAttributeValues = { + 'color': [ 1, 1, 1 ], + 'uv': [ 0, 0 ], + 'uv1': [ 0, 0 ] + }; + + this.index0AttributeName = undefined; + this.uniformsNeedUpdate = false; + + this.glslVersion = null; + + if ( parameters !== undefined ) { + + this.setValues( parameters ); + + } + + } + + copy( source ) { + + super.copy( source ); + + this.fragmentShader = source.fragmentShader; + this.vertexShader = source.vertexShader; + + this.uniforms = cloneUniforms( source.uniforms ); + this.uniformsGroups = cloneUniformsGroups( source.uniformsGroups ); + + this.defines = Object.assign( {}, source.defines ); + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + + this.fog = source.fog; + this.lights = source.lights; + this.clipping = source.clipping; + + this.extensions = Object.assign( {}, source.extensions ); + + this.glslVersion = source.glslVersion; + + return this; + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + data.glslVersion = this.glslVersion; + data.uniforms = {}; + + for ( const name in this.uniforms ) { + + const uniform = this.uniforms[ name ]; + const value = uniform.value; + + if ( value && value.isTexture ) { + + data.uniforms[ name ] = { + type: 't', + value: value.toJSON( meta ).uuid + }; + + } else if ( value && value.isColor ) { + + data.uniforms[ name ] = { + type: 'c', + value: value.getHex() + }; + + } else if ( value && value.isVector2 ) { + + data.uniforms[ name ] = { + type: 'v2', + value: value.toArray() + }; + + } else if ( value && value.isVector3 ) { + + data.uniforms[ name ] = { + type: 'v3', + value: value.toArray() + }; + + } else if ( value && value.isVector4 ) { + + data.uniforms[ name ] = { + type: 'v4', + value: value.toArray() + }; + + } else if ( value && value.isMatrix3 ) { + + data.uniforms[ name ] = { + type: 'm3', + value: value.toArray() + }; + + } else if ( value && value.isMatrix4 ) { + + data.uniforms[ name ] = { + type: 'm4', + value: value.toArray() + }; + + } else { + + data.uniforms[ name ] = { + value: value + }; + + // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far + + } + + } + + if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines; + + data.vertexShader = this.vertexShader; + data.fragmentShader = this.fragmentShader; + + data.lights = this.lights; + data.clipping = this.clipping; + + const extensions = {}; + + for ( const key in this.extensions ) { + + if ( this.extensions[ key ] === true ) extensions[ key ] = true; + + } + + if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions; + + return data; + + } + +} + +class Camera extends Object3D { + + constructor() { + + super(); + + this.isCamera = true; + + this.type = 'Camera'; + + this.matrixWorldInverse = new Matrix4(); + + this.projectionMatrix = new Matrix4(); + this.projectionMatrixInverse = new Matrix4(); + + this.coordinateSystem = WebGLCoordinateSystem; + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.matrixWorldInverse.copy( source.matrixWorldInverse ); + + this.projectionMatrix.copy( source.projectionMatrix ); + this.projectionMatrixInverse.copy( source.projectionMatrixInverse ); + + this.coordinateSystem = source.coordinateSystem; + + return this; + + } + + getWorldDirection( target ) { + + return super.getWorldDirection( target ).negate(); + + } + + updateMatrixWorld( force ) { + + super.updateMatrixWorld( force ); + + this.matrixWorldInverse.copy( this.matrixWorld ).invert(); + + } + + updateWorldMatrix( updateParents, updateChildren ) { + + super.updateWorldMatrix( updateParents, updateChildren ); + + this.matrixWorldInverse.copy( this.matrixWorld ).invert(); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +const _v3$1 = /*@__PURE__*/ new Vector3(); +const _minTarget = /*@__PURE__*/ new Vector2(); +const _maxTarget = /*@__PURE__*/ new Vector2(); + + +class PerspectiveCamera extends Camera { + + constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) { + + super(); + + this.isPerspectiveCamera = true; + + this.type = 'PerspectiveCamera'; + + this.fov = fov; + this.zoom = 1; + + this.near = near; + this.far = far; + this.focus = 10; + + this.aspect = aspect; + this.view = null; + + this.filmGauge = 35; // width of the film (default in millimeters) + this.filmOffset = 0; // horizontal film offset (same unit as gauge) + + this.updateProjectionMatrix(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.fov = source.fov; + this.zoom = source.zoom; + + this.near = source.near; + this.far = source.far; + this.focus = source.focus; + + this.aspect = source.aspect; + this.view = source.view === null ? null : Object.assign( {}, source.view ); + + this.filmGauge = source.filmGauge; + this.filmOffset = source.filmOffset; + + return this; + + } + + /** + * Sets the FOV by focal length in respect to the current .filmGauge. + * + * The default film gauge is 35, so that the focal length can be specified for + * a 35mm (full frame) camera. + * + * Values for focal length and film gauge must have the same unit. + */ + setFocalLength( focalLength ) { + + /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */ + const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; + + this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope ); + this.updateProjectionMatrix(); + + } + + /** + * Calculates the focal length from the current .fov and .filmGauge. + */ + getFocalLength() { + + const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov ); + + return 0.5 * this.getFilmHeight() / vExtentSlope; + + } + + getEffectiveFOV() { + + return RAD2DEG * 2 * Math.atan( + Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom ); + + } + + getFilmWidth() { + + // film not completely covered in portrait format (aspect < 1) + return this.filmGauge * Math.min( this.aspect, 1 ); + + } + + getFilmHeight() { + + // film not completely covered in landscape format (aspect > 1) + return this.filmGauge / Math.max( this.aspect, 1 ); + + } + + /** + * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction. + * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle. + */ + getViewBounds( distance, minTarget, maxTarget ) { + + _v3$1.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse ); + + minTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z ); + + _v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse ); + + maxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z ); + + } + + /** + * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction. + * Copies the result into the target Vector2, where x is width and y is height. + */ + getViewSize( distance, target ) { + + this.getViewBounds( distance, _minTarget, _maxTarget ); + + return target.subVectors( _maxTarget, _minTarget ); + + } + + /** + * Sets an offset in a larger frustum. This is useful for multi-window or + * multi-monitor/multi-machine setups. + * + * For example, if you have 3x2 monitors and each monitor is 1920x1080 and + * the monitors are in grid like this + * + * +---+---+---+ + * | A | B | C | + * +---+---+---+ + * | D | E | F | + * +---+---+---+ + * + * then for each monitor you would call it like this + * + * const w = 1920; + * const h = 1080; + * const fullWidth = w * 3; + * const fullHeight = h * 2; + * + * --A-- + * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); + * --B-- + * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); + * --C-- + * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); + * --D-- + * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); + * --E-- + * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); + * --F-- + * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); + * + * Note there is no reason monitors have to be the same size or in a grid. + */ + setViewOffset( fullWidth, fullHeight, x, y, width, height ) { + + this.aspect = fullWidth / fullHeight; + + if ( this.view === null ) { + + this.view = { + enabled: true, + fullWidth: 1, + fullHeight: 1, + offsetX: 0, + offsetY: 0, + width: 1, + height: 1 + }; + + } + + this.view.enabled = true; + this.view.fullWidth = fullWidth; + this.view.fullHeight = fullHeight; + this.view.offsetX = x; + this.view.offsetY = y; + this.view.width = width; + this.view.height = height; + + this.updateProjectionMatrix(); + + } + + clearViewOffset() { + + if ( this.view !== null ) { + + this.view.enabled = false; + + } + + this.updateProjectionMatrix(); + + } + + updateProjectionMatrix() { + + const near = this.near; + let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom; + let height = 2 * top; + let width = this.aspect * height; + let left = - 0.5 * width; + const view = this.view; + + if ( this.view !== null && this.view.enabled ) { + + const fullWidth = view.fullWidth, + fullHeight = view.fullHeight; + + left += view.offsetX * width / fullWidth; + top -= view.offsetY * height / fullHeight; + width *= view.width / fullWidth; + height *= view.height / fullHeight; + + } + + const skew = this.filmOffset; + if ( skew !== 0 ) left += near * skew / this.getFilmWidth(); + + this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem ); + + this.projectionMatrixInverse.copy( this.projectionMatrix ).invert(); + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + data.object.fov = this.fov; + data.object.zoom = this.zoom; + + data.object.near = this.near; + data.object.far = this.far; + data.object.focus = this.focus; + + data.object.aspect = this.aspect; + + if ( this.view !== null ) data.object.view = Object.assign( {}, this.view ); + + data.object.filmGauge = this.filmGauge; + data.object.filmOffset = this.filmOffset; + + return data; + + } + +} + +const fov = - 90; // negative fov is not an error +const aspect = 1; + +class CubeCamera extends Object3D { + + constructor( near, far, renderTarget ) { + + super(); + + this.type = 'CubeCamera'; + + this.renderTarget = renderTarget; + this.coordinateSystem = null; + this.activeMipmapLevel = 0; + + const cameraPX = new PerspectiveCamera( fov, aspect, near, far ); + cameraPX.layers = this.layers; + this.add( cameraPX ); + + const cameraNX = new PerspectiveCamera( fov, aspect, near, far ); + cameraNX.layers = this.layers; + this.add( cameraNX ); + + const cameraPY = new PerspectiveCamera( fov, aspect, near, far ); + cameraPY.layers = this.layers; + this.add( cameraPY ); + + const cameraNY = new PerspectiveCamera( fov, aspect, near, far ); + cameraNY.layers = this.layers; + this.add( cameraNY ); + + const cameraPZ = new PerspectiveCamera( fov, aspect, near, far ); + cameraPZ.layers = this.layers; + this.add( cameraPZ ); + + const cameraNZ = new PerspectiveCamera( fov, aspect, near, far ); + cameraNZ.layers = this.layers; + this.add( cameraNZ ); + + } + + updateCoordinateSystem() { + + const coordinateSystem = this.coordinateSystem; + + const cameras = this.children.concat(); + + const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras; + + for ( const camera of cameras ) this.remove( camera ); + + if ( coordinateSystem === WebGLCoordinateSystem ) { + + cameraPX.up.set( 0, 1, 0 ); + cameraPX.lookAt( 1, 0, 0 ); + + cameraNX.up.set( 0, 1, 0 ); + cameraNX.lookAt( - 1, 0, 0 ); + + cameraPY.up.set( 0, 0, - 1 ); + cameraPY.lookAt( 0, 1, 0 ); + + cameraNY.up.set( 0, 0, 1 ); + cameraNY.lookAt( 0, - 1, 0 ); + + cameraPZ.up.set( 0, 1, 0 ); + cameraPZ.lookAt( 0, 0, 1 ); + + cameraNZ.up.set( 0, 1, 0 ); + cameraNZ.lookAt( 0, 0, - 1 ); + + } else if ( coordinateSystem === WebGPUCoordinateSystem ) { + + cameraPX.up.set( 0, - 1, 0 ); + cameraPX.lookAt( - 1, 0, 0 ); + + cameraNX.up.set( 0, - 1, 0 ); + cameraNX.lookAt( 1, 0, 0 ); + + cameraPY.up.set( 0, 0, 1 ); + cameraPY.lookAt( 0, 1, 0 ); + + cameraNY.up.set( 0, 0, - 1 ); + cameraNY.lookAt( 0, - 1, 0 ); + + cameraPZ.up.set( 0, - 1, 0 ); + cameraPZ.lookAt( 0, 0, 1 ); + + cameraNZ.up.set( 0, - 1, 0 ); + cameraNZ.lookAt( 0, 0, - 1 ); + + } else { + + throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem ); + + } + + for ( const camera of cameras ) { + + this.add( camera ); + + camera.updateMatrixWorld(); + + } + + } + + update( renderer, scene ) { + + if ( this.parent === null ) this.updateMatrixWorld(); + + const { renderTarget, activeMipmapLevel } = this; + + if ( this.coordinateSystem !== renderer.coordinateSystem ) { + + this.coordinateSystem = renderer.coordinateSystem; + + this.updateCoordinateSystem(); + + } + + const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children; + + const currentRenderTarget = renderer.getRenderTarget(); + const currentActiveCubeFace = renderer.getActiveCubeFace(); + const currentActiveMipmapLevel = renderer.getActiveMipmapLevel(); + + const currentXrEnabled = renderer.xr.enabled; + + renderer.xr.enabled = false; + + const generateMipmaps = renderTarget.texture.generateMipmaps; + + renderTarget.texture.generateMipmaps = false; + + renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel ); + renderer.render( scene, cameraPX ); + + renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel ); + renderer.render( scene, cameraNX ); + + renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel ); + renderer.render( scene, cameraPY ); + + renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel ); + renderer.render( scene, cameraNY ); + + renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel ); + renderer.render( scene, cameraPZ ); + + // mipmaps are generated during the last call of render() + // at this point, all sides of the cube render target are defined + + renderTarget.texture.generateMipmaps = generateMipmaps; + + renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel ); + renderer.render( scene, cameraNZ ); + + renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel ); + + renderer.xr.enabled = currentXrEnabled; + + renderTarget.texture.needsPMREMUpdate = true; + + } + +} + +class CubeTexture extends Texture { + + constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) { + + images = images !== undefined ? images : []; + mapping = mapping !== undefined ? mapping : CubeReflectionMapping; + + super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ); + + this.isCubeTexture = true; + + this.flipY = false; + + } + + get images() { + + return this.image; + + } + + set images( value ) { + + this.image = value; + + } + +} + +class WebGLCubeRenderTarget extends WebGLRenderTarget { + + constructor( size = 1, options = {} ) { + + super( size, size, options ); + + this.isWebGLCubeRenderTarget = true; + + const image = { width: size, height: size, depth: 1 }; + const images = [ image, image, image, image, image, image ]; + + this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace ); + + // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js) + // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words, + // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly. + + // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped + // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture + // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures). + + this.texture.isRenderTargetTexture = true; + + this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false; + this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter; + + } + + fromEquirectangularTexture( renderer, texture ) { + + this.texture.type = texture.type; + this.texture.colorSpace = texture.colorSpace; + + this.texture.generateMipmaps = texture.generateMipmaps; + this.texture.minFilter = texture.minFilter; + this.texture.magFilter = texture.magFilter; + + const shader = { + + uniforms: { + tEquirect: { value: null }, + }, + + vertexShader: /* glsl */` + + varying vec3 vWorldDirection; + + vec3 transformDirection( in vec3 dir, in mat4 matrix ) { + + return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); + + } + + void main() { + + vWorldDirection = transformDirection( position, modelMatrix ); + + #include + #include + + } + `, + + fragmentShader: /* glsl */` + + uniform sampler2D tEquirect; + + varying vec3 vWorldDirection; + + #include + + void main() { + + vec3 direction = normalize( vWorldDirection ); + + vec2 sampleUV = equirectUv( direction ); + + gl_FragColor = texture2D( tEquirect, sampleUV ); + + } + ` + }; + + const geometry = new BoxGeometry( 5, 5, 5 ); + + const material = new ShaderMaterial( { + + name: 'CubemapFromEquirect', + + uniforms: cloneUniforms( shader.uniforms ), + vertexShader: shader.vertexShader, + fragmentShader: shader.fragmentShader, + side: BackSide, + blending: NoBlending + + } ); + + material.uniforms.tEquirect.value = texture; + + const mesh = new Mesh( geometry, material ); + + const currentMinFilter = texture.minFilter; + + // Avoid blurred poles + if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter; + + const camera = new CubeCamera( 1, 10, this ); + camera.update( renderer, mesh ); + + texture.minFilter = currentMinFilter; + + mesh.geometry.dispose(); + mesh.material.dispose(); + + return this; + + } + + clear( renderer, color, depth, stencil ) { + + const currentRenderTarget = renderer.getRenderTarget(); + + for ( let i = 0; i < 6; i ++ ) { + + renderer.setRenderTarget( this, i ); + + renderer.clear( color, depth, stencil ); + + } + + renderer.setRenderTarget( currentRenderTarget ); + + } + +} + +class FogExp2 { + + constructor( color, density = 0.00025 ) { + + this.isFogExp2 = true; + + this.name = ''; + + this.color = new Color( color ); + this.density = density; + + } + + clone() { + + return new FogExp2( this.color, this.density ); + + } + + toJSON( /* meta */ ) { + + return { + type: 'FogExp2', + name: this.name, + color: this.color.getHex(), + density: this.density + }; + + } + +} + +class Fog { + + constructor( color, near = 1, far = 1000 ) { + + this.isFog = true; + + this.name = ''; + + this.color = new Color( color ); + + this.near = near; + this.far = far; + + } + + clone() { + + return new Fog( this.color, this.near, this.far ); + + } + + toJSON( /* meta */ ) { + + return { + type: 'Fog', + name: this.name, + color: this.color.getHex(), + near: this.near, + far: this.far + }; + + } + +} + +class Scene extends Object3D { + + constructor() { + + super(); + + this.isScene = true; + + this.type = 'Scene'; + + this.background = null; + this.environment = null; + this.fog = null; + + this.backgroundBlurriness = 0; + this.backgroundIntensity = 1; + this.backgroundRotation = new Euler(); + + this.environmentIntensity = 1; + this.environmentRotation = new Euler(); + + this.overrideMaterial = null; + + if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); + + } + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + if ( source.background !== null ) this.background = source.background.clone(); + if ( source.environment !== null ) this.environment = source.environment.clone(); + if ( source.fog !== null ) this.fog = source.fog.clone(); + + this.backgroundBlurriness = source.backgroundBlurriness; + this.backgroundIntensity = source.backgroundIntensity; + this.backgroundRotation.copy( source.backgroundRotation ); + + this.environmentIntensity = source.environmentIntensity; + this.environmentRotation.copy( source.environmentRotation ); + + if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone(); + + this.matrixAutoUpdate = source.matrixAutoUpdate; + + return this; + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + if ( this.fog !== null ) data.object.fog = this.fog.toJSON(); + + if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness; + if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity; + data.object.backgroundRotation = this.backgroundRotation.toArray(); + + if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity; + data.object.environmentRotation = this.environmentRotation.toArray(); + + return data; + + } + +} + +class InterleavedBuffer { + + constructor( array, stride ) { + + this.isInterleavedBuffer = true; + + this.array = array; + this.stride = stride; + this.count = array !== undefined ? array.length / stride : 0; + + this.usage = StaticDrawUsage; + this.updateRanges = []; + + this.version = 0; + + this.uuid = generateUUID(); + + } + + onUploadCallback() {} + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + setUsage( value ) { + + this.usage = value; + + return this; + + } + + addUpdateRange( start, count ) { + + this.updateRanges.push( { start, count } ); + + } + + clearUpdateRanges() { + + this.updateRanges.length = 0; + + } + + copy( source ) { + + this.array = new source.array.constructor( source.array ); + this.count = source.count; + this.stride = source.stride; + this.usage = source.usage; + + return this; + + } + + copyAt( index1, attribute, index2 ) { + + index1 *= this.stride; + index2 *= attribute.stride; + + for ( let i = 0, l = this.stride; i < l; i ++ ) { + + this.array[ index1 + i ] = attribute.array[ index2 + i ]; + + } + + return this; + + } + + set( value, offset = 0 ) { + + this.array.set( value, offset ); + + return this; + + } + + clone( data ) { + + if ( data.arrayBuffers === undefined ) { + + data.arrayBuffers = {}; + + } + + if ( this.array.buffer._uuid === undefined ) { + + this.array.buffer._uuid = generateUUID(); + + } + + if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) { + + data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer; + + } + + const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] ); + + const ib = new this.constructor( array, this.stride ); + ib.setUsage( this.usage ); + + return ib; + + } + + onUpload( callback ) { + + this.onUploadCallback = callback; + + return this; + + } + + toJSON( data ) { + + if ( data.arrayBuffers === undefined ) { + + data.arrayBuffers = {}; + + } + + // generate UUID for array buffer if necessary + + if ( this.array.buffer._uuid === undefined ) { + + this.array.buffer._uuid = generateUUID(); + + } + + if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) { + + data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) ); + + } + + // + + return { + uuid: this.uuid, + buffer: this.array.buffer._uuid, + type: this.array.constructor.name, + stride: this.stride + }; + + } + +} + +const _vector$7 = /*@__PURE__*/ new Vector3(); + +class InterleavedBufferAttribute { + + constructor( interleavedBuffer, itemSize, offset, normalized = false ) { + + this.isInterleavedBufferAttribute = true; + + this.name = ''; + + this.data = interleavedBuffer; + this.itemSize = itemSize; + this.offset = offset; + + this.normalized = normalized; + + } + + get count() { + + return this.data.count; + + } + + get array() { + + return this.data.array; + + } + + set needsUpdate( value ) { + + this.data.needsUpdate = value; + + } + + applyMatrix4( m ) { + + for ( let i = 0, l = this.data.count; i < l; i ++ ) { + + _vector$7.fromBufferAttribute( this, i ); + + _vector$7.applyMatrix4( m ); + + this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z ); + + } + + return this; + + } + + applyNormalMatrix( m ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector$7.fromBufferAttribute( this, i ); + + _vector$7.applyNormalMatrix( m ); + + this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z ); + + } + + return this; + + } + + transformDirection( m ) { + + for ( let i = 0, l = this.count; i < l; i ++ ) { + + _vector$7.fromBufferAttribute( this, i ); + + _vector$7.transformDirection( m ); + + this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z ); + + } + + return this; + + } + + getComponent( index, component ) { + + let value = this.array[ index * this.data.stride + this.offset + component ]; + + if ( this.normalized ) value = denormalize( value, this.array ); + + return value; + + } + + setComponent( index, component, value ) { + + if ( this.normalized ) value = normalize( value, this.array ); + + this.data.array[ index * this.data.stride + this.offset + component ] = value; + + return this; + + } + + setX( index, x ) { + + if ( this.normalized ) x = normalize( x, this.array ); + + this.data.array[ index * this.data.stride + this.offset ] = x; + + return this; + + } + + setY( index, y ) { + + if ( this.normalized ) y = normalize( y, this.array ); + + this.data.array[ index * this.data.stride + this.offset + 1 ] = y; + + return this; + + } + + setZ( index, z ) { + + if ( this.normalized ) z = normalize( z, this.array ); + + this.data.array[ index * this.data.stride + this.offset + 2 ] = z; + + return this; + + } + + setW( index, w ) { + + if ( this.normalized ) w = normalize( w, this.array ); + + this.data.array[ index * this.data.stride + this.offset + 3 ] = w; + + return this; + + } + + getX( index ) { + + let x = this.data.array[ index * this.data.stride + this.offset ]; + + if ( this.normalized ) x = denormalize( x, this.array ); + + return x; + + } + + getY( index ) { + + let y = this.data.array[ index * this.data.stride + this.offset + 1 ]; + + if ( this.normalized ) y = denormalize( y, this.array ); + + return y; + + } + + getZ( index ) { + + let z = this.data.array[ index * this.data.stride + this.offset + 2 ]; + + if ( this.normalized ) z = denormalize( z, this.array ); + + return z; + + } + + getW( index ) { + + let w = this.data.array[ index * this.data.stride + this.offset + 3 ]; + + if ( this.normalized ) w = denormalize( w, this.array ); + + return w; + + } + + setXY( index, x, y ) { + + index = index * this.data.stride + this.offset; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + + } + + this.data.array[ index + 0 ] = x; + this.data.array[ index + 1 ] = y; + + return this; + + } + + setXYZ( index, x, y, z ) { + + index = index * this.data.stride + this.offset; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + z = normalize( z, this.array ); + + } + + this.data.array[ index + 0 ] = x; + this.data.array[ index + 1 ] = y; + this.data.array[ index + 2 ] = z; + + return this; + + } + + setXYZW( index, x, y, z, w ) { + + index = index * this.data.stride + this.offset; + + if ( this.normalized ) { + + x = normalize( x, this.array ); + y = normalize( y, this.array ); + z = normalize( z, this.array ); + w = normalize( w, this.array ); + + } + + this.data.array[ index + 0 ] = x; + this.data.array[ index + 1 ] = y; + this.data.array[ index + 2 ] = z; + this.data.array[ index + 3 ] = w; + + return this; + + } + + clone( data ) { + + if ( data === undefined ) { + + console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' ); + + const array = []; + + for ( let i = 0; i < this.count; i ++ ) { + + const index = i * this.data.stride + this.offset; + + for ( let j = 0; j < this.itemSize; j ++ ) { + + array.push( this.data.array[ index + j ] ); + + } + + } + + return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized ); + + } else { + + if ( data.interleavedBuffers === undefined ) { + + data.interleavedBuffers = {}; + + } + + if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) { + + data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data ); + + } + + return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized ); + + } + + } + + toJSON( data ) { + + if ( data === undefined ) { + + console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' ); + + const array = []; + + for ( let i = 0; i < this.count; i ++ ) { + + const index = i * this.data.stride + this.offset; + + for ( let j = 0; j < this.itemSize; j ++ ) { + + array.push( this.data.array[ index + j ] ); + + } + + } + + // de-interleave data and save it as an ordinary buffer attribute for now + + return { + itemSize: this.itemSize, + type: this.array.constructor.name, + array: array, + normalized: this.normalized + }; + + } else { + + // save as true interleaved attribute + + if ( data.interleavedBuffers === undefined ) { + + data.interleavedBuffers = {}; + + } + + if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) { + + data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data ); + + } + + return { + isInterleavedBufferAttribute: true, + itemSize: this.itemSize, + data: this.data.uuid, + offset: this.offset, + normalized: this.normalized + }; + + } + + } + +} + +class SpriteMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isSpriteMaterial = true; + + this.type = 'SpriteMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + + this.alphaMap = null; + + this.rotation = 0; + + this.sizeAttenuation = true; + + this.transparent = true; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.rotation = source.rotation; + + this.sizeAttenuation = source.sizeAttenuation; + + this.fog = source.fog; + + return this; + + } + +} + +let _geometry; + +const _intersectPoint = /*@__PURE__*/ new Vector3(); +const _worldScale = /*@__PURE__*/ new Vector3(); +const _mvPosition = /*@__PURE__*/ new Vector3(); + +const _alignedPosition = /*@__PURE__*/ new Vector2(); +const _rotatedPosition = /*@__PURE__*/ new Vector2(); +const _viewWorldMatrix = /*@__PURE__*/ new Matrix4(); + +const _vA = /*@__PURE__*/ new Vector3(); +const _vB = /*@__PURE__*/ new Vector3(); +const _vC = /*@__PURE__*/ new Vector3(); + +const _uvA = /*@__PURE__*/ new Vector2(); +const _uvB = /*@__PURE__*/ new Vector2(); +const _uvC = /*@__PURE__*/ new Vector2(); + +class Sprite extends Object3D { + + constructor( material = new SpriteMaterial() ) { + + super(); + + this.isSprite = true; + + this.type = 'Sprite'; + + if ( _geometry === undefined ) { + + _geometry = new BufferGeometry(); + + const float32Array = new Float32Array( [ + - 0.5, - 0.5, 0, 0, 0, + 0.5, - 0.5, 0, 1, 0, + 0.5, 0.5, 0, 1, 1, + - 0.5, 0.5, 0, 0, 1 + ] ); + + const interleavedBuffer = new InterleavedBuffer( float32Array, 5 ); + + _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] ); + _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) ); + _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) ); + + } + + this.geometry = _geometry; + this.material = material; + + this.center = new Vector2( 0.5, 0.5 ); + + } + + raycast( raycaster, intersects ) { + + if ( raycaster.camera === null ) { + + console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' ); + + } + + _worldScale.setFromMatrixScale( this.matrixWorld ); + + _viewWorldMatrix.copy( raycaster.camera.matrixWorld ); + this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld ); + + _mvPosition.setFromMatrixPosition( this.modelViewMatrix ); + + if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) { + + _worldScale.multiplyScalar( - _mvPosition.z ); + + } + + const rotation = this.material.rotation; + let sin, cos; + + if ( rotation !== 0 ) { + + cos = Math.cos( rotation ); + sin = Math.sin( rotation ); + + } + + const center = this.center; + + transformVertex( _vA.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + transformVertex( _vB.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + + _uvA.set( 0, 0 ); + _uvB.set( 1, 0 ); + _uvC.set( 1, 1 ); + + // check first triangle + let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint ); + + if ( intersect === null ) { + + // check second triangle + transformVertex( _vB.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + _uvB.set( 0, 1 ); + + intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint ); + if ( intersect === null ) { + + return; + + } + + } + + const distance = raycaster.ray.origin.distanceTo( _intersectPoint ); + + if ( distance < raycaster.near || distance > raycaster.far ) return; + + intersects.push( { + + distance: distance, + point: _intersectPoint.clone(), + uv: Triangle.getInterpolation( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ), + face: null, + object: this + + } ); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + if ( source.center !== undefined ) this.center.copy( source.center ); + + this.material = source.material; + + return this; + + } + +} + +function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) { + + // compute position in camera space + _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale ); + + // to check if rotation is not zero + if ( sin !== undefined ) { + + _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y ); + _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y ); + + } else { + + _rotatedPosition.copy( _alignedPosition ); + + } + + + vertexPosition.copy( mvPosition ); + vertexPosition.x += _rotatedPosition.x; + vertexPosition.y += _rotatedPosition.y; + + // transform to world space + vertexPosition.applyMatrix4( _viewWorldMatrix ); + +} + +const _v1$2 = /*@__PURE__*/ new Vector3(); +const _v2$1 = /*@__PURE__*/ new Vector3(); + +class LOD extends Object3D { + + constructor() { + + super(); + + this._currentLevel = 0; + + this.type = 'LOD'; + + Object.defineProperties( this, { + levels: { + enumerable: true, + value: [] + }, + isLOD: { + value: true, + } + } ); + + this.autoUpdate = true; + + } + + copy( source ) { + + super.copy( source, false ); + + const levels = source.levels; + + for ( let i = 0, l = levels.length; i < l; i ++ ) { + + const level = levels[ i ]; + + this.addLevel( level.object.clone(), level.distance, level.hysteresis ); + + } + + this.autoUpdate = source.autoUpdate; + + return this; + + } + + addLevel( object, distance = 0, hysteresis = 0 ) { + + distance = Math.abs( distance ); + + const levels = this.levels; + + let l; + + for ( l = 0; l < levels.length; l ++ ) { + + if ( distance < levels[ l ].distance ) { + + break; + + } + + } + + levels.splice( l, 0, { distance: distance, hysteresis: hysteresis, object: object } ); + + this.add( object ); + + return this; + + } + + removeLevel( distance ) { + + const levels = this.levels; + + for ( let i = 0; i < levels.length; i ++ ) { + + if ( levels[ i ].distance === distance ) { + + const removedElements = levels.splice( i, 1 ); + this.remove( removedElements[ 0 ].object ); + + return true; + + } + + } + + return false; + + } + + getCurrentLevel() { + + return this._currentLevel; + + } + + + + getObjectForDistance( distance ) { + + const levels = this.levels; + + if ( levels.length > 0 ) { + + let i, l; + + for ( i = 1, l = levels.length; i < l; i ++ ) { + + let levelDistance = levels[ i ].distance; + + if ( levels[ i ].object.visible ) { + + levelDistance -= levelDistance * levels[ i ].hysteresis; + + } + + if ( distance < levelDistance ) { + + break; + + } + + } + + return levels[ i - 1 ].object; + + } + + return null; + + } + + raycast( raycaster, intersects ) { + + const levels = this.levels; + + if ( levels.length > 0 ) { + + _v1$2.setFromMatrixPosition( this.matrixWorld ); + + const distance = raycaster.ray.origin.distanceTo( _v1$2 ); + + this.getObjectForDistance( distance ).raycast( raycaster, intersects ); + + } + + } + + update( camera ) { + + const levels = this.levels; + + if ( levels.length > 1 ) { + + _v1$2.setFromMatrixPosition( camera.matrixWorld ); + _v2$1.setFromMatrixPosition( this.matrixWorld ); + + const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom; + + levels[ 0 ].object.visible = true; + + let i, l; + + for ( i = 1, l = levels.length; i < l; i ++ ) { + + let levelDistance = levels[ i ].distance; + + if ( levels[ i ].object.visible ) { + + levelDistance -= levelDistance * levels[ i ].hysteresis; + + } + + if ( distance >= levelDistance ) { + + levels[ i - 1 ].object.visible = false; + levels[ i ].object.visible = true; + + } else { + + break; + + } + + } + + this._currentLevel = i - 1; + + for ( ; i < l; i ++ ) { + + levels[ i ].object.visible = false; + + } + + } + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + if ( this.autoUpdate === false ) data.object.autoUpdate = false; + + data.object.levels = []; + + const levels = this.levels; + + for ( let i = 0, l = levels.length; i < l; i ++ ) { + + const level = levels[ i ]; + + data.object.levels.push( { + object: level.object.uuid, + distance: level.distance, + hysteresis: level.hysteresis + } ); + + } + + return data; + + } + +} + +const _basePosition = /*@__PURE__*/ new Vector3(); + +const _skinIndex = /*@__PURE__*/ new Vector4(); +const _skinWeight = /*@__PURE__*/ new Vector4(); + +const _vector3 = /*@__PURE__*/ new Vector3(); +const _matrix4 = /*@__PURE__*/ new Matrix4(); +const _vertex = /*@__PURE__*/ new Vector3(); + +const _sphere$5 = /*@__PURE__*/ new Sphere(); +const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4(); +const _ray$2 = /*@__PURE__*/ new Ray(); + +class SkinnedMesh extends Mesh { + + constructor( geometry, material ) { + + super( geometry, material ); + + this.isSkinnedMesh = true; + + this.type = 'SkinnedMesh'; + + this.bindMode = AttachedBindMode; + this.bindMatrix = new Matrix4(); + this.bindMatrixInverse = new Matrix4(); + + this.boundingBox = null; + this.boundingSphere = null; + + } + + computeBoundingBox() { + + const geometry = this.geometry; + + if ( this.boundingBox === null ) { + + this.boundingBox = new Box3(); + + } + + this.boundingBox.makeEmpty(); + + const positionAttribute = geometry.getAttribute( 'position' ); + + for ( let i = 0; i < positionAttribute.count; i ++ ) { + + this.getVertexPosition( i, _vertex ); + this.boundingBox.expandByPoint( _vertex ); + + } + + } + + computeBoundingSphere() { + + const geometry = this.geometry; + + if ( this.boundingSphere === null ) { + + this.boundingSphere = new Sphere(); + + } + + this.boundingSphere.makeEmpty(); + + const positionAttribute = geometry.getAttribute( 'position' ); + + for ( let i = 0; i < positionAttribute.count; i ++ ) { + + this.getVertexPosition( i, _vertex ); + this.boundingSphere.expandByPoint( _vertex ); + + } + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.bindMode = source.bindMode; + this.bindMatrix.copy( source.bindMatrix ); + this.bindMatrixInverse.copy( source.bindMatrixInverse ); + + this.skeleton = source.skeleton; + + if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone(); + if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone(); + + return this; + + } + + raycast( raycaster, intersects ) { + + const material = this.material; + const matrixWorld = this.matrixWorld; + + if ( material === undefined ) return; + + // test with bounding sphere in world space + + if ( this.boundingSphere === null ) this.computeBoundingSphere(); + + _sphere$5.copy( this.boundingSphere ); + _sphere$5.applyMatrix4( matrixWorld ); + + if ( raycaster.ray.intersectsSphere( _sphere$5 ) === false ) return; + + // convert ray to local space of skinned mesh + + _inverseMatrix$2.copy( matrixWorld ).invert(); + _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 ); + + // test with bounding box in local space + + if ( this.boundingBox !== null ) { + + if ( _ray$2.intersectsBox( this.boundingBox ) === false ) return; + + } + + // test for intersections with geometry + + this._computeIntersections( raycaster, intersects, _ray$2 ); + + } + + getVertexPosition( index, target ) { + + super.getVertexPosition( index, target ); + + this.applyBoneTransform( index, target ); + + return target; + + } + + bind( skeleton, bindMatrix ) { + + this.skeleton = skeleton; + + if ( bindMatrix === undefined ) { + + this.updateMatrixWorld( true ); + + this.skeleton.calculateInverses(); + + bindMatrix = this.matrixWorld; + + } + + this.bindMatrix.copy( bindMatrix ); + this.bindMatrixInverse.copy( bindMatrix ).invert(); + + } + + pose() { + + this.skeleton.pose(); + + } + + normalizeSkinWeights() { + + const vector = new Vector4(); + + const skinWeight = this.geometry.attributes.skinWeight; + + for ( let i = 0, l = skinWeight.count; i < l; i ++ ) { + + vector.fromBufferAttribute( skinWeight, i ); + + const scale = 1.0 / vector.manhattanLength(); + + if ( scale !== Infinity ) { + + vector.multiplyScalar( scale ); + + } else { + + vector.set( 1, 0, 0, 0 ); // do something reasonable + + } + + skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w ); + + } + + } + + updateMatrixWorld( force ) { + + super.updateMatrixWorld( force ); + + if ( this.bindMode === AttachedBindMode ) { + + this.bindMatrixInverse.copy( this.matrixWorld ).invert(); + + } else if ( this.bindMode === DetachedBindMode ) { + + this.bindMatrixInverse.copy( this.bindMatrix ).invert(); + + } else { + + console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode ); + + } + + } + + applyBoneTransform( index, vector ) { + + const skeleton = this.skeleton; + const geometry = this.geometry; + + _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index ); + _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index ); + + _basePosition.copy( vector ).applyMatrix4( this.bindMatrix ); + + vector.set( 0, 0, 0 ); + + for ( let i = 0; i < 4; i ++ ) { + + const weight = _skinWeight.getComponent( i ); + + if ( weight !== 0 ) { + + const boneIndex = _skinIndex.getComponent( i ); + + _matrix4.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] ); + + vector.addScaledVector( _vector3.copy( _basePosition ).applyMatrix4( _matrix4 ), weight ); + + } + + } + + return vector.applyMatrix4( this.bindMatrixInverse ); + + } + +} + +class Bone extends Object3D { + + constructor() { + + super(); + + this.isBone = true; + + this.type = 'Bone'; + + } + +} + +class DataTexture extends Texture { + + constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) { + + super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ); + + this.isDataTexture = true; + + this.image = { data: data, width: width, height: height }; + + this.generateMipmaps = false; + this.flipY = false; + this.unpackAlignment = 1; + + } + +} + +const _offsetMatrix = /*@__PURE__*/ new Matrix4(); +const _identityMatrix = /*@__PURE__*/ new Matrix4(); + +class Skeleton { + + constructor( bones = [], boneInverses = [] ) { + + this.uuid = generateUUID(); + + this.bones = bones.slice( 0 ); + this.boneInverses = boneInverses; + this.boneMatrices = null; + + this.boneTexture = null; + + this.init(); + + } + + init() { + + const bones = this.bones; + const boneInverses = this.boneInverses; + + this.boneMatrices = new Float32Array( bones.length * 16 ); + + // calculate inverse bone matrices if necessary + + if ( boneInverses.length === 0 ) { + + this.calculateInverses(); + + } else { + + // handle special case + + if ( bones.length !== boneInverses.length ) { + + console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' ); + + this.boneInverses = []; + + for ( let i = 0, il = this.bones.length; i < il; i ++ ) { + + this.boneInverses.push( new Matrix4() ); + + } + + } + + } + + } + + calculateInverses() { + + this.boneInverses.length = 0; + + for ( let i = 0, il = this.bones.length; i < il; i ++ ) { + + const inverse = new Matrix4(); + + if ( this.bones[ i ] ) { + + inverse.copy( this.bones[ i ].matrixWorld ).invert(); + + } + + this.boneInverses.push( inverse ); + + } + + } + + pose() { + + // recover the bind-time world matrices + + for ( let i = 0, il = this.bones.length; i < il; i ++ ) { + + const bone = this.bones[ i ]; + + if ( bone ) { + + bone.matrixWorld.copy( this.boneInverses[ i ] ).invert(); + + } + + } + + // compute the local matrices, positions, rotations and scales + + for ( let i = 0, il = this.bones.length; i < il; i ++ ) { + + const bone = this.bones[ i ]; + + if ( bone ) { + + if ( bone.parent && bone.parent.isBone ) { + + bone.matrix.copy( bone.parent.matrixWorld ).invert(); + bone.matrix.multiply( bone.matrixWorld ); + + } else { + + bone.matrix.copy( bone.matrixWorld ); + + } + + bone.matrix.decompose( bone.position, bone.quaternion, bone.scale ); + + } + + } + + } + + update() { + + const bones = this.bones; + const boneInverses = this.boneInverses; + const boneMatrices = this.boneMatrices; + const boneTexture = this.boneTexture; + + // flatten bone matrices to array + + for ( let i = 0, il = bones.length; i < il; i ++ ) { + + // compute the offset between the current and the original transform + + const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix; + + _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] ); + _offsetMatrix.toArray( boneMatrices, i * 16 ); + + } + + if ( boneTexture !== null ) { + + boneTexture.needsUpdate = true; + + } + + } + + clone() { + + return new Skeleton( this.bones, this.boneInverses ); + + } + + computeBoneTexture() { + + // layout (1 matrix = 4 pixels) + // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4) + // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8) + // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16) + // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32) + // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64) + + let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix + size = Math.ceil( size / 4 ) * 4; + size = Math.max( size, 4 ); + + const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel + boneMatrices.set( this.boneMatrices ); // copy current values + + const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType ); + boneTexture.needsUpdate = true; + + this.boneMatrices = boneMatrices; + this.boneTexture = boneTexture; + + return this; + + } + + getBoneByName( name ) { + + for ( let i = 0, il = this.bones.length; i < il; i ++ ) { + + const bone = this.bones[ i ]; + + if ( bone.name === name ) { + + return bone; + + } + + } + + return undefined; + + } + + dispose( ) { + + if ( this.boneTexture !== null ) { + + this.boneTexture.dispose(); + + this.boneTexture = null; + + } + + } + + fromJSON( json, bones ) { + + this.uuid = json.uuid; + + for ( let i = 0, l = json.bones.length; i < l; i ++ ) { + + const uuid = json.bones[ i ]; + let bone = bones[ uuid ]; + + if ( bone === undefined ) { + + console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid ); + bone = new Bone(); + + } + + this.bones.push( bone ); + this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) ); + + } + + this.init(); + + return this; + + } + + toJSON() { + + const data = { + metadata: { + version: 4.6, + type: 'Skeleton', + generator: 'Skeleton.toJSON' + }, + bones: [], + boneInverses: [] + }; + + data.uuid = this.uuid; + + const bones = this.bones; + const boneInverses = this.boneInverses; + + for ( let i = 0, l = bones.length; i < l; i ++ ) { + + const bone = bones[ i ]; + data.bones.push( bone.uuid ); + + const boneInverse = boneInverses[ i ]; + data.boneInverses.push( boneInverse.toArray() ); + + } + + return data; + + } + +} + +class InstancedBufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized, meshPerAttribute = 1 ) { + + super( array, itemSize, normalized ); + + this.isInstancedBufferAttribute = true; + + this.meshPerAttribute = meshPerAttribute; + + } + + copy( source ) { + + super.copy( source ); + + this.meshPerAttribute = source.meshPerAttribute; + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.meshPerAttribute = this.meshPerAttribute; + + data.isInstancedBufferAttribute = true; + + return data; + + } + +} + +const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4(); +const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4(); + +const _instanceIntersects = []; + +const _box3 = /*@__PURE__*/ new Box3(); +const _identity = /*@__PURE__*/ new Matrix4(); +const _mesh$1 = /*@__PURE__*/ new Mesh(); +const _sphere$4 = /*@__PURE__*/ new Sphere(); + +class InstancedMesh extends Mesh { + + constructor( geometry, material, count ) { + + super( geometry, material ); + + this.isInstancedMesh = true; + + this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 ); + this.instanceColor = null; + this.morphTexture = null; + + this.count = count; + + this.boundingBox = null; + this.boundingSphere = null; + + for ( let i = 0; i < count; i ++ ) { + + this.setMatrixAt( i, _identity ); + + } + + } + + computeBoundingBox() { + + const geometry = this.geometry; + const count = this.count; + + if ( this.boundingBox === null ) { + + this.boundingBox = new Box3(); + + } + + if ( geometry.boundingBox === null ) { + + geometry.computeBoundingBox(); + + } + + this.boundingBox.makeEmpty(); + + for ( let i = 0; i < count; i ++ ) { + + this.getMatrixAt( i, _instanceLocalMatrix ); + + _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix ); + + this.boundingBox.union( _box3 ); + + } + + } + + computeBoundingSphere() { + + const geometry = this.geometry; + const count = this.count; + + if ( this.boundingSphere === null ) { + + this.boundingSphere = new Sphere(); + + } + + if ( geometry.boundingSphere === null ) { + + geometry.computeBoundingSphere(); + + } + + this.boundingSphere.makeEmpty(); + + for ( let i = 0; i < count; i ++ ) { + + this.getMatrixAt( i, _instanceLocalMatrix ); + + _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix ); + + this.boundingSphere.union( _sphere$4 ); + + } + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.instanceMatrix.copy( source.instanceMatrix ); + + if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone(); + if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone(); + + this.count = source.count; + + if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone(); + if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone(); + + return this; + + } + + getColorAt( index, color ) { + + color.fromArray( this.instanceColor.array, index * 3 ); + + } + + getMatrixAt( index, matrix ) { + + matrix.fromArray( this.instanceMatrix.array, index * 16 ); + + } + + getMorphAt( index, object ) { + + const objectInfluences = object.morphTargetInfluences; + + const array = this.morphTexture.source.data.data; + + const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum + + const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning + + for ( let i = 0; i < objectInfluences.length; i ++ ) { + + objectInfluences[ i ] = array[ dataIndex + i ]; + + } + + } + + raycast( raycaster, intersects ) { + + const matrixWorld = this.matrixWorld; + const raycastTimes = this.count; + + _mesh$1.geometry = this.geometry; + _mesh$1.material = this.material; + + if ( _mesh$1.material === undefined ) return; + + // test with bounding sphere first + + if ( this.boundingSphere === null ) this.computeBoundingSphere(); + + _sphere$4.copy( this.boundingSphere ); + _sphere$4.applyMatrix4( matrixWorld ); + + if ( raycaster.ray.intersectsSphere( _sphere$4 ) === false ) return; + + // now test each instance + + for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) { + + // calculate the world matrix for each instance + + this.getMatrixAt( instanceId, _instanceLocalMatrix ); + + _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix ); + + // the mesh represents this single instance + + _mesh$1.matrixWorld = _instanceWorldMatrix; + + _mesh$1.raycast( raycaster, _instanceIntersects ); + + // process the result of raycast + + for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) { + + const intersect = _instanceIntersects[ i ]; + intersect.instanceId = instanceId; + intersect.object = this; + intersects.push( intersect ); + + } + + _instanceIntersects.length = 0; + + } + + } + + setColorAt( index, color ) { + + if ( this.instanceColor === null ) { + + this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ).fill( 1 ), 3 ); + + } + + color.toArray( this.instanceColor.array, index * 3 ); + + } + + setMatrixAt( index, matrix ) { + + matrix.toArray( this.instanceMatrix.array, index * 16 ); + + } + + setMorphAt( index, object ) { + + const objectInfluences = object.morphTargetInfluences; + + const len = objectInfluences.length + 1; // morphBaseInfluence + all influences + + if ( this.morphTexture === null ) { + + this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType ); + + } + + const array = this.morphTexture.source.data.data; + + let morphInfluencesSum = 0; + + for ( let i = 0; i < objectInfluences.length; i ++ ) { + + morphInfluencesSum += objectInfluences[ i ]; + + } + + const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; + + const dataIndex = len * index; + + array[ dataIndex ] = morphBaseInfluence; + + array.set( objectInfluences, dataIndex + 1 ); + + } + + updateMorphTargets() { + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + if ( this.morphTexture !== null ) { + + this.morphTexture.dispose(); + this.morphTexture = null; + + } + + return this; + + } + +} + +const _vector1 = /*@__PURE__*/ new Vector3(); +const _vector2 = /*@__PURE__*/ new Vector3(); +const _normalMatrix = /*@__PURE__*/ new Matrix3(); + +class Plane { + + constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) { + + this.isPlane = true; + + // normal is assumed to be normalized + + this.normal = normal; + this.constant = constant; + + } + + set( normal, constant ) { + + this.normal.copy( normal ); + this.constant = constant; + + return this; + + } + + setComponents( x, y, z, w ) { + + this.normal.set( x, y, z ); + this.constant = w; + + return this; + + } + + setFromNormalAndCoplanarPoint( normal, point ) { + + this.normal.copy( normal ); + this.constant = - point.dot( this.normal ); + + return this; + + } + + setFromCoplanarPoints( a, b, c ) { + + const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize(); + + // Q: should an error be thrown if normal is zero (e.g. degenerate plane)? + + this.setFromNormalAndCoplanarPoint( normal, a ); + + return this; + + } + + copy( plane ) { + + this.normal.copy( plane.normal ); + this.constant = plane.constant; + + return this; + + } + + normalize() { + + // Note: will lead to a divide by zero if the plane is invalid. + + const inverseNormalLength = 1.0 / this.normal.length(); + this.normal.multiplyScalar( inverseNormalLength ); + this.constant *= inverseNormalLength; + + return this; + + } + + negate() { + + this.constant *= - 1; + this.normal.negate(); + + return this; + + } + + distanceToPoint( point ) { + + return this.normal.dot( point ) + this.constant; + + } + + distanceToSphere( sphere ) { + + return this.distanceToPoint( sphere.center ) - sphere.radius; + + } + + projectPoint( point, target ) { + + return target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) ); + + } + + intersectLine( line, target ) { + + const direction = line.delta( _vector1 ); + + const denominator = this.normal.dot( direction ); + + if ( denominator === 0 ) { + + // line is coplanar, return origin + if ( this.distanceToPoint( line.start ) === 0 ) { + + return target.copy( line.start ); + + } + + // Unsure if this is the correct method to handle this case. + return null; + + } + + const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator; + + if ( t < 0 || t > 1 ) { + + return null; + + } + + return target.copy( line.start ).addScaledVector( direction, t ); + + } + + intersectsLine( line ) { + + // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it. + + const startSign = this.distanceToPoint( line.start ); + const endSign = this.distanceToPoint( line.end ); + + return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 ); + + } + + intersectsBox( box ) { + + return box.intersectsPlane( this ); + + } + + intersectsSphere( sphere ) { + + return sphere.intersectsPlane( this ); + + } + + coplanarPoint( target ) { + + return target.copy( this.normal ).multiplyScalar( - this.constant ); + + } + + applyMatrix4( matrix, optionalNormalMatrix ) { + + const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix ); + + const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix ); + + const normal = this.normal.applyMatrix3( normalMatrix ).normalize(); + + this.constant = - referencePoint.dot( normal ); + + return this; + + } + + translate( offset ) { + + this.constant -= offset.dot( this.normal ); + + return this; + + } + + equals( plane ) { + + return plane.normal.equals( this.normal ) && ( plane.constant === this.constant ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +const _sphere$3 = /*@__PURE__*/ new Sphere(); +const _vector$6 = /*@__PURE__*/ new Vector3(); + +class Frustum { + + constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) { + + this.planes = [ p0, p1, p2, p3, p4, p5 ]; + + } + + set( p0, p1, p2, p3, p4, p5 ) { + + const planes = this.planes; + + planes[ 0 ].copy( p0 ); + planes[ 1 ].copy( p1 ); + planes[ 2 ].copy( p2 ); + planes[ 3 ].copy( p3 ); + planes[ 4 ].copy( p4 ); + planes[ 5 ].copy( p5 ); + + return this; + + } + + copy( frustum ) { + + const planes = this.planes; + + for ( let i = 0; i < 6; i ++ ) { + + planes[ i ].copy( frustum.planes[ i ] ); + + } + + return this; + + } + + setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) { + + const planes = this.planes; + const me = m.elements; + const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ]; + const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ]; + const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ]; + const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ]; + + planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize(); + planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize(); + planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize(); + planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize(); + planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); + + if ( coordinateSystem === WebGLCoordinateSystem ) { + + planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize(); + + } else if ( coordinateSystem === WebGPUCoordinateSystem ) { + + planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize(); + + } else { + + throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem ); + + } + + return this; + + } + + intersectsObject( object ) { + + if ( object.boundingSphere !== undefined ) { + + if ( object.boundingSphere === null ) object.computeBoundingSphere(); + + _sphere$3.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld ); + + } else { + + const geometry = object.geometry; + + if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere(); + + _sphere$3.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld ); + + } + + return this.intersectsSphere( _sphere$3 ); + + } + + intersectsSprite( sprite ) { + + _sphere$3.center.set( 0, 0, 0 ); + _sphere$3.radius = 0.7071067811865476; + _sphere$3.applyMatrix4( sprite.matrixWorld ); + + return this.intersectsSphere( _sphere$3 ); + + } + + intersectsSphere( sphere ) { + + const planes = this.planes; + const center = sphere.center; + const negRadius = - sphere.radius; + + for ( let i = 0; i < 6; i ++ ) { + + const distance = planes[ i ].distanceToPoint( center ); + + if ( distance < negRadius ) { + + return false; + + } + + } + + return true; + + } + + intersectsBox( box ) { + + const planes = this.planes; + + for ( let i = 0; i < 6; i ++ ) { + + const plane = planes[ i ]; + + // corner at max distance + + _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x; + _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y; + _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z; + + if ( plane.distanceToPoint( _vector$6 ) < 0 ) { + + return false; + + } + + } + + return true; + + } + + containsPoint( point ) { + + const planes = this.planes; + + for ( let i = 0; i < 6; i ++ ) { + + if ( planes[ i ].distanceToPoint( point ) < 0 ) { + + return false; + + } + + } + + return true; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +function ascIdSort( a, b ) { + + return a - b; + +} + +function sortOpaque( a, b ) { + + return a.z - b.z; + +} + +function sortTransparent( a, b ) { + + return b.z - a.z; + +} + +class MultiDrawRenderList { + + constructor() { + + this.index = 0; + this.pool = []; + this.list = []; + + } + + push( start, count, z, index ) { + + const pool = this.pool; + const list = this.list; + if ( this.index >= pool.length ) { + + pool.push( { + + start: - 1, + count: - 1, + z: - 1, + index: - 1, + + } ); + + } + + const item = pool[ this.index ]; + list.push( item ); + this.index ++; + + item.start = start; + item.count = count; + item.z = z; + item.index = index; + + } + + reset() { + + this.list.length = 0; + this.index = 0; + + } + +} + +const _matrix$1 = /*@__PURE__*/ new Matrix4(); +const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 ); +const _frustum = /*@__PURE__*/ new Frustum(); +const _box$1 = /*@__PURE__*/ new Box3(); +const _sphere$2 = /*@__PURE__*/ new Sphere(); +const _vector$5 = /*@__PURE__*/ new Vector3(); +const _forward = /*@__PURE__*/ new Vector3(); +const _temp = /*@__PURE__*/ new Vector3(); +const _renderList = /*@__PURE__*/ new MultiDrawRenderList(); +const _mesh = /*@__PURE__*/ new Mesh(); +const _batchIntersects = []; + +// copies data from attribute "src" into "target" starting at "targetOffset" +function copyAttributeData( src, target, targetOffset = 0 ) { + + const itemSize = target.itemSize; + if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) { + + // use the component getters and setters if the array data cannot + // be copied directly + const vertexCount = src.count; + for ( let i = 0; i < vertexCount; i ++ ) { + + for ( let c = 0; c < itemSize; c ++ ) { + + target.setComponent( i + targetOffset, c, src.getComponent( i, c ) ); + + } + + } + + } else { + + // faster copy approach using typed array set function + target.array.set( src.array, targetOffset * itemSize ); + + } + + target.needsUpdate = true; + +} + +// safely copies array contents to a potentially smaller array +function copyArrayContents( src, target ) { + + if ( src.constructor !== target.constructor ) { + + // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied + const len = Math.min( src.length, target.length ); + for ( let i = 0; i < len; i ++ ) { + + target[ i ] = src[ i ]; + + } + + } else { + + // if the arrays use the same data layout we can use a fast block copy + const len = Math.min( src.length, target.length ); + target.set( new src.constructor( src.buffer, 0, len ) ); + + } + +} + +class BatchedMesh extends Mesh { + + get maxInstanceCount() { + + return this._maxInstanceCount; + + } + + get instanceCount() { + + return this._instanceInfo.length - this._availableInstanceIds.length; + + } + + get unusedVertexCount() { + + return this._maxVertexCount - this._nextVertexStart; + + } + + get unusedIndexCount() { + + return this._maxIndexCount - this._nextIndexStart; + + } + + constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) { + + super( new BufferGeometry(), material ); + + this.isBatchedMesh = true; + this.perObjectFrustumCulled = true; + this.sortObjects = true; + this.boundingBox = null; + this.boundingSphere = null; + this.customSort = null; + + // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries + this._instanceInfo = []; + this._geometryInfo = []; + + // instance, geometry ids that have been set as inactive, and are available to be overwritten + this._availableInstanceIds = []; + this._availableGeometryIds = []; + + // used to track where the next point is that geometry should be inserted + this._nextIndexStart = 0; + this._nextVertexStart = 0; + this._geometryCount = 0; + + // flags + this._visibilityChanged = true; + this._geometryInitialized = false; + + // cached user options + this._maxInstanceCount = maxInstanceCount; + this._maxVertexCount = maxVertexCount; + this._maxIndexCount = maxIndexCount; + + // buffers for multi draw + this._multiDrawCounts = new Int32Array( maxInstanceCount ); + this._multiDrawStarts = new Int32Array( maxInstanceCount ); + this._multiDrawCount = 0; + this._multiDrawInstances = null; + + // Local matrix per geometry by using data texture + this._matricesTexture = null; + this._indirectTexture = null; + this._colorsTexture = null; + + this._initMatricesTexture(); + this._initIndirectTexture(); + + } + + _initMatricesTexture() { + + // layout (1 matrix = 4 pixels) + // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4) + // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8) + // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16) + // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32) + // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64) + + let size = Math.sqrt( this._maxInstanceCount * 4 ); // 4 pixels needed for 1 matrix + size = Math.ceil( size / 4 ) * 4; + size = Math.max( size, 4 ); + + const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel + const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType ); + + this._matricesTexture = matricesTexture; + + } + + _initIndirectTexture() { + + let size = Math.sqrt( this._maxInstanceCount ); + size = Math.ceil( size ); + + const indirectArray = new Uint32Array( size * size ); + const indirectTexture = new DataTexture( indirectArray, size, size, RedIntegerFormat, UnsignedIntType ); + + this._indirectTexture = indirectTexture; + + } + + _initColorsTexture() { + + let size = Math.sqrt( this._maxInstanceCount ); + size = Math.ceil( size ); + + // 4 floats per RGBA pixel initialized to white + const colorsArray = new Float32Array( size * size * 4 ).fill( 1 ); + const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType ); + colorsTexture.colorSpace = ColorManagement.workingColorSpace; + + this._colorsTexture = colorsTexture; + + } + + _initializeGeometry( reference ) { + + const geometry = this.geometry; + const maxVertexCount = this._maxVertexCount; + const maxIndexCount = this._maxIndexCount; + if ( this._geometryInitialized === false ) { + + for ( const attributeName in reference.attributes ) { + + const srcAttribute = reference.getAttribute( attributeName ); + const { array, itemSize, normalized } = srcAttribute; + + const dstArray = new array.constructor( maxVertexCount * itemSize ); + const dstAttribute = new BufferAttribute( dstArray, itemSize, normalized ); + + geometry.setAttribute( attributeName, dstAttribute ); + + } + + if ( reference.getIndex() !== null ) { + + // Reserve last u16 index for primitive restart. + const indexArray = maxVertexCount > 65535 + ? new Uint32Array( maxIndexCount ) + : new Uint16Array( maxIndexCount ); + + geometry.setIndex( new BufferAttribute( indexArray, 1 ) ); + + } + + this._geometryInitialized = true; + + } + + } + + // Make sure the geometry is compatible with the existing combined geometry attributes + _validateGeometry( geometry ) { + + // check to ensure the geometries are using consistent attributes and indices + const batchGeometry = this.geometry; + if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) { + + throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' ); + + } + + for ( const attributeName in batchGeometry.attributes ) { + + if ( ! geometry.hasAttribute( attributeName ) ) { + + throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` ); + + } + + const srcAttribute = geometry.getAttribute( attributeName ); + const dstAttribute = batchGeometry.getAttribute( attributeName ); + if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) { + + throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' ); + + } + + } + + } + + validateInstanceId( instanceId ) { + + const instanceInfo = this._instanceInfo; + if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) { + + throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` ); + + } + + } + + validateGeometryId( geometryId ) { + + const geometryInfoList = this._geometryInfo; + if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) { + + throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` ); + + } + + } + + + setCustomSort( func ) { + + this.customSort = func; + return this; + + } + + computeBoundingBox() { + + if ( this.boundingBox === null ) { + + this.boundingBox = new Box3(); + + } + + const boundingBox = this.boundingBox; + const instanceInfo = this._instanceInfo; + + boundingBox.makeEmpty(); + for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) { + + if ( instanceInfo[ i ].active === false ) continue; + + const geometryId = instanceInfo[ i ].geometryIndex; + this.getMatrixAt( i, _matrix$1 ); + this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 ); + boundingBox.union( _box$1 ); + + } + + } + + computeBoundingSphere() { + + if ( this.boundingSphere === null ) { + + this.boundingSphere = new Sphere(); + + } + + const boundingSphere = this.boundingSphere; + const instanceInfo = this._instanceInfo; + + boundingSphere.makeEmpty(); + for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) { + + if ( instanceInfo[ i ].active === false ) continue; + + const geometryId = instanceInfo[ i ].geometryIndex; + this.getMatrixAt( i, _matrix$1 ); + this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 ); + boundingSphere.union( _sphere$2 ); + + } + + } + + addInstance( geometryId ) { + + const atCapacity = this._instanceInfo.length >= this.maxInstanceCount; + + // ensure we're not over geometry + if ( atCapacity && this._availableInstanceIds.length === 0 ) { + + throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' ); + + } + + const instanceInfo = { + visible: true, + active: true, + geometryIndex: geometryId, + }; + + let drawId = null; + + // Prioritize using previously freed instance ids + if ( this._availableInstanceIds.length > 0 ) { + + this._availableInstanceIds.sort( ascIdSort ); + + drawId = this._availableInstanceIds.shift(); + this._instanceInfo[ drawId ] = instanceInfo; + + } else { + + drawId = this._instanceInfo.length; + this._instanceInfo.push( instanceInfo ); + + } + + const matricesTexture = this._matricesTexture; + _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 ); + matricesTexture.needsUpdate = true; + + const colorsTexture = this._colorsTexture; + if ( colorsTexture ) { + + _whiteColor.toArray( colorsTexture.image.data, drawId * 4 ); + colorsTexture.needsUpdate = true; + + } + + this._visibilityChanged = true; + return drawId; + + } + + addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) { + + this._initializeGeometry( geometry ); + + this._validateGeometry( geometry ); + + const geometryInfo = { + // geometry information + vertexStart: - 1, + vertexCount: - 1, + reservedVertexCount: - 1, + + indexStart: - 1, + indexCount: - 1, + reservedIndexCount: - 1, + + // draw range information + start: - 1, + count: - 1, + + // state + boundingBox: null, + boundingSphere: null, + active: true, + }; + + const geometryInfoList = this._geometryInfo; + geometryInfo.vertexStart = this._nextVertexStart; + geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount; + + const index = geometry.getIndex(); + const hasIndex = index !== null; + if ( hasIndex ) { + + geometryInfo.indexStart = this._nextIndexStart; + geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount; + + } + + if ( + geometryInfo.indexStart !== - 1 && + geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount || + geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount + ) { + + throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' ); + + } + + // update id + let geometryId; + if ( this._availableGeometryIds.length > 0 ) { + + this._availableGeometryIds.sort( ascIdSort ); + + geometryId = this._availableGeometryIds.shift(); + geometryInfoList[ geometryId ] = geometryInfo; + + + } else { + + geometryId = this._geometryCount; + this._geometryCount ++; + geometryInfoList.push( geometryInfo ); + + } + + // update the geometry + this.setGeometryAt( geometryId, geometry ); + + // increment the next geometry position + this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount; + this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount; + + return geometryId; + + } + + setGeometryAt( geometryId, geometry ) { + + if ( geometryId >= this._geometryCount ) { + + throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' ); + + } + + this._validateGeometry( geometry ); + + const batchGeometry = this.geometry; + const hasIndex = batchGeometry.getIndex() !== null; + const dstIndex = batchGeometry.getIndex(); + const srcIndex = geometry.getIndex(); + const geometryInfo = this._geometryInfo[ geometryId ]; + if ( + hasIndex && + srcIndex.count > geometryInfo.reservedIndexCount || + geometry.attributes.position.count > geometryInfo.reservedVertexCount + ) { + + throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' ); + + } + + // copy geometry buffer data over + const vertexStart = geometryInfo.vertexStart; + const reservedVertexCount = geometryInfo.reservedVertexCount; + geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count; + + for ( const attributeName in batchGeometry.attributes ) { + + // copy attribute data + const srcAttribute = geometry.getAttribute( attributeName ); + const dstAttribute = batchGeometry.getAttribute( attributeName ); + copyAttributeData( srcAttribute, dstAttribute, vertexStart ); + + // fill the rest in with zeroes + const itemSize = srcAttribute.itemSize; + for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) { + + const index = vertexStart + i; + for ( let c = 0; c < itemSize; c ++ ) { + + dstAttribute.setComponent( index, c, 0 ); + + } + + } + + dstAttribute.needsUpdate = true; + dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize ); + + } + + // copy index + if ( hasIndex ) { + + const indexStart = geometryInfo.indexStart; + const reservedIndexCount = geometryInfo.reservedIndexCount; + geometryInfo.indexCount = geometry.getIndex().count; + + // copy index data over + for ( let i = 0; i < srcIndex.count; i ++ ) { + + dstIndex.setX( indexStart + i, vertexStart + srcIndex.getX( i ) ); + + } + + // fill the rest in with zeroes + for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) { + + dstIndex.setX( indexStart + i, vertexStart ); + + } + + dstIndex.needsUpdate = true; + dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount ); + + } + + // update the draw range + geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart; + geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount; + + // store the bounding boxes + geometryInfo.boundingBox = null; + if ( geometry.boundingBox !== null ) { + + geometryInfo.boundingBox = geometry.boundingBox.clone(); + + } + + geometryInfo.boundingSphere = null; + if ( geometry.boundingSphere !== null ) { + + geometryInfo.boundingSphere = geometry.boundingSphere.clone(); + + } + + this._visibilityChanged = true; + return geometryId; + + } + + deleteGeometry( geometryId ) { + + const geometryInfoList = this._geometryInfo; + if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) { + + return this; + + } + + // delete any instances associated with this geometry + const instanceInfo = this._instanceInfo; + for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) { + + if ( instanceInfo[ i ].geometryIndex === geometryId ) { + + this.deleteInstance( i ); + + } + + } + + geometryInfoList[ geometryId ].active = false; + this._availableGeometryIds.push( geometryId ); + this._visibilityChanged = true; + + return this; + + } + + deleteInstance( instanceId ) { + + this.validateInstanceId( instanceId ); + + this._instanceInfo[ instanceId ].active = false; + this._availableInstanceIds.push( instanceId ); + this._visibilityChanged = true; + + return this; + + } + + optimize() { + + // track the next indices to copy data to + let nextVertexStart = 0; + let nextIndexStart = 0; + + // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest + // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order. + const geometryInfoList = this._geometryInfo; + const indices = geometryInfoList + .map( ( e, i ) => i ) + .sort( ( a, b ) => { + + return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart; + + } ); + + const geometry = this.geometry; + for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) { + + // if a geometry range is inactive then don't copy anything + const index = indices[ i ]; + const geometryInfo = geometryInfoList[ index ]; + if ( geometryInfo.active === false ) { + + continue; + + } + + // if a geometry contains an index buffer then shift it, as well + if ( geometry.index !== null ) { + + if ( geometryInfo.indexStart !== nextIndexStart ) { + + const { indexStart, vertexStart, reservedIndexCount } = geometryInfo; + const index = geometry.index; + const array = index.array; + + // shift the index pointers based on how the vertex data will shift + // adjusting the index must happen first so the original vertex start value is available + const elementDelta = nextVertexStart - vertexStart; + for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) { + + array[ j ] = array[ j ] + elementDelta; + + } + + index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount ); + index.addUpdateRange( nextIndexStart, reservedIndexCount ); + + geometryInfo.indexStart = nextIndexStart; + + } + + nextIndexStart += geometryInfo.reservedIndexCount; + + } + + // if a geometry needs to be moved then copy attribute data to overwrite unused space + if ( geometryInfo.vertexStart !== nextVertexStart ) { + + const { vertexStart, reservedVertexCount } = geometryInfo; + const attributes = geometry.attributes; + for ( const key in attributes ) { + + const attribute = attributes[ key ]; + const { array, itemSize } = attribute; + array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize ); + attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize ); + + } + + geometryInfo.vertexStart = nextVertexStart; + + } + + nextVertexStart += geometryInfo.reservedVertexCount; + geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart; + + // step the next geometry points to the shifted position + this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0; + this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount; + + } + + return this; + + } + + // get bounding box and compute it if it doesn't exist + getBoundingBoxAt( geometryId, target ) { + + if ( geometryId >= this._geometryCount ) { + + return null; + + } + + // compute bounding box + const geometry = this.geometry; + const geometryInfo = this._geometryInfo[ geometryId ]; + if ( geometryInfo.boundingBox === null ) { + + const box = new Box3(); + const index = geometry.index; + const position = geometry.attributes.position; + for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) { + + let iv = i; + if ( index ) { + + iv = index.getX( iv ); + + } + + box.expandByPoint( _vector$5.fromBufferAttribute( position, iv ) ); + + } + + geometryInfo.boundingBox = box; + + } + + target.copy( geometryInfo.boundingBox ); + return target; + + } + + // get bounding sphere and compute it if it doesn't exist + getBoundingSphereAt( geometryId, target ) { + + if ( geometryId >= this._geometryCount ) { + + return null; + + } + + // compute bounding sphere + const geometry = this.geometry; + const geometryInfo = this._geometryInfo[ geometryId ]; + if ( geometryInfo.boundingSphere === null ) { + + const sphere = new Sphere(); + this.getBoundingBoxAt( geometryId, _box$1 ); + _box$1.getCenter( sphere.center ); + + const index = geometry.index; + const position = geometry.attributes.position; + + let maxRadiusSq = 0; + for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) { + + let iv = i; + if ( index ) { + + iv = index.getX( iv ); + + } + + _vector$5.fromBufferAttribute( position, iv ); + maxRadiusSq = Math.max( maxRadiusSq, sphere.center.distanceToSquared( _vector$5 ) ); + + } + + sphere.radius = Math.sqrt( maxRadiusSq ); + geometryInfo.boundingSphere = sphere; + + } + + target.copy( geometryInfo.boundingSphere ); + return target; + + } + + setMatrixAt( instanceId, matrix ) { + + this.validateInstanceId( instanceId ); + + const matricesTexture = this._matricesTexture; + const matricesArray = this._matricesTexture.image.data; + matrix.toArray( matricesArray, instanceId * 16 ); + matricesTexture.needsUpdate = true; + + return this; + + } + + getMatrixAt( instanceId, matrix ) { + + this.validateInstanceId( instanceId ); + return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 ); + + } + + setColorAt( instanceId, color ) { + + this.validateInstanceId( instanceId ); + + if ( this._colorsTexture === null ) { + + this._initColorsTexture(); + + } + + color.toArray( this._colorsTexture.image.data, instanceId * 4 ); + this._colorsTexture.needsUpdate = true; + + return this; + + } + + getColorAt( instanceId, color ) { + + this.validateInstanceId( instanceId ); + return color.fromArray( this._colorsTexture.image.data, instanceId * 4 ); + + } + + setVisibleAt( instanceId, value ) { + + this.validateInstanceId( instanceId ); + + if ( this._instanceInfo[ instanceId ].visible === value ) { + + return this; + + } + + this._instanceInfo[ instanceId ].visible = value; + this._visibilityChanged = true; + + return this; + + } + + getVisibleAt( instanceId ) { + + this.validateInstanceId( instanceId ); + + return this._instanceInfo[ instanceId ].visible; + + } + + setGeometryIdAt( instanceId, geometryId ) { + + this.validateInstanceId( instanceId ); + this.validateGeometryId( geometryId ); + + this._instanceInfo[ instanceId ].geometryIndex = geometryId; + + return this; + + } + + getGeometryIdAt( instanceId ) { + + this.validateInstanceId( instanceId ); + + return this._instanceInfo[ instanceId ].geometryIndex; + + } + + getGeometryRangeAt( geometryId, target = {} ) { + + this.validateGeometryId( geometryId ); + + const geometryInfo = this._geometryInfo[ geometryId ]; + target.vertexStart = geometryInfo.vertexStart; + target.vertexCount = geometryInfo.vertexCount; + target.reservedVertexCount = geometryInfo.reservedVertexCount; + + target.indexStart = geometryInfo.indexStart; + target.indexCount = geometryInfo.indexCount; + target.reservedIndexCount = geometryInfo.reservedIndexCount; + + target.start = geometryInfo.start; + target.count = geometryInfo.count; + + return target; + + } + + setInstanceCount( maxInstanceCount ) { + + // shrink the available instances as much as possible + const availableInstanceIds = this._availableInstanceIds; + const instanceInfo = this._instanceInfo; + availableInstanceIds.sort( ascIdSort ); + while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) { + + instanceInfo.pop(); + availableInstanceIds.pop(); + + } + + // throw an error if it can't be shrunk to the desired size + if ( maxInstanceCount < instanceInfo.length ) { + + throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` ); + + } + + // copy the multi draw counts + const multiDrawCounts = new Int32Array( maxInstanceCount ); + const multiDrawStarts = new Int32Array( maxInstanceCount ); + copyArrayContents( this._multiDrawCounts, multiDrawCounts ); + copyArrayContents( this._multiDrawStarts, multiDrawStarts ); + + this._multiDrawCounts = multiDrawCounts; + this._multiDrawStarts = multiDrawStarts; + this._maxInstanceCount = maxInstanceCount; + + // update texture data for instance sampling + const indirectTexture = this._indirectTexture; + const matricesTexture = this._matricesTexture; + const colorsTexture = this._colorsTexture; + + indirectTexture.dispose(); + this._initIndirectTexture(); + copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data ); + + matricesTexture.dispose(); + this._initMatricesTexture(); + copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data ); + + if ( colorsTexture ) { + + colorsTexture.dispose(); + this._initColorsTexture(); + copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data ); + + } + + } + + setGeometrySize( maxVertexCount, maxIndexCount ) { + + // Check if we can shrink to the requested vertex attribute size + const validRanges = [ ...this._geometryInfo ].filter( info => info.active ); + const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) ); + if ( requiredVertexLength > maxVertexCount ) { + + throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` ); + + } + + // Check if we can shrink to the requested index attribute size + if ( this.geometry.index ) { + + const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) ); + if ( requiredIndexLength > maxIndexCount ) { + + throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` ); + + } + + } + + // + + // dispose of the previous geometry + const oldGeometry = this.geometry; + oldGeometry.dispose(); + + // recreate the geometry needed based on the previous variant + this._maxVertexCount = maxVertexCount; + this._maxIndexCount = maxIndexCount; + + if ( this._geometryInitialized ) { + + this._geometryInitialized = false; + this.geometry = new BufferGeometry(); + this._initializeGeometry( oldGeometry ); + + } + + // copy data from the previous geometry + const geometry = this.geometry; + if ( oldGeometry.index ) { + + copyArrayContents( oldGeometry.index.array, geometry.index.array ); + + } + + for ( const key in oldGeometry.attributes ) { + + copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array ); + + } + + } + + raycast( raycaster, intersects ) { + + const instanceInfo = this._instanceInfo; + const geometryInfoList = this._geometryInfo; + const matrixWorld = this.matrixWorld; + const batchGeometry = this.geometry; + + // iterate over each geometry + _mesh.material = this.material; + _mesh.geometry.index = batchGeometry.index; + _mesh.geometry.attributes = batchGeometry.attributes; + if ( _mesh.geometry.boundingBox === null ) { + + _mesh.geometry.boundingBox = new Box3(); + + } + + if ( _mesh.geometry.boundingSphere === null ) { + + _mesh.geometry.boundingSphere = new Sphere(); + + } + + for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) { + + if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) { + + continue; + + } + + const geometryId = instanceInfo[ i ].geometryIndex; + const geometryInfo = geometryInfoList[ geometryId ]; + _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count ); + + // get the intersects + this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld ); + this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox ); + this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere ); + _mesh.raycast( raycaster, _batchIntersects ); + + // add batch id to the intersects + for ( let j = 0, l = _batchIntersects.length; j < l; j ++ ) { + + const intersect = _batchIntersects[ j ]; + intersect.object = this; + intersect.batchId = i; + intersects.push( intersect ); + + } + + _batchIntersects.length = 0; + + } + + _mesh.material = null; + _mesh.geometry.index = null; + _mesh.geometry.attributes = {}; + _mesh.geometry.setDrawRange( 0, Infinity ); + + } + + copy( source ) { + + super.copy( source ); + + this.geometry = source.geometry.clone(); + this.perObjectFrustumCulled = source.perObjectFrustumCulled; + this.sortObjects = source.sortObjects; + this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null; + this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null; + + this._geometryInfo = source._geometryInfo.map( info => ( { + ...info, + + boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null, + boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null, + } ) ); + this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) ); + + this._maxInstanceCount = source._maxInstanceCount; + this._maxVertexCount = source._maxVertexCount; + this._maxIndexCount = source._maxIndexCount; + + this._geometryInitialized = source._geometryInitialized; + this._geometryCount = source._geometryCount; + this._multiDrawCounts = source._multiDrawCounts.slice(); + this._multiDrawStarts = source._multiDrawStarts.slice(); + + this._matricesTexture = source._matricesTexture.clone(); + this._matricesTexture.image.data = this._matricesTexture.image.data.slice(); + + if ( this._colorsTexture !== null ) { + + this._colorsTexture = source._colorsTexture.clone(); + this._colorsTexture.image.data = this._colorsTexture.image.data.slice(); + + } + + return this; + + } + + dispose() { + + // Assuming the geometry is not shared with other meshes + this.geometry.dispose(); + + this._matricesTexture.dispose(); + this._matricesTexture = null; + + this._indirectTexture.dispose(); + this._indirectTexture = null; + + if ( this._colorsTexture !== null ) { + + this._colorsTexture.dispose(); + this._colorsTexture = null; + + } + + return this; + + } + + onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) { + + // if visibility has not changed and frustum culling and object sorting is not required + // then skip iterating over all items + if ( ! this._visibilityChanged && ! this.perObjectFrustumCulled && ! this.sortObjects ) { + + return; + + } + + // the indexed version of the multi draw function requires specifying the start + // offset in bytes. + const index = geometry.getIndex(); + const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT; + + const instanceInfo = this._instanceInfo; + const multiDrawStarts = this._multiDrawStarts; + const multiDrawCounts = this._multiDrawCounts; + const geometryInfoList = this._geometryInfo; + const perObjectFrustumCulled = this.perObjectFrustumCulled; + const indirectTexture = this._indirectTexture; + const indirectArray = indirectTexture.image.data; + + // prepare the frustum in the local frame + if ( perObjectFrustumCulled ) { + + _matrix$1 + .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ) + .multiply( this.matrixWorld ); + _frustum.setFromProjectionMatrix( + _matrix$1, + renderer.coordinateSystem + ); + + } + + let multiDrawCount = 0; + if ( this.sortObjects ) { + + // get the camera position in the local frame + _matrix$1.copy( this.matrixWorld ).invert(); + _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 ); + _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 ); + + for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) { + + if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) { + + const geometryId = instanceInfo[ i ].geometryIndex; + + // get the bounds in world space + this.getMatrixAt( i, _matrix$1 ); + this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 ); + + // determine whether the batched geometry is within the frustum + let culled = false; + if ( perObjectFrustumCulled ) { + + culled = ! _frustum.intersectsSphere( _sphere$2 ); + + } + + if ( ! culled ) { + + // get the distance from camera used for sorting + const geometryInfo = geometryInfoList[ geometryId ]; + const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward ); + _renderList.push( geometryInfo.start, geometryInfo.count, z, i ); + + } + + } + + } + + // Sort the draw ranges and prep for rendering + const list = _renderList.list; + const customSort = this.customSort; + if ( customSort === null ) { + + list.sort( material.transparent ? sortTransparent : sortOpaque ); + + } else { + + customSort.call( this, list, camera ); + + } + + for ( let i = 0, l = list.length; i < l; i ++ ) { + + const item = list[ i ]; + multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement; + multiDrawCounts[ multiDrawCount ] = item.count; + indirectArray[ multiDrawCount ] = item.index; + multiDrawCount ++; + + } + + _renderList.reset(); + + } else { + + for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) { + + if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) { + + const geometryId = instanceInfo[ i ].geometryIndex; + + // determine whether the batched geometry is within the frustum + let culled = false; + if ( perObjectFrustumCulled ) { + + // get the bounds in world space + this.getMatrixAt( i, _matrix$1 ); + this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 ); + culled = ! _frustum.intersectsSphere( _sphere$2 ); + + } + + if ( ! culled ) { + + const geometryInfo = geometryInfoList[ geometryId ]; + multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement; + multiDrawCounts[ multiDrawCount ] = geometryInfo.count; + indirectArray[ multiDrawCount ] = i; + multiDrawCount ++; + + } + + } + + } + + } + + indirectTexture.needsUpdate = true; + this._multiDrawCount = multiDrawCount; + this._visibilityChanged = false; + + } + + onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial/* , group */ ) { + + this.onBeforeRender( renderer, null, shadowCamera, geometry, depthMaterial ); + + } + +} + +class LineBasicMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isLineBasicMaterial = true; + + this.type = 'LineBasicMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + + this.linewidth = 1; + this.linecap = 'round'; + this.linejoin = 'round'; + + this.fog = true; + + this.setValues( parameters ); + + } + + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.linewidth = source.linewidth; + this.linecap = source.linecap; + this.linejoin = source.linejoin; + + this.fog = source.fog; + + return this; + + } + +} + +const _vStart = /*@__PURE__*/ new Vector3(); +const _vEnd = /*@__PURE__*/ new Vector3(); + +const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4(); +const _ray$1 = /*@__PURE__*/ new Ray(); +const _sphere$1 = /*@__PURE__*/ new Sphere(); + +const _intersectPointOnRay = /*@__PURE__*/ new Vector3(); +const _intersectPointOnSegment = /*@__PURE__*/ new Vector3(); + +class Line extends Object3D { + + constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) { + + super(); + + this.isLine = true; + + this.type = 'Line'; + + this.geometry = geometry; + this.material = material; + + this.updateMorphTargets(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.material = Array.isArray( source.material ) ? source.material.slice() : source.material; + this.geometry = source.geometry; + + return this; + + } + + computeLineDistances() { + + const geometry = this.geometry; + + // we assume non-indexed geometry + + if ( geometry.index === null ) { + + const positionAttribute = geometry.attributes.position; + const lineDistances = [ 0 ]; + + for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) { + + _vStart.fromBufferAttribute( positionAttribute, i - 1 ); + _vEnd.fromBufferAttribute( positionAttribute, i ); + + lineDistances[ i ] = lineDistances[ i - 1 ]; + lineDistances[ i ] += _vStart.distanceTo( _vEnd ); + + } + + geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) ); + + } else { + + console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' ); + + } + + return this; + + } + + raycast( raycaster, intersects ) { + + const geometry = this.geometry; + const matrixWorld = this.matrixWorld; + const threshold = raycaster.params.Line.threshold; + const drawRange = geometry.drawRange; + + // Checking boundingSphere distance to ray + + if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere(); + + _sphere$1.copy( geometry.boundingSphere ); + _sphere$1.applyMatrix4( matrixWorld ); + _sphere$1.radius += threshold; + + if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return; + + // + + _inverseMatrix$1.copy( matrixWorld ).invert(); + _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 ); + + const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); + const localThresholdSq = localThreshold * localThreshold; + + const step = this.isLineSegments ? 2 : 1; + + const index = geometry.index; + const attributes = geometry.attributes; + const positionAttribute = attributes.position; + + if ( index !== null ) { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( index.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, l = end - 1; i < l; i += step ) { + + const a = index.getX( i ); + const b = index.getX( i + 1 ); + + const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b ); + + if ( intersect ) { + + intersects.push( intersect ); + + } + + } + + if ( this.isLineLoop ) { + + const a = index.getX( end - 1 ); + const b = index.getX( start ); + + const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b ); + + if ( intersect ) { + + intersects.push( intersect ); + + } + + } + + } else { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, l = end - 1; i < l; i += step ) { + + const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 ); + + if ( intersect ) { + + intersects.push( intersect ); + + } + + } + + if ( this.isLineLoop ) { + + const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start ); + + if ( intersect ) { + + intersects.push( intersect ); + + } + + } + + } + + } + + updateMorphTargets() { + + const geometry = this.geometry; + + const morphAttributes = geometry.morphAttributes; + const keys = Object.keys( morphAttributes ); + + if ( keys.length > 0 ) { + + const morphAttribute = morphAttributes[ keys[ 0 ] ]; + + if ( morphAttribute !== undefined ) { + + this.morphTargetInfluences = []; + this.morphTargetDictionary = {}; + + for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) { + + const name = morphAttribute[ m ].name || String( m ); + + this.morphTargetInfluences.push( 0 ); + this.morphTargetDictionary[ name ] = m; + + } + + } + + } + + } + +} + +function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) { + + const positionAttribute = object.geometry.attributes.position; + + _vStart.fromBufferAttribute( positionAttribute, a ); + _vEnd.fromBufferAttribute( positionAttribute, b ); + + const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment ); + + if ( distSq > thresholdSq ) return; + + _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation + + const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay ); + + if ( distance < raycaster.near || distance > raycaster.far ) return; + + return { + + distance: distance, + // What do we want? intersection point on the ray or on the segment?? + // point: raycaster.ray.at( distance ), + point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ), + index: a, + face: null, + faceIndex: null, + barycoord: null, + object: object + + }; + +} + +const _start = /*@__PURE__*/ new Vector3(); +const _end = /*@__PURE__*/ new Vector3(); + +class LineSegments extends Line { + + constructor( geometry, material ) { + + super( geometry, material ); + + this.isLineSegments = true; + + this.type = 'LineSegments'; + + } + + computeLineDistances() { + + const geometry = this.geometry; + + // we assume non-indexed geometry + + if ( geometry.index === null ) { + + const positionAttribute = geometry.attributes.position; + const lineDistances = []; + + for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) { + + _start.fromBufferAttribute( positionAttribute, i ); + _end.fromBufferAttribute( positionAttribute, i + 1 ); + + lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ]; + lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end ); + + } + + geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) ); + + } else { + + console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' ); + + } + + return this; + + } + +} + +class LineLoop extends Line { + + constructor( geometry, material ) { + + super( geometry, material ); + + this.isLineLoop = true; + + this.type = 'LineLoop'; + + } + +} + +class PointsMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isPointsMaterial = true; + + this.type = 'PointsMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + + this.alphaMap = null; + + this.size = 1; + this.sizeAttenuation = true; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.size = source.size; + this.sizeAttenuation = source.sizeAttenuation; + + this.fog = source.fog; + + return this; + + } + +} + +const _inverseMatrix = /*@__PURE__*/ new Matrix4(); +const _ray = /*@__PURE__*/ new Ray(); +const _sphere = /*@__PURE__*/ new Sphere(); +const _position$2 = /*@__PURE__*/ new Vector3(); + +class Points extends Object3D { + + constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) { + + super(); + + this.isPoints = true; + + this.type = 'Points'; + + this.geometry = geometry; + this.material = material; + + this.updateMorphTargets(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.material = Array.isArray( source.material ) ? source.material.slice() : source.material; + this.geometry = source.geometry; + + return this; + + } + + raycast( raycaster, intersects ) { + + const geometry = this.geometry; + const matrixWorld = this.matrixWorld; + const threshold = raycaster.params.Points.threshold; + const drawRange = geometry.drawRange; + + // Checking boundingSphere distance to ray + + if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere(); + + _sphere.copy( geometry.boundingSphere ); + _sphere.applyMatrix4( matrixWorld ); + _sphere.radius += threshold; + + if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return; + + // + + _inverseMatrix.copy( matrixWorld ).invert(); + _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix ); + + const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); + const localThresholdSq = localThreshold * localThreshold; + + const index = geometry.index; + const attributes = geometry.attributes; + const positionAttribute = attributes.position; + + if ( index !== null ) { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( index.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, il = end; i < il; i ++ ) { + + const a = index.getX( i ); + + _position$2.fromBufferAttribute( positionAttribute, a ); + + testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this ); + + } + + } else { + + const start = Math.max( 0, drawRange.start ); + const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) ); + + for ( let i = start, l = end; i < l; i ++ ) { + + _position$2.fromBufferAttribute( positionAttribute, i ); + + testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this ); + + } + + } + + } + + updateMorphTargets() { + + const geometry = this.geometry; + + const morphAttributes = geometry.morphAttributes; + const keys = Object.keys( morphAttributes ); + + if ( keys.length > 0 ) { + + const morphAttribute = morphAttributes[ keys[ 0 ] ]; + + if ( morphAttribute !== undefined ) { + + this.morphTargetInfluences = []; + this.morphTargetDictionary = {}; + + for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) { + + const name = morphAttribute[ m ].name || String( m ); + + this.morphTargetInfluences.push( 0 ); + this.morphTargetDictionary[ name ] = m; + + } + + } + + } + + } + +} + +function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) { + + const rayPointDistanceSq = _ray.distanceSqToPoint( point ); + + if ( rayPointDistanceSq < localThresholdSq ) { + + const intersectPoint = new Vector3(); + + _ray.closestPointToPoint( point, intersectPoint ); + intersectPoint.applyMatrix4( matrixWorld ); + + const distance = raycaster.ray.origin.distanceTo( intersectPoint ); + + if ( distance < raycaster.near || distance > raycaster.far ) return; + + intersects.push( { + + distance: distance, + distanceToRay: Math.sqrt( rayPointDistanceSq ), + point: intersectPoint, + index: index, + face: null, + faceIndex: null, + barycoord: null, + object: object + + } ); + + } + +} + +class Group extends Object3D { + + constructor() { + + super(); + + this.isGroup = true; + + this.type = 'Group'; + + } + +} + +class VideoTexture extends Texture { + + constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) { + + super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); + + this.isVideoTexture = true; + + this.minFilter = minFilter !== undefined ? minFilter : LinearFilter; + this.magFilter = magFilter !== undefined ? magFilter : LinearFilter; + + this.generateMipmaps = false; + + const scope = this; + + function updateVideo() { + + scope.needsUpdate = true; + video.requestVideoFrameCallback( updateVideo ); + + } + + if ( 'requestVideoFrameCallback' in video ) { + + video.requestVideoFrameCallback( updateVideo ); + + } + + } + + clone() { + + return new this.constructor( this.image ).copy( this ); + + } + + update() { + + const video = this.image; + const hasVideoFrameCallback = 'requestVideoFrameCallback' in video; + + if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) { + + this.needsUpdate = true; + + } + + } + +} + +class FramebufferTexture extends Texture { + + constructor( width, height ) { + + super( { width, height } ); + + this.isFramebufferTexture = true; + + this.magFilter = NearestFilter; + this.minFilter = NearestFilter; + + this.generateMipmaps = false; + + this.needsUpdate = true; + + } + +} + +class CompressedTexture extends Texture { + + constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) { + + super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ); + + this.isCompressedTexture = true; + + this.image = { width: width, height: height }; + this.mipmaps = mipmaps; + + // no flipping for cube textures + // (also flipping doesn't work for compressed textures ) + + this.flipY = false; + + // can't generate mipmaps for compressed textures + // mips must be embedded in DDS files + + this.generateMipmaps = false; + + } + +} + +class CompressedArrayTexture extends CompressedTexture { + + constructor( mipmaps, width, height, depth, format, type ) { + + super( mipmaps, width, height, format, type ); + + this.isCompressedArrayTexture = true; + this.image.depth = depth; + this.wrapR = ClampToEdgeWrapping; + + this.layerUpdates = new Set(); + + } + + addLayerUpdate( layerIndex ) { + + this.layerUpdates.add( layerIndex ); + + } + + clearLayerUpdates() { + + this.layerUpdates.clear(); + + } + +} + +class CompressedCubeTexture extends CompressedTexture { + + constructor( images, format, type ) { + + super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping ); + + this.isCompressedCubeTexture = true; + this.isCubeTexture = true; + + this.image = images; + + } + +} + +class CanvasTexture extends Texture { + + constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) { + + super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); + + this.isCanvasTexture = true; + + this.needsUpdate = true; + + } + +} + +class DepthTexture extends Texture { + + constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) { + + if ( format !== DepthFormat && format !== DepthStencilFormat ) { + + throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' ); + + } + + if ( type === undefined && format === DepthFormat ) type = UnsignedIntType; + if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type; + + super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); + + this.isDepthTexture = true; + + this.image = { width: width, height: height }; + + this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; + this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; + + this.flipY = false; + this.generateMipmaps = false; + + this.compareFunction = null; + + } + + + copy( source ) { + + super.copy( source ); + + this.compareFunction = source.compareFunction; + + return this; + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction; + + return data; + + } + +} + +/** + * Extensible curve object. + * + * Some common of curve methods: + * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget ) + * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget ) + * .getPoints(), .getSpacedPoints() + * .getLength() + * .updateArcLengths() + * + * This following curves inherit from THREE.Curve: + * + * -- 2D curves -- + * THREE.ArcCurve + * THREE.CubicBezierCurve + * THREE.EllipseCurve + * THREE.LineCurve + * THREE.QuadraticBezierCurve + * THREE.SplineCurve + * + * -- 3D curves -- + * THREE.CatmullRomCurve3 + * THREE.CubicBezierCurve3 + * THREE.LineCurve3 + * THREE.QuadraticBezierCurve3 + * + * A series of curves can be represented as a THREE.CurvePath. + * + **/ + +class Curve { + + constructor() { + + this.type = 'Curve'; + + this.arcLengthDivisions = 200; + + } + + // Virtual base class method to overwrite and implement in subclasses + // - t [0 .. 1] + + getPoint( /* t, optionalTarget */ ) { + + console.warn( 'THREE.Curve: .getPoint() not implemented.' ); + return null; + + } + + // Get point at relative position in curve according to arc length + // - u [0 .. 1] + + getPointAt( u, optionalTarget ) { + + const t = this.getUtoTmapping( u ); + return this.getPoint( t, optionalTarget ); + + } + + // Get sequence of points using getPoint( t ) + + getPoints( divisions = 5 ) { + + const points = []; + + for ( let d = 0; d <= divisions; d ++ ) { + + points.push( this.getPoint( d / divisions ) ); + + } + + return points; + + } + + // Get sequence of points using getPointAt( u ) + + getSpacedPoints( divisions = 5 ) { + + const points = []; + + for ( let d = 0; d <= divisions; d ++ ) { + + points.push( this.getPointAt( d / divisions ) ); + + } + + return points; + + } + + // Get total curve arc length + + getLength() { + + const lengths = this.getLengths(); + return lengths[ lengths.length - 1 ]; + + } + + // Get list of cumulative segment lengths + + getLengths( divisions = this.arcLengthDivisions ) { + + if ( this.cacheArcLengths && + ( this.cacheArcLengths.length === divisions + 1 ) && + ! this.needsUpdate ) { + + return this.cacheArcLengths; + + } + + this.needsUpdate = false; + + const cache = []; + let current, last = this.getPoint( 0 ); + let sum = 0; + + cache.push( 0 ); + + for ( let p = 1; p <= divisions; p ++ ) { + + current = this.getPoint( p / divisions ); + sum += current.distanceTo( last ); + cache.push( sum ); + last = current; + + } + + this.cacheArcLengths = cache; + + return cache; // { sums: cache, sum: sum }; Sum is in the last element. + + } + + updateArcLengths() { + + this.needsUpdate = true; + this.getLengths(); + + } + + // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant + + getUtoTmapping( u, distance ) { + + const arcLengths = this.getLengths(); + + let i = 0; + const il = arcLengths.length; + + let targetArcLength; // The targeted u distance value to get + + if ( distance ) { + + targetArcLength = distance; + + } else { + + targetArcLength = u * arcLengths[ il - 1 ]; + + } + + // binary search for the index with largest value smaller than target u distance + + let low = 0, high = il - 1, comparison; + + while ( low <= high ) { + + i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats + + comparison = arcLengths[ i ] - targetArcLength; + + if ( comparison < 0 ) { + + low = i + 1; + + } else if ( comparison > 0 ) { + + high = i - 1; + + } else { + + high = i; + break; + + // DONE + + } + + } + + i = high; + + if ( arcLengths[ i ] === targetArcLength ) { + + return i / ( il - 1 ); + + } + + // we could get finer grain at lengths, or use simple interpolation between two points + + const lengthBefore = arcLengths[ i ]; + const lengthAfter = arcLengths[ i + 1 ]; + + const segmentLength = lengthAfter - lengthBefore; + + // determine where we are between the 'before' and 'after' points + + const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength; + + // add that fractional amount to t + + const t = ( i + segmentFraction ) / ( il - 1 ); + + return t; + + } + + // Returns a unit vector tangent at t + // In case any sub curve does not implement its tangent derivation, + // 2 points a small delta apart will be used to find its gradient + // which seems to give a reasonable approximation + + getTangent( t, optionalTarget ) { + + const delta = 0.0001; + let t1 = t - delta; + let t2 = t + delta; + + // Capping in case of danger + + if ( t1 < 0 ) t1 = 0; + if ( t2 > 1 ) t2 = 1; + + const pt1 = this.getPoint( t1 ); + const pt2 = this.getPoint( t2 ); + + const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() ); + + tangent.copy( pt2 ).sub( pt1 ).normalize(); + + return tangent; + + } + + getTangentAt( u, optionalTarget ) { + + const t = this.getUtoTmapping( u ); + return this.getTangent( t, optionalTarget ); + + } + + computeFrenetFrames( segments, closed ) { + + // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf + + const normal = new Vector3(); + + const tangents = []; + const normals = []; + const binormals = []; + + const vec = new Vector3(); + const mat = new Matrix4(); + + // compute the tangent vectors for each segment on the curve + + for ( let i = 0; i <= segments; i ++ ) { + + const u = i / segments; + + tangents[ i ] = this.getTangentAt( u, new Vector3() ); + + } + + // select an initial normal vector perpendicular to the first tangent vector, + // and in the direction of the minimum tangent xyz component + + normals[ 0 ] = new Vector3(); + binormals[ 0 ] = new Vector3(); + let min = Number.MAX_VALUE; + const tx = Math.abs( tangents[ 0 ].x ); + const ty = Math.abs( tangents[ 0 ].y ); + const tz = Math.abs( tangents[ 0 ].z ); + + if ( tx <= min ) { + + min = tx; + normal.set( 1, 0, 0 ); + + } + + if ( ty <= min ) { + + min = ty; + normal.set( 0, 1, 0 ); + + } + + if ( tz <= min ) { + + normal.set( 0, 0, 1 ); + + } + + vec.crossVectors( tangents[ 0 ], normal ).normalize(); + + normals[ 0 ].crossVectors( tangents[ 0 ], vec ); + binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ); + + + // compute the slowly-varying normal and binormal vectors for each segment on the curve + + for ( let i = 1; i <= segments; i ++ ) { + + normals[ i ] = normals[ i - 1 ].clone(); + + binormals[ i ] = binormals[ i - 1 ].clone(); + + vec.crossVectors( tangents[ i - 1 ], tangents[ i ] ); + + if ( vec.length() > Number.EPSILON ) { + + vec.normalize(); + + const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors + + normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) ); + + } + + binormals[ i ].crossVectors( tangents[ i ], normals[ i ] ); + + } + + // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same + + if ( closed === true ) { + + let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) ); + theta /= segments; + + if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) { + + theta = - theta; + + } + + for ( let i = 1; i <= segments; i ++ ) { + + // twist a little... + normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) ); + binormals[ i ].crossVectors( tangents[ i ], normals[ i ] ); + + } + + } + + return { + tangents: tangents, + normals: normals, + binormals: binormals + }; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( source ) { + + this.arcLengthDivisions = source.arcLengthDivisions; + + return this; + + } + + toJSON() { + + const data = { + metadata: { + version: 4.6, + type: 'Curve', + generator: 'Curve.toJSON' + } + }; + + data.arcLengthDivisions = this.arcLengthDivisions; + data.type = this.type; + + return data; + + } + + fromJSON( json ) { + + this.arcLengthDivisions = json.arcLengthDivisions; + + return this; + + } + +} + +class EllipseCurve extends Curve { + + constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) { + + super(); + + this.isEllipseCurve = true; + + this.type = 'EllipseCurve'; + + this.aX = aX; + this.aY = aY; + + this.xRadius = xRadius; + this.yRadius = yRadius; + + this.aStartAngle = aStartAngle; + this.aEndAngle = aEndAngle; + + this.aClockwise = aClockwise; + + this.aRotation = aRotation; + + } + + getPoint( t, optionalTarget = new Vector2() ) { + + const point = optionalTarget; + + const twoPi = Math.PI * 2; + let deltaAngle = this.aEndAngle - this.aStartAngle; + const samePoints = Math.abs( deltaAngle ) < Number.EPSILON; + + // ensures that deltaAngle is 0 .. 2 PI + while ( deltaAngle < 0 ) deltaAngle += twoPi; + while ( deltaAngle > twoPi ) deltaAngle -= twoPi; + + if ( deltaAngle < Number.EPSILON ) { + + if ( samePoints ) { + + deltaAngle = 0; + + } else { + + deltaAngle = twoPi; + + } + + } + + if ( this.aClockwise === true && ! samePoints ) { + + if ( deltaAngle === twoPi ) { + + deltaAngle = - twoPi; + + } else { + + deltaAngle = deltaAngle - twoPi; + + } + + } + + const angle = this.aStartAngle + t * deltaAngle; + let x = this.aX + this.xRadius * Math.cos( angle ); + let y = this.aY + this.yRadius * Math.sin( angle ); + + if ( this.aRotation !== 0 ) { + + const cos = Math.cos( this.aRotation ); + const sin = Math.sin( this.aRotation ); + + const tx = x - this.aX; + const ty = y - this.aY; + + // Rotate the point about the center of the ellipse. + x = tx * cos - ty * sin + this.aX; + y = tx * sin + ty * cos + this.aY; + + } + + return point.set( x, y ); + + } + + copy( source ) { + + super.copy( source ); + + this.aX = source.aX; + this.aY = source.aY; + + this.xRadius = source.xRadius; + this.yRadius = source.yRadius; + + this.aStartAngle = source.aStartAngle; + this.aEndAngle = source.aEndAngle; + + this.aClockwise = source.aClockwise; + + this.aRotation = source.aRotation; + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.aX = this.aX; + data.aY = this.aY; + + data.xRadius = this.xRadius; + data.yRadius = this.yRadius; + + data.aStartAngle = this.aStartAngle; + data.aEndAngle = this.aEndAngle; + + data.aClockwise = this.aClockwise; + + data.aRotation = this.aRotation; + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.aX = json.aX; + this.aY = json.aY; + + this.xRadius = json.xRadius; + this.yRadius = json.yRadius; + + this.aStartAngle = json.aStartAngle; + this.aEndAngle = json.aEndAngle; + + this.aClockwise = json.aClockwise; + + this.aRotation = json.aRotation; + + return this; + + } + +} + +class ArcCurve extends EllipseCurve { + + constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { + + super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise ); + + this.isArcCurve = true; + + this.type = 'ArcCurve'; + + } + +} + +/** + * Centripetal CatmullRom Curve - which is useful for avoiding + * cusps and self-intersections in non-uniform catmull rom curves. + * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf + * + * curve.type accepts centripetal(default), chordal and catmullrom + * curve.tension is used for catmullrom which defaults to 0.5 + */ + + +/* +Based on an optimized c++ solution in + - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/ + - http://ideone.com/NoEbVM + +This CubicPoly class could be used for reusing some variables and calculations, +but for three.js curve use, it could be possible inlined and flatten into a single function call +which can be placed in CurveUtils. +*/ + +function CubicPoly() { + + let c0 = 0, c1 = 0, c2 = 0, c3 = 0; + + /* + * Compute coefficients for a cubic polynomial + * p(s) = c0 + c1*s + c2*s^2 + c3*s^3 + * such that + * p(0) = x0, p(1) = x1 + * and + * p'(0) = t0, p'(1) = t1. + */ + function init( x0, x1, t0, t1 ) { + + c0 = x0; + c1 = t0; + c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1; + c3 = 2 * x0 - 2 * x1 + t0 + t1; + + } + + return { + + initCatmullRom: function ( x0, x1, x2, x3, tension ) { + + init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) ); + + }, + + initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) { + + // compute tangents when parameterized in [t1,t2] + let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1; + let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2; + + // rescale tangents for parametrization in [0,1] + t1 *= dt1; + t2 *= dt1; + + init( x1, x2, t1, t2 ); + + }, + + calc: function ( t ) { + + const t2 = t * t; + const t3 = t2 * t; + return c0 + c1 * t + c2 * t2 + c3 * t3; + + } + + }; + +} + +// + +const tmp = /*@__PURE__*/ new Vector3(); +const px = /*@__PURE__*/ new CubicPoly(); +const py = /*@__PURE__*/ new CubicPoly(); +const pz = /*@__PURE__*/ new CubicPoly(); + +class CatmullRomCurve3 extends Curve { + + constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) { + + super(); + + this.isCatmullRomCurve3 = true; + + this.type = 'CatmullRomCurve3'; + + this.points = points; + this.closed = closed; + this.curveType = curveType; + this.tension = tension; + + } + + getPoint( t, optionalTarget = new Vector3() ) { + + const point = optionalTarget; + + const points = this.points; + const l = points.length; + + const p = ( l - ( this.closed ? 0 : 1 ) ) * t; + let intPoint = Math.floor( p ); + let weight = p - intPoint; + + if ( this.closed ) { + + intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l; + + } else if ( weight === 0 && intPoint === l - 1 ) { + + intPoint = l - 2; + weight = 1; + + } + + let p0, p3; // 4 points (p1 & p2 defined below) + + if ( this.closed || intPoint > 0 ) { + + p0 = points[ ( intPoint - 1 ) % l ]; + + } else { + + // extrapolate first point + tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] ); + p0 = tmp; + + } + + const p1 = points[ intPoint % l ]; + const p2 = points[ ( intPoint + 1 ) % l ]; + + if ( this.closed || intPoint + 2 < l ) { + + p3 = points[ ( intPoint + 2 ) % l ]; + + } else { + + // extrapolate last point + tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] ); + p3 = tmp; + + } + + if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) { + + // init Centripetal / Chordal Catmull-Rom + const pow = this.curveType === 'chordal' ? 0.5 : 0.25; + let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow ); + let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow ); + let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow ); + + // safety check for repeated points + if ( dt1 < 1e-4 ) dt1 = 1.0; + if ( dt0 < 1e-4 ) dt0 = dt1; + if ( dt2 < 1e-4 ) dt2 = dt1; + + px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 ); + py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 ); + pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 ); + + } else if ( this.curveType === 'catmullrom' ) { + + px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension ); + py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension ); + pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension ); + + } + + point.set( + px.calc( weight ), + py.calc( weight ), + pz.calc( weight ) + ); + + return point; + + } + + copy( source ) { + + super.copy( source ); + + this.points = []; + + for ( let i = 0, l = source.points.length; i < l; i ++ ) { + + const point = source.points[ i ]; + + this.points.push( point.clone() ); + + } + + this.closed = source.closed; + this.curveType = source.curveType; + this.tension = source.tension; + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.points = []; + + for ( let i = 0, l = this.points.length; i < l; i ++ ) { + + const point = this.points[ i ]; + data.points.push( point.toArray() ); + + } + + data.closed = this.closed; + data.curveType = this.curveType; + data.tension = this.tension; + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.points = []; + + for ( let i = 0, l = json.points.length; i < l; i ++ ) { + + const point = json.points[ i ]; + this.points.push( new Vector3().fromArray( point ) ); + + } + + this.closed = json.closed; + this.curveType = json.curveType; + this.tension = json.tension; + + return this; + + } + +} + +/** + * Bezier Curves formulas obtained from + * https://en.wikipedia.org/wiki/B%C3%A9zier_curve + */ + +function CatmullRom( t, p0, p1, p2, p3 ) { + + const v0 = ( p2 - p0 ) * 0.5; + const v1 = ( p3 - p1 ) * 0.5; + const t2 = t * t; + const t3 = t * t2; + return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1; + +} + +// + +function QuadraticBezierP0( t, p ) { + + const k = 1 - t; + return k * k * p; + +} + +function QuadraticBezierP1( t, p ) { + + return 2 * ( 1 - t ) * t * p; + +} + +function QuadraticBezierP2( t, p ) { + + return t * t * p; + +} + +function QuadraticBezier( t, p0, p1, p2 ) { + + return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) + + QuadraticBezierP2( t, p2 ); + +} + +// + +function CubicBezierP0( t, p ) { + + const k = 1 - t; + return k * k * k * p; + +} + +function CubicBezierP1( t, p ) { + + const k = 1 - t; + return 3 * k * k * t * p; + +} + +function CubicBezierP2( t, p ) { + + return 3 * ( 1 - t ) * t * t * p; + +} + +function CubicBezierP3( t, p ) { + + return t * t * t * p; + +} + +function CubicBezier( t, p0, p1, p2, p3 ) { + + return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) + + CubicBezierP3( t, p3 ); + +} + +class CubicBezierCurve extends Curve { + + constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) { + + super(); + + this.isCubicBezierCurve = true; + + this.type = 'CubicBezierCurve'; + + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + + } + + getPoint( t, optionalTarget = new Vector2() ) { + + const point = optionalTarget; + + const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3; + + point.set( + CubicBezier( t, v0.x, v1.x, v2.x, v3.x ), + CubicBezier( t, v0.y, v1.y, v2.y, v3.y ) + ); + + return point; + + } + + copy( source ) { + + super.copy( source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + this.v3.copy( source.v3 ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + data.v3 = this.v3.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + this.v3.fromArray( json.v3 ); + + return this; + + } + +} + +class CubicBezierCurve3 extends Curve { + + constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) { + + super(); + + this.isCubicBezierCurve3 = true; + + this.type = 'CubicBezierCurve3'; + + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + + } + + getPoint( t, optionalTarget = new Vector3() ) { + + const point = optionalTarget; + + const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3; + + point.set( + CubicBezier( t, v0.x, v1.x, v2.x, v3.x ), + CubicBezier( t, v0.y, v1.y, v2.y, v3.y ), + CubicBezier( t, v0.z, v1.z, v2.z, v3.z ) + ); + + return point; + + } + + copy( source ) { + + super.copy( source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + this.v3.copy( source.v3 ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + data.v3 = this.v3.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + this.v3.fromArray( json.v3 ); + + return this; + + } + +} + +class LineCurve extends Curve { + + constructor( v1 = new Vector2(), v2 = new Vector2() ) { + + super(); + + this.isLineCurve = true; + + this.type = 'LineCurve'; + + this.v1 = v1; + this.v2 = v2; + + } + + getPoint( t, optionalTarget = new Vector2() ) { + + const point = optionalTarget; + + if ( t === 1 ) { + + point.copy( this.v2 ); + + } else { + + point.copy( this.v2 ).sub( this.v1 ); + point.multiplyScalar( t ).add( this.v1 ); + + } + + return point; + + } + + // Line curve is linear, so we can overwrite default getPointAt + getPointAt( u, optionalTarget ) { + + return this.getPoint( u, optionalTarget ); + + } + + getTangent( t, optionalTarget = new Vector2() ) { + + return optionalTarget.subVectors( this.v2, this.v1 ).normalize(); + + } + + getTangentAt( u, optionalTarget ) { + + return this.getTangent( u, optionalTarget ); + + } + + copy( source ) { + + super.copy( source ); + + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + } + +} + +class LineCurve3 extends Curve { + + constructor( v1 = new Vector3(), v2 = new Vector3() ) { + + super(); + + this.isLineCurve3 = true; + + this.type = 'LineCurve3'; + + this.v1 = v1; + this.v2 = v2; + + } + + getPoint( t, optionalTarget = new Vector3() ) { + + const point = optionalTarget; + + if ( t === 1 ) { + + point.copy( this.v2 ); + + } else { + + point.copy( this.v2 ).sub( this.v1 ); + point.multiplyScalar( t ).add( this.v1 ); + + } + + return point; + + } + + // Line curve is linear, so we can overwrite default getPointAt + getPointAt( u, optionalTarget ) { + + return this.getPoint( u, optionalTarget ); + + } + + getTangent( t, optionalTarget = new Vector3() ) { + + return optionalTarget.subVectors( this.v2, this.v1 ).normalize(); + + } + + getTangentAt( u, optionalTarget ) { + + return this.getTangent( u, optionalTarget ); + + } + + copy( source ) { + + super.copy( source ); + + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + } + +} + +class QuadraticBezierCurve extends Curve { + + constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) { + + super(); + + this.isQuadraticBezierCurve = true; + + this.type = 'QuadraticBezierCurve'; + + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + + } + + getPoint( t, optionalTarget = new Vector2() ) { + + const point = optionalTarget; + + const v0 = this.v0, v1 = this.v1, v2 = this.v2; + + point.set( + QuadraticBezier( t, v0.x, v1.x, v2.x ), + QuadraticBezier( t, v0.y, v1.y, v2.y ) + ); + + return point; + + } + + copy( source ) { + + super.copy( source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + } + +} + +class QuadraticBezierCurve3 extends Curve { + + constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) { + + super(); + + this.isQuadraticBezierCurve3 = true; + + this.type = 'QuadraticBezierCurve3'; + + this.v0 = v0; + this.v1 = v1; + this.v2 = v2; + + } + + getPoint( t, optionalTarget = new Vector3() ) { + + const point = optionalTarget; + + const v0 = this.v0, v1 = this.v1, v2 = this.v2; + + point.set( + QuadraticBezier( t, v0.x, v1.x, v2.x ), + QuadraticBezier( t, v0.y, v1.y, v2.y ), + QuadraticBezier( t, v0.z, v1.z, v2.z ) + ); + + return point; + + } + + copy( source ) { + + super.copy( source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + } + +} + +class SplineCurve extends Curve { + + constructor( points = [] ) { + + super(); + + this.isSplineCurve = true; + + this.type = 'SplineCurve'; + + this.points = points; + + } + + getPoint( t, optionalTarget = new Vector2() ) { + + const point = optionalTarget; + + const points = this.points; + const p = ( points.length - 1 ) * t; + + const intPoint = Math.floor( p ); + const weight = p - intPoint; + + const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ]; + const p1 = points[ intPoint ]; + const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ]; + const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ]; + + point.set( + CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ), + CatmullRom( weight, p0.y, p1.y, p2.y, p3.y ) + ); + + return point; + + } + + copy( source ) { + + super.copy( source ); + + this.points = []; + + for ( let i = 0, l = source.points.length; i < l; i ++ ) { + + const point = source.points[ i ]; + + this.points.push( point.clone() ); + + } + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.points = []; + + for ( let i = 0, l = this.points.length; i < l; i ++ ) { + + const point = this.points[ i ]; + data.points.push( point.toArray() ); + + } + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.points = []; + + for ( let i = 0, l = json.points.length; i < l; i ++ ) { + + const point = json.points[ i ]; + this.points.push( new Vector2().fromArray( point ) ); + + } + + return this; + + } + +} + +var Curves = /*#__PURE__*/Object.freeze({ + __proto__: null, + ArcCurve: ArcCurve, + CatmullRomCurve3: CatmullRomCurve3, + CubicBezierCurve: CubicBezierCurve, + CubicBezierCurve3: CubicBezierCurve3, + EllipseCurve: EllipseCurve, + LineCurve: LineCurve, + LineCurve3: LineCurve3, + QuadraticBezierCurve: QuadraticBezierCurve, + QuadraticBezierCurve3: QuadraticBezierCurve3, + SplineCurve: SplineCurve +}); + +/************************************************************** + * Curved Path - a curve path is simply a array of connected + * curves, but retains the api of a curve + **************************************************************/ + +class CurvePath extends Curve { + + constructor() { + + super(); + + this.type = 'CurvePath'; + + this.curves = []; + this.autoClose = false; // Automatically closes the path + + } + + add( curve ) { + + this.curves.push( curve ); + + } + + closePath() { + + // Add a line curve if start and end of lines are not connected + const startPoint = this.curves[ 0 ].getPoint( 0 ); + const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 ); + + if ( ! startPoint.equals( endPoint ) ) { + + const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3'; + this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) ); + + } + + return this; + + } + + // To get accurate point with reference to + // entire path distance at time t, + // following has to be done: + + // 1. Length of each sub path have to be known + // 2. Locate and identify type of curve + // 3. Get t for the curve + // 4. Return curve.getPointAt(t') + + getPoint( t, optionalTarget ) { + + const d = t * this.getLength(); + const curveLengths = this.getCurveLengths(); + let i = 0; + + // To think about boundaries points. + + while ( i < curveLengths.length ) { + + if ( curveLengths[ i ] >= d ) { + + const diff = curveLengths[ i ] - d; + const curve = this.curves[ i ]; + + const segmentLength = curve.getLength(); + const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength; + + return curve.getPointAt( u, optionalTarget ); + + } + + i ++; + + } + + return null; + + // loop where sum != 0, sum > d , sum+1 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) { + + points.push( points[ 0 ] ); + + } + + return points; + + } + + copy( source ) { + + super.copy( source ); + + this.curves = []; + + for ( let i = 0, l = source.curves.length; i < l; i ++ ) { + + const curve = source.curves[ i ]; + + this.curves.push( curve.clone() ); + + } + + this.autoClose = source.autoClose; + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.autoClose = this.autoClose; + data.curves = []; + + for ( let i = 0, l = this.curves.length; i < l; i ++ ) { + + const curve = this.curves[ i ]; + data.curves.push( curve.toJSON() ); + + } + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.autoClose = json.autoClose; + this.curves = []; + + for ( let i = 0, l = json.curves.length; i < l; i ++ ) { + + const curve = json.curves[ i ]; + this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) ); + + } + + return this; + + } + +} + +class Path extends CurvePath { + + constructor( points ) { + + super(); + + this.type = 'Path'; + + this.currentPoint = new Vector2(); + + if ( points ) { + + this.setFromPoints( points ); + + } + + } + + setFromPoints( points ) { + + this.moveTo( points[ 0 ].x, points[ 0 ].y ); + + for ( let i = 1, l = points.length; i < l; i ++ ) { + + this.lineTo( points[ i ].x, points[ i ].y ); + + } + + return this; + + } + + moveTo( x, y ) { + + this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying? + + return this; + + } + + lineTo( x, y ) { + + const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) ); + this.curves.push( curve ); + + this.currentPoint.set( x, y ); + + return this; + + } + + quadraticCurveTo( aCPx, aCPy, aX, aY ) { + + const curve = new QuadraticBezierCurve( + this.currentPoint.clone(), + new Vector2( aCPx, aCPy ), + new Vector2( aX, aY ) + ); + + this.curves.push( curve ); + + this.currentPoint.set( aX, aY ); + + return this; + + } + + bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) { + + const curve = new CubicBezierCurve( + this.currentPoint.clone(), + new Vector2( aCP1x, aCP1y ), + new Vector2( aCP2x, aCP2y ), + new Vector2( aX, aY ) + ); + + this.curves.push( curve ); + + this.currentPoint.set( aX, aY ); + + return this; + + } + + splineThru( pts /*Array of Vector*/ ) { + + const npts = [ this.currentPoint.clone() ].concat( pts ); + + const curve = new SplineCurve( npts ); + this.curves.push( curve ); + + this.currentPoint.copy( pts[ pts.length - 1 ] ); + + return this; + + } + + arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { + + const x0 = this.currentPoint.x; + const y0 = this.currentPoint.y; + + this.absarc( aX + x0, aY + y0, aRadius, + aStartAngle, aEndAngle, aClockwise ); + + return this; + + } + + absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { + + this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise ); + + return this; + + } + + ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) { + + const x0 = this.currentPoint.x; + const y0 = this.currentPoint.y; + + this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ); + + return this; + + } + + absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) { + + const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ); + + if ( this.curves.length > 0 ) { + + // if a previous curve is present, attempt to join + const firstPoint = curve.getPoint( 0 ); + + if ( ! firstPoint.equals( this.currentPoint ) ) { + + this.lineTo( firstPoint.x, firstPoint.y ); + + } + + } + + this.curves.push( curve ); + + const lastPoint = curve.getPoint( 1 ); + this.currentPoint.copy( lastPoint ); + + return this; + + } + + copy( source ) { + + super.copy( source ); + + this.currentPoint.copy( source.currentPoint ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.currentPoint = this.currentPoint.toArray(); + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.currentPoint.fromArray( json.currentPoint ); + + return this; + + } + +} + +class LatheGeometry extends BufferGeometry { + + constructor( points = [ new Vector2( 0, - 0.5 ), new Vector2( 0.5, 0 ), new Vector2( 0, 0.5 ) ], segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) { + + super(); + + this.type = 'LatheGeometry'; + + this.parameters = { + points: points, + segments: segments, + phiStart: phiStart, + phiLength: phiLength + }; + + segments = Math.floor( segments ); + + // clamp phiLength so it's in range of [ 0, 2PI ] + + phiLength = clamp( phiLength, 0, Math.PI * 2 ); + + // buffers + + const indices = []; + const vertices = []; + const uvs = []; + const initNormals = []; + const normals = []; + + // helper variables + + const inverseSegments = 1.0 / segments; + const vertex = new Vector3(); + const uv = new Vector2(); + const normal = new Vector3(); + const curNormal = new Vector3(); + const prevNormal = new Vector3(); + let dx = 0; + let dy = 0; + + // pre-compute normals for initial "meridian" + + for ( let j = 0; j <= ( points.length - 1 ); j ++ ) { + + switch ( j ) { + + case 0: // special handling for 1st vertex on path + + dx = points[ j + 1 ].x - points[ j ].x; + dy = points[ j + 1 ].y - points[ j ].y; + + normal.x = dy * 1.0; + normal.y = - dx; + normal.z = dy * 0.0; + + prevNormal.copy( normal ); + + normal.normalize(); + + initNormals.push( normal.x, normal.y, normal.z ); + + break; + + case ( points.length - 1 ): // special handling for last Vertex on path + + initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z ); + + break; + + default: // default handling for all vertices in between + + dx = points[ j + 1 ].x - points[ j ].x; + dy = points[ j + 1 ].y - points[ j ].y; + + normal.x = dy * 1.0; + normal.y = - dx; + normal.z = dy * 0.0; + + curNormal.copy( normal ); + + normal.x += prevNormal.x; + normal.y += prevNormal.y; + normal.z += prevNormal.z; + + normal.normalize(); + + initNormals.push( normal.x, normal.y, normal.z ); + + prevNormal.copy( curNormal ); + + } + + } + + // generate vertices, uvs and normals + + for ( let i = 0; i <= segments; i ++ ) { + + const phi = phiStart + i * inverseSegments * phiLength; + + const sin = Math.sin( phi ); + const cos = Math.cos( phi ); + + for ( let j = 0; j <= ( points.length - 1 ); j ++ ) { + + // vertex + + vertex.x = points[ j ].x * sin; + vertex.y = points[ j ].y; + vertex.z = points[ j ].x * cos; + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // uv + + uv.x = i / segments; + uv.y = j / ( points.length - 1 ); + + uvs.push( uv.x, uv.y ); + + // normal + + const x = initNormals[ 3 * j + 0 ] * sin; + const y = initNormals[ 3 * j + 1 ]; + const z = initNormals[ 3 * j + 0 ] * cos; + + normals.push( x, y, z ); + + } + + } + + // indices + + for ( let i = 0; i < segments; i ++ ) { + + for ( let j = 0; j < ( points.length - 1 ); j ++ ) { + + const base = j + i * points.length; + + const a = base; + const b = base + points.length; + const c = base + points.length + 1; + const d = base + 1; + + // faces + + indices.push( a, b, d ); + indices.push( c, d, b ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength ); + + } + +} + +class CapsuleGeometry extends LatheGeometry { + + constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) { + + const path = new Path(); + path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 ); + path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 ); + + super( path.getPoints( capSegments ), radialSegments ); + + this.type = 'CapsuleGeometry'; + + this.parameters = { + radius: radius, + length: length, + capSegments: capSegments, + radialSegments: radialSegments, + }; + + } + + static fromJSON( data ) { + + return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments ); + + } + +} + +class CircleGeometry extends BufferGeometry { + + constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) { + + super(); + + this.type = 'CircleGeometry'; + + this.parameters = { + radius: radius, + segments: segments, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + segments = Math.max( 3, segments ); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // helper variables + + const vertex = new Vector3(); + const uv = new Vector2(); + + // center point + + vertices.push( 0, 0, 0 ); + normals.push( 0, 0, 1 ); + uvs.push( 0.5, 0.5 ); + + for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) { + + const segment = thetaStart + s / segments * thetaLength; + + // vertex + + vertex.x = radius * Math.cos( segment ); + vertex.y = radius * Math.sin( segment ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normals.push( 0, 0, 1 ); + + // uvs + + uv.x = ( vertices[ i ] / radius + 1 ) / 2; + uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2; + + uvs.push( uv.x, uv.y ); + + } + + // indices + + for ( let i = 1; i <= segments; i ++ ) { + + indices.push( i, i + 1, 0 ); + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength ); + + } + +} + +class CylinderGeometry extends BufferGeometry { + + constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) { + + super(); + + this.type = 'CylinderGeometry'; + + this.parameters = { + radiusTop: radiusTop, + radiusBottom: radiusBottom, + height: height, + radialSegments: radialSegments, + heightSegments: heightSegments, + openEnded: openEnded, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + const scope = this; + + radialSegments = Math.floor( radialSegments ); + heightSegments = Math.floor( heightSegments ); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // helper variables + + let index = 0; + const indexArray = []; + const halfHeight = height / 2; + let groupStart = 0; + + // generate geometry + + generateTorso(); + + if ( openEnded === false ) { + + if ( radiusTop > 0 ) generateCap( true ); + if ( radiusBottom > 0 ) generateCap( false ); + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + function generateTorso() { + + const normal = new Vector3(); + const vertex = new Vector3(); + + let groupCount = 0; + + // this will be used to calculate the normal + const slope = ( radiusBottom - radiusTop ) / height; + + // generate vertices, normals and uvs + + for ( let y = 0; y <= heightSegments; y ++ ) { + + const indexRow = []; + + const v = y / heightSegments; + + // calculate the radius of the current row + + const radius = v * ( radiusBottom - radiusTop ) + radiusTop; + + for ( let x = 0; x <= radialSegments; x ++ ) { + + const u = x / radialSegments; + + const theta = u * thetaLength + thetaStart; + + const sinTheta = Math.sin( theta ); + const cosTheta = Math.cos( theta ); + + // vertex + + vertex.x = radius * sinTheta; + vertex.y = - v * height + halfHeight; + vertex.z = radius * cosTheta; + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normal.set( sinTheta, slope, cosTheta ).normalize(); + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( u, 1 - v ); + + // save index of vertex in respective row + + indexRow.push( index ++ ); + + } + + // now save vertices of the row in our index array + + indexArray.push( indexRow ); + + } + + // generate indices + + for ( let x = 0; x < radialSegments; x ++ ) { + + for ( let y = 0; y < heightSegments; y ++ ) { + + // we use the index array to access the correct indices + + const a = indexArray[ y ][ x ]; + const b = indexArray[ y + 1 ][ x ]; + const c = indexArray[ y + 1 ][ x + 1 ]; + const d = indexArray[ y ][ x + 1 ]; + + // faces + + if ( radiusTop > 0 || y !== 0 ) { + + indices.push( a, b, d ); + groupCount += 3; + + } + + if ( radiusBottom > 0 || y !== heightSegments - 1 ) { + + indices.push( b, c, d ); + groupCount += 3; + + } + + } + + } + + // add a group to the geometry. this will ensure multi material support + + scope.addGroup( groupStart, groupCount, 0 ); + + // calculate new start value for groups + + groupStart += groupCount; + + } + + function generateCap( top ) { + + // save the index of the first center vertex + const centerIndexStart = index; + + const uv = new Vector2(); + const vertex = new Vector3(); + + let groupCount = 0; + + const radius = ( top === true ) ? radiusTop : radiusBottom; + const sign = ( top === true ) ? 1 : - 1; + + // first we generate the center vertex data of the cap. + // because the geometry needs one set of uvs per face, + // we must generate a center vertex per face/segment + + for ( let x = 1; x <= radialSegments; x ++ ) { + + // vertex + + vertices.push( 0, halfHeight * sign, 0 ); + + // normal + + normals.push( 0, sign, 0 ); + + // uv + + uvs.push( 0.5, 0.5 ); + + // increase index + + index ++; + + } + + // save the index of the last center vertex + const centerIndexEnd = index; + + // now we generate the surrounding vertices, normals and uvs + + for ( let x = 0; x <= radialSegments; x ++ ) { + + const u = x / radialSegments; + const theta = u * thetaLength + thetaStart; + + const cosTheta = Math.cos( theta ); + const sinTheta = Math.sin( theta ); + + // vertex + + vertex.x = radius * sinTheta; + vertex.y = halfHeight * sign; + vertex.z = radius * cosTheta; + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normals.push( 0, sign, 0 ); + + // uv + + uv.x = ( cosTheta * 0.5 ) + 0.5; + uv.y = ( sinTheta * 0.5 * sign ) + 0.5; + uvs.push( uv.x, uv.y ); + + // increase index + + index ++; + + } + + // generate indices + + for ( let x = 0; x < radialSegments; x ++ ) { + + const c = centerIndexStart + x; + const i = centerIndexEnd + x; + + if ( top === true ) { + + // face top + + indices.push( i, i + 1, c ); + + } else { + + // face bottom + + indices.push( i + 1, i, c ); + + } + + groupCount += 3; + + } + + // add a group to the geometry. this will ensure multi material support + + scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 ); + + // calculate new start value for groups + + groupStart += groupCount; + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength ); + + } + +} + +class ConeGeometry extends CylinderGeometry { + + constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) { + + super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ); + + this.type = 'ConeGeometry'; + + this.parameters = { + radius: radius, + height: height, + radialSegments: radialSegments, + heightSegments: heightSegments, + openEnded: openEnded, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + } + + static fromJSON( data ) { + + return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength ); + + } + +} + +class PolyhedronGeometry extends BufferGeometry { + + constructor( vertices = [], indices = [], radius = 1, detail = 0 ) { + + super(); + + this.type = 'PolyhedronGeometry'; + + this.parameters = { + vertices: vertices, + indices: indices, + radius: radius, + detail: detail + }; + + // default buffer data + + const vertexBuffer = []; + const uvBuffer = []; + + // the subdivision creates the vertex buffer data + + subdivide( detail ); + + // all vertices should lie on a conceptual sphere with a given radius + + applyRadius( radius ); + + // finally, create the uv data + + generateUVs(); + + // build non-indexed geometry + + this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) ); + + if ( detail === 0 ) { + + this.computeVertexNormals(); // flat normals + + } else { + + this.normalizeNormals(); // smooth normals + + } + + // helper functions + + function subdivide( detail ) { + + const a = new Vector3(); + const b = new Vector3(); + const c = new Vector3(); + + // iterate over all faces and apply a subdivision with the given detail value + + for ( let i = 0; i < indices.length; i += 3 ) { + + // get the vertices of the face + + getVertexByIndex( indices[ i + 0 ], a ); + getVertexByIndex( indices[ i + 1 ], b ); + getVertexByIndex( indices[ i + 2 ], c ); + + // perform subdivision + + subdivideFace( a, b, c, detail ); + + } + + } + + function subdivideFace( a, b, c, detail ) { + + const cols = detail + 1; + + // we use this multidimensional array as a data structure for creating the subdivision + + const v = []; + + // construct all of the vertices for this subdivision + + for ( let i = 0; i <= cols; i ++ ) { + + v[ i ] = []; + + const aj = a.clone().lerp( c, i / cols ); + const bj = b.clone().lerp( c, i / cols ); + + const rows = cols - i; + + for ( let j = 0; j <= rows; j ++ ) { + + if ( j === 0 && i === cols ) { + + v[ i ][ j ] = aj; + + } else { + + v[ i ][ j ] = aj.clone().lerp( bj, j / rows ); + + } + + } + + } + + // construct all of the faces + + for ( let i = 0; i < cols; i ++ ) { + + for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) { + + const k = Math.floor( j / 2 ); + + if ( j % 2 === 0 ) { + + pushVertex( v[ i ][ k + 1 ] ); + pushVertex( v[ i + 1 ][ k ] ); + pushVertex( v[ i ][ k ] ); + + } else { + + pushVertex( v[ i ][ k + 1 ] ); + pushVertex( v[ i + 1 ][ k + 1 ] ); + pushVertex( v[ i + 1 ][ k ] ); + + } + + } + + } + + } + + function applyRadius( radius ) { + + const vertex = new Vector3(); + + // iterate over the entire buffer and apply the radius to each vertex + + for ( let i = 0; i < vertexBuffer.length; i += 3 ) { + + vertex.x = vertexBuffer[ i + 0 ]; + vertex.y = vertexBuffer[ i + 1 ]; + vertex.z = vertexBuffer[ i + 2 ]; + + vertex.normalize().multiplyScalar( radius ); + + vertexBuffer[ i + 0 ] = vertex.x; + vertexBuffer[ i + 1 ] = vertex.y; + vertexBuffer[ i + 2 ] = vertex.z; + + } + + } + + function generateUVs() { + + const vertex = new Vector3(); + + for ( let i = 0; i < vertexBuffer.length; i += 3 ) { + + vertex.x = vertexBuffer[ i + 0 ]; + vertex.y = vertexBuffer[ i + 1 ]; + vertex.z = vertexBuffer[ i + 2 ]; + + const u = azimuth( vertex ) / 2 / Math.PI + 0.5; + const v = inclination( vertex ) / Math.PI + 0.5; + uvBuffer.push( u, 1 - v ); + + } + + correctUVs(); + + correctSeam(); + + } + + function correctSeam() { + + // handle case when face straddles the seam, see #3269 + + for ( let i = 0; i < uvBuffer.length; i += 6 ) { + + // uv data of a single face + + const x0 = uvBuffer[ i + 0 ]; + const x1 = uvBuffer[ i + 2 ]; + const x2 = uvBuffer[ i + 4 ]; + + const max = Math.max( x0, x1, x2 ); + const min = Math.min( x0, x1, x2 ); + + // 0.9 is somewhat arbitrary + + if ( max > 0.9 && min < 0.1 ) { + + if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1; + if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1; + if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1; + + } + + } + + } + + function pushVertex( vertex ) { + + vertexBuffer.push( vertex.x, vertex.y, vertex.z ); + + } + + function getVertexByIndex( index, vertex ) { + + const stride = index * 3; + + vertex.x = vertices[ stride + 0 ]; + vertex.y = vertices[ stride + 1 ]; + vertex.z = vertices[ stride + 2 ]; + + } + + function correctUVs() { + + const a = new Vector3(); + const b = new Vector3(); + const c = new Vector3(); + + const centroid = new Vector3(); + + const uvA = new Vector2(); + const uvB = new Vector2(); + const uvC = new Vector2(); + + for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) { + + a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] ); + b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] ); + c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] ); + + uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] ); + uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] ); + uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] ); + + centroid.copy( a ).add( b ).add( c ).divideScalar( 3 ); + + const azi = azimuth( centroid ); + + correctUV( uvA, j + 0, a, azi ); + correctUV( uvB, j + 2, b, azi ); + correctUV( uvC, j + 4, c, azi ); + + } + + } + + function correctUV( uv, stride, vector, azimuth ) { + + if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) { + + uvBuffer[ stride ] = uv.x - 1; + + } + + if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) { + + uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5; + + } + + } + + // Angle around the Y axis, counter-clockwise when looking from above. + + function azimuth( vector ) { + + return Math.atan2( vector.z, - vector.x ); + + } + + + // Angle above the XZ plane. + + function inclination( vector ) { + + return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) ); + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details ); + + } + +} + +class DodecahedronGeometry extends PolyhedronGeometry { + + constructor( radius = 1, detail = 0 ) { + + const t = ( 1 + Math.sqrt( 5 ) ) / 2; + const r = 1 / t; + + const vertices = [ + + // (±1, ±1, ±1) + - 1, - 1, - 1, - 1, - 1, 1, + - 1, 1, - 1, - 1, 1, 1, + 1, - 1, - 1, 1, - 1, 1, + 1, 1, - 1, 1, 1, 1, + + // (0, ±1/φ, ±φ) + 0, - r, - t, 0, - r, t, + 0, r, - t, 0, r, t, + + // (±1/φ, ±φ, 0) + - r, - t, 0, - r, t, 0, + r, - t, 0, r, t, 0, + + // (±φ, 0, ±1/φ) + - t, 0, - r, t, 0, - r, + - t, 0, r, t, 0, r + ]; + + const indices = [ + 3, 11, 7, 3, 7, 15, 3, 15, 13, + 7, 19, 17, 7, 17, 6, 7, 6, 15, + 17, 4, 8, 17, 8, 10, 17, 10, 6, + 8, 0, 16, 8, 16, 2, 8, 2, 10, + 0, 12, 1, 0, 1, 18, 0, 18, 16, + 6, 10, 2, 6, 2, 13, 6, 13, 15, + 2, 16, 18, 2, 18, 3, 2, 3, 13, + 18, 1, 9, 18, 9, 11, 18, 11, 3, + 4, 14, 12, 4, 12, 0, 4, 0, 8, + 11, 9, 5, 11, 5, 19, 11, 19, 7, + 19, 5, 14, 19, 14, 4, 19, 4, 17, + 1, 12, 14, 1, 14, 5, 1, 5, 9 + ]; + + super( vertices, indices, radius, detail ); + + this.type = 'DodecahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + static fromJSON( data ) { + + return new DodecahedronGeometry( data.radius, data.detail ); + + } + +} + +const _v0 = /*@__PURE__*/ new Vector3(); +const _v1$1 = /*@__PURE__*/ new Vector3(); +const _normal = /*@__PURE__*/ new Vector3(); +const _triangle = /*@__PURE__*/ new Triangle(); + +class EdgesGeometry extends BufferGeometry { + + constructor( geometry = null, thresholdAngle = 1 ) { + + super(); + + this.type = 'EdgesGeometry'; + + this.parameters = { + geometry: geometry, + thresholdAngle: thresholdAngle + }; + + if ( geometry !== null ) { + + const precisionPoints = 4; + const precision = Math.pow( 10, precisionPoints ); + const thresholdDot = Math.cos( DEG2RAD * thresholdAngle ); + + const indexAttr = geometry.getIndex(); + const positionAttr = geometry.getAttribute( 'position' ); + const indexCount = indexAttr ? indexAttr.count : positionAttr.count; + + const indexArr = [ 0, 0, 0 ]; + const vertKeys = [ 'a', 'b', 'c' ]; + const hashes = new Array( 3 ); + + const edgeData = {}; + const vertices = []; + for ( let i = 0; i < indexCount; i += 3 ) { + + if ( indexAttr ) { + + indexArr[ 0 ] = indexAttr.getX( i ); + indexArr[ 1 ] = indexAttr.getX( i + 1 ); + indexArr[ 2 ] = indexAttr.getX( i + 2 ); + + } else { + + indexArr[ 0 ] = i; + indexArr[ 1 ] = i + 1; + indexArr[ 2 ] = i + 2; + + } + + const { a, b, c } = _triangle; + a.fromBufferAttribute( positionAttr, indexArr[ 0 ] ); + b.fromBufferAttribute( positionAttr, indexArr[ 1 ] ); + c.fromBufferAttribute( positionAttr, indexArr[ 2 ] ); + _triangle.getNormal( _normal ); + + // create hashes for the edge from the vertices + hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`; + hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`; + hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`; + + // skip degenerate triangles + if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) { + + continue; + + } + + // iterate over every edge + for ( let j = 0; j < 3; j ++ ) { + + // get the first and next vertex making up the edge + const jNext = ( j + 1 ) % 3; + const vecHash0 = hashes[ j ]; + const vecHash1 = hashes[ jNext ]; + const v0 = _triangle[ vertKeys[ j ] ]; + const v1 = _triangle[ vertKeys[ jNext ] ]; + + const hash = `${ vecHash0 }_${ vecHash1 }`; + const reverseHash = `${ vecHash1 }_${ vecHash0 }`; + + if ( reverseHash in edgeData && edgeData[ reverseHash ] ) { + + // if we found a sibling edge add it into the vertex array if + // it meets the angle threshold and delete the edge from the map. + if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) { + + vertices.push( v0.x, v0.y, v0.z ); + vertices.push( v1.x, v1.y, v1.z ); + + } + + edgeData[ reverseHash ] = null; + + } else if ( ! ( hash in edgeData ) ) { + + // if we've already got an edge here then skip adding a new one + edgeData[ hash ] = { + + index0: indexArr[ j ], + index1: indexArr[ jNext ], + normal: _normal.clone(), + + }; + + } + + } + + } + + // iterate over all remaining, unmatched edges and add them to the vertex array + for ( const key in edgeData ) { + + if ( edgeData[ key ] ) { + + const { index0, index1 } = edgeData[ key ]; + _v0.fromBufferAttribute( positionAttr, index0 ); + _v1$1.fromBufferAttribute( positionAttr, index1 ); + + vertices.push( _v0.x, _v0.y, _v0.z ); + vertices.push( _v1$1.x, _v1$1.y, _v1$1.z ); + + } + + } + + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + +} + +class Shape extends Path { + + constructor( points ) { + + super( points ); + + this.uuid = generateUUID(); + + this.type = 'Shape'; + + this.holes = []; + + } + + getPointsHoles( divisions ) { + + const holesPts = []; + + for ( let i = 0, l = this.holes.length; i < l; i ++ ) { + + holesPts[ i ] = this.holes[ i ].getPoints( divisions ); + + } + + return holesPts; + + } + + // get points of shape and holes (keypoints based on segments parameter) + + extractPoints( divisions ) { + + return { + + shape: this.getPoints( divisions ), + holes: this.getPointsHoles( divisions ) + + }; + + } + + copy( source ) { + + super.copy( source ); + + this.holes = []; + + for ( let i = 0, l = source.holes.length; i < l; i ++ ) { + + const hole = source.holes[ i ]; + + this.holes.push( hole.clone() ); + + } + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.uuid = this.uuid; + data.holes = []; + + for ( let i = 0, l = this.holes.length; i < l; i ++ ) { + + const hole = this.holes[ i ]; + data.holes.push( hole.toJSON() ); + + } + + return data; + + } + + fromJSON( json ) { + + super.fromJSON( json ); + + this.uuid = json.uuid; + this.holes = []; + + for ( let i = 0, l = json.holes.length; i < l; i ++ ) { + + const hole = json.holes[ i ]; + this.holes.push( new Path().fromJSON( hole ) ); + + } + + return this; + + } + +} + +/** + * Port from https://github.com/mapbox/earcut (v2.2.4) + */ + +const Earcut = { + + triangulate: function ( data, holeIndices, dim = 2 ) { + + const hasHoles = holeIndices && holeIndices.length; + const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length; + let outerNode = linkedList( data, 0, outerLen, dim, true ); + const triangles = []; + + if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles; + + let minX, minY, maxX, maxY, x, y, invSize; + + if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim ); + + // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox + if ( data.length > 80 * dim ) { + + minX = maxX = data[ 0 ]; + minY = maxY = data[ 1 ]; + + for ( let i = dim; i < outerLen; i += dim ) { + + x = data[ i ]; + y = data[ i + 1 ]; + if ( x < minX ) minX = x; + if ( y < minY ) minY = y; + if ( x > maxX ) maxX = x; + if ( y > maxY ) maxY = y; + + } + + // minX, minY and invSize are later used to transform coords into integers for z-order calculation + invSize = Math.max( maxX - minX, maxY - minY ); + invSize = invSize !== 0 ? 32767 / invSize : 0; + + } + + earcutLinked( outerNode, triangles, dim, minX, minY, invSize, 0 ); + + return triangles; + + } + +}; + +// create a circular doubly linked list from polygon points in the specified winding order +function linkedList( data, start, end, dim, clockwise ) { + + let i, last; + + if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) { + + for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last ); + + } else { + + for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last ); + + } + + if ( last && equals( last, last.next ) ) { + + removeNode( last ); + last = last.next; + + } + + return last; + +} + +// eliminate colinear or duplicate points +function filterPoints( start, end ) { + + if ( ! start ) return start; + if ( ! end ) end = start; + + let p = start, + again; + do { + + again = false; + + if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) { + + removeNode( p ); + p = end = p.prev; + if ( p === p.next ) break; + again = true; + + } else { + + p = p.next; + + } + + } while ( again || p !== end ); + + return end; + +} + +// main ear slicing loop which triangulates a polygon (given as a linked list) +function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) { + + if ( ! ear ) return; + + // interlink polygon nodes in z-order + if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize ); + + let stop = ear, + prev, next; + + // iterate through ears, slicing them one by one + while ( ear.prev !== ear.next ) { + + prev = ear.prev; + next = ear.next; + + if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) { + + // cut off the triangle + triangles.push( prev.i / dim | 0 ); + triangles.push( ear.i / dim | 0 ); + triangles.push( next.i / dim | 0 ); + + removeNode( ear ); + + // skipping the next vertex leads to less sliver triangles + ear = next.next; + stop = next.next; + + continue; + + } + + ear = next; + + // if we looped through the whole remaining polygon and can't find any more ears + if ( ear === stop ) { + + // try filtering points and slicing again + if ( ! pass ) { + + earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 ); + + // if this didn't work, try curing all small self-intersections locally + + } else if ( pass === 1 ) { + + ear = cureLocalIntersections( filterPoints( ear ), triangles, dim ); + earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 ); + + // as a last resort, try splitting the remaining polygon into two + + } else if ( pass === 2 ) { + + splitEarcut( ear, triangles, dim, minX, minY, invSize ); + + } + + break; + + } + + } + +} + +// check whether a polygon node forms a valid ear with adjacent nodes +function isEar( ear ) { + + const a = ear.prev, + b = ear, + c = ear.next; + + if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear + + // now make sure we don't have other points inside the potential ear + const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y; + + // triangle bbox; min & max are calculated like this for speed + const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ), + y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ), + x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ), + y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy ); + + let p = c.next; + while ( p !== a ) { + + if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && + pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && + area( p.prev, p, p.next ) >= 0 ) return false; + p = p.next; + + } + + return true; + +} + +function isEarHashed( ear, minX, minY, invSize ) { + + const a = ear.prev, + b = ear, + c = ear.next; + + if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear + + const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y; + + // triangle bbox; min & max are calculated like this for speed + const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ), + y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ), + x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ), + y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy ); + + // z-order range for the current triangle bbox; + const minZ = zOrder( x0, y0, minX, minY, invSize ), + maxZ = zOrder( x1, y1, minX, minY, invSize ); + + let p = ear.prevZ, + n = ear.nextZ; + + // look for points inside the triangle in both directions + while ( p && p.z >= minZ && n && n.z <= maxZ ) { + + if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && + pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false; + p = p.prevZ; + + if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && + pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false; + n = n.nextZ; + + } + + // look for remaining points in decreasing z-order + while ( p && p.z >= minZ ) { + + if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && + pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false; + p = p.prevZ; + + } + + // look for remaining points in increasing z-order + while ( n && n.z <= maxZ ) { + + if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && + pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false; + n = n.nextZ; + + } + + return true; + +} + +// go through all polygon nodes and cure small local self-intersections +function cureLocalIntersections( start, triangles, dim ) { + + let p = start; + do { + + const a = p.prev, + b = p.next.next; + + if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) { + + triangles.push( a.i / dim | 0 ); + triangles.push( p.i / dim | 0 ); + triangles.push( b.i / dim | 0 ); + + // remove two nodes involved + removeNode( p ); + removeNode( p.next ); + + p = start = b; + + } + + p = p.next; + + } while ( p !== start ); + + return filterPoints( p ); + +} + +// try splitting polygon into two and triangulate them independently +function splitEarcut( start, triangles, dim, minX, minY, invSize ) { + + // look for a valid diagonal that divides the polygon into two + let a = start; + do { + + let b = a.next.next; + while ( b !== a.prev ) { + + if ( a.i !== b.i && isValidDiagonal( a, b ) ) { + + // split the polygon in two by the diagonal + let c = splitPolygon( a, b ); + + // filter colinear points around the cuts + a = filterPoints( a, a.next ); + c = filterPoints( c, c.next ); + + // run earcut on each half + earcutLinked( a, triangles, dim, minX, minY, invSize, 0 ); + earcutLinked( c, triangles, dim, minX, minY, invSize, 0 ); + return; + + } + + b = b.next; + + } + + a = a.next; + + } while ( a !== start ); + +} + +// link every hole into the outer loop, producing a single-ring polygon without holes +function eliminateHoles( data, holeIndices, outerNode, dim ) { + + const queue = []; + let i, len, start, end, list; + + for ( i = 0, len = holeIndices.length; i < len; i ++ ) { + + start = holeIndices[ i ] * dim; + end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length; + list = linkedList( data, start, end, dim, false ); + if ( list === list.next ) list.steiner = true; + queue.push( getLeftmost( list ) ); + + } + + queue.sort( compareX ); + + // process holes from left to right + for ( i = 0; i < queue.length; i ++ ) { + + outerNode = eliminateHole( queue[ i ], outerNode ); + + } + + return outerNode; + +} + +function compareX( a, b ) { + + return a.x - b.x; + +} + +// find a bridge between vertices that connects hole with an outer ring and link it +function eliminateHole( hole, outerNode ) { + + const bridge = findHoleBridge( hole, outerNode ); + if ( ! bridge ) { + + return outerNode; + + } + + const bridgeReverse = splitPolygon( bridge, hole ); + + // filter collinear points around the cuts + filterPoints( bridgeReverse, bridgeReverse.next ); + return filterPoints( bridge, bridge.next ); + +} + +// David Eberly's algorithm for finding a bridge between hole and outer polygon +function findHoleBridge( hole, outerNode ) { + + let p = outerNode, + qx = - Infinity, + m; + + const hx = hole.x, hy = hole.y; + + // find a segment intersected by a ray from the hole's leftmost point to the left; + // segment's endpoint with lesser x will be potential connection point + do { + + if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) { + + const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y ); + if ( x <= hx && x > qx ) { + + qx = x; + m = p.x < p.next.x ? p : p.next; + if ( x === hx ) return m; // hole touches outer segment; pick leftmost endpoint + + } + + } + + p = p.next; + + } while ( p !== outerNode ); + + if ( ! m ) return null; + + // look for points inside the triangle of hole point, segment intersection and endpoint; + // if there are no points found, we have a valid connection; + // otherwise choose the point of the minimum angle with the ray as connection point + + const stop = m, + mx = m.x, + my = m.y; + let tanMin = Infinity, tan; + + p = m; + + do { + + if ( hx >= p.x && p.x >= mx && hx !== p.x && + pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) { + + tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential + + if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) { + + m = p; + tanMin = tan; + + } + + } + + p = p.next; + + } while ( p !== stop ); + + return m; + +} + +// whether sector in vertex m contains sector in vertex p in the same coordinates +function sectorContainsSector( m, p ) { + + return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0; + +} + +// interlink polygon nodes in z-order +function indexCurve( start, minX, minY, invSize ) { + + let p = start; + do { + + if ( p.z === 0 ) p.z = zOrder( p.x, p.y, minX, minY, invSize ); + p.prevZ = p.prev; + p.nextZ = p.next; + p = p.next; + + } while ( p !== start ); + + p.prevZ.nextZ = null; + p.prevZ = null; + + sortLinked( p ); + +} + +// Simon Tatham's linked list merge sort algorithm +// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html +function sortLinked( list ) { + + let i, p, q, e, tail, numMerges, pSize, qSize, + inSize = 1; + + do { + + p = list; + list = null; + tail = null; + numMerges = 0; + + while ( p ) { + + numMerges ++; + q = p; + pSize = 0; + for ( i = 0; i < inSize; i ++ ) { + + pSize ++; + q = q.nextZ; + if ( ! q ) break; + + } + + qSize = inSize; + + while ( pSize > 0 || ( qSize > 0 && q ) ) { + + if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) { + + e = p; + p = p.nextZ; + pSize --; + + } else { + + e = q; + q = q.nextZ; + qSize --; + + } + + if ( tail ) tail.nextZ = e; + else list = e; + + e.prevZ = tail; + tail = e; + + } + + p = q; + + } + + tail.nextZ = null; + inSize *= 2; + + } while ( numMerges > 1 ); + + return list; + +} + +// z-order of a point given coords and inverse of the longer side of data bbox +function zOrder( x, y, minX, minY, invSize ) { + + // coords are transformed into non-negative 15-bit integer range + x = ( x - minX ) * invSize | 0; + y = ( y - minY ) * invSize | 0; + + x = ( x | ( x << 8 ) ) & 0x00FF00FF; + x = ( x | ( x << 4 ) ) & 0x0F0F0F0F; + x = ( x | ( x << 2 ) ) & 0x33333333; + x = ( x | ( x << 1 ) ) & 0x55555555; + + y = ( y | ( y << 8 ) ) & 0x00FF00FF; + y = ( y | ( y << 4 ) ) & 0x0F0F0F0F; + y = ( y | ( y << 2 ) ) & 0x33333333; + y = ( y | ( y << 1 ) ) & 0x55555555; + + return x | ( y << 1 ); + +} + +// find the leftmost node of a polygon ring +function getLeftmost( start ) { + + let p = start, + leftmost = start; + do { + + if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p; + p = p.next; + + } while ( p !== start ); + + return leftmost; + +} + +// check if a point lies within a convex triangle +function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) { + + return ( cx - px ) * ( ay - py ) >= ( ax - px ) * ( cy - py ) && + ( ax - px ) * ( by - py ) >= ( bx - px ) * ( ay - py ) && + ( bx - px ) * ( cy - py ) >= ( cx - px ) * ( by - py ); + +} + +// check if a diagonal between two polygon nodes is valid (lies in polygon interior) +function isValidDiagonal( a, b ) { + + return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges + ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible + ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors + equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case + +} + +// signed area of a triangle +function area( p, q, r ) { + + return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y ); + +} + +// check if two points are equal +function equals( p1, p2 ) { + + return p1.x === p2.x && p1.y === p2.y; + +} + +// check if two segments intersect +function intersects( p1, q1, p2, q2 ) { + + const o1 = sign( area( p1, q1, p2 ) ); + const o2 = sign( area( p1, q1, q2 ) ); + const o3 = sign( area( p2, q2, p1 ) ); + const o4 = sign( area( p2, q2, q1 ) ); + + if ( o1 !== o2 && o3 !== o4 ) return true; // general case + + if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1 + if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1 + if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2 + if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2 + + return false; + +} + +// for collinear points p, q, r, check if point q lies on segment pr +function onSegment( p, q, r ) { + + return q.x <= Math.max( p.x, r.x ) && q.x >= Math.min( p.x, r.x ) && q.y <= Math.max( p.y, r.y ) && q.y >= Math.min( p.y, r.y ); + +} + +function sign( num ) { + + return num > 0 ? 1 : num < 0 ? - 1 : 0; + +} + +// check if a polygon diagonal intersects any polygon segments +function intersectsPolygon( a, b ) { + + let p = a; + do { + + if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && + intersects( p, p.next, a, b ) ) return true; + p = p.next; + + } while ( p !== a ); + + return false; + +} + +// check if a polygon diagonal is locally inside the polygon +function locallyInside( a, b ) { + + return area( a.prev, a, a.next ) < 0 ? + area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 : + area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0; + +} + +// check if the middle point of a polygon diagonal is inside the polygon +function middleInside( a, b ) { + + let p = a, + inside = false; + const px = ( a.x + b.x ) / 2, + py = ( a.y + b.y ) / 2; + do { + + if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y && + ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) + inside = ! inside; + p = p.next; + + } while ( p !== a ); + + return inside; + +} + +// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; +// if one belongs to the outer ring and another to a hole, it merges it into a single ring +function splitPolygon( a, b ) { + + const a2 = new Node( a.i, a.x, a.y ), + b2 = new Node( b.i, b.x, b.y ), + an = a.next, + bp = b.prev; + + a.next = b; + b.prev = a; + + a2.next = an; + an.prev = a2; + + b2.next = a2; + a2.prev = b2; + + bp.next = b2; + b2.prev = bp; + + return b2; + +} + +// create a node and optionally link it with previous one (in a circular doubly linked list) +function insertNode( i, x, y, last ) { + + const p = new Node( i, x, y ); + + if ( ! last ) { + + p.prev = p; + p.next = p; + + } else { + + p.next = last.next; + p.prev = last; + last.next.prev = p; + last.next = p; + + } + + return p; + +} + +function removeNode( p ) { + + p.next.prev = p.prev; + p.prev.next = p.next; + + if ( p.prevZ ) p.prevZ.nextZ = p.nextZ; + if ( p.nextZ ) p.nextZ.prevZ = p.prevZ; + +} + +function Node( i, x, y ) { + + // vertex index in coordinates array + this.i = i; + + // vertex coordinates + this.x = x; + this.y = y; + + // previous and next vertex nodes in a polygon ring + this.prev = null; + this.next = null; + + // z-order curve value + this.z = 0; + + // previous and next nodes in z-order + this.prevZ = null; + this.nextZ = null; + + // indicates whether this is a steiner point + this.steiner = false; + +} + +function signedArea( data, start, end, dim ) { + + let sum = 0; + for ( let i = start, j = end - dim; i < end; i += dim ) { + + sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] ); + j = i; + + } + + return sum; + +} + +class ShapeUtils { + + // calculate area of the contour polygon + + static area( contour ) { + + const n = contour.length; + let a = 0.0; + + for ( let p = n - 1, q = 0; q < n; p = q ++ ) { + + a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y; + + } + + return a * 0.5; + + } + + static isClockWise( pts ) { + + return ShapeUtils.area( pts ) < 0; + + } + + static triangulateShape( contour, holes ) { + + const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ] + const holeIndices = []; // array of hole indices + const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ] + + removeDupEndPts( contour ); + addContour( vertices, contour ); + + // + + let holeIndex = contour.length; + + holes.forEach( removeDupEndPts ); + + for ( let i = 0; i < holes.length; i ++ ) { + + holeIndices.push( holeIndex ); + holeIndex += holes[ i ].length; + addContour( vertices, holes[ i ] ); + + } + + // + + const triangles = Earcut.triangulate( vertices, holeIndices ); + + // + + for ( let i = 0; i < triangles.length; i += 3 ) { + + faces.push( triangles.slice( i, i + 3 ) ); + + } + + return faces; + + } + +} + +function removeDupEndPts( points ) { + + const l = points.length; + + if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) { + + points.pop(); + + } + +} + +function addContour( vertices, contour ) { + + for ( let i = 0; i < contour.length; i ++ ) { + + vertices.push( contour[ i ].x ); + vertices.push( contour[ i ].y ); + + } + +} + +/** + * Creates extruded geometry from a path shape. + * + * parameters = { + * + * curveSegments: , // number of points on the curves + * steps: , // number of points for z-side extrusions / used for subdividing segments of extrude spline too + * depth: , // Depth to extrude the shape + * + * bevelEnabled: , // turn on bevel + * bevelThickness: , // how deep into the original shape bevel goes + * bevelSize: , // how far from shape outline (including bevelOffset) is bevel + * bevelOffset: , // how far from shape outline does bevel start + * bevelSegments: , // number of bevel layers + * + * extrudePath: // curve to extrude shape along + * + * UVGenerator: // object that provides UV generator functions + * + * } + */ + + +class ExtrudeGeometry extends BufferGeometry { + + constructor( shapes = new Shape( [ new Vector2( 0.5, 0.5 ), new Vector2( - 0.5, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), options = {} ) { + + super(); + + this.type = 'ExtrudeGeometry'; + + this.parameters = { + shapes: shapes, + options: options + }; + + shapes = Array.isArray( shapes ) ? shapes : [ shapes ]; + + const scope = this; + + const verticesArray = []; + const uvArray = []; + + for ( let i = 0, l = shapes.length; i < l; i ++ ) { + + const shape = shapes[ i ]; + addShape( shape ); + + } + + // build geometry + + this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) ); + + this.computeVertexNormals(); + + // functions + + function addShape( shape ) { + + const placeholder = []; + + // options + + const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12; + const steps = options.steps !== undefined ? options.steps : 1; + const depth = options.depth !== undefined ? options.depth : 1; + + let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; + let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2; + let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1; + let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0; + let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3; + + const extrudePath = options.extrudePath; + + const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; + + // + + let extrudePts, extrudeByPath = false; + let splineTube, binormal, normal, position2; + + if ( extrudePath ) { + + extrudePts = extrudePath.getSpacedPoints( steps ); + + extrudeByPath = true; + bevelEnabled = false; // bevels not supported for path extrusion + + // SETUP TNB variables + + // TODO1 - have a .isClosed in spline? + + splineTube = extrudePath.computeFrenetFrames( steps, false ); + + // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length); + + binormal = new Vector3(); + normal = new Vector3(); + position2 = new Vector3(); + + } + + // Safeguards if bevels are not enabled + + if ( ! bevelEnabled ) { + + bevelSegments = 0; + bevelThickness = 0; + bevelSize = 0; + bevelOffset = 0; + + } + + // Variables initialization + + const shapePoints = shape.extractPoints( curveSegments ); + + let vertices = shapePoints.shape; + const holes = shapePoints.holes; + + const reverse = ! ShapeUtils.isClockWise( vertices ); + + if ( reverse ) { + + vertices = vertices.reverse(); + + // Maybe we should also check if holes are in the opposite direction, just to be safe ... + + for ( let h = 0, hl = holes.length; h < hl; h ++ ) { + + const ahole = holes[ h ]; + + if ( ShapeUtils.isClockWise( ahole ) ) { + + holes[ h ] = ahole.reverse(); + + } + + } + + } + + + const faces = ShapeUtils.triangulateShape( vertices, holes ); + + /* Vertices */ + + const contour = vertices; // vertices has all points but contour has only points of circumference + + for ( let h = 0, hl = holes.length; h < hl; h ++ ) { + + const ahole = holes[ h ]; + + vertices = vertices.concat( ahole ); + + } + + + function scalePt2( pt, vec, size ) { + + if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' ); + + return pt.clone().addScaledVector( vec, size ); + + } + + const vlen = vertices.length, flen = faces.length; + + + // Find directions for point movement + + + function getBevelVec( inPt, inPrev, inNext ) { + + // computes for inPt the corresponding point inPt' on a new contour + // shifted by 1 unit (length of normalized vector) to the left + // if we walk along contour clockwise, this new contour is outside the old one + // + // inPt' is the intersection of the two lines parallel to the two + // adjacent edges of inPt at a distance of 1 unit on the left side. + + let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt + + // good reading for geometry algorithms (here: line-line intersection) + // http://geomalgorithms.com/a05-_intersect-1.html + + const v_prev_x = inPt.x - inPrev.x, + v_prev_y = inPt.y - inPrev.y; + const v_next_x = inNext.x - inPt.x, + v_next_y = inNext.y - inPt.y; + + const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y ); + + // check for collinear edges + const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x ); + + if ( Math.abs( collinear0 ) > Number.EPSILON ) { + + // not collinear + + // length of vectors for normalizing + + const v_prev_len = Math.sqrt( v_prev_lensq ); + const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y ); + + // shift adjacent points by unit vectors to the left + + const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len ); + const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len ); + + const ptNextShift_x = ( inNext.x - v_next_y / v_next_len ); + const ptNextShift_y = ( inNext.y + v_next_x / v_next_len ); + + // scaling factor for v_prev to intersection point + + const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y - + ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) / + ( v_prev_x * v_next_y - v_prev_y * v_next_x ); + + // vector from inPt to intersection point + + v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x ); + v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y ); + + // Don't normalize!, otherwise sharp corners become ugly + // but prevent crazy spikes + const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y ); + if ( v_trans_lensq <= 2 ) { + + return new Vector2( v_trans_x, v_trans_y ); + + } else { + + shrink_by = Math.sqrt( v_trans_lensq / 2 ); + + } + + } else { + + // handle special case of collinear edges + + let direction_eq = false; // assumes: opposite + + if ( v_prev_x > Number.EPSILON ) { + + if ( v_next_x > Number.EPSILON ) { + + direction_eq = true; + + } + + } else { + + if ( v_prev_x < - Number.EPSILON ) { + + if ( v_next_x < - Number.EPSILON ) { + + direction_eq = true; + + } + + } else { + + if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) { + + direction_eq = true; + + } + + } + + } + + if ( direction_eq ) { + + // console.log("Warning: lines are a straight sequence"); + v_trans_x = - v_prev_y; + v_trans_y = v_prev_x; + shrink_by = Math.sqrt( v_prev_lensq ); + + } else { + + // console.log("Warning: lines are a straight spike"); + v_trans_x = v_prev_x; + v_trans_y = v_prev_y; + shrink_by = Math.sqrt( v_prev_lensq / 2 ); + + } + + } + + return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by ); + + } + + + const contourMovements = []; + + for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) { + + if ( j === il ) j = 0; + if ( k === il ) k = 0; + + // (j)---(i)---(k) + // console.log('i,j,k', i, j , k) + + contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] ); + + } + + const holesMovements = []; + let oneHoleMovements, verticesMovements = contourMovements.concat(); + + for ( let h = 0, hl = holes.length; h < hl; h ++ ) { + + const ahole = holes[ h ]; + + oneHoleMovements = []; + + for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) { + + if ( j === il ) j = 0; + if ( k === il ) k = 0; + + // (j)---(i)---(k) + oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] ); + + } + + holesMovements.push( oneHoleMovements ); + verticesMovements = verticesMovements.concat( oneHoleMovements ); + + } + + + // Loop bevelSegments, 1 for the front, 1 for the back + + for ( let b = 0; b < bevelSegments; b ++ ) { + + //for ( b = bevelSegments; b > 0; b -- ) { + + const t = b / bevelSegments; + const z = bevelThickness * Math.cos( t * Math.PI / 2 ); + const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset; + + // contract shape + + for ( let i = 0, il = contour.length; i < il; i ++ ) { + + const vert = scalePt2( contour[ i ], contourMovements[ i ], bs ); + + v( vert.x, vert.y, - z ); + + } + + // expand holes + + for ( let h = 0, hl = holes.length; h < hl; h ++ ) { + + const ahole = holes[ h ]; + oneHoleMovements = holesMovements[ h ]; + + for ( let i = 0, il = ahole.length; i < il; i ++ ) { + + const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs ); + + v( vert.x, vert.y, - z ); + + } + + } + + } + + const bs = bevelSize + bevelOffset; + + // Back facing vertices + + for ( let i = 0; i < vlen; i ++ ) { + + const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ]; + + if ( ! extrudeByPath ) { + + v( vert.x, vert.y, 0 ); + + } else { + + // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x ); + + normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x ); + binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y ); + + position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal ); + + v( position2.x, position2.y, position2.z ); + + } + + } + + // Add stepped vertices... + // Including front facing vertices + + for ( let s = 1; s <= steps; s ++ ) { + + for ( let i = 0; i < vlen; i ++ ) { + + const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ]; + + if ( ! extrudeByPath ) { + + v( vert.x, vert.y, depth / steps * s ); + + } else { + + // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x ); + + normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x ); + binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y ); + + position2.copy( extrudePts[ s ] ).add( normal ).add( binormal ); + + v( position2.x, position2.y, position2.z ); + + } + + } + + } + + + // Add bevel segments planes + + //for ( b = 1; b <= bevelSegments; b ++ ) { + for ( let b = bevelSegments - 1; b >= 0; b -- ) { + + const t = b / bevelSegments; + const z = bevelThickness * Math.cos( t * Math.PI / 2 ); + const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset; + + // contract shape + + for ( let i = 0, il = contour.length; i < il; i ++ ) { + + const vert = scalePt2( contour[ i ], contourMovements[ i ], bs ); + v( vert.x, vert.y, depth + z ); + + } + + // expand holes + + for ( let h = 0, hl = holes.length; h < hl; h ++ ) { + + const ahole = holes[ h ]; + oneHoleMovements = holesMovements[ h ]; + + for ( let i = 0, il = ahole.length; i < il; i ++ ) { + + const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs ); + + if ( ! extrudeByPath ) { + + v( vert.x, vert.y, depth + z ); + + } else { + + v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z ); + + } + + } + + } + + } + + /* Faces */ + + // Top and bottom faces + + buildLidFaces(); + + // Sides faces + + buildSideFaces(); + + + ///// Internal functions + + function buildLidFaces() { + + const start = verticesArray.length / 3; + + if ( bevelEnabled ) { + + let layer = 0; // steps + 1 + let offset = vlen * layer; + + // Bottom faces + + for ( let i = 0; i < flen; i ++ ) { + + const face = faces[ i ]; + f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset ); + + } + + layer = steps + bevelSegments * 2; + offset = vlen * layer; + + // Top faces + + for ( let i = 0; i < flen; i ++ ) { + + const face = faces[ i ]; + f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset ); + + } + + } else { + + // Bottom faces + + for ( let i = 0; i < flen; i ++ ) { + + const face = faces[ i ]; + f3( face[ 2 ], face[ 1 ], face[ 0 ] ); + + } + + // Top faces + + for ( let i = 0; i < flen; i ++ ) { + + const face = faces[ i ]; + f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps ); + + } + + } + + scope.addGroup( start, verticesArray.length / 3 - start, 0 ); + + } + + // Create faces for the z-sides of the shape + + function buildSideFaces() { + + const start = verticesArray.length / 3; + let layeroffset = 0; + sidewalls( contour, layeroffset ); + layeroffset += contour.length; + + for ( let h = 0, hl = holes.length; h < hl; h ++ ) { + + const ahole = holes[ h ]; + sidewalls( ahole, layeroffset ); + + //, true + layeroffset += ahole.length; + + } + + + scope.addGroup( start, verticesArray.length / 3 - start, 1 ); + + + } + + function sidewalls( contour, layeroffset ) { + + let i = contour.length; + + while ( -- i >= 0 ) { + + const j = i; + let k = i - 1; + if ( k < 0 ) k = contour.length - 1; + + //console.log('b', i,j, i-1, k,vertices.length); + + for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) { + + const slen1 = vlen * s; + const slen2 = vlen * ( s + 1 ); + + const a = layeroffset + j + slen1, + b = layeroffset + k + slen1, + c = layeroffset + k + slen2, + d = layeroffset + j + slen2; + + f4( a, b, c, d ); + + } + + } + + } + + function v( x, y, z ) { + + placeholder.push( x ); + placeholder.push( y ); + placeholder.push( z ); + + } + + + function f3( a, b, c ) { + + addVertex( a ); + addVertex( b ); + addVertex( c ); + + const nextIndex = verticesArray.length / 3; + const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 ); + + addUV( uvs[ 0 ] ); + addUV( uvs[ 1 ] ); + addUV( uvs[ 2 ] ); + + } + + function f4( a, b, c, d ) { + + addVertex( a ); + addVertex( b ); + addVertex( d ); + + addVertex( b ); + addVertex( c ); + addVertex( d ); + + + const nextIndex = verticesArray.length / 3; + const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 ); + + addUV( uvs[ 0 ] ); + addUV( uvs[ 1 ] ); + addUV( uvs[ 3 ] ); + + addUV( uvs[ 1 ] ); + addUV( uvs[ 2 ] ); + addUV( uvs[ 3 ] ); + + } + + function addVertex( index ) { + + verticesArray.push( placeholder[ index * 3 + 0 ] ); + verticesArray.push( placeholder[ index * 3 + 1 ] ); + verticesArray.push( placeholder[ index * 3 + 2 ] ); + + } + + + function addUV( vector2 ) { + + uvArray.push( vector2.x ); + uvArray.push( vector2.y ); + + } + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + const shapes = this.parameters.shapes; + const options = this.parameters.options; + + return toJSON$1( shapes, options, data ); + + } + + static fromJSON( data, shapes ) { + + const geometryShapes = []; + + for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) { + + const shape = shapes[ data.shapes[ j ] ]; + + geometryShapes.push( shape ); + + } + + const extrudePath = data.options.extrudePath; + + if ( extrudePath !== undefined ) { + + data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath ); + + } + + return new ExtrudeGeometry( geometryShapes, data.options ); + + } + +} + +const WorldUVGenerator = { + + generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) { + + const a_x = vertices[ indexA * 3 ]; + const a_y = vertices[ indexA * 3 + 1 ]; + const b_x = vertices[ indexB * 3 ]; + const b_y = vertices[ indexB * 3 + 1 ]; + const c_x = vertices[ indexC * 3 ]; + const c_y = vertices[ indexC * 3 + 1 ]; + + return [ + new Vector2( a_x, a_y ), + new Vector2( b_x, b_y ), + new Vector2( c_x, c_y ) + ]; + + }, + + generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) { + + const a_x = vertices[ indexA * 3 ]; + const a_y = vertices[ indexA * 3 + 1 ]; + const a_z = vertices[ indexA * 3 + 2 ]; + const b_x = vertices[ indexB * 3 ]; + const b_y = vertices[ indexB * 3 + 1 ]; + const b_z = vertices[ indexB * 3 + 2 ]; + const c_x = vertices[ indexC * 3 ]; + const c_y = vertices[ indexC * 3 + 1 ]; + const c_z = vertices[ indexC * 3 + 2 ]; + const d_x = vertices[ indexD * 3 ]; + const d_y = vertices[ indexD * 3 + 1 ]; + const d_z = vertices[ indexD * 3 + 2 ]; + + if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) { + + return [ + new Vector2( a_x, 1 - a_z ), + new Vector2( b_x, 1 - b_z ), + new Vector2( c_x, 1 - c_z ), + new Vector2( d_x, 1 - d_z ) + ]; + + } else { + + return [ + new Vector2( a_y, 1 - a_z ), + new Vector2( b_y, 1 - b_z ), + new Vector2( c_y, 1 - c_z ), + new Vector2( d_y, 1 - d_z ) + ]; + + } + + } + +}; + +function toJSON$1( shapes, options, data ) { + + data.shapes = []; + + if ( Array.isArray( shapes ) ) { + + for ( let i = 0, l = shapes.length; i < l; i ++ ) { + + const shape = shapes[ i ]; + + data.shapes.push( shape.uuid ); + + } + + } else { + + data.shapes.push( shapes.uuid ); + + } + + data.options = Object.assign( {}, options ); + + if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON(); + + return data; + +} + +class IcosahedronGeometry extends PolyhedronGeometry { + + constructor( radius = 1, detail = 0 ) { + + const t = ( 1 + Math.sqrt( 5 ) ) / 2; + + const vertices = [ + - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0, + 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, + t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1 + ]; + + const indices = [ + 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, + 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, + 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, + 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1 + ]; + + super( vertices, indices, radius, detail ); + + this.type = 'IcosahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + static fromJSON( data ) { + + return new IcosahedronGeometry( data.radius, data.detail ); + + } + +} + +class OctahedronGeometry extends PolyhedronGeometry { + + constructor( radius = 1, detail = 0 ) { + + const vertices = [ + 1, 0, 0, - 1, 0, 0, 0, 1, 0, + 0, - 1, 0, 0, 0, 1, 0, 0, - 1 + ]; + + const indices = [ + 0, 2, 4, 0, 4, 3, 0, 3, 5, + 0, 5, 2, 1, 2, 5, 1, 5, 3, + 1, 3, 4, 1, 4, 2 + ]; + + super( vertices, indices, radius, detail ); + + this.type = 'OctahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + static fromJSON( data ) { + + return new OctahedronGeometry( data.radius, data.detail ); + + } + +} + +class PlaneGeometry extends BufferGeometry { + + constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) { + + super(); + + this.type = 'PlaneGeometry'; + + this.parameters = { + width: width, + height: height, + widthSegments: widthSegments, + heightSegments: heightSegments + }; + + const width_half = width / 2; + const height_half = height / 2; + + const gridX = Math.floor( widthSegments ); + const gridY = Math.floor( heightSegments ); + + const gridX1 = gridX + 1; + const gridY1 = gridY + 1; + + const segment_width = width / gridX; + const segment_height = height / gridY; + + // + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + for ( let iy = 0; iy < gridY1; iy ++ ) { + + const y = iy * segment_height - height_half; + + for ( let ix = 0; ix < gridX1; ix ++ ) { + + const x = ix * segment_width - width_half; + + vertices.push( x, - y, 0 ); + + normals.push( 0, 0, 1 ); + + uvs.push( ix / gridX ); + uvs.push( 1 - ( iy / gridY ) ); + + } + + } + + for ( let iy = 0; iy < gridY; iy ++ ) { + + for ( let ix = 0; ix < gridX; ix ++ ) { + + const a = ix + gridX1 * iy; + const b = ix + gridX1 * ( iy + 1 ); + const c = ( ix + 1 ) + gridX1 * ( iy + 1 ); + const d = ( ix + 1 ) + gridX1 * iy; + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments ); + + } + +} + +class RingGeometry extends BufferGeometry { + + constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) { + + super(); + + this.type = 'RingGeometry'; + + this.parameters = { + innerRadius: innerRadius, + outerRadius: outerRadius, + thetaSegments: thetaSegments, + phiSegments: phiSegments, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + thetaSegments = Math.max( 3, thetaSegments ); + phiSegments = Math.max( 1, phiSegments ); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // some helper variables + + let radius = innerRadius; + const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments ); + const vertex = new Vector3(); + const uv = new Vector2(); + + // generate vertices, normals and uvs + + for ( let j = 0; j <= phiSegments; j ++ ) { + + for ( let i = 0; i <= thetaSegments; i ++ ) { + + // values are generate from the inside of the ring to the outside + + const segment = thetaStart + i / thetaSegments * thetaLength; + + // vertex + + vertex.x = radius * Math.cos( segment ); + vertex.y = radius * Math.sin( segment ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normals.push( 0, 0, 1 ); + + // uv + + uv.x = ( vertex.x / outerRadius + 1 ) / 2; + uv.y = ( vertex.y / outerRadius + 1 ) / 2; + + uvs.push( uv.x, uv.y ); + + } + + // increase the radius for next row of vertices + + radius += radiusStep; + + } + + // indices + + for ( let j = 0; j < phiSegments; j ++ ) { + + const thetaSegmentLevel = j * ( thetaSegments + 1 ); + + for ( let i = 0; i < thetaSegments; i ++ ) { + + const segment = i + thetaSegmentLevel; + + const a = segment; + const b = segment + thetaSegments + 1; + const c = segment + thetaSegments + 2; + const d = segment + 1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength ); + + } + +} + +class ShapeGeometry extends BufferGeometry { + + constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) { + + super(); + + this.type = 'ShapeGeometry'; + + this.parameters = { + shapes: shapes, + curveSegments: curveSegments + }; + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // helper variables + + let groupStart = 0; + let groupCount = 0; + + // allow single and array values for "shapes" parameter + + if ( Array.isArray( shapes ) === false ) { + + addShape( shapes ); + + } else { + + for ( let i = 0; i < shapes.length; i ++ ) { + + addShape( shapes[ i ] ); + + this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support + + groupStart += groupCount; + groupCount = 0; + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + + // helper functions + + function addShape( shape ) { + + const indexOffset = vertices.length / 3; + const points = shape.extractPoints( curveSegments ); + + let shapeVertices = points.shape; + const shapeHoles = points.holes; + + // check direction of vertices + + if ( ShapeUtils.isClockWise( shapeVertices ) === false ) { + + shapeVertices = shapeVertices.reverse(); + + } + + for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) { + + const shapeHole = shapeHoles[ i ]; + + if ( ShapeUtils.isClockWise( shapeHole ) === true ) { + + shapeHoles[ i ] = shapeHole.reverse(); + + } + + } + + const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles ); + + // join vertices of inner and outer paths to a single array + + for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) { + + const shapeHole = shapeHoles[ i ]; + shapeVertices = shapeVertices.concat( shapeHole ); + + } + + // vertices, normals, uvs + + for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) { + + const vertex = shapeVertices[ i ]; + + vertices.push( vertex.x, vertex.y, 0 ); + normals.push( 0, 0, 1 ); + uvs.push( vertex.x, vertex.y ); // world uvs + + } + + // indices + + for ( let i = 0, l = faces.length; i < l; i ++ ) { + + const face = faces[ i ]; + + const a = face[ 0 ] + indexOffset; + const b = face[ 1 ] + indexOffset; + const c = face[ 2 ] + indexOffset; + + indices.push( a, b, c ); + groupCount += 3; + + } + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + const shapes = this.parameters.shapes; + + return toJSON( shapes, data ); + + } + + static fromJSON( data, shapes ) { + + const geometryShapes = []; + + for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) { + + const shape = shapes[ data.shapes[ j ] ]; + + geometryShapes.push( shape ); + + } + + return new ShapeGeometry( geometryShapes, data.curveSegments ); + + } + +} + +function toJSON( shapes, data ) { + + data.shapes = []; + + if ( Array.isArray( shapes ) ) { + + for ( let i = 0, l = shapes.length; i < l; i ++ ) { + + const shape = shapes[ i ]; + + data.shapes.push( shape.uuid ); + + } + + } else { + + data.shapes.push( shapes.uuid ); + + } + + return data; + +} + +class SphereGeometry extends BufferGeometry { + + constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) { + + super(); + + this.type = 'SphereGeometry'; + + this.parameters = { + radius: radius, + widthSegments: widthSegments, + heightSegments: heightSegments, + phiStart: phiStart, + phiLength: phiLength, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + widthSegments = Math.max( 3, Math.floor( widthSegments ) ); + heightSegments = Math.max( 2, Math.floor( heightSegments ) ); + + const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI ); + + let index = 0; + const grid = []; + + const vertex = new Vector3(); + const normal = new Vector3(); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // generate vertices, normals and uvs + + for ( let iy = 0; iy <= heightSegments; iy ++ ) { + + const verticesRow = []; + + const v = iy / heightSegments; + + // special case for the poles + + let uOffset = 0; + + if ( iy === 0 && thetaStart === 0 ) { + + uOffset = 0.5 / widthSegments; + + } else if ( iy === heightSegments && thetaEnd === Math.PI ) { + + uOffset = - 0.5 / widthSegments; + + } + + for ( let ix = 0; ix <= widthSegments; ix ++ ) { + + const u = ix / widthSegments; + + // vertex + + vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength ); + vertex.y = radius * Math.cos( thetaStart + v * thetaLength ); + vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normal.copy( vertex ).normalize(); + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( u + uOffset, 1 - v ); + + verticesRow.push( index ++ ); + + } + + grid.push( verticesRow ); + + } + + // indices + + for ( let iy = 0; iy < heightSegments; iy ++ ) { + + for ( let ix = 0; ix < widthSegments; ix ++ ) { + + const a = grid[ iy ][ ix + 1 ]; + const b = grid[ iy ][ ix ]; + const c = grid[ iy + 1 ][ ix ]; + const d = grid[ iy + 1 ][ ix + 1 ]; + + if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d ); + if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength ); + + } + +} + +class TetrahedronGeometry extends PolyhedronGeometry { + + constructor( radius = 1, detail = 0 ) { + + const vertices = [ + 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1 + ]; + + const indices = [ + 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1 + ]; + + super( vertices, indices, radius, detail ); + + this.type = 'TetrahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + static fromJSON( data ) { + + return new TetrahedronGeometry( data.radius, data.detail ); + + } + +} + +class TorusGeometry extends BufferGeometry { + + constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) { + + super(); + + this.type = 'TorusGeometry'; + + this.parameters = { + radius: radius, + tube: tube, + radialSegments: radialSegments, + tubularSegments: tubularSegments, + arc: arc + }; + + radialSegments = Math.floor( radialSegments ); + tubularSegments = Math.floor( tubularSegments ); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // helper variables + + const center = new Vector3(); + const vertex = new Vector3(); + const normal = new Vector3(); + + // generate vertices, normals and uvs + + for ( let j = 0; j <= radialSegments; j ++ ) { + + for ( let i = 0; i <= tubularSegments; i ++ ) { + + const u = i / tubularSegments * arc; + const v = j / radialSegments * Math.PI * 2; + + // vertex + + vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u ); + vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u ); + vertex.z = tube * Math.sin( v ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + center.x = radius * Math.cos( u ); + center.y = radius * Math.sin( u ); + normal.subVectors( vertex, center ).normalize(); + + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( i / tubularSegments ); + uvs.push( j / radialSegments ); + + } + + } + + // generate indices + + for ( let j = 1; j <= radialSegments; j ++ ) { + + for ( let i = 1; i <= tubularSegments; i ++ ) { + + // indices + + const a = ( tubularSegments + 1 ) * j + i - 1; + const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1; + const c = ( tubularSegments + 1 ) * ( j - 1 ) + i; + const d = ( tubularSegments + 1 ) * j + i; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc ); + + } + +} + +class TorusKnotGeometry extends BufferGeometry { + + constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) { + + super(); + + this.type = 'TorusKnotGeometry'; + + this.parameters = { + radius: radius, + tube: tube, + tubularSegments: tubularSegments, + radialSegments: radialSegments, + p: p, + q: q + }; + + tubularSegments = Math.floor( tubularSegments ); + radialSegments = Math.floor( radialSegments ); + + // buffers + + const indices = []; + const vertices = []; + const normals = []; + const uvs = []; + + // helper variables + + const vertex = new Vector3(); + const normal = new Vector3(); + + const P1 = new Vector3(); + const P2 = new Vector3(); + + const B = new Vector3(); + const T = new Vector3(); + const N = new Vector3(); + + // generate vertices, normals and uvs + + for ( let i = 0; i <= tubularSegments; ++ i ) { + + // the radian "u" is used to calculate the position on the torus curve of the current tubular segment + + const u = i / tubularSegments * p * Math.PI * 2; + + // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead. + // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions + + calculatePositionOnCurve( u, p, q, radius, P1 ); + calculatePositionOnCurve( u + 0.01, p, q, radius, P2 ); + + // calculate orthonormal basis + + T.subVectors( P2, P1 ); + N.addVectors( P2, P1 ); + B.crossVectors( T, N ); + N.crossVectors( B, T ); + + // normalize B, N. T can be ignored, we don't use it + + B.normalize(); + N.normalize(); + + for ( let j = 0; j <= radialSegments; ++ j ) { + + // now calculate the vertices. they are nothing more than an extrusion of the torus curve. + // because we extrude a shape in the xy-plane, there is no need to calculate a z-value. + + const v = j / radialSegments * Math.PI * 2; + const cx = - tube * Math.cos( v ); + const cy = tube * Math.sin( v ); + + // now calculate the final vertex position. + // first we orient the extrusion with our basis vectors, then we add it to the current position on the curve + + vertex.x = P1.x + ( cx * N.x + cy * B.x ); + vertex.y = P1.y + ( cx * N.y + cy * B.y ); + vertex.z = P1.z + ( cx * N.z + cy * B.z ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal) + + normal.subVectors( vertex, P1 ).normalize(); + + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( i / tubularSegments ); + uvs.push( j / radialSegments ); + + } + + } + + // generate indices + + for ( let j = 1; j <= tubularSegments; j ++ ) { + + for ( let i = 1; i <= radialSegments; i ++ ) { + + // indices + + const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 ); + const b = ( radialSegments + 1 ) * j + ( i - 1 ); + const c = ( radialSegments + 1 ) * j + i; + const d = ( radialSegments + 1 ) * ( j - 1 ) + i; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + // this function calculates the current position on the torus curve + + function calculatePositionOnCurve( u, p, q, radius, position ) { + + const cu = Math.cos( u ); + const su = Math.sin( u ); + const quOverP = q / p * u; + const cs = Math.cos( quOverP ); + + position.x = radius * ( 2 + cs ) * 0.5 * cu; + position.y = radius * ( 2 + cs ) * su * 0.5; + position.z = radius * Math.sin( quOverP ) * 0.5; + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + static fromJSON( data ) { + + return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q ); + + } + +} + +class TubeGeometry extends BufferGeometry { + + constructor( path = new QuadraticBezierCurve3( new Vector3( - 1, - 1, 0 ), new Vector3( - 1, 1, 0 ), new Vector3( 1, 1, 0 ) ), tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) { + + super(); + + this.type = 'TubeGeometry'; + + this.parameters = { + path: path, + tubularSegments: tubularSegments, + radius: radius, + radialSegments: radialSegments, + closed: closed + }; + + const frames = path.computeFrenetFrames( tubularSegments, closed ); + + // expose internals + + this.tangents = frames.tangents; + this.normals = frames.normals; + this.binormals = frames.binormals; + + // helper variables + + const vertex = new Vector3(); + const normal = new Vector3(); + const uv = new Vector2(); + let P = new Vector3(); + + // buffer + + const vertices = []; + const normals = []; + const uvs = []; + const indices = []; + + // create buffer data + + generateBufferData(); + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + // functions + + function generateBufferData() { + + for ( let i = 0; i < tubularSegments; i ++ ) { + + generateSegment( i ); + + } + + // if the geometry is not closed, generate the last row of vertices and normals + // at the regular position on the given path + // + // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ) + + generateSegment( ( closed === false ) ? tubularSegments : 0 ); + + // uvs are generated in a separate function. + // this makes it easy compute correct values for closed geometries + + generateUVs(); + + // finally create faces + + generateIndices(); + + } + + function generateSegment( i ) { + + // we use getPointAt to sample evenly distributed points from the given path + + P = path.getPointAt( i / tubularSegments, P ); + + // retrieve corresponding normal and binormal + + const N = frames.normals[ i ]; + const B = frames.binormals[ i ]; + + // generate normals and vertices for the current segment + + for ( let j = 0; j <= radialSegments; j ++ ) { + + const v = j / radialSegments * Math.PI * 2; + + const sin = Math.sin( v ); + const cos = - Math.cos( v ); + + // normal + + normal.x = ( cos * N.x + sin * B.x ); + normal.y = ( cos * N.y + sin * B.y ); + normal.z = ( cos * N.z + sin * B.z ); + normal.normalize(); + + normals.push( normal.x, normal.y, normal.z ); + + // vertex + + vertex.x = P.x + radius * normal.x; + vertex.y = P.y + radius * normal.y; + vertex.z = P.z + radius * normal.z; + + vertices.push( vertex.x, vertex.y, vertex.z ); + + } + + } + + function generateIndices() { + + for ( let j = 1; j <= tubularSegments; j ++ ) { + + for ( let i = 1; i <= radialSegments; i ++ ) { + + const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 ); + const b = ( radialSegments + 1 ) * j + ( i - 1 ); + const c = ( radialSegments + 1 ) * j + i; + const d = ( radialSegments + 1 ) * ( j - 1 ) + i; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + } + + function generateUVs() { + + for ( let i = 0; i <= tubularSegments; i ++ ) { + + for ( let j = 0; j <= radialSegments; j ++ ) { + + uv.x = i / tubularSegments; + uv.y = j / radialSegments; + + uvs.push( uv.x, uv.y ); + + } + + } + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.path = this.parameters.path.toJSON(); + + return data; + + } + + static fromJSON( data ) { + + // This only works for built-in curves (e.g. CatmullRomCurve3). + // User defined curves or instances of CurvePath will not be deserialized. + return new TubeGeometry( + new Curves[ data.path.type ]().fromJSON( data.path ), + data.tubularSegments, + data.radius, + data.radialSegments, + data.closed + ); + + } + +} + +class WireframeGeometry extends BufferGeometry { + + constructor( geometry = null ) { + + super(); + + this.type = 'WireframeGeometry'; + + this.parameters = { + geometry: geometry + }; + + if ( geometry !== null ) { + + // buffer + + const vertices = []; + const edges = new Set(); + + // helper variables + + const start = new Vector3(); + const end = new Vector3(); + + if ( geometry.index !== null ) { + + // indexed BufferGeometry + + const position = geometry.attributes.position; + const indices = geometry.index; + let groups = geometry.groups; + + if ( groups.length === 0 ) { + + groups = [ { start: 0, count: indices.count, materialIndex: 0 } ]; + + } + + // create a data structure that contains all edges without duplicates + + for ( let o = 0, ol = groups.length; o < ol; ++ o ) { + + const group = groups[ o ]; + + const groupStart = group.start; + const groupCount = group.count; + + for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) { + + for ( let j = 0; j < 3; j ++ ) { + + const index1 = indices.getX( i + j ); + const index2 = indices.getX( i + ( j + 1 ) % 3 ); + + start.fromBufferAttribute( position, index1 ); + end.fromBufferAttribute( position, index2 ); + + if ( isUniqueEdge( start, end, edges ) === true ) { + + vertices.push( start.x, start.y, start.z ); + vertices.push( end.x, end.y, end.z ); + + } + + } + + } + + } + + } else { + + // non-indexed BufferGeometry + + const position = geometry.attributes.position; + + for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) { + + for ( let j = 0; j < 3; j ++ ) { + + // three edges per triangle, an edge is represented as (index1, index2) + // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0) + + const index1 = 3 * i + j; + const index2 = 3 * i + ( ( j + 1 ) % 3 ); + + start.fromBufferAttribute( position, index1 ); + end.fromBufferAttribute( position, index2 ); + + if ( isUniqueEdge( start, end, edges ) === true ) { + + vertices.push( start.x, start.y, start.z ); + vertices.push( end.x, end.y, end.z ); + + } + + } + + } + + } + + // build geometry + + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + + } + + } + + copy( source ) { + + super.copy( source ); + + this.parameters = Object.assign( {}, source.parameters ); + + return this; + + } + +} + +function isUniqueEdge( start, end, edges ) { + + const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`; + const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge + + if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) { + + return false; + + } else { + + edges.add( hash1 ); + edges.add( hash2 ); + return true; + + } + +} + +var Geometries = /*#__PURE__*/Object.freeze({ + __proto__: null, + BoxGeometry: BoxGeometry, + CapsuleGeometry: CapsuleGeometry, + CircleGeometry: CircleGeometry, + ConeGeometry: ConeGeometry, + CylinderGeometry: CylinderGeometry, + DodecahedronGeometry: DodecahedronGeometry, + EdgesGeometry: EdgesGeometry, + ExtrudeGeometry: ExtrudeGeometry, + IcosahedronGeometry: IcosahedronGeometry, + LatheGeometry: LatheGeometry, + OctahedronGeometry: OctahedronGeometry, + PlaneGeometry: PlaneGeometry, + PolyhedronGeometry: PolyhedronGeometry, + RingGeometry: RingGeometry, + ShapeGeometry: ShapeGeometry, + SphereGeometry: SphereGeometry, + TetrahedronGeometry: TetrahedronGeometry, + TorusGeometry: TorusGeometry, + TorusKnotGeometry: TorusKnotGeometry, + TubeGeometry: TubeGeometry, + WireframeGeometry: WireframeGeometry +}); + +class ShadowMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isShadowMaterial = true; + + this.type = 'ShadowMaterial'; + + this.color = new Color( 0x000000 ); + this.transparent = true; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.fog = source.fog; + + return this; + + } + +} + +class RawShaderMaterial extends ShaderMaterial { + + constructor( parameters ) { + + super( parameters ); + + this.isRawShaderMaterial = true; + + this.type = 'RawShaderMaterial'; + + } + +} + +class MeshStandardMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshStandardMaterial = true; + + this.type = 'MeshStandardMaterial'; + + this.defines = { 'STANDARD': '' }; + + this.color = new Color( 0xffffff ); // diffuse + this.roughness = 1.0; + this.metalness = 0.0; + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.roughnessMap = null; + + this.metalnessMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.envMapRotation = new Euler(); + this.envMapIntensity = 1.0; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.flatShading = false; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.defines = { 'STANDARD': '' }; + + this.color.copy( source.color ); + this.roughness = source.roughness; + this.metalness = source.metalness; + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.roughnessMap = source.roughnessMap; + + this.metalnessMap = source.metalnessMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapRotation.copy( source.envMapRotation ); + this.envMapIntensity = source.envMapIntensity; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.flatShading = source.flatShading; + + this.fog = source.fog; + + return this; + + } + +} + +class MeshPhysicalMaterial extends MeshStandardMaterial { + + constructor( parameters ) { + + super(); + + this.isMeshPhysicalMaterial = true; + + this.defines = { + + 'STANDARD': '', + 'PHYSICAL': '' + + }; + + this.type = 'MeshPhysicalMaterial'; + + this.anisotropyRotation = 0; + this.anisotropyMap = null; + + this.clearcoatMap = null; + this.clearcoatRoughness = 0.0; + this.clearcoatRoughnessMap = null; + this.clearcoatNormalScale = new Vector2( 1, 1 ); + this.clearcoatNormalMap = null; + + this.ior = 1.5; + + Object.defineProperty( this, 'reflectivity', { + get: function () { + + return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) ); + + }, + set: function ( reflectivity ) { + + this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity ); + + } + } ); + + this.iridescenceMap = null; + this.iridescenceIOR = 1.3; + this.iridescenceThicknessRange = [ 100, 400 ]; + this.iridescenceThicknessMap = null; + + this.sheenColor = new Color( 0x000000 ); + this.sheenColorMap = null; + this.sheenRoughness = 1.0; + this.sheenRoughnessMap = null; + + this.transmissionMap = null; + + this.thickness = 0; + this.thicknessMap = null; + this.attenuationDistance = Infinity; + this.attenuationColor = new Color( 1, 1, 1 ); + + this.specularIntensity = 1.0; + this.specularIntensityMap = null; + this.specularColor = new Color( 1, 1, 1 ); + this.specularColorMap = null; + + this._anisotropy = 0; + this._clearcoat = 0; + this._dispersion = 0; + this._iridescence = 0; + this._sheen = 0.0; + this._transmission = 0; + + this.setValues( parameters ); + + } + + get anisotropy() { + + return this._anisotropy; + + } + + set anisotropy( value ) { + + if ( this._anisotropy > 0 !== value > 0 ) { + + this.version ++; + + } + + this._anisotropy = value; + + } + + get clearcoat() { + + return this._clearcoat; + + } + + set clearcoat( value ) { + + if ( this._clearcoat > 0 !== value > 0 ) { + + this.version ++; + + } + + this._clearcoat = value; + + } + + get iridescence() { + + return this._iridescence; + + } + + set iridescence( value ) { + + if ( this._iridescence > 0 !== value > 0 ) { + + this.version ++; + + } + + this._iridescence = value; + + } + + get dispersion() { + + return this._dispersion; + + } + + set dispersion( value ) { + + if ( this._dispersion > 0 !== value > 0 ) { + + this.version ++; + + } + + this._dispersion = value; + + } + + get sheen() { + + return this._sheen; + + } + + set sheen( value ) { + + if ( this._sheen > 0 !== value > 0 ) { + + this.version ++; + + } + + this._sheen = value; + + } + + get transmission() { + + return this._transmission; + + } + + set transmission( value ) { + + if ( this._transmission > 0 !== value > 0 ) { + + this.version ++; + + } + + this._transmission = value; + + } + + copy( source ) { + + super.copy( source ); + + this.defines = { + + 'STANDARD': '', + 'PHYSICAL': '' + + }; + + this.anisotropy = source.anisotropy; + this.anisotropyRotation = source.anisotropyRotation; + this.anisotropyMap = source.anisotropyMap; + + this.clearcoat = source.clearcoat; + this.clearcoatMap = source.clearcoatMap; + this.clearcoatRoughness = source.clearcoatRoughness; + this.clearcoatRoughnessMap = source.clearcoatRoughnessMap; + this.clearcoatNormalMap = source.clearcoatNormalMap; + this.clearcoatNormalScale.copy( source.clearcoatNormalScale ); + + this.dispersion = source.dispersion; + this.ior = source.ior; + + this.iridescence = source.iridescence; + this.iridescenceMap = source.iridescenceMap; + this.iridescenceIOR = source.iridescenceIOR; + this.iridescenceThicknessRange = [ ...source.iridescenceThicknessRange ]; + this.iridescenceThicknessMap = source.iridescenceThicknessMap; + + this.sheen = source.sheen; + this.sheenColor.copy( source.sheenColor ); + this.sheenColorMap = source.sheenColorMap; + this.sheenRoughness = source.sheenRoughness; + this.sheenRoughnessMap = source.sheenRoughnessMap; + + this.transmission = source.transmission; + this.transmissionMap = source.transmissionMap; + + this.thickness = source.thickness; + this.thicknessMap = source.thicknessMap; + this.attenuationDistance = source.attenuationDistance; + this.attenuationColor.copy( source.attenuationColor ); + + this.specularIntensity = source.specularIntensity; + this.specularIntensityMap = source.specularIntensityMap; + this.specularColor.copy( source.specularColor ); + this.specularColorMap = source.specularColorMap; + + return this; + + } + +} + +class MeshPhongMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshPhongMaterial = true; + + this.type = 'MeshPhongMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + this.specular = new Color( 0x111111 ); + this.shininess = 30; + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.specularMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.envMapRotation = new Euler(); + + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.flatShading = false; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + this.specular.copy( source.specular ); + this.shininess = source.shininess; + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.specularMap = source.specularMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapRotation.copy( source.envMapRotation ); + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.flatShading = source.flatShading; + + this.fog = source.fog; + + return this; + + } + +} + +class MeshToonMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshToonMaterial = true; + + this.defines = { 'TOON': '' }; + + this.type = 'MeshToonMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + this.gradientMap = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.alphaMap = null; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.map = source.map; + this.gradientMap = source.gradientMap; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.alphaMap = source.alphaMap; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.fog = source.fog; + + return this; + + } + +} + +class MeshNormalMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshNormalMaterial = true; + + this.type = 'MeshNormalMaterial'; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.wireframe = false; + this.wireframeLinewidth = 1; + + this.flatShading = false; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + + this.flatShading = source.flatShading; + + return this; + + } + +} + +class MeshLambertMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshLambertMaterial = true; + + this.type = 'MeshLambertMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.specularMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.envMapRotation = new Euler(); + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.flatShading = false; + + this.fog = true; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.specularMap = source.specularMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapRotation.copy( source.envMapRotation ); + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.flatShading = source.flatShading; + + this.fog = source.fog; + + return this; + + } + +} + +class MeshDepthMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshDepthMaterial = true; + + this.type = 'MeshDepthMaterial'; + + this.depthPacking = BasicDepthPacking; + + this.map = null; + + this.alphaMap = null; + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.wireframe = false; + this.wireframeLinewidth = 1; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.depthPacking = source.depthPacking; + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + + return this; + + } + +} + +class MeshDistanceMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshDistanceMaterial = true; + + this.type = 'MeshDistanceMaterial'; + + this.map = null; + + this.alphaMap = null; + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + return this; + + } + +} + +class MeshMatcapMaterial extends Material { + + constructor( parameters ) { + + super(); + + this.isMeshMatcapMaterial = true; + + this.defines = { 'MATCAP': '' }; + + this.type = 'MeshMatcapMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + + this.matcap = null; + + this.map = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.alphaMap = null; + + this.flatShading = false; + + this.fog = true; + + this.setValues( parameters ); + + } + + + copy( source ) { + + super.copy( source ); + + this.defines = { 'MATCAP': '' }; + + this.color.copy( source.color ); + + this.matcap = source.matcap; + + this.map = source.map; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.alphaMap = source.alphaMap; + + this.flatShading = source.flatShading; + + this.fog = source.fog; + + return this; + + } + +} + +class LineDashedMaterial extends LineBasicMaterial { + + constructor( parameters ) { + + super(); + + this.isLineDashedMaterial = true; + this.type = 'LineDashedMaterial'; + + this.scale = 1; + this.dashSize = 3; + this.gapSize = 1; + + this.setValues( parameters ); + + } + + copy( source ) { + + super.copy( source ); + + this.scale = source.scale; + this.dashSize = source.dashSize; + this.gapSize = source.gapSize; + + return this; + + } + +} + +// converts an array to a specific type +function convertArray( array, type, forceClone ) { + + if ( ! array || // let 'undefined' and 'null' pass + ! forceClone && array.constructor === type ) return array; + + if ( typeof type.BYTES_PER_ELEMENT === 'number' ) { + + return new type( array ); // create typed array + + } + + return Array.prototype.slice.call( array ); // create Array + +} + +function isTypedArray( object ) { + + return ArrayBuffer.isView( object ) && + ! ( object instanceof DataView ); + +} + +// returns an array by which times and values can be sorted +function getKeyframeOrder( times ) { + + function compareTime( i, j ) { + + return times[ i ] - times[ j ]; + + } + + const n = times.length; + const result = new Array( n ); + for ( let i = 0; i !== n; ++ i ) result[ i ] = i; + + result.sort( compareTime ); + + return result; + +} + +// uses the array previously returned by 'getKeyframeOrder' to sort data +function sortedArray( values, stride, order ) { + + const nValues = values.length; + const result = new values.constructor( nValues ); + + for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) { + + const srcOffset = order[ i ] * stride; + + for ( let j = 0; j !== stride; ++ j ) { + + result[ dstOffset ++ ] = values[ srcOffset + j ]; + + } + + } + + return result; + +} + +// function for parsing AOS keyframe formats +function flattenJSON( jsonKeys, times, values, valuePropertyName ) { + + let i = 1, key = jsonKeys[ 0 ]; + + while ( key !== undefined && key[ valuePropertyName ] === undefined ) { + + key = jsonKeys[ i ++ ]; + + } + + if ( key === undefined ) return; // no data + + let value = key[ valuePropertyName ]; + if ( value === undefined ) return; // no data + + if ( Array.isArray( value ) ) { + + do { + + value = key[ valuePropertyName ]; + + if ( value !== undefined ) { + + times.push( key.time ); + values.push.apply( values, value ); // push all elements + + } + + key = jsonKeys[ i ++ ]; + + } while ( key !== undefined ); + + } else if ( value.toArray !== undefined ) { + + // ...assume THREE.Math-ish + + do { + + value = key[ valuePropertyName ]; + + if ( value !== undefined ) { + + times.push( key.time ); + value.toArray( values, values.length ); + + } + + key = jsonKeys[ i ++ ]; + + } while ( key !== undefined ); + + } else { + + // otherwise push as-is + + do { + + value = key[ valuePropertyName ]; + + if ( value !== undefined ) { + + times.push( key.time ); + values.push( value ); + + } + + key = jsonKeys[ i ++ ]; + + } while ( key !== undefined ); + + } + +} + +function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) { + + const clip = sourceClip.clone(); + + clip.name = name; + + const tracks = []; + + for ( let i = 0; i < clip.tracks.length; ++ i ) { + + const track = clip.tracks[ i ]; + const valueSize = track.getValueSize(); + + const times = []; + const values = []; + + for ( let j = 0; j < track.times.length; ++ j ) { + + const frame = track.times[ j ] * fps; + + if ( frame < startFrame || frame >= endFrame ) continue; + + times.push( track.times[ j ] ); + + for ( let k = 0; k < valueSize; ++ k ) { + + values.push( track.values[ j * valueSize + k ] ); + + } + + } + + if ( times.length === 0 ) continue; + + track.times = convertArray( times, track.times.constructor ); + track.values = convertArray( values, track.values.constructor ); + + tracks.push( track ); + + } + + clip.tracks = tracks; + + // find minimum .times value across all tracks in the trimmed clip + + let minStartTime = Infinity; + + for ( let i = 0; i < clip.tracks.length; ++ i ) { + + if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) { + + minStartTime = clip.tracks[ i ].times[ 0 ]; + + } + + } + + // shift all tracks such that clip begins at t=0 + + for ( let i = 0; i < clip.tracks.length; ++ i ) { + + clip.tracks[ i ].shift( - 1 * minStartTime ); + + } + + clip.resetDuration(); + + return clip; + +} + +function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) { + + if ( fps <= 0 ) fps = 30; + + const numTracks = referenceClip.tracks.length; + const referenceTime = referenceFrame / fps; + + // Make each track's values relative to the values at the reference frame + for ( let i = 0; i < numTracks; ++ i ) { + + const referenceTrack = referenceClip.tracks[ i ]; + const referenceTrackType = referenceTrack.ValueTypeName; + + // Skip this track if it's non-numeric + if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue; + + // Find the track in the target clip whose name and type matches the reference track + const targetTrack = targetClip.tracks.find( function ( track ) { + + return track.name === referenceTrack.name + && track.ValueTypeName === referenceTrackType; + + } ); + + if ( targetTrack === undefined ) continue; + + let referenceOffset = 0; + const referenceValueSize = referenceTrack.getValueSize(); + + if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) { + + referenceOffset = referenceValueSize / 3; + + } + + let targetOffset = 0; + const targetValueSize = targetTrack.getValueSize(); + + if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) { + + targetOffset = targetValueSize / 3; + + } + + const lastIndex = referenceTrack.times.length - 1; + let referenceValue; + + // Find the value to subtract out of the track + if ( referenceTime <= referenceTrack.times[ 0 ] ) { + + // Reference frame is earlier than the first keyframe, so just use the first keyframe + const startIndex = referenceOffset; + const endIndex = referenceValueSize - referenceOffset; + referenceValue = referenceTrack.values.slice( startIndex, endIndex ); + + } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) { + + // Reference frame is after the last keyframe, so just use the last keyframe + const startIndex = lastIndex * referenceValueSize + referenceOffset; + const endIndex = startIndex + referenceValueSize - referenceOffset; + referenceValue = referenceTrack.values.slice( startIndex, endIndex ); + + } else { + + // Interpolate to the reference value + const interpolant = referenceTrack.createInterpolant(); + const startIndex = referenceOffset; + const endIndex = referenceValueSize - referenceOffset; + interpolant.evaluate( referenceTime ); + referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex ); + + } + + // Conjugate the quaternion + if ( referenceTrackType === 'quaternion' ) { + + const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate(); + referenceQuat.toArray( referenceValue ); + + } + + // Subtract the reference value from all of the track values + + const numTimes = targetTrack.times.length; + for ( let j = 0; j < numTimes; ++ j ) { + + const valueStart = j * targetValueSize + targetOffset; + + if ( referenceTrackType === 'quaternion' ) { + + // Multiply the conjugate for quaternion track types + Quaternion.multiplyQuaternionsFlat( + targetTrack.values, + valueStart, + referenceValue, + 0, + targetTrack.values, + valueStart + ); + + } else { + + const valueEnd = targetValueSize - targetOffset * 2; + + // Subtract each value for all other numeric track types + for ( let k = 0; k < valueEnd; ++ k ) { + + targetTrack.values[ valueStart + k ] -= referenceValue[ k ]; + + } + + } + + } + + } + + targetClip.blendMode = AdditiveAnimationBlendMode; + + return targetClip; + +} + +const AnimationUtils = { + convertArray: convertArray, + isTypedArray: isTypedArray, + getKeyframeOrder: getKeyframeOrder, + sortedArray: sortedArray, + flattenJSON: flattenJSON, + subclip: subclip, + makeClipAdditive: makeClipAdditive +}; + +/** + * Abstract base class of interpolants over parametric samples. + * + * The parameter domain is one dimensional, typically the time or a path + * along a curve defined by the data. + * + * The sample values can have any dimensionality and derived classes may + * apply special interpretations to the data. + * + * This class provides the interval seek in a Template Method, deferring + * the actual interpolation to derived classes. + * + * Time complexity is O(1) for linear access crossing at most two points + * and O(log N) for random access, where N is the number of positions. + * + * References: + * + * http://www.oodesign.com/template-method-pattern.html + * + */ + +class Interpolant { + + constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + this.parameterPositions = parameterPositions; + this._cachedIndex = 0; + + this.resultBuffer = resultBuffer !== undefined ? + resultBuffer : new sampleValues.constructor( sampleSize ); + this.sampleValues = sampleValues; + this.valueSize = sampleSize; + + this.settings = null; + this.DefaultSettings_ = {}; + + } + + evaluate( t ) { + + const pp = this.parameterPositions; + let i1 = this._cachedIndex, + t1 = pp[ i1 ], + t0 = pp[ i1 - 1 ]; + + validate_interval: { + + seek: { + + let right; + + linear_scan: { + + //- See http://jsperf.com/comparison-to-undefined/3 + //- slower code: + //- + //- if ( t >= t1 || t1 === undefined ) { + forward_scan: if ( ! ( t < t1 ) ) { + + for ( let giveUpAt = i1 + 2; ; ) { + + if ( t1 === undefined ) { + + if ( t < t0 ) break forward_scan; + + // after end + + i1 = pp.length; + this._cachedIndex = i1; + return this.copySampleValue_( i1 - 1 ); + + } + + if ( i1 === giveUpAt ) break; // this loop + + t0 = t1; + t1 = pp[ ++ i1 ]; + + if ( t < t1 ) { + + // we have arrived at the sought interval + break seek; + + } + + } + + // prepare binary search on the right side of the index + right = pp.length; + break linear_scan; + + } + + //- slower code: + //- if ( t < t0 || t0 === undefined ) { + if ( ! ( t >= t0 ) ) { + + // looping? + + const t1global = pp[ 1 ]; + + if ( t < t1global ) { + + i1 = 2; // + 1, using the scan for the details + t0 = t1global; + + } + + // linear reverse scan + + for ( let giveUpAt = i1 - 2; ; ) { + + if ( t0 === undefined ) { + + // before start + + this._cachedIndex = 0; + return this.copySampleValue_( 0 ); + + } + + if ( i1 === giveUpAt ) break; // this loop + + t1 = t0; + t0 = pp[ -- i1 - 1 ]; + + if ( t >= t0 ) { + + // we have arrived at the sought interval + break seek; + + } + + } + + // prepare binary search on the left side of the index + right = i1; + i1 = 0; + break linear_scan; + + } + + // the interval is valid + + break validate_interval; + + } // linear scan + + // binary search + + while ( i1 < right ) { + + const mid = ( i1 + right ) >>> 1; + + if ( t < pp[ mid ] ) { + + right = mid; + + } else { + + i1 = mid + 1; + + } + + } + + t1 = pp[ i1 ]; + t0 = pp[ i1 - 1 ]; + + // check boundary cases, again + + if ( t0 === undefined ) { + + this._cachedIndex = 0; + return this.copySampleValue_( 0 ); + + } + + if ( t1 === undefined ) { + + i1 = pp.length; + this._cachedIndex = i1; + return this.copySampleValue_( i1 - 1 ); + + } + + } // seek + + this._cachedIndex = i1; + + this.intervalChanged_( i1, t0, t1 ); + + } // validate_interval + + return this.interpolate_( i1, t0, t, t1 ); + + } + + getSettings_() { + + return this.settings || this.DefaultSettings_; + + } + + copySampleValue_( index ) { + + // copies a sample value to the result buffer + + const result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + offset = index * stride; + + for ( let i = 0; i !== stride; ++ i ) { + + result[ i ] = values[ offset + i ]; + + } + + return result; + + } + + // Template methods for derived classes: + + interpolate_( /* i1, t0, t, t1 */ ) { + + throw new Error( 'call to abstract method' ); + // implementations shall return this.resultBuffer + + } + + intervalChanged_( /* i1, t0, t1 */ ) { + + // empty + + } + +} + +/** + * Fast and simple cubic spline interpolant. + * + * It was derived from a Hermitian construction setting the first derivative + * at each sample position to the linear slope between neighboring positions + * over their parameter interval. + */ + +class CubicInterpolant extends Interpolant { + + constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + super( parameterPositions, sampleValues, sampleSize, resultBuffer ); + + this._weightPrev = - 0; + this._offsetPrev = - 0; + this._weightNext = - 0; + this._offsetNext = - 0; + + this.DefaultSettings_ = { + + endingStart: ZeroCurvatureEnding, + endingEnd: ZeroCurvatureEnding + + }; + + } + + intervalChanged_( i1, t0, t1 ) { + + const pp = this.parameterPositions; + let iPrev = i1 - 2, + iNext = i1 + 1, + + tPrev = pp[ iPrev ], + tNext = pp[ iNext ]; + + if ( tPrev === undefined ) { + + switch ( this.getSettings_().endingStart ) { + + case ZeroSlopeEnding: + + // f'(t0) = 0 + iPrev = i1; + tPrev = 2 * t0 - t1; + + break; + + case WrapAroundEnding: + + // use the other end of the curve + iPrev = pp.length - 2; + tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ]; + + break; + + default: // ZeroCurvatureEnding + + // f''(t0) = 0 a.k.a. Natural Spline + iPrev = i1; + tPrev = t1; + + } + + } + + if ( tNext === undefined ) { + + switch ( this.getSettings_().endingEnd ) { + + case ZeroSlopeEnding: + + // f'(tN) = 0 + iNext = i1; + tNext = 2 * t1 - t0; + + break; + + case WrapAroundEnding: + + // use the other end of the curve + iNext = 1; + tNext = t1 + pp[ 1 ] - pp[ 0 ]; + + break; + + default: // ZeroCurvatureEnding + + // f''(tN) = 0, a.k.a. Natural Spline + iNext = i1 - 1; + tNext = t0; + + } + + } + + const halfDt = ( t1 - t0 ) * 0.5, + stride = this.valueSize; + + this._weightPrev = halfDt / ( t0 - tPrev ); + this._weightNext = halfDt / ( tNext - t1 ); + this._offsetPrev = iPrev * stride; + this._offsetNext = iNext * stride; + + } + + interpolate_( i1, t0, t, t1 ) { + + const result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + + o1 = i1 * stride, o0 = o1 - stride, + oP = this._offsetPrev, oN = this._offsetNext, + wP = this._weightPrev, wN = this._weightNext, + + p = ( t - t0 ) / ( t1 - t0 ), + pp = p * p, + ppp = pp * p; + + // evaluate polynomials + + const sP = - wP * ppp + 2 * wP * pp - wP * p; + const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1; + const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p; + const sN = wN * ppp - wN * pp; + + // combine data linearly + + for ( let i = 0; i !== stride; ++ i ) { + + result[ i ] = + sP * values[ oP + i ] + + s0 * values[ o0 + i ] + + s1 * values[ o1 + i ] + + sN * values[ oN + i ]; + + } + + return result; + + } + +} + +class LinearInterpolant extends Interpolant { + + constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + super( parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + interpolate_( i1, t0, t, t1 ) { + + const result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + + offset1 = i1 * stride, + offset0 = offset1 - stride, + + weight1 = ( t - t0 ) / ( t1 - t0 ), + weight0 = 1 - weight1; + + for ( let i = 0; i !== stride; ++ i ) { + + result[ i ] = + values[ offset0 + i ] * weight0 + + values[ offset1 + i ] * weight1; + + } + + return result; + + } + +} + +/** + * + * Interpolant that evaluates to the sample value at the position preceding + * the parameter. + */ + +class DiscreteInterpolant extends Interpolant { + + constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + super( parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + interpolate_( i1 /*, t0, t, t1 */ ) { + + return this.copySampleValue_( i1 - 1 ); + + } + +} + +class KeyframeTrack { + + constructor( name, times, values, interpolation ) { + + if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' ); + if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name ); + + this.name = name; + + this.times = convertArray( times, this.TimeBufferType ); + this.values = convertArray( values, this.ValueBufferType ); + + this.setInterpolation( interpolation || this.DefaultInterpolation ); + + } + + // Serialization (in static context, because of constructor invocation + // and automatic invocation of .toJSON): + + static toJSON( track ) { + + const trackType = track.constructor; + + let json; + + // derived classes can define a static toJSON method + if ( trackType.toJSON !== this.toJSON ) { + + json = trackType.toJSON( track ); + + } else { + + // by default, we assume the data can be serialized as-is + json = { + + 'name': track.name, + 'times': convertArray( track.times, Array ), + 'values': convertArray( track.values, Array ) + + }; + + const interpolation = track.getInterpolation(); + + if ( interpolation !== track.DefaultInterpolation ) { + + json.interpolation = interpolation; + + } + + } + + json.type = track.ValueTypeName; // mandatory + + return json; + + } + + InterpolantFactoryMethodDiscrete( result ) { + + return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result ); + + } + + InterpolantFactoryMethodLinear( result ) { + + return new LinearInterpolant( this.times, this.values, this.getValueSize(), result ); + + } + + InterpolantFactoryMethodSmooth( result ) { + + return new CubicInterpolant( this.times, this.values, this.getValueSize(), result ); + + } + + setInterpolation( interpolation ) { + + let factoryMethod; + + switch ( interpolation ) { + + case InterpolateDiscrete: + + factoryMethod = this.InterpolantFactoryMethodDiscrete; + + break; + + case InterpolateLinear: + + factoryMethod = this.InterpolantFactoryMethodLinear; + + break; + + case InterpolateSmooth: + + factoryMethod = this.InterpolantFactoryMethodSmooth; + + break; + + } + + if ( factoryMethod === undefined ) { + + const message = 'unsupported interpolation for ' + + this.ValueTypeName + ' keyframe track named ' + this.name; + + if ( this.createInterpolant === undefined ) { + + // fall back to default, unless the default itself is messed up + if ( interpolation !== this.DefaultInterpolation ) { + + this.setInterpolation( this.DefaultInterpolation ); + + } else { + + throw new Error( message ); // fatal, in this case + + } + + } + + console.warn( 'THREE.KeyframeTrack:', message ); + return this; + + } + + this.createInterpolant = factoryMethod; + + return this; + + } + + getInterpolation() { + + switch ( this.createInterpolant ) { + + case this.InterpolantFactoryMethodDiscrete: + + return InterpolateDiscrete; + + case this.InterpolantFactoryMethodLinear: + + return InterpolateLinear; + + case this.InterpolantFactoryMethodSmooth: + + return InterpolateSmooth; + + } + + } + + getValueSize() { + + return this.values.length / this.times.length; + + } + + // move all keyframes either forwards or backwards in time + shift( timeOffset ) { + + if ( timeOffset !== 0.0 ) { + + const times = this.times; + + for ( let i = 0, n = times.length; i !== n; ++ i ) { + + times[ i ] += timeOffset; + + } + + } + + return this; + + } + + // scale all keyframe times by a factor (useful for frame <-> seconds conversions) + scale( timeScale ) { + + if ( timeScale !== 1.0 ) { + + const times = this.times; + + for ( let i = 0, n = times.length; i !== n; ++ i ) { + + times[ i ] *= timeScale; + + } + + } + + return this; + + } + + // removes keyframes before and after animation without changing any values within the range [startTime, endTime]. + // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values + trim( startTime, endTime ) { + + const times = this.times, + nKeys = times.length; + + let from = 0, + to = nKeys - 1; + + while ( from !== nKeys && times[ from ] < startTime ) { + + ++ from; + + } + + while ( to !== - 1 && times[ to ] > endTime ) { + + -- to; + + } + + ++ to; // inclusive -> exclusive bound + + if ( from !== 0 || to !== nKeys ) { + + // empty tracks are forbidden, so keep at least one keyframe + if ( from >= to ) { + + to = Math.max( to, 1 ); + from = to - 1; + + } + + const stride = this.getValueSize(); + this.times = times.slice( from, to ); + this.values = this.values.slice( from * stride, to * stride ); + + } + + return this; + + } + + // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable + validate() { + + let valid = true; + + const valueSize = this.getValueSize(); + if ( valueSize - Math.floor( valueSize ) !== 0 ) { + + console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this ); + valid = false; + + } + + const times = this.times, + values = this.values, + + nKeys = times.length; + + if ( nKeys === 0 ) { + + console.error( 'THREE.KeyframeTrack: Track is empty.', this ); + valid = false; + + } + + let prevTime = null; + + for ( let i = 0; i !== nKeys; i ++ ) { + + const currTime = times[ i ]; + + if ( typeof currTime === 'number' && isNaN( currTime ) ) { + + console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime ); + valid = false; + break; + + } + + if ( prevTime !== null && prevTime > currTime ) { + + console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime ); + valid = false; + break; + + } + + prevTime = currTime; + + } + + if ( values !== undefined ) { + + if ( isTypedArray( values ) ) { + + for ( let i = 0, n = values.length; i !== n; ++ i ) { + + const value = values[ i ]; + + if ( isNaN( value ) ) { + + console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value ); + valid = false; + break; + + } + + } + + } + + } + + return valid; + + } + + // removes equivalent sequential keys as common in morph target sequences + // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0) + optimize() { + + // times or values may be shared with other tracks, so overwriting is unsafe + const times = this.times.slice(), + values = this.values.slice(), + stride = this.getValueSize(), + + smoothInterpolation = this.getInterpolation() === InterpolateSmooth, + + lastIndex = times.length - 1; + + let writeIndex = 1; + + for ( let i = 1; i < lastIndex; ++ i ) { + + let keep = false; + + const time = times[ i ]; + const timeNext = times[ i + 1 ]; + + // remove adjacent keyframes scheduled at the same time + + if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) { + + if ( ! smoothInterpolation ) { + + // remove unnecessary keyframes same as their neighbors + + const offset = i * stride, + offsetP = offset - stride, + offsetN = offset + stride; + + for ( let j = 0; j !== stride; ++ j ) { + + const value = values[ offset + j ]; + + if ( value !== values[ offsetP + j ] || + value !== values[ offsetN + j ] ) { + + keep = true; + break; + + } + + } + + } else { + + keep = true; + + } + + } + + // in-place compaction + + if ( keep ) { + + if ( i !== writeIndex ) { + + times[ writeIndex ] = times[ i ]; + + const readOffset = i * stride, + writeOffset = writeIndex * stride; + + for ( let j = 0; j !== stride; ++ j ) { + + values[ writeOffset + j ] = values[ readOffset + j ]; + + } + + } + + ++ writeIndex; + + } + + } + + // flush last keyframe (compaction looks ahead) + + if ( lastIndex > 0 ) { + + times[ writeIndex ] = times[ lastIndex ]; + + for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) { + + values[ writeOffset + j ] = values[ readOffset + j ]; + + } + + ++ writeIndex; + + } + + if ( writeIndex !== times.length ) { + + this.times = times.slice( 0, writeIndex ); + this.values = values.slice( 0, writeIndex * stride ); + + } else { + + this.times = times; + this.values = values; + + } + + return this; + + } + + clone() { + + const times = this.times.slice(); + const values = this.values.slice(); + + const TypedKeyframeTrack = this.constructor; + const track = new TypedKeyframeTrack( this.name, times, values ); + + // Interpolant argument to constructor is not saved, so copy the factory method directly. + track.createInterpolant = this.createInterpolant; + + return track; + + } + +} + +KeyframeTrack.prototype.TimeBufferType = Float32Array; +KeyframeTrack.prototype.ValueBufferType = Float32Array; +KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear; + +/** + * A Track of Boolean keyframe values. + */ +class BooleanKeyframeTrack extends KeyframeTrack { + + // No interpolation parameter because only InterpolateDiscrete is valid. + constructor( name, times, values ) { + + super( name, times, values ); + + } + +} + +BooleanKeyframeTrack.prototype.ValueTypeName = 'bool'; +BooleanKeyframeTrack.prototype.ValueBufferType = Array; +BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete; +BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined; +BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined; + +/** + * A Track of keyframe values that represent color. + */ +class ColorKeyframeTrack extends KeyframeTrack {} + +ColorKeyframeTrack.prototype.ValueTypeName = 'color'; + +/** + * A Track of numeric keyframe values. + */ +class NumberKeyframeTrack extends KeyframeTrack {} + +NumberKeyframeTrack.prototype.ValueTypeName = 'number'; + +/** + * Spherical linear unit quaternion interpolant. + */ + +class QuaternionLinearInterpolant extends Interpolant { + + constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + super( parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + interpolate_( i1, t0, t, t1 ) { + + const result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + + alpha = ( t - t0 ) / ( t1 - t0 ); + + let offset = i1 * stride; + + for ( let end = offset + stride; offset !== end; offset += 4 ) { + + Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha ); + + } + + return result; + + } + +} + +/** + * A Track of quaternion keyframe values. + */ +class QuaternionKeyframeTrack extends KeyframeTrack { + + InterpolantFactoryMethodLinear( result ) { + + return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result ); + + } + +} + +QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion'; +// ValueBufferType is inherited +// DefaultInterpolation is inherited; +QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined; + +/** + * A Track that interpolates Strings + */ +class StringKeyframeTrack extends KeyframeTrack { + + // No interpolation parameter because only InterpolateDiscrete is valid. + constructor( name, times, values ) { + + super( name, times, values ); + + } + +} + +StringKeyframeTrack.prototype.ValueTypeName = 'string'; +StringKeyframeTrack.prototype.ValueBufferType = Array; +StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete; +StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined; +StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined; + +/** + * A Track of vectored keyframe values. + */ +class VectorKeyframeTrack extends KeyframeTrack {} + +VectorKeyframeTrack.prototype.ValueTypeName = 'vector'; + +class AnimationClip { + + constructor( name = '', duration = - 1, tracks = [], blendMode = NormalAnimationBlendMode ) { + + this.name = name; + this.tracks = tracks; + this.duration = duration; + this.blendMode = blendMode; + + this.uuid = generateUUID(); + + // this means it should figure out its duration by scanning the tracks + if ( this.duration < 0 ) { + + this.resetDuration(); + + } + + } + + + static parse( json ) { + + const tracks = [], + jsonTracks = json.tracks, + frameTime = 1.0 / ( json.fps || 1.0 ); + + for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) { + + tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) ); + + } + + const clip = new this( json.name, json.duration, tracks, json.blendMode ); + clip.uuid = json.uuid; + + return clip; + + } + + static toJSON( clip ) { + + const tracks = [], + clipTracks = clip.tracks; + + const json = { + + 'name': clip.name, + 'duration': clip.duration, + 'tracks': tracks, + 'uuid': clip.uuid, + 'blendMode': clip.blendMode + + }; + + for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) { + + tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) ); + + } + + return json; + + } + + static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) { + + const numMorphTargets = morphTargetSequence.length; + const tracks = []; + + for ( let i = 0; i < numMorphTargets; i ++ ) { + + let times = []; + let values = []; + + times.push( + ( i + numMorphTargets - 1 ) % numMorphTargets, + i, + ( i + 1 ) % numMorphTargets ); + + values.push( 0, 1, 0 ); + + const order = getKeyframeOrder( times ); + times = sortedArray( times, 1, order ); + values = sortedArray( values, 1, order ); + + // if there is a key at the first frame, duplicate it as the + // last frame as well for perfect loop. + if ( ! noLoop && times[ 0 ] === 0 ) { + + times.push( numMorphTargets ); + values.push( values[ 0 ] ); + + } + + tracks.push( + new NumberKeyframeTrack( + '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']', + times, values + ).scale( 1.0 / fps ) ); + + } + + return new this( name, - 1, tracks ); + + } + + static findByName( objectOrClipArray, name ) { + + let clipArray = objectOrClipArray; + + if ( ! Array.isArray( objectOrClipArray ) ) { + + const o = objectOrClipArray; + clipArray = o.geometry && o.geometry.animations || o.animations; + + } + + for ( let i = 0; i < clipArray.length; i ++ ) { + + if ( clipArray[ i ].name === name ) { + + return clipArray[ i ]; + + } + + } + + return null; + + } + + static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) { + + const animationToMorphTargets = {}; + + // tested with https://regex101.com/ on trick sequences + // such flamingo_flyA_003, flamingo_run1_003, crdeath0059 + const pattern = /^([\w-]*?)([\d]+)$/; + + // sort morph target names into animation groups based + // patterns like Walk_001, Walk_002, Run_001, Run_002 + for ( let i = 0, il = morphTargets.length; i < il; i ++ ) { + + const morphTarget = morphTargets[ i ]; + const parts = morphTarget.name.match( pattern ); + + if ( parts && parts.length > 1 ) { + + const name = parts[ 1 ]; + + let animationMorphTargets = animationToMorphTargets[ name ]; + + if ( ! animationMorphTargets ) { + + animationToMorphTargets[ name ] = animationMorphTargets = []; + + } + + animationMorphTargets.push( morphTarget ); + + } + + } + + const clips = []; + + for ( const name in animationToMorphTargets ) { + + clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) ); + + } + + return clips; + + } + + // parse the animation.hierarchy format + static parseAnimation( animation, bones ) { + + if ( ! animation ) { + + console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' ); + return null; + + } + + const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) { + + // only return track if there are actually keys. + if ( animationKeys.length !== 0 ) { + + const times = []; + const values = []; + + flattenJSON( animationKeys, times, values, propertyName ); + + // empty keys are filtered out, so check again + if ( times.length !== 0 ) { + + destTracks.push( new trackType( trackName, times, values ) ); + + } + + } + + }; + + const tracks = []; + + const clipName = animation.name || 'default'; + const fps = animation.fps || 30; + const blendMode = animation.blendMode; + + // automatic length determination in AnimationClip. + let duration = animation.length || - 1; + + const hierarchyTracks = animation.hierarchy || []; + + for ( let h = 0; h < hierarchyTracks.length; h ++ ) { + + const animationKeys = hierarchyTracks[ h ].keys; + + // skip empty tracks + if ( ! animationKeys || animationKeys.length === 0 ) continue; + + // process morph targets + if ( animationKeys[ 0 ].morphTargets ) { + + // figure out all morph targets used in this track + const morphTargetNames = {}; + + let k; + + for ( k = 0; k < animationKeys.length; k ++ ) { + + if ( animationKeys[ k ].morphTargets ) { + + for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) { + + morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1; + + } + + } + + } + + // create a track for each morph target with all zero + // morphTargetInfluences except for the keys in which + // the morphTarget is named. + for ( const morphTargetName in morphTargetNames ) { + + const times = []; + const values = []; + + for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) { + + const animationKey = animationKeys[ k ]; + + times.push( animationKey.time ); + values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 ); + + } + + tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) ); + + } + + duration = morphTargetNames.length * fps; + + } else { + + // ...assume skeletal animation + + const boneName = '.bones[' + bones[ h ].name + ']'; + + addNonemptyTrack( + VectorKeyframeTrack, boneName + '.position', + animationKeys, 'pos', tracks ); + + addNonemptyTrack( + QuaternionKeyframeTrack, boneName + '.quaternion', + animationKeys, 'rot', tracks ); + + addNonemptyTrack( + VectorKeyframeTrack, boneName + '.scale', + animationKeys, 'scl', tracks ); + + } + + } + + if ( tracks.length === 0 ) { + + return null; + + } + + const clip = new this( clipName, duration, tracks, blendMode ); + + return clip; + + } + + resetDuration() { + + const tracks = this.tracks; + let duration = 0; + + for ( let i = 0, n = tracks.length; i !== n; ++ i ) { + + const track = this.tracks[ i ]; + + duration = Math.max( duration, track.times[ track.times.length - 1 ] ); + + } + + this.duration = duration; + + return this; + + } + + trim() { + + for ( let i = 0; i < this.tracks.length; i ++ ) { + + this.tracks[ i ].trim( 0, this.duration ); + + } + + return this; + + } + + validate() { + + let valid = true; + + for ( let i = 0; i < this.tracks.length; i ++ ) { + + valid = valid && this.tracks[ i ].validate(); + + } + + return valid; + + } + + optimize() { + + for ( let i = 0; i < this.tracks.length; i ++ ) { + + this.tracks[ i ].optimize(); + + } + + return this; + + } + + clone() { + + const tracks = []; + + for ( let i = 0; i < this.tracks.length; i ++ ) { + + tracks.push( this.tracks[ i ].clone() ); + + } + + return new this.constructor( this.name, this.duration, tracks, this.blendMode ); + + } + + toJSON() { + + return this.constructor.toJSON( this ); + + } + +} + +function getTrackTypeForValueTypeName( typeName ) { + + switch ( typeName.toLowerCase() ) { + + case 'scalar': + case 'double': + case 'float': + case 'number': + case 'integer': + + return NumberKeyframeTrack; + + case 'vector': + case 'vector2': + case 'vector3': + case 'vector4': + + return VectorKeyframeTrack; + + case 'color': + + return ColorKeyframeTrack; + + case 'quaternion': + + return QuaternionKeyframeTrack; + + case 'bool': + case 'boolean': + + return BooleanKeyframeTrack; + + case 'string': + + return StringKeyframeTrack; + + } + + throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName ); + +} + +function parseKeyframeTrack( json ) { + + if ( json.type === undefined ) { + + throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' ); + + } + + const trackType = getTrackTypeForValueTypeName( json.type ); + + if ( json.times === undefined ) { + + const times = [], values = []; + + flattenJSON( json.keys, times, values, 'value' ); + + json.times = times; + json.values = values; + + } + + // derived classes can define a static parse method + if ( trackType.parse !== undefined ) { + + return trackType.parse( json ); + + } else { + + // by default, we assume a constructor compatible with the base + return new trackType( json.name, json.times, json.values, json.interpolation ); + + } + +} + +const Cache = { + + enabled: false, + + files: {}, + + add: function ( key, file ) { + + if ( this.enabled === false ) return; + + // console.log( 'THREE.Cache', 'Adding key:', key ); + + this.files[ key ] = file; + + }, + + get: function ( key ) { + + if ( this.enabled === false ) return; + + // console.log( 'THREE.Cache', 'Checking key:', key ); + + return this.files[ key ]; + + }, + + remove: function ( key ) { + + delete this.files[ key ]; + + }, + + clear: function () { + + this.files = {}; + + } + +}; + +class LoadingManager { + + constructor( onLoad, onProgress, onError ) { + + const scope = this; + + let isLoading = false; + let itemsLoaded = 0; + let itemsTotal = 0; + let urlModifier = undefined; + const handlers = []; + + // Refer to #5689 for the reason why we don't set .onStart + // in the constructor + + this.onStart = undefined; + this.onLoad = onLoad; + this.onProgress = onProgress; + this.onError = onError; + + this.itemStart = function ( url ) { + + itemsTotal ++; + + if ( isLoading === false ) { + + if ( scope.onStart !== undefined ) { + + scope.onStart( url, itemsLoaded, itemsTotal ); + + } + + } + + isLoading = true; + + }; + + this.itemEnd = function ( url ) { + + itemsLoaded ++; + + if ( scope.onProgress !== undefined ) { + + scope.onProgress( url, itemsLoaded, itemsTotal ); + + } + + if ( itemsLoaded === itemsTotal ) { + + isLoading = false; + + if ( scope.onLoad !== undefined ) { + + scope.onLoad(); + + } + + } + + }; + + this.itemError = function ( url ) { + + if ( scope.onError !== undefined ) { + + scope.onError( url ); + + } + + }; + + this.resolveURL = function ( url ) { + + if ( urlModifier ) { + + return urlModifier( url ); + + } + + return url; + + }; + + this.setURLModifier = function ( transform ) { + + urlModifier = transform; + + return this; + + }; + + this.addHandler = function ( regex, loader ) { + + handlers.push( regex, loader ); + + return this; + + }; + + this.removeHandler = function ( regex ) { + + const index = handlers.indexOf( regex ); + + if ( index !== - 1 ) { + + handlers.splice( index, 2 ); + + } + + return this; + + }; + + this.getHandler = function ( file ) { + + for ( let i = 0, l = handlers.length; i < l; i += 2 ) { + + const regex = handlers[ i ]; + const loader = handlers[ i + 1 ]; + + if ( regex.global ) regex.lastIndex = 0; // see #17920 + + if ( regex.test( file ) ) { + + return loader; + + } + + } + + return null; + + }; + + } + +} + +const DefaultLoadingManager = /*@__PURE__*/ new LoadingManager(); + +class Loader { + + constructor( manager ) { + + this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager; + + this.crossOrigin = 'anonymous'; + this.withCredentials = false; + this.path = ''; + this.resourcePath = ''; + this.requestHeader = {}; + + } + + load( /* url, onLoad, onProgress, onError */ ) {} + + loadAsync( url, onProgress ) { + + const scope = this; + + return new Promise( function ( resolve, reject ) { + + scope.load( url, resolve, onProgress, reject ); + + } ); + + } + + parse( /* data */ ) {} + + setCrossOrigin( crossOrigin ) { + + this.crossOrigin = crossOrigin; + return this; + + } + + setWithCredentials( value ) { + + this.withCredentials = value; + return this; + + } + + setPath( path ) { + + this.path = path; + return this; + + } + + setResourcePath( resourcePath ) { + + this.resourcePath = resourcePath; + return this; + + } + + setRequestHeader( requestHeader ) { + + this.requestHeader = requestHeader; + return this; + + } + +} + +Loader.DEFAULT_MATERIAL_NAME = '__DEFAULT'; + +const loading = {}; + +class HttpError extends Error { + + constructor( message, response ) { + + super( message ); + this.response = response; + + } + +} + +class FileLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + if ( url === undefined ) url = ''; + + if ( this.path !== undefined ) url = this.path + url; + + url = this.manager.resolveURL( url ); + + const cached = Cache.get( url ); + + if ( cached !== undefined ) { + + this.manager.itemStart( url ); + + setTimeout( () => { + + if ( onLoad ) onLoad( cached ); + + this.manager.itemEnd( url ); + + }, 0 ); + + return cached; + + } + + // Check if request is duplicate + + if ( loading[ url ] !== undefined ) { + + loading[ url ].push( { + + onLoad: onLoad, + onProgress: onProgress, + onError: onError + + } ); + + return; + + } + + // Initialise array for duplicate requests + loading[ url ] = []; + + loading[ url ].push( { + onLoad: onLoad, + onProgress: onProgress, + onError: onError, + } ); + + // create request + const req = new Request( url, { + headers: new Headers( this.requestHeader ), + credentials: this.withCredentials ? 'include' : 'same-origin', + // An abort controller could be added within a future PR + } ); + + // record states ( avoid data race ) + const mimeType = this.mimeType; + const responseType = this.responseType; + + // start the fetch + fetch( req ) + .then( response => { + + if ( response.status === 200 || response.status === 0 ) { + + // Some browsers return HTTP Status 0 when using non-http protocol + // e.g. 'file://' or 'data://'. Handle as success. + + if ( response.status === 0 ) { + + console.warn( 'THREE.FileLoader: HTTP Status 0 received.' ); + + } + + // Workaround: Checking if response.body === undefined for Alipay browser #23548 + + if ( typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined ) { + + return response; + + } + + const callbacks = loading[ url ]; + const reader = response.body.getReader(); + + // Nginx needs X-File-Size check + // https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content + const contentLength = response.headers.get( 'X-File-Size' ) || response.headers.get( 'Content-Length' ); + const total = contentLength ? parseInt( contentLength ) : 0; + const lengthComputable = total !== 0; + let loaded = 0; + + // periodically read data into the new stream tracking while download progress + const stream = new ReadableStream( { + start( controller ) { + + readData(); + + function readData() { + + reader.read().then( ( { done, value } ) => { + + if ( done ) { + + controller.close(); + + } else { + + loaded += value.byteLength; + + const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } ); + for ( let i = 0, il = callbacks.length; i < il; i ++ ) { + + const callback = callbacks[ i ]; + if ( callback.onProgress ) callback.onProgress( event ); + + } + + controller.enqueue( value ); + readData(); + + } + + }, ( e ) => { + + controller.error( e ); + + } ); + + } + + } + + } ); + + return new Response( stream ); + + } else { + + throw new HttpError( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response ); + + } + + } ) + .then( response => { + + switch ( responseType ) { + + case 'arraybuffer': + + return response.arrayBuffer(); + + case 'blob': + + return response.blob(); + + case 'document': + + return response.text() + .then( text => { + + const parser = new DOMParser(); + return parser.parseFromString( text, mimeType ); + + } ); + + case 'json': + + return response.json(); + + default: + + if ( mimeType === undefined ) { + + return response.text(); + + } else { + + // sniff encoding + const re = /charset="?([^;"\s]*)"?/i; + const exec = re.exec( mimeType ); + const label = exec && exec[ 1 ] ? exec[ 1 ].toLowerCase() : undefined; + const decoder = new TextDecoder( label ); + return response.arrayBuffer().then( ab => decoder.decode( ab ) ); + + } + + } + + } ) + .then( data => { + + // Add to cache only on HTTP success, so that we do not cache + // error response bodies as proper responses to requests. + Cache.add( url, data ); + + const callbacks = loading[ url ]; + delete loading[ url ]; + + for ( let i = 0, il = callbacks.length; i < il; i ++ ) { + + const callback = callbacks[ i ]; + if ( callback.onLoad ) callback.onLoad( data ); + + } + + } ) + .catch( err => { + + // Abort errors and other errors are handled the same + + const callbacks = loading[ url ]; + + if ( callbacks === undefined ) { + + // When onLoad was called and url was deleted in `loading` + this.manager.itemError( url ); + throw err; + + } + + delete loading[ url ]; + + for ( let i = 0, il = callbacks.length; i < il; i ++ ) { + + const callback = callbacks[ i ]; + if ( callback.onError ) callback.onError( err ); + + } + + this.manager.itemError( url ); + + } ) + .finally( () => { + + this.manager.itemEnd( url ); + + } ); + + this.manager.itemStart( url ); + + } + + setResponseType( value ) { + + this.responseType = value; + return this; + + } + + setMimeType( value ) { + + this.mimeType = value; + return this; + + } + +} + +class AnimationLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + loader.load( url, function ( text ) { + + try { + + onLoad( scope.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + } + + parse( json ) { + + const animations = []; + + for ( let i = 0; i < json.length; i ++ ) { + + const clip = AnimationClip.parse( json[ i ] ); + + animations.push( clip ); + + } + + return animations; + + } + +} + +/** + * Abstract Base class to block based textures loader (dds, pvr, ...) + * + * Sub classes have to implement the parse() method which will be used in load(). + */ + +class CompressedTextureLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const images = []; + + const texture = new CompressedTexture(); + + const loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setResponseType( 'arraybuffer' ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( scope.withCredentials ); + + let loaded = 0; + + function loadTexture( i ) { + + loader.load( url[ i ], function ( buffer ) { + + const texDatas = scope.parse( buffer, true ); + + images[ i ] = { + width: texDatas.width, + height: texDatas.height, + format: texDatas.format, + mipmaps: texDatas.mipmaps + }; + + loaded += 1; + + if ( loaded === 6 ) { + + if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter; + + texture.image = images; + texture.format = texDatas.format; + texture.needsUpdate = true; + + if ( onLoad ) onLoad( texture ); + + } + + }, onProgress, onError ); + + } + + if ( Array.isArray( url ) ) { + + for ( let i = 0, il = url.length; i < il; ++ i ) { + + loadTexture( i ); + + } + + } else { + + // compressed cubemap texture stored in a single DDS file + + loader.load( url, function ( buffer ) { + + const texDatas = scope.parse( buffer, true ); + + if ( texDatas.isCubemap ) { + + const faces = texDatas.mipmaps.length / texDatas.mipmapCount; + + for ( let f = 0; f < faces; f ++ ) { + + images[ f ] = { mipmaps: [] }; + + for ( let i = 0; i < texDatas.mipmapCount; i ++ ) { + + images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] ); + images[ f ].format = texDatas.format; + images[ f ].width = texDatas.width; + images[ f ].height = texDatas.height; + + } + + } + + texture.image = images; + + } else { + + texture.image.width = texDatas.width; + texture.image.height = texDatas.height; + texture.mipmaps = texDatas.mipmaps; + + } + + if ( texDatas.mipmapCount === 1 ) { + + texture.minFilter = LinearFilter; + + } + + texture.format = texDatas.format; + texture.needsUpdate = true; + + if ( onLoad ) onLoad( texture ); + + }, onProgress, onError ); + + } + + return texture; + + } + +} + +class ImageLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + if ( this.path !== undefined ) url = this.path + url; + + url = this.manager.resolveURL( url ); + + const scope = this; + + const cached = Cache.get( url ); + + if ( cached !== undefined ) { + + scope.manager.itemStart( url ); + + setTimeout( function () { + + if ( onLoad ) onLoad( cached ); + + scope.manager.itemEnd( url ); + + }, 0 ); + + return cached; + + } + + const image = createElementNS( 'img' ); + + function onImageLoad() { + + removeEventListeners(); + + Cache.add( url, this ); + + if ( onLoad ) onLoad( this ); + + scope.manager.itemEnd( url ); + + } + + function onImageError( event ) { + + removeEventListeners(); + + if ( onError ) onError( event ); + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } + + function removeEventListeners() { + + image.removeEventListener( 'load', onImageLoad, false ); + image.removeEventListener( 'error', onImageError, false ); + + } + + image.addEventListener( 'load', onImageLoad, false ); + image.addEventListener( 'error', onImageError, false ); + + if ( url.slice( 0, 5 ) !== 'data:' ) { + + if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin; + + } + + scope.manager.itemStart( url ); + + image.src = url; + + return image; + + } + +} + +class CubeTextureLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( urls, onLoad, onProgress, onError ) { + + const texture = new CubeTexture(); + texture.colorSpace = SRGBColorSpace; + + const loader = new ImageLoader( this.manager ); + loader.setCrossOrigin( this.crossOrigin ); + loader.setPath( this.path ); + + let loaded = 0; + + function loadTexture( i ) { + + loader.load( urls[ i ], function ( image ) { + + texture.images[ i ] = image; + + loaded ++; + + if ( loaded === 6 ) { + + texture.needsUpdate = true; + + if ( onLoad ) onLoad( texture ); + + } + + }, undefined, onError ); + + } + + for ( let i = 0; i < urls.length; ++ i ) { + + loadTexture( i ); + + } + + return texture; + + } + +} + +/** + * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...) + * + * Sub classes have to implement the parse() method which will be used in load(). + */ + +class DataTextureLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const texture = new DataTexture(); + + const loader = new FileLoader( this.manager ); + loader.setResponseType( 'arraybuffer' ); + loader.setRequestHeader( this.requestHeader ); + loader.setPath( this.path ); + loader.setWithCredentials( scope.withCredentials ); + loader.load( url, function ( buffer ) { + + let texData; + + try { + + texData = scope.parse( buffer ); + + } catch ( error ) { + + if ( onError !== undefined ) { + + onError( error ); + + } else { + + console.error( error ); + return; + + } + + } + + if ( texData.image !== undefined ) { + + texture.image = texData.image; + + } else if ( texData.data !== undefined ) { + + texture.image.width = texData.width; + texture.image.height = texData.height; + texture.image.data = texData.data; + + } + + texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping; + texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping; + + texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter; + texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter; + + texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1; + + if ( texData.colorSpace !== undefined ) { + + texture.colorSpace = texData.colorSpace; + + } + + if ( texData.flipY !== undefined ) { + + texture.flipY = texData.flipY; + + } + + if ( texData.format !== undefined ) { + + texture.format = texData.format; + + } + + if ( texData.type !== undefined ) { + + texture.type = texData.type; + + } + + if ( texData.mipmaps !== undefined ) { + + texture.mipmaps = texData.mipmaps; + texture.minFilter = LinearMipmapLinearFilter; // presumably... + + } + + if ( texData.mipmapCount === 1 ) { + + texture.minFilter = LinearFilter; + + } + + if ( texData.generateMipmaps !== undefined ) { + + texture.generateMipmaps = texData.generateMipmaps; + + } + + texture.needsUpdate = true; + + if ( onLoad ) onLoad( texture, texData ); + + }, onProgress, onError ); + + + return texture; + + } + +} + +class TextureLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const texture = new Texture(); + + const loader = new ImageLoader( this.manager ); + loader.setCrossOrigin( this.crossOrigin ); + loader.setPath( this.path ); + + loader.load( url, function ( image ) { + + texture.image = image; + texture.needsUpdate = true; + + if ( onLoad !== undefined ) { + + onLoad( texture ); + + } + + }, onProgress, onError ); + + return texture; + + } + +} + +class Light extends Object3D { + + constructor( color, intensity = 1 ) { + + super(); + + this.isLight = true; + + this.type = 'Light'; + + this.color = new Color( color ); + this.intensity = intensity; + + } + + dispose() { + + // Empty here in base class; some subclasses override. + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.color.copy( source.color ); + this.intensity = source.intensity; + + return this; + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + data.object.color = this.color.getHex(); + data.object.intensity = this.intensity; + + if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex(); + + if ( this.distance !== undefined ) data.object.distance = this.distance; + if ( this.angle !== undefined ) data.object.angle = this.angle; + if ( this.decay !== undefined ) data.object.decay = this.decay; + if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra; + + if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON(); + if ( this.target !== undefined ) data.object.target = this.target.uuid; + + return data; + + } + +} + +class HemisphereLight extends Light { + + constructor( skyColor, groundColor, intensity ) { + + super( skyColor, intensity ); + + this.isHemisphereLight = true; + + this.type = 'HemisphereLight'; + + this.position.copy( Object3D.DEFAULT_UP ); + this.updateMatrix(); + + this.groundColor = new Color( groundColor ); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.groundColor.copy( source.groundColor ); + + return this; + + } + +} + +const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4(); +const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3(); +const _lookTarget$1 = /*@__PURE__*/ new Vector3(); + +class LightShadow { + + constructor( camera ) { + + this.camera = camera; + + this.intensity = 1; + + this.bias = 0; + this.normalBias = 0; + this.radius = 1; + this.blurSamples = 8; + + this.mapSize = new Vector2( 512, 512 ); + + this.map = null; + this.mapPass = null; + this.matrix = new Matrix4(); + + this.autoUpdate = true; + this.needsUpdate = false; + + this._frustum = new Frustum(); + this._frameExtents = new Vector2( 1, 1 ); + + this._viewportCount = 1; + + this._viewports = [ + + new Vector4( 0, 0, 1, 1 ) + + ]; + + } + + getViewportCount() { + + return this._viewportCount; + + } + + getFrustum() { + + return this._frustum; + + } + + updateMatrices( light ) { + + const shadowCamera = this.camera; + const shadowMatrix = this.matrix; + + _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld ); + shadowCamera.position.copy( _lightPositionWorld$1 ); + + _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld ); + shadowCamera.lookAt( _lookTarget$1 ); + shadowCamera.updateMatrixWorld(); + + _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse ); + this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 ); + + shadowMatrix.set( + 0.5, 0.0, 0.0, 0.5, + 0.0, 0.5, 0.0, 0.5, + 0.0, 0.0, 0.5, 0.5, + 0.0, 0.0, 0.0, 1.0 + ); + + shadowMatrix.multiply( _projScreenMatrix$1 ); + + } + + getViewport( viewportIndex ) { + + return this._viewports[ viewportIndex ]; + + } + + getFrameExtents() { + + return this._frameExtents; + + } + + dispose() { + + if ( this.map ) { + + this.map.dispose(); + + } + + if ( this.mapPass ) { + + this.mapPass.dispose(); + + } + + } + + copy( source ) { + + this.camera = source.camera.clone(); + + this.intensity = source.intensity; + + this.bias = source.bias; + this.radius = source.radius; + + this.mapSize.copy( source.mapSize ); + + return this; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + toJSON() { + + const object = {}; + + if ( this.intensity !== 1 ) object.intensity = this.intensity; + if ( this.bias !== 0 ) object.bias = this.bias; + if ( this.normalBias !== 0 ) object.normalBias = this.normalBias; + if ( this.radius !== 1 ) object.radius = this.radius; + if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray(); + + object.camera = this.camera.toJSON( false ).object; + delete object.camera.matrix; + + return object; + + } + +} + +class SpotLightShadow extends LightShadow { + + constructor() { + + super( new PerspectiveCamera( 50, 1, 0.5, 500 ) ); + + this.isSpotLightShadow = true; + + this.focus = 1; + + } + + updateMatrices( light ) { + + const camera = this.camera; + + const fov = RAD2DEG * 2 * light.angle * this.focus; + const aspect = this.mapSize.width / this.mapSize.height; + const far = light.distance || camera.far; + + if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) { + + camera.fov = fov; + camera.aspect = aspect; + camera.far = far; + camera.updateProjectionMatrix(); + + } + + super.updateMatrices( light ); + + } + + copy( source ) { + + super.copy( source ); + + this.focus = source.focus; + + return this; + + } + +} + +class SpotLight extends Light { + + constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) { + + super( color, intensity ); + + this.isSpotLight = true; + + this.type = 'SpotLight'; + + this.position.copy( Object3D.DEFAULT_UP ); + this.updateMatrix(); + + this.target = new Object3D(); + + this.distance = distance; + this.angle = angle; + this.penumbra = penumbra; + this.decay = decay; + + this.map = null; + + this.shadow = new SpotLightShadow(); + + } + + get power() { + + // compute the light's luminous power (in lumens) from its intensity (in candela) + // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd) + return this.intensity * Math.PI; + + } + + set power( power ) { + + // set the light's intensity (in candela) from the desired luminous power (in lumens) + this.intensity = power / Math.PI; + + } + + dispose() { + + this.shadow.dispose(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.distance = source.distance; + this.angle = source.angle; + this.penumbra = source.penumbra; + this.decay = source.decay; + + this.target = source.target.clone(); + + this.shadow = source.shadow.clone(); + + return this; + + } + +} + +const _projScreenMatrix = /*@__PURE__*/ new Matrix4(); +const _lightPositionWorld = /*@__PURE__*/ new Vector3(); +const _lookTarget = /*@__PURE__*/ new Vector3(); + +class PointLightShadow extends LightShadow { + + constructor() { + + super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + + this.isPointLightShadow = true; + + this._frameExtents = new Vector2( 4, 2 ); + + this._viewportCount = 6; + + this._viewports = [ + // These viewports map a cube-map onto a 2D texture with the + // following orientation: + // + // xzXZ + // y Y + // + // X - Positive x direction + // x - Negative x direction + // Y - Positive y direction + // y - Negative y direction + // Z - Positive z direction + // z - Negative z direction + + // positive X + new Vector4( 2, 1, 1, 1 ), + // negative X + new Vector4( 0, 1, 1, 1 ), + // positive Z + new Vector4( 3, 1, 1, 1 ), + // negative Z + new Vector4( 1, 1, 1, 1 ), + // positive Y + new Vector4( 3, 0, 1, 1 ), + // negative Y + new Vector4( 1, 0, 1, 1 ) + ]; + + this._cubeDirections = [ + new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ), + new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 ) + ]; + + this._cubeUps = [ + new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), + new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 ) + ]; + + } + + updateMatrices( light, viewportIndex = 0 ) { + + const camera = this.camera; + const shadowMatrix = this.matrix; + + const far = light.distance || camera.far; + + if ( far !== camera.far ) { + + camera.far = far; + camera.updateProjectionMatrix(); + + } + + _lightPositionWorld.setFromMatrixPosition( light.matrixWorld ); + camera.position.copy( _lightPositionWorld ); + + _lookTarget.copy( camera.position ); + _lookTarget.add( this._cubeDirections[ viewportIndex ] ); + camera.up.copy( this._cubeUps[ viewportIndex ] ); + camera.lookAt( _lookTarget ); + camera.updateMatrixWorld(); + + shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z ); + + _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); + this._frustum.setFromProjectionMatrix( _projScreenMatrix ); + + } + +} + +class PointLight extends Light { + + constructor( color, intensity, distance = 0, decay = 2 ) { + + super( color, intensity ); + + this.isPointLight = true; + + this.type = 'PointLight'; + + this.distance = distance; + this.decay = decay; + + this.shadow = new PointLightShadow(); + + } + + get power() { + + // compute the light's luminous power (in lumens) from its intensity (in candela) + // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd) + return this.intensity * 4 * Math.PI; + + } + + set power( power ) { + + // set the light's intensity (in candela) from the desired luminous power (in lumens) + this.intensity = power / ( 4 * Math.PI ); + + } + + dispose() { + + this.shadow.dispose(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.distance = source.distance; + this.decay = source.decay; + + this.shadow = source.shadow.clone(); + + return this; + + } + +} + +class OrthographicCamera extends Camera { + + constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) { + + super(); + + this.isOrthographicCamera = true; + + this.type = 'OrthographicCamera'; + + this.zoom = 1; + this.view = null; + + this.left = left; + this.right = right; + this.top = top; + this.bottom = bottom; + + this.near = near; + this.far = far; + + this.updateProjectionMatrix(); + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.left = source.left; + this.right = source.right; + this.top = source.top; + this.bottom = source.bottom; + this.near = source.near; + this.far = source.far; + + this.zoom = source.zoom; + this.view = source.view === null ? null : Object.assign( {}, source.view ); + + return this; + + } + + setViewOffset( fullWidth, fullHeight, x, y, width, height ) { + + if ( this.view === null ) { + + this.view = { + enabled: true, + fullWidth: 1, + fullHeight: 1, + offsetX: 0, + offsetY: 0, + width: 1, + height: 1 + }; + + } + + this.view.enabled = true; + this.view.fullWidth = fullWidth; + this.view.fullHeight = fullHeight; + this.view.offsetX = x; + this.view.offsetY = y; + this.view.width = width; + this.view.height = height; + + this.updateProjectionMatrix(); + + } + + clearViewOffset() { + + if ( this.view !== null ) { + + this.view.enabled = false; + + } + + this.updateProjectionMatrix(); + + } + + updateProjectionMatrix() { + + const dx = ( this.right - this.left ) / ( 2 * this.zoom ); + const dy = ( this.top - this.bottom ) / ( 2 * this.zoom ); + const cx = ( this.right + this.left ) / 2; + const cy = ( this.top + this.bottom ) / 2; + + let left = cx - dx; + let right = cx + dx; + let top = cy + dy; + let bottom = cy - dy; + + if ( this.view !== null && this.view.enabled ) { + + const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom; + const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom; + + left += scaleW * this.view.offsetX; + right = left + scaleW * this.view.width; + top -= scaleH * this.view.offsetY; + bottom = top - scaleH * this.view.height; + + } + + this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem ); + + this.projectionMatrixInverse.copy( this.projectionMatrix ).invert(); + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + data.object.zoom = this.zoom; + data.object.left = this.left; + data.object.right = this.right; + data.object.top = this.top; + data.object.bottom = this.bottom; + data.object.near = this.near; + data.object.far = this.far; + + if ( this.view !== null ) data.object.view = Object.assign( {}, this.view ); + + return data; + + } + +} + +class DirectionalLightShadow extends LightShadow { + + constructor() { + + super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); + + this.isDirectionalLightShadow = true; + + } + +} + +class DirectionalLight extends Light { + + constructor( color, intensity ) { + + super( color, intensity ); + + this.isDirectionalLight = true; + + this.type = 'DirectionalLight'; + + this.position.copy( Object3D.DEFAULT_UP ); + this.updateMatrix(); + + this.target = new Object3D(); + + this.shadow = new DirectionalLightShadow(); + + } + + dispose() { + + this.shadow.dispose(); + + } + + copy( source ) { + + super.copy( source ); + + this.target = source.target.clone(); + this.shadow = source.shadow.clone(); + + return this; + + } + +} + +class AmbientLight extends Light { + + constructor( color, intensity ) { + + super( color, intensity ); + + this.isAmbientLight = true; + + this.type = 'AmbientLight'; + + } + +} + +class RectAreaLight extends Light { + + constructor( color, intensity, width = 10, height = 10 ) { + + super( color, intensity ); + + this.isRectAreaLight = true; + + this.type = 'RectAreaLight'; + + this.width = width; + this.height = height; + + } + + get power() { + + // compute the light's luminous power (in lumens) from its intensity (in nits) + return this.intensity * this.width * this.height * Math.PI; + + } + + set power( power ) { + + // set the light's intensity (in nits) from the desired luminous power (in lumens) + this.intensity = power / ( this.width * this.height * Math.PI ); + + } + + copy( source ) { + + super.copy( source ); + + this.width = source.width; + this.height = source.height; + + return this; + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + data.object.width = this.width; + data.object.height = this.height; + + return data; + + } + +} + +/** + * Primary reference: + * https://graphics.stanford.edu/papers/envmap/envmap.pdf + * + * Secondary reference: + * https://www.ppsloan.org/publications/StupidSH36.pdf + */ + +// 3-band SH defined by 9 coefficients + +class SphericalHarmonics3 { + + constructor() { + + this.isSphericalHarmonics3 = true; + + this.coefficients = []; + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients.push( new Vector3() ); + + } + + } + + set( coefficients ) { + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].copy( coefficients[ i ] ); + + } + + return this; + + } + + zero() { + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].set( 0, 0, 0 ); + + } + + return this; + + } + + // get the radiance in the direction of the normal + // target is a Vector3 + getAt( normal, target ) { + + // normal is assumed to be unit length + + const x = normal.x, y = normal.y, z = normal.z; + + const coeff = this.coefficients; + + // band 0 + target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 ); + + // band 1 + target.addScaledVector( coeff[ 1 ], 0.488603 * y ); + target.addScaledVector( coeff[ 2 ], 0.488603 * z ); + target.addScaledVector( coeff[ 3 ], 0.488603 * x ); + + // band 2 + target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) ); + target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) ); + target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) ); + target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) ); + target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) ); + + return target; + + } + + // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal + // target is a Vector3 + // https://graphics.stanford.edu/papers/envmap/envmap.pdf + getIrradianceAt( normal, target ) { + + // normal is assumed to be unit length + + const x = normal.x, y = normal.y, z = normal.z; + + const coeff = this.coefficients; + + // band 0 + target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095 + + // band 1 + target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603 + target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z ); + target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x ); + + // band 2 + target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548 + target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z ); + target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3 + target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z ); + target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274 + + return target; + + } + + add( sh ) { + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].add( sh.coefficients[ i ] ); + + } + + return this; + + } + + addScaledSH( sh, s ) { + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s ); + + } + + return this; + + } + + scale( s ) { + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].multiplyScalar( s ); + + } + + return this; + + } + + lerp( sh, alpha ) { + + for ( let i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha ); + + } + + return this; + + } + + equals( sh ) { + + for ( let i = 0; i < 9; i ++ ) { + + if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) { + + return false; + + } + + } + + return true; + + } + + copy( sh ) { + + return this.set( sh.coefficients ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + fromArray( array, offset = 0 ) { + + const coefficients = this.coefficients; + + for ( let i = 0; i < 9; i ++ ) { + + coefficients[ i ].fromArray( array, offset + ( i * 3 ) ); + + } + + return this; + + } + + toArray( array = [], offset = 0 ) { + + const coefficients = this.coefficients; + + for ( let i = 0; i < 9; i ++ ) { + + coefficients[ i ].toArray( array, offset + ( i * 3 ) ); + + } + + return array; + + } + + // evaluate the basis functions + // shBasis is an Array[ 9 ] + static getBasisAt( normal, shBasis ) { + + // normal is assumed to be unit length + + const x = normal.x, y = normal.y, z = normal.z; + + // band 0 + shBasis[ 0 ] = 0.282095; + + // band 1 + shBasis[ 1 ] = 0.488603 * y; + shBasis[ 2 ] = 0.488603 * z; + shBasis[ 3 ] = 0.488603 * x; + + // band 2 + shBasis[ 4 ] = 1.092548 * x * y; + shBasis[ 5 ] = 1.092548 * y * z; + shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 ); + shBasis[ 7 ] = 1.092548 * x * z; + shBasis[ 8 ] = 0.546274 * ( x * x - y * y ); + + } + +} + +class LightProbe extends Light { + + constructor( sh = new SphericalHarmonics3(), intensity = 1 ) { + + super( undefined, intensity ); + + this.isLightProbe = true; + + this.sh = sh; + + } + + copy( source ) { + + super.copy( source ); + + this.sh.copy( source.sh ); + + return this; + + } + + fromJSON( json ) { + + this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON(); + this.sh.fromArray( json.sh ); + + return this; + + } + + toJSON( meta ) { + + const data = super.toJSON( meta ); + + data.object.sh = this.sh.toArray(); + + return data; + + } + +} + +class MaterialLoader extends Loader { + + constructor( manager ) { + + super( manager ); + this.textures = {}; + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const loader = new FileLoader( scope.manager ); + loader.setPath( scope.path ); + loader.setRequestHeader( scope.requestHeader ); + loader.setWithCredentials( scope.withCredentials ); + loader.load( url, function ( text ) { + + try { + + onLoad( scope.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + } + + parse( json ) { + + const textures = this.textures; + + function getTexture( name ) { + + if ( textures[ name ] === undefined ) { + + console.warn( 'THREE.MaterialLoader: Undefined texture', name ); + + } + + return textures[ name ]; + + } + + const material = this.createMaterialFromType( json.type ); + + if ( json.uuid !== undefined ) material.uuid = json.uuid; + if ( json.name !== undefined ) material.name = json.name; + if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color ); + if ( json.roughness !== undefined ) material.roughness = json.roughness; + if ( json.metalness !== undefined ) material.metalness = json.metalness; + if ( json.sheen !== undefined ) material.sheen = json.sheen; + if ( json.sheenColor !== undefined ) material.sheenColor = new Color().setHex( json.sheenColor ); + if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness; + if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive ); + if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular ); + if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity; + if ( json.specularColor !== undefined && material.specularColor !== undefined ) material.specularColor.setHex( json.specularColor ); + if ( json.shininess !== undefined ) material.shininess = json.shininess; + if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat; + if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness; + if ( json.dispersion !== undefined ) material.dispersion = json.dispersion; + if ( json.iridescence !== undefined ) material.iridescence = json.iridescence; + if ( json.iridescenceIOR !== undefined ) material.iridescenceIOR = json.iridescenceIOR; + if ( json.iridescenceThicknessRange !== undefined ) material.iridescenceThicknessRange = json.iridescenceThicknessRange; + if ( json.transmission !== undefined ) material.transmission = json.transmission; + if ( json.thickness !== undefined ) material.thickness = json.thickness; + if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance; + if ( json.attenuationColor !== undefined && material.attenuationColor !== undefined ) material.attenuationColor.setHex( json.attenuationColor ); + if ( json.anisotropy !== undefined ) material.anisotropy = json.anisotropy; + if ( json.anisotropyRotation !== undefined ) material.anisotropyRotation = json.anisotropyRotation; + if ( json.fog !== undefined ) material.fog = json.fog; + if ( json.flatShading !== undefined ) material.flatShading = json.flatShading; + if ( json.blending !== undefined ) material.blending = json.blending; + if ( json.combine !== undefined ) material.combine = json.combine; + if ( json.side !== undefined ) material.side = json.side; + if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide; + if ( json.opacity !== undefined ) material.opacity = json.opacity; + if ( json.transparent !== undefined ) material.transparent = json.transparent; + if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest; + if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash; + if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc; + if ( json.depthTest !== undefined ) material.depthTest = json.depthTest; + if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite; + if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite; + if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc; + if ( json.blendDst !== undefined ) material.blendDst = json.blendDst; + if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation; + if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha; + if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha; + if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha; + if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor ); + if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha; + if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask; + if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc; + if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef; + if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask; + if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail; + if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail; + if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass; + if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite; + + if ( json.wireframe !== undefined ) material.wireframe = json.wireframe; + if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth; + if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap; + if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin; + + if ( json.rotation !== undefined ) material.rotation = json.rotation; + + if ( json.linewidth !== undefined ) material.linewidth = json.linewidth; + if ( json.dashSize !== undefined ) material.dashSize = json.dashSize; + if ( json.gapSize !== undefined ) material.gapSize = json.gapSize; + if ( json.scale !== undefined ) material.scale = json.scale; + + if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset; + if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor; + if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits; + + if ( json.dithering !== undefined ) material.dithering = json.dithering; + + if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage; + if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha; + if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass; + + if ( json.visible !== undefined ) material.visible = json.visible; + + if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped; + + if ( json.userData !== undefined ) material.userData = json.userData; + + if ( json.vertexColors !== undefined ) { + + if ( typeof json.vertexColors === 'number' ) { + + material.vertexColors = ( json.vertexColors > 0 ) ? true : false; + + } else { + + material.vertexColors = json.vertexColors; + + } + + } + + // Shader Material + + if ( json.uniforms !== undefined ) { + + for ( const name in json.uniforms ) { + + const uniform = json.uniforms[ name ]; + + material.uniforms[ name ] = {}; + + switch ( uniform.type ) { + + case 't': + material.uniforms[ name ].value = getTexture( uniform.value ); + break; + + case 'c': + material.uniforms[ name ].value = new Color().setHex( uniform.value ); + break; + + case 'v2': + material.uniforms[ name ].value = new Vector2().fromArray( uniform.value ); + break; + + case 'v3': + material.uniforms[ name ].value = new Vector3().fromArray( uniform.value ); + break; + + case 'v4': + material.uniforms[ name ].value = new Vector4().fromArray( uniform.value ); + break; + + case 'm3': + material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value ); + break; + + case 'm4': + material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value ); + break; + + default: + material.uniforms[ name ].value = uniform.value; + + } + + } + + } + + if ( json.defines !== undefined ) material.defines = json.defines; + if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader; + if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader; + if ( json.glslVersion !== undefined ) material.glslVersion = json.glslVersion; + + if ( json.extensions !== undefined ) { + + for ( const key in json.extensions ) { + + material.extensions[ key ] = json.extensions[ key ]; + + } + + } + + if ( json.lights !== undefined ) material.lights = json.lights; + if ( json.clipping !== undefined ) material.clipping = json.clipping; + + // for PointsMaterial + + if ( json.size !== undefined ) material.size = json.size; + if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation; + + // maps + + if ( json.map !== undefined ) material.map = getTexture( json.map ); + if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap ); + + if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap ); + + if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap ); + if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale; + + if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap ); + if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType; + if ( json.normalScale !== undefined ) { + + let normalScale = json.normalScale; + + if ( Array.isArray( normalScale ) === false ) { + + // Blender exporter used to export a scalar. See #7459 + + normalScale = [ normalScale, normalScale ]; + + } + + material.normalScale = new Vector2().fromArray( normalScale ); + + } + + if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap ); + if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale; + if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias; + + if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap ); + if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap ); + + if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap ); + if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity; + + if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap ); + if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap ); + if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap ); + + if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap ); + if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation ); + if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity; + + if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity; + if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio; + + if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap ); + if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity; + + if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap ); + if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity; + + if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap ); + + if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap ); + if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap ); + if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap ); + if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale ); + + if ( json.iridescenceMap !== undefined ) material.iridescenceMap = getTexture( json.iridescenceMap ); + if ( json.iridescenceThicknessMap !== undefined ) material.iridescenceThicknessMap = getTexture( json.iridescenceThicknessMap ); + + if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap ); + if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap ); + + if ( json.anisotropyMap !== undefined ) material.anisotropyMap = getTexture( json.anisotropyMap ); + + if ( json.sheenColorMap !== undefined ) material.sheenColorMap = getTexture( json.sheenColorMap ); + if ( json.sheenRoughnessMap !== undefined ) material.sheenRoughnessMap = getTexture( json.sheenRoughnessMap ); + + return material; + + } + + setTextures( value ) { + + this.textures = value; + return this; + + } + + createMaterialFromType( type ) { + + return MaterialLoader.createMaterialFromType( type ); + + } + + static createMaterialFromType( type ) { + + const materialLib = { + ShadowMaterial, + SpriteMaterial, + RawShaderMaterial, + ShaderMaterial, + PointsMaterial, + MeshPhysicalMaterial, + MeshStandardMaterial, + MeshPhongMaterial, + MeshToonMaterial, + MeshNormalMaterial, + MeshLambertMaterial, + MeshDepthMaterial, + MeshDistanceMaterial, + MeshBasicMaterial, + MeshMatcapMaterial, + LineDashedMaterial, + LineBasicMaterial, + Material + }; + + return new materialLib[ type ](); + + } + +} + +class LoaderUtils { + + static decodeText( array ) { // @deprecated, r165 + + console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' ); + + if ( typeof TextDecoder !== 'undefined' ) { + + return new TextDecoder().decode( array ); + + } + + // Avoid the String.fromCharCode.apply(null, array) shortcut, which + // throws a "maximum call stack size exceeded" error for large arrays. + + let s = ''; + + for ( let i = 0, il = array.length; i < il; i ++ ) { + + // Implicitly assumes little-endian. + s += String.fromCharCode( array[ i ] ); + + } + + try { + + // merges multi-byte utf-8 characters. + + return decodeURIComponent( escape( s ) ); + + } catch ( e ) { // see #16358 + + return s; + + } + + } + + static extractUrlBase( url ) { + + const index = url.lastIndexOf( '/' ); + + if ( index === - 1 ) return './'; + + return url.slice( 0, index + 1 ); + + } + + static resolveURL( url, path ) { + + // Invalid URL + if ( typeof url !== 'string' || url === '' ) return ''; + + // Host Relative URL + if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) { + + path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' ); + + } + + // Absolute URL http://,https://,// + if ( /^(https?:)?\/\//i.test( url ) ) return url; + + // Data URI + if ( /^data:.*,.*$/i.test( url ) ) return url; + + // Blob URL + if ( /^blob:.*$/i.test( url ) ) return url; + + // Relative URL + return path + url; + + } + +} + +class InstancedBufferGeometry extends BufferGeometry { + + constructor() { + + super(); + + this.isInstancedBufferGeometry = true; + + this.type = 'InstancedBufferGeometry'; + this.instanceCount = Infinity; + + } + + copy( source ) { + + super.copy( source ); + + this.instanceCount = source.instanceCount; + + return this; + + } + + toJSON() { + + const data = super.toJSON(); + + data.instanceCount = this.instanceCount; + + data.isInstancedBufferGeometry = true; + + return data; + + } + +} + +class BufferGeometryLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const loader = new FileLoader( scope.manager ); + loader.setPath( scope.path ); + loader.setRequestHeader( scope.requestHeader ); + loader.setWithCredentials( scope.withCredentials ); + loader.load( url, function ( text ) { + + try { + + onLoad( scope.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + } + + parse( json ) { + + const interleavedBufferMap = {}; + const arrayBufferMap = {}; + + function getInterleavedBuffer( json, uuid ) { + + if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ]; + + const interleavedBuffers = json.interleavedBuffers; + const interleavedBuffer = interleavedBuffers[ uuid ]; + + const buffer = getArrayBuffer( json, interleavedBuffer.buffer ); + + const array = getTypedArray( interleavedBuffer.type, buffer ); + const ib = new InterleavedBuffer( array, interleavedBuffer.stride ); + ib.uuid = interleavedBuffer.uuid; + + interleavedBufferMap[ uuid ] = ib; + + return ib; + + } + + function getArrayBuffer( json, uuid ) { + + if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ]; + + const arrayBuffers = json.arrayBuffers; + const arrayBuffer = arrayBuffers[ uuid ]; + + const ab = new Uint32Array( arrayBuffer ).buffer; + + arrayBufferMap[ uuid ] = ab; + + return ab; + + } + + const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry(); + + const index = json.data.index; + + if ( index !== undefined ) { + + const typedArray = getTypedArray( index.type, index.array ); + geometry.setIndex( new BufferAttribute( typedArray, 1 ) ); + + } + + const attributes = json.data.attributes; + + for ( const key in attributes ) { + + const attribute = attributes[ key ]; + let bufferAttribute; + + if ( attribute.isInterleavedBufferAttribute ) { + + const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data ); + bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized ); + + } else { + + const typedArray = getTypedArray( attribute.type, attribute.array ); + const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute; + bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized ); + + } + + if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name; + if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage ); + + geometry.setAttribute( key, bufferAttribute ); + + } + + const morphAttributes = json.data.morphAttributes; + + if ( morphAttributes ) { + + for ( const key in morphAttributes ) { + + const attributeArray = morphAttributes[ key ]; + + const array = []; + + for ( let i = 0, il = attributeArray.length; i < il; i ++ ) { + + const attribute = attributeArray[ i ]; + let bufferAttribute; + + if ( attribute.isInterleavedBufferAttribute ) { + + const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data ); + bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized ); + + } else { + + const typedArray = getTypedArray( attribute.type, attribute.array ); + bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ); + + } + + if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name; + array.push( bufferAttribute ); + + } + + geometry.morphAttributes[ key ] = array; + + } + + } + + const morphTargetsRelative = json.data.morphTargetsRelative; + + if ( morphTargetsRelative ) { + + geometry.morphTargetsRelative = true; + + } + + const groups = json.data.groups || json.data.drawcalls || json.data.offsets; + + if ( groups !== undefined ) { + + for ( let i = 0, n = groups.length; i !== n; ++ i ) { + + const group = groups[ i ]; + + geometry.addGroup( group.start, group.count, group.materialIndex ); + + } + + } + + const boundingSphere = json.data.boundingSphere; + + if ( boundingSphere !== undefined ) { + + const center = new Vector3(); + + if ( boundingSphere.center !== undefined ) { + + center.fromArray( boundingSphere.center ); + + } + + geometry.boundingSphere = new Sphere( center, boundingSphere.radius ); + + } + + if ( json.name ) geometry.name = json.name; + if ( json.userData ) geometry.userData = json.userData; + + return geometry; + + } + +} + +class ObjectLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path; + this.resourcePath = this.resourcePath || path; + + const loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + loader.load( url, function ( text ) { + + let json = null; + + try { + + json = JSON.parse( text ); + + } catch ( error ) { + + if ( onError !== undefined ) onError( error ); + + console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message ); + + return; + + } + + const metadata = json.metadata; + + if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) { + + if ( onError !== undefined ) onError( new Error( 'THREE.ObjectLoader: Can\'t load ' + url ) ); + + console.error( 'THREE.ObjectLoader: Can\'t load ' + url ); + return; + + } + + scope.parse( json, onLoad ); + + }, onProgress, onError ); + + } + + async loadAsync( url, onProgress ) { + + const scope = this; + + const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path; + this.resourcePath = this.resourcePath || path; + + const loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + + const text = await loader.loadAsync( url, onProgress ); + + const json = JSON.parse( text ); + + const metadata = json.metadata; + + if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) { + + throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url ); + + } + + return await scope.parseAsync( json ); + + } + + parse( json, onLoad ) { + + const animations = this.parseAnimations( json.animations ); + const shapes = this.parseShapes( json.shapes ); + const geometries = this.parseGeometries( json.geometries, shapes ); + + const images = this.parseImages( json.images, function () { + + if ( onLoad !== undefined ) onLoad( object ); + + } ); + + const textures = this.parseTextures( json.textures, images ); + const materials = this.parseMaterials( json.materials, textures ); + + const object = this.parseObject( json.object, geometries, materials, textures, animations ); + const skeletons = this.parseSkeletons( json.skeletons, object ); + + this.bindSkeletons( object, skeletons ); + this.bindLightTargets( object ); + + // + + if ( onLoad !== undefined ) { + + let hasImages = false; + + for ( const uuid in images ) { + + if ( images[ uuid ].data instanceof HTMLImageElement ) { + + hasImages = true; + break; + + } + + } + + if ( hasImages === false ) onLoad( object ); + + } + + return object; + + } + + async parseAsync( json ) { + + const animations = this.parseAnimations( json.animations ); + const shapes = this.parseShapes( json.shapes ); + const geometries = this.parseGeometries( json.geometries, shapes ); + + const images = await this.parseImagesAsync( json.images ); + + const textures = this.parseTextures( json.textures, images ); + const materials = this.parseMaterials( json.materials, textures ); + + const object = this.parseObject( json.object, geometries, materials, textures, animations ); + const skeletons = this.parseSkeletons( json.skeletons, object ); + + this.bindSkeletons( object, skeletons ); + this.bindLightTargets( object ); + + return object; + + } + + parseShapes( json ) { + + const shapes = {}; + + if ( json !== undefined ) { + + for ( let i = 0, l = json.length; i < l; i ++ ) { + + const shape = new Shape().fromJSON( json[ i ] ); + + shapes[ shape.uuid ] = shape; + + } + + } + + return shapes; + + } + + parseSkeletons( json, object ) { + + const skeletons = {}; + const bones = {}; + + // generate bone lookup table + + object.traverse( function ( child ) { + + if ( child.isBone ) bones[ child.uuid ] = child; + + } ); + + // create skeletons + + if ( json !== undefined ) { + + for ( let i = 0, l = json.length; i < l; i ++ ) { + + const skeleton = new Skeleton().fromJSON( json[ i ], bones ); + + skeletons[ skeleton.uuid ] = skeleton; + + } + + } + + return skeletons; + + } + + parseGeometries( json, shapes ) { + + const geometries = {}; + + if ( json !== undefined ) { + + const bufferGeometryLoader = new BufferGeometryLoader(); + + for ( let i = 0, l = json.length; i < l; i ++ ) { + + let geometry; + const data = json[ i ]; + + switch ( data.type ) { + + case 'BufferGeometry': + case 'InstancedBufferGeometry': + + geometry = bufferGeometryLoader.parse( data ); + break; + + default: + + if ( data.type in Geometries ) { + + geometry = Geometries[ data.type ].fromJSON( data, shapes ); + + } else { + + console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` ); + + } + + } + + geometry.uuid = data.uuid; + + if ( data.name !== undefined ) geometry.name = data.name; + if ( data.userData !== undefined ) geometry.userData = data.userData; + + geometries[ data.uuid ] = geometry; + + } + + } + + return geometries; + + } + + parseMaterials( json, textures ) { + + const cache = {}; // MultiMaterial + const materials = {}; + + if ( json !== undefined ) { + + const loader = new MaterialLoader(); + loader.setTextures( textures ); + + for ( let i = 0, l = json.length; i < l; i ++ ) { + + const data = json[ i ]; + + if ( cache[ data.uuid ] === undefined ) { + + cache[ data.uuid ] = loader.parse( data ); + + } + + materials[ data.uuid ] = cache[ data.uuid ]; + + } + + } + + return materials; + + } + + parseAnimations( json ) { + + const animations = {}; + + if ( json !== undefined ) { + + for ( let i = 0; i < json.length; i ++ ) { + + const data = json[ i ]; + + const clip = AnimationClip.parse( data ); + + animations[ clip.uuid ] = clip; + + } + + } + + return animations; + + } + + parseImages( json, onLoad ) { + + const scope = this; + const images = {}; + + let loader; + + function loadImage( url ) { + + scope.manager.itemStart( url ); + + return loader.load( url, function () { + + scope.manager.itemEnd( url ); + + }, undefined, function () { + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } ); + + } + + function deserializeImage( image ) { + + if ( typeof image === 'string' ) { + + const url = image; + + const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url; + + return loadImage( path ); + + } else { + + if ( image.data ) { + + return { + data: getTypedArray( image.type, image.data ), + width: image.width, + height: image.height + }; + + } else { + + return null; + + } + + } + + } + + if ( json !== undefined && json.length > 0 ) { + + const manager = new LoadingManager( onLoad ); + + loader = new ImageLoader( manager ); + loader.setCrossOrigin( this.crossOrigin ); + + for ( let i = 0, il = json.length; i < il; i ++ ) { + + const image = json[ i ]; + const url = image.url; + + if ( Array.isArray( url ) ) { + + // load array of images e.g CubeTexture + + const imageArray = []; + + for ( let j = 0, jl = url.length; j < jl; j ++ ) { + + const currentUrl = url[ j ]; + + const deserializedImage = deserializeImage( currentUrl ); + + if ( deserializedImage !== null ) { + + if ( deserializedImage instanceof HTMLImageElement ) { + + imageArray.push( deserializedImage ); + + } else { + + // special case: handle array of data textures for cube textures + + imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) ); + + } + + } + + } + + images[ image.uuid ] = new Source( imageArray ); + + } else { + + // load single image + + const deserializedImage = deserializeImage( image.url ); + images[ image.uuid ] = new Source( deserializedImage ); + + + } + + } + + } + + return images; + + } + + async parseImagesAsync( json ) { + + const scope = this; + const images = {}; + + let loader; + + async function deserializeImage( image ) { + + if ( typeof image === 'string' ) { + + const url = image; + + const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url; + + return await loader.loadAsync( path ); + + } else { + + if ( image.data ) { + + return { + data: getTypedArray( image.type, image.data ), + width: image.width, + height: image.height + }; + + } else { + + return null; + + } + + } + + } + + if ( json !== undefined && json.length > 0 ) { + + loader = new ImageLoader( this.manager ); + loader.setCrossOrigin( this.crossOrigin ); + + for ( let i = 0, il = json.length; i < il; i ++ ) { + + const image = json[ i ]; + const url = image.url; + + if ( Array.isArray( url ) ) { + + // load array of images e.g CubeTexture + + const imageArray = []; + + for ( let j = 0, jl = url.length; j < jl; j ++ ) { + + const currentUrl = url[ j ]; + + const deserializedImage = await deserializeImage( currentUrl ); + + if ( deserializedImage !== null ) { + + if ( deserializedImage instanceof HTMLImageElement ) { + + imageArray.push( deserializedImage ); + + } else { + + // special case: handle array of data textures for cube textures + + imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) ); + + } + + } + + } + + images[ image.uuid ] = new Source( imageArray ); + + } else { + + // load single image + + const deserializedImage = await deserializeImage( image.url ); + images[ image.uuid ] = new Source( deserializedImage ); + + } + + } + + } + + return images; + + } + + parseTextures( json, images ) { + + function parseConstant( value, type ) { + + if ( typeof value === 'number' ) return value; + + console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value ); + + return type[ value ]; + + } + + const textures = {}; + + if ( json !== undefined ) { + + for ( let i = 0, l = json.length; i < l; i ++ ) { + + const data = json[ i ]; + + if ( data.image === undefined ) { + + console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid ); + + } + + if ( images[ data.image ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined image', data.image ); + + } + + const source = images[ data.image ]; + const image = source.data; + + let texture; + + if ( Array.isArray( image ) ) { + + texture = new CubeTexture(); + + if ( image.length === 6 ) texture.needsUpdate = true; + + } else { + + if ( image && image.data ) { + + texture = new DataTexture(); + + } else { + + texture = new Texture(); + + } + + if ( image ) texture.needsUpdate = true; // textures can have undefined image data + + } + + texture.source = source; + + texture.uuid = data.uuid; + + if ( data.name !== undefined ) texture.name = data.name; + + if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING ); + if ( data.channel !== undefined ) texture.channel = data.channel; + + if ( data.offset !== undefined ) texture.offset.fromArray( data.offset ); + if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat ); + if ( data.center !== undefined ) texture.center.fromArray( data.center ); + if ( data.rotation !== undefined ) texture.rotation = data.rotation; + + if ( data.wrap !== undefined ) { + + texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING ); + texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING ); + + } + + if ( data.format !== undefined ) texture.format = data.format; + if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat; + if ( data.type !== undefined ) texture.type = data.type; + if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace; + + if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); + if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); + if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy; + + if ( data.flipY !== undefined ) texture.flipY = data.flipY; + + if ( data.generateMipmaps !== undefined ) texture.generateMipmaps = data.generateMipmaps; + if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha; + if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment; + if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction; + + if ( data.userData !== undefined ) texture.userData = data.userData; + + textures[ data.uuid ] = texture; + + } + + } + + return textures; + + } + + parseObject( data, geometries, materials, textures, animations ) { + + let object; + + function getGeometry( name ) { + + if ( geometries[ name ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined geometry', name ); + + } + + return geometries[ name ]; + + } + + function getMaterial( name ) { + + if ( name === undefined ) return undefined; + + if ( Array.isArray( name ) ) { + + const array = []; + + for ( let i = 0, l = name.length; i < l; i ++ ) { + + const uuid = name[ i ]; + + if ( materials[ uuid ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined material', uuid ); + + } + + array.push( materials[ uuid ] ); + + } + + return array; + + } + + if ( materials[ name ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined material', name ); + + } + + return materials[ name ]; + + } + + function getTexture( uuid ) { + + if ( textures[ uuid ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined texture', uuid ); + + } + + return textures[ uuid ]; + + } + + let geometry, material; + + switch ( data.type ) { + + case 'Scene': + + object = new Scene(); + + if ( data.background !== undefined ) { + + if ( Number.isInteger( data.background ) ) { + + object.background = new Color( data.background ); + + } else { + + object.background = getTexture( data.background ); + + } + + } + + if ( data.environment !== undefined ) { + + object.environment = getTexture( data.environment ); + + } + + if ( data.fog !== undefined ) { + + if ( data.fog.type === 'Fog' ) { + + object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far ); + + } else if ( data.fog.type === 'FogExp2' ) { + + object.fog = new FogExp2( data.fog.color, data.fog.density ); + + } + + if ( data.fog.name !== '' ) { + + object.fog.name = data.fog.name; + + } + + } + + if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness; + if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity; + if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation ); + + if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity; + if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation ); + + break; + + case 'PerspectiveCamera': + + object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far ); + + if ( data.focus !== undefined ) object.focus = data.focus; + if ( data.zoom !== undefined ) object.zoom = data.zoom; + if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge; + if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset; + if ( data.view !== undefined ) object.view = Object.assign( {}, data.view ); + + break; + + case 'OrthographicCamera': + + object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far ); + + if ( data.zoom !== undefined ) object.zoom = data.zoom; + if ( data.view !== undefined ) object.view = Object.assign( {}, data.view ); + + break; + + case 'AmbientLight': + + object = new AmbientLight( data.color, data.intensity ); + + break; + + case 'DirectionalLight': + + object = new DirectionalLight( data.color, data.intensity ); + object.target = data.target || ''; + + break; + + case 'PointLight': + + object = new PointLight( data.color, data.intensity, data.distance, data.decay ); + + break; + + case 'RectAreaLight': + + object = new RectAreaLight( data.color, data.intensity, data.width, data.height ); + + break; + + case 'SpotLight': + + object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay ); + object.target = data.target || ''; + + break; + + case 'HemisphereLight': + + object = new HemisphereLight( data.color, data.groundColor, data.intensity ); + + break; + + case 'LightProbe': + + object = new LightProbe().fromJSON( data ); + + break; + + case 'SkinnedMesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + + object = new SkinnedMesh( geometry, material ); + + if ( data.bindMode !== undefined ) object.bindMode = data.bindMode; + if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix ); + if ( data.skeleton !== undefined ) object.skeleton = data.skeleton; + + break; + + case 'Mesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + + object = new Mesh( geometry, material ); + + break; + + case 'InstancedMesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + const count = data.count; + const instanceMatrix = data.instanceMatrix; + const instanceColor = data.instanceColor; + + object = new InstancedMesh( geometry, material, count ); + object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 ); + if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize ); + + break; + + case 'BatchedMesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + + object = new BatchedMesh( data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material ); + object.geometry = geometry; + object.perObjectFrustumCulled = data.perObjectFrustumCulled; + object.sortObjects = data.sortObjects; + + object._drawRanges = data.drawRanges; + object._reservedRanges = data.reservedRanges; + + object._visibility = data.visibility; + object._active = data.active; + object._bounds = data.bounds.map( bound => { + + const box = new Box3(); + box.min.fromArray( bound.boxMin ); + box.max.fromArray( bound.boxMax ); + + const sphere = new Sphere(); + sphere.radius = bound.sphereRadius; + sphere.center.fromArray( bound.sphereCenter ); + + return { + boxInitialized: bound.boxInitialized, + box: box, + + sphereInitialized: bound.sphereInitialized, + sphere: sphere + }; + + } ); + + object._maxInstanceCount = data.maxInstanceCount; + object._maxVertexCount = data.maxVertexCount; + object._maxIndexCount = data.maxIndexCount; + + object._geometryInitialized = data.geometryInitialized; + object._geometryCount = data.geometryCount; + + object._matricesTexture = getTexture( data.matricesTexture.uuid ); + if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid ); + + break; + + case 'LOD': + + object = new LOD(); + + break; + + case 'Line': + + object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'LineLoop': + + object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'LineSegments': + + object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'PointCloud': + case 'Points': + + object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'Sprite': + + object = new Sprite( getMaterial( data.material ) ); + + break; + + case 'Group': + + object = new Group(); + + break; + + case 'Bone': + + object = new Bone(); + + break; + + default: + + object = new Object3D(); + + } + + object.uuid = data.uuid; + + if ( data.name !== undefined ) object.name = data.name; + + if ( data.matrix !== undefined ) { + + object.matrix.fromArray( data.matrix ); + + if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate; + if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale ); + + } else { + + if ( data.position !== undefined ) object.position.fromArray( data.position ); + if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation ); + if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion ); + if ( data.scale !== undefined ) object.scale.fromArray( data.scale ); + + } + + if ( data.up !== undefined ) object.up.fromArray( data.up ); + + if ( data.castShadow !== undefined ) object.castShadow = data.castShadow; + if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow; + + if ( data.shadow ) { + + if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity; + if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias; + if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias; + if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius; + if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize ); + if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera ); + + } + + if ( data.visible !== undefined ) object.visible = data.visible; + if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled; + if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder; + if ( data.userData !== undefined ) object.userData = data.userData; + if ( data.layers !== undefined ) object.layers.mask = data.layers; + + if ( data.children !== undefined ) { + + const children = data.children; + + for ( let i = 0; i < children.length; i ++ ) { + + object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) ); + + } + + } + + if ( data.animations !== undefined ) { + + const objectAnimations = data.animations; + + for ( let i = 0; i < objectAnimations.length; i ++ ) { + + const uuid = objectAnimations[ i ]; + + object.animations.push( animations[ uuid ] ); + + } + + } + + if ( data.type === 'LOD' ) { + + if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate; + + const levels = data.levels; + + for ( let l = 0; l < levels.length; l ++ ) { + + const level = levels[ l ]; + const child = object.getObjectByProperty( 'uuid', level.object ); + + if ( child !== undefined ) { + + object.addLevel( child, level.distance, level.hysteresis ); + + } + + } + + } + + return object; + + } + + bindSkeletons( object, skeletons ) { + + if ( Object.keys( skeletons ).length === 0 ) return; + + object.traverse( function ( child ) { + + if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) { + + const skeleton = skeletons[ child.skeleton ]; + + if ( skeleton === undefined ) { + + console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton ); + + } else { + + child.bind( skeleton, child.bindMatrix ); + + } + + } + + } ); + + } + + bindLightTargets( object ) { + + object.traverse( function ( child ) { + + if ( child.isDirectionalLight || child.isSpotLight ) { + + const uuid = child.target; + + const target = object.getObjectByProperty( 'uuid', uuid ); + + if ( target !== undefined ) { + + child.target = target; + + } else { + + child.target = new Object3D(); + + } + + } + + } ); + + } + +} + +const TEXTURE_MAPPING = { + UVMapping: UVMapping, + CubeReflectionMapping: CubeReflectionMapping, + CubeRefractionMapping: CubeRefractionMapping, + EquirectangularReflectionMapping: EquirectangularReflectionMapping, + EquirectangularRefractionMapping: EquirectangularRefractionMapping, + CubeUVReflectionMapping: CubeUVReflectionMapping +}; + +const TEXTURE_WRAPPING = { + RepeatWrapping: RepeatWrapping, + ClampToEdgeWrapping: ClampToEdgeWrapping, + MirroredRepeatWrapping: MirroredRepeatWrapping +}; + +const TEXTURE_FILTER = { + NearestFilter: NearestFilter, + NearestMipmapNearestFilter: NearestMipmapNearestFilter, + NearestMipmapLinearFilter: NearestMipmapLinearFilter, + LinearFilter: LinearFilter, + LinearMipmapNearestFilter: LinearMipmapNearestFilter, + LinearMipmapLinearFilter: LinearMipmapLinearFilter +}; + +class ImageBitmapLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.isImageBitmapLoader = true; + + if ( typeof createImageBitmap === 'undefined' ) { + + console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' ); + + } + + if ( typeof fetch === 'undefined' ) { + + console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' ); + + } + + this.options = { premultiplyAlpha: 'none' }; + + } + + setOptions( options ) { + + this.options = options; + + return this; + + } + + load( url, onLoad, onProgress, onError ) { + + if ( url === undefined ) url = ''; + + if ( this.path !== undefined ) url = this.path + url; + + url = this.manager.resolveURL( url ); + + const scope = this; + + const cached = Cache.get( url ); + + if ( cached !== undefined ) { + + scope.manager.itemStart( url ); + + // If cached is a promise, wait for it to resolve + if ( cached.then ) { + + cached.then( imageBitmap => { + + if ( onLoad ) onLoad( imageBitmap ); + + scope.manager.itemEnd( url ); + + } ).catch( e => { + + if ( onError ) onError( e ); + + } ); + return; + + } + + // If cached is not a promise (i.e., it's already an imageBitmap) + setTimeout( function () { + + if ( onLoad ) onLoad( cached ); + + scope.manager.itemEnd( url ); + + }, 0 ); + + return cached; + + } + + const fetchOptions = {}; + fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include'; + fetchOptions.headers = this.requestHeader; + + const promise = fetch( url, fetchOptions ).then( function ( res ) { + + return res.blob(); + + } ).then( function ( blob ) { + + return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) ); + + } ).then( function ( imageBitmap ) { + + Cache.add( url, imageBitmap ); + + if ( onLoad ) onLoad( imageBitmap ); + + scope.manager.itemEnd( url ); + + return imageBitmap; + + } ).catch( function ( e ) { + + if ( onError ) onError( e ); + + Cache.remove( url ); + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } ); + + Cache.add( url, promise ); + scope.manager.itemStart( url ); + + } + +} + +let _context; + +class AudioContext { + + static getContext() { + + if ( _context === undefined ) { + + _context = new ( window.AudioContext || window.webkitAudioContext )(); + + } + + return _context; + + } + + static setContext( value ) { + + _context = value; + + } + +} + +class AudioLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + const loader = new FileLoader( this.manager ); + loader.setResponseType( 'arraybuffer' ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + loader.load( url, function ( buffer ) { + + try { + + // Create a copy of the buffer. The `decodeAudioData` method + // detaches the buffer when complete, preventing reuse. + const bufferCopy = buffer.slice( 0 ); + + const context = AudioContext.getContext(); + context.decodeAudioData( bufferCopy, function ( audioBuffer ) { + + onLoad( audioBuffer ); + + } ).catch( handleError ); + + } catch ( e ) { + + handleError( e ); + + } + + }, onProgress, onError ); + + function handleError( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + } + +} + +const _eyeRight = /*@__PURE__*/ new Matrix4(); +const _eyeLeft = /*@__PURE__*/ new Matrix4(); +const _projectionMatrix = /*@__PURE__*/ new Matrix4(); + +class StereoCamera { + + constructor() { + + this.type = 'StereoCamera'; + + this.aspect = 1; + + this.eyeSep = 0.064; + + this.cameraL = new PerspectiveCamera(); + this.cameraL.layers.enable( 1 ); + this.cameraL.matrixAutoUpdate = false; + + this.cameraR = new PerspectiveCamera(); + this.cameraR.layers.enable( 2 ); + this.cameraR.matrixAutoUpdate = false; + + this._cache = { + focus: null, + fov: null, + aspect: null, + near: null, + far: null, + zoom: null, + eyeSep: null + }; + + } + + update( camera ) { + + const cache = this._cache; + + const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov || + cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near || + cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep; + + if ( needsUpdate ) { + + cache.focus = camera.focus; + cache.fov = camera.fov; + cache.aspect = camera.aspect * this.aspect; + cache.near = camera.near; + cache.far = camera.far; + cache.zoom = camera.zoom; + cache.eyeSep = this.eyeSep; + + // Off-axis stereoscopic effect based on + // http://paulbourke.net/stereographics/stereorender/ + + _projectionMatrix.copy( camera.projectionMatrix ); + const eyeSepHalf = cache.eyeSep / 2; + const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus; + const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom; + let xmin, xmax; + + // translate xOffset + + _eyeLeft.elements[ 12 ] = - eyeSepHalf; + _eyeRight.elements[ 12 ] = eyeSepHalf; + + // for left eye + + xmin = - ymax * cache.aspect + eyeSepOnProjection; + xmax = ymax * cache.aspect + eyeSepOnProjection; + + _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); + _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); + + this.cameraL.projectionMatrix.copy( _projectionMatrix ); + + // for right eye + + xmin = - ymax * cache.aspect - eyeSepOnProjection; + xmax = ymax * cache.aspect - eyeSepOnProjection; + + _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); + _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); + + this.cameraR.projectionMatrix.copy( _projectionMatrix ); + + } + + this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft ); + this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight ); + + } + +} + +class ArrayCamera extends PerspectiveCamera { + + constructor( array = [] ) { + + super(); + + this.isArrayCamera = true; + + this.cameras = array; + + } + +} + +class Clock { + + constructor( autoStart = true ) { + + this.autoStart = autoStart; + + this.startTime = 0; + this.oldTime = 0; + this.elapsedTime = 0; + + this.running = false; + + } + + start() { + + this.startTime = now(); + + this.oldTime = this.startTime; + this.elapsedTime = 0; + this.running = true; + + } + + stop() { + + this.getElapsedTime(); + this.running = false; + this.autoStart = false; + + } + + getElapsedTime() { + + this.getDelta(); + return this.elapsedTime; + + } + + getDelta() { + + let diff = 0; + + if ( this.autoStart && ! this.running ) { + + this.start(); + return 0; + + } + + if ( this.running ) { + + const newTime = now(); + + diff = ( newTime - this.oldTime ) / 1000; + this.oldTime = newTime; + + this.elapsedTime += diff; + + } + + return diff; + + } + +} + +function now() { + + return performance.now(); + +} + +const _position$1 = /*@__PURE__*/ new Vector3(); +const _quaternion$1 = /*@__PURE__*/ new Quaternion(); +const _scale$1 = /*@__PURE__*/ new Vector3(); +const _orientation$1 = /*@__PURE__*/ new Vector3(); + +class AudioListener extends Object3D { + + constructor() { + + super(); + + this.type = 'AudioListener'; + + this.context = AudioContext.getContext(); + + this.gain = this.context.createGain(); + this.gain.connect( this.context.destination ); + + this.filter = null; + + this.timeDelta = 0; + + // private + + this._clock = new Clock(); + + } + + getInput() { + + return this.gain; + + } + + removeFilter() { + + if ( this.filter !== null ) { + + this.gain.disconnect( this.filter ); + this.filter.disconnect( this.context.destination ); + this.gain.connect( this.context.destination ); + this.filter = null; + + } + + return this; + + } + + getFilter() { + + return this.filter; + + } + + setFilter( value ) { + + if ( this.filter !== null ) { + + this.gain.disconnect( this.filter ); + this.filter.disconnect( this.context.destination ); + + } else { + + this.gain.disconnect( this.context.destination ); + + } + + this.filter = value; + this.gain.connect( this.filter ); + this.filter.connect( this.context.destination ); + + return this; + + } + + getMasterVolume() { + + return this.gain.gain.value; + + } + + setMasterVolume( value ) { + + this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 ); + + return this; + + } + + updateMatrixWorld( force ) { + + super.updateMatrixWorld( force ); + + const listener = this.context.listener; + const up = this.up; + + this.timeDelta = this._clock.getDelta(); + + this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 ); + + _orientation$1.set( 0, 0, - 1 ).applyQuaternion( _quaternion$1 ); + + if ( listener.positionX ) { + + // code path for Chrome (see #14393) + + const endTime = this.context.currentTime + this.timeDelta; + + listener.positionX.linearRampToValueAtTime( _position$1.x, endTime ); + listener.positionY.linearRampToValueAtTime( _position$1.y, endTime ); + listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime ); + listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime ); + listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime ); + listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime ); + listener.upX.linearRampToValueAtTime( up.x, endTime ); + listener.upY.linearRampToValueAtTime( up.y, endTime ); + listener.upZ.linearRampToValueAtTime( up.z, endTime ); + + } else { + + listener.setPosition( _position$1.x, _position$1.y, _position$1.z ); + listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z ); + + } + + } + +} + +class Audio extends Object3D { + + constructor( listener ) { + + super(); + + this.type = 'Audio'; + + this.listener = listener; + this.context = listener.context; + + this.gain = this.context.createGain(); + this.gain.connect( listener.getInput() ); + + this.autoplay = false; + + this.buffer = null; + this.detune = 0; + this.loop = false; + this.loopStart = 0; + this.loopEnd = 0; + this.offset = 0; + this.duration = undefined; + this.playbackRate = 1; + this.isPlaying = false; + this.hasPlaybackControl = true; + this.source = null; + this.sourceType = 'empty'; + + this._startedAt = 0; + this._progress = 0; + this._connected = false; + + this.filters = []; + + } + + getOutput() { + + return this.gain; + + } + + setNodeSource( audioNode ) { + + this.hasPlaybackControl = false; + this.sourceType = 'audioNode'; + this.source = audioNode; + this.connect(); + + return this; + + } + + setMediaElementSource( mediaElement ) { + + this.hasPlaybackControl = false; + this.sourceType = 'mediaNode'; + this.source = this.context.createMediaElementSource( mediaElement ); + this.connect(); + + return this; + + } + + setMediaStreamSource( mediaStream ) { + + this.hasPlaybackControl = false; + this.sourceType = 'mediaStreamNode'; + this.source = this.context.createMediaStreamSource( mediaStream ); + this.connect(); + + return this; + + } + + setBuffer( audioBuffer ) { + + this.buffer = audioBuffer; + this.sourceType = 'buffer'; + + if ( this.autoplay ) this.play(); + + return this; + + } + + play( delay = 0 ) { + + if ( this.isPlaying === true ) { + + console.warn( 'THREE.Audio: Audio is already playing.' ); + return; + + } + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this._startedAt = this.context.currentTime + delay; + + const source = this.context.createBufferSource(); + source.buffer = this.buffer; + source.loop = this.loop; + source.loopStart = this.loopStart; + source.loopEnd = this.loopEnd; + source.onended = this.onEnded.bind( this ); + source.start( this._startedAt, this._progress + this.offset, this.duration ); + + this.isPlaying = true; + + this.source = source; + + this.setDetune( this.detune ); + this.setPlaybackRate( this.playbackRate ); + + return this.connect(); + + } + + pause() { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + if ( this.isPlaying === true ) { + + // update current progress + + this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate; + + if ( this.loop === true ) { + + // ensure _progress does not exceed duration with looped audios + + this._progress = this._progress % ( this.duration || this.buffer.duration ); + + } + + this.source.stop(); + this.source.onended = null; + + this.isPlaying = false; + + } + + return this; + + } + + stop( delay = 0 ) { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this._progress = 0; + + if ( this.source !== null ) { + + this.source.stop( this.context.currentTime + delay ); + this.source.onended = null; + + } + + this.isPlaying = false; + + return this; + + } + + connect() { + + if ( this.filters.length > 0 ) { + + this.source.connect( this.filters[ 0 ] ); + + for ( let i = 1, l = this.filters.length; i < l; i ++ ) { + + this.filters[ i - 1 ].connect( this.filters[ i ] ); + + } + + this.filters[ this.filters.length - 1 ].connect( this.getOutput() ); + + } else { + + this.source.connect( this.getOutput() ); + + } + + this._connected = true; + + return this; + + } + + disconnect() { + + if ( this._connected === false ) { + + return; + + } + + if ( this.filters.length > 0 ) { + + this.source.disconnect( this.filters[ 0 ] ); + + for ( let i = 1, l = this.filters.length; i < l; i ++ ) { + + this.filters[ i - 1 ].disconnect( this.filters[ i ] ); + + } + + this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() ); + + } else { + + this.source.disconnect( this.getOutput() ); + + } + + this._connected = false; + + return this; + + } + + getFilters() { + + return this.filters; + + } + + setFilters( value ) { + + if ( ! value ) value = []; + + if ( this._connected === true ) { + + this.disconnect(); + this.filters = value.slice(); + this.connect(); + + } else { + + this.filters = value.slice(); + + } + + return this; + + } + + setDetune( value ) { + + this.detune = value; + + if ( this.isPlaying === true && this.source.detune !== undefined ) { + + this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 ); + + } + + return this; + + } + + getDetune() { + + return this.detune; + + } + + getFilter() { + + return this.getFilters()[ 0 ]; + + } + + setFilter( filter ) { + + return this.setFilters( filter ? [ filter ] : [] ); + + } + + setPlaybackRate( value ) { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this.playbackRate = value; + + if ( this.isPlaying === true ) { + + this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 ); + + } + + return this; + + } + + getPlaybackRate() { + + return this.playbackRate; + + } + + onEnded() { + + this.isPlaying = false; + this._progress = 0; + + } + + getLoop() { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return false; + + } + + return this.loop; + + } + + setLoop( value ) { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this.loop = value; + + if ( this.isPlaying === true ) { + + this.source.loop = this.loop; + + } + + return this; + + } + + setLoopStart( value ) { + + this.loopStart = value; + + return this; + + } + + setLoopEnd( value ) { + + this.loopEnd = value; + + return this; + + } + + getVolume() { + + return this.gain.gain.value; + + } + + setVolume( value ) { + + this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 ); + + return this; + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + if ( source.sourceType !== 'buffer' ) { + + console.warn( 'THREE.Audio: Audio source type cannot be copied.' ); + + return this; + + } + + this.autoplay = source.autoplay; + + this.buffer = source.buffer; + this.detune = source.detune; + this.loop = source.loop; + this.loopStart = source.loopStart; + this.loopEnd = source.loopEnd; + this.offset = source.offset; + this.duration = source.duration; + this.playbackRate = source.playbackRate; + this.hasPlaybackControl = source.hasPlaybackControl; + this.sourceType = source.sourceType; + + this.filters = source.filters.slice(); + + return this; + + } + + clone( recursive ) { + + return new this.constructor( this.listener ).copy( this, recursive ); + + } + +} + +const _position = /*@__PURE__*/ new Vector3(); +const _quaternion = /*@__PURE__*/ new Quaternion(); +const _scale = /*@__PURE__*/ new Vector3(); +const _orientation = /*@__PURE__*/ new Vector3(); + +class PositionalAudio extends Audio { + + constructor( listener ) { + + super( listener ); + + this.panner = this.context.createPanner(); + this.panner.panningModel = 'HRTF'; + this.panner.connect( this.gain ); + + } + + connect() { + + super.connect(); + + this.panner.connect( this.gain ); + + } + + disconnect() { + + super.disconnect(); + + this.panner.disconnect( this.gain ); + + } + + getOutput() { + + return this.panner; + + } + + getRefDistance() { + + return this.panner.refDistance; + + } + + setRefDistance( value ) { + + this.panner.refDistance = value; + + return this; + + } + + getRolloffFactor() { + + return this.panner.rolloffFactor; + + } + + setRolloffFactor( value ) { + + this.panner.rolloffFactor = value; + + return this; + + } + + getDistanceModel() { + + return this.panner.distanceModel; + + } + + setDistanceModel( value ) { + + this.panner.distanceModel = value; + + return this; + + } + + getMaxDistance() { + + return this.panner.maxDistance; + + } + + setMaxDistance( value ) { + + this.panner.maxDistance = value; + + return this; + + } + + setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) { + + this.panner.coneInnerAngle = coneInnerAngle; + this.panner.coneOuterAngle = coneOuterAngle; + this.panner.coneOuterGain = coneOuterGain; + + return this; + + } + + updateMatrixWorld( force ) { + + super.updateMatrixWorld( force ); + + if ( this.hasPlaybackControl === true && this.isPlaying === false ) return; + + this.matrixWorld.decompose( _position, _quaternion, _scale ); + + _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion ); + + const panner = this.panner; + + if ( panner.positionX ) { + + // code path for Chrome and Firefox (see #14393) + + const endTime = this.context.currentTime + this.listener.timeDelta; + + panner.positionX.linearRampToValueAtTime( _position.x, endTime ); + panner.positionY.linearRampToValueAtTime( _position.y, endTime ); + panner.positionZ.linearRampToValueAtTime( _position.z, endTime ); + panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime ); + panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime ); + panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime ); + + } else { + + panner.setPosition( _position.x, _position.y, _position.z ); + panner.setOrientation( _orientation.x, _orientation.y, _orientation.z ); + + } + + } + +} + +class AudioAnalyser { + + constructor( audio, fftSize = 2048 ) { + + this.analyser = audio.context.createAnalyser(); + this.analyser.fftSize = fftSize; + + this.data = new Uint8Array( this.analyser.frequencyBinCount ); + + audio.getOutput().connect( this.analyser ); + + } + + + getFrequencyData() { + + this.analyser.getByteFrequencyData( this.data ); + + return this.data; + + } + + getAverageFrequency() { + + let value = 0; + const data = this.getFrequencyData(); + + for ( let i = 0; i < data.length; i ++ ) { + + value += data[ i ]; + + } + + return value / data.length; + + } + +} + +class PropertyMixer { + + constructor( binding, typeName, valueSize ) { + + this.binding = binding; + this.valueSize = valueSize; + + let mixFunction, + mixFunctionAdditive, + setIdentity; + + // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ] + // + // interpolators can use .buffer as their .result + // the data then goes to 'incoming' + // + // 'accu0' and 'accu1' are used frame-interleaved for + // the cumulative result and are compared to detect + // changes + // + // 'orig' stores the original state of the property + // + // 'add' is used for additive cumulative results + // + // 'work' is optional and is only present for quaternion types. It is used + // to store intermediate quaternion multiplication results + + switch ( typeName ) { + + case 'quaternion': + mixFunction = this._slerp; + mixFunctionAdditive = this._slerpAdditive; + setIdentity = this._setAdditiveIdentityQuaternion; + + this.buffer = new Float64Array( valueSize * 6 ); + this._workIndex = 5; + break; + + case 'string': + case 'bool': + mixFunction = this._select; + + // Use the regular mix function and for additive on these types, + // additive is not relevant for non-numeric types + mixFunctionAdditive = this._select; + + setIdentity = this._setAdditiveIdentityOther; + + this.buffer = new Array( valueSize * 5 ); + break; + + default: + mixFunction = this._lerp; + mixFunctionAdditive = this._lerpAdditive; + setIdentity = this._setAdditiveIdentityNumeric; + + this.buffer = new Float64Array( valueSize * 5 ); + + } + + this._mixBufferRegion = mixFunction; + this._mixBufferRegionAdditive = mixFunctionAdditive; + this._setIdentity = setIdentity; + this._origIndex = 3; + this._addIndex = 4; + + this.cumulativeWeight = 0; + this.cumulativeWeightAdditive = 0; + + this.useCount = 0; + this.referenceCount = 0; + + } + + // accumulate data in the 'incoming' region into 'accu' + accumulate( accuIndex, weight ) { + + // note: happily accumulating nothing when weight = 0, the caller knows + // the weight and shouldn't have made the call in the first place + + const buffer = this.buffer, + stride = this.valueSize, + offset = accuIndex * stride + stride; + + let currentWeight = this.cumulativeWeight; + + if ( currentWeight === 0 ) { + + // accuN := incoming * weight + + for ( let i = 0; i !== stride; ++ i ) { + + buffer[ offset + i ] = buffer[ i ]; + + } + + currentWeight = weight; + + } else { + + // accuN := accuN + incoming * weight + + currentWeight += weight; + const mix = weight / currentWeight; + this._mixBufferRegion( buffer, offset, 0, mix, stride ); + + } + + this.cumulativeWeight = currentWeight; + + } + + // accumulate data in the 'incoming' region into 'add' + accumulateAdditive( weight ) { + + const buffer = this.buffer, + stride = this.valueSize, + offset = stride * this._addIndex; + + if ( this.cumulativeWeightAdditive === 0 ) { + + // add = identity + + this._setIdentity(); + + } + + // add := add + incoming * weight + + this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride ); + this.cumulativeWeightAdditive += weight; + + } + + // apply the state of 'accu' to the binding when accus differ + apply( accuIndex ) { + + const stride = this.valueSize, + buffer = this.buffer, + offset = accuIndex * stride + stride, + + weight = this.cumulativeWeight, + weightAdditive = this.cumulativeWeightAdditive, + + binding = this.binding; + + this.cumulativeWeight = 0; + this.cumulativeWeightAdditive = 0; + + if ( weight < 1 ) { + + // accuN := accuN + original * ( 1 - cumulativeWeight ) + + const originalValueOffset = stride * this._origIndex; + + this._mixBufferRegion( + buffer, offset, originalValueOffset, 1 - weight, stride ); + + } + + if ( weightAdditive > 0 ) { + + // accuN := accuN + additive accuN + + this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride ); + + } + + for ( let i = stride, e = stride + stride; i !== e; ++ i ) { + + if ( buffer[ i ] !== buffer[ i + stride ] ) { + + // value has changed -> update scene graph + + binding.setValue( buffer, offset ); + break; + + } + + } + + } + + // remember the state of the bound property and copy it to both accus + saveOriginalState() { + + const binding = this.binding; + + const buffer = this.buffer, + stride = this.valueSize, + + originalValueOffset = stride * this._origIndex; + + binding.getValue( buffer, originalValueOffset ); + + // accu[0..1] := orig -- initially detect changes against the original + for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) { + + buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ]; + + } + + // Add to identity for additive + this._setIdentity(); + + this.cumulativeWeight = 0; + this.cumulativeWeightAdditive = 0; + + } + + // apply the state previously taken via 'saveOriginalState' to the binding + restoreOriginalState() { + + const originalValueOffset = this.valueSize * 3; + this.binding.setValue( this.buffer, originalValueOffset ); + + } + + _setAdditiveIdentityNumeric() { + + const startIndex = this._addIndex * this.valueSize; + const endIndex = startIndex + this.valueSize; + + for ( let i = startIndex; i < endIndex; i ++ ) { + + this.buffer[ i ] = 0; + + } + + } + + _setAdditiveIdentityQuaternion() { + + this._setAdditiveIdentityNumeric(); + this.buffer[ this._addIndex * this.valueSize + 3 ] = 1; + + } + + _setAdditiveIdentityOther() { + + const startIndex = this._origIndex * this.valueSize; + const targetIndex = this._addIndex * this.valueSize; + + for ( let i = 0; i < this.valueSize; i ++ ) { + + this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ]; + + } + + } + + + // mix functions + + _select( buffer, dstOffset, srcOffset, t, stride ) { + + if ( t >= 0.5 ) { + + for ( let i = 0; i !== stride; ++ i ) { + + buffer[ dstOffset + i ] = buffer[ srcOffset + i ]; + + } + + } + + } + + _slerp( buffer, dstOffset, srcOffset, t ) { + + Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t ); + + } + + _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) { + + const workOffset = this._workIndex * stride; + + // Store result in intermediate buffer offset + Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset ); + + // Slerp to the intermediate result + Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t ); + + } + + _lerp( buffer, dstOffset, srcOffset, t, stride ) { + + const s = 1 - t; + + for ( let i = 0; i !== stride; ++ i ) { + + const j = dstOffset + i; + + buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t; + + } + + } + + _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) { + + for ( let i = 0; i !== stride; ++ i ) { + + const j = dstOffset + i; + + buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t; + + } + + } + +} + +// Characters [].:/ are reserved for track binding syntax. +const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/'; +const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' ); + +// Attempts to allow node names from any language. ES5's `\w` regexp matches +// only latin characters, and the unicode \p{L} is not yet supported. So +// instead, we exclude reserved characters and match everything else. +const _wordChar = '[^' + _RESERVED_CHARS_RE + ']'; +const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']'; + +// Parent directories, delimited by '/' or ':'. Currently unused, but must +// be matched to parse the rest of the track name. +const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar ); + +// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'. +const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot ); + +// Object on target node, and accessor. May not contain reserved +// characters. Accessor may contain any character except closing bracket. +const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar ); + +// Property and accessor. May not contain reserved characters. Accessor may +// contain any non-bracket characters. +const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar ); + +const _trackRe = new RegExp( '' + + '^' + + _directoryRe + + _nodeRe + + _objectRe + + _propertyRe + + '$' +); + +const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ]; + +class Composite { + + constructor( targetGroup, path, optionalParsedPath ) { + + const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path ); + + this._targetGroup = targetGroup; + this._bindings = targetGroup.subscribe_( path, parsedPath ); + + } + + getValue( array, offset ) { + + this.bind(); // bind all binding + + const firstValidIndex = this._targetGroup.nCachedObjects_, + binding = this._bindings[ firstValidIndex ]; + + // and only call .getValue on the first + if ( binding !== undefined ) binding.getValue( array, offset ); + + } + + setValue( array, offset ) { + + const bindings = this._bindings; + + for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) { + + bindings[ i ].setValue( array, offset ); + + } + + } + + bind() { + + const bindings = this._bindings; + + for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) { + + bindings[ i ].bind(); + + } + + } + + unbind() { + + const bindings = this._bindings; + + for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) { + + bindings[ i ].unbind(); + + } + + } + +} + +// Note: This class uses a State pattern on a per-method basis: +// 'bind' sets 'this.getValue' / 'setValue' and shadows the +// prototype version of these methods with one that represents +// the bound state. When the property is not found, the methods +// become no-ops. +class PropertyBinding { + + constructor( rootNode, path, parsedPath ) { + + this.path = path; + this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path ); + + this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ); + + this.rootNode = rootNode; + + // initial state of these methods that calls 'bind' + this.getValue = this._getValue_unbound; + this.setValue = this._setValue_unbound; + + } + + + static create( root, path, parsedPath ) { + + if ( ! ( root && root.isAnimationObjectGroup ) ) { + + return new PropertyBinding( root, path, parsedPath ); + + } else { + + return new PropertyBinding.Composite( root, path, parsedPath ); + + } + + } + + /** + * Replaces spaces with underscores and removes unsupported characters from + * node names, to ensure compatibility with parseTrackName(). + * + * @param {string} name Node name to be sanitized. + * @return {string} + */ + static sanitizeNodeName( name ) { + + return name.replace( /\s/g, '_' ).replace( _reservedRe, '' ); + + } + + static parseTrackName( trackName ) { + + const matches = _trackRe.exec( trackName ); + + if ( matches === null ) { + + throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName ); + + } + + const results = { + // directoryName: matches[ 1 ], // (tschw) currently unused + nodeName: matches[ 2 ], + objectName: matches[ 3 ], + objectIndex: matches[ 4 ], + propertyName: matches[ 5 ], // required + propertyIndex: matches[ 6 ] + }; + + const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' ); + + if ( lastDot !== undefined && lastDot !== - 1 ) { + + const objectName = results.nodeName.substring( lastDot + 1 ); + + // Object names must be checked against an allowlist. Otherwise, there + // is no way to parse 'foo.bar.baz': 'baz' must be a property, but + // 'bar' could be the objectName, or part of a nodeName (which can + // include '.' characters). + if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) { + + results.nodeName = results.nodeName.substring( 0, lastDot ); + results.objectName = objectName; + + } + + } + + if ( results.propertyName === null || results.propertyName.length === 0 ) { + + throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName ); + + } + + return results; + + } + + static findNode( root, nodeName ) { + + if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) { + + return root; + + } + + // search into skeleton bones. + if ( root.skeleton ) { + + const bone = root.skeleton.getBoneByName( nodeName ); + + if ( bone !== undefined ) { + + return bone; + + } + + } + + // search into node subtree. + if ( root.children ) { + + const searchNodeSubtree = function ( children ) { + + for ( let i = 0; i < children.length; i ++ ) { + + const childNode = children[ i ]; + + if ( childNode.name === nodeName || childNode.uuid === nodeName ) { + + return childNode; + + } + + const result = searchNodeSubtree( childNode.children ); + + if ( result ) return result; + + } + + return null; + + }; + + const subTreeNode = searchNodeSubtree( root.children ); + + if ( subTreeNode ) { + + return subTreeNode; + + } + + } + + return null; + + } + + // these are used to "bind" a nonexistent property + _getValue_unavailable() {} + _setValue_unavailable() {} + + // Getters + + _getValue_direct( buffer, offset ) { + + buffer[ offset ] = this.targetObject[ this.propertyName ]; + + } + + _getValue_array( buffer, offset ) { + + const source = this.resolvedProperty; + + for ( let i = 0, n = source.length; i !== n; ++ i ) { + + buffer[ offset ++ ] = source[ i ]; + + } + + } + + _getValue_arrayElement( buffer, offset ) { + + buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ]; + + } + + _getValue_toArray( buffer, offset ) { + + this.resolvedProperty.toArray( buffer, offset ); + + } + + // Direct + + _setValue_direct( buffer, offset ) { + + this.targetObject[ this.propertyName ] = buffer[ offset ]; + + } + + _setValue_direct_setNeedsUpdate( buffer, offset ) { + + this.targetObject[ this.propertyName ] = buffer[ offset ]; + this.targetObject.needsUpdate = true; + + } + + _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) { + + this.targetObject[ this.propertyName ] = buffer[ offset ]; + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + // EntireArray + + _setValue_array( buffer, offset ) { + + const dest = this.resolvedProperty; + + for ( let i = 0, n = dest.length; i !== n; ++ i ) { + + dest[ i ] = buffer[ offset ++ ]; + + } + + } + + _setValue_array_setNeedsUpdate( buffer, offset ) { + + const dest = this.resolvedProperty; + + for ( let i = 0, n = dest.length; i !== n; ++ i ) { + + dest[ i ] = buffer[ offset ++ ]; + + } + + this.targetObject.needsUpdate = true; + + } + + _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) { + + const dest = this.resolvedProperty; + + for ( let i = 0, n = dest.length; i !== n; ++ i ) { + + dest[ i ] = buffer[ offset ++ ]; + + } + + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + // ArrayElement + + _setValue_arrayElement( buffer, offset ) { + + this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ]; + + } + + _setValue_arrayElement_setNeedsUpdate( buffer, offset ) { + + this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ]; + this.targetObject.needsUpdate = true; + + } + + _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) { + + this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ]; + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + // HasToFromArray + + _setValue_fromArray( buffer, offset ) { + + this.resolvedProperty.fromArray( buffer, offset ); + + } + + _setValue_fromArray_setNeedsUpdate( buffer, offset ) { + + this.resolvedProperty.fromArray( buffer, offset ); + this.targetObject.needsUpdate = true; + + } + + _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) { + + this.resolvedProperty.fromArray( buffer, offset ); + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + _getValue_unbound( targetArray, offset ) { + + this.bind(); + this.getValue( targetArray, offset ); + + } + + _setValue_unbound( sourceArray, offset ) { + + this.bind(); + this.setValue( sourceArray, offset ); + + } + + // create getter / setter pair for a property in the scene graph + bind() { + + let targetObject = this.node; + const parsedPath = this.parsedPath; + + const objectName = parsedPath.objectName; + const propertyName = parsedPath.propertyName; + let propertyIndex = parsedPath.propertyIndex; + + if ( ! targetObject ) { + + targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ); + + this.node = targetObject; + + } + + // set fail state so we can just 'return' on error + this.getValue = this._getValue_unavailable; + this.setValue = this._setValue_unavailable; + + // ensure there is a value node + if ( ! targetObject ) { + + console.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' ); + return; + + } + + if ( objectName ) { + + let objectIndex = parsedPath.objectIndex; + + // special cases were we need to reach deeper into the hierarchy to get the face materials.... + switch ( objectName ) { + + case 'materials': + + if ( ! targetObject.material ) { + + console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this ); + return; + + } + + if ( ! targetObject.material.materials ) { + + console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this ); + return; + + } + + targetObject = targetObject.material.materials; + + break; + + case 'bones': + + if ( ! targetObject.skeleton ) { + + console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this ); + return; + + } + + // potential future optimization: skip this if propertyIndex is already an integer + // and convert the integer string to a true integer. + + targetObject = targetObject.skeleton.bones; + + // support resolving morphTarget names into indices. + for ( let i = 0; i < targetObject.length; i ++ ) { + + if ( targetObject[ i ].name === objectIndex ) { + + objectIndex = i; + break; + + } + + } + + break; + + case 'map': + + if ( 'map' in targetObject ) { + + targetObject = targetObject.map; + break; + + } + + if ( ! targetObject.material ) { + + console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this ); + return; + + } + + if ( ! targetObject.material.map ) { + + console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this ); + return; + + } + + targetObject = targetObject.material.map; + break; + + default: + + if ( targetObject[ objectName ] === undefined ) { + + console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this ); + return; + + } + + targetObject = targetObject[ objectName ]; + + } + + + if ( objectIndex !== undefined ) { + + if ( targetObject[ objectIndex ] === undefined ) { + + console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject ); + return; + + } + + targetObject = targetObject[ objectIndex ]; + + } + + } + + // resolve property + const nodeProperty = targetObject[ propertyName ]; + + if ( nodeProperty === undefined ) { + + const nodeName = parsedPath.nodeName; + + console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName + + '.' + propertyName + ' but it wasn\'t found.', targetObject ); + return; + + } + + // determine versioning scheme + let versioning = this.Versioning.None; + + this.targetObject = targetObject; + + if ( targetObject.needsUpdate !== undefined ) { // material + + versioning = this.Versioning.NeedsUpdate; + + } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform + + versioning = this.Versioning.MatrixWorldNeedsUpdate; + + } + + // determine how the property gets bound + let bindingType = this.BindingType.Direct; + + if ( propertyIndex !== undefined ) { + + // access a sub element of the property array (only primitives are supported right now) + + if ( propertyName === 'morphTargetInfluences' ) { + + // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer. + + // support resolving morphTarget names into indices. + if ( ! targetObject.geometry ) { + + console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this ); + return; + + } + + if ( ! targetObject.geometry.morphAttributes ) { + + console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this ); + return; + + } + + if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) { + + propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ]; + + } + + } + + bindingType = this.BindingType.ArrayElement; + + this.resolvedProperty = nodeProperty; + this.propertyIndex = propertyIndex; + + } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) { + + // must use copy for Object3D.Euler/Quaternion + + bindingType = this.BindingType.HasFromToArray; + + this.resolvedProperty = nodeProperty; + + } else if ( Array.isArray( nodeProperty ) ) { + + bindingType = this.BindingType.EntireArray; + + this.resolvedProperty = nodeProperty; + + } else { + + this.propertyName = propertyName; + + } + + // select getter / setter + this.getValue = this.GetterByBindingType[ bindingType ]; + this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ]; + + } + + unbind() { + + this.node = null; + + // back to the prototype version of getValue / setValue + // note: avoiding to mutate the shape of 'this' via 'delete' + this.getValue = this._getValue_unbound; + this.setValue = this._setValue_unbound; + + } + +} + +PropertyBinding.Composite = Composite; + +PropertyBinding.prototype.BindingType = { + Direct: 0, + EntireArray: 1, + ArrayElement: 2, + HasFromToArray: 3 +}; + +PropertyBinding.prototype.Versioning = { + None: 0, + NeedsUpdate: 1, + MatrixWorldNeedsUpdate: 2 +}; + +PropertyBinding.prototype.GetterByBindingType = [ + + PropertyBinding.prototype._getValue_direct, + PropertyBinding.prototype._getValue_array, + PropertyBinding.prototype._getValue_arrayElement, + PropertyBinding.prototype._getValue_toArray, + +]; + +PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [ + + [ + // Direct + PropertyBinding.prototype._setValue_direct, + PropertyBinding.prototype._setValue_direct_setNeedsUpdate, + PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate, + + ], [ + + // EntireArray + + PropertyBinding.prototype._setValue_array, + PropertyBinding.prototype._setValue_array_setNeedsUpdate, + PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate, + + ], [ + + // ArrayElement + PropertyBinding.prototype._setValue_arrayElement, + PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate, + PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate, + + ], [ + + // HasToFromArray + PropertyBinding.prototype._setValue_fromArray, + PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate, + PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate, + + ] + +]; + +/** + * + * A group of objects that receives a shared animation state. + * + * Usage: + * + * - Add objects you would otherwise pass as 'root' to the + * constructor or the .clipAction method of AnimationMixer. + * + * - Instead pass this object as 'root'. + * + * - You can also add and remove objects later when the mixer + * is running. + * + * Note: + * + * Objects of this class appear as one object to the mixer, + * so cache control of the individual objects must be done + * on the group. + * + * Limitation: + * + * - The animated properties must be compatible among the + * all objects in the group. + * + * - A single property can either be controlled through a + * target group or directly, but not both. + */ + +class AnimationObjectGroup { + + constructor() { + + this.isAnimationObjectGroup = true; + + this.uuid = generateUUID(); + + // cached objects followed by the active ones + this._objects = Array.prototype.slice.call( arguments ); + + this.nCachedObjects_ = 0; // threshold + // note: read by PropertyBinding.Composite + + const indices = {}; + this._indicesByUUID = indices; // for bookkeeping + + for ( let i = 0, n = arguments.length; i !== n; ++ i ) { + + indices[ arguments[ i ].uuid ] = i; + + } + + this._paths = []; // inside: string + this._parsedPaths = []; // inside: { we don't care, here } + this._bindings = []; // inside: Array< PropertyBinding > + this._bindingsIndicesByPath = {}; // inside: indices in these arrays + + const scope = this; + + this.stats = { + + objects: { + get total() { + + return scope._objects.length; + + }, + get inUse() { + + return this.total - scope.nCachedObjects_; + + } + }, + get bindingsPerObject() { + + return scope._bindings.length; + + } + + }; + + } + + add() { + + const objects = this._objects, + indicesByUUID = this._indicesByUUID, + paths = this._paths, + parsedPaths = this._parsedPaths, + bindings = this._bindings, + nBindings = bindings.length; + + let knownObject = undefined, + nObjects = objects.length, + nCachedObjects = this.nCachedObjects_; + + for ( let i = 0, n = arguments.length; i !== n; ++ i ) { + + const object = arguments[ i ], + uuid = object.uuid; + let index = indicesByUUID[ uuid ]; + + if ( index === undefined ) { + + // unknown object -> add it to the ACTIVE region + + index = nObjects ++; + indicesByUUID[ uuid ] = index; + objects.push( object ); + + // accounting is done, now do the same for all bindings + + for ( let j = 0, m = nBindings; j !== m; ++ j ) { + + bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) ); + + } + + } else if ( index < nCachedObjects ) { + + knownObject = objects[ index ]; + + // move existing object to the ACTIVE region + + const firstActiveIndex = -- nCachedObjects, + lastCachedObject = objects[ firstActiveIndex ]; + + indicesByUUID[ lastCachedObject.uuid ] = index; + objects[ index ] = lastCachedObject; + + indicesByUUID[ uuid ] = firstActiveIndex; + objects[ firstActiveIndex ] = object; + + // accounting is done, now do the same for all bindings + + for ( let j = 0, m = nBindings; j !== m; ++ j ) { + + const bindingsForPath = bindings[ j ], + lastCached = bindingsForPath[ firstActiveIndex ]; + + let binding = bindingsForPath[ index ]; + + bindingsForPath[ index ] = lastCached; + + if ( binding === undefined ) { + + // since we do not bother to create new bindings + // for objects that are cached, the binding may + // or may not exist + + binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ); + + } + + bindingsForPath[ firstActiveIndex ] = binding; + + } + + } else if ( objects[ index ] !== knownObject ) { + + console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' + + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' ); + + } // else the object is already where we want it to be + + } // for arguments + + this.nCachedObjects_ = nCachedObjects; + + } + + remove() { + + const objects = this._objects, + indicesByUUID = this._indicesByUUID, + bindings = this._bindings, + nBindings = bindings.length; + + let nCachedObjects = this.nCachedObjects_; + + for ( let i = 0, n = arguments.length; i !== n; ++ i ) { + + const object = arguments[ i ], + uuid = object.uuid, + index = indicesByUUID[ uuid ]; + + if ( index !== undefined && index >= nCachedObjects ) { + + // move existing object into the CACHED region + + const lastCachedIndex = nCachedObjects ++, + firstActiveObject = objects[ lastCachedIndex ]; + + indicesByUUID[ firstActiveObject.uuid ] = index; + objects[ index ] = firstActiveObject; + + indicesByUUID[ uuid ] = lastCachedIndex; + objects[ lastCachedIndex ] = object; + + // accounting is done, now do the same for all bindings + + for ( let j = 0, m = nBindings; j !== m; ++ j ) { + + const bindingsForPath = bindings[ j ], + firstActive = bindingsForPath[ lastCachedIndex ], + binding = bindingsForPath[ index ]; + + bindingsForPath[ index ] = firstActive; + bindingsForPath[ lastCachedIndex ] = binding; + + } + + } + + } // for arguments + + this.nCachedObjects_ = nCachedObjects; + + } + + // remove & forget + uncache() { + + const objects = this._objects, + indicesByUUID = this._indicesByUUID, + bindings = this._bindings, + nBindings = bindings.length; + + let nCachedObjects = this.nCachedObjects_, + nObjects = objects.length; + + for ( let i = 0, n = arguments.length; i !== n; ++ i ) { + + const object = arguments[ i ], + uuid = object.uuid, + index = indicesByUUID[ uuid ]; + + if ( index !== undefined ) { + + delete indicesByUUID[ uuid ]; + + if ( index < nCachedObjects ) { + + // object is cached, shrink the CACHED region + + const firstActiveIndex = -- nCachedObjects, + lastCachedObject = objects[ firstActiveIndex ], + lastIndex = -- nObjects, + lastObject = objects[ lastIndex ]; + + // last cached object takes this object's place + indicesByUUID[ lastCachedObject.uuid ] = index; + objects[ index ] = lastCachedObject; + + // last object goes to the activated slot and pop + indicesByUUID[ lastObject.uuid ] = firstActiveIndex; + objects[ firstActiveIndex ] = lastObject; + objects.pop(); + + // accounting is done, now do the same for all bindings + + for ( let j = 0, m = nBindings; j !== m; ++ j ) { + + const bindingsForPath = bindings[ j ], + lastCached = bindingsForPath[ firstActiveIndex ], + last = bindingsForPath[ lastIndex ]; + + bindingsForPath[ index ] = lastCached; + bindingsForPath[ firstActiveIndex ] = last; + bindingsForPath.pop(); + + } + + } else { + + // object is active, just swap with the last and pop + + const lastIndex = -- nObjects, + lastObject = objects[ lastIndex ]; + + if ( lastIndex > 0 ) { + + indicesByUUID[ lastObject.uuid ] = index; + + } + + objects[ index ] = lastObject; + objects.pop(); + + // accounting is done, now do the same for all bindings + + for ( let j = 0, m = nBindings; j !== m; ++ j ) { + + const bindingsForPath = bindings[ j ]; + + bindingsForPath[ index ] = bindingsForPath[ lastIndex ]; + bindingsForPath.pop(); + + } + + } // cached or active + + } // if object is known + + } // for arguments + + this.nCachedObjects_ = nCachedObjects; + + } + + // Internal interface used by befriended PropertyBinding.Composite: + + subscribe_( path, parsedPath ) { + + // returns an array of bindings for the given path that is changed + // according to the contained objects in the group + + const indicesByPath = this._bindingsIndicesByPath; + let index = indicesByPath[ path ]; + const bindings = this._bindings; + + if ( index !== undefined ) return bindings[ index ]; + + const paths = this._paths, + parsedPaths = this._parsedPaths, + objects = this._objects, + nObjects = objects.length, + nCachedObjects = this.nCachedObjects_, + bindingsForPath = new Array( nObjects ); + + index = bindings.length; + + indicesByPath[ path ] = index; + + paths.push( path ); + parsedPaths.push( parsedPath ); + bindings.push( bindingsForPath ); + + for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) { + + const object = objects[ i ]; + bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath ); + + } + + return bindingsForPath; + + } + + unsubscribe_( path ) { + + // tells the group to forget about a property path and no longer + // update the array previously obtained with 'subscribe_' + + const indicesByPath = this._bindingsIndicesByPath, + index = indicesByPath[ path ]; + + if ( index !== undefined ) { + + const paths = this._paths, + parsedPaths = this._parsedPaths, + bindings = this._bindings, + lastBindingsIndex = bindings.length - 1, + lastBindings = bindings[ lastBindingsIndex ], + lastBindingsPath = path[ lastBindingsIndex ]; + + indicesByPath[ lastBindingsPath ] = index; + + bindings[ index ] = lastBindings; + bindings.pop(); + + parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ]; + parsedPaths.pop(); + + paths[ index ] = paths[ lastBindingsIndex ]; + paths.pop(); + + } + + } + +} + +class AnimationAction { + + constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) { + + this._mixer = mixer; + this._clip = clip; + this._localRoot = localRoot; + this.blendMode = blendMode; + + const tracks = clip.tracks, + nTracks = tracks.length, + interpolants = new Array( nTracks ); + + const interpolantSettings = { + endingStart: ZeroCurvatureEnding, + endingEnd: ZeroCurvatureEnding + }; + + for ( let i = 0; i !== nTracks; ++ i ) { + + const interpolant = tracks[ i ].createInterpolant( null ); + interpolants[ i ] = interpolant; + interpolant.settings = interpolantSettings; + + } + + this._interpolantSettings = interpolantSettings; + + this._interpolants = interpolants; // bound by the mixer + + // inside: PropertyMixer (managed by the mixer) + this._propertyBindings = new Array( nTracks ); + + this._cacheIndex = null; // for the memory manager + this._byClipCacheIndex = null; // for the memory manager + + this._timeScaleInterpolant = null; + this._weightInterpolant = null; + + this.loop = LoopRepeat; + this._loopCount = - 1; + + // global mixer time when the action is to be started + // it's set back to 'null' upon start of the action + this._startTime = null; + + // scaled local time of the action + // gets clamped or wrapped to 0..clip.duration according to loop + this.time = 0; + + this.timeScale = 1; + this._effectiveTimeScale = 1; + + this.weight = 1; + this._effectiveWeight = 1; + + this.repetitions = Infinity; // no. of repetitions when looping + + this.paused = false; // true -> zero effective time scale + this.enabled = true; // false -> zero effective weight + + this.clampWhenFinished = false;// keep feeding the last frame? + + this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate + this.zeroSlopeAtEnd = true;// clips for start, loop and end + + } + + // State & Scheduling + + play() { + + this._mixer._activateAction( this ); + + return this; + + } + + stop() { + + this._mixer._deactivateAction( this ); + + return this.reset(); + + } + + reset() { + + this.paused = false; + this.enabled = true; + + this.time = 0; // restart clip + this._loopCount = - 1;// forget previous loops + this._startTime = null;// forget scheduling + + return this.stopFading().stopWarping(); + + } + + isRunning() { + + return this.enabled && ! this.paused && this.timeScale !== 0 && + this._startTime === null && this._mixer._isActiveAction( this ); + + } + + // return true when play has been called + isScheduled() { + + return this._mixer._isActiveAction( this ); + + } + + startAt( time ) { + + this._startTime = time; + + return this; + + } + + setLoop( mode, repetitions ) { + + this.loop = mode; + this.repetitions = repetitions; + + return this; + + } + + // Weight + + // set the weight stopping any scheduled fading + // although .enabled = false yields an effective weight of zero, this + // method does *not* change .enabled, because it would be confusing + setEffectiveWeight( weight ) { + + this.weight = weight; + + // note: same logic as when updated at runtime + this._effectiveWeight = this.enabled ? weight : 0; + + return this.stopFading(); + + } + + // return the weight considering fading and .enabled + getEffectiveWeight() { + + return this._effectiveWeight; + + } + + fadeIn( duration ) { + + return this._scheduleFading( duration, 0, 1 ); + + } + + fadeOut( duration ) { + + return this._scheduleFading( duration, 1, 0 ); + + } + + crossFadeFrom( fadeOutAction, duration, warp ) { + + fadeOutAction.fadeOut( duration ); + this.fadeIn( duration ); + + if ( warp ) { + + const fadeInDuration = this._clip.duration, + fadeOutDuration = fadeOutAction._clip.duration, + + startEndRatio = fadeOutDuration / fadeInDuration, + endStartRatio = fadeInDuration / fadeOutDuration; + + fadeOutAction.warp( 1.0, startEndRatio, duration ); + this.warp( endStartRatio, 1.0, duration ); + + } + + return this; + + } + + crossFadeTo( fadeInAction, duration, warp ) { + + return fadeInAction.crossFadeFrom( this, duration, warp ); + + } + + stopFading() { + + const weightInterpolant = this._weightInterpolant; + + if ( weightInterpolant !== null ) { + + this._weightInterpolant = null; + this._mixer._takeBackControlInterpolant( weightInterpolant ); + + } + + return this; + + } + + // Time Scale Control + + // set the time scale stopping any scheduled warping + // although .paused = true yields an effective time scale of zero, this + // method does *not* change .paused, because it would be confusing + setEffectiveTimeScale( timeScale ) { + + this.timeScale = timeScale; + this._effectiveTimeScale = this.paused ? 0 : timeScale; + + return this.stopWarping(); + + } + + // return the time scale considering warping and .paused + getEffectiveTimeScale() { + + return this._effectiveTimeScale; + + } + + setDuration( duration ) { + + this.timeScale = this._clip.duration / duration; + + return this.stopWarping(); + + } + + syncWith( action ) { + + this.time = action.time; + this.timeScale = action.timeScale; + + return this.stopWarping(); + + } + + halt( duration ) { + + return this.warp( this._effectiveTimeScale, 0, duration ); + + } + + warp( startTimeScale, endTimeScale, duration ) { + + const mixer = this._mixer, + now = mixer.time, + timeScale = this.timeScale; + + let interpolant = this._timeScaleInterpolant; + + if ( interpolant === null ) { + + interpolant = mixer._lendControlInterpolant(); + this._timeScaleInterpolant = interpolant; + + } + + const times = interpolant.parameterPositions, + values = interpolant.sampleValues; + + times[ 0 ] = now; + times[ 1 ] = now + duration; + + values[ 0 ] = startTimeScale / timeScale; + values[ 1 ] = endTimeScale / timeScale; + + return this; + + } + + stopWarping() { + + const timeScaleInterpolant = this._timeScaleInterpolant; + + if ( timeScaleInterpolant !== null ) { + + this._timeScaleInterpolant = null; + this._mixer._takeBackControlInterpolant( timeScaleInterpolant ); + + } + + return this; + + } + + // Object Accessors + + getMixer() { + + return this._mixer; + + } + + getClip() { + + return this._clip; + + } + + getRoot() { + + return this._localRoot || this._mixer._root; + + } + + // Interna + + _update( time, deltaTime, timeDirection, accuIndex ) { + + // called by the mixer + + if ( ! this.enabled ) { + + // call ._updateWeight() to update ._effectiveWeight + + this._updateWeight( time ); + return; + + } + + const startTime = this._startTime; + + if ( startTime !== null ) { + + // check for scheduled start of action + + const timeRunning = ( time - startTime ) * timeDirection; + if ( timeRunning < 0 || timeDirection === 0 ) { + + deltaTime = 0; + + } else { + + + this._startTime = null; // unschedule + deltaTime = timeDirection * timeRunning; + + } + + } + + // apply time scale and advance time + + deltaTime *= this._updateTimeScale( time ); + const clipTime = this._updateTime( deltaTime ); + + // note: _updateTime may disable the action resulting in + // an effective weight of 0 + + const weight = this._updateWeight( time ); + + if ( weight > 0 ) { + + const interpolants = this._interpolants; + const propertyMixers = this._propertyBindings; + + switch ( this.blendMode ) { + + case AdditiveAnimationBlendMode: + + for ( let j = 0, m = interpolants.length; j !== m; ++ j ) { + + interpolants[ j ].evaluate( clipTime ); + propertyMixers[ j ].accumulateAdditive( weight ); + + } + + break; + + case NormalAnimationBlendMode: + default: + + for ( let j = 0, m = interpolants.length; j !== m; ++ j ) { + + interpolants[ j ].evaluate( clipTime ); + propertyMixers[ j ].accumulate( accuIndex, weight ); + + } + + } + + } + + } + + _updateWeight( time ) { + + let weight = 0; + + if ( this.enabled ) { + + weight = this.weight; + const interpolant = this._weightInterpolant; + + if ( interpolant !== null ) { + + const interpolantValue = interpolant.evaluate( time )[ 0 ]; + + weight *= interpolantValue; + + if ( time > interpolant.parameterPositions[ 1 ] ) { + + this.stopFading(); + + if ( interpolantValue === 0 ) { + + // faded out, disable + this.enabled = false; + + } + + } + + } + + } + + this._effectiveWeight = weight; + return weight; + + } + + _updateTimeScale( time ) { + + let timeScale = 0; + + if ( ! this.paused ) { + + timeScale = this.timeScale; + + const interpolant = this._timeScaleInterpolant; + + if ( interpolant !== null ) { + + const interpolantValue = interpolant.evaluate( time )[ 0 ]; + + timeScale *= interpolantValue; + + if ( time > interpolant.parameterPositions[ 1 ] ) { + + this.stopWarping(); + + if ( timeScale === 0 ) { + + // motion has halted, pause + this.paused = true; + + } else { + + // warp done - apply final time scale + this.timeScale = timeScale; + + } + + } + + } + + } + + this._effectiveTimeScale = timeScale; + return timeScale; + + } + + _updateTime( deltaTime ) { + + const duration = this._clip.duration; + const loop = this.loop; + + let time = this.time + deltaTime; + let loopCount = this._loopCount; + + const pingPong = ( loop === LoopPingPong ); + + if ( deltaTime === 0 ) { + + if ( loopCount === - 1 ) return time; + + return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time; + + } + + if ( loop === LoopOnce ) { + + if ( loopCount === - 1 ) { + + // just started + + this._loopCount = 0; + this._setEndings( true, true, false ); + + } + + handle_stop: { + + if ( time >= duration ) { + + time = duration; + + } else if ( time < 0 ) { + + time = 0; + + } else { + + this.time = time; + + break handle_stop; + + } + + if ( this.clampWhenFinished ) this.paused = true; + else this.enabled = false; + + this.time = time; + + this._mixer.dispatchEvent( { + type: 'finished', action: this, + direction: deltaTime < 0 ? - 1 : 1 + } ); + + } + + } else { // repetitive Repeat or PingPong + + if ( loopCount === - 1 ) { + + // just started + + if ( deltaTime >= 0 ) { + + loopCount = 0; + + this._setEndings( true, this.repetitions === 0, pingPong ); + + } else { + + // when looping in reverse direction, the initial + // transition through zero counts as a repetition, + // so leave loopCount at -1 + + this._setEndings( this.repetitions === 0, true, pingPong ); + + } + + } + + if ( time >= duration || time < 0 ) { + + // wrap around + + const loopDelta = Math.floor( time / duration ); // signed + time -= duration * loopDelta; + + loopCount += Math.abs( loopDelta ); + + const pending = this.repetitions - loopCount; + + if ( pending <= 0 ) { + + // have to stop (switch state, clamp time, fire event) + + if ( this.clampWhenFinished ) this.paused = true; + else this.enabled = false; + + time = deltaTime > 0 ? duration : 0; + + this.time = time; + + this._mixer.dispatchEvent( { + type: 'finished', action: this, + direction: deltaTime > 0 ? 1 : - 1 + } ); + + } else { + + // keep running + + if ( pending === 1 ) { + + // entering the last round + + const atStart = deltaTime < 0; + this._setEndings( atStart, ! atStart, pingPong ); + + } else { + + this._setEndings( false, false, pingPong ); + + } + + this._loopCount = loopCount; + + this.time = time; + + this._mixer.dispatchEvent( { + type: 'loop', action: this, loopDelta: loopDelta + } ); + + } + + } else { + + this.time = time; + + } + + if ( pingPong && ( loopCount & 1 ) === 1 ) { + + // invert time for the "pong round" + + return duration - time; + + } + + } + + return time; + + } + + _setEndings( atStart, atEnd, pingPong ) { + + const settings = this._interpolantSettings; + + if ( pingPong ) { + + settings.endingStart = ZeroSlopeEnding; + settings.endingEnd = ZeroSlopeEnding; + + } else { + + // assuming for LoopOnce atStart == atEnd == true + + if ( atStart ) { + + settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding; + + } else { + + settings.endingStart = WrapAroundEnding; + + } + + if ( atEnd ) { + + settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding; + + } else { + + settings.endingEnd = WrapAroundEnding; + + } + + } + + } + + _scheduleFading( duration, weightNow, weightThen ) { + + const mixer = this._mixer, now = mixer.time; + let interpolant = this._weightInterpolant; + + if ( interpolant === null ) { + + interpolant = mixer._lendControlInterpolant(); + this._weightInterpolant = interpolant; + + } + + const times = interpolant.parameterPositions, + values = interpolant.sampleValues; + + times[ 0 ] = now; + values[ 0 ] = weightNow; + times[ 1 ] = now + duration; + values[ 1 ] = weightThen; + + return this; + + } + +} + +const _controlInterpolantsResultBuffer = new Float32Array( 1 ); + + +class AnimationMixer extends EventDispatcher { + + constructor( root ) { + + super(); + + this._root = root; + this._initMemoryManager(); + this._accuIndex = 0; + this.time = 0; + this.timeScale = 1.0; + + } + + _bindAction( action, prototypeAction ) { + + const root = action._localRoot || this._root, + tracks = action._clip.tracks, + nTracks = tracks.length, + bindings = action._propertyBindings, + interpolants = action._interpolants, + rootUuid = root.uuid, + bindingsByRoot = this._bindingsByRootAndName; + + let bindingsByName = bindingsByRoot[ rootUuid ]; + + if ( bindingsByName === undefined ) { + + bindingsByName = {}; + bindingsByRoot[ rootUuid ] = bindingsByName; + + } + + for ( let i = 0; i !== nTracks; ++ i ) { + + const track = tracks[ i ], + trackName = track.name; + + let binding = bindingsByName[ trackName ]; + + if ( binding !== undefined ) { + + ++ binding.referenceCount; + bindings[ i ] = binding; + + } else { + + binding = bindings[ i ]; + + if ( binding !== undefined ) { + + // existing binding, make sure the cache knows + + if ( binding._cacheIndex === null ) { + + ++ binding.referenceCount; + this._addInactiveBinding( binding, rootUuid, trackName ); + + } + + continue; + + } + + const path = prototypeAction && prototypeAction. + _propertyBindings[ i ].binding.parsedPath; + + binding = new PropertyMixer( + PropertyBinding.create( root, trackName, path ), + track.ValueTypeName, track.getValueSize() ); + + ++ binding.referenceCount; + this._addInactiveBinding( binding, rootUuid, trackName ); + + bindings[ i ] = binding; + + } + + interpolants[ i ].resultBuffer = binding.buffer; + + } + + } + + _activateAction( action ) { + + if ( ! this._isActiveAction( action ) ) { + + if ( action._cacheIndex === null ) { + + // this action has been forgotten by the cache, but the user + // appears to be still using it -> rebind + + const rootUuid = ( action._localRoot || this._root ).uuid, + clipUuid = action._clip.uuid, + actionsForClip = this._actionsByClip[ clipUuid ]; + + this._bindAction( action, + actionsForClip && actionsForClip.knownActions[ 0 ] ); + + this._addInactiveAction( action, clipUuid, rootUuid ); + + } + + const bindings = action._propertyBindings; + + // increment reference counts / sort out state + for ( let i = 0, n = bindings.length; i !== n; ++ i ) { + + const binding = bindings[ i ]; + + if ( binding.useCount ++ === 0 ) { + + this._lendBinding( binding ); + binding.saveOriginalState(); + + } + + } + + this._lendAction( action ); + + } + + } + + _deactivateAction( action ) { + + if ( this._isActiveAction( action ) ) { + + const bindings = action._propertyBindings; + + // decrement reference counts / sort out state + for ( let i = 0, n = bindings.length; i !== n; ++ i ) { + + const binding = bindings[ i ]; + + if ( -- binding.useCount === 0 ) { + + binding.restoreOriginalState(); + this._takeBackBinding( binding ); + + } + + } + + this._takeBackAction( action ); + + } + + } + + // Memory manager + + _initMemoryManager() { + + this._actions = []; // 'nActiveActions' followed by inactive ones + this._nActiveActions = 0; + + this._actionsByClip = {}; + // inside: + // { + // knownActions: Array< AnimationAction > - used as prototypes + // actionByRoot: AnimationAction - lookup + // } + + + this._bindings = []; // 'nActiveBindings' followed by inactive ones + this._nActiveBindings = 0; + + this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer > + + + this._controlInterpolants = []; // same game as above + this._nActiveControlInterpolants = 0; + + const scope = this; + + this.stats = { + + actions: { + get total() { + + return scope._actions.length; + + }, + get inUse() { + + return scope._nActiveActions; + + } + }, + bindings: { + get total() { + + return scope._bindings.length; + + }, + get inUse() { + + return scope._nActiveBindings; + + } + }, + controlInterpolants: { + get total() { + + return scope._controlInterpolants.length; + + }, + get inUse() { + + return scope._nActiveControlInterpolants; + + } + } + + }; + + } + + // Memory management for AnimationAction objects + + _isActiveAction( action ) { + + const index = action._cacheIndex; + return index !== null && index < this._nActiveActions; + + } + + _addInactiveAction( action, clipUuid, rootUuid ) { + + const actions = this._actions, + actionsByClip = this._actionsByClip; + + let actionsForClip = actionsByClip[ clipUuid ]; + + if ( actionsForClip === undefined ) { + + actionsForClip = { + + knownActions: [ action ], + actionByRoot: {} + + }; + + action._byClipCacheIndex = 0; + + actionsByClip[ clipUuid ] = actionsForClip; + + } else { + + const knownActions = actionsForClip.knownActions; + + action._byClipCacheIndex = knownActions.length; + knownActions.push( action ); + + } + + action._cacheIndex = actions.length; + actions.push( action ); + + actionsForClip.actionByRoot[ rootUuid ] = action; + + } + + _removeInactiveAction( action ) { + + const actions = this._actions, + lastInactiveAction = actions[ actions.length - 1 ], + cacheIndex = action._cacheIndex; + + lastInactiveAction._cacheIndex = cacheIndex; + actions[ cacheIndex ] = lastInactiveAction; + actions.pop(); + + action._cacheIndex = null; + + + const clipUuid = action._clip.uuid, + actionsByClip = this._actionsByClip, + actionsForClip = actionsByClip[ clipUuid ], + knownActionsForClip = actionsForClip.knownActions, + + lastKnownAction = + knownActionsForClip[ knownActionsForClip.length - 1 ], + + byClipCacheIndex = action._byClipCacheIndex; + + lastKnownAction._byClipCacheIndex = byClipCacheIndex; + knownActionsForClip[ byClipCacheIndex ] = lastKnownAction; + knownActionsForClip.pop(); + + action._byClipCacheIndex = null; + + + const actionByRoot = actionsForClip.actionByRoot, + rootUuid = ( action._localRoot || this._root ).uuid; + + delete actionByRoot[ rootUuid ]; + + if ( knownActionsForClip.length === 0 ) { + + delete actionsByClip[ clipUuid ]; + + } + + this._removeInactiveBindingsForAction( action ); + + } + + _removeInactiveBindingsForAction( action ) { + + const bindings = action._propertyBindings; + + for ( let i = 0, n = bindings.length; i !== n; ++ i ) { + + const binding = bindings[ i ]; + + if ( -- binding.referenceCount === 0 ) { + + this._removeInactiveBinding( binding ); + + } + + } + + } + + _lendAction( action ) { + + // [ active actions | inactive actions ] + // [ active actions >| inactive actions ] + // s a + // <-swap-> + // a s + + const actions = this._actions, + prevIndex = action._cacheIndex, + + lastActiveIndex = this._nActiveActions ++, + + firstInactiveAction = actions[ lastActiveIndex ]; + + action._cacheIndex = lastActiveIndex; + actions[ lastActiveIndex ] = action; + + firstInactiveAction._cacheIndex = prevIndex; + actions[ prevIndex ] = firstInactiveAction; + + } + + _takeBackAction( action ) { + + // [ active actions | inactive actions ] + // [ active actions |< inactive actions ] + // a s + // <-swap-> + // s a + + const actions = this._actions, + prevIndex = action._cacheIndex, + + firstInactiveIndex = -- this._nActiveActions, + + lastActiveAction = actions[ firstInactiveIndex ]; + + action._cacheIndex = firstInactiveIndex; + actions[ firstInactiveIndex ] = action; + + lastActiveAction._cacheIndex = prevIndex; + actions[ prevIndex ] = lastActiveAction; + + } + + // Memory management for PropertyMixer objects + + _addInactiveBinding( binding, rootUuid, trackName ) { + + const bindingsByRoot = this._bindingsByRootAndName, + bindings = this._bindings; + + let bindingByName = bindingsByRoot[ rootUuid ]; + + if ( bindingByName === undefined ) { + + bindingByName = {}; + bindingsByRoot[ rootUuid ] = bindingByName; + + } + + bindingByName[ trackName ] = binding; + + binding._cacheIndex = bindings.length; + bindings.push( binding ); + + } + + _removeInactiveBinding( binding ) { + + const bindings = this._bindings, + propBinding = binding.binding, + rootUuid = propBinding.rootNode.uuid, + trackName = propBinding.path, + bindingsByRoot = this._bindingsByRootAndName, + bindingByName = bindingsByRoot[ rootUuid ], + + lastInactiveBinding = bindings[ bindings.length - 1 ], + cacheIndex = binding._cacheIndex; + + lastInactiveBinding._cacheIndex = cacheIndex; + bindings[ cacheIndex ] = lastInactiveBinding; + bindings.pop(); + + delete bindingByName[ trackName ]; + + if ( Object.keys( bindingByName ).length === 0 ) { + + delete bindingsByRoot[ rootUuid ]; + + } + + } + + _lendBinding( binding ) { + + const bindings = this._bindings, + prevIndex = binding._cacheIndex, + + lastActiveIndex = this._nActiveBindings ++, + + firstInactiveBinding = bindings[ lastActiveIndex ]; + + binding._cacheIndex = lastActiveIndex; + bindings[ lastActiveIndex ] = binding; + + firstInactiveBinding._cacheIndex = prevIndex; + bindings[ prevIndex ] = firstInactiveBinding; + + } + + _takeBackBinding( binding ) { + + const bindings = this._bindings, + prevIndex = binding._cacheIndex, + + firstInactiveIndex = -- this._nActiveBindings, + + lastActiveBinding = bindings[ firstInactiveIndex ]; + + binding._cacheIndex = firstInactiveIndex; + bindings[ firstInactiveIndex ] = binding; + + lastActiveBinding._cacheIndex = prevIndex; + bindings[ prevIndex ] = lastActiveBinding; + + } + + + // Memory management of Interpolants for weight and time scale + + _lendControlInterpolant() { + + const interpolants = this._controlInterpolants, + lastActiveIndex = this._nActiveControlInterpolants ++; + + let interpolant = interpolants[ lastActiveIndex ]; + + if ( interpolant === undefined ) { + + interpolant = new LinearInterpolant( + new Float32Array( 2 ), new Float32Array( 2 ), + 1, _controlInterpolantsResultBuffer ); + + interpolant.__cacheIndex = lastActiveIndex; + interpolants[ lastActiveIndex ] = interpolant; + + } + + return interpolant; + + } + + _takeBackControlInterpolant( interpolant ) { + + const interpolants = this._controlInterpolants, + prevIndex = interpolant.__cacheIndex, + + firstInactiveIndex = -- this._nActiveControlInterpolants, + + lastActiveInterpolant = interpolants[ firstInactiveIndex ]; + + interpolant.__cacheIndex = firstInactiveIndex; + interpolants[ firstInactiveIndex ] = interpolant; + + lastActiveInterpolant.__cacheIndex = prevIndex; + interpolants[ prevIndex ] = lastActiveInterpolant; + + } + + // return an action for a clip optionally using a custom root target + // object (this method allocates a lot of dynamic memory in case a + // previously unknown clip/root combination is specified) + clipAction( clip, optionalRoot, blendMode ) { + + const root = optionalRoot || this._root, + rootUuid = root.uuid; + + let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip; + + const clipUuid = clipObject !== null ? clipObject.uuid : clip; + + const actionsForClip = this._actionsByClip[ clipUuid ]; + let prototypeAction = null; + + if ( blendMode === undefined ) { + + if ( clipObject !== null ) { + + blendMode = clipObject.blendMode; + + } else { + + blendMode = NormalAnimationBlendMode; + + } + + } + + if ( actionsForClip !== undefined ) { + + const existingAction = actionsForClip.actionByRoot[ rootUuid ]; + + if ( existingAction !== undefined && existingAction.blendMode === blendMode ) { + + return existingAction; + + } + + // we know the clip, so we don't have to parse all + // the bindings again but can just copy + prototypeAction = actionsForClip.knownActions[ 0 ]; + + // also, take the clip from the prototype action + if ( clipObject === null ) + clipObject = prototypeAction._clip; + + } + + // clip must be known when specified via string + if ( clipObject === null ) return null; + + // allocate all resources required to run it + const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode ); + + this._bindAction( newAction, prototypeAction ); + + // and make the action known to the memory manager + this._addInactiveAction( newAction, clipUuid, rootUuid ); + + return newAction; + + } + + // get an existing action + existingAction( clip, optionalRoot ) { + + const root = optionalRoot || this._root, + rootUuid = root.uuid, + + clipObject = typeof clip === 'string' ? + AnimationClip.findByName( root, clip ) : clip, + + clipUuid = clipObject ? clipObject.uuid : clip, + + actionsForClip = this._actionsByClip[ clipUuid ]; + + if ( actionsForClip !== undefined ) { + + return actionsForClip.actionByRoot[ rootUuid ] || null; + + } + + return null; + + } + + // deactivates all previously scheduled actions + stopAllAction() { + + const actions = this._actions, + nActions = this._nActiveActions; + + for ( let i = nActions - 1; i >= 0; -- i ) { + + actions[ i ].stop(); + + } + + return this; + + } + + // advance the time and update apply the animation + update( deltaTime ) { + + deltaTime *= this.timeScale; + + const actions = this._actions, + nActions = this._nActiveActions, + + time = this.time += deltaTime, + timeDirection = Math.sign( deltaTime ), + + accuIndex = this._accuIndex ^= 1; + + // run active actions + + for ( let i = 0; i !== nActions; ++ i ) { + + const action = actions[ i ]; + + action._update( time, deltaTime, timeDirection, accuIndex ); + + } + + // update scene graph + + const bindings = this._bindings, + nBindings = this._nActiveBindings; + + for ( let i = 0; i !== nBindings; ++ i ) { + + bindings[ i ].apply( accuIndex ); + + } + + return this; + + } + + // Allows you to seek to a specific time in an animation. + setTime( timeInSeconds ) { + + this.time = 0; // Zero out time attribute for AnimationMixer object; + for ( let i = 0; i < this._actions.length; i ++ ) { + + this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects. + + } + + return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object. + + } + + // return this mixer's root target object + getRoot() { + + return this._root; + + } + + // free all resources specific to a particular clip + uncacheClip( clip ) { + + const actions = this._actions, + clipUuid = clip.uuid, + actionsByClip = this._actionsByClip, + actionsForClip = actionsByClip[ clipUuid ]; + + if ( actionsForClip !== undefined ) { + + // note: just calling _removeInactiveAction would mess up the + // iteration state and also require updating the state we can + // just throw away + + const actionsToRemove = actionsForClip.knownActions; + + for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) { + + const action = actionsToRemove[ i ]; + + this._deactivateAction( action ); + + const cacheIndex = action._cacheIndex, + lastInactiveAction = actions[ actions.length - 1 ]; + + action._cacheIndex = null; + action._byClipCacheIndex = null; + + lastInactiveAction._cacheIndex = cacheIndex; + actions[ cacheIndex ] = lastInactiveAction; + actions.pop(); + + this._removeInactiveBindingsForAction( action ); + + } + + delete actionsByClip[ clipUuid ]; + + } + + } + + // free all resources specific to a particular root target object + uncacheRoot( root ) { + + const rootUuid = root.uuid, + actionsByClip = this._actionsByClip; + + for ( const clipUuid in actionsByClip ) { + + const actionByRoot = actionsByClip[ clipUuid ].actionByRoot, + action = actionByRoot[ rootUuid ]; + + if ( action !== undefined ) { + + this._deactivateAction( action ); + this._removeInactiveAction( action ); + + } + + } + + const bindingsByRoot = this._bindingsByRootAndName, + bindingByName = bindingsByRoot[ rootUuid ]; + + if ( bindingByName !== undefined ) { + + for ( const trackName in bindingByName ) { + + const binding = bindingByName[ trackName ]; + binding.restoreOriginalState(); + this._removeInactiveBinding( binding ); + + } + + } + + } + + // remove a targeted clip from the cache + uncacheAction( clip, optionalRoot ) { + + const action = this.existingAction( clip, optionalRoot ); + + if ( action !== null ) { + + this._deactivateAction( action ); + this._removeInactiveAction( action ); + + } + + } + +} + +class Uniform { + + constructor( value ) { + + this.value = value; + + } + + clone() { + + return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() ); + + } + +} + +let _id = 0; + +class UniformsGroup extends EventDispatcher { + + constructor() { + + super(); + + this.isUniformsGroup = true; + + Object.defineProperty( this, 'id', { value: _id ++ } ); + + this.name = ''; + + this.usage = StaticDrawUsage; + this.uniforms = []; + + } + + add( uniform ) { + + this.uniforms.push( uniform ); + + return this; + + } + + remove( uniform ) { + + const index = this.uniforms.indexOf( uniform ); + + if ( index !== - 1 ) this.uniforms.splice( index, 1 ); + + return this; + + } + + setName( name ) { + + this.name = name; + + return this; + + } + + setUsage( value ) { + + this.usage = value; + + return this; + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + return this; + + } + + copy( source ) { + + this.name = source.name; + this.usage = source.usage; + + const uniformsSource = source.uniforms; + + this.uniforms.length = 0; + + for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) { + + const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ]; + + for ( let j = 0; j < uniforms.length; j ++ ) { + + this.uniforms.push( uniforms[ j ].clone() ); + + } + + } + + return this; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +class InstancedInterleavedBuffer extends InterleavedBuffer { + + constructor( array, stride, meshPerAttribute = 1 ) { + + super( array, stride ); + + this.isInstancedInterleavedBuffer = true; + + this.meshPerAttribute = meshPerAttribute; + + } + + copy( source ) { + + super.copy( source ); + + this.meshPerAttribute = source.meshPerAttribute; + + return this; + + } + + clone( data ) { + + const ib = super.clone( data ); + + ib.meshPerAttribute = this.meshPerAttribute; + + return ib; + + } + + toJSON( data ) { + + const json = super.toJSON( data ); + + json.isInstancedInterleavedBuffer = true; + json.meshPerAttribute = this.meshPerAttribute; + + return json; + + } + +} + +class GLBufferAttribute { + + constructor( buffer, type, itemSize, elementSize, count ) { + + this.isGLBufferAttribute = true; + + this.name = ''; + + this.buffer = buffer; + this.type = type; + this.itemSize = itemSize; + this.elementSize = elementSize; + this.count = count; + + this.version = 0; + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + setBuffer( buffer ) { + + this.buffer = buffer; + + return this; + + } + + setType( type, elementSize ) { + + this.type = type; + this.elementSize = elementSize; + + return this; + + } + + setItemSize( itemSize ) { + + this.itemSize = itemSize; + + return this; + + } + + setCount( count ) { + + this.count = count; + + return this; + + } + +} + +const _matrix = /*@__PURE__*/ new Matrix4(); + +class Raycaster { + + constructor( origin, direction, near = 0, far = Infinity ) { + + this.ray = new Ray( origin, direction ); + // direction is assumed to be normalized (for accurate distance calculations) + + this.near = near; + this.far = far; + this.camera = null; + this.layers = new Layers(); + + this.params = { + Mesh: {}, + Line: { threshold: 1 }, + LOD: {}, + Points: { threshold: 1 }, + Sprite: {} + }; + + } + + set( origin, direction ) { + + // direction is assumed to be normalized (for accurate distance calculations) + + this.ray.set( origin, direction ); + + } + + setFromCamera( coords, camera ) { + + if ( camera.isPerspectiveCamera ) { + + this.ray.origin.setFromMatrixPosition( camera.matrixWorld ); + this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize(); + this.camera = camera; + + } else if ( camera.isOrthographicCamera ) { + + this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera + this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ); + this.camera = camera; + + } else { + + console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type ); + + } + + } + + setFromXRController( controller ) { + + _matrix.identity().extractRotation( controller.matrixWorld ); + + this.ray.origin.setFromMatrixPosition( controller.matrixWorld ); + this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix ); + + return this; + + } + + intersectObject( object, recursive = true, intersects = [] ) { + + intersect( object, this, intersects, recursive ); + + intersects.sort( ascSort ); + + return intersects; + + } + + intersectObjects( objects, recursive = true, intersects = [] ) { + + for ( let i = 0, l = objects.length; i < l; i ++ ) { + + intersect( objects[ i ], this, intersects, recursive ); + + } + + intersects.sort( ascSort ); + + return intersects; + + } + +} + +function ascSort( a, b ) { + + return a.distance - b.distance; + +} + +function intersect( object, raycaster, intersects, recursive ) { + + let propagate = true; + + if ( object.layers.test( raycaster.layers ) ) { + + const result = object.raycast( raycaster, intersects ); + + if ( result === false ) propagate = false; + + } + + if ( propagate === true && recursive === true ) { + + const children = object.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + intersect( children[ i ], raycaster, intersects, true ); + + } + + } + +} + +/** + * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system + * + * phi (the polar angle) is measured from the positive y-axis. The positive y-axis is up. + * theta (the azimuthal angle) is measured from the positive z-axis. + */ +class Spherical { + + constructor( radius = 1, phi = 0, theta = 0 ) { + + this.radius = radius; + this.phi = phi; // polar angle + this.theta = theta; // azimuthal angle + + return this; + + } + + set( radius, phi, theta ) { + + this.radius = radius; + this.phi = phi; + this.theta = theta; + + return this; + + } + + copy( other ) { + + this.radius = other.radius; + this.phi = other.phi; + this.theta = other.theta; + + return this; + + } + + // restrict phi to be between EPS and PI-EPS + makeSafe() { + + const EPS = 0.000001; + this.phi = clamp( this.phi, EPS, Math.PI - EPS ); + + return this; + + } + + setFromVector3( v ) { + + return this.setFromCartesianCoords( v.x, v.y, v.z ); + + } + + setFromCartesianCoords( x, y, z ) { + + this.radius = Math.sqrt( x * x + y * y + z * z ); + + if ( this.radius === 0 ) { + + this.theta = 0; + this.phi = 0; + + } else { + + this.theta = Math.atan2( x, z ); + this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) ); + + } + + return this; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +/** + * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system + */ + +class Cylindrical { + + constructor( radius = 1, theta = 0, y = 0 ) { + + this.radius = radius; // distance from the origin to a point in the x-z plane + this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis + this.y = y; // height above the x-z plane + + return this; + + } + + set( radius, theta, y ) { + + this.radius = radius; + this.theta = theta; + this.y = y; + + return this; + + } + + copy( other ) { + + this.radius = other.radius; + this.theta = other.theta; + this.y = other.y; + + return this; + + } + + setFromVector3( v ) { + + return this.setFromCartesianCoords( v.x, v.y, v.z ); + + } + + setFromCartesianCoords( x, y, z ) { + + this.radius = Math.sqrt( x * x + z * z ); + this.theta = Math.atan2( x, z ); + this.y = y; + + return this; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +class Matrix2 { + + constructor( n11, n12, n21, n22 ) { + + Matrix2.prototype.isMatrix2 = true; + + this.elements = [ + 1, 0, + 0, 1, + ]; + + if ( n11 !== undefined ) { + + this.set( n11, n12, n21, n22 ); + + } + + } + + identity() { + + this.set( + 1, 0, + 0, 1, + ); + + return this; + + } + + fromArray( array, offset = 0 ) { + + for ( let i = 0; i < 4; i ++ ) { + + this.elements[ i ] = array[ i + offset ]; + + } + + return this; + + } + + set( n11, n12, n21, n22 ) { + + const te = this.elements; + + te[ 0 ] = n11; te[ 2 ] = n12; + te[ 1 ] = n21; te[ 3 ] = n22; + + return this; + + } + +} + +const _vector$4 = /*@__PURE__*/ new Vector2(); + +class Box2 { + + constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) { + + this.isBox2 = true; + + this.min = min; + this.max = max; + + } + + set( min, max ) { + + this.min.copy( min ); + this.max.copy( max ); + + return this; + + } + + setFromPoints( points ) { + + this.makeEmpty(); + + for ( let i = 0, il = points.length; i < il; i ++ ) { + + this.expandByPoint( points[ i ] ); + + } + + return this; + + } + + setFromCenterAndSize( center, size ) { + + const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 ); + this.min.copy( center ).sub( halfSize ); + this.max.copy( center ).add( halfSize ); + + return this; + + } + + clone() { + + return new this.constructor().copy( this ); + + } + + copy( box ) { + + this.min.copy( box.min ); + this.max.copy( box.max ); + + return this; + + } + + makeEmpty() { + + this.min.x = this.min.y = + Infinity; + this.max.x = this.max.y = - Infinity; + + return this; + + } + + isEmpty() { + + // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes + + return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ); + + } + + getCenter( target ) { + + return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 ); + + } + + getSize( target ) { + + return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min ); + + } + + expandByPoint( point ) { + + this.min.min( point ); + this.max.max( point ); + + return this; + + } + + expandByVector( vector ) { + + this.min.sub( vector ); + this.max.add( vector ); + + return this; + + } + + expandByScalar( scalar ) { + + this.min.addScalar( - scalar ); + this.max.addScalar( scalar ); + + return this; + + } + + containsPoint( point ) { + + return point.x >= this.min.x && point.x <= this.max.x && + point.y >= this.min.y && point.y <= this.max.y; + + } + + containsBox( box ) { + + return this.min.x <= box.min.x && box.max.x <= this.max.x && + this.min.y <= box.min.y && box.max.y <= this.max.y; + + } + + getParameter( point, target ) { + + // This can potentially have a divide by zero if the box + // has a size dimension of 0. + + return target.set( + ( point.x - this.min.x ) / ( this.max.x - this.min.x ), + ( point.y - this.min.y ) / ( this.max.y - this.min.y ) + ); + + } + + intersectsBox( box ) { + + // using 4 splitting planes to rule out intersections + + return box.max.x >= this.min.x && box.min.x <= this.max.x && + box.max.y >= this.min.y && box.min.y <= this.max.y; + + } + + clampPoint( point, target ) { + + return target.copy( point ).clamp( this.min, this.max ); + + } + + distanceToPoint( point ) { + + return this.clampPoint( point, _vector$4 ).distanceTo( point ); + + } + + intersect( box ) { + + this.min.max( box.min ); + this.max.min( box.max ); + + if ( this.isEmpty() ) this.makeEmpty(); + + return this; + + } + + union( box ) { + + this.min.min( box.min ); + this.max.max( box.max ); + + return this; + + } + + translate( offset ) { + + this.min.add( offset ); + this.max.add( offset ); + + return this; + + } + + equals( box ) { + + return box.min.equals( this.min ) && box.max.equals( this.max ); + + } + +} + +const _startP = /*@__PURE__*/ new Vector3(); +const _startEnd = /*@__PURE__*/ new Vector3(); + +class Line3 { + + constructor( start = new Vector3(), end = new Vector3() ) { + + this.start = start; + this.end = end; + + } + + set( start, end ) { + + this.start.copy( start ); + this.end.copy( end ); + + return this; + + } + + copy( line ) { + + this.start.copy( line.start ); + this.end.copy( line.end ); + + return this; + + } + + getCenter( target ) { + + return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 ); + + } + + delta( target ) { + + return target.subVectors( this.end, this.start ); + + } + + distanceSq() { + + return this.start.distanceToSquared( this.end ); + + } + + distance() { + + return this.start.distanceTo( this.end ); + + } + + at( t, target ) { + + return this.delta( target ).multiplyScalar( t ).add( this.start ); + + } + + closestPointToPointParameter( point, clampToLine ) { + + _startP.subVectors( point, this.start ); + _startEnd.subVectors( this.end, this.start ); + + const startEnd2 = _startEnd.dot( _startEnd ); + const startEnd_startP = _startEnd.dot( _startP ); + + let t = startEnd_startP / startEnd2; + + if ( clampToLine ) { + + t = clamp( t, 0, 1 ); + + } + + return t; + + } + + closestPointToPoint( point, clampToLine, target ) { + + const t = this.closestPointToPointParameter( point, clampToLine ); + + return this.delta( target ).multiplyScalar( t ).add( this.start ); + + } + + applyMatrix4( matrix ) { + + this.start.applyMatrix4( matrix ); + this.end.applyMatrix4( matrix ); + + return this; + + } + + equals( line ) { + + return line.start.equals( this.start ) && line.end.equals( this.end ); + + } + + clone() { + + return new this.constructor().copy( this ); + + } + +} + +const _vector$3 = /*@__PURE__*/ new Vector3(); + +class SpotLightHelper extends Object3D { + + constructor( light, color ) { + + super(); + + this.light = light; + + this.matrixAutoUpdate = false; + + this.color = color; + + this.type = 'SpotLightHelper'; + + const geometry = new BufferGeometry(); + + const positions = [ + 0, 0, 0, 0, 0, 1, + 0, 0, 0, 1, 0, 1, + 0, 0, 0, - 1, 0, 1, + 0, 0, 0, 0, 1, 1, + 0, 0, 0, 0, - 1, 1 + ]; + + for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) { + + const p1 = ( i / l ) * Math.PI * 2; + const p2 = ( j / l ) * Math.PI * 2; + + positions.push( + Math.cos( p1 ), Math.sin( p1 ), 1, + Math.cos( p2 ), Math.sin( p2 ), 1 + ); + + } + + geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + + const material = new LineBasicMaterial( { fog: false, toneMapped: false } ); + + this.cone = new LineSegments( geometry, material ); + this.add( this.cone ); + + this.update(); + + } + + dispose() { + + this.cone.geometry.dispose(); + this.cone.material.dispose(); + + } + + update() { + + this.light.updateWorldMatrix( true, false ); + this.light.target.updateWorldMatrix( true, false ); + + // update the local matrix based on the parent and light target transforms + if ( this.parent ) { + + this.parent.updateWorldMatrix( true ); + + this.matrix + .copy( this.parent.matrixWorld ) + .invert() + .multiply( this.light.matrixWorld ); + + } else { + + this.matrix.copy( this.light.matrixWorld ); + + } + + this.matrixWorld.copy( this.light.matrixWorld ); + + const coneLength = this.light.distance ? this.light.distance : 1000; + const coneWidth = coneLength * Math.tan( this.light.angle ); + + this.cone.scale.set( coneWidth, coneWidth, coneLength ); + + _vector$3.setFromMatrixPosition( this.light.target.matrixWorld ); + + this.cone.lookAt( _vector$3 ); + + if ( this.color !== undefined ) { + + this.cone.material.color.set( this.color ); + + } else { + + this.cone.material.color.copy( this.light.color ); + + } + + } + +} + +const _vector$2 = /*@__PURE__*/ new Vector3(); +const _boneMatrix = /*@__PURE__*/ new Matrix4(); +const _matrixWorldInv = /*@__PURE__*/ new Matrix4(); + + +class SkeletonHelper extends LineSegments { + + constructor( object ) { + + const bones = getBoneList( object ); + + const geometry = new BufferGeometry(); + + const vertices = []; + const colors = []; + + const color1 = new Color( 0, 0, 1 ); + const color2 = new Color( 0, 1, 0 ); + + for ( let i = 0; i < bones.length; i ++ ) { + + const bone = bones[ i ]; + + if ( bone.parent && bone.parent.isBone ) { + + vertices.push( 0, 0, 0 ); + vertices.push( 0, 0, 0 ); + colors.push( color1.r, color1.g, color1.b ); + colors.push( color2.r, color2.g, color2.b ); + + } + + } + + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } ); + + super( geometry, material ); + + this.isSkeletonHelper = true; + + this.type = 'SkeletonHelper'; + + this.root = object; + this.bones = bones; + + this.matrix = object.matrixWorld; + this.matrixAutoUpdate = false; + + } + + updateMatrixWorld( force ) { + + const bones = this.bones; + + const geometry = this.geometry; + const position = geometry.getAttribute( 'position' ); + + _matrixWorldInv.copy( this.root.matrixWorld ).invert(); + + for ( let i = 0, j = 0; i < bones.length; i ++ ) { + + const bone = bones[ i ]; + + if ( bone.parent && bone.parent.isBone ) { + + _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld ); + _vector$2.setFromMatrixPosition( _boneMatrix ); + position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z ); + + _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld ); + _vector$2.setFromMatrixPosition( _boneMatrix ); + position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z ); + + j += 2; + + } + + } + + geometry.getAttribute( 'position' ).needsUpdate = true; + + super.updateMatrixWorld( force ); + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + + +function getBoneList( object ) { + + const boneList = []; + + if ( object.isBone === true ) { + + boneList.push( object ); + + } + + for ( let i = 0; i < object.children.length; i ++ ) { + + boneList.push.apply( boneList, getBoneList( object.children[ i ] ) ); + + } + + return boneList; + +} + +class PointLightHelper extends Mesh { + + constructor( light, sphereSize, color ) { + + const geometry = new SphereGeometry( sphereSize, 4, 2 ); + const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } ); + + super( geometry, material ); + + this.light = light; + + this.color = color; + + this.type = 'PointLightHelper'; + + this.matrix = this.light.matrixWorld; + this.matrixAutoUpdate = false; + + this.update(); + + + /* + // TODO: delete this comment? + const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 ); + const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } ); + + this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial ); + this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial ); + + const d = light.distance; + + if ( d === 0.0 ) { + + this.lightDistance.visible = false; + + } else { + + this.lightDistance.scale.set( d, d, d ); + + } + + this.add( this.lightDistance ); + */ + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + + update() { + + this.light.updateWorldMatrix( true, false ); + + if ( this.color !== undefined ) { + + this.material.color.set( this.color ); + + } else { + + this.material.color.copy( this.light.color ); + + } + + /* + const d = this.light.distance; + + if ( d === 0.0 ) { + + this.lightDistance.visible = false; + + } else { + + this.lightDistance.visible = true; + this.lightDistance.scale.set( d, d, d ); + + } + */ + + } + +} + +const _vector$1 = /*@__PURE__*/ new Vector3(); +const _color1 = /*@__PURE__*/ new Color(); +const _color2 = /*@__PURE__*/ new Color(); + +class HemisphereLightHelper extends Object3D { + + constructor( light, size, color ) { + + super(); + + this.light = light; + + this.matrix = light.matrixWorld; + this.matrixAutoUpdate = false; + + this.color = color; + + this.type = 'HemisphereLightHelper'; + + const geometry = new OctahedronGeometry( size ); + geometry.rotateY( Math.PI * 0.5 ); + + this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } ); + if ( this.color === undefined ) this.material.vertexColors = true; + + const position = geometry.getAttribute( 'position' ); + const colors = new Float32Array( position.count * 3 ); + + geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) ); + + this.add( new Mesh( geometry, this.material ) ); + + this.update(); + + } + + dispose() { + + this.children[ 0 ].geometry.dispose(); + this.children[ 0 ].material.dispose(); + + } + + update() { + + const mesh = this.children[ 0 ]; + + if ( this.color !== undefined ) { + + this.material.color.set( this.color ); + + } else { + + const colors = mesh.geometry.getAttribute( 'color' ); + + _color1.copy( this.light.color ); + _color2.copy( this.light.groundColor ); + + for ( let i = 0, l = colors.count; i < l; i ++ ) { + + const color = ( i < ( l / 2 ) ) ? _color1 : _color2; + + colors.setXYZ( i, color.r, color.g, color.b ); + + } + + colors.needsUpdate = true; + + } + + this.light.updateWorldMatrix( true, false ); + + mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() ); + + } + +} + +class GridHelper extends LineSegments { + + constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) { + + color1 = new Color( color1 ); + color2 = new Color( color2 ); + + const center = divisions / 2; + const step = size / divisions; + const halfSize = size / 2; + + const vertices = [], colors = []; + + for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) { + + vertices.push( - halfSize, 0, k, halfSize, 0, k ); + vertices.push( k, 0, - halfSize, k, 0, halfSize ); + + const color = i === center ? color1 : color2; + + color.toArray( colors, j ); j += 3; + color.toArray( colors, j ); j += 3; + color.toArray( colors, j ); j += 3; + color.toArray( colors, j ); j += 3; + + } + + const geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } ); + + super( geometry, material ); + + this.type = 'GridHelper'; + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + +class PolarGridHelper extends LineSegments { + + constructor( radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) { + + color1 = new Color( color1 ); + color2 = new Color( color2 ); + + const vertices = []; + const colors = []; + + // create the sectors + + if ( sectors > 1 ) { + + for ( let i = 0; i < sectors; i ++ ) { + + const v = ( i / sectors ) * ( Math.PI * 2 ); + + const x = Math.sin( v ) * radius; + const z = Math.cos( v ) * radius; + + vertices.push( 0, 0, 0 ); + vertices.push( x, 0, z ); + + const color = ( i & 1 ) ? color1 : color2; + + colors.push( color.r, color.g, color.b ); + colors.push( color.r, color.g, color.b ); + + } + + } + + // create the rings + + for ( let i = 0; i < rings; i ++ ) { + + const color = ( i & 1 ) ? color1 : color2; + + const r = radius - ( radius / rings * i ); + + for ( let j = 0; j < divisions; j ++ ) { + + // first vertex + + let v = ( j / divisions ) * ( Math.PI * 2 ); + + let x = Math.sin( v ) * r; + let z = Math.cos( v ) * r; + + vertices.push( x, 0, z ); + colors.push( color.r, color.g, color.b ); + + // second vertex + + v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 ); + + x = Math.sin( v ) * r; + z = Math.cos( v ) * r; + + vertices.push( x, 0, z ); + colors.push( color.r, color.g, color.b ); + + } + + } + + const geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } ); + + super( geometry, material ); + + this.type = 'PolarGridHelper'; + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + +const _v1 = /*@__PURE__*/ new Vector3(); +const _v2 = /*@__PURE__*/ new Vector3(); +const _v3 = /*@__PURE__*/ new Vector3(); + +class DirectionalLightHelper extends Object3D { + + constructor( light, size, color ) { + + super(); + + this.light = light; + + this.matrix = light.matrixWorld; + this.matrixAutoUpdate = false; + + this.color = color; + + this.type = 'DirectionalLightHelper'; + + if ( size === undefined ) size = 1; + + let geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( [ + - size, size, 0, + size, size, 0, + size, - size, 0, + - size, - size, 0, + - size, size, 0 + ], 3 ) ); + + const material = new LineBasicMaterial( { fog: false, toneMapped: false } ); + + this.lightPlane = new Line( geometry, material ); + this.add( this.lightPlane ); + + geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) ); + + this.targetLine = new Line( geometry, material ); + this.add( this.targetLine ); + + this.update(); + + } + + dispose() { + + this.lightPlane.geometry.dispose(); + this.lightPlane.material.dispose(); + this.targetLine.geometry.dispose(); + this.targetLine.material.dispose(); + + } + + update() { + + this.light.updateWorldMatrix( true, false ); + this.light.target.updateWorldMatrix( true, false ); + + _v1.setFromMatrixPosition( this.light.matrixWorld ); + _v2.setFromMatrixPosition( this.light.target.matrixWorld ); + _v3.subVectors( _v2, _v1 ); + + this.lightPlane.lookAt( _v2 ); + + if ( this.color !== undefined ) { + + this.lightPlane.material.color.set( this.color ); + this.targetLine.material.color.set( this.color ); + + } else { + + this.lightPlane.material.color.copy( this.light.color ); + this.targetLine.material.color.copy( this.light.color ); + + } + + this.targetLine.lookAt( _v2 ); + this.targetLine.scale.z = _v3.length(); + + } + +} + +const _vector = /*@__PURE__*/ new Vector3(); +const _camera = /*@__PURE__*/ new Camera(); + +/** + * - shows frustum, line of sight and up of the camera + * - suitable for fast updates + * - based on frustum visualization in lightgl.js shadowmap example + * https://github.com/evanw/lightgl.js/blob/master/tests/shadowmap.html + */ + +class CameraHelper extends LineSegments { + + constructor( camera ) { + + const geometry = new BufferGeometry(); + const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } ); + + const vertices = []; + const colors = []; + + const pointMap = {}; + + // near + + addLine( 'n1', 'n2' ); + addLine( 'n2', 'n4' ); + addLine( 'n4', 'n3' ); + addLine( 'n3', 'n1' ); + + // far + + addLine( 'f1', 'f2' ); + addLine( 'f2', 'f4' ); + addLine( 'f4', 'f3' ); + addLine( 'f3', 'f1' ); + + // sides + + addLine( 'n1', 'f1' ); + addLine( 'n2', 'f2' ); + addLine( 'n3', 'f3' ); + addLine( 'n4', 'f4' ); + + // cone + + addLine( 'p', 'n1' ); + addLine( 'p', 'n2' ); + addLine( 'p', 'n3' ); + addLine( 'p', 'n4' ); + + // up + + addLine( 'u1', 'u2' ); + addLine( 'u2', 'u3' ); + addLine( 'u3', 'u1' ); + + // target + + addLine( 'c', 't' ); + addLine( 'p', 'c' ); + + // cross + + addLine( 'cn1', 'cn2' ); + addLine( 'cn3', 'cn4' ); + + addLine( 'cf1', 'cf2' ); + addLine( 'cf3', 'cf4' ); + + function addLine( a, b ) { + + addPoint( a ); + addPoint( b ); + + } + + function addPoint( id ) { + + vertices.push( 0, 0, 0 ); + colors.push( 0, 0, 0 ); + + if ( pointMap[ id ] === undefined ) { + + pointMap[ id ] = []; + + } + + pointMap[ id ].push( ( vertices.length / 3 ) - 1 ); + + } + + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + super( geometry, material ); + + this.type = 'CameraHelper'; + + this.camera = camera; + if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix(); + + this.matrix = camera.matrixWorld; + this.matrixAutoUpdate = false; + + this.pointMap = pointMap; + + this.update(); + + // colors + + const colorFrustum = new Color( 0xffaa00 ); + const colorCone = new Color( 0xff0000 ); + const colorUp = new Color( 0x00aaff ); + const colorTarget = new Color( 0xffffff ); + const colorCross = new Color( 0x333333 ); + + this.setColors( colorFrustum, colorCone, colorUp, colorTarget, colorCross ); + + } + + setColors( frustum, cone, up, target, cross ) { + + const geometry = this.geometry; + + const colorAttribute = geometry.getAttribute( 'color' ); + + // near + + colorAttribute.setXYZ( 0, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 1, frustum.r, frustum.g, frustum.b ); // n1, n2 + colorAttribute.setXYZ( 2, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 3, frustum.r, frustum.g, frustum.b ); // n2, n4 + colorAttribute.setXYZ( 4, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 5, frustum.r, frustum.g, frustum.b ); // n4, n3 + colorAttribute.setXYZ( 6, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 7, frustum.r, frustum.g, frustum.b ); // n3, n1 + + // far + + colorAttribute.setXYZ( 8, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 9, frustum.r, frustum.g, frustum.b ); // f1, f2 + colorAttribute.setXYZ( 10, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 11, frustum.r, frustum.g, frustum.b ); // f2, f4 + colorAttribute.setXYZ( 12, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 13, frustum.r, frustum.g, frustum.b ); // f4, f3 + colorAttribute.setXYZ( 14, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 15, frustum.r, frustum.g, frustum.b ); // f3, f1 + + // sides + + colorAttribute.setXYZ( 16, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 17, frustum.r, frustum.g, frustum.b ); // n1, f1 + colorAttribute.setXYZ( 18, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 19, frustum.r, frustum.g, frustum.b ); // n2, f2 + colorAttribute.setXYZ( 20, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 21, frustum.r, frustum.g, frustum.b ); // n3, f3 + colorAttribute.setXYZ( 22, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 23, frustum.r, frustum.g, frustum.b ); // n4, f4 + + // cone + + colorAttribute.setXYZ( 24, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 25, cone.r, cone.g, cone.b ); // p, n1 + colorAttribute.setXYZ( 26, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 27, cone.r, cone.g, cone.b ); // p, n2 + colorAttribute.setXYZ( 28, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 29, cone.r, cone.g, cone.b ); // p, n3 + colorAttribute.setXYZ( 30, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 31, cone.r, cone.g, cone.b ); // p, n4 + + // up + + colorAttribute.setXYZ( 32, up.r, up.g, up.b ); colorAttribute.setXYZ( 33, up.r, up.g, up.b ); // u1, u2 + colorAttribute.setXYZ( 34, up.r, up.g, up.b ); colorAttribute.setXYZ( 35, up.r, up.g, up.b ); // u2, u3 + colorAttribute.setXYZ( 36, up.r, up.g, up.b ); colorAttribute.setXYZ( 37, up.r, up.g, up.b ); // u3, u1 + + // target + + colorAttribute.setXYZ( 38, target.r, target.g, target.b ); colorAttribute.setXYZ( 39, target.r, target.g, target.b ); // c, t + colorAttribute.setXYZ( 40, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 41, cross.r, cross.g, cross.b ); // p, c + + // cross + + colorAttribute.setXYZ( 42, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 43, cross.r, cross.g, cross.b ); // cn1, cn2 + colorAttribute.setXYZ( 44, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 45, cross.r, cross.g, cross.b ); // cn3, cn4 + + colorAttribute.setXYZ( 46, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 47, cross.r, cross.g, cross.b ); // cf1, cf2 + colorAttribute.setXYZ( 48, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 49, cross.r, cross.g, cross.b ); // cf3, cf4 + + colorAttribute.needsUpdate = true; + + } + + update() { + + const geometry = this.geometry; + const pointMap = this.pointMap; + + const w = 1, h = 1; + + // we need just camera projection matrix inverse + // world matrix must be identity + + _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse ); + + // center / target + + setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 ); + setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 ); + + // near + + setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 ); + setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 ); + setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 ); + setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 ); + + // far + + setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 ); + setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 ); + setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 ); + setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 ); + + // up + + setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 ); + setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 ); + setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 ); + + // cross + + setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 ); + setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 ); + setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 ); + setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 ); + + setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 ); + setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 ); + setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 ); + setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 ); + + geometry.getAttribute( 'position' ).needsUpdate = true; + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + + +function setPoint( point, pointMap, geometry, camera, x, y, z ) { + + _vector.set( x, y, z ).unproject( camera ); + + const points = pointMap[ point ]; + + if ( points !== undefined ) { + + const position = geometry.getAttribute( 'position' ); + + for ( let i = 0, l = points.length; i < l; i ++ ) { + + position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z ); + + } + + } + +} + +const _box = /*@__PURE__*/ new Box3(); + +class BoxHelper extends LineSegments { + + constructor( object, color = 0xffff00 ) { + + const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] ); + const positions = new Float32Array( 8 * 3 ); + + const geometry = new BufferGeometry(); + geometry.setIndex( new BufferAttribute( indices, 1 ) ); + geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) ); + + super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + + this.object = object; + this.type = 'BoxHelper'; + + this.matrixAutoUpdate = false; + + this.update(); + + } + + update( object ) { + + if ( object !== undefined ) { + + console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' ); + + } + + if ( this.object !== undefined ) { + + _box.setFromObject( this.object ); + + } + + if ( _box.isEmpty() ) return; + + const min = _box.min; + const max = _box.max; + + /* + 5____4 + 1/___0/| + | 6__|_7 + 2/___3/ + + 0: max.x, max.y, max.z + 1: min.x, max.y, max.z + 2: min.x, min.y, max.z + 3: max.x, min.y, max.z + 4: max.x, max.y, min.z + 5: min.x, max.y, min.z + 6: min.x, min.y, min.z + 7: max.x, min.y, min.z + */ + + const position = this.geometry.attributes.position; + const array = position.array; + + array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z; + array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z; + array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z; + array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z; + array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z; + array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z; + array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z; + array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z; + + position.needsUpdate = true; + + this.geometry.computeBoundingSphere(); + + } + + setFromObject( object ) { + + this.object = object; + this.update(); + + return this; + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.object = source.object; + + return this; + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + +class Box3Helper extends LineSegments { + + constructor( box, color = 0xffff00 ) { + + const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] ); + + const positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ]; + + const geometry = new BufferGeometry(); + + geometry.setIndex( new BufferAttribute( indices, 1 ) ); + + geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + + super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + + this.box = box; + + this.type = 'Box3Helper'; + + this.geometry.computeBoundingSphere(); + + } + + updateMatrixWorld( force ) { + + const box = this.box; + + if ( box.isEmpty() ) return; + + box.getCenter( this.position ); + + box.getSize( this.scale ); + + this.scale.multiplyScalar( 0.5 ); + + super.updateMatrixWorld( force ); + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + +class PlaneHelper extends Line { + + constructor( plane, size = 1, hex = 0xffff00 ) { + + const color = hex; + + const positions = [ 1, - 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ]; + + const geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + geometry.computeBoundingSphere(); + + super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + + this.type = 'PlaneHelper'; + + this.plane = plane; + + this.size = size; + + const positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ]; + + const geometry2 = new BufferGeometry(); + geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) ); + geometry2.computeBoundingSphere(); + + this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) ); + + } + + updateMatrixWorld( force ) { + + this.position.set( 0, 0, 0 ); + + this.scale.set( 0.5 * this.size, 0.5 * this.size, 1 ); + + this.lookAt( this.plane.normal ); + + this.translateZ( - this.plane.constant ); + + super.updateMatrixWorld( force ); + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + this.children[ 0 ].geometry.dispose(); + this.children[ 0 ].material.dispose(); + + } + +} + +const _axis = /*@__PURE__*/ new Vector3(); +let _lineGeometry, _coneGeometry; + +class ArrowHelper extends Object3D { + + // dir is assumed to be normalized + + constructor( dir = new Vector3( 0, 0, 1 ), origin = new Vector3( 0, 0, 0 ), length = 1, color = 0xffff00, headLength = length * 0.2, headWidth = headLength * 0.2 ) { + + super(); + + this.type = 'ArrowHelper'; + + if ( _lineGeometry === undefined ) { + + _lineGeometry = new BufferGeometry(); + _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) ); + + _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 ); + _coneGeometry.translate( 0, - 0.5, 0 ); + + } + + this.position.copy( origin ); + + this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + this.line.matrixAutoUpdate = false; + this.add( this.line ); + + this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) ); + this.cone.matrixAutoUpdate = false; + this.add( this.cone ); + + this.setDirection( dir ); + this.setLength( length, headLength, headWidth ); + + } + + setDirection( dir ) { + + // dir is assumed to be normalized + + if ( dir.y > 0.99999 ) { + + this.quaternion.set( 0, 0, 0, 1 ); + + } else if ( dir.y < - 0.99999 ) { + + this.quaternion.set( 1, 0, 0, 0 ); + + } else { + + _axis.set( dir.z, 0, - dir.x ).normalize(); + + const radians = Math.acos( dir.y ); + + this.quaternion.setFromAxisAngle( _axis, radians ); + + } + + } + + setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) { + + this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458 + this.line.updateMatrix(); + + this.cone.scale.set( headWidth, headLength, headWidth ); + this.cone.position.y = length; + this.cone.updateMatrix(); + + } + + setColor( color ) { + + this.line.material.color.set( color ); + this.cone.material.color.set( color ); + + } + + copy( source ) { + + super.copy( source, false ); + + this.line.copy( source.line ); + this.cone.copy( source.cone ); + + return this; + + } + + dispose() { + + this.line.geometry.dispose(); + this.line.material.dispose(); + this.cone.geometry.dispose(); + this.cone.material.dispose(); + + } + +} + +class AxesHelper extends LineSegments { + + constructor( size = 1 ) { + + const vertices = [ + 0, 0, 0, size, 0, 0, + 0, 0, 0, 0, size, 0, + 0, 0, 0, 0, 0, size + ]; + + const colors = [ + 1, 0, 0, 1, 0.6, 0, + 0, 1, 0, 0.6, 1, 0, + 0, 0, 1, 0, 0.6, 1 + ]; + + const geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } ); + + super( geometry, material ); + + this.type = 'AxesHelper'; + + } + + setColors( xAxisColor, yAxisColor, zAxisColor ) { + + const color = new Color(); + const array = this.geometry.attributes.color.array; + + color.set( xAxisColor ); + color.toArray( array, 0 ); + color.toArray( array, 3 ); + + color.set( yAxisColor ); + color.toArray( array, 6 ); + color.toArray( array, 9 ); + + color.set( zAxisColor ); + color.toArray( array, 12 ); + color.toArray( array, 15 ); + + this.geometry.attributes.color.needsUpdate = true; + + return this; + + } + + dispose() { + + this.geometry.dispose(); + this.material.dispose(); + + } + +} + +class ShapePath { + + constructor() { + + this.type = 'ShapePath'; + + this.color = new Color(); + + this.subPaths = []; + this.currentPath = null; + + } + + moveTo( x, y ) { + + this.currentPath = new Path(); + this.subPaths.push( this.currentPath ); + this.currentPath.moveTo( x, y ); + + return this; + + } + + lineTo( x, y ) { + + this.currentPath.lineTo( x, y ); + + return this; + + } + + quadraticCurveTo( aCPx, aCPy, aX, aY ) { + + this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY ); + + return this; + + } + + bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) { + + this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ); + + return this; + + } + + splineThru( pts ) { + + this.currentPath.splineThru( pts ); + + return this; + + } + + toShapes( isCCW ) { + + function toShapesNoHoles( inSubpaths ) { + + const shapes = []; + + for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) { + + const tmpPath = inSubpaths[ i ]; + + const tmpShape = new Shape(); + tmpShape.curves = tmpPath.curves; + + shapes.push( tmpShape ); + + } + + return shapes; + + } + + function isPointInsidePolygon( inPt, inPolygon ) { + + const polyLen = inPolygon.length; + + // inPt on polygon contour => immediate success or + // toggling of inside/outside at every single! intersection point of an edge + // with the horizontal line through inPt, left of inPt + // not counting lowerY endpoints of edges and whole edges on that line + let inside = false; + for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) { + + let edgeLowPt = inPolygon[ p ]; + let edgeHighPt = inPolygon[ q ]; + + let edgeDx = edgeHighPt.x - edgeLowPt.x; + let edgeDy = edgeHighPt.y - edgeLowPt.y; + + if ( Math.abs( edgeDy ) > Number.EPSILON ) { + + // not parallel + if ( edgeDy < 0 ) { + + edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx; + edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy; + + } + + if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue; + + if ( inPt.y === edgeLowPt.y ) { + + if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ? + // continue; // no intersection or edgeLowPt => doesn't count !!! + + } else { + + const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y ); + if ( perpEdge === 0 ) return true; // inPt is on contour ? + if ( perpEdge < 0 ) continue; + inside = ! inside; // true intersection left of inPt + + } + + } else { + + // parallel or collinear + if ( inPt.y !== edgeLowPt.y ) continue; // parallel + // edge lies on the same horizontal line as inPt + if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) || + ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour ! + // continue; + + } + + } + + return inside; + + } + + const isClockWise = ShapeUtils.isClockWise; + + const subPaths = this.subPaths; + if ( subPaths.length === 0 ) return []; + + let solid, tmpPath, tmpShape; + const shapes = []; + + if ( subPaths.length === 1 ) { + + tmpPath = subPaths[ 0 ]; + tmpShape = new Shape(); + tmpShape.curves = tmpPath.curves; + shapes.push( tmpShape ); + return shapes; + + } + + let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() ); + holesFirst = isCCW ? ! holesFirst : holesFirst; + + // console.log("Holes first", holesFirst); + + const betterShapeHoles = []; + const newShapes = []; + let newShapeHoles = []; + let mainIdx = 0; + let tmpPoints; + + newShapes[ mainIdx ] = undefined; + newShapeHoles[ mainIdx ] = []; + + for ( let i = 0, l = subPaths.length; i < l; i ++ ) { + + tmpPath = subPaths[ i ]; + tmpPoints = tmpPath.getPoints(); + solid = isClockWise( tmpPoints ); + solid = isCCW ? ! solid : solid; + + if ( solid ) { + + if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++; + + newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints }; + newShapes[ mainIdx ].s.curves = tmpPath.curves; + + if ( holesFirst ) mainIdx ++; + newShapeHoles[ mainIdx ] = []; + + //console.log('cw', i); + + } else { + + newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } ); + + //console.log('ccw', i); + + } + + } + + // only Holes? -> probably all Shapes with wrong orientation + if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths ); + + + if ( newShapes.length > 1 ) { + + let ambiguous = false; + let toChange = 0; + + for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) { + + betterShapeHoles[ sIdx ] = []; + + } + + for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) { + + const sho = newShapeHoles[ sIdx ]; + + for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) { + + const ho = sho[ hIdx ]; + let hole_unassigned = true; + + for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) { + + if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) { + + if ( sIdx !== s2Idx ) toChange ++; + + if ( hole_unassigned ) { + + hole_unassigned = false; + betterShapeHoles[ s2Idx ].push( ho ); + + } else { + + ambiguous = true; + + } + + } + + } + + if ( hole_unassigned ) { + + betterShapeHoles[ sIdx ].push( ho ); + + } + + } + + } + + if ( toChange > 0 && ambiguous === false ) { + + newShapeHoles = betterShapeHoles; + + } + + } + + let tmpHoles; + + for ( let i = 0, il = newShapes.length; i < il; i ++ ) { + + tmpShape = newShapes[ i ].s; + shapes.push( tmpShape ); + tmpHoles = newShapeHoles[ i ]; + + for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) { + + tmpShape.holes.push( tmpHoles[ j ].h ); + + } + + } + + //console.log("shape", shapes); + + return shapes; + + } + +} + +class Controls extends EventDispatcher { + + constructor( object, domElement = null ) { + + super(); + + this.object = object; + this.domElement = domElement; + + this.enabled = true; + + this.state = - 1; + + this.keys = {}; + this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null }; + this.touches = { ONE: null, TWO: null }; + + } + + connect() {} + + disconnect() {} + + dispose() {} + + update( /* delta */ ) {} + +} + +function contain( texture, aspect ) { + + const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1; + + if ( imageAspect > aspect ) { + + texture.repeat.x = 1; + texture.repeat.y = imageAspect / aspect; + + texture.offset.x = 0; + texture.offset.y = ( 1 - texture.repeat.y ) / 2; + + } else { + + texture.repeat.x = aspect / imageAspect; + texture.repeat.y = 1; + + texture.offset.x = ( 1 - texture.repeat.x ) / 2; + texture.offset.y = 0; + + } + + return texture; + +} + +function cover( texture, aspect ) { + + const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1; + + if ( imageAspect > aspect ) { + + texture.repeat.x = aspect / imageAspect; + texture.repeat.y = 1; + + texture.offset.x = ( 1 - texture.repeat.x ) / 2; + texture.offset.y = 0; + + } else { + + texture.repeat.x = 1; + texture.repeat.y = imageAspect / aspect; + + texture.offset.x = 0; + texture.offset.y = ( 1 - texture.repeat.y ) / 2; + + } + + return texture; + +} + +function fill( texture ) { + + texture.repeat.x = 1; + texture.repeat.y = 1; + + texture.offset.x = 0; + texture.offset.y = 0; + + return texture; + +} + + + +/** + * Given the width, height, format, and type of a texture. Determines how many + * bytes must be used to represent the texture. + */ +function getByteLength( width, height, format, type ) { + + const typeByteLength = getTextureTypeByteLength( type ); + + switch ( format ) { + + // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml + case AlphaFormat: + return width * height; + case LuminanceFormat: + return width * height; + case LuminanceAlphaFormat: + return width * height * 2; + case RedFormat: + return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength; + case RedIntegerFormat: + return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength; + case RGFormat: + return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength; + case RGIntegerFormat: + return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength; + case RGBFormat: + return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength; + case RGBAFormat: + return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength; + case RGBAIntegerFormat: + return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength; + + // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/ + case RGB_S3TC_DXT1_Format: + case RGBA_S3TC_DXT1_Format: + return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8; + case RGBA_S3TC_DXT3_Format: + case RGBA_S3TC_DXT5_Format: + return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16; + + // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/ + case RGB_PVRTC_2BPPV1_Format: + case RGBA_PVRTC_2BPPV1_Format: + return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4; + case RGB_PVRTC_4BPPV1_Format: + case RGBA_PVRTC_4BPPV1_Format: + return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2; + + // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/ + case RGB_ETC1_Format: + case RGB_ETC2_Format: + return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8; + case RGBA_ETC2_EAC_Format: + return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16; + + // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/ + case RGBA_ASTC_4x4_Format: + return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16; + case RGBA_ASTC_5x4_Format: + return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16; + case RGBA_ASTC_5x5_Format: + return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16; + case RGBA_ASTC_6x5_Format: + return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16; + case RGBA_ASTC_6x6_Format: + return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16; + case RGBA_ASTC_8x5_Format: + return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16; + case RGBA_ASTC_8x6_Format: + return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16; + case RGBA_ASTC_8x8_Format: + return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16; + case RGBA_ASTC_10x5_Format: + return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16; + case RGBA_ASTC_10x6_Format: + return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16; + case RGBA_ASTC_10x8_Format: + return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16; + case RGBA_ASTC_10x10_Format: + return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16; + case RGBA_ASTC_12x10_Format: + return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16; + case RGBA_ASTC_12x12_Format: + return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16; + + // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/ + case RGBA_BPTC_Format: + case RGB_BPTC_SIGNED_Format: + case RGB_BPTC_UNSIGNED_Format: + return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16; + + // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/ + case RED_RGTC1_Format: + case SIGNED_RED_RGTC1_Format: + return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8; + case RED_GREEN_RGTC2_Format: + case SIGNED_RED_GREEN_RGTC2_Format: + return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16; + + } + + throw new Error( + `Unable to determine texture byte length for ${format} format.`, + ); + +} + +function getTextureTypeByteLength( type ) { + + switch ( type ) { + + case UnsignedByteType: + case ByteType: + return { byteLength: 1, components: 1 }; + case UnsignedShortType: + case ShortType: + case HalfFloatType: + return { byteLength: 2, components: 1 }; + case UnsignedShort4444Type: + case UnsignedShort5551Type: + return { byteLength: 2, components: 4 }; + case UnsignedIntType: + case IntType: + case FloatType: + return { byteLength: 4, components: 1 }; + case UnsignedInt5999Type: + return { byteLength: 4, components: 3 }; + + } + + throw new Error( `Unknown texture type ${type}.` ); + +} + +const TextureUtils = { + contain, + cover, + fill, + getByteLength +}; + +class WebGLMultipleRenderTargets extends WebGLRenderTarget { // @deprecated, r162 + + constructor( width = 1, height = 1, count = 1, options = {} ) { + + console.warn( 'THREE.WebGLMultipleRenderTargets has been deprecated and will be removed in r172. Use THREE.WebGLRenderTarget and set the "count" parameter to enable MRT.' ); + + super( width, height, { ...options, count } ); + + this.isWebGLMultipleRenderTargets = true; + + } + + get texture() { + + return this.textures; + + } + +} + +if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: { + revision: REVISION, + } } ) ); + +} + +if ( typeof window !== 'undefined' ) { + + if ( window.__THREE__ ) { + + console.warn( 'WARNING: Multiple instances of Three.js being imported.' ); + + } else { + + window.__THREE__ = REVISION; + + } + +} + +export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BackSide, BasicDepthPacking, BasicShadowMap, BatchedMesh, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CineonToneMapping, CircleGeometry, ClampToEdgeWrapping, Clock, Color, ColorKeyframeTrack, ColorManagement, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, ConstantAlphaFactor, ConstantColorFactor, Controls, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry, Cylindrical, Data3DTexture, DataArrayTexture, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fog, FogExp2, FramebufferTexture, FrontSide, Frustum, GLBufferAttribute, GLSL1, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, NormalAnimationBlendMode, NormalBlending, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, Path, PerspectiveCamera, Plane, PlaneGeometry, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RAD2DEG, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDepthPacking, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGDepthPacking, RGFormat, RGIntegerFormat, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RedFormat, RedIntegerFormat, ReinhardToneMapping, RenderTarget, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingGeometry, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, ShaderMaterial, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronGeometry, Texture, TextureLoader, TextureUtils, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, VectorKeyframeTrack, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLMultipleRenderTargets, WebGLRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, arrayNeedsUint32, cloneUniforms, createCanvasElement, createElementNS, getByteLength, getUnlitUniformColorSpace, mergeUniforms, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce }; diff --git a/libs/three.js/r171/build/three.core.min.js b/libs/three.js/r171/build/three.core.min.js new file mode 100644 index 000000000..ea8def159 --- /dev/null +++ b/libs/three.js/r171/build/three.core.min.js @@ -0,0 +1,6 @@ +/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */ +const t="171",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},s={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,r=1,n=2,o=3,a=0,h=1,l=2,c=3,u=0,d=1,p=2,m=0,y=1,f=2,g=3,x=4,b=5,v=100,w=101,M=102,S=103,_=104,A=200,T=201,z=202,C=203,I=204,B=205,k=206,E=207,R=208,P=209,O=210,F=211,N=212,L=213,V=214,W=0,U=1,j=2,D=3,H=4,q=5,J=6,X=7,Y=0,Z=1,G=2,$=0,Q=1,K=2,tt=3,et=4,st=5,it=6,rt=7,nt="attached",ot="detached",at=300,ht=301,lt=302,ct=303,ut=304,dt=306,pt=1e3,mt=1001,yt=1002,ft=1003,gt=1004,xt=1004,bt=1005,vt=1005,wt=1006,Mt=1007,St=1007,_t=1008,At=1008,Tt=1009,zt=1010,Ct=1011,It=1012,Bt=1013,kt=1014,Et=1015,Rt=1016,Pt=1017,Ot=1018,Ft=1020,Nt=35902,Lt=1021,Vt=1022,Wt=1023,Ut=1024,jt=1025,Dt=1026,Ht=1027,qt=1028,Jt=1029,Xt=1030,Yt=1031,Zt=1032,Gt=1033,$t=33776,Qt=33777,Kt=33778,te=33779,ee=35840,se=35841,ie=35842,re=35843,ne=36196,oe=37492,ae=37496,he=37808,le=37809,ce=37810,ue=37811,de=37812,pe=37813,me=37814,ye=37815,fe=37816,ge=37817,xe=37818,be=37819,ve=37820,we=37821,Me=36492,Se=36494,_e=36495,Ae=36283,Te=36284,ze=36285,Ce=36286,Ie=2200,Be=2201,ke=2202,Ee=2300,Re=2301,Pe=2302,Oe=2400,Fe=2401,Ne=2402,Le=2500,Ve=2501,We=0,Ue=1,je=2,De=3200,He=3201,qe=3202,Je=3203,Xe=0,Ye=1,Ze="",Ge="srgb",$e="srgb-linear",Qe="linear",Ke="srgb",ts=0,es=7680,ss=7681,is=7682,rs=7683,ns=34055,os=34056,as=5386,hs=512,ls=513,cs=514,us=515,ds=516,ps=517,ms=518,ys=519,fs=512,gs=513,xs=514,bs=515,vs=516,ws=517,Ms=518,Ss=519,_s=35044,As=35048,Ts=35040,zs=35045,Cs=35049,Is=35041,Bs=35046,ks=35050,Es=35042,Rs="100",Ps="300 es",Os=2e3,Fs=2001;class Ns{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[t]&&(s[t]=[]),-1===s[t].indexOf(e)&&s[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const s=this._listeners;return void 0!==s[t]&&-1!==s[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const s=this._listeners[t];if(void 0!==s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const s=e.slice(0);for(let e=0,i=s.length;e>8&255]+Ls[t>>16&255]+Ls[t>>24&255]+"-"+Ls[255&e]+Ls[e>>8&255]+"-"+Ls[e>>16&15|64]+Ls[e>>24&255]+"-"+Ls[63&s|128]+Ls[s>>8&255]+"-"+Ls[s>>16&255]+Ls[s>>24&255]+Ls[255&i]+Ls[i>>8&255]+Ls[i>>16&255]+Ls[i>>24&255]).toLowerCase()}function Ds(t,e,s){return Math.max(e,Math.min(s,t))}function Hs(t,e){return(t%e+e)%e}function qs(t,e,s){return(1-s)*t+s*e}function Js(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Xs(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Ys={DEG2RAD:Ws,RAD2DEG:Us,generateUUID:js,clamp:Ds,euclideanModulo:Hs,mapLinear:function(t,e,s,i,r){return i+(t-e)*(r-i)/(s-e)},inverseLerp:function(t,e,s){return t!==e?(s-t)/(e-t):0},lerp:qs,damp:function(t,e,s,i){return qs(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(Hs(t,2*e)-e)},smoothstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*(3-2*t)},smootherstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(Vs=t);let e=Vs+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*Ws},radToDeg:function(t){return t*Us},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),l=n((e+i)/2),c=o((e+i)/2),u=n((e-i)/2),d=o((e-i)/2),p=n((i-e)/2),m=o((i-e)/2);switch(r){case"XYX":t.set(a*c,h*u,h*d,a*l);break;case"YZY":t.set(h*d,a*c,h*u,a*l);break;case"ZXZ":t.set(h*u,h*d,a*c,a*l);break;case"XZX":t.set(a*c,h*m,h*p,a*l);break;case"YXY":t.set(h*p,a*c,h*m,a*l);break;case"ZYZ":t.set(h*m,h*p,a*c,a*l);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:Xs,denormalize:Js};class Zs{constructor(t=0,e=0){Zs.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Ds(this.x,t.x,e.x),this.y=Ds(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Ds(this.x,t,e),this.y=Ds(this.y,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Ds(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(Ds(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Gs{constructor(t,e,s,i,r,n,o,a,h){Gs.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,o,a,h){const l=this.elements;return l[0]=t,l[1]=i,l[2]=o,l[3]=e,l[4]=r,l[5]=a,l[6]=s,l[7]=n,l[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],l=s[4],c=s[7],u=s[2],d=s[5],p=s[8],m=i[0],y=i[3],f=i[6],g=i[1],x=i[4],b=i[7],v=i[2],w=i[5],M=i[8];return r[0]=n*m+o*g+a*v,r[3]=n*y+o*x+a*w,r[6]=n*f+o*b+a*M,r[1]=h*m+l*g+c*v,r[4]=h*y+l*x+c*w,r[7]=h*f+l*b+c*M,r[2]=u*m+d*g+p*v,r[5]=u*y+d*x+p*w,r[8]=u*f+d*b+p*M,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8];return e*n*l-e*o*h-s*r*l+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=l*n-o*h,u=o*a-l*r,d=h*r-n*a,p=e*c+s*u+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=c*m,t[1]=(i*h-l*s)*m,t[2]=(o*s-i*n)*m,t[3]=u*m,t[4]=(l*e-i*a)*m,t[5]=(i*r-o*e)*m,t[6]=d*m,t[7]=(s*a-h*e)*m,t[8]=(n*e-s*r)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply($s.makeScale(t,e)),this}rotate(t){return this.premultiply($s.makeRotation(-t)),this}translate(t,e){return this.premultiply($s.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,s,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const $s=new Gs;function Qs(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}const Ks={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ti(t,e){return new Ks[t](e)}function ei(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function si(){const t=ei("canvas");return t.style.display="block",t}const ii={};function ri(t){t in ii||(ii[t]=!0,console.warn(t))}function ni(t,e,s){return new Promise((function(i,r){setTimeout((function n(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:r();break;case t.TIMEOUT_EXPIRED:setTimeout(n,s);break;default:i()}}),s)}))}function oi(t){const e=t.elements;e[2]=.5*e[2]+.5*e[3],e[6]=.5*e[6]+.5*e[7],e[10]=.5*e[10]+.5*e[11],e[14]=.5*e[14]+.5*e[15]}function ai(t){const e=t.elements;-1===e[11]?(e[10]=-e[10]-1,e[14]=-e[14]):(e[10]=-e[10],e[14]=1-e[14])}const hi=(new Gs).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),li=(new Gs).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function ci(){const t={enabled:!0,workingColorSpace:$e,spaces:{},convert:function(t,e,s){return!1!==this.enabled&&e!==s&&e&&s?(this.spaces[e].transfer===Ke&&(t.r=di(t.r),t.g=di(t.g),t.b=di(t.b)),this.spaces[e].primaries!==this.spaces[s].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[s].fromXYZ)),this.spaces[s].transfer===Ke&&(t.r=pi(t.r),t.g=pi(t.g),t.b=pi(t.b)),t):t},fromWorkingColorSpace:function(t,e){return this.convert(t,this.workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this.workingColorSpace)},getPrimaries:function(t){return this.spaces[t].primaries},getTransfer:function(t){return""===t?Qe:this.spaces[t].transfer},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,s){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[s].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace}},e=[.64,.33,.3,.6,.15,.06],s=[.2126,.7152,.0722],i=[.3127,.329];return t.define({[$e]:{primaries:e,whitePoint:i,transfer:Qe,toXYZ:hi,fromXYZ:li,luminanceCoefficients:s,workingColorSpaceConfig:{unpackColorSpace:Ge},outputColorSpaceConfig:{drawingBufferColorSpace:Ge}},[Ge]:{primaries:e,whitePoint:i,transfer:Ke,toXYZ:hi,fromXYZ:li,luminanceCoefficients:s,outputColorSpaceConfig:{drawingBufferColorSpace:Ge}}}),t}const ui=ci();function di(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function pi(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let mi;class yi{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===mi&&(mi=ei("canvas")),mi.width=t.width,mi.height=t.height;const s=mi.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=mi}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ei("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t0&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==at)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case pt:t.x=t.x-Math.floor(t.x);break;case mt:t.x=t.x<0?0:1;break;case yt:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case pt:t.y=t.y-Math.floor(t.y);break;case mt:t.y=t.y<0?0:1;break;case yt:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}vi.DEFAULT_IMAGE=null,vi.DEFAULT_MAPPING=at,vi.DEFAULT_ANISOTROPY=1;class wi{constructor(t=0,e=0,s=0,i=1){wi.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],l=a[4],c=a[8],u=a[1],d=a[5],p=a[9],m=a[2],y=a[6],f=a[10];if(Math.abs(l-u)a&&t>g?tg?a=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+u*r,h=h*t+d*r,l=l*t+p*r,c=c*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+l*l+c*c);a*=t,h*=t,l*=t,c*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=c}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],l=s[i+3],c=r[n],u=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+l*c+a*d-h*u,t[e+1]=a*p+l*u+h*c-o*d,t[e+2]=h*p+l*d+o*u-a*c,t[e+3]=l*p-o*c-a*u-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),l=o(i/2),c=o(r/2),u=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"YXZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"ZXY":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"ZYX":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"YZX":this._x=u*l*c+h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c-u*d*p;break;case"XZY":this._x=u*l*c-h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c+u*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],l=e[6],c=e[10],u=s+o+c;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>c){const t=2*Math.sqrt(1+s-o-c);this._w=(l-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>c){const t=2*Math.sqrt(1+o-s-c);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+c-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+l)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return sMath.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Ds(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,l=e._w;return this._x=s*l+n*o+i*h-r*a,this._y=i*l+n*a+r*o-s*h,this._z=r*l+n*h+s*a-i*o,this._w=n*l-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),l=Math.atan2(h,o),c=Math.sin((1-e)*l)/h,u=Math.sin(e*l)/h;return this._w=n*c+this._w*u,this._x=s*c+this._x*u,this._y=i*c+this._y*u,this._z=r*c+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Ii{constructor(t=0,e=0,s=0){Ii.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(ki.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(ki.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),l=2*(o*e-r*i),c=2*(r*s-n*e);return this.x=e+a*h+n*c-o*l,this.y=s+a*l+o*h-r*c,this.z=i+a*c+r*l-n*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Ds(this.x,t.x,e.x),this.y=Ds(this.y,t.y,e.y),this.z=Ds(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Ds(this.x,t,e),this.y=Ds(this.y,t,e),this.z=Ds(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Ds(s,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Bi.copy(this).projectOnVector(t),this.sub(Bi)}reflect(t){return this.sub(Bi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(Ds(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Bi=new Ii,ki=new Ci;class Ei{constructor(t=new Ii(1/0,1/0,1/0),e=new Ii(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,s=t.length;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,Pi),Pi.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(ji),Di.subVectors(this.max,ji),Fi.subVectors(t.a,ji),Ni.subVectors(t.b,ji),Li.subVectors(t.c,ji),Vi.subVectors(Ni,Fi),Wi.subVectors(Li,Ni),Ui.subVectors(Fi,Li);let e=[0,-Vi.z,Vi.y,0,-Wi.z,Wi.y,0,-Ui.z,Ui.y,Vi.z,0,-Vi.x,Wi.z,0,-Wi.x,Ui.z,0,-Ui.x,-Vi.y,Vi.x,0,-Wi.y,Wi.x,0,-Ui.y,Ui.x,0];return!!Ji(e,Fi,Ni,Li,Di)&&(e=[1,0,0,0,1,0,0,0,1],!!Ji(e,Fi,Ni,Li,Di)&&(Hi.crossVectors(Vi,Wi),e=[Hi.x,Hi.y,Hi.z],Ji(e,Fi,Ni,Li,Di)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Pi).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Pi).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Ri[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ri[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ri[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ri[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ri[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ri[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ri[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ri[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ri)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Ri=[new Ii,new Ii,new Ii,new Ii,new Ii,new Ii,new Ii,new Ii],Pi=new Ii,Oi=new Ei,Fi=new Ii,Ni=new Ii,Li=new Ii,Vi=new Ii,Wi=new Ii,Ui=new Ii,ji=new Ii,Di=new Ii,Hi=new Ii,qi=new Ii;function Ji(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){qi.fromArray(t,n);const o=r.x*Math.abs(qi.x)+r.y*Math.abs(qi.y)+r.z*Math.abs(qi.z),a=e.dot(qi),h=s.dot(qi),l=i.dot(qi);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const Xi=new Ei,Yi=new Ii,Zi=new Ii;class Gi{constructor(t=new Ii,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const s=this.center;void 0!==e?s.copy(e):Xi.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=t.length;ethis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;Yi.subVectors(t,this.center);const e=Yi.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(Yi,s/t),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(Zi.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Yi.copy(t.center).add(Zi)),this.expandByPoint(Yi.copy(t.center).sub(Zi))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const $i=new Ii,Qi=new Ii,Ki=new Ii,tr=new Ii,er=new Ii,sr=new Ii,ir=new Ii;class rr{constructor(t=new Ii,e=new Ii(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,$i)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=$i.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):($i.copy(this.origin).addScaledVector(this.direction,e),$i.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Qi.copy(t).add(e).multiplyScalar(.5),Ki.copy(e).sub(t).normalize(),tr.copy(this.origin).sub(Qi);const r=.5*t.distanceTo(e),n=-this.direction.dot(Ki),o=tr.dot(this.direction),a=-tr.dot(Ki),h=tr.lengthSq(),l=Math.abs(1-n*n);let c,u,d,p;if(l>0)if(c=n*a-o,u=n*o-a,p=r*l,c>=0)if(u>=-p)if(u<=p){const t=1/l;c*=t,u*=t,d=c*(c+n*u+2*o)+u*(n*c+u+2*a)+h}else u=r,c=Math.max(0,-(n*u+o)),d=-c*c+u*(u+2*a)+h;else u=-r,c=Math.max(0,-(n*u+o)),d=-c*c+u*(u+2*a)+h;else u<=-p?(c=Math.max(0,-(-n*r+o)),u=c>0?-r:Math.min(Math.max(-r,-a),r),d=-c*c+u*(u+2*a)+h):u<=p?(c=0,u=Math.min(Math.max(-r,-a),r),d=u*(u+2*a)+h):(c=Math.max(0,-(n*r+o)),u=c>0?r:Math.min(Math.max(-r,-a),r),d=-c*c+u*(u+2*a)+h);else u=n>0?-r:r,c=Math.max(0,-(n*u+o)),d=-c*c+u*(u+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,c),i&&i.copy(Qi).addScaledVector(Ki,u),d}intersectSphere(t,e){$i.subVectors(t.center,this.origin);const s=$i.dot(this.direction),i=$i.dot($i)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,r,n,o,a;const h=1/this.direction.x,l=1/this.direction.y,c=1/this.direction.z,u=this.origin;return h>=0?(s=(t.min.x-u.x)*h,i=(t.max.x-u.x)*h):(s=(t.max.x-u.x)*h,i=(t.min.x-u.x)*h),l>=0?(r=(t.min.y-u.y)*l,n=(t.max.y-u.y)*l):(r=(t.max.y-u.y)*l,n=(t.min.y-u.y)*l),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n=0?(o=(t.min.z-u.z)*c,a=(t.max.z-u.z)*c):(o=(t.max.z-u.z)*c,a=(t.min.z-u.z)*c),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,$i)}intersectTriangle(t,e,s,i,r){er.subVectors(e,t),sr.subVectors(s,t),ir.crossVectors(er,sr);let n,o=this.direction.dot(ir);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}tr.subVectors(this.origin,t);const a=n*this.direction.dot(sr.crossVectors(tr,sr));if(a<0)return null;const h=n*this.direction.dot(er.cross(tr));if(h<0)return null;if(a+h>o)return null;const l=-n*tr.dot(ir);return l<0?null:this.at(l/o,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class nr{constructor(t,e,s,i,r,n,o,a,h,l,c,u,d,p,m,y){nr.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,l,c,u,d,p,m,y)}set(t,e,s,i,r,n,o,a,h,l,c,u,d,p,m,y){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=l,f[10]=c,f[14]=u,f[3]=d,f[7]=p,f[11]=m,f[15]=y,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new nr).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/or.setFromMatrixColumn(t,0).length(),r=1/or.setFromMatrixColumn(t,1).length(),n=1/or.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),l=Math.cos(r),c=Math.sin(r);if("XYZ"===t.order){const t=n*l,s=n*c,i=o*l,r=o*c;e[0]=a*l,e[4]=-a*c,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*l,s=a*c,i=h*l,r=h*c;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*c,e[5]=n*l,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*l,s=a*c,i=h*l,r=h*c;e[0]=t-r*o,e[4]=-n*c,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*l,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*l,s=n*c,i=o*l,r=o*c;e[0]=a*l,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*c,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*l,e[4]=r-t*c,e[8]=i*c+s,e[1]=c,e[5]=n*l,e[9]=-o*l,e[2]=-h*l,e[6]=s*c+i,e[10]=t-r*c}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*l,e[4]=-c,e[8]=h*l,e[1]=t*c+r,e[5]=n*l,e[9]=s*c-i,e[2]=i*c-s,e[6]=o*l,e[10]=r*c+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(hr,t,lr)}lookAt(t,e,s){const i=this.elements;return dr.subVectors(t,e),0===dr.lengthSq()&&(dr.z=1),dr.normalize(),cr.crossVectors(s,dr),0===cr.lengthSq()&&(1===Math.abs(s.z)?dr.x+=1e-4:dr.z+=1e-4,dr.normalize(),cr.crossVectors(s,dr)),cr.normalize(),ur.crossVectors(dr,cr),i[0]=cr.x,i[4]=ur.x,i[8]=dr.x,i[1]=cr.y,i[5]=ur.y,i[9]=dr.y,i[2]=cr.z,i[6]=ur.z,i[10]=dr.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],l=s[1],c=s[5],u=s[9],d=s[13],p=s[2],m=s[6],y=s[10],f=s[14],g=s[3],x=s[7],b=s[11],v=s[15],w=i[0],M=i[4],S=i[8],_=i[12],A=i[1],T=i[5],z=i[9],C=i[13],I=i[2],B=i[6],k=i[10],E=i[14],R=i[3],P=i[7],O=i[11],F=i[15];return r[0]=n*w+o*A+a*I+h*R,r[4]=n*M+o*T+a*B+h*P,r[8]=n*S+o*z+a*k+h*O,r[12]=n*_+o*C+a*E+h*F,r[1]=l*w+c*A+u*I+d*R,r[5]=l*M+c*T+u*B+d*P,r[9]=l*S+c*z+u*k+d*O,r[13]=l*_+c*C+u*E+d*F,r[2]=p*w+m*A+y*I+f*R,r[6]=p*M+m*T+y*B+f*P,r[10]=p*S+m*z+y*k+f*O,r[14]=p*_+m*C+y*E+f*F,r[3]=g*w+x*A+b*I+v*R,r[7]=g*M+x*T+b*B+v*P,r[11]=g*S+x*z+b*k+v*O,r[15]=g*_+x*C+b*E+v*F,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],l=t[2],c=t[6],u=t[10],d=t[14];return t[3]*(+r*a*c-i*h*c-r*o*u+s*h*u+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*u+r*n*u-i*n*d+i*h*l-r*a*l)+t[11]*(+e*h*c-e*o*d-r*n*c+s*n*d+r*o*l-s*h*l)+t[15]*(-i*o*l-e*a*c+e*o*u+i*n*c-s*n*u+s*a*l)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=t[9],u=t[10],d=t[11],p=t[12],m=t[13],y=t[14],f=t[15],g=c*y*h-m*u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t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,l=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,l*o+s,l*a-i*n,0,h*a-i*o,l*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,l=n+n,c=o+o,u=r*h,d=r*l,p=r*c,m=n*l,y=n*c,f=o*c,g=a*h,x=a*l,b=a*c,v=s.x,w=s.y,M=s.z;return i[0]=(1-(m+f))*v,i[1]=(d+b)*v,i[2]=(p-x)*v,i[3]=0,i[4]=(d-b)*w,i[5]=(1-(u+f))*w,i[6]=(y+g)*w,i[7]=0,i[8]=(p+x)*M,i[9]=(y-g)*M,i[10]=(1-(u+m))*M,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=or.set(i[0],i[1],i[2]).length();const n=or.set(i[4],i[5],i[6]).length(),o=or.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],ar.copy(this);const a=1/r,h=1/n,l=1/o;return ar.elements[0]*=a,ar.elements[1]*=a,ar.elements[2]*=a,ar.elements[4]*=h,ar.elements[5]*=h,ar.elements[6]*=h,ar.elements[8]*=l,ar.elements[9]*=l,ar.elements[10]*=l,e.setFromRotationMatrix(ar),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),l=2*r/(s-i),c=(e+t)/(e-t),u=(s+i)/(s-i);let d,p;if(o===Os)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Fs)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=c,a[12]=0,a[1]=0,a[5]=l,a[9]=u,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),l=1/(s-i),c=1/(n-r),u=(e+t)*h,d=(s+i)*l;let p,m;if(o===Os)p=(n+r)*c,m=-2*c;else{if(o!==Fs)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*c,m=-1*c}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-u,a[1]=0,a[5]=2*l,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=m,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const or=new Ii,ar=new nr,hr=new Ii(0,0,0),lr=new Ii(1,1,1),cr=new Ii,ur=new Ii,dr=new Ii,pr=new nr,mr=new Ci;class yr{constructor(t=0,e=0,s=0,i=yr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],l=i[9],c=i[2],u=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Ds(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,h),this._z=0);break;case"YXZ":this._x=Math.asin(-Ds(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-c,r),this._z=0);break;case"ZXY":this._x=Math.asin(Ds(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-Ds(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(Ds(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-c,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-Ds(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return pr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(pr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return mr.setFromEuler(this),this.setFromQuaternion(mr,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}yr.DEFAULT_ORDER="XYZ";class fr{constructor(){this.mask=1}set(t){this.mask=(1<>>0}enable(t){this.mask|=1<1){for(let t=0;t1){for(let t=0;t0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e0){i.children=[];for(let e=0;e0){i.animations=[];for(let e=0;e0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),l.length>0&&(s.animations=l),c.length>0&&(s.nodes=c)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){Rr.subVectors(i,e),Pr.subVectors(s,e),Or.subVectors(t,e);const n=Rr.dot(Rr),o=Rr.dot(Pr),a=Rr.dot(Or),h=Pr.dot(Pr),l=Pr.dot(Or),c=n*h-o*o;if(0===c)return r.set(0,0,0),null;const u=1/c,d=(h*a-o*l)*u,p=(n*l-o*a)*u;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,Fr)&&(Fr.x>=0&&Fr.y>=0&&Fr.x+Fr.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,Fr)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,Fr.x),a.addScaledVector(n,Fr.y),a.addScaledVector(o,Fr.z),a)}static getInterpolatedAttribute(t,e,s,i,r,n){return Dr.setScalar(0),Hr.setScalar(0),qr.setScalar(0),Dr.fromBufferAttribute(t,e),Hr.fromBufferAttribute(t,s),qr.fromBufferAttribute(t,i),n.setScalar(0),n.addScaledVector(Dr,r.x),n.addScaledVector(Hr,r.y),n.addScaledVector(qr,r.z),n}static isFrontFacing(t,e,s,i){return Rr.subVectors(s,e),Pr.subVectors(t,e),Rr.cross(Pr).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Rr.subVectors(this.c,this.b),Pr.subVectors(this.a,this.b),.5*Rr.cross(Pr).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Jr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Jr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return Jr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return Jr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Jr.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;Nr.subVectors(i,s),Lr.subVectors(r,s),Wr.subVectors(t,s);const a=Nr.dot(Wr),h=Lr.dot(Wr);if(a<=0&&h<=0)return e.copy(s);Ur.subVectors(t,i);const l=Nr.dot(Ur),c=Lr.dot(Ur);if(l>=0&&c<=l)return e.copy(i);const u=a*c-l*h;if(u<=0&&a>=0&&l<=0)return n=a/(a-l),e.copy(s).addScaledVector(Nr,n);jr.subVectors(t,r);const d=Nr.dot(jr),p=Lr.dot(jr);if(p>=0&&d<=p)return e.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(s).addScaledVector(Lr,o);const y=l*p-d*c;if(y<=0&&c-l>=0&&d-p>=0)return Vr.subVectors(r,i),o=(c-l)/(c-l+(d-p)),e.copy(i).addScaledVector(Vr,o);const f=1/(y+m+u);return n=m*f,o=u*f,e.copy(s).addScaledVector(Nr,n).addScaledVector(Lr,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Xr={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Yr={h:0,s:0,l:0},Zr={h:0,s:0,l:0};function Gr(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class $r{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Ge){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,ui.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=ui.workingColorSpace){return this.r=t,this.g=e,this.b=s,ui.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=ui.workingColorSpace){if(t=Hs(t,1),e=Ds(e,0,1),s=Ds(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=Gr(r,i,t+1/3),this.g=Gr(r,i,t),this.b=Gr(r,i,t-1/3)}return ui.toWorkingColorSpace(this,i),this}setStyle(t,e=Ge){function s(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Ge){const s=Xr[t.toLowerCase()];return void 0!==s?this.setHex(s,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=di(t.r),this.g=di(t.g),this.b=di(t.b),this}copyLinearToSRGB(t){return this.r=pi(t.r),this.g=pi(t.g),this.b=pi(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Ge){return ui.fromWorkingColorSpace(Qr.copy(this),t),65536*Math.round(Ds(255*Qr.r,0,255))+256*Math.round(Ds(255*Qr.g,0,255))+Math.round(Ds(255*Qr.b,0,255))}getHexString(t=Ge){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=ui.workingColorSpace){ui.fromWorkingColorSpace(Qr.copy(this),e);const s=Qr.r,i=Qr.g,r=Qr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const l=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=l<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s:console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),this.side!==u&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),204!==this.blendSrc&&(s.blendSrc=this.blendSrc),205!==this.blendDst&&(s.blendDst=this.blendDst),100!==this.blendEquation&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==es&&(s.stencilFail=this.stencilFail),this.stencilZFail!==es&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==es&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class en extends tn{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new $r(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new yr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const sn=rn();function rn(){const t=new ArrayBuffer(4),e=new Float32Array(t),s=new Uint32Array(t),i=new Uint32Array(512),r=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,r[t]=24,r[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,r[t]=-e-1,r[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,r[t]=13,r[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,r[t]=24,r[256|t]=24):(i[t]=31744,i[256|t]=64512,r[t]=13,r[256|t]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,s=0;for(;0==(8388608&e);)e<<=1,s-=8388608;e&=-8388609,s+=947912704,n[t]=e|s}for(let t=1024;t<2048;++t)n[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)o[t]=t<<23;o[31]=1199570944,o[32]=2147483648;for(let t=33;t<63;++t)o[t]=2147483648+(t-32<<23);o[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(a[t]=1024);return{floatView:e,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function nn(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=Ds(t,-65504,65504),sn.floatView[0]=t;const e=sn.uint32View[0],s=e>>23&511;return sn.baseTable[s]+((8388607&e)>>sn.shiftTable[s])}function on(t){const e=t>>10;return sn.uint32View[0]=sn.mantissaTable[sn.offsetTable[e]+(1023&t)]+sn.exponentTable[e],sn.floatView[0]}const an={toHalfFloat:nn,fromHalfFloat:on},hn=new Ii,ln=new Zs;class cn{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=s,this.usage=_s,this.updateRanges=[],this.gpuType=Et,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;ie.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Ei);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new Ii(-1/0,-1/0,-1/0),new Ii(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const s in e)void 0!==e[s]&&(t[s]=e[s]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const s=t.index;null!==s&&this.setIndex(s.clone(e));const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t(t.far-t.near)**2)return}Cn.copy(r).invert(),In.copy(t.ray).applyMatrix4(Cn),null!==s.boundingBox&&!1===In.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,In)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,l=r.attributes.uv1,c=r.attributes.normal,u=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=u.length;rs.far?null:{distance:l,point:Ln.clone(),object:t}}(t,e,s,i,En,Rn,Pn,Nn);if(c){const t=new Ii;Jr.getBarycoord(Nn,En,Rn,Pn,t),r&&(c.uv=Jr.getInterpolatedAttribute(r,a,h,l,t,new Zs)),n&&(c.uv1=Jr.getInterpolatedAttribute(n,a,h,l,t,new Zs)),o&&(c.normal=Jr.getInterpolatedAttribute(o,a,h,l,t,new Ii),c.normal.dot(i.direction)>0&&c.normal.multiplyScalar(-1));const e={a:a,b:h,c:l,normal:new Ii,materialIndex:0};Jr.getNormal(En,Rn,Pn,e.normal),c.face=e,c.barycoord=t}return c}class Un extends zn{constructor(t=1,e=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:r,depthSegments:n};const o=this;i=Math.floor(i),r=Math.floor(r),n=Math.floor(n);const a=[],h=[],l=[],c=[];let u=0,d=0;function p(t,e,s,i,r,n,p,m,y,f,g){const x=n/y,b=p/f,v=n/2,w=p/2,M=m/2,S=y+1,_=f+1;let A=0,T=0;const z=new Ii;for(let n=0;n<_;n++){const o=n*b-w;for(let a=0;a0?1:-1,l.push(z.x,z.y,z.z),c.push(a/y),c.push(1-n/f),A+=1}}for(let t=0;t0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const s={};for(const t in this.extensions)!0===this.extensions[t]&&(s[t]=!0);return Object.keys(s).length>0&&(e.extensions=s),e}}class Xn extends Er{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new nr,this.projectionMatrix=new nr,this.projectionMatrixInverse=new nr,this.coordinateSystem=Os}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}const Yn=new Ii,Zn=new Zs,Gn=new Zs;class $n extends Xn{constructor(t=50,e=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=s,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Us*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*Ws*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Us*Math.atan(Math.tan(.5*Ws*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,s){Yn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z),Yn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z)}getViewSize(t,e){return this.getViewBounds(t,Zn,Gn),e.subVectors(Gn,Zn)}setViewOffset(t,e,s,i,r,n){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*Ws*this.fov)/this.zoom,s=2*e,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const t=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/t,e-=n.offsetY*s/o,i*=n.width/t,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-s,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const Qn=-90;class Kn extends Er{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new $n(Qn,1,t,e);i.layers=this.layers,this.add(i);const r=new $n(Qn,1,t,e);r.layers=this.layers,this.add(r);const n=new $n(Qn,1,t,e);n.layers=this.layers,this.add(n);const o=new $n(Qn,1,t,e);o.layers=this.layers,this.add(o);const a=new $n(Qn,1,t,e);a.layers=this.layers,this.add(a);const h=new $n(Qn,1,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,r,n,o,a]=e;for(const t of e)this.remove(t);if(t===Os)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),n.up.set(0,0,1),n.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),a.up.set(0,1,0),a.lookAt(0,0,-1);else{if(t!==Fs)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),n.up.set(0,0,-1),n.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),a.up.set(0,-1,0),a.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,l]=this.children,c=t.getRenderTarget(),u=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,t.setRenderTarget(s,0,i),t.render(e,r),t.setRenderTarget(s,1,i),t.render(e,n),t.setRenderTarget(s,2,i),t.render(e,o),t.setRenderTarget(s,3,i),t.render(e,a),t.setRenderTarget(s,4,i),t.render(e,h),s.texture.generateMipmaps=m,t.setRenderTarget(s,5,i),t.render(e,l),t.setRenderTarget(c,u,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class to extends vi{constructor(t,e,s,i,r,n,o,a,h,l){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,l),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class eo extends Si{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new to(i,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:wt}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const s={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include \n\t\t\t\t\t#include \n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include \n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},i=new Un(5,5,5),r=new Jn({name:"CubemapFromEquirect",uniforms:jn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:0});r.uniforms.tEquirect.value=e;const n=new Vn(i,r),o=e.minFilter;e.minFilter===_t&&(e.minFilter=wt);return new Kn(1,10,this).update(t,n),e.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(t,e,s,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,s,i);t.setRenderTarget(r)}}class so{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new $r(t),this.density=e}clone(){return new so(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class io{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new $r(t),this.near=e,this.far=s}clone(){return new io(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class ro extends Er{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new yr,this.environmentIntensity=1,this.environmentRotation=new yr,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class no{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=_s,this.updateRanges=[],this.version=0,this.uuid=js()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,s){t*=this.stride,s*=e.stride;for(let i=0,r=this.stride;it.far||e.push({distance:a,point:co.clone(),uv:Jr.getInterpolation(co,go,xo,bo,vo,wo,Mo,new Zs),face:null,object:this})}copy(t,e){return super.copy(t,e),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}function _o(t,e,s,i,r,n){mo.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(yo.x=n*mo.x-r*mo.y,yo.y=r*mo.x+n*mo.y):yo.copy(mo),t.copy(e),t.x+=yo.x,t.y+=yo.y,t.applyMatrix4(fo)}const Ao=new Ii,To=new Ii;class zo extends Er{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);const e=t.levels;for(let t=0,s=e.length;t0){let s,i;for(s=1,i=e.length;s0){Ao.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(Ao);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){Ao.setFromMatrixPosition(t.matrixWorld),To.setFromMatrixPosition(this.matrixWorld);const s=Ao.distanceTo(To)/t.zoom;let i,r;for(e[0].object.visible=!0,i=1,r=e.length;i=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i1?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const s=e||ta.getNormalMatrix(t),i=this.coplanarPoint(Qo).applyMatrix4(t),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const sa=new Gi,ia=new Ii;class ra{constructor(t=new ea,e=new ea,s=new ea,i=new ea,r=new ea,n=new ea){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],l=i[5],c=i[6],u=i[7],d=i[8],p=i[9],m=i[10],y=i[11],f=i[12],g=i[13],x=i[14],b=i[15];if(s[0].setComponents(a-r,u-h,y-d,b-f).normalize(),s[1].setComponents(a+r,u+h,y+d,b+f).normalize(),s[2].setComponents(a+n,u+l,y+p,b+g).normalize(),s[3].setComponents(a-n,u-l,y-p,b-g).normalize(),s[4].setComponents(a-o,u-c,y-m,b-x).normalize(),e===Os)s[5].setComponents(a+o,u+c,y+m,b+x).normalize();else{if(e!==Fs)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,c,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),sa.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),sa.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(sa)}intersectsSprite(t){return sa.center.set(0,0,0),sa.radius=.7071067811865476,sa.applyMatrix4(t.matrixWorld),this.intersectsSphere(sa)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)0?t.max.x:t.min.x,ia.y=i.normal.y>0?t.max.y:t.min.y,ia.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ia)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function na(t,e){return t-e}function oa(t,e){return t.z-e.z}function aa(t,e){return e.z-t.z}class ha{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,s,i){const r=this.pool,n=this.list;this.index>=r.length&&r.push({start:-1,count:-1,z:-1,index:-1});const o=r[this.index];n.push(o),this.index++,o.start=t,o.count=e,o.z=s,o.index=i}reset(){this.list.length=0,this.index=0}}const la=new nr,ca=new $r(1,1,1),ua=new ra,da=new Ei,pa=new Gi,ma=new Ii,ya=new Ii,fa=new Ii,ga=new ha,xa=new Vn,ba=[];function va(t,e,s=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const r=t.count;for(let n=0;n65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new cn(t,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(Boolean(t.getIndex())!==Boolean(e.getIndex()))throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');for(const s in e.attributes){if(!t.hasAttribute(s))throw new Error(`THREE.BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=t.getAttribute(s),r=e.getAttribute(s);if(i.itemSize!==r.itemSize||i.normalized!==r.normalized)throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}validateInstanceId(t){const e=this._instanceInfo;if(t<0||t>=e.length||!1===e[t].active)throw new Error(`THREE.BatchedMesh: Invalid instanceId ${t}. Instance is either out of range or has been deleted.`)}validateGeometryId(t){const e=this._geometryInfo;if(t<0||t>=e.length||!1===e[t].active)throw new Error(`THREE.BatchedMesh: Invalid geometryId ${t}. Geometry is either out of range or has been deleted.`)}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Ei);const t=this.boundingBox,e=this._instanceInfo;t.makeEmpty();for(let s=0,i=e.length;s=this.maxInstanceCount&&0===this._availableInstanceIds.length)throw new Error("THREE.BatchedMesh: Maximum item count reached.");const e={visible:!0,active:!0,geometryIndex:t};let s=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(na),s=this._availableInstanceIds.shift(),this._instanceInfo[s]=e):(s=this._instanceInfo.length,this._instanceInfo.push(e));const i=this._matricesTexture;la.identity().toArray(i.image.data,16*s),i.needsUpdate=!0;const r=this._colorsTexture;return r&&(ca.toArray(r.image.data,4*s),r.needsUpdate=!0),this._visibilityChanged=!0,s}addGeometry(t,e=-1,s=-1){this._initializeGeometry(t),this._validateGeometry(t);const i={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},r=this._geometryInfo;i.vertexStart=this._nextVertexStart,i.reservedVertexCount=-1===e?t.getAttribute("position").count:e;const n=t.getIndex();if(null!==n&&(i.indexStart=this._nextIndexStart,i.reservedIndexCount=-1===s?n.count:s),-1!==i.indexStart&&i.indexStart+i.reservedIndexCount>this._maxIndexCount||i.vertexStart+i.reservedVertexCount>this._maxVertexCount)throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");let o;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(na),o=this._availableGeometryIds.shift(),r[o]=i):(o=this._geometryCount,this._geometryCount++,r.push(i)),this.setGeometryAt(o,t),this._nextIndexStart=i.indexStart+i.reservedIndexCount,this._nextVertexStart=i.vertexStart+i.reservedVertexCount,o}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=e.getIndex(),o=this._geometryInfo[t];if(i&&n.count>o.reservedIndexCount||e.attributes.position.count>o.reservedVertexCount)throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");const a=o.vertexStart,h=o.reservedVertexCount;o.vertexCount=e.getAttribute("position").count;for(const t in s.attributes){const i=e.getAttribute(t),r=s.getAttribute(t);va(i,r,a);const n=i.itemSize;for(let t=i.count,e=h;t=e.length||!1===e[t].active)return this;const s=this._instanceInfo;for(let e=0,i=s.length;ee)).sort(((t,e)=>s[t].vertexStart-s[e].vertexStart)),r=this.geometry;for(let n=0,o=s.length;n=this._geometryCount)return null;const s=this.geometry,i=this._geometryInfo[t];if(null===i.boundingBox){const t=new Ei,e=s.index,r=s.attributes.position;for(let s=i.start,n=i.start+i.count;s=this._geometryCount)return null;const s=this.geometry,i=this._geometryInfo[t];if(null===i.boundingSphere){const e=new Gi;this.getBoundingBoxAt(t,da),da.getCenter(e.center);const r=s.index,n=s.attributes.position;let o=0;for(let t=i.start,s=i.start+i.count;tt.active));if(Math.max(...s.map((t=>t.vertexStart+t.reservedVertexCount)))>t)throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${e}. Cannot shrink further.`);if(this.geometry.index){if(Math.max(...s.map((t=>t.indexStart+t.reservedIndexCount)))>e)throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${e}. Cannot shrink further.`)}const i=this.geometry;i.dispose(),this._maxVertexCount=t,this._maxIndexCount=e,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new zn,this._initializeGeometry(i));const r=this.geometry;i.index&&wa(i.index.array,r.index.array);for(const t in i.attributes)wa(i.attributes[t].array,r.attributes[t].array)}raycast(t,e){const s=this._instanceInfo,i=this._geometryInfo,r=this.matrixWorld,n=this.geometry;xa.material=this.material,xa.geometry.index=n.index,xa.geometry.attributes=n.attributes,null===xa.geometry.boundingBox&&(xa.geometry.boundingBox=new Ei),null===xa.geometry.boundingSphere&&(xa.geometry.boundingSphere=new Gi);for(let n=0,o=s.length;n({...t,boundingBox:null!==t.boundingBox?t.boundingBox.clone():null,boundingSphere:null!==t.boundingSphere?t.boundingSphere.clone():null}))),this._instanceInfo=t._instanceInfo.map((t=>({...t}))),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),null!==this._colorsTexture&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,null!==this._colorsTexture&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,s,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const n=i.getIndex(),o=null===n?1:n.array.BYTES_PER_ELEMENT,a=this._instanceInfo,h=this._multiDrawStarts,l=this._multiDrawCounts,c=this._geometryInfo,u=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;u&&(la.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),ua.setFromProjectionMatrix(la,t.coordinateSystem));let m=0;if(this.sortObjects){la.copy(this.matrixWorld).invert(),ma.setFromMatrixPosition(s.matrixWorld).applyMatrix4(la),ya.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(la);for(let t=0,e=a.length;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;ti)return;Ia.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Ia);return ae.far?void 0:{distance:a,point:Ba.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:t}}const Ra=new Ii,Pa=new Ii;class Oa extends ka{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,s=[];for(let t=0,i=e.count;t0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;tr.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:e,face:null,faceIndex:null,barycoord:null,object:o})}}class Ha extends Er{constructor(){super(),this.isGroup=!0,this.type="Group"}}class qa extends vi{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:wt,this.magFilter=void 0!==r?r:wt,this.generateMipmaps=!1;const l=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){l.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class Ja extends vi{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class Xa extends vi{constructor(t,e,s,i,r,n,o,a,h,l,c,u){super(null,n,o,a,h,l,i,r,c,u),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Ya extends Xa{constructor(t,e,s,i,r,n){super(t,e,s,r,n),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=mt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Za extends Xa{constructor(t,e,s){super(void 0,t[0].width,t[0].height,e,s,ht),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Ga extends vi{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class $a extends vi{constructor(t,e,s,i,r,n,o,a,h,l=1026){if(l!==Dt&&l!==Ht)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&l===Dt&&(s=kt),void 0===s&&l===Ht&&(s=1020),super(null,i,r,n,o,a,l,s,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==o?o:ft,this.minFilter=void 0!==a?a:ft,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return null!==this.compareFunction&&(e.compareFunction=this.compareFunction),e}}class Qa{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const s=this.getUtoTmapping(t);return this.getPoint(s,e)}getPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return e}getSpacedPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPointAt(s/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let s,i=this.getPoint(0),r=0;e.push(0);for(let n=1;n<=t;n++)s=this.getPoint(n/t),r+=s.distanceTo(i),e.push(r),i=s;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const s=this.getLengths();let i=0;const r=s.length;let n;n=e||t*s[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=s[i]-n,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,s[i]===n)return i/(r-1);const l=s[i];return(i+(n-l)/(s[i+1]-l))/(r-1)}getTangent(t,e){const s=1e-4;let i=t-s,r=t+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=e||(n.isVector2?new Zs:new Ii);return a.copy(o).sub(n).normalize(),a}getTangentAt(t,e){const s=this.getUtoTmapping(t);return this.getTangent(s,e)}computeFrenetFrames(t,e){const s=new Ii,i=[],r=[],n=[],o=new Ii,a=new nr;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ii)}r[0]=new Ii,n[0]=new Ii;let h=Number.MAX_VALUE;const l=Math.abs(i[0].x),c=Math.abs(i[0].y),u=Math.abs(i[0].z);l<=h&&(h=l,s.set(1,0,0)),c<=h&&(h=c,s.set(0,1,0)),u<=h&&s.set(0,0,1),o.crossVectors(i[0],s).normalize(),r[0].crossVectors(i[0],o),n[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),n[e]=n[e-1].clone(),o.crossVectors(i[e-1],i[e]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos(Ds(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(a.makeRotationAxis(o,t))}n[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos(Ds(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let s=1;s<=t;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],e*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class Ka extends Qa{constructor(t=0,e=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new Zs){const s=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)i;)r-=i;r0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===l&&h===r-1&&(h=r-2,l=1),this.closed||h>0?o=i[(h-1)%r]:(sh.subVectors(i[0],i[1]).add(i[0]),o=sh);const c=i[h%r],u=i[(h+1)%r];if(this.closed||h+2i.length-2?i.length-1:n+1],c=i[n>i.length-3?i.length-1:n+2];return s.set(ah(o,a.x,h.x,l.x,c.x),ah(o,a.y,h.y,l.y,c.y)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e=s){const t=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-t/o;return n.getPointAt(a,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let s=0,i=this.curves.length;s1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,s=t.curves.length;e0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const l=h.getPoint(1);return this.currentPoint.copy(l),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class vh extends zn{constructor(t=[new Zs(0,-.5),new Zs(.5,0),new Zs(0,.5)],e=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:s,phiLength:i},e=Math.floor(e),i=Ds(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],l=1/e,c=new Ii,u=new Zs,d=new Ii,p=new Ii,m=new Ii;let y=0,f=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:y=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-y,d.z=0*f,m.copy(d),d.normalize(),a.push(d.x,d.y,d.z);break;case t.length-1:a.push(m.x,m.y,m.z);break;default:y=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-y,d.z=0*f,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),a.push(d.x,d.y,d.z),m.copy(p)}for(let r=0;r<=e;r++){const d=s+r*l*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){c.x=t[s].x*p,c.y=t[s].y,c.z=t[s].x*m,n.push(c.x,c.y,c.z),u.x=r/e,u.y=s/(t.length-1),o.push(u.x,u.y);const i=a[3*s+0]*p,l=a[3*s+1],d=a[3*s+0]*m;h.push(i,l,d)}}for(let s=0;s0||0!==i)&&(l.push(n,o,h),x+=3),(e>0||i!==r-1)&&(l.push(o,a,h),x+=3)}h.addGroup(f,x,0),f+=x}(),!1===n&&(t>0&&g(!0),e>0&&g(!1)),this.setIndex(l),this.setAttribute("position",new bn(c,3)),this.setAttribute("normal",new bn(u,3)),this.setAttribute("uv",new bn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Sh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class _h extends Sh{constructor(t=1,e=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,t,e,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(t){return new _h(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Ah extends zn{constructor(t=[],e=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:s,detail:i};const r=[],n=[];function o(t,e,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=t.clone().lerp(s,i/r),a=e.clone().lerp(s,i/r),h=r-i;for(let t=0;t<=h;t++)n[i][t]=0===t&&i===r?o:o.clone().lerp(a,t/h)}for(let t=0;t.9&&o<.1&&(e<.2&&(n[t+0]+=1),s<.2&&(n[t+2]+=1),i<.2&&(n[t+4]+=1))}}()}(),this.setAttribute("position",new bn(r,3)),this.setAttribute("normal",new bn(r.slice(),3)),this.setAttribute("uv",new bn(n,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ah(t.vertices,t.indices,t.radius,t.details)}}class Th extends Ah{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2,i=1/s;super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-s,0,-i,s,0,i,-s,0,i,s,-i,-s,0,-i,s,0,i,-s,0,i,s,0,-s,0,-i,s,0,-i,-s,0,i,s,0,i],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Th(t.radius,t.detail)}}const zh=new Ii,Ch=new Ii,Ih=new Ii,Bh=new Jr;class kh extends zn{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const s=4,i=Math.pow(10,s),r=Math.cos(Ws*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],l=["a","b","c"],c=new Array(3),u={},d=[];for(let t=0;t80*s){a=l=t[0],h=c=t[1];for(let e=s;el&&(l=u),d>c&&(c=d);p=Math.max(l-a,c-h),p=0!==p?32767/p:0}return Fh(n,o,s,a,h,p,0),o};function Ph(t,e,s,i,r){let n,o;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n0)for(n=e;n=e;n-=i)o=el(n,t[n],t[n+1],o);return o&&Zh(o,o.next)&&(sl(o),o=o.next),o}function Oh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!Zh(i,i.next)&&0!==Yh(i.prev,i,i.next))i=i.next;else{if(sl(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Fh(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=Hh(r.x,r.y,e,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,s,i,r,n,o,a,h,l=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e0||h>0&&i;)0!==a&&(0===h||!i||s.z<=i.z)?(r=s,s=s.nextZ,a--):(r=i,i=i.nextZ,h--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;s=i}n.nextZ=null,l*=2}while(o>1)}(r)}(t,i,r,n);let a,h,l=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Lh(t,i,r,n):Nh(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),sl(t),t=h.next,l=h.next;else if((t=h)===l){o?1===o?Fh(t=Vh(Oh(t),e,s),e,s,i,r,n,2):2===o&&Wh(t,e,s,i,r,n):Fh(Oh(t),e,s,i,r,n,1);break}}function Nh(t){const e=t.prev,s=t,i=t.next;if(Yh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,l=i.y,c=rn?r>o?r:o:n>o?n:o,p=a>h?a>l?a:l:h>l?h:l;let m=i.next;for(;m!==e;){if(m.x>=c&&m.x<=d&&m.y>=u&&m.y<=p&&Jh(r,a,n,h,o,l,m.x,m.y)&&Yh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Lh(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Yh(r,n,o)>=0)return!1;const a=r.x,h=n.x,l=o.x,c=r.y,u=n.y,d=o.y,p=ah?a>l?a:l:h>l?h:l,f=c>u?c>d?c:d:u>d?u:d,g=Hh(p,m,e,s,i),x=Hh(y,f,e,s,i);let b=t.prevZ,v=t.nextZ;for(;b&&b.z>=g&&v&&v.z<=x;){if(b.x>=p&&b.x<=y&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Jh(a,c,h,u,l,d,b.x,b.y)&&Yh(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,v.x>=p&&v.x<=y&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Jh(a,c,h,u,l,d,v.x,v.y)&&Yh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;b&&b.z>=g;){if(b.x>=p&&b.x<=y&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Jh(a,c,h,u,l,d,b.x,b.y)&&Yh(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=y&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Jh(a,c,h,u,l,d,v.x,v.y)&&Yh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Vh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!Zh(r,n)&&Gh(r,i,i.next,n)&&Kh(r,n)&&Kh(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),sl(i),sl(i.next),i=t=n),i=i.next}while(i!==t);return Oh(i)}function Wh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Xh(o,t)){let a=tl(o,t);return o=Oh(o,o.next),a=Oh(a,a.next),Fh(o,e,s,i,r,n,0),void Fh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Uh(t,e){return t.x-e.x}function jh(t,e){const s=function(t,e){let s,i=e,r=-1/0;const n=t.x,o=t.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const t=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>r&&(r=t,s=i.x=i.x&&i.x>=h&&n!==i.x&&Jh(os.x||i.x===s.x&&Dh(s,i)))&&(s=i,u=c)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=tl(s,t);return Oh(i,i.next),Oh(s,s.next)}function Dh(t,e){return Yh(t.prev,t,e.prev)<0&&Yh(e.next,t,t.next)<0}function Hh(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function qh(t){let e=t,s=t;do{(e.x=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Xh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Gh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(Kh(t,e)&&Kh(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Yh(t.prev,t,e.prev)||Yh(t,e.prev,e))||Zh(t,e)&&Yh(t.prev,t,t.next)>0&&Yh(e.prev,e,e.next)>0)}function Yh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Zh(t,e){return t.x===e.x&&t.y===e.y}function Gh(t,e,s,i){const r=Qh(Yh(t,e,s)),n=Qh(Yh(t,e,i)),o=Qh(Yh(s,i,t)),a=Qh(Yh(s,i,e));return r!==n&&o!==a||(!(0!==r||!$h(t,s,e))||(!(0!==n||!$h(t,i,e))||(!(0!==o||!$h(s,t,i))||!(0!==a||!$h(s,e,i)))))}function $h(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function Qh(t){return t>0?1:t<0?-1:0}function Kh(t,e){return Yh(t.prev,t,t.next)<0?Yh(t,e,t.next)>=0&&Yh(t,t.prev,e)>=0:Yh(t,e,t.prev)<0||Yh(t,t.next,e)<0}function tl(t,e){const s=new il(t.i,t.x,t.y),i=new il(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function el(t,e,s,i){const r=new il(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function sl(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function il(t,e,s){this.i=t,this.x=e,this.y=s,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class rl{static area(t){const e=t.length;let s=0;for(let i=e-1,r=0;r2&&t[e-1].equals(t[0])&&t.pop()}function ol(t,e){for(let s=0;sNumber.EPSILON){const u=Math.sqrt(c),d=Math.sqrt(h*h+l*l),p=e.x-a/u,m=e.y+o/u,y=((s.x-l/d-p)*l-(s.y+h/d-m)*h)/(o*l-a*h);i=p+o*y-t.x,r=m+a*y-t.y;const f=i*i+r*r;if(f<=2)return new Zs(i,r);n=Math.sqrt(f/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(l)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(c)):(i=o,r=a,n=Math.sqrt(c/2))}return new Zs(i/n,r/n)}const k=[];for(let t=0,e=T.length,s=e-1,i=t+1;t=0;t--){const e=t/p,s=c*Math.cos(e*Math.PI/2),i=u*Math.sin(e*Math.PI/2)+d;for(let t=0,e=T.length;t=0;){const i=s;let r=s-1;r<0&&(r=t.length-1);for(let t=0,s=a+2*p;t0)&&d.push(e,r,h),(t!==s-1||a0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class Tl extends tn{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new $r(16777215),this.specular=new $r(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new yr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class zl extends tn{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new $r(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}class Cl extends tn{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class Il extends tn{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new $r(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new $r(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new yr,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Bl extends tn{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class kl extends tn{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}class El extends tn{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new $r(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Zs(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}class Rl extends Sa{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function Pl(t,e,s){return!t||!s&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function Ol(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Fl(t){const e=t.length,s=new Array(e);for(let t=0;t!==e;++t)s[t]=t;return s.sort((function(e,s){return t[e]-t[s]})),s}function Nl(t,e,s){const i=t.length,r=new t.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*e;for(let s=0;s!==e;++s)r[o++]=t[i+s]}return r}function Ll(t,e,s,i){let r=1,n=t[0];for(;void 0!==n&&void 0===n[i];)n=t[r++];if(void 0===n)return;let o=n[i];if(void 0!==o)if(Array.isArray(o))do{o=n[i],void 0!==o&&(e.push(n.time),s.push.apply(s,o)),n=t[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(e.push(n.time),o.toArray(s,s.length)),n=t[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(e.push(n.time),s.push(o)),n=t[r++]}while(void 0!==n)}const Vl={convertArray:Pl,isTypedArray:Ol,getKeyframeOrder:Fl,sortedArray:Nl,flattenJSON:Ll,subclip:function(t,e,s,i,r=30){const n=t.clone();n.name=e;const o=[];for(let t=0;t=i)){h.push(e.times[t]);for(let s=0;sn.tracks[t].times[0]&&(a=n.tracks[t].times[0]);for(let t=0;t=i.times[u]){const t=u*h+a,e=t+h-a;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=a,s=h-a;t.evaluate(n),d=t.resultBuffer.slice(e,s)}if("quaternion"===r){(new Ci).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t=r)break t;{const o=e[1];t=r)break e}n=s,s=0}}for(;s>>1;te;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const t=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*t,n*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let n=null;for(let e=0;e!==r;e++){const i=s[e];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,n),t=!1;break}n=i}if(void 0!==i&&Ol(i))for(let e=0,s=i.length;e!==s;++e){const s=i[e];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,s),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===Pe,r=t.length-1;let n=1;for(let o=1;o0){t[n]=t[r];for(let t=r*s,i=n*s,o=0;o!==s;++o)e[i+o]=e[t+o];++n}return n!==t.length?(this.times=t.slice(0,n),this.values=e.slice(0,n*s)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),s=new(0,this.constructor)(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}Hl.prototype.TimeBufferType=Float32Array,Hl.prototype.ValueBufferType=Float32Array,Hl.prototype.DefaultInterpolation=Re;class ql extends Hl{constructor(t,e,s){super(t,e,s)}}ql.prototype.ValueTypeName="bool",ql.prototype.ValueBufferType=Array,ql.prototype.DefaultInterpolation=Ee,ql.prototype.InterpolantFactoryMethodLinear=void 0,ql.prototype.InterpolantFactoryMethodSmooth=void 0;class Jl extends Hl{}Jl.prototype.ValueTypeName="color";class Xl extends Hl{}Xl.prototype.ValueTypeName="number";class Yl extends Wl{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-e)/(i-e);let h=t*o;for(let t=h+o;h!==t;h+=4)Ci.slerpFlat(r,0,n,h-o,n,h,a);return r}}class Zl extends Hl{InterpolantFactoryMethodLinear(t){return new Yl(this.times,this.values,this.getValueSize(),t)}}Zl.prototype.ValueTypeName="quaternion",Zl.prototype.InterpolantFactoryMethodSmooth=void 0;class Gl extends Hl{constructor(t,e,s){super(t,e,s)}}Gl.prototype.ValueTypeName="string",Gl.prototype.ValueBufferType=Array,Gl.prototype.DefaultInterpolation=Ee,Gl.prototype.InterpolantFactoryMethodLinear=void 0,Gl.prototype.InterpolantFactoryMethodSmooth=void 0;class $l extends Hl{}$l.prototype.ValueTypeName="vector";class Ql{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=js(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],s=t.tracks,i=1/(t.fps||1);for(let t=0,r=s.length;t!==r;++t)e.push(Kl(s[t]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],s=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=s.length;t!==i;++t)e.push(Hl.toJSON(s[t]));return i}static CreateFromMorphTargetSequence(t,e,s,i){const r=e.length,n=[];for(let t=0;t1){const t=n[1];let e=i[t];e||(i[t]=e=[]),e.push(s)}}const n=[];for(const t in i)n.push(this.CreateFromMorphTargetSequence(t,i[t],e,s));return n}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(t,e,s,i,r){if(0!==s.length){const n=[],o=[];Ll(s,n,o,i),0!==n.length&&r.push(new t(e,n,o))}},i=[],r=t.name||"default",n=t.fps||30,o=t.blendMode;let a=t.length||-1;const h=t.hierarchy||[];for(let t=0;t{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==rc[t])return void rc[t].push({onLoad:e,onProgress:s,onError:i});rc[t]=[],rc[t].push({onLoad:e,onProgress:s,onError:i});const n=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).then((e=>{if(200===e.status||0===e.status){if(0===e.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===e.body||void 0===e.body.getReader)return e;const s=rc[t],i=e.body.getReader(),r=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:r})=>{if(i)t.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let t=0,e=s.length;t{t.error(e)}))}()}});return new Response(h)}throw new nc(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(a){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,o)));case"json":return t.json();default:if(void 0===o)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(o),s=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(s);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{tc.add(t,e);const s=rc[t];delete rc[t];for(let t=0,i=s.length;t{const s=rc[t];if(void 0===s)throw this.manager.itemError(t),e;delete rc[t];for(let t=0,i=s.length;t{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class ac extends ic{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new oc(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=[];for(let s=0;s0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const r=t.uniforms[e];switch(i.uniforms[e]={},r.type){case"t":i.uniforms[e].value=s(r.value);break;case"c":i.uniforms[e].value=(new $r).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Zs).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ii).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new wi).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new Gs).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new nr).fromArray(r.value);break;default:i.uniforms[e].value=r.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.glslVersion&&(i.glslVersion=t.glslVersion),void 0!==t.extensions)for(const e in t.extensions)i.extensions[e]=t.extensions[e];if(void 0!==t.lights&&(i.lights=t.lights),void 0!==t.clipping&&(i.clipping=t.clipping),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=s(t.map)),void 0!==t.matcap&&(i.matcap=s(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=s(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=s(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=s(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){let e=t.normalScale;!1===Array.isArray(e)&&(e=[e,e]),i.normalScale=(new Zs).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=s(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=s(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=s(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=s(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=s(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=s(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=s(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=s(t.envMap)),void 0!==t.envMapRotation&&i.envMapRotation.fromArray(t.envMapRotation),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=s(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=s(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=s(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=s(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=s(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new Zs).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=s(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=s(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=s(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=s(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=s(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=s(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}createMaterialFromType(t){return Rc.createMaterialFromType(t)}static createMaterialFromType(t){return new{ShadowMaterial:Ml,SpriteMaterial:ho,RawShaderMaterial:Sl,ShaderMaterial:Jn,PointsMaterial:Na,MeshPhysicalMaterial:Al,MeshStandardMaterial:_l,MeshPhongMaterial:Tl,MeshToonMaterial:zl,MeshNormalMaterial:Cl,MeshLambertMaterial:Il,MeshDepthMaterial:Bl,MeshDistanceMaterial:kl,MeshBasicMaterial:en,MeshMatcapMaterial:El,LineDashedMaterial:Rl,LineBasicMaterial:Sa,Material:tn}[t]}}class Pc{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let s=0,i=t.length;s0){const s=new ec(e);r=new lc(s),r.setCrossOrigin(this.crossOrigin);for(let e=0,s=t.length;e0){i=new lc(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e{const e=new Ei;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new Gi;return s.radius=t.sphereRadius,s.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:s}})),n._maxInstanceCount=t.maxInstanceCount,n._maxVertexCount=t.maxVertexCount,n._maxIndexCount=t.maxIndexCount,n._geometryInitialized=t.geometryInitialized,n._geometryCount=t.geometryCount,n._matricesTexture=c(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=c(t.colorsTexture.uuid));break;case"LOD":n=new zo;break;case"Line":n=new ka(h(t.geometry),l(t.material));break;case"LineLoop":n=new Fa(h(t.geometry),l(t.material));break;case"LineSegments":n=new Oa(h(t.geometry),l(t.material));break;case"PointCloud":case"Points":n=new ja(h(t.geometry),l(t.material));break;case"Sprite":n=new So(l(t.material));break;case"Group":n=new Ha;break;case"Bone":n=new Lo;break;default:n=new Er}if(n.uuid=t.uuid,void 0!==t.name&&(n.name=t.name),void 0!==t.matrix?(n.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(n.matrixAutoUpdate=t.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==t.position&&n.position.fromArray(t.position),void 0!==t.rotation&&n.rotation.fromArray(t.rotation),void 0!==t.quaternion&&n.quaternion.fromArray(t.quaternion),void 0!==t.scale&&n.scale.fromArray(t.scale)),void 0!==t.up&&n.up.fromArray(t.up),void 0!==t.castShadow&&(n.castShadow=t.castShadow),void 0!==t.receiveShadow&&(n.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(n.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(n.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(n.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(n.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&n.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(n.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.frustumCulled&&(n.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(n.renderOrder=t.renderOrder),void 0!==t.userData&&(n.userData=t.userData),void 0!==t.layers&&(n.layers.mask=t.layers),void 0!==t.children){const o=t.children;for(let t=0;t{e&&e(s),r.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(t,o).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(r.options,{colorSpaceConversion:"none"}))})).then((function(s){return tc.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),tc.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));tc.add(t,a),r.manager.itemStart(t)}}let jc;class Dc{static getContext(){return void 0===jc&&(jc=new(window.AudioContext||window.webkitAudioContext)),jc}static setContext(t){jc=t}}class Hc extends ic{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new oc(this.manager);function o(e){i?i(e):console.error(e),r.manager.itemError(t)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(t){try{const s=t.slice(0);Dc.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const qc=new nr,Jc=new nr,Xc=new nr;class Yc{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new $n,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new $n,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,Xc.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(Ws*e.fov*.5)/e.zoom;let n,o;Jc.elements[12]=-s,qc.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,Xc.elements[0]=2*e.near/(o-n),Xc.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Xc),n=-r*e.aspect-i,o=r*e.aspect-i,Xc.elements[0]=2*e.near/(o-n),Xc.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Xc)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(Jc),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(qc)}}class Zc extends $n{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Gc{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=$c(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=$c();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function $c(){return performance.now()}const Qc=new Ii,Kc=new Ci,tu=new Ii,eu=new Ii;class su extends Er{constructor(){super(),this.type="AudioListener",this.context=Dc.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Gc}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return null!==this.filter?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(Qc,Kc,tu),eu.set(0,0,-1).applyQuaternion(Kc),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(Qc.x,t),e.positionY.linearRampToValueAtTime(Qc.y,t),e.positionZ.linearRampToValueAtTime(Qc.z,t),e.forwardX.linearRampToValueAtTime(eu.x,t),e.forwardY.linearRampToValueAtTime(eu.y,t),e.forwardZ.linearRampToValueAtTime(eu.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(Qc.x,Qc.y,Qc.z),e.setOrientation(eu.x,eu.y,eu.z,s.x,s.y,s.z)}}class iu extends Er{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return void console.warn("THREE.Audio: Audio is already playing.");if(!1===this.hasPlaybackControl)return void console.warn("THREE.Audio: this Audio has no playback control.");this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(t=0){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(this.context.currentTime+t),this.source.onended=null),this.isPlaying=!1,this;console.warn("THREE.Audio: this Audio has no playback control.")}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t0&&this._mixBufferRegionAdditive(s,i,this._addIndex*e,1,e);for(let t=e,r=e+e;t!==r;++t)if(s[t]!==s[t+e]){o.setValue(s,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,s=this.valueSize,i=s*this._origIndex;t.getValue(e,i);for(let t=s,r=i;t!==r;++t)e[t]=e[i+t%s];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let s=t;s=.5)for(let i=0;i!==r;++i)t[e+i]=t[s+i]}_slerp(t,e,s,i){Ci.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Ci.multiplyQuaternionsFlat(t,n,t,e,t,s),Ci.slerpFlat(t,e,t,e,t,n,i)}_lerp(t,e,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=e+o;t[r]=t[r]*n+t[s+o]*i}}_lerpAdditive(t,e,s,i,r){for(let n=0;n!==r;++n){const r=e+n;t[r]=t[r]+t[s+n]*i}}}const uu="\\[\\]\\.:\\/",du=new RegExp("["+uu+"]","g"),pu="[^"+uu+"]",mu="[^"+uu.replace("\\.","")+"]",yu=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",pu)+/(WCOD+)?/.source.replace("WCOD",mu)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",pu)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",pu)+"$"),fu=["material","materials","bones","map"];class gu{constructor(t,e,s){this.path=e,this.parsedPath=s||gu.parseTrackName(e),this.node=gu.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,s){return t&&t.isAnimationObjectGroup?new gu.Composite(t,e,s):new gu(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(du,"")}static parseTrackName(t){const e=yu.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const s={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=s.nodeName.substring(i+1);-1!==fu.indexOf(t)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=t)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return s}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const s=t.skeleton.getBoneByName(e);if(void 0!==s)return s}if(t.children){const s=function(t){for(let i=0;i=r){const n=r++,l=t[n];e[l.uuid]=h,t[h]=l,e[a]=n,t[n]=o;for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[n],r=e[h];e[h]=i,e[n]=r}}}this.nCachedObjects_=r}uncache(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=t.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=e[a];if(void 0!==h)if(delete e[a],h0&&(e[o.uuid]=h),t[h]=o,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t];e[h]=e[r],e.pop()}}}this.nCachedObjects_=r}subscribe_(t,e){const s=this._bindingsIndicesByPath;let i=s[t];const r=this._bindings;if(void 0!==i)return r[i];const n=this._paths,o=this._parsedPaths,a=this._objects,h=a.length,l=this.nCachedObjects_,c=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(c);for(let s=l,i=a.length;s!==i;++s){const i=a[s];c[s]=new gu(i,t,e)}return c}unsubscribe_(t){const e=this._bindingsIndicesByPath,s=e[t];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];e[t[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class bu{constructor(t,e,s=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=s,this.blendMode=i;const r=e.tracks,n=r.length,o=new Array(n),a={endingStart:Oe,endingEnd:Oe};for(let t=0;t!==n;++t){const e=r[t].createInterpolant(null);o[t]=e,e.settings=a}this._interpolantSettings=a,this._interpolants=o,this._propertyBindings=new Array(n),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,s){if(t.fadeOut(e),this.fadeIn(e),s){const s=this._clip.duration,i=t._clip.duration,r=i/s,n=s/i;t.warp(1,r,e),this.warp(n,1,e)}return this}crossFadeTo(t,e,s){return t.crossFadeFrom(this,e,s)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,s){const i=this._mixer,r=i.time,n=this.timeScale;let o=this._timeScaleInterpolant;null===o&&(o=i._lendControlInterpolant(),this._timeScaleInterpolant=o);const a=o.parameterPositions,h=o.sampleValues;return a[0]=r,a[1]=r+s,h[0]=t/n,h[1]=e/n,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,s,i){if(!this.enabled)return void this._updateWeight(t);const r=this._startTime;if(null!==r){const i=(t-r)*s;i<0||0===s?e=0:(this._startTime=null,e=s*i)}e*=this._updateTimeScale(t);const n=this._updateTime(e),o=this._updateWeight(t);if(o>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Ve)for(let s=0,i=t.length;s!==i;++s)t[s].evaluate(n),e[s].accumulateAdditive(o);else for(let s=0,r=t.length;s!==r;++s)t[s].evaluate(n),e[s].accumulate(i,o)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(t)[0];e*=i,t>s.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const s=this._timeScaleInterpolant;if(null!==s){e*=s.evaluate(t)[0],t>s.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,s=this.loop;let i=this.time+t,r=this._loopCount;const n=2202===s;if(0===t)return-1===r?i:n&&1==(1&r)?e-i:i;if(2200===s){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=e||i<0){const s=Math.floor(i/e);i-=e*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===o){const e=t<0;this._setEndings(e,!e,n)}else this._setEndings(!1,!1,n);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:s})}}else this.time=i;if(n&&1==(1&r))return e-i}return i}_setEndings(t,e,s){const i=this._interpolantSettings;s?(i.endingStart=Fe,i.endingEnd=Fe):(i.endingStart=t?this.zeroSlopeAtStart?Fe:Oe:Ne,i.endingEnd=e?this.zeroSlopeAtEnd?Fe:Oe:Ne)}_scheduleFading(t,e,s){const i=this._mixer,r=i.time;let n=this._weightInterpolant;null===n&&(n=i._lendControlInterpolant(),this._weightInterpolant=n);const o=n.parameterPositions,a=n.sampleValues;return o[0]=r,a[0]=e,o[1]=r+t,a[1]=s,this}}const vu=new Float32Array(1);class wu extends Ns{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const s=t._localRoot||this._root,i=t._clip.tracks,r=i.length,n=t._propertyBindings,o=t._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let l=h[a];void 0===l&&(l={},h[a]=l);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let c=l[h];if(void 0!==c)++c.referenceCount,n[t]=c;else{if(c=n[t],void 0!==c){null===c._cacheIndex&&(++c.referenceCount,this._addInactiveBinding(c,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;c=new cu(gu.create(s,h,i),r.ValueTypeName,r.getValueSize()),++c.referenceCount,this._addInactiveBinding(c,a,h),n[t]=c}o[t].resultBuffer=c.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,s=t._clip.uuid,i=this._actionsByClip[s];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,s,e)}const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,s=this._nActiveActions,i=this.time+=t,r=Math.sign(t),n=this._accuIndex^=1;for(let o=0;o!==s;++o){e[o]._update(i,t,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let t=0;t!==a;++t)o[t].apply(n);return this}setTime(t){this.time=0;for(let t=0;t=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Pu).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Fu=new Ii,Nu=new Ii;class Lu{constructor(t=new Ii,e=new Ii){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){Fu.subVectors(t,this.start),Nu.subVectors(this.end,this.start);const s=Nu.dot(Nu);let i=Nu.dot(Fu)/s;return e&&(i=Ds(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(i).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}const Vu=new Ii;class Wu extends Er{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new zn,i=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let t=0,e=1,s=32;t1)for(let s=0;s.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{ud.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(ud,e)}}setLength(t,e=.2*t,s=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(s,e,s),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class yd extends Oa{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],s=new zn;s.setAttribute("position",new bn(e,3)),s.setAttribute("color",new bn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new Sa({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new $r,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(s),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class fd{constructor(){this.type="ShapePath",this.color=new $r,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new bh,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,s,i){return this.currentPath.quadraticCurveTo(t,e,s,i),this}bezierCurveTo(t,e,s,i,r,n){return this.currentPath.bezierCurveTo(t,e,s,i,r,n),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const s=e.length;let i=!1;for(let r=s-1,n=0;nNumber.EPSILON){if(h<0&&(s=e[n],a=-a,o=e[r],h=-h),t.yo.y)continue;if(t.y===s.y){if(t.x===s.x)return!0}else{const e=h*(t.x-s.x)-a*(t.y-s.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==s.y)continue;if(o.x<=t.x&&t.x<=s.x||s.x<=t.x&&t.x<=o.x)return!0}}return i}const s=rl.isClockWise,i=this.subPaths;if(0===i.length)return[];let r,n,o;const a=[];if(1===i.length)return n=i[0],o=new Eh,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const l=[],c=[];let u,d,p=[],m=0;c[m]=void 0,p[m]=[];for(let e=0,o=i.length;e1){let t=!1,s=0;for(let t=0,e=c.length;t0&&!1===t&&(p=l)}for(let t=0,e=c.length;te?(t.repeat.x=1,t.repeat.y=s/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2):(t.repeat.x=e/s,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0),t},cover:function(t,e){const s=t.image&&t.image.width?t.image.width/t.image.height:1;return s>e?(t.repeat.x=e/s,t.repeat.y=1,t.offset.x=(1-t.repeat.x)/2,t.offset.y=0):(t.repeat.x=1,t.repeat.y=s/e,t.offset.x=0,t.offset.y=(1-t.repeat.y)/2),t},fill:function(t){return t.repeat.x=1,t.repeat.y=1,t.offset.x=0,t.offset.y=0,t},getByteLength:xd};class vd extends Si{constructor(t=1,e=1,s=1,i={}){console.warn('THREE.WebGLMultipleRenderTargets has been deprecated and will be removed in r172. Use THREE.WebGLRenderTarget and set the "count" parameter to enable MRT.'),super(t,e,{...i,count:s}),this.isWebGLMultipleRenderTargets=!0}get texture(){return this.textures}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:t}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=t);export{et as ACESFilmicToneMapping,v as AddEquation,G as AddOperation,Ve as AdditiveAnimationBlendMode,f as AdditiveBlending,it as AgXToneMapping,Lt as AlphaFormat,Ss as AlwaysCompare,U as AlwaysDepth,ys as AlwaysStencilFunc,Ic as AmbientLight,bu as AnimationAction,Ql as AnimationClip,ac as AnimationLoader,wu as AnimationMixer,xu as AnimationObjectGroup,Vl as AnimationUtils,th as ArcCurve,Zc as ArrayCamera,md as ArrowHelper,nt as AttachedBindMode,iu as Audio,lu as AudioAnalyser,Dc as AudioContext,su as AudioListener,Hc as AudioLoader,yd as AxesHelper,d as BackSide,De as BasicDepthPacking,a as BasicShadowMap,Ma as BatchedMesh,Lo as Bone,ql as BooleanKeyframeTrack,Ou as Box2,Ei as Box3,ld as Box3Helper,Un as BoxGeometry,hd as BoxHelper,cn as BufferAttribute,zn as BufferGeometry,Fc as BufferGeometryLoader,zt as ByteType,tc as Cache,Xn as Camera,nd as CameraHelper,Ga as CanvasTexture,wh as CapsuleGeometry,oh as CatmullRomCurve3,tt as CineonToneMapping,Mh as CircleGeometry,mt as ClampToEdgeWrapping,Gc as Clock,$r as Color,Jl as ColorKeyframeTrack,ui as ColorManagement,Ya as CompressedArrayTexture,Za as CompressedCubeTexture,Xa as CompressedTexture,hc as CompressedTextureLoader,_h as ConeGeometry,L as ConstantAlphaFactor,F as ConstantColorFactor,gd as Controls,Kn as CubeCamera,ht as CubeReflectionMapping,lt as CubeRefractionMapping,to as CubeTexture,cc as CubeTextureLoader,dt as CubeUVReflectionMapping,ch as CubicBezierCurve,uh as CubicBezierCurve3,Ul as CubicInterpolant,r as CullFaceBack,n as CullFaceFront,o as CullFaceFrontBack,i as CullFaceNone,Qa as Curve,xh as CurvePath,b as CustomBlending,st as CustomToneMapping,Sh as CylinderGeometry,Eu as Cylindrical,Ti as Data3DTexture,_i as DataArrayTexture,Vo as DataTexture,uc as DataTextureLoader,an as DataUtils,rs as DecrementStencilOp,os as DecrementWrapStencilOp,sc as DefaultLoadingManager,Dt as DepthFormat,Ht as DepthStencilFormat,$a as DepthTexture,ot as DetachedBindMode,Cc as DirectionalLight,sd as DirectionalLightHelper,Dl as DiscreteInterpolant,Th as DodecahedronGeometry,p as DoubleSide,k as DstAlphaFactor,R as DstColorFactor,ks as DynamicCopyUsage,As as DynamicDrawUsage,Cs as DynamicReadUsage,kh as EdgesGeometry,Ka as EllipseCurve,xs as EqualCompare,H as EqualDepth,cs as EqualStencilFunc,ct as EquirectangularReflectionMapping,ut as EquirectangularRefractionMapping,yr as Euler,Ns as EventDispatcher,al as ExtrudeGeometry,oc as FileLoader,xn as Float16BufferAttribute,bn as Float32BufferAttribute,Et as FloatType,io as Fog,so as FogExp2,Ja as FramebufferTexture,u as FrontSide,ra as Frustum,Tu as GLBufferAttribute,Rs as GLSL1,Ps as GLSL3,vs as GreaterCompare,J as GreaterDepth,Ms as GreaterEqualCompare,q as GreaterEqualDepth,ms as GreaterEqualStencilFunc,ds as GreaterStencilFunc,$u as GridHelper,Ha as Group,Rt as HalfFloatType,mc as HemisphereLight,Gu as HemisphereLightHelper,ll as IcosahedronGeometry,Uc as ImageBitmapLoader,lc as ImageLoader,yi as ImageUtils,is as IncrementStencilOp,ns as IncrementWrapStencilOp,Do as InstancedBufferAttribute,Oc as InstancedBufferGeometry,Au as InstancedInterleavedBuffer,$o as InstancedMesh,mn as Int16BufferAttribute,fn as Int32BufferAttribute,un as Int8BufferAttribute,Bt as IntType,no as InterleavedBuffer,ao as InterleavedBufferAttribute,Wl as Interpolant,Ee as InterpolateDiscrete,Re as InterpolateLinear,Pe as InterpolateSmooth,as as InvertStencilOp,es as KeepStencilOp,Hl as KeyframeTrack,zo as LOD,vh as LatheGeometry,fr as Layers,gs as LessCompare,j as LessDepth,bs as LessEqualCompare,D as LessEqualDepth,us as LessEqualStencilFunc,ls as LessStencilFunc,pc as Light,Ec as LightProbe,ka as Line,Lu as Line3,Sa as LineBasicMaterial,dh as LineCurve,ph as LineCurve3,Rl as LineDashedMaterial,Fa as LineLoop,Oa as LineSegments,wt as LinearFilter,jl as LinearInterpolant,At as LinearMipMapLinearFilter,St as LinearMipMapNearestFilter,_t as LinearMipmapLinearFilter,Mt as LinearMipmapNearestFilter,$e as LinearSRGBColorSpace,Q as LinearToneMapping,Qe as LinearTransfer,ic as Loader,Pc as LoaderUtils,ec as LoadingManager,Ie as LoopOnce,ke as LoopPingPong,Be as LoopRepeat,jt as LuminanceAlphaFormat,Ut as LuminanceFormat,e as MOUSE,tn as Material,Rc as MaterialLoader,Ys as MathUtils,Ru as Matrix2,Gs as Matrix3,nr as Matrix4,_ as MaxEquation,Vn as Mesh,en as MeshBasicMaterial,Bl as MeshDepthMaterial,kl as MeshDistanceMaterial,Il as MeshLambertMaterial,El as MeshMatcapMaterial,Cl as MeshNormalMaterial,Tl as MeshPhongMaterial,Al as MeshPhysicalMaterial,_l as MeshStandardMaterial,zl as MeshToonMaterial,S as MinEquation,yt as MirroredRepeatWrapping,Z as MixOperation,x as MultiplyBlending,Y as MultiplyOperation,ft as NearestFilter,vt as NearestMipMapLinearFilter,xt as NearestMipMapNearestFilter,bt as NearestMipmapLinearFilter,gt as NearestMipmapNearestFilter,rt as NeutralToneMapping,fs as NeverCompare,W as NeverDepth,hs as NeverStencilFunc,m as NoBlending,Ze as NoColorSpace,$ as NoToneMapping,Le as NormalAnimationBlendMode,y as NormalBlending,ws as NotEqualCompare,X as NotEqualDepth,ps as NotEqualStencilFunc,Xl as NumberKeyframeTrack,Er as Object3D,Nc as ObjectLoader,Ye as ObjectSpaceNormalMap,cl as OctahedronGeometry,T as OneFactor,V as OneMinusConstantAlphaFactor,N as OneMinusConstantColorFactor,E as OneMinusDstAlphaFactor,P as OneMinusDstColorFactor,B as OneMinusSrcAlphaFactor,C as OneMinusSrcColorFactor,Tc as OrthographicCamera,h as PCFShadowMap,l as PCFSoftShadowMap,bh as Path,$n as PerspectiveCamera,ea as Plane,ul as PlaneGeometry,cd as PlaneHelper,Ac as PointLight,Ju as PointLightHelper,ja as Points,Na as PointsMaterial,Qu as PolarGridHelper,Ah as PolyhedronGeometry,hu as PositionalAudio,gu as PropertyBinding,cu as PropertyMixer,mh as QuadraticBezierCurve,yh as QuadraticBezierCurve3,Ci as Quaternion,Zl as QuaternionKeyframeTrack,Yl as QuaternionLinearInterpolant,Us as RAD2DEG,ze as RED_GREEN_RGTC2_Format,Ae as RED_RGTC1_Format,t as REVISION,He as RGBADepthPacking,Wt as RGBAFormat,Gt as RGBAIntegerFormat,be as RGBA_ASTC_10x10_Format,fe as RGBA_ASTC_10x5_Format,ge as RGBA_ASTC_10x6_Format,xe as RGBA_ASTC_10x8_Format,ve as RGBA_ASTC_12x10_Format,we as RGBA_ASTC_12x12_Format,he as RGBA_ASTC_4x4_Format,le as RGBA_ASTC_5x4_Format,ce as RGBA_ASTC_5x5_Format,ue as RGBA_ASTC_6x5_Format,de as RGBA_ASTC_6x6_Format,pe as RGBA_ASTC_8x5_Format,me as RGBA_ASTC_8x6_Format,ye as RGBA_ASTC_8x8_Format,Me as RGBA_BPTC_Format,ae as RGBA_ETC2_EAC_Format,re as RGBA_PVRTC_2BPPV1_Format,ie as RGBA_PVRTC_4BPPV1_Format,Qt as RGBA_S3TC_DXT1_Format,Kt as RGBA_S3TC_DXT3_Format,te as RGBA_S3TC_DXT5_Format,qe as RGBDepthPacking,Vt as RGBFormat,Zt as RGBIntegerFormat,Se as RGB_BPTC_SIGNED_Format,_e as RGB_BPTC_UNSIGNED_Format,ne as RGB_ETC1_Format,oe as RGB_ETC2_Format,se as RGB_PVRTC_2BPPV1_Format,ee as RGB_PVRTC_4BPPV1_Format,$t as RGB_S3TC_DXT1_Format,Je as RGDepthPacking,Xt as RGFormat,Yt as RGIntegerFormat,Sl as RawShaderMaterial,rr as Ray,Cu as Raycaster,Bc as RectAreaLight,qt as RedFormat,Jt as RedIntegerFormat,K as ReinhardToneMapping,Mi as RenderTarget,pt as RepeatWrapping,ss as ReplaceStencilOp,M as ReverseSubtractEquation,dl as RingGeometry,Ce as SIGNED_RED_GREEN_RGTC2_Format,Te as SIGNED_RED_RGTC1_Format,Ge as SRGBColorSpace,Ke as SRGBTransfer,ro as Scene,Jn as ShaderMaterial,Ml as ShadowMaterial,Eh as Shape,pl as ShapeGeometry,fd as ShapePath,rl as ShapeUtils,Ct as ShortType,jo as Skeleton,Hu as SkeletonHelper,No as SkinnedMesh,gi as Source,Gi as Sphere,ml as SphereGeometry,ku as Spherical,kc as SphericalHarmonics3,fh as SplineCurve,vc as SpotLight,Wu as SpotLightHelper,So as Sprite,ho as SpriteMaterial,I as SrcAlphaFactor,O as SrcAlphaSaturateFactor,z as SrcColorFactor,Bs as StaticCopyUsage,_s as StaticDrawUsage,zs as StaticReadUsage,Yc as StereoCamera,Es as StreamCopyUsage,Ts as StreamDrawUsage,Is as StreamReadUsage,Gl as StringKeyframeTrack,w as SubtractEquation,g as SubtractiveBlending,s as TOUCH,Xe as TangentSpaceNormalMap,yl as TetrahedronGeometry,vi as Texture,dc as TextureLoader,bd as TextureUtils,fl as TorusGeometry,gl as TorusKnotGeometry,Jr as Triangle,je as TriangleFanDrawMode,Ue as TriangleStripDrawMode,We as TrianglesDrawMode,xl as TubeGeometry,at as UVMapping,yn as Uint16BufferAttribute,gn as Uint32BufferAttribute,dn as Uint8BufferAttribute,pn as Uint8ClampedBufferAttribute,Mu as Uniform,_u as UniformsGroup,qn as UniformsUtils,Tt as UnsignedByteType,Ft as UnsignedInt248Type,Nt as UnsignedInt5999Type,kt as UnsignedIntType,Pt as UnsignedShort4444Type,Ot as UnsignedShort5551Type,It as UnsignedShortType,c as VSMShadowMap,Zs as Vector2,Ii as Vector3,wi as Vector4,$l as VectorKeyframeTrack,qa as VideoTexture,zi as WebGL3DRenderTarget,Ai as WebGLArrayRenderTarget,Os as WebGLCoordinateSystem,eo as WebGLCubeRenderTarget,vd as WebGLMultipleRenderTargets,Si as WebGLRenderTarget,Fs as WebGPUCoordinateSystem,bl as WireframeGeometry,Ne as WrapAroundEnding,Oe as ZeroCurvatureEnding,A as ZeroFactor,Fe as ZeroSlopeEnding,ts as ZeroStencilOp,Qs as arrayNeedsUint32,jn as cloneUniforms,si as createCanvasElement,ei as createElementNS,xd as getByteLength,Hn as getUnlitUniformColorSpace,Dn as mergeUniforms,ni as probeAsync,oi as toNormalizedProjectionMatrix,ai as toReversedProjectionMatrix,ri as warnOnce}; diff --git a/libs/three.js/r171/build/three.module.js b/libs/three.js/r171/build/three.module.js new file mode 100644 index 000000000..7b7a499ba --- /dev/null +++ b/libs/three.js/r171/build/three.module.js @@ -0,0 +1,17581 @@ +/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */ +import { Color, Matrix3, Vector2, mergeUniforms, Vector3, CubeUVReflectionMapping, Mesh, BoxGeometry, ShaderMaterial, cloneUniforms, BackSide, ColorManagement, SRGBTransfer, PlaneGeometry, FrontSide, getUnlitUniformColorSpace, Euler, Matrix4, IntType, RGBAFormat, HalfFloatType, UnsignedByteType, FloatType, Plane, EquirectangularReflectionMapping, EquirectangularRefractionMapping, WebGLCubeRenderTarget, CubeReflectionMapping, CubeRefractionMapping, PerspectiveCamera, NoToneMapping, MeshBasicMaterial, BufferGeometry, BufferAttribute, WebGLRenderTarget, NoBlending, OrthographicCamera, LinearFilter, LinearSRGBColorSpace, warnOnce, arrayNeedsUint32, Uint32BufferAttribute, Uint16BufferAttribute, Vector4, DataArrayTexture, LessEqualCompare, Texture, DepthTexture, Data3DTexture, CubeTexture, GLSL3, CustomToneMapping, NeutralToneMapping, AgXToneMapping, ACESFilmicToneMapping, CineonToneMapping, ReinhardToneMapping, LinearToneMapping, PCFShadowMap, PCFSoftShadowMap, VSMShadowMap, LinearTransfer, AddOperation, MixOperation, MultiplyOperation, ObjectSpaceNormalMap, TangentSpaceNormalMap, NormalBlending, DoubleSide, UniformsUtils, Layers, Frustum, MeshDepthMaterial, RGBADepthPacking, MeshDistanceMaterial, NearestFilter, LessEqualDepth, AddEquation, SubtractEquation, ReverseSubtractEquation, ZeroFactor, OneFactor, SrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, DstColorFactor, DstAlphaFactor, OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor, ConstantColorFactor, OneMinusConstantColorFactor, ConstantAlphaFactor, OneMinusConstantAlphaFactor, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, CullFaceNone, CullFaceBack, CullFaceFront, MinEquation, MaxEquation, NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessDepth, AlwaysDepth, NeverDepth, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter, NeverCompare, AlwaysCompare, LessCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, NoColorSpace, DepthStencilFormat, getByteLength, UnsignedIntType, UnsignedInt248Type, UnsignedShortType, DepthFormat, createElementNS, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedInt5999Type, ByteType, ShortType, AlphaFormat, RGBFormat, LuminanceFormat, LuminanceAlphaFormat, RedFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, Group, EventDispatcher, ArrayCamera, RAD2DEG, createCanvasElement, SRGBColorSpace, REVISION, toNormalizedProjectionMatrix, toReversedProjectionMatrix, probeAsync, WebGLCoordinateSystem } from './three.core.js'; +export { AdditiveAnimationBlendMode, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BasicDepthPacking, BasicShadowMap, BatchedMesh, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxHelper, BufferGeometryLoader, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CircleGeometry, Clock, ColorKeyframeTrack, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, Controls, CubeCamera, CubeTextureLoader, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceFrontBack, Curve, CurvePath, CylinderGeometry, Cylindrical, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualStencilFunc, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Float32BufferAttribute, Fog, FogExp2, FramebufferTexture, GLBufferAttribute, GLSL1, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, MOUSE, Material, MaterialLoader, MathUtils, Matrix2, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NeverStencilFunc, NormalAnimationBlendMode, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, OctahedronGeometry, Path, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RGBDepthPacking, RGBIntegerFormat, RGDepthPacking, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RenderTarget, ReplaceStencilOp, RingGeometry, Scene, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, TOUCH, TetrahedronGeometry, TextureLoader, TextureUtils, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, VectorKeyframeTrack, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLMultipleRenderTargets, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, ZeroStencilOp } from './three.core.js'; + +function WebGLAnimation() { + + let context = null; + let isAnimating = false; + let animationLoop = null; + let requestId = null; + + function onAnimationFrame( time, frame ) { + + animationLoop( time, frame ); + + requestId = context.requestAnimationFrame( onAnimationFrame ); + + } + + return { + + start: function () { + + if ( isAnimating === true ) return; + if ( animationLoop === null ) return; + + requestId = context.requestAnimationFrame( onAnimationFrame ); + + isAnimating = true; + + }, + + stop: function () { + + context.cancelAnimationFrame( requestId ); + + isAnimating = false; + + }, + + setAnimationLoop: function ( callback ) { + + animationLoop = callback; + + }, + + setContext: function ( value ) { + + context = value; + + } + + }; + +} + +function WebGLAttributes( gl ) { + + const buffers = new WeakMap(); + + function createBuffer( attribute, bufferType ) { + + const array = attribute.array; + const usage = attribute.usage; + const size = array.byteLength; + + const buffer = gl.createBuffer(); + + gl.bindBuffer( bufferType, buffer ); + gl.bufferData( bufferType, array, usage ); + + attribute.onUploadCallback(); + + let type; + + if ( array instanceof Float32Array ) { + + type = gl.FLOAT; + + } else if ( array instanceof Uint16Array ) { + + if ( attribute.isFloat16BufferAttribute ) { + + type = gl.HALF_FLOAT; + + } else { + + type = gl.UNSIGNED_SHORT; + + } + + } else if ( array instanceof Int16Array ) { + + type = gl.SHORT; + + } else if ( array instanceof Uint32Array ) { + + type = gl.UNSIGNED_INT; + + } else if ( array instanceof Int32Array ) { + + type = gl.INT; + + } else if ( array instanceof Int8Array ) { + + type = gl.BYTE; + + } else if ( array instanceof Uint8Array ) { + + type = gl.UNSIGNED_BYTE; + + } else if ( array instanceof Uint8ClampedArray ) { + + type = gl.UNSIGNED_BYTE; + + } else { + + throw new Error( 'THREE.WebGLAttributes: Unsupported buffer data format: ' + array ); + + } + + return { + buffer: buffer, + type: type, + bytesPerElement: array.BYTES_PER_ELEMENT, + version: attribute.version, + size: size + }; + + } + + function updateBuffer( buffer, attribute, bufferType ) { + + const array = attribute.array; + const updateRanges = attribute.updateRanges; + + gl.bindBuffer( bufferType, buffer ); + + if ( updateRanges.length === 0 ) { + + // Not using update ranges + gl.bufferSubData( bufferType, 0, array ); + + } else { + + // Before applying update ranges, we merge any adjacent / overlapping + // ranges to reduce load on `gl.bufferSubData`. Empirically, this has led + // to performance improvements for applications which make heavy use of + // update ranges. Likely due to GPU command overhead. + // + // Note that to reduce garbage collection between frames, we merge the + // update ranges in-place. This is safe because this method will clear the + // update ranges once updated. + + updateRanges.sort( ( a, b ) => a.start - b.start ); + + // To merge the update ranges in-place, we work from left to right in the + // existing updateRanges array, merging ranges. This may result in a final + // array which is smaller than the original. This index tracks the last + // index representing a merged range, any data after this index can be + // trimmed once the merge algorithm is completed. + let mergeIndex = 0; + + for ( let i = 1; i < updateRanges.length; i ++ ) { + + const previousRange = updateRanges[ mergeIndex ]; + const range = updateRanges[ i ]; + + // We add one here to merge adjacent ranges. This is safe because ranges + // operate over positive integers. + if ( range.start <= previousRange.start + previousRange.count + 1 ) { + + previousRange.count = Math.max( + previousRange.count, + range.start + range.count - previousRange.start + ); + + } else { + + ++ mergeIndex; + updateRanges[ mergeIndex ] = range; + + } + + } + + // Trim the array to only contain the merged ranges. + updateRanges.length = mergeIndex + 1; + + for ( let i = 0, l = updateRanges.length; i < l; i ++ ) { + + const range = updateRanges[ i ]; + + gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT, + array, range.start, range.count ); + + } + + attribute.clearUpdateRanges(); + + } + + attribute.onUploadCallback(); + + } + + // + + function get( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; + + return buffers.get( attribute ); + + } + + function remove( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; + + const data = buffers.get( attribute ); + + if ( data ) { + + gl.deleteBuffer( data.buffer ); + + buffers.delete( attribute ); + + } + + } + + function update( attribute, bufferType ) { + + if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; + + if ( attribute.isGLBufferAttribute ) { + + const cached = buffers.get( attribute ); + + if ( ! cached || cached.version < attribute.version ) { + + buffers.set( attribute, { + buffer: attribute.buffer, + type: attribute.type, + bytesPerElement: attribute.elementSize, + version: attribute.version + } ); + + } + + return; + + } + + const data = buffers.get( attribute ); + + if ( data === undefined ) { + + buffers.set( attribute, createBuffer( attribute, bufferType ) ); + + } else if ( data.version < attribute.version ) { + + if ( data.size !== attribute.array.byteLength ) { + + throw new Error( 'THREE.WebGLAttributes: The size of the buffer attribute\'s array buffer does not match the original size. Resizing buffer attributes is not supported.' ); + + } + + updateBuffer( data.buffer, attribute, bufferType ); + + data.version = attribute.version; + + } + + } + + return { + + get: get, + remove: remove, + update: update + + }; + +} + +var alphahash_fragment = "#ifdef USE_ALPHAHASH\n\tif ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif"; + +var alphahash_pars_fragment = "#ifdef USE_ALPHAHASH\n\tconst float ALPHA_HASH_SCALE = 0.05;\n\tfloat hash2D( vec2 value ) {\n\t\treturn fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n\t}\n\tfloat hash3D( vec3 value ) {\n\t\treturn hash2D( vec2( hash2D( value.xy ), value.z ) );\n\t}\n\tfloat getAlphaHashThreshold( vec3 position ) {\n\t\tfloat maxDeriv = max(\n\t\t\tlength( dFdx( position.xyz ) ),\n\t\t\tlength( dFdy( position.xyz ) )\n\t\t);\n\t\tfloat pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n\t\tvec2 pixScales = vec2(\n\t\t\texp2( floor( log2( pixScale ) ) ),\n\t\t\texp2( ceil( log2( pixScale ) ) )\n\t\t);\n\t\tvec2 alpha = vec2(\n\t\t\thash3D( floor( pixScales.x * position.xyz ) ),\n\t\t\thash3D( floor( pixScales.y * position.xyz ) )\n\t\t);\n\t\tfloat lerpFactor = fract( log2( pixScale ) );\n\t\tfloat x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n\t\tfloat a = min( lerpFactor, 1.0 - lerpFactor );\n\t\tvec3 cases = vec3(\n\t\t\tx * x / ( 2.0 * a * ( 1.0 - a ) ),\n\t\t\t( x - 0.5 * a ) / ( 1.0 - a ),\n\t\t\t1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n\t\t);\n\t\tfloat threshold = ( x < ( 1.0 - a ) )\n\t\t\t? ( ( x < a ) ? cases.x : cases.y )\n\t\t\t: cases.z;\n\t\treturn clamp( threshold , 1.0e-6, 1.0 );\n\t}\n#endif"; + +var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif"; + +var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif"; + +var alphatest_fragment = "#ifdef USE_ALPHATEST\n\t#ifdef ALPHA_TO_COVERAGE\n\tdiffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\n\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\tif ( diffuseColor.a < alphaTest ) discard;\n\t#endif\n#endif"; + +var alphatest_pars_fragment = "#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif"; + +var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_CLEARCOAT ) \n\t\tclearcoatSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_SHEEN ) \n\t\tsheenSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif"; + +var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif"; + +var batching_pars_vertex = "#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec3 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;\n\t}\n#endif"; + +var batching_vertex = "#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif"; + +var begin_vertex = "vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n\tvPosition = vec3( position );\n#endif"; + +var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif"; + +var bsdfs = "float G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated"; + +var iridescence_fragment = "#ifdef USE_IRIDESCENCE\n\tconst mat3 XYZ_TO_REC709 = mat3(\n\t\t 3.2404542, -0.9692660, 0.0556434,\n\t\t-1.5371385, 1.8760108, -0.2040259,\n\t\t-0.4985314, 0.0415560, 1.0572252\n\t);\n\tvec3 Fresnel0ToIor( vec3 fresnel0 ) {\n\t\tvec3 sqrtF0 = sqrt( fresnel0 );\n\t\treturn ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\t}\n\tvec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n\t}\n\tfloat IorToFresnel0( float transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n\t}\n\tvec3 evalSensitivity( float OPD, vec3 shift ) {\n\t\tfloat phase = 2.0 * PI * OPD * 1.0e-9;\n\t\tvec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n\t\tvec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n\t\tvec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n\t\tvec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n\t\txyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n\t\txyz /= 1.0685e-7;\n\t\tvec3 rgb = XYZ_TO_REC709 * xyz;\n\t\treturn rgb;\n\t}\n\tvec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n\t\tvec3 I;\n\t\tfloat iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n\t\tfloat sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n\t\tfloat cosTheta2Sq = 1.0 - sinTheta2Sq;\n\t\tif ( cosTheta2Sq < 0.0 ) {\n\t\t\treturn vec3( 1.0 );\n\t\t}\n\t\tfloat cosTheta2 = sqrt( cosTheta2Sq );\n\t\tfloat R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n\t\tfloat R12 = F_Schlick( R0, 1.0, cosTheta1 );\n\t\tfloat T121 = 1.0 - R12;\n\t\tfloat phi12 = 0.0;\n\t\tif ( iridescenceIOR < outsideIOR ) phi12 = PI;\n\t\tfloat phi21 = PI - phi12;\n\t\tvec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );\t\tvec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n\t\tvec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n\t\tvec3 phi23 = vec3( 0.0 );\n\t\tif ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n\t\tif ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n\t\tif ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n\t\tfloat OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n\t\tvec3 phi = vec3( phi21 ) + phi23;\n\t\tvec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n\t\tvec3 r123 = sqrt( R123 );\n\t\tvec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n\t\tvec3 C0 = R12 + Rs;\n\t\tI = C0;\n\t\tvec3 Cm = Rs - T121;\n\t\tfor ( int m = 1; m <= 2; ++ m ) {\n\t\t\tCm *= r123;\n\t\t\tvec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n\t\t\tI += Cm * Sm;\n\t\t}\n\t\treturn max( I, vec3( 0.0 ) );\n\t}\n#endif"; + +var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vBumpMapUv );\n\t\tvec2 dSTdy = dFdy( vBumpMapUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n\t\tvec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif"; + +var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif"; + +var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif"; + +var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif"; + +var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif"; + +var color_fragment = "#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif"; + +var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif"; + +var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif"; + +var color_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\tvColor.xyz *= batchingColor.xyz;\n#endif"; + +var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated"; + +var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif"; + +var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif"; + +var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif"; + +var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif"; + +var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif"; + +var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif"; + +var colorspace_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );"; + +var colorspace_pars_fragment = "vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}"; + +var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif"; + +var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif"; + +var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif"; + +var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif"; + +var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif"; + +var fog_vertex = "#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif"; + +var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif"; + +var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif"; + +var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif"; + +var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}"; + +var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif"; + +var lights_lambert_fragment = "LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;"; + +var lights_lambert_pars_fragment = "varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert"; + +var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif"; + +var envmap_physical_pars_fragment = "#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif"; + +var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;"; + +var lights_toon_pars_fragment = "varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon"; + +var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;"; + +var lights_phong_pars_fragment = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong"; + +var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif"; + +var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn saturate(v);\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColor;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\t#endif\n\tvec3 totalScattering = singleScattering + multiScattering;\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}"; + +var lights_fragment_begin = "\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif"; + +var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif"; + +var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif"; + +var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif"; + +var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif"; + +var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif"; + +var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif"; + +var map_fragment = "#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif"; + +var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif"; + +var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif"; + +var map_particle_pars_fragment = "#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif"; + +var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif"; + +var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif"; + +var morphinstance_vertex = "#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif"; + +var morphcolor_vertex = "#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif"; + +var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif"; + +var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif"; + +var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif"; + +var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;"; + +var normal_fragment_maps = "#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif"; + +var normal_pars_fragment = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif"; + +var normal_pars_vertex = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif"; + +var normal_vertex = "#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif"; + +var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif"; + +var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif"; + +var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif"; + +var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif"; + +var iridescence_pars_fragment = "#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif"; + +var opaque_fragment = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );"; + +var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * depth - far );\n}"; + +var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif"; + +var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;"; + +var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif"; + +var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif"; + +var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif"; + +var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif"; + +var shadowmap_pars_fragment = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\t\n\t\tfloat lightToPositionLength = length( lightToPosition );\n\t\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t\t) * ( 1.0 / 9.0 );\n\t\t\t#else\n\t\t\t\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n#endif"; + +var shadowmap_pars_vertex = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif"; + +var shadowmap_vertex = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif"; + +var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}"; + +var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif"; + +var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif"; + +var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif"; + +var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif"; + +var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif"; + +var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif"; + +var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif"; + +var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }"; + +var transmission_fragment = "#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif"; + +var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t\n\t\t#else\n\t\t\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif"; + +var uv_pars_fragment = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif"; + +var uv_pars_vertex = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif"; + +var uv_vertex = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif"; + +var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif"; + +const vertex$h = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}"; + +const fragment$h = "uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}"; + +const vertex$g = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}"; + +const fragment$g = "#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}"; + +const vertex$f = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}"; + +const fragment$f = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include \n\t#include \n}"; + +const vertex$e = "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvHighPrecisionZW = gl_Position.zw;\n}"; + +const fragment$e = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}"; + +const vertex$d = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvWorldPosition = worldPosition.xyz;\n}"; + +const fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}"; + +const vertex$c = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n}"; + +const fragment$c = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include \n\t#include \n}"; + +const vertex$b = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const fragment$b = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$a = "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include \n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$9 = "#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const fragment$9 = "#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$8 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n}"; + +const fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$7 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}"; + +const fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}"; + +const vertex$6 = "#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const fragment$6 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$5 = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}"; + +const fragment$5 = "#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include \n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$4 = "#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}"; + +const fragment$4 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$3 = "uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const fragment$3 = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const vertex$2 = "#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include \n\t#include \n\t#include \n}"; + +const vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include \n\t#include \n\t#include \n}"; + +const fragment$1 = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + +const ShaderChunk = { + alphahash_fragment: alphahash_fragment, + alphahash_pars_fragment: alphahash_pars_fragment, + alphamap_fragment: alphamap_fragment, + alphamap_pars_fragment: alphamap_pars_fragment, + alphatest_fragment: alphatest_fragment, + alphatest_pars_fragment: alphatest_pars_fragment, + aomap_fragment: aomap_fragment, + aomap_pars_fragment: aomap_pars_fragment, + batching_pars_vertex: batching_pars_vertex, + batching_vertex: batching_vertex, + begin_vertex: begin_vertex, + beginnormal_vertex: beginnormal_vertex, + bsdfs: bsdfs, + iridescence_fragment: iridescence_fragment, + bumpmap_pars_fragment: bumpmap_pars_fragment, + clipping_planes_fragment: clipping_planes_fragment, + clipping_planes_pars_fragment: clipping_planes_pars_fragment, + clipping_planes_pars_vertex: clipping_planes_pars_vertex, + clipping_planes_vertex: clipping_planes_vertex, + color_fragment: color_fragment, + color_pars_fragment: color_pars_fragment, + color_pars_vertex: color_pars_vertex, + color_vertex: color_vertex, + common: common, + cube_uv_reflection_fragment: cube_uv_reflection_fragment, + defaultnormal_vertex: defaultnormal_vertex, + displacementmap_pars_vertex: displacementmap_pars_vertex, + displacementmap_vertex: displacementmap_vertex, + emissivemap_fragment: emissivemap_fragment, + emissivemap_pars_fragment: emissivemap_pars_fragment, + colorspace_fragment: colorspace_fragment, + colorspace_pars_fragment: colorspace_pars_fragment, + envmap_fragment: envmap_fragment, + envmap_common_pars_fragment: envmap_common_pars_fragment, + envmap_pars_fragment: envmap_pars_fragment, + envmap_pars_vertex: envmap_pars_vertex, + envmap_physical_pars_fragment: envmap_physical_pars_fragment, + envmap_vertex: envmap_vertex, + fog_vertex: fog_vertex, + fog_pars_vertex: fog_pars_vertex, + fog_fragment: fog_fragment, + fog_pars_fragment: fog_pars_fragment, + gradientmap_pars_fragment: gradientmap_pars_fragment, + lightmap_pars_fragment: lightmap_pars_fragment, + lights_lambert_fragment: lights_lambert_fragment, + lights_lambert_pars_fragment: lights_lambert_pars_fragment, + lights_pars_begin: lights_pars_begin, + lights_toon_fragment: lights_toon_fragment, + lights_toon_pars_fragment: lights_toon_pars_fragment, + lights_phong_fragment: lights_phong_fragment, + lights_phong_pars_fragment: lights_phong_pars_fragment, + lights_physical_fragment: lights_physical_fragment, + lights_physical_pars_fragment: lights_physical_pars_fragment, + lights_fragment_begin: lights_fragment_begin, + lights_fragment_maps: lights_fragment_maps, + lights_fragment_end: lights_fragment_end, + logdepthbuf_fragment: logdepthbuf_fragment, + logdepthbuf_pars_fragment: logdepthbuf_pars_fragment, + logdepthbuf_pars_vertex: logdepthbuf_pars_vertex, + logdepthbuf_vertex: logdepthbuf_vertex, + map_fragment: map_fragment, + map_pars_fragment: map_pars_fragment, + map_particle_fragment: map_particle_fragment, + map_particle_pars_fragment: map_particle_pars_fragment, + metalnessmap_fragment: metalnessmap_fragment, + metalnessmap_pars_fragment: metalnessmap_pars_fragment, + morphinstance_vertex: morphinstance_vertex, + morphcolor_vertex: morphcolor_vertex, + morphnormal_vertex: morphnormal_vertex, + morphtarget_pars_vertex: morphtarget_pars_vertex, + morphtarget_vertex: morphtarget_vertex, + normal_fragment_begin: normal_fragment_begin, + normal_fragment_maps: normal_fragment_maps, + normal_pars_fragment: normal_pars_fragment, + normal_pars_vertex: normal_pars_vertex, + normal_vertex: normal_vertex, + normalmap_pars_fragment: normalmap_pars_fragment, + clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin, + clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps, + clearcoat_pars_fragment: clearcoat_pars_fragment, + iridescence_pars_fragment: iridescence_pars_fragment, + opaque_fragment: opaque_fragment, + packing: packing, + premultiplied_alpha_fragment: premultiplied_alpha_fragment, + project_vertex: project_vertex, + dithering_fragment: dithering_fragment, + dithering_pars_fragment: dithering_pars_fragment, + roughnessmap_fragment: roughnessmap_fragment, + roughnessmap_pars_fragment: roughnessmap_pars_fragment, + shadowmap_pars_fragment: shadowmap_pars_fragment, + shadowmap_pars_vertex: shadowmap_pars_vertex, + shadowmap_vertex: shadowmap_vertex, + shadowmask_pars_fragment: shadowmask_pars_fragment, + skinbase_vertex: skinbase_vertex, + skinning_pars_vertex: skinning_pars_vertex, + skinning_vertex: skinning_vertex, + skinnormal_vertex: skinnormal_vertex, + specularmap_fragment: specularmap_fragment, + specularmap_pars_fragment: specularmap_pars_fragment, + tonemapping_fragment: tonemapping_fragment, + tonemapping_pars_fragment: tonemapping_pars_fragment, + transmission_fragment: transmission_fragment, + transmission_pars_fragment: transmission_pars_fragment, + uv_pars_fragment: uv_pars_fragment, + uv_pars_vertex: uv_pars_vertex, + uv_vertex: uv_vertex, + worldpos_vertex: worldpos_vertex, + + background_vert: vertex$h, + background_frag: fragment$h, + backgroundCube_vert: vertex$g, + backgroundCube_frag: fragment$g, + cube_vert: vertex$f, + cube_frag: fragment$f, + depth_vert: vertex$e, + depth_frag: fragment$e, + distanceRGBA_vert: vertex$d, + distanceRGBA_frag: fragment$d, + equirect_vert: vertex$c, + equirect_frag: fragment$c, + linedashed_vert: vertex$b, + linedashed_frag: fragment$b, + meshbasic_vert: vertex$a, + meshbasic_frag: fragment$a, + meshlambert_vert: vertex$9, + meshlambert_frag: fragment$9, + meshmatcap_vert: vertex$8, + meshmatcap_frag: fragment$8, + meshnormal_vert: vertex$7, + meshnormal_frag: fragment$7, + meshphong_vert: vertex$6, + meshphong_frag: fragment$6, + meshphysical_vert: vertex$5, + meshphysical_frag: fragment$5, + meshtoon_vert: vertex$4, + meshtoon_frag: fragment$4, + points_vert: vertex$3, + points_frag: fragment$3, + shadow_vert: vertex$2, + shadow_frag: fragment$2, + sprite_vert: vertex$1, + sprite_frag: fragment$1 +}; + +/** + * Uniforms library for shared webgl shaders + */ + +const UniformsLib = { + + common: { + + diffuse: { value: /*@__PURE__*/ new Color( 0xffffff ) }, + opacity: { value: 1.0 }, + + map: { value: null }, + mapTransform: { value: /*@__PURE__*/ new Matrix3() }, + + alphaMap: { value: null }, + alphaMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + + alphaTest: { value: 0 } + + }, + + specularmap: { + + specularMap: { value: null }, + specularMapTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + envmap: { + + envMap: { value: null }, + envMapRotation: { value: /*@__PURE__*/ new Matrix3() }, + flipEnvMap: { value: - 1 }, + reflectivity: { value: 1.0 }, // basic, lambert, phong + ior: { value: 1.5 }, // physical + refractionRatio: { value: 0.98 }, // basic, lambert, phong + + }, + + aomap: { + + aoMap: { value: null }, + aoMapIntensity: { value: 1 }, + aoMapTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + lightmap: { + + lightMap: { value: null }, + lightMapIntensity: { value: 1 }, + lightMapTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + bumpmap: { + + bumpMap: { value: null }, + bumpMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + bumpScale: { value: 1 } + + }, + + normalmap: { + + normalMap: { value: null }, + normalMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + normalScale: { value: /*@__PURE__*/ new Vector2( 1, 1 ) } + + }, + + displacementmap: { + + displacementMap: { value: null }, + displacementMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + displacementScale: { value: 1 }, + displacementBias: { value: 0 } + + }, + + emissivemap: { + + emissiveMap: { value: null }, + emissiveMapTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + metalnessmap: { + + metalnessMap: { value: null }, + metalnessMapTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + roughnessmap: { + + roughnessMap: { value: null }, + roughnessMapTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + gradientmap: { + + gradientMap: { value: null } + + }, + + fog: { + + fogDensity: { value: 0.00025 }, + fogNear: { value: 1 }, + fogFar: { value: 2000 }, + fogColor: { value: /*@__PURE__*/ new Color( 0xffffff ) } + + }, + + lights: { + + ambientLightColor: { value: [] }, + + lightProbe: { value: [] }, + + directionalLights: { value: [], properties: { + direction: {}, + color: {} + } }, + + directionalLightShadows: { value: [], properties: { + shadowIntensity: 1, + shadowBias: {}, + shadowNormalBias: {}, + shadowRadius: {}, + shadowMapSize: {} + } }, + + directionalShadowMap: { value: [] }, + directionalShadowMatrix: { value: [] }, + + spotLights: { value: [], properties: { + color: {}, + position: {}, + direction: {}, + distance: {}, + coneCos: {}, + penumbraCos: {}, + decay: {} + } }, + + spotLightShadows: { value: [], properties: { + shadowIntensity: 1, + shadowBias: {}, + shadowNormalBias: {}, + shadowRadius: {}, + shadowMapSize: {} + } }, + + spotLightMap: { value: [] }, + spotShadowMap: { value: [] }, + spotLightMatrix: { value: [] }, + + pointLights: { value: [], properties: { + color: {}, + position: {}, + decay: {}, + distance: {} + } }, + + pointLightShadows: { value: [], properties: { + shadowIntensity: 1, + shadowBias: {}, + shadowNormalBias: {}, + shadowRadius: {}, + shadowMapSize: {}, + shadowCameraNear: {}, + shadowCameraFar: {} + } }, + + pointShadowMap: { value: [] }, + pointShadowMatrix: { value: [] }, + + hemisphereLights: { value: [], properties: { + direction: {}, + skyColor: {}, + groundColor: {} + } }, + + // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src + rectAreaLights: { value: [], properties: { + color: {}, + position: {}, + width: {}, + height: {} + } }, + + ltc_1: { value: null }, + ltc_2: { value: null } + + }, + + points: { + + diffuse: { value: /*@__PURE__*/ new Color( 0xffffff ) }, + opacity: { value: 1.0 }, + size: { value: 1.0 }, + scale: { value: 1.0 }, + map: { value: null }, + alphaMap: { value: null }, + alphaMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + alphaTest: { value: 0 }, + uvTransform: { value: /*@__PURE__*/ new Matrix3() } + + }, + + sprite: { + + diffuse: { value: /*@__PURE__*/ new Color( 0xffffff ) }, + opacity: { value: 1.0 }, + center: { value: /*@__PURE__*/ new Vector2( 0.5, 0.5 ) }, + rotation: { value: 0.0 }, + map: { value: null }, + mapTransform: { value: /*@__PURE__*/ new Matrix3() }, + alphaMap: { value: null }, + alphaMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + alphaTest: { value: 0 } + + } + +}; + +const ShaderLib = { + + basic: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.specularmap, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.fog + ] ), + + vertexShader: ShaderChunk.meshbasic_vert, + fragmentShader: ShaderChunk.meshbasic_frag + + }, + + lambert: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.specularmap, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) } + } + ] ), + + vertexShader: ShaderChunk.meshlambert_vert, + fragmentShader: ShaderChunk.meshlambert_frag + + }, + + phong: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.specularmap, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) }, + specular: { value: /*@__PURE__*/ new Color( 0x111111 ) }, + shininess: { value: 30 } + } + ] ), + + vertexShader: ShaderChunk.meshphong_vert, + fragmentShader: ShaderChunk.meshphong_frag + + }, + + standard: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.roughnessmap, + UniformsLib.metalnessmap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) }, + roughness: { value: 1.0 }, + metalness: { value: 0.0 }, + envMapIntensity: { value: 1 } + } + ] ), + + vertexShader: ShaderChunk.meshphysical_vert, + fragmentShader: ShaderChunk.meshphysical_frag + + }, + + toon: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.gradientmap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) } + } + ] ), + + vertexShader: ShaderChunk.meshtoon_vert, + fragmentShader: ShaderChunk.meshtoon_frag + + }, + + matcap: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.fog, + { + matcap: { value: null } + } + ] ), + + vertexShader: ShaderChunk.meshmatcap_vert, + fragmentShader: ShaderChunk.meshmatcap_frag + + }, + + points: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.points, + UniformsLib.fog + ] ), + + vertexShader: ShaderChunk.points_vert, + fragmentShader: ShaderChunk.points_frag + + }, + + dashed: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.fog, + { + scale: { value: 1 }, + dashSize: { value: 1 }, + totalSize: { value: 2 } + } + ] ), + + vertexShader: ShaderChunk.linedashed_vert, + fragmentShader: ShaderChunk.linedashed_frag + + }, + + depth: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.displacementmap + ] ), + + vertexShader: ShaderChunk.depth_vert, + fragmentShader: ShaderChunk.depth_frag + + }, + + normal: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + { + opacity: { value: 1.0 } + } + ] ), + + vertexShader: ShaderChunk.meshnormal_vert, + fragmentShader: ShaderChunk.meshnormal_frag + + }, + + sprite: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.sprite, + UniformsLib.fog + ] ), + + vertexShader: ShaderChunk.sprite_vert, + fragmentShader: ShaderChunk.sprite_frag + + }, + + background: { + + uniforms: { + uvTransform: { value: /*@__PURE__*/ new Matrix3() }, + t2D: { value: null }, + backgroundIntensity: { value: 1 } + }, + + vertexShader: ShaderChunk.background_vert, + fragmentShader: ShaderChunk.background_frag + + }, + + backgroundCube: { + + uniforms: { + envMap: { value: null }, + flipEnvMap: { value: - 1 }, + backgroundBlurriness: { value: 0 }, + backgroundIntensity: { value: 1 }, + backgroundRotation: { value: /*@__PURE__*/ new Matrix3() } + }, + + vertexShader: ShaderChunk.backgroundCube_vert, + fragmentShader: ShaderChunk.backgroundCube_frag + + }, + + cube: { + + uniforms: { + tCube: { value: null }, + tFlip: { value: - 1 }, + opacity: { value: 1.0 } + }, + + vertexShader: ShaderChunk.cube_vert, + fragmentShader: ShaderChunk.cube_frag + + }, + + equirect: { + + uniforms: { + tEquirect: { value: null }, + }, + + vertexShader: ShaderChunk.equirect_vert, + fragmentShader: ShaderChunk.equirect_frag + + }, + + distanceRGBA: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.common, + UniformsLib.displacementmap, + { + referencePosition: { value: /*@__PURE__*/ new Vector3() }, + nearDistance: { value: 1 }, + farDistance: { value: 1000 } + } + ] ), + + vertexShader: ShaderChunk.distanceRGBA_vert, + fragmentShader: ShaderChunk.distanceRGBA_frag + + }, + + shadow: { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + UniformsLib.lights, + UniformsLib.fog, + { + color: { value: /*@__PURE__*/ new Color( 0x00000 ) }, + opacity: { value: 1.0 } + }, + ] ), + + vertexShader: ShaderChunk.shadow_vert, + fragmentShader: ShaderChunk.shadow_frag + + } + +}; + +ShaderLib.physical = { + + uniforms: /*@__PURE__*/ mergeUniforms( [ + ShaderLib.standard.uniforms, + { + clearcoat: { value: 0 }, + clearcoatMap: { value: null }, + clearcoatMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + clearcoatNormalMap: { value: null }, + clearcoatNormalMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + clearcoatNormalScale: { value: /*@__PURE__*/ new Vector2( 1, 1 ) }, + clearcoatRoughness: { value: 0 }, + clearcoatRoughnessMap: { value: null }, + clearcoatRoughnessMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + dispersion: { value: 0 }, + iridescence: { value: 0 }, + iridescenceMap: { value: null }, + iridescenceMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + iridescenceIOR: { value: 1.3 }, + iridescenceThicknessMinimum: { value: 100 }, + iridescenceThicknessMaximum: { value: 400 }, + iridescenceThicknessMap: { value: null }, + iridescenceThicknessMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + sheen: { value: 0 }, + sheenColor: { value: /*@__PURE__*/ new Color( 0x000000 ) }, + sheenColorMap: { value: null }, + sheenColorMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + sheenRoughness: { value: 1 }, + sheenRoughnessMap: { value: null }, + sheenRoughnessMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + transmission: { value: 0 }, + transmissionMap: { value: null }, + transmissionMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + transmissionSamplerSize: { value: /*@__PURE__*/ new Vector2() }, + transmissionSamplerMap: { value: null }, + thickness: { value: 0 }, + thicknessMap: { value: null }, + thicknessMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + attenuationDistance: { value: 0 }, + attenuationColor: { value: /*@__PURE__*/ new Color( 0x000000 ) }, + specularColor: { value: /*@__PURE__*/ new Color( 1, 1, 1 ) }, + specularColorMap: { value: null }, + specularColorMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + specularIntensity: { value: 1 }, + specularIntensityMap: { value: null }, + specularIntensityMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + anisotropyVector: { value: /*@__PURE__*/ new Vector2() }, + anisotropyMap: { value: null }, + anisotropyMapTransform: { value: /*@__PURE__*/ new Matrix3() }, + } + ] ), + + vertexShader: ShaderChunk.meshphysical_vert, + fragmentShader: ShaderChunk.meshphysical_frag + +}; + +const _rgb = { r: 0, b: 0, g: 0 }; +const _e1$1 = /*@__PURE__*/ new Euler(); +const _m1$1 = /*@__PURE__*/ new Matrix4(); + +function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha, premultipliedAlpha ) { + + const clearColor = new Color( 0x000000 ); + let clearAlpha = alpha === true ? 0 : 1; + + let planeMesh; + let boxMesh; + + let currentBackground = null; + let currentBackgroundVersion = 0; + let currentTonemapping = null; + + function getBackground( scene ) { + + let background = scene.isScene === true ? scene.background : null; + + if ( background && background.isTexture ) { + + const usePMREM = scene.backgroundBlurriness > 0; // use PMREM if the user wants to blur the background + background = ( usePMREM ? cubeuvmaps : cubemaps ).get( background ); + + } + + return background; + + } + + function render( scene ) { + + let forceClear = false; + const background = getBackground( scene ); + + if ( background === null ) { + + setClear( clearColor, clearAlpha ); + + } else if ( background && background.isColor ) { + + setClear( background, 1 ); + forceClear = true; + + } + + const environmentBlendMode = renderer.xr.getEnvironmentBlendMode(); + + if ( environmentBlendMode === 'additive' ) { + + state.buffers.color.setClear( 0, 0, 0, 1, premultipliedAlpha ); + + } else if ( environmentBlendMode === 'alpha-blend' ) { + + state.buffers.color.setClear( 0, 0, 0, 0, premultipliedAlpha ); + + } + + if ( renderer.autoClear || forceClear ) { + + // buffers might not be writable which is required to ensure a correct clear + + state.buffers.depth.setTest( true ); + state.buffers.depth.setMask( true ); + state.buffers.color.setMask( true ); + + renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); + + } + + } + + function addToRenderList( renderList, scene ) { + + const background = getBackground( scene ); + + if ( background && ( background.isCubeTexture || background.mapping === CubeUVReflectionMapping ) ) { + + if ( boxMesh === undefined ) { + + boxMesh = new Mesh( + new BoxGeometry( 1, 1, 1 ), + new ShaderMaterial( { + name: 'BackgroundCubeMaterial', + uniforms: cloneUniforms( ShaderLib.backgroundCube.uniforms ), + vertexShader: ShaderLib.backgroundCube.vertexShader, + fragmentShader: ShaderLib.backgroundCube.fragmentShader, + side: BackSide, + depthTest: false, + depthWrite: false, + fog: false + } ) + ); + + boxMesh.geometry.deleteAttribute( 'normal' ); + boxMesh.geometry.deleteAttribute( 'uv' ); + + boxMesh.onBeforeRender = function ( renderer, scene, camera ) { + + this.matrixWorld.copyPosition( camera.matrixWorld ); + + }; + + // add "envMap" material property so the renderer can evaluate it like for built-in materials + Object.defineProperty( boxMesh.material, 'envMap', { + + get: function () { + + return this.uniforms.envMap.value; + + } + + } ); + + objects.update( boxMesh ); + + } + + _e1$1.copy( scene.backgroundRotation ); + + // accommodate left-handed frame + _e1$1.x *= - 1; _e1$1.y *= - 1; _e1$1.z *= - 1; + + if ( background.isCubeTexture && background.isRenderTargetTexture === false ) { + + // environment maps which are not cube render targets or PMREMs follow a different convention + _e1$1.y *= - 1; + _e1$1.z *= - 1; + + } + + boxMesh.material.uniforms.envMap.value = background; + boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background.isRenderTargetTexture === false ) ? - 1 : 1; + boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness; + boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity; + boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4( _m1$1.makeRotationFromEuler( _e1$1 ) ); + boxMesh.material.toneMapped = ColorManagement.getTransfer( background.colorSpace ) !== SRGBTransfer; + + if ( currentBackground !== background || + currentBackgroundVersion !== background.version || + currentTonemapping !== renderer.toneMapping ) { + + boxMesh.material.needsUpdate = true; + + currentBackground = background; + currentBackgroundVersion = background.version; + currentTonemapping = renderer.toneMapping; + + } + + boxMesh.layers.enableAll(); + + // push to the pre-sorted opaque render list + renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null ); + + } else if ( background && background.isTexture ) { + + if ( planeMesh === undefined ) { + + planeMesh = new Mesh( + new PlaneGeometry( 2, 2 ), + new ShaderMaterial( { + name: 'BackgroundMaterial', + uniforms: cloneUniforms( ShaderLib.background.uniforms ), + vertexShader: ShaderLib.background.vertexShader, + fragmentShader: ShaderLib.background.fragmentShader, + side: FrontSide, + depthTest: false, + depthWrite: false, + fog: false + } ) + ); + + planeMesh.geometry.deleteAttribute( 'normal' ); + + // add "map" material property so the renderer can evaluate it like for built-in materials + Object.defineProperty( planeMesh.material, 'map', { + + get: function () { + + return this.uniforms.t2D.value; + + } + + } ); + + objects.update( planeMesh ); + + } + + planeMesh.material.uniforms.t2D.value = background; + planeMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity; + planeMesh.material.toneMapped = ColorManagement.getTransfer( background.colorSpace ) !== SRGBTransfer; + + if ( background.matrixAutoUpdate === true ) { + + background.updateMatrix(); + + } + + planeMesh.material.uniforms.uvTransform.value.copy( background.matrix ); + + if ( currentBackground !== background || + currentBackgroundVersion !== background.version || + currentTonemapping !== renderer.toneMapping ) { + + planeMesh.material.needsUpdate = true; + + currentBackground = background; + currentBackgroundVersion = background.version; + currentTonemapping = renderer.toneMapping; + + } + + planeMesh.layers.enableAll(); + + // push to the pre-sorted opaque render list + renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null ); + + } + + } + + function setClear( color, alpha ) { + + color.getRGB( _rgb, getUnlitUniformColorSpace( renderer ) ); + + state.buffers.color.setClear( _rgb.r, _rgb.g, _rgb.b, alpha, premultipliedAlpha ); + + } + + function dispose() { + + if ( boxMesh !== undefined ) { + + boxMesh.geometry.dispose(); + boxMesh.material.dispose(); + + } + + if ( planeMesh !== undefined ) { + + planeMesh.geometry.dispose(); + planeMesh.material.dispose(); + + } + + } + + return { + + getClearColor: function () { + + return clearColor; + + }, + setClearColor: function ( color, alpha = 1 ) { + + clearColor.set( color ); + clearAlpha = alpha; + setClear( clearColor, clearAlpha ); + + }, + getClearAlpha: function () { + + return clearAlpha; + + }, + setClearAlpha: function ( alpha ) { + + clearAlpha = alpha; + setClear( clearColor, clearAlpha ); + + }, + render: render, + addToRenderList: addToRenderList, + dispose: dispose + + }; + +} + +function WebGLBindingStates( gl, attributes ) { + + const maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS ); + + const bindingStates = {}; + + const defaultState = createBindingState( null ); + let currentState = defaultState; + let forceUpdate = false; + + function setup( object, material, program, geometry, index ) { + + let updateBuffers = false; + + const state = getBindingState( geometry, program, material ); + + if ( currentState !== state ) { + + currentState = state; + bindVertexArrayObject( currentState.object ); + + } + + updateBuffers = needsUpdate( object, geometry, program, index ); + + if ( updateBuffers ) saveCache( object, geometry, program, index ); + + if ( index !== null ) { + + attributes.update( index, gl.ELEMENT_ARRAY_BUFFER ); + + } + + if ( updateBuffers || forceUpdate ) { + + forceUpdate = false; + + setupVertexAttributes( object, material, program, geometry ); + + if ( index !== null ) { + + gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, attributes.get( index ).buffer ); + + } + + } + + } + + function createVertexArrayObject() { + + return gl.createVertexArray(); + + } + + function bindVertexArrayObject( vao ) { + + return gl.bindVertexArray( vao ); + + } + + function deleteVertexArrayObject( vao ) { + + return gl.deleteVertexArray( vao ); + + } + + function getBindingState( geometry, program, material ) { + + const wireframe = ( material.wireframe === true ); + + let programMap = bindingStates[ geometry.id ]; + + if ( programMap === undefined ) { + + programMap = {}; + bindingStates[ geometry.id ] = programMap; + + } + + let stateMap = programMap[ program.id ]; + + if ( stateMap === undefined ) { + + stateMap = {}; + programMap[ program.id ] = stateMap; + + } + + let state = stateMap[ wireframe ]; + + if ( state === undefined ) { + + state = createBindingState( createVertexArrayObject() ); + stateMap[ wireframe ] = state; + + } + + return state; + + } + + function createBindingState( vao ) { + + const newAttributes = []; + const enabledAttributes = []; + const attributeDivisors = []; + + for ( let i = 0; i < maxVertexAttributes; i ++ ) { + + newAttributes[ i ] = 0; + enabledAttributes[ i ] = 0; + attributeDivisors[ i ] = 0; + + } + + return { + + // for backward compatibility on non-VAO support browser + geometry: null, + program: null, + wireframe: false, + + newAttributes: newAttributes, + enabledAttributes: enabledAttributes, + attributeDivisors: attributeDivisors, + object: vao, + attributes: {}, + index: null + + }; + + } + + function needsUpdate( object, geometry, program, index ) { + + const cachedAttributes = currentState.attributes; + const geometryAttributes = geometry.attributes; + + let attributesNum = 0; + + const programAttributes = program.getAttributes(); + + for ( const name in programAttributes ) { + + const programAttribute = programAttributes[ name ]; + + if ( programAttribute.location >= 0 ) { + + const cachedAttribute = cachedAttributes[ name ]; + let geometryAttribute = geometryAttributes[ name ]; + + if ( geometryAttribute === undefined ) { + + if ( name === 'instanceMatrix' && object.instanceMatrix ) geometryAttribute = object.instanceMatrix; + if ( name === 'instanceColor' && object.instanceColor ) geometryAttribute = object.instanceColor; + + } + + if ( cachedAttribute === undefined ) return true; + + if ( cachedAttribute.attribute !== geometryAttribute ) return true; + + if ( geometryAttribute && cachedAttribute.data !== geometryAttribute.data ) return true; + + attributesNum ++; + + } + + } + + if ( currentState.attributesNum !== attributesNum ) return true; + + if ( currentState.index !== index ) return true; + + return false; + + } + + function saveCache( object, geometry, program, index ) { + + const cache = {}; + const attributes = geometry.attributes; + let attributesNum = 0; + + const programAttributes = program.getAttributes(); + + for ( const name in programAttributes ) { + + const programAttribute = programAttributes[ name ]; + + if ( programAttribute.location >= 0 ) { + + let attribute = attributes[ name ]; + + if ( attribute === undefined ) { + + if ( name === 'instanceMatrix' && object.instanceMatrix ) attribute = object.instanceMatrix; + if ( name === 'instanceColor' && object.instanceColor ) attribute = object.instanceColor; + + } + + const data = {}; + data.attribute = attribute; + + if ( attribute && attribute.data ) { + + data.data = attribute.data; + + } + + cache[ name ] = data; + + attributesNum ++; + + } + + } + + currentState.attributes = cache; + currentState.attributesNum = attributesNum; + + currentState.index = index; + + } + + function initAttributes() { + + const newAttributes = currentState.newAttributes; + + for ( let i = 0, il = newAttributes.length; i < il; i ++ ) { + + newAttributes[ i ] = 0; + + } + + } + + function enableAttribute( attribute ) { + + enableAttributeAndDivisor( attribute, 0 ); + + } + + function enableAttributeAndDivisor( attribute, meshPerAttribute ) { + + const newAttributes = currentState.newAttributes; + const enabledAttributes = currentState.enabledAttributes; + const attributeDivisors = currentState.attributeDivisors; + + newAttributes[ attribute ] = 1; + + if ( enabledAttributes[ attribute ] === 0 ) { + + gl.enableVertexAttribArray( attribute ); + enabledAttributes[ attribute ] = 1; + + } + + if ( attributeDivisors[ attribute ] !== meshPerAttribute ) { + + gl.vertexAttribDivisor( attribute, meshPerAttribute ); + attributeDivisors[ attribute ] = meshPerAttribute; + + } + + } + + function disableUnusedAttributes() { + + const newAttributes = currentState.newAttributes; + const enabledAttributes = currentState.enabledAttributes; + + for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) { + + if ( enabledAttributes[ i ] !== newAttributes[ i ] ) { + + gl.disableVertexAttribArray( i ); + enabledAttributes[ i ] = 0; + + } + + } + + } + + function vertexAttribPointer( index, size, type, normalized, stride, offset, integer ) { + + if ( integer === true ) { + + gl.vertexAttribIPointer( index, size, type, stride, offset ); + + } else { + + gl.vertexAttribPointer( index, size, type, normalized, stride, offset ); + + } + + } + + function setupVertexAttributes( object, material, program, geometry ) { + + initAttributes(); + + const geometryAttributes = geometry.attributes; + + const programAttributes = program.getAttributes(); + + const materialDefaultAttributeValues = material.defaultAttributeValues; + + for ( const name in programAttributes ) { + + const programAttribute = programAttributes[ name ]; + + if ( programAttribute.location >= 0 ) { + + let geometryAttribute = geometryAttributes[ name ]; + + if ( geometryAttribute === undefined ) { + + if ( name === 'instanceMatrix' && object.instanceMatrix ) geometryAttribute = object.instanceMatrix; + if ( name === 'instanceColor' && object.instanceColor ) geometryAttribute = object.instanceColor; + + } + + if ( geometryAttribute !== undefined ) { + + const normalized = geometryAttribute.normalized; + const size = geometryAttribute.itemSize; + + const attribute = attributes.get( geometryAttribute ); + + // TODO Attribute may not be available on context restore + + if ( attribute === undefined ) continue; + + const buffer = attribute.buffer; + const type = attribute.type; + const bytesPerElement = attribute.bytesPerElement; + + // check for integer attributes + + const integer = ( type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType ); + + if ( geometryAttribute.isInterleavedBufferAttribute ) { + + const data = geometryAttribute.data; + const stride = data.stride; + const offset = geometryAttribute.offset; + + if ( data.isInstancedInterleavedBuffer ) { + + for ( let i = 0; i < programAttribute.locationSize; i ++ ) { + + enableAttributeAndDivisor( programAttribute.location + i, data.meshPerAttribute ); + + } + + if ( object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined ) { + + geometry._maxInstanceCount = data.meshPerAttribute * data.count; + + } + + } else { + + for ( let i = 0; i < programAttribute.locationSize; i ++ ) { + + enableAttribute( programAttribute.location + i ); + + } + + } + + gl.bindBuffer( gl.ARRAY_BUFFER, buffer ); + + for ( let i = 0; i < programAttribute.locationSize; i ++ ) { + + vertexAttribPointer( + programAttribute.location + i, + size / programAttribute.locationSize, + type, + normalized, + stride * bytesPerElement, + ( offset + ( size / programAttribute.locationSize ) * i ) * bytesPerElement, + integer + ); + + } + + } else { + + if ( geometryAttribute.isInstancedBufferAttribute ) { + + for ( let i = 0; i < programAttribute.locationSize; i ++ ) { + + enableAttributeAndDivisor( programAttribute.location + i, geometryAttribute.meshPerAttribute ); + + } + + if ( object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined ) { + + geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count; + + } + + } else { + + for ( let i = 0; i < programAttribute.locationSize; i ++ ) { + + enableAttribute( programAttribute.location + i ); + + } + + } + + gl.bindBuffer( gl.ARRAY_BUFFER, buffer ); + + for ( let i = 0; i < programAttribute.locationSize; i ++ ) { + + vertexAttribPointer( + programAttribute.location + i, + size / programAttribute.locationSize, + type, + normalized, + size * bytesPerElement, + ( size / programAttribute.locationSize ) * i * bytesPerElement, + integer + ); + + } + + } + + } else if ( materialDefaultAttributeValues !== undefined ) { + + const value = materialDefaultAttributeValues[ name ]; + + if ( value !== undefined ) { + + switch ( value.length ) { + + case 2: + gl.vertexAttrib2fv( programAttribute.location, value ); + break; + + case 3: + gl.vertexAttrib3fv( programAttribute.location, value ); + break; + + case 4: + gl.vertexAttrib4fv( programAttribute.location, value ); + break; + + default: + gl.vertexAttrib1fv( programAttribute.location, value ); + + } + + } + + } + + } + + } + + disableUnusedAttributes(); + + } + + function dispose() { + + reset(); + + for ( const geometryId in bindingStates ) { + + const programMap = bindingStates[ geometryId ]; + + for ( const programId in programMap ) { + + const stateMap = programMap[ programId ]; + + for ( const wireframe in stateMap ) { + + deleteVertexArrayObject( stateMap[ wireframe ].object ); + + delete stateMap[ wireframe ]; + + } + + delete programMap[ programId ]; + + } + + delete bindingStates[ geometryId ]; + + } + + } + + function releaseStatesOfGeometry( geometry ) { + + if ( bindingStates[ geometry.id ] === undefined ) return; + + const programMap = bindingStates[ geometry.id ]; + + for ( const programId in programMap ) { + + const stateMap = programMap[ programId ]; + + for ( const wireframe in stateMap ) { + + deleteVertexArrayObject( stateMap[ wireframe ].object ); + + delete stateMap[ wireframe ]; + + } + + delete programMap[ programId ]; + + } + + delete bindingStates[ geometry.id ]; + + } + + function releaseStatesOfProgram( program ) { + + for ( const geometryId in bindingStates ) { + + const programMap = bindingStates[ geometryId ]; + + if ( programMap[ program.id ] === undefined ) continue; + + const stateMap = programMap[ program.id ]; + + for ( const wireframe in stateMap ) { + + deleteVertexArrayObject( stateMap[ wireframe ].object ); + + delete stateMap[ wireframe ]; + + } + + delete programMap[ program.id ]; + + } + + } + + function reset() { + + resetDefaultState(); + forceUpdate = true; + + if ( currentState === defaultState ) return; + + currentState = defaultState; + bindVertexArrayObject( currentState.object ); + + } + + // for backward-compatibility + + function resetDefaultState() { + + defaultState.geometry = null; + defaultState.program = null; + defaultState.wireframe = false; + + } + + return { + + setup: setup, + reset: reset, + resetDefaultState: resetDefaultState, + dispose: dispose, + releaseStatesOfGeometry: releaseStatesOfGeometry, + releaseStatesOfProgram: releaseStatesOfProgram, + + initAttributes: initAttributes, + enableAttribute: enableAttribute, + disableUnusedAttributes: disableUnusedAttributes + + }; + +} + +function WebGLBufferRenderer( gl, extensions, info ) { + + let mode; + + function setMode( value ) { + + mode = value; + + } + + function render( start, count ) { + + gl.drawArrays( mode, start, count ); + + info.update( count, mode, 1 ); + + } + + function renderInstances( start, count, primcount ) { + + if ( primcount === 0 ) return; + + gl.drawArraysInstanced( mode, start, count, primcount ); + + info.update( count, mode, primcount ); + + } + + function renderMultiDraw( starts, counts, drawCount ) { + + if ( drawCount === 0 ) return; + + const extension = extensions.get( 'WEBGL_multi_draw' ); + extension.multiDrawArraysWEBGL( mode, starts, 0, counts, 0, drawCount ); + + let elementCount = 0; + for ( let i = 0; i < drawCount; i ++ ) { + + elementCount += counts[ i ]; + + } + + info.update( elementCount, mode, 1 ); + + } + + function renderMultiDrawInstances( starts, counts, drawCount, primcount ) { + + if ( drawCount === 0 ) return; + + const extension = extensions.get( 'WEBGL_multi_draw' ); + + if ( extension === null ) { + + for ( let i = 0; i < starts.length; i ++ ) { + + renderInstances( starts[ i ], counts[ i ], primcount[ i ] ); + + } + + } else { + + extension.multiDrawArraysInstancedWEBGL( mode, starts, 0, counts, 0, primcount, 0, drawCount ); + + let elementCount = 0; + for ( let i = 0; i < drawCount; i ++ ) { + + elementCount += counts[ i ] * primcount[ i ]; + + } + + info.update( elementCount, mode, 1 ); + + } + + } + + // + + this.setMode = setMode; + this.render = render; + this.renderInstances = renderInstances; + this.renderMultiDraw = renderMultiDraw; + this.renderMultiDrawInstances = renderMultiDrawInstances; + +} + +function WebGLCapabilities( gl, extensions, parameters, utils ) { + + let maxAnisotropy; + + function getMaxAnisotropy() { + + if ( maxAnisotropy !== undefined ) return maxAnisotropy; + + if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) { + + const extension = extensions.get( 'EXT_texture_filter_anisotropic' ); + + maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT ); + + } else { + + maxAnisotropy = 0; + + } + + return maxAnisotropy; + + } + + function textureFormatReadable( textureFormat ) { + + if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) { + + return false; + + } + + return true; + + } + + function textureTypeReadable( textureType ) { + + const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) ); + + if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // Edge and Chrome Mac < 52 (#9513) + textureType !== FloatType && ! halfFloatSupportedByExt ) { + + return false; + + } + + return true; + + } + + function getMaxPrecision( precision ) { + + if ( precision === 'highp' ) { + + if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 && + gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) { + + return 'highp'; + + } + + precision = 'mediump'; + + } + + if ( precision === 'mediump' ) { + + if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 && + gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) { + + return 'mediump'; + + } + + } + + return 'lowp'; + + } + + let precision = parameters.precision !== undefined ? parameters.precision : 'highp'; + const maxPrecision = getMaxPrecision( precision ); + + if ( maxPrecision !== precision ) { + + console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' ); + precision = maxPrecision; + + } + + const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true; + const reverseDepthBuffer = parameters.reverseDepthBuffer === true && extensions.has( 'EXT_clip_control' ); + + const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS ); + const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ); + const maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE ); + const maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE ); + + const maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS ); + const maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS ); + const maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS ); + const maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS ); + + const vertexTextures = maxVertexTextures > 0; + + const maxSamples = gl.getParameter( gl.MAX_SAMPLES ); + + return { + + isWebGL2: true, // keeping this for backwards compatibility + + getMaxAnisotropy: getMaxAnisotropy, + getMaxPrecision: getMaxPrecision, + + textureFormatReadable: textureFormatReadable, + textureTypeReadable: textureTypeReadable, + + precision: precision, + logarithmicDepthBuffer: logarithmicDepthBuffer, + reverseDepthBuffer: reverseDepthBuffer, + + maxTextures: maxTextures, + maxVertexTextures: maxVertexTextures, + maxTextureSize: maxTextureSize, + maxCubemapSize: maxCubemapSize, + + maxAttributes: maxAttributes, + maxVertexUniforms: maxVertexUniforms, + maxVaryings: maxVaryings, + maxFragmentUniforms: maxFragmentUniforms, + + vertexTextures: vertexTextures, + + maxSamples: maxSamples + + }; + +} + +function WebGLClipping( properties ) { + + const scope = this; + + let globalState = null, + numGlobalPlanes = 0, + localClippingEnabled = false, + renderingShadows = false; + + const plane = new Plane(), + viewNormalMatrix = new Matrix3(), + + uniform = { value: null, needsUpdate: false }; + + this.uniform = uniform; + this.numPlanes = 0; + this.numIntersection = 0; + + this.init = function ( planes, enableLocalClipping ) { + + const enabled = + planes.length !== 0 || + enableLocalClipping || + // enable state of previous frame - the clipping code has to + // run another frame in order to reset the state: + numGlobalPlanes !== 0 || + localClippingEnabled; + + localClippingEnabled = enableLocalClipping; + + numGlobalPlanes = planes.length; + + return enabled; + + }; + + this.beginShadows = function () { + + renderingShadows = true; + projectPlanes( null ); + + }; + + this.endShadows = function () { + + renderingShadows = false; + + }; + + this.setGlobalState = function ( planes, camera ) { + + globalState = projectPlanes( planes, camera, 0 ); + + }; + + this.setState = function ( material, camera, useCache ) { + + const planes = material.clippingPlanes, + clipIntersection = material.clipIntersection, + clipShadows = material.clipShadows; + + const materialProperties = properties.get( material ); + + if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) { + + // there's no local clipping + + if ( renderingShadows ) { + + // there's no global clipping + + projectPlanes( null ); + + } else { + + resetGlobalState(); + + } + + } else { + + const nGlobal = renderingShadows ? 0 : numGlobalPlanes, + lGlobal = nGlobal * 4; + + let dstArray = materialProperties.clippingState || null; + + uniform.value = dstArray; // ensure unique state + + dstArray = projectPlanes( planes, camera, lGlobal, useCache ); + + for ( let i = 0; i !== lGlobal; ++ i ) { + + dstArray[ i ] = globalState[ i ]; + + } + + materialProperties.clippingState = dstArray; + this.numIntersection = clipIntersection ? this.numPlanes : 0; + this.numPlanes += nGlobal; + + } + + + }; + + function resetGlobalState() { + + if ( uniform.value !== globalState ) { + + uniform.value = globalState; + uniform.needsUpdate = numGlobalPlanes > 0; + + } + + scope.numPlanes = numGlobalPlanes; + scope.numIntersection = 0; + + } + + function projectPlanes( planes, camera, dstOffset, skipTransform ) { + + const nPlanes = planes !== null ? planes.length : 0; + let dstArray = null; + + if ( nPlanes !== 0 ) { + + dstArray = uniform.value; + + if ( skipTransform !== true || dstArray === null ) { + + const flatSize = dstOffset + nPlanes * 4, + viewMatrix = camera.matrixWorldInverse; + + viewNormalMatrix.getNormalMatrix( viewMatrix ); + + if ( dstArray === null || dstArray.length < flatSize ) { + + dstArray = new Float32Array( flatSize ); + + } + + for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) { + + plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix ); + + plane.normal.toArray( dstArray, i4 ); + dstArray[ i4 + 3 ] = plane.constant; + + } + + } + + uniform.value = dstArray; + uniform.needsUpdate = true; + + } + + scope.numPlanes = nPlanes; + scope.numIntersection = 0; + + return dstArray; + + } + +} + +function WebGLCubeMaps( renderer ) { + + let cubemaps = new WeakMap(); + + function mapTextureMapping( texture, mapping ) { + + if ( mapping === EquirectangularReflectionMapping ) { + + texture.mapping = CubeReflectionMapping; + + } else if ( mapping === EquirectangularRefractionMapping ) { + + texture.mapping = CubeRefractionMapping; + + } + + return texture; + + } + + function get( texture ) { + + if ( texture && texture.isTexture ) { + + const mapping = texture.mapping; + + if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) { + + if ( cubemaps.has( texture ) ) { + + const cubemap = cubemaps.get( texture ).texture; + return mapTextureMapping( cubemap, texture.mapping ); + + } else { + + const image = texture.image; + + if ( image && image.height > 0 ) { + + const renderTarget = new WebGLCubeRenderTarget( image.height ); + renderTarget.fromEquirectangularTexture( renderer, texture ); + cubemaps.set( texture, renderTarget ); + + texture.addEventListener( 'dispose', onTextureDispose ); + + return mapTextureMapping( renderTarget.texture, texture.mapping ); + + } else { + + // image not yet ready. try the conversion next frame + + return null; + + } + + } + + } + + } + + return texture; + + } + + function onTextureDispose( event ) { + + const texture = event.target; + + texture.removeEventListener( 'dispose', onTextureDispose ); + + const cubemap = cubemaps.get( texture ); + + if ( cubemap !== undefined ) { + + cubemaps.delete( texture ); + cubemap.dispose(); + + } + + } + + function dispose() { + + cubemaps = new WeakMap(); + + } + + return { + get: get, + dispose: dispose + }; + +} + +const LOD_MIN = 4; + +// The standard deviations (radians) associated with the extra mips. These are +// chosen to approximate a Trowbridge-Reitz distribution function times the +// geometric shadowing function. These sigma values squared must match the +// variance #defines in cube_uv_reflection_fragment.glsl.js. +const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ]; + +// The maximum length of the blur for loop. Smaller sigmas will use fewer +// samples and exit early, but not recompile the shader. +const MAX_SAMPLES = 20; + +const _flatCamera = /*@__PURE__*/ new OrthographicCamera(); +const _clearColor = /*@__PURE__*/ new Color(); +let _oldTarget = null; +let _oldActiveCubeFace = 0; +let _oldActiveMipmapLevel = 0; +let _oldXrEnabled = false; + +// Golden Ratio +const PHI = ( 1 + Math.sqrt( 5 ) ) / 2; +const INV_PHI = 1 / PHI; + +// Vertices of a dodecahedron (except the opposites, which represent the +// same axis), used as axis directions evenly spread on a sphere. +const _axisDirections = [ + /*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ), + /*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ), + /*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ), + /*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ), + /*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ), + /*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ), + /*@__PURE__*/ new Vector3( - 1, 1, - 1 ), + /*@__PURE__*/ new Vector3( 1, 1, - 1 ), + /*@__PURE__*/ new Vector3( - 1, 1, 1 ), + /*@__PURE__*/ new Vector3( 1, 1, 1 ) ]; + +/** + * This class generates a Prefiltered, Mipmapped Radiance Environment Map + * (PMREM) from a cubeMap environment texture. This allows different levels of + * blur to be quickly accessed based on material roughness. It is packed into a + * special CubeUV format that allows us to perform custom interpolation so that + * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap + * chain, it only goes down to the LOD_MIN level (above), and then creates extra + * even more filtered 'mips' at the same LOD_MIN resolution, associated with + * higher roughness levels. In this way we maintain resolution to smoothly + * interpolate diffuse lighting while limiting sampling computation. + * + * Paper: Fast, Accurate Image-Based Lighting + * https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view +*/ + +class PMREMGenerator { + + constructor( renderer ) { + + this._renderer = renderer; + this._pingPongRenderTarget = null; + + this._lodMax = 0; + this._cubeSize = 0; + this._lodPlanes = []; + this._sizeLods = []; + this._sigmas = []; + + this._blurMaterial = null; + this._cubemapMaterial = null; + this._equirectMaterial = null; + + this._compileMaterial( this._blurMaterial ); + + } + + /** + * Generates a PMREM from a supplied Scene, which can be faster than using an + * image if networking bandwidth is low. Optional sigma specifies a blur radius + * in radians to be applied to the scene before PMREM generation. Optional near + * and far planes ensure the scene is rendered in its entirety (the cubeCamera + * is placed at the origin). + */ + fromScene( scene, sigma = 0, near = 0.1, far = 100 ) { + + _oldTarget = this._renderer.getRenderTarget(); + _oldActiveCubeFace = this._renderer.getActiveCubeFace(); + _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); + _oldXrEnabled = this._renderer.xr.enabled; + + this._renderer.xr.enabled = false; + + this._setSize( 256 ); + + const cubeUVRenderTarget = this._allocateTargets(); + cubeUVRenderTarget.depthBuffer = true; + + this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget ); + + if ( sigma > 0 ) { + + this._blur( cubeUVRenderTarget, 0, 0, sigma ); + + } + + this._applyPMREM( cubeUVRenderTarget ); + this._cleanup( cubeUVRenderTarget ); + + return cubeUVRenderTarget; + + } + + /** + * Generates a PMREM from an equirectangular texture, which can be either LDR + * or HDR. The ideal input image size is 1k (1024 x 512), + * as this matches best with the 256 x 256 cubemap output. + * The smallest supported equirectangular image size is 64 x 32. + */ + fromEquirectangular( equirectangular, renderTarget = null ) { + + return this._fromTexture( equirectangular, renderTarget ); + + } + + /** + * Generates a PMREM from an cubemap texture, which can be either LDR + * or HDR. The ideal input cube size is 256 x 256, + * as this matches best with the 256 x 256 cubemap output. + * The smallest supported cube size is 16 x 16. + */ + fromCubemap( cubemap, renderTarget = null ) { + + return this._fromTexture( cubemap, renderTarget ); + + } + + /** + * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during + * your texture's network fetch for increased concurrency. + */ + compileCubemapShader() { + + if ( this._cubemapMaterial === null ) { + + this._cubemapMaterial = _getCubemapMaterial(); + this._compileMaterial( this._cubemapMaterial ); + + } + + } + + /** + * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during + * your texture's network fetch for increased concurrency. + */ + compileEquirectangularShader() { + + if ( this._equirectMaterial === null ) { + + this._equirectMaterial = _getEquirectMaterial(); + this._compileMaterial( this._equirectMaterial ); + + } + + } + + /** + * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class, + * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on + * one of them will cause any others to also become unusable. + */ + dispose() { + + this._dispose(); + + if ( this._cubemapMaterial !== null ) this._cubemapMaterial.dispose(); + if ( this._equirectMaterial !== null ) this._equirectMaterial.dispose(); + + } + + // private interface + + _setSize( cubeSize ) { + + this._lodMax = Math.floor( Math.log2( cubeSize ) ); + this._cubeSize = Math.pow( 2, this._lodMax ); + + } + + _dispose() { + + if ( this._blurMaterial !== null ) this._blurMaterial.dispose(); + + if ( this._pingPongRenderTarget !== null ) this._pingPongRenderTarget.dispose(); + + for ( let i = 0; i < this._lodPlanes.length; i ++ ) { + + this._lodPlanes[ i ].dispose(); + + } + + } + + _cleanup( outputTarget ) { + + this._renderer.setRenderTarget( _oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel ); + this._renderer.xr.enabled = _oldXrEnabled; + + outputTarget.scissorTest = false; + _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height ); + + } + + _fromTexture( texture, renderTarget ) { + + if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) { + + this._setSize( texture.image.length === 0 ? 16 : ( texture.image[ 0 ].width || texture.image[ 0 ].image.width ) ); + + } else { // Equirectangular + + this._setSize( texture.image.width / 4 ); + + } + + _oldTarget = this._renderer.getRenderTarget(); + _oldActiveCubeFace = this._renderer.getActiveCubeFace(); + _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); + _oldXrEnabled = this._renderer.xr.enabled; + + this._renderer.xr.enabled = false; + + const cubeUVRenderTarget = renderTarget || this._allocateTargets(); + this._textureToCubeUV( texture, cubeUVRenderTarget ); + this._applyPMREM( cubeUVRenderTarget ); + this._cleanup( cubeUVRenderTarget ); + + return cubeUVRenderTarget; + + } + + _allocateTargets() { + + const width = 3 * Math.max( this._cubeSize, 16 * 7 ); + const height = 4 * this._cubeSize; + + const params = { + magFilter: LinearFilter, + minFilter: LinearFilter, + generateMipmaps: false, + type: HalfFloatType, + format: RGBAFormat, + colorSpace: LinearSRGBColorSpace, + depthBuffer: false + }; + + const cubeUVRenderTarget = _createRenderTarget( width, height, params ); + + if ( this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height ) { + + if ( this._pingPongRenderTarget !== null ) { + + this._dispose(); + + } + + this._pingPongRenderTarget = _createRenderTarget( width, height, params ); + + const { _lodMax } = this; + ( { sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = _createPlanes( _lodMax ) ); + + this._blurMaterial = _getBlurShader( _lodMax, width, height ); + + } + + return cubeUVRenderTarget; + + } + + _compileMaterial( material ) { + + const tmpMesh = new Mesh( this._lodPlanes[ 0 ], material ); + this._renderer.compile( tmpMesh, _flatCamera ); + + } + + _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) { + + const fov = 90; + const aspect = 1; + const cubeCamera = new PerspectiveCamera( fov, aspect, near, far ); + const upSign = [ 1, - 1, 1, 1, 1, 1 ]; + const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ]; + const renderer = this._renderer; + + const originalAutoClear = renderer.autoClear; + const toneMapping = renderer.toneMapping; + renderer.getClearColor( _clearColor ); + + renderer.toneMapping = NoToneMapping; + renderer.autoClear = false; + + const backgroundMaterial = new MeshBasicMaterial( { + name: 'PMREM.Background', + side: BackSide, + depthWrite: false, + depthTest: false, + } ); + + const backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial ); + + let useSolidColor = false; + const background = scene.background; + + if ( background ) { + + if ( background.isColor ) { + + backgroundMaterial.color.copy( background ); + scene.background = null; + useSolidColor = true; + + } + + } else { + + backgroundMaterial.color.copy( _clearColor ); + useSolidColor = true; + + } + + for ( let i = 0; i < 6; i ++ ) { + + const col = i % 3; + + if ( col === 0 ) { + + cubeCamera.up.set( 0, upSign[ i ], 0 ); + cubeCamera.lookAt( forwardSign[ i ], 0, 0 ); + + } else if ( col === 1 ) { + + cubeCamera.up.set( 0, 0, upSign[ i ] ); + cubeCamera.lookAt( 0, forwardSign[ i ], 0 ); + + } else { + + cubeCamera.up.set( 0, upSign[ i ], 0 ); + cubeCamera.lookAt( 0, 0, forwardSign[ i ] ); + + } + + const size = this._cubeSize; + + _setViewport( cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size ); + + renderer.setRenderTarget( cubeUVRenderTarget ); + + if ( useSolidColor ) { + + renderer.render( backgroundBox, cubeCamera ); + + } + + renderer.render( scene, cubeCamera ); + + } + + backgroundBox.geometry.dispose(); + backgroundBox.material.dispose(); + + renderer.toneMapping = toneMapping; + renderer.autoClear = originalAutoClear; + scene.background = background; + + } + + _textureToCubeUV( texture, cubeUVRenderTarget ) { + + const renderer = this._renderer; + + const isCubeTexture = ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ); + + if ( isCubeTexture ) { + + if ( this._cubemapMaterial === null ) { + + this._cubemapMaterial = _getCubemapMaterial(); + + } + + this._cubemapMaterial.uniforms.flipEnvMap.value = ( texture.isRenderTargetTexture === false ) ? - 1 : 1; + + } else { + + if ( this._equirectMaterial === null ) { + + this._equirectMaterial = _getEquirectMaterial(); + + } + + } + + const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial; + const mesh = new Mesh( this._lodPlanes[ 0 ], material ); + + const uniforms = material.uniforms; + + uniforms[ 'envMap' ].value = texture; + + const size = this._cubeSize; + + _setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size ); + + renderer.setRenderTarget( cubeUVRenderTarget ); + renderer.render( mesh, _flatCamera ); + + } + + _applyPMREM( cubeUVRenderTarget ) { + + const renderer = this._renderer; + const autoClear = renderer.autoClear; + renderer.autoClear = false; + const n = this._lodPlanes.length; + + for ( let i = 1; i < n; i ++ ) { + + const sigma = Math.sqrt( this._sigmas[ i ] * this._sigmas[ i ] - this._sigmas[ i - 1 ] * this._sigmas[ i - 1 ] ); + + const poleAxis = _axisDirections[ ( n - i - 1 ) % _axisDirections.length ]; + + this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis ); + + } + + renderer.autoClear = autoClear; + + } + + /** + * This is a two-pass Gaussian blur for a cubemap. Normally this is done + * vertically and horizontally, but this breaks down on a cube. Here we apply + * the blur latitudinally (around the poles), and then longitudinally (towards + * the poles) to approximate the orthogonally-separable blur. It is least + * accurate at the poles, but still does a decent job. + */ + _blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) { + + const pingPongRenderTarget = this._pingPongRenderTarget; + + this._halfBlur( + cubeUVRenderTarget, + pingPongRenderTarget, + lodIn, + lodOut, + sigma, + 'latitudinal', + poleAxis ); + + this._halfBlur( + pingPongRenderTarget, + cubeUVRenderTarget, + lodOut, + lodOut, + sigma, + 'longitudinal', + poleAxis ); + + } + + _halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) { + + const renderer = this._renderer; + const blurMaterial = this._blurMaterial; + + if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) { + + console.error( + 'blur direction must be either latitudinal or longitudinal!' ); + + } + + // Number of standard deviations at which to cut off the discrete approximation. + const STANDARD_DEVIATIONS = 3; + + const blurMesh = new Mesh( this._lodPlanes[ lodOut ], blurMaterial ); + const blurUniforms = blurMaterial.uniforms; + + const pixels = this._sizeLods[ lodIn ] - 1; + const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 ); + const sigmaPixels = sigmaRadians / radiansPerPixel; + const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES; + + if ( samples > MAX_SAMPLES ) { + + console.warn( `sigmaRadians, ${ + sigmaRadians}, is too large and will clip, as it requested ${ + samples} samples when the maximum is set to ${MAX_SAMPLES}` ); + + } + + const weights = []; + let sum = 0; + + for ( let i = 0; i < MAX_SAMPLES; ++ i ) { + + const x = i / sigmaPixels; + const weight = Math.exp( - x * x / 2 ); + weights.push( weight ); + + if ( i === 0 ) { + + sum += weight; + + } else if ( i < samples ) { + + sum += 2 * weight; + + } + + } + + for ( let i = 0; i < weights.length; i ++ ) { + + weights[ i ] = weights[ i ] / sum; + + } + + blurUniforms[ 'envMap' ].value = targetIn.texture; + blurUniforms[ 'samples' ].value = samples; + blurUniforms[ 'weights' ].value = weights; + blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal'; + + if ( poleAxis ) { + + blurUniforms[ 'poleAxis' ].value = poleAxis; + + } + + const { _lodMax } = this; + blurUniforms[ 'dTheta' ].value = radiansPerPixel; + blurUniforms[ 'mipInt' ].value = _lodMax - lodIn; + + const outputSize = this._sizeLods[ lodOut ]; + const x = 3 * outputSize * ( lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0 ); + const y = 4 * ( this._cubeSize - outputSize ); + + _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize ); + renderer.setRenderTarget( targetOut ); + renderer.render( blurMesh, _flatCamera ); + + } + +} + + + +function _createPlanes( lodMax ) { + + const lodPlanes = []; + const sizeLods = []; + const sigmas = []; + + let lod = lodMax; + + const totalLods = lodMax - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length; + + for ( let i = 0; i < totalLods; i ++ ) { + + const sizeLod = Math.pow( 2, lod ); + sizeLods.push( sizeLod ); + let sigma = 1.0 / sizeLod; + + if ( i > lodMax - LOD_MIN ) { + + sigma = EXTRA_LOD_SIGMA[ i - lodMax + LOD_MIN - 1 ]; + + } else if ( i === 0 ) { + + sigma = 0; + + } + + sigmas.push( sigma ); + + const texelSize = 1.0 / ( sizeLod - 2 ); + const min = - texelSize; + const max = 1 + texelSize; + const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ]; + + const cubeFaces = 6; + const vertices = 6; + const positionSize = 3; + const uvSize = 2; + const faceIndexSize = 1; + + const position = new Float32Array( positionSize * vertices * cubeFaces ); + const uv = new Float32Array( uvSize * vertices * cubeFaces ); + const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces ); + + for ( let face = 0; face < cubeFaces; face ++ ) { + + const x = ( face % 3 ) * 2 / 3 - 1; + const y = face > 2 ? 0 : - 1; + const coordinates = [ + x, y, 0, + x + 2 / 3, y, 0, + x + 2 / 3, y + 1, 0, + x, y, 0, + x + 2 / 3, y + 1, 0, + x, y + 1, 0 + ]; + position.set( coordinates, positionSize * vertices * face ); + uv.set( uv1, uvSize * vertices * face ); + const fill = [ face, face, face, face, face, face ]; + faceIndex.set( fill, faceIndexSize * vertices * face ); + + } + + const planes = new BufferGeometry(); + planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) ); + planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) ); + planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) ); + lodPlanes.push( planes ); + + if ( lod > LOD_MIN ) { + + lod --; + + } + + } + + return { lodPlanes, sizeLods, sigmas }; + +} + +function _createRenderTarget( width, height, params ) { + + const cubeUVRenderTarget = new WebGLRenderTarget( width, height, params ); + cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping; + cubeUVRenderTarget.texture.name = 'PMREM.cubeUv'; + cubeUVRenderTarget.scissorTest = true; + return cubeUVRenderTarget; + +} + +function _setViewport( target, x, y, width, height ) { + + target.viewport.set( x, y, width, height ); + target.scissor.set( x, y, width, height ); + +} + +function _getBlurShader( lodMax, width, height ) { + + const weights = new Float32Array( MAX_SAMPLES ); + const poleAxis = new Vector3( 0, 1, 0 ); + const shaderMaterial = new ShaderMaterial( { + + name: 'SphericalGaussianBlur', + + defines: { + 'n': MAX_SAMPLES, + 'CUBEUV_TEXEL_WIDTH': 1.0 / width, + 'CUBEUV_TEXEL_HEIGHT': 1.0 / height, + 'CUBEUV_MAX_MIP': `${lodMax}.0`, + }, + + uniforms: { + 'envMap': { value: null }, + 'samples': { value: 1 }, + 'weights': { value: weights }, + 'latitudinal': { value: false }, + 'dTheta': { value: 0 }, + 'mipInt': { value: 0 }, + 'poleAxis': { value: poleAxis } + }, + + vertexShader: _getCommonVertexShader(), + + fragmentShader: /* glsl */` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + uniform int samples; + uniform float weights[ n ]; + uniform bool latitudinal; + uniform float dTheta; + uniform float mipInt; + uniform vec3 poleAxis; + + #define ENVMAP_TYPE_CUBE_UV + #include + + vec3 getSample( float theta, vec3 axis ) { + + float cosTheta = cos( theta ); + // Rodrigues' axis-angle rotation + vec3 sampleDirection = vOutputDirection * cosTheta + + cross( axis, vOutputDirection ) * sin( theta ) + + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); + + return bilinearCubeUV( envMap, sampleDirection, mipInt ); + + } + + void main() { + + vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); + + if ( all( equal( axis, vec3( 0.0 ) ) ) ) { + + axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); + + } + + axis = normalize( axis ); + + gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); + gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); + + for ( int i = 1; i < n; i++ ) { + + if ( i >= samples ) { + + break; + + } + + float theta = dTheta * float( i ); + gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); + gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); + + } + + } + `, + + blending: NoBlending, + depthTest: false, + depthWrite: false + + } ); + + return shaderMaterial; + +} + +function _getEquirectMaterial() { + + return new ShaderMaterial( { + + name: 'EquirectangularToCubeUV', + + uniforms: { + 'envMap': { value: null } + }, + + vertexShader: _getCommonVertexShader(), + + fragmentShader: /* glsl */` + + precision mediump float; + precision mediump int; + + varying vec3 vOutputDirection; + + uniform sampler2D envMap; + + #include + + void main() { + + vec3 outputDirection = normalize( vOutputDirection ); + vec2 uv = equirectUv( outputDirection ); + + gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); + + } + `, + + blending: NoBlending, + depthTest: false, + depthWrite: false + + } ); + +} + +function _getCubemapMaterial() { + + return new ShaderMaterial( { + + name: 'CubemapToCubeUV', + + uniforms: { + 'envMap': { value: null }, + 'flipEnvMap': { value: - 1 } + }, + + vertexShader: _getCommonVertexShader(), + + fragmentShader: /* glsl */` + + precision mediump float; + precision mediump int; + + uniform float flipEnvMap; + + varying vec3 vOutputDirection; + + uniform samplerCube envMap; + + void main() { + + gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); + + } + `, + + blending: NoBlending, + depthTest: false, + depthWrite: false + + } ); + +} + +function _getCommonVertexShader() { + + return /* glsl */` + + precision mediump float; + precision mediump int; + + attribute float faceIndex; + + varying vec3 vOutputDirection; + + // RH coordinate system; PMREM face-indexing convention + vec3 getDirection( vec2 uv, float face ) { + + uv = 2.0 * uv - 1.0; + + vec3 direction = vec3( uv, 1.0 ); + + if ( face == 0.0 ) { + + direction = direction.zyx; // ( 1, v, u ) pos x + + } else if ( face == 1.0 ) { + + direction = direction.xzy; + direction.xz *= -1.0; // ( -u, 1, -v ) pos y + + } else if ( face == 2.0 ) { + + direction.x *= -1.0; // ( -u, v, 1 ) pos z + + } else if ( face == 3.0 ) { + + direction = direction.zyx; + direction.xz *= -1.0; // ( -1, v, -u ) neg x + + } else if ( face == 4.0 ) { + + direction = direction.xzy; + direction.xy *= -1.0; // ( -u, -1, v ) neg y + + } else if ( face == 5.0 ) { + + direction.z *= -1.0; // ( u, v, -1 ) neg z + + } + + return direction; + + } + + void main() { + + vOutputDirection = getDirection( uv, faceIndex ); + gl_Position = vec4( position, 1.0 ); + + } + `; + +} + +function WebGLCubeUVMaps( renderer ) { + + let cubeUVmaps = new WeakMap(); + + let pmremGenerator = null; + + function get( texture ) { + + if ( texture && texture.isTexture ) { + + const mapping = texture.mapping; + + const isEquirectMap = ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ); + const isCubeMap = ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping ); + + // equirect/cube map to cubeUV conversion + + if ( isEquirectMap || isCubeMap ) { + + let renderTarget = cubeUVmaps.get( texture ); + + const currentPMREMVersion = renderTarget !== undefined ? renderTarget.texture.pmremVersion : 0; + + if ( texture.isRenderTargetTexture && texture.pmremVersion !== currentPMREMVersion ) { + + if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer ); + + renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture, renderTarget ) : pmremGenerator.fromCubemap( texture, renderTarget ); + renderTarget.texture.pmremVersion = texture.pmremVersion; + + cubeUVmaps.set( texture, renderTarget ); + + return renderTarget.texture; + + } else { + + if ( renderTarget !== undefined ) { + + return renderTarget.texture; + + } else { + + const image = texture.image; + + if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) { + + if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer ); + + renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture ); + renderTarget.texture.pmremVersion = texture.pmremVersion; + + cubeUVmaps.set( texture, renderTarget ); + + texture.addEventListener( 'dispose', onTextureDispose ); + + return renderTarget.texture; + + } else { + + // image not yet ready. try the conversion next frame + + return null; + + } + + } + + } + + } + + } + + return texture; + + } + + function isCubeTextureComplete( image ) { + + let count = 0; + const length = 6; + + for ( let i = 0; i < length; i ++ ) { + + if ( image[ i ] !== undefined ) count ++; + + } + + return count === length; + + + } + + function onTextureDispose( event ) { + + const texture = event.target; + + texture.removeEventListener( 'dispose', onTextureDispose ); + + const cubemapUV = cubeUVmaps.get( texture ); + + if ( cubemapUV !== undefined ) { + + cubeUVmaps.delete( texture ); + cubemapUV.dispose(); + + } + + } + + function dispose() { + + cubeUVmaps = new WeakMap(); + + if ( pmremGenerator !== null ) { + + pmremGenerator.dispose(); + pmremGenerator = null; + + } + + } + + return { + get: get, + dispose: dispose + }; + +} + +function WebGLExtensions( gl ) { + + const extensions = {}; + + function getExtension( name ) { + + if ( extensions[ name ] !== undefined ) { + + return extensions[ name ]; + + } + + let extension; + + switch ( name ) { + + case 'WEBGL_depth_texture': + extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' ); + break; + + case 'EXT_texture_filter_anisotropic': + extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' ); + break; + + case 'WEBGL_compressed_texture_s3tc': + extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' ); + break; + + case 'WEBGL_compressed_texture_pvrtc': + extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' ); + break; + + default: + extension = gl.getExtension( name ); + + } + + extensions[ name ] = extension; + + return extension; + + } + + return { + + has: function ( name ) { + + return getExtension( name ) !== null; + + }, + + init: function () { + + getExtension( 'EXT_color_buffer_float' ); + getExtension( 'WEBGL_clip_cull_distance' ); + getExtension( 'OES_texture_float_linear' ); + getExtension( 'EXT_color_buffer_half_float' ); + getExtension( 'WEBGL_multisampled_render_to_texture' ); + getExtension( 'WEBGL_render_shared_exponent' ); + + }, + + get: function ( name ) { + + const extension = getExtension( name ); + + if ( extension === null ) { + + warnOnce( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' ); + + } + + return extension; + + } + + }; + +} + +function WebGLGeometries( gl, attributes, info, bindingStates ) { + + const geometries = {}; + const wireframeAttributes = new WeakMap(); + + function onGeometryDispose( event ) { + + const geometry = event.target; + + if ( geometry.index !== null ) { + + attributes.remove( geometry.index ); + + } + + for ( const name in geometry.attributes ) { + + attributes.remove( geometry.attributes[ name ] ); + + } + + geometry.removeEventListener( 'dispose', onGeometryDispose ); + + delete geometries[ geometry.id ]; + + const attribute = wireframeAttributes.get( geometry ); + + if ( attribute ) { + + attributes.remove( attribute ); + wireframeAttributes.delete( geometry ); + + } + + bindingStates.releaseStatesOfGeometry( geometry ); + + if ( geometry.isInstancedBufferGeometry === true ) { + + delete geometry._maxInstanceCount; + + } + + // + + info.memory.geometries --; + + } + + function get( object, geometry ) { + + if ( geometries[ geometry.id ] === true ) return geometry; + + geometry.addEventListener( 'dispose', onGeometryDispose ); + + geometries[ geometry.id ] = true; + + info.memory.geometries ++; + + return geometry; + + } + + function update( geometry ) { + + const geometryAttributes = geometry.attributes; + + // Updating index buffer in VAO now. See WebGLBindingStates. + + for ( const name in geometryAttributes ) { + + attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER ); + + } + + } + + function updateWireframeAttribute( geometry ) { + + const indices = []; + + const geometryIndex = geometry.index; + const geometryPosition = geometry.attributes.position; + let version = 0; + + if ( geometryIndex !== null ) { + + const array = geometryIndex.array; + version = geometryIndex.version; + + for ( let i = 0, l = array.length; i < l; i += 3 ) { + + const a = array[ i + 0 ]; + const b = array[ i + 1 ]; + const c = array[ i + 2 ]; + + indices.push( a, b, b, c, c, a ); + + } + + } else if ( geometryPosition !== undefined ) { + + const array = geometryPosition.array; + version = geometryPosition.version; + + for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) { + + const a = i + 0; + const b = i + 1; + const c = i + 2; + + indices.push( a, b, b, c, c, a ); + + } + + } else { + + return; + + } + + const attribute = new ( arrayNeedsUint32( indices ) ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ); + attribute.version = version; + + // Updating index buffer in VAO now. See WebGLBindingStates + + // + + const previousAttribute = wireframeAttributes.get( geometry ); + + if ( previousAttribute ) attributes.remove( previousAttribute ); + + // + + wireframeAttributes.set( geometry, attribute ); + + } + + function getWireframeAttribute( geometry ) { + + const currentAttribute = wireframeAttributes.get( geometry ); + + if ( currentAttribute ) { + + const geometryIndex = geometry.index; + + if ( geometryIndex !== null ) { + + // if the attribute is obsolete, create a new one + + if ( currentAttribute.version < geometryIndex.version ) { + + updateWireframeAttribute( geometry ); + + } + + } + + } else { + + updateWireframeAttribute( geometry ); + + } + + return wireframeAttributes.get( geometry ); + + } + + return { + + get: get, + update: update, + + getWireframeAttribute: getWireframeAttribute + + }; + +} + +function WebGLIndexedBufferRenderer( gl, extensions, info ) { + + let mode; + + function setMode( value ) { + + mode = value; + + } + + let type, bytesPerElement; + + function setIndex( value ) { + + type = value.type; + bytesPerElement = value.bytesPerElement; + + } + + function render( start, count ) { + + gl.drawElements( mode, count, type, start * bytesPerElement ); + + info.update( count, mode, 1 ); + + } + + function renderInstances( start, count, primcount ) { + + if ( primcount === 0 ) return; + + gl.drawElementsInstanced( mode, count, type, start * bytesPerElement, primcount ); + + info.update( count, mode, primcount ); + + } + + function renderMultiDraw( starts, counts, drawCount ) { + + if ( drawCount === 0 ) return; + + const extension = extensions.get( 'WEBGL_multi_draw' ); + extension.multiDrawElementsWEBGL( mode, counts, 0, type, starts, 0, drawCount ); + + let elementCount = 0; + for ( let i = 0; i < drawCount; i ++ ) { + + elementCount += counts[ i ]; + + } + + info.update( elementCount, mode, 1 ); + + + } + + function renderMultiDrawInstances( starts, counts, drawCount, primcount ) { + + if ( drawCount === 0 ) return; + + const extension = extensions.get( 'WEBGL_multi_draw' ); + + if ( extension === null ) { + + for ( let i = 0; i < starts.length; i ++ ) { + + renderInstances( starts[ i ] / bytesPerElement, counts[ i ], primcount[ i ] ); + + } + + } else { + + extension.multiDrawElementsInstancedWEBGL( mode, counts, 0, type, starts, 0, primcount, 0, drawCount ); + + let elementCount = 0; + for ( let i = 0; i < drawCount; i ++ ) { + + elementCount += counts[ i ] * primcount[ i ]; + + } + + info.update( elementCount, mode, 1 ); + + } + + } + + // + + this.setMode = setMode; + this.setIndex = setIndex; + this.render = render; + this.renderInstances = renderInstances; + this.renderMultiDraw = renderMultiDraw; + this.renderMultiDrawInstances = renderMultiDrawInstances; + +} + +function WebGLInfo( gl ) { + + const memory = { + geometries: 0, + textures: 0 + }; + + const render = { + frame: 0, + calls: 0, + triangles: 0, + points: 0, + lines: 0 + }; + + function update( count, mode, instanceCount ) { + + render.calls ++; + + switch ( mode ) { + + case gl.TRIANGLES: + render.triangles += instanceCount * ( count / 3 ); + break; + + case gl.LINES: + render.lines += instanceCount * ( count / 2 ); + break; + + case gl.LINE_STRIP: + render.lines += instanceCount * ( count - 1 ); + break; + + case gl.LINE_LOOP: + render.lines += instanceCount * count; + break; + + case gl.POINTS: + render.points += instanceCount * count; + break; + + default: + console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode ); + break; + + } + + } + + function reset() { + + render.calls = 0; + render.triangles = 0; + render.points = 0; + render.lines = 0; + + } + + return { + memory: memory, + render: render, + programs: null, + autoReset: true, + reset: reset, + update: update + }; + +} + +function WebGLMorphtargets( gl, capabilities, textures ) { + + const morphTextures = new WeakMap(); + const morph = new Vector4(); + + function update( object, geometry, program ) { + + const objectInfluences = object.morphTargetInfluences; + + // the following encodes morph targets into an array of data textures. Each layer represents a single morph target. + + const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; + const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0; + + let entry = morphTextures.get( geometry ); + + if ( entry === undefined || entry.count !== morphTargetsCount ) { + + if ( entry !== undefined ) entry.texture.dispose(); + + const hasMorphPosition = geometry.morphAttributes.position !== undefined; + const hasMorphNormals = geometry.morphAttributes.normal !== undefined; + const hasMorphColors = geometry.morphAttributes.color !== undefined; + + const morphTargets = geometry.morphAttributes.position || []; + const morphNormals = geometry.morphAttributes.normal || []; + const morphColors = geometry.morphAttributes.color || []; + + let vertexDataCount = 0; + + if ( hasMorphPosition === true ) vertexDataCount = 1; + if ( hasMorphNormals === true ) vertexDataCount = 2; + if ( hasMorphColors === true ) vertexDataCount = 3; + + let width = geometry.attributes.position.count * vertexDataCount; + let height = 1; + + if ( width > capabilities.maxTextureSize ) { + + height = Math.ceil( width / capabilities.maxTextureSize ); + width = capabilities.maxTextureSize; + + } + + const buffer = new Float32Array( width * height * 4 * morphTargetsCount ); + + const texture = new DataArrayTexture( buffer, width, height, morphTargetsCount ); + texture.type = FloatType; + texture.needsUpdate = true; + + // fill buffer + + const vertexDataStride = vertexDataCount * 4; + + for ( let i = 0; i < morphTargetsCount; i ++ ) { + + const morphTarget = morphTargets[ i ]; + const morphNormal = morphNormals[ i ]; + const morphColor = morphColors[ i ]; + + const offset = width * height * 4 * i; + + for ( let j = 0; j < morphTarget.count; j ++ ) { + + const stride = j * vertexDataStride; + + if ( hasMorphPosition === true ) { + + morph.fromBufferAttribute( morphTarget, j ); + + buffer[ offset + stride + 0 ] = morph.x; + buffer[ offset + stride + 1 ] = morph.y; + buffer[ offset + stride + 2 ] = morph.z; + buffer[ offset + stride + 3 ] = 0; + + } + + if ( hasMorphNormals === true ) { + + morph.fromBufferAttribute( morphNormal, j ); + + buffer[ offset + stride + 4 ] = morph.x; + buffer[ offset + stride + 5 ] = morph.y; + buffer[ offset + stride + 6 ] = morph.z; + buffer[ offset + stride + 7 ] = 0; + + } + + if ( hasMorphColors === true ) { + + morph.fromBufferAttribute( morphColor, j ); + + buffer[ offset + stride + 8 ] = morph.x; + buffer[ offset + stride + 9 ] = morph.y; + buffer[ offset + stride + 10 ] = morph.z; + buffer[ offset + stride + 11 ] = ( morphColor.itemSize === 4 ) ? morph.w : 1; + + } + + } + + } + + entry = { + count: morphTargetsCount, + texture: texture, + size: new Vector2( width, height ) + }; + + morphTextures.set( geometry, entry ); + + function disposeTexture() { + + texture.dispose(); + + morphTextures.delete( geometry ); + + geometry.removeEventListener( 'dispose', disposeTexture ); + + } + + geometry.addEventListener( 'dispose', disposeTexture ); + + } + + // + if ( object.isInstancedMesh === true && object.morphTexture !== null ) { + + program.getUniforms().setValue( gl, 'morphTexture', object.morphTexture, textures ); + + } else { + + let morphInfluencesSum = 0; + + for ( let i = 0; i < objectInfluences.length; i ++ ) { + + morphInfluencesSum += objectInfluences[ i ]; + + } + + const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; + + + program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence ); + program.getUniforms().setValue( gl, 'morphTargetInfluences', objectInfluences ); + + } + + program.getUniforms().setValue( gl, 'morphTargetsTexture', entry.texture, textures ); + program.getUniforms().setValue( gl, 'morphTargetsTextureSize', entry.size ); + + } + + return { + + update: update + + }; + +} + +function WebGLObjects( gl, geometries, attributes, info ) { + + let updateMap = new WeakMap(); + + function update( object ) { + + const frame = info.render.frame; + + const geometry = object.geometry; + const buffergeometry = geometries.get( object, geometry ); + + // Update once per frame + + if ( updateMap.get( buffergeometry ) !== frame ) { + + geometries.update( buffergeometry ); + + updateMap.set( buffergeometry, frame ); + + } + + if ( object.isInstancedMesh ) { + + if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) { + + object.addEventListener( 'dispose', onInstancedMeshDispose ); + + } + + if ( updateMap.get( object ) !== frame ) { + + attributes.update( object.instanceMatrix, gl.ARRAY_BUFFER ); + + if ( object.instanceColor !== null ) { + + attributes.update( object.instanceColor, gl.ARRAY_BUFFER ); + + } + + updateMap.set( object, frame ); + + } + + } + + if ( object.isSkinnedMesh ) { + + const skeleton = object.skeleton; + + if ( updateMap.get( skeleton ) !== frame ) { + + skeleton.update(); + + updateMap.set( skeleton, frame ); + + } + + } + + return buffergeometry; + + } + + function dispose() { + + updateMap = new WeakMap(); + + } + + function onInstancedMeshDispose( event ) { + + const instancedMesh = event.target; + + instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose ); + + attributes.remove( instancedMesh.instanceMatrix ); + + if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor ); + + } + + return { + + update: update, + dispose: dispose + + }; + +} + +/** + * Uniforms of a program. + * Those form a tree structure with a special top-level container for the root, + * which you get by calling 'new WebGLUniforms( gl, program )'. + * + * + * Properties of inner nodes including the top-level container: + * + * .seq - array of nested uniforms + * .map - nested uniforms by name + * + * + * Methods of all nodes except the top-level container: + * + * .setValue( gl, value, [textures] ) + * + * uploads a uniform value(s) + * the 'textures' parameter is needed for sampler uniforms + * + * + * Static methods of the top-level container (textures factorizations): + * + * .upload( gl, seq, values, textures ) + * + * sets uniforms in 'seq' to 'values[id].value' + * + * .seqWithValue( seq, values ) : filteredSeq + * + * filters 'seq' entries with corresponding entry in values + * + * + * Methods of the top-level container (textures factorizations): + * + * .setValue( gl, name, value, textures ) + * + * sets uniform with name 'name' to 'value' + * + * .setOptional( gl, obj, prop ) + * + * like .set for an optional property of the object + * + */ + + +const emptyTexture = /*@__PURE__*/ new Texture(); + +const emptyShadowTexture = /*@__PURE__*/ new DepthTexture( 1, 1 ); + +const emptyArrayTexture = /*@__PURE__*/ new DataArrayTexture(); +const empty3dTexture = /*@__PURE__*/ new Data3DTexture(); +const emptyCubeTexture = /*@__PURE__*/ new CubeTexture(); + +// --- Utilities --- + +// Array Caches (provide typed arrays for temporary by size) + +const arrayCacheF32 = []; +const arrayCacheI32 = []; + +// Float32Array caches used for uploading Matrix uniforms + +const mat4array = new Float32Array( 16 ); +const mat3array = new Float32Array( 9 ); +const mat2array = new Float32Array( 4 ); + +// Flattening for arrays of vectors and matrices + +function flatten( array, nBlocks, blockSize ) { + + const firstElem = array[ 0 ]; + + if ( firstElem <= 0 || firstElem > 0 ) return array; + // unoptimized: ! isNaN( firstElem ) + // see http://jacksondunstan.com/articles/983 + + const n = nBlocks * blockSize; + let r = arrayCacheF32[ n ]; + + if ( r === undefined ) { + + r = new Float32Array( n ); + arrayCacheF32[ n ] = r; + + } + + if ( nBlocks !== 0 ) { + + firstElem.toArray( r, 0 ); + + for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) { + + offset += blockSize; + array[ i ].toArray( r, offset ); + + } + + } + + return r; + +} + +function arraysEqual( a, b ) { + + if ( a.length !== b.length ) return false; + + for ( let i = 0, l = a.length; i < l; i ++ ) { + + if ( a[ i ] !== b[ i ] ) return false; + + } + + return true; + +} + +function copyArray( a, b ) { + + for ( let i = 0, l = b.length; i < l; i ++ ) { + + a[ i ] = b[ i ]; + + } + +} + +// Texture unit allocation + +function allocTexUnits( textures, n ) { + + let r = arrayCacheI32[ n ]; + + if ( r === undefined ) { + + r = new Int32Array( n ); + arrayCacheI32[ n ] = r; + + } + + for ( let i = 0; i !== n; ++ i ) { + + r[ i ] = textures.allocateTextureUnit(); + + } + + return r; + +} + +// --- Setters --- + +// Note: Defining these methods externally, because they come in a bunch +// and this way their names minify. + +// Single scalar + +function setValueV1f( gl, v ) { + + const cache = this.cache; + + if ( cache[ 0 ] === v ) return; + + gl.uniform1f( this.addr, v ); + + cache[ 0 ] = v; + +} + +// Single float vector (from flat array or THREE.VectorN) + +function setValueV2f( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) { + + gl.uniform2f( this.addr, v.x, v.y ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform2fv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +function setValueV3f( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) { + + gl.uniform3f( this.addr, v.x, v.y, v.z ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + + } + + } else if ( v.r !== undefined ) { + + if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) { + + gl.uniform3f( this.addr, v.r, v.g, v.b ); + + cache[ 0 ] = v.r; + cache[ 1 ] = v.g; + cache[ 2 ] = v.b; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform3fv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +function setValueV4f( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) { + + gl.uniform4f( this.addr, v.x, v.y, v.z, v.w ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + cache[ 3 ] = v.w; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform4fv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +// Single matrix (from flat array or THREE.MatrixN) + +function setValueM2( gl, v ) { + + const cache = this.cache; + const elements = v.elements; + + if ( elements === undefined ) { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniformMatrix2fv( this.addr, false, v ); + + copyArray( cache, v ); + + } else { + + if ( arraysEqual( cache, elements ) ) return; + + mat2array.set( elements ); + + gl.uniformMatrix2fv( this.addr, false, mat2array ); + + copyArray( cache, elements ); + + } + +} + +function setValueM3( gl, v ) { + + const cache = this.cache; + const elements = v.elements; + + if ( elements === undefined ) { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniformMatrix3fv( this.addr, false, v ); + + copyArray( cache, v ); + + } else { + + if ( arraysEqual( cache, elements ) ) return; + + mat3array.set( elements ); + + gl.uniformMatrix3fv( this.addr, false, mat3array ); + + copyArray( cache, elements ); + + } + +} + +function setValueM4( gl, v ) { + + const cache = this.cache; + const elements = v.elements; + + if ( elements === undefined ) { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniformMatrix4fv( this.addr, false, v ); + + copyArray( cache, v ); + + } else { + + if ( arraysEqual( cache, elements ) ) return; + + mat4array.set( elements ); + + gl.uniformMatrix4fv( this.addr, false, mat4array ); + + copyArray( cache, elements ); + + } + +} + +// Single integer / boolean + +function setValueV1i( gl, v ) { + + const cache = this.cache; + + if ( cache[ 0 ] === v ) return; + + gl.uniform1i( this.addr, v ); + + cache[ 0 ] = v; + +} + +// Single integer / boolean vector (from flat array or THREE.VectorN) + +function setValueV2i( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) { + + gl.uniform2i( this.addr, v.x, v.y ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform2iv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +function setValueV3i( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) { + + gl.uniform3i( this.addr, v.x, v.y, v.z ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform3iv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +function setValueV4i( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) { + + gl.uniform4i( this.addr, v.x, v.y, v.z, v.w ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + cache[ 3 ] = v.w; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform4iv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +// Single unsigned integer + +function setValueV1ui( gl, v ) { + + const cache = this.cache; + + if ( cache[ 0 ] === v ) return; + + gl.uniform1ui( this.addr, v ); + + cache[ 0 ] = v; + +} + +// Single unsigned integer vector (from flat array or THREE.VectorN) + +function setValueV2ui( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) { + + gl.uniform2ui( this.addr, v.x, v.y ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform2uiv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +function setValueV3ui( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) { + + gl.uniform3ui( this.addr, v.x, v.y, v.z ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform3uiv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + +function setValueV4ui( gl, v ) { + + const cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) { + + gl.uniform4ui( this.addr, v.x, v.y, v.z, v.w ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + cache[ 3 ] = v.w; + + } + + } else { + + if ( arraysEqual( cache, v ) ) return; + + gl.uniform4uiv( this.addr, v ); + + copyArray( cache, v ); + + } + +} + + +// Single texture (2D / Cube) + +function setValueT1( gl, v, textures ) { + + const cache = this.cache; + const unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + let emptyTexture2D; + + if ( this.type === gl.SAMPLER_2D_SHADOW ) { + + emptyShadowTexture.compareFunction = LessEqualCompare; // #28670 + emptyTexture2D = emptyShadowTexture; + + } else { + + emptyTexture2D = emptyTexture; + + } + + textures.setTexture2D( v || emptyTexture2D, unit ); + +} + +function setValueT3D1( gl, v, textures ) { + + const cache = this.cache; + const unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.setTexture3D( v || empty3dTexture, unit ); + +} + +function setValueT6( gl, v, textures ) { + + const cache = this.cache; + const unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.setTextureCube( v || emptyCubeTexture, unit ); + +} + +function setValueT2DArray1( gl, v, textures ) { + + const cache = this.cache; + const unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.setTexture2DArray( v || emptyArrayTexture, unit ); + +} + +// Helper to pick the right setter for the singular case + +function getSingularSetter( type ) { + + switch ( type ) { + + case 0x1406: return setValueV1f; // FLOAT + case 0x8b50: return setValueV2f; // _VEC2 + case 0x8b51: return setValueV3f; // _VEC3 + case 0x8b52: return setValueV4f; // _VEC4 + + case 0x8b5a: return setValueM2; // _MAT2 + case 0x8b5b: return setValueM3; // _MAT3 + case 0x8b5c: return setValueM4; // _MAT4 + + case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL + case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2 + case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3 + case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4 + + case 0x1405: return setValueV1ui; // UINT + case 0x8dc6: return setValueV2ui; // _VEC2 + case 0x8dc7: return setValueV3ui; // _VEC3 + case 0x8dc8: return setValueV4ui; // _VEC4 + + case 0x8b5e: // SAMPLER_2D + case 0x8d66: // SAMPLER_EXTERNAL_OES + case 0x8dca: // INT_SAMPLER_2D + case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D + case 0x8b62: // SAMPLER_2D_SHADOW + return setValueT1; + + case 0x8b5f: // SAMPLER_3D + case 0x8dcb: // INT_SAMPLER_3D + case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D + return setValueT3D1; + + case 0x8b60: // SAMPLER_CUBE + case 0x8dcc: // INT_SAMPLER_CUBE + case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE + case 0x8dc5: // SAMPLER_CUBE_SHADOW + return setValueT6; + + case 0x8dc1: // SAMPLER_2D_ARRAY + case 0x8dcf: // INT_SAMPLER_2D_ARRAY + case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY + case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW + return setValueT2DArray1; + + } + +} + + +// Array of scalars + +function setValueV1fArray( gl, v ) { + + gl.uniform1fv( this.addr, v ); + +} + +// Array of vectors (from flat array or array of THREE.VectorN) + +function setValueV2fArray( gl, v ) { + + const data = flatten( v, this.size, 2 ); + + gl.uniform2fv( this.addr, data ); + +} + +function setValueV3fArray( gl, v ) { + + const data = flatten( v, this.size, 3 ); + + gl.uniform3fv( this.addr, data ); + +} + +function setValueV4fArray( gl, v ) { + + const data = flatten( v, this.size, 4 ); + + gl.uniform4fv( this.addr, data ); + +} + +// Array of matrices (from flat array or array of THREE.MatrixN) + +function setValueM2Array( gl, v ) { + + const data = flatten( v, this.size, 4 ); + + gl.uniformMatrix2fv( this.addr, false, data ); + +} + +function setValueM3Array( gl, v ) { + + const data = flatten( v, this.size, 9 ); + + gl.uniformMatrix3fv( this.addr, false, data ); + +} + +function setValueM4Array( gl, v ) { + + const data = flatten( v, this.size, 16 ); + + gl.uniformMatrix4fv( this.addr, false, data ); + +} + +// Array of integer / boolean + +function setValueV1iArray( gl, v ) { + + gl.uniform1iv( this.addr, v ); + +} + +// Array of integer / boolean vectors (from flat array) + +function setValueV2iArray( gl, v ) { + + gl.uniform2iv( this.addr, v ); + +} + +function setValueV3iArray( gl, v ) { + + gl.uniform3iv( this.addr, v ); + +} + +function setValueV4iArray( gl, v ) { + + gl.uniform4iv( this.addr, v ); + +} + +// Array of unsigned integer + +function setValueV1uiArray( gl, v ) { + + gl.uniform1uiv( this.addr, v ); + +} + +// Array of unsigned integer vectors (from flat array) + +function setValueV2uiArray( gl, v ) { + + gl.uniform2uiv( this.addr, v ); + +} + +function setValueV3uiArray( gl, v ) { + + gl.uniform3uiv( this.addr, v ); + +} + +function setValueV4uiArray( gl, v ) { + + gl.uniform4uiv( this.addr, v ); + +} + + +// Array of textures (2D / 3D / Cube / 2DArray) + +function setValueT1Array( gl, v, textures ) { + + const cache = this.cache; + + const n = v.length; + + const units = allocTexUnits( textures, n ); + + if ( ! arraysEqual( cache, units ) ) { + + gl.uniform1iv( this.addr, units ); + + copyArray( cache, units ); + + } + + for ( let i = 0; i !== n; ++ i ) { + + textures.setTexture2D( v[ i ] || emptyTexture, units[ i ] ); + + } + +} + +function setValueT3DArray( gl, v, textures ) { + + const cache = this.cache; + + const n = v.length; + + const units = allocTexUnits( textures, n ); + + if ( ! arraysEqual( cache, units ) ) { + + gl.uniform1iv( this.addr, units ); + + copyArray( cache, units ); + + } + + for ( let i = 0; i !== n; ++ i ) { + + textures.setTexture3D( v[ i ] || empty3dTexture, units[ i ] ); + + } + +} + +function setValueT6Array( gl, v, textures ) { + + const cache = this.cache; + + const n = v.length; + + const units = allocTexUnits( textures, n ); + + if ( ! arraysEqual( cache, units ) ) { + + gl.uniform1iv( this.addr, units ); + + copyArray( cache, units ); + + } + + for ( let i = 0; i !== n; ++ i ) { + + textures.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] ); + + } + +} + +function setValueT2DArrayArray( gl, v, textures ) { + + const cache = this.cache; + + const n = v.length; + + const units = allocTexUnits( textures, n ); + + if ( ! arraysEqual( cache, units ) ) { + + gl.uniform1iv( this.addr, units ); + + copyArray( cache, units ); + + } + + for ( let i = 0; i !== n; ++ i ) { + + textures.setTexture2DArray( v[ i ] || emptyArrayTexture, units[ i ] ); + + } + +} + + +// Helper to pick the right setter for a pure (bottom-level) array + +function getPureArraySetter( type ) { + + switch ( type ) { + + case 0x1406: return setValueV1fArray; // FLOAT + case 0x8b50: return setValueV2fArray; // _VEC2 + case 0x8b51: return setValueV3fArray; // _VEC3 + case 0x8b52: return setValueV4fArray; // _VEC4 + + case 0x8b5a: return setValueM2Array; // _MAT2 + case 0x8b5b: return setValueM3Array; // _MAT3 + case 0x8b5c: return setValueM4Array; // _MAT4 + + case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL + case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2 + case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3 + case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4 + + case 0x1405: return setValueV1uiArray; // UINT + case 0x8dc6: return setValueV2uiArray; // _VEC2 + case 0x8dc7: return setValueV3uiArray; // _VEC3 + case 0x8dc8: return setValueV4uiArray; // _VEC4 + + case 0x8b5e: // SAMPLER_2D + case 0x8d66: // SAMPLER_EXTERNAL_OES + case 0x8dca: // INT_SAMPLER_2D + case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D + case 0x8b62: // SAMPLER_2D_SHADOW + return setValueT1Array; + + case 0x8b5f: // SAMPLER_3D + case 0x8dcb: // INT_SAMPLER_3D + case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D + return setValueT3DArray; + + case 0x8b60: // SAMPLER_CUBE + case 0x8dcc: // INT_SAMPLER_CUBE + case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE + case 0x8dc5: // SAMPLER_CUBE_SHADOW + return setValueT6Array; + + case 0x8dc1: // SAMPLER_2D_ARRAY + case 0x8dcf: // INT_SAMPLER_2D_ARRAY + case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY + case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW + return setValueT2DArrayArray; + + } + +} + +// --- Uniform Classes --- + +class SingleUniform { + + constructor( id, activeInfo, addr ) { + + this.id = id; + this.addr = addr; + this.cache = []; + this.type = activeInfo.type; + this.setValue = getSingularSetter( activeInfo.type ); + + // this.path = activeInfo.name; // DEBUG + + } + +} + +class PureArrayUniform { + + constructor( id, activeInfo, addr ) { + + this.id = id; + this.addr = addr; + this.cache = []; + this.type = activeInfo.type; + this.size = activeInfo.size; + this.setValue = getPureArraySetter( activeInfo.type ); + + // this.path = activeInfo.name; // DEBUG + + } + +} + +class StructuredUniform { + + constructor( id ) { + + this.id = id; + + this.seq = []; + this.map = {}; + + } + + setValue( gl, value, textures ) { + + const seq = this.seq; + + for ( let i = 0, n = seq.length; i !== n; ++ i ) { + + const u = seq[ i ]; + u.setValue( gl, value[ u.id ], textures ); + + } + + } + +} + +// --- Top-level --- + +// Parser - builds up the property tree from the path strings + +const RePathPart = /(\w+)(\])?(\[|\.)?/g; + +// extracts +// - the identifier (member name or array index) +// - followed by an optional right bracket (found when array index) +// - followed by an optional left bracket or dot (type of subscript) +// +// Note: These portions can be read in a non-overlapping fashion and +// allow straightforward parsing of the hierarchy that WebGL encodes +// in the uniform names. + +function addUniform( container, uniformObject ) { + + container.seq.push( uniformObject ); + container.map[ uniformObject.id ] = uniformObject; + +} + +function parseUniform( activeInfo, addr, container ) { + + const path = activeInfo.name, + pathLength = path.length; + + // reset RegExp object, because of the early exit of a previous run + RePathPart.lastIndex = 0; + + while ( true ) { + + const match = RePathPart.exec( path ), + matchEnd = RePathPart.lastIndex; + + let id = match[ 1 ]; + const idIsIndex = match[ 2 ] === ']', + subscript = match[ 3 ]; + + if ( idIsIndex ) id = id | 0; // convert to integer + + if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) { + + // bare name or "pure" bottom-level array "[0]" suffix + + addUniform( container, subscript === undefined ? + new SingleUniform( id, activeInfo, addr ) : + new PureArrayUniform( id, activeInfo, addr ) ); + + break; + + } else { + + // step into inner node / create it in case it doesn't exist + + const map = container.map; + let next = map[ id ]; + + if ( next === undefined ) { + + next = new StructuredUniform( id ); + addUniform( container, next ); + + } + + container = next; + + } + + } + +} + +// Root Container + +class WebGLUniforms { + + constructor( gl, program ) { + + this.seq = []; + this.map = {}; + + const n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS ); + + for ( let i = 0; i < n; ++ i ) { + + const info = gl.getActiveUniform( program, i ), + addr = gl.getUniformLocation( program, info.name ); + + parseUniform( info, addr, this ); + + } + + } + + setValue( gl, name, value, textures ) { + + const u = this.map[ name ]; + + if ( u !== undefined ) u.setValue( gl, value, textures ); + + } + + setOptional( gl, object, name ) { + + const v = object[ name ]; + + if ( v !== undefined ) this.setValue( gl, name, v ); + + } + + static upload( gl, seq, values, textures ) { + + for ( let i = 0, n = seq.length; i !== n; ++ i ) { + + const u = seq[ i ], + v = values[ u.id ]; + + if ( v.needsUpdate !== false ) { + + // note: always updating when .needsUpdate is undefined + u.setValue( gl, v.value, textures ); + + } + + } + + } + + static seqWithValue( seq, values ) { + + const r = []; + + for ( let i = 0, n = seq.length; i !== n; ++ i ) { + + const u = seq[ i ]; + if ( u.id in values ) r.push( u ); + + } + + return r; + + } + +} + +function WebGLShader( gl, type, string ) { + + const shader = gl.createShader( type ); + + gl.shaderSource( shader, string ); + gl.compileShader( shader ); + + return shader; + +} + +// From https://www.khronos.org/registry/webgl/extensions/KHR_parallel_shader_compile/ +const COMPLETION_STATUS_KHR = 0x91B1; + +let programIdCount = 0; + +function handleSource( string, errorLine ) { + + const lines = string.split( '\n' ); + const lines2 = []; + + const from = Math.max( errorLine - 6, 0 ); + const to = Math.min( errorLine + 6, lines.length ); + + for ( let i = from; i < to; i ++ ) { + + const line = i + 1; + lines2.push( `${line === errorLine ? '>' : ' '} ${line}: ${lines[ i ]}` ); + + } + + return lines2.join( '\n' ); + +} + +const _m0 = /*@__PURE__*/ new Matrix3(); + +function getEncodingComponents( colorSpace ) { + + ColorManagement._getMatrix( _m0, ColorManagement.workingColorSpace, colorSpace ); + + const encodingMatrix = `mat3( ${ _m0.elements.map( ( v ) => v.toFixed( 4 ) ) } )`; + + switch ( ColorManagement.getTransfer( colorSpace ) ) { + + case LinearTransfer: + return [ encodingMatrix, 'LinearTransferOETF' ]; + + case SRGBTransfer: + return [ encodingMatrix, 'sRGBTransferOETF' ]; + + default: + console.warn( 'THREE.WebGLProgram: Unsupported color space: ', colorSpace ); + return [ encodingMatrix, 'LinearTransferOETF' ]; + + } + +} + +function getShaderErrors( gl, shader, type ) { + + const status = gl.getShaderParameter( shader, gl.COMPILE_STATUS ); + const errors = gl.getShaderInfoLog( shader ).trim(); + + if ( status && errors === '' ) return ''; + + const errorMatches = /ERROR: 0:(\d+)/.exec( errors ); + if ( errorMatches ) { + + // --enable-privileged-webgl-extension + // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) ); + + const errorLine = parseInt( errorMatches[ 1 ] ); + return type.toUpperCase() + '\n\n' + errors + '\n\n' + handleSource( gl.getShaderSource( shader ), errorLine ); + + } else { + + return errors; + + } + +} + +function getTexelEncodingFunction( functionName, colorSpace ) { + + const components = getEncodingComponents( colorSpace ); + + return [ + + `vec4 ${functionName}( vec4 value ) {`, + + ` return ${components[ 1 ]}( vec4( value.rgb * ${components[ 0 ]}, value.a ) );`, + + '}', + + ].join( '\n' ); + +} + +function getToneMappingFunction( functionName, toneMapping ) { + + let toneMappingName; + + switch ( toneMapping ) { + + case LinearToneMapping: + toneMappingName = 'Linear'; + break; + + case ReinhardToneMapping: + toneMappingName = 'Reinhard'; + break; + + case CineonToneMapping: + toneMappingName = 'Cineon'; + break; + + case ACESFilmicToneMapping: + toneMappingName = 'ACESFilmic'; + break; + + case AgXToneMapping: + toneMappingName = 'AgX'; + break; + + case NeutralToneMapping: + toneMappingName = 'Neutral'; + break; + + case CustomToneMapping: + toneMappingName = 'Custom'; + break; + + default: + console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping ); + toneMappingName = 'Linear'; + + } + + return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }'; + +} + +const _v0 = /*@__PURE__*/ new Vector3(); + +function getLuminanceFunction() { + + ColorManagement.getLuminanceCoefficients( _v0 ); + + const r = _v0.x.toFixed( 4 ); + const g = _v0.y.toFixed( 4 ); + const b = _v0.z.toFixed( 4 ); + + return [ + + 'float luminance( const in vec3 rgb ) {', + + ` const vec3 weights = vec3( ${ r }, ${ g }, ${ b } );`, + + ' return dot( weights, rgb );', + + '}' + + ].join( '\n' ); + +} + +function generateVertexExtensions( parameters ) { + + const chunks = [ + parameters.extensionClipCullDistance ? '#extension GL_ANGLE_clip_cull_distance : require' : '', + parameters.extensionMultiDraw ? '#extension GL_ANGLE_multi_draw : require' : '', + ]; + + return chunks.filter( filterEmptyLine ).join( '\n' ); + +} + +function generateDefines( defines ) { + + const chunks = []; + + for ( const name in defines ) { + + const value = defines[ name ]; + + if ( value === false ) continue; + + chunks.push( '#define ' + name + ' ' + value ); + + } + + return chunks.join( '\n' ); + +} + +function fetchAttributeLocations( gl, program ) { + + const attributes = {}; + + const n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES ); + + for ( let i = 0; i < n; i ++ ) { + + const info = gl.getActiveAttrib( program, i ); + const name = info.name; + + let locationSize = 1; + if ( info.type === gl.FLOAT_MAT2 ) locationSize = 2; + if ( info.type === gl.FLOAT_MAT3 ) locationSize = 3; + if ( info.type === gl.FLOAT_MAT4 ) locationSize = 4; + + // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i ); + + attributes[ name ] = { + type: info.type, + location: gl.getAttribLocation( program, name ), + locationSize: locationSize + }; + + } + + return attributes; + +} + +function filterEmptyLine( string ) { + + return string !== ''; + +} + +function replaceLightNums( string, parameters ) { + + const numSpotLightCoords = parameters.numSpotLightShadows + parameters.numSpotLightMaps - parameters.numSpotLightShadowsWithMaps; + + return string + .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights ) + .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights ) + .replace( /NUM_SPOT_LIGHT_MAPS/g, parameters.numSpotLightMaps ) + .replace( /NUM_SPOT_LIGHT_COORDS/g, numSpotLightCoords ) + .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights ) + .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights ) + .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights ) + .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows ) + .replace( /NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, parameters.numSpotLightShadowsWithMaps ) + .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows ) + .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows ); + +} + +function replaceClippingPlaneNums( string, parameters ) { + + return string + .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes ) + .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) ); + +} + +// Resolve Includes + +const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm; + +function resolveIncludes( string ) { + + return string.replace( includePattern, includeReplacer ); + +} + +const shaderChunkMap = new Map(); + +function includeReplacer( match, include ) { + + let string = ShaderChunk[ include ]; + + if ( string === undefined ) { + + const newInclude = shaderChunkMap.get( include ); + + if ( newInclude !== undefined ) { + + string = ShaderChunk[ newInclude ]; + console.warn( 'THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.', include, newInclude ); + + } else { + + throw new Error( 'Can not resolve #include <' + include + '>' ); + + } + + } + + return resolveIncludes( string ); + +} + +// Unroll Loops + +const unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g; + +function unrollLoops( string ) { + + return string.replace( unrollLoopPattern, loopReplacer ); + +} + +function loopReplacer( match, start, end, snippet ) { + + let string = ''; + + for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) { + + string += snippet + .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' ) + .replace( /UNROLLED_LOOP_INDEX/g, i ); + + } + + return string; + +} + +// + +function generatePrecision( parameters ) { + + let precisionstring = `precision ${parameters.precision} float; + precision ${parameters.precision} int; + precision ${parameters.precision} sampler2D; + precision ${parameters.precision} samplerCube; + precision ${parameters.precision} sampler3D; + precision ${parameters.precision} sampler2DArray; + precision ${parameters.precision} sampler2DShadow; + precision ${parameters.precision} samplerCubeShadow; + precision ${parameters.precision} sampler2DArrayShadow; + precision ${parameters.precision} isampler2D; + precision ${parameters.precision} isampler3D; + precision ${parameters.precision} isamplerCube; + precision ${parameters.precision} isampler2DArray; + precision ${parameters.precision} usampler2D; + precision ${parameters.precision} usampler3D; + precision ${parameters.precision} usamplerCube; + precision ${parameters.precision} usampler2DArray; + `; + + if ( parameters.precision === 'highp' ) { + + precisionstring += '\n#define HIGH_PRECISION'; + + } else if ( parameters.precision === 'mediump' ) { + + precisionstring += '\n#define MEDIUM_PRECISION'; + + } else if ( parameters.precision === 'lowp' ) { + + precisionstring += '\n#define LOW_PRECISION'; + + } + + return precisionstring; + +} + +function generateShadowMapTypeDefine( parameters ) { + + let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC'; + + if ( parameters.shadowMapType === PCFShadowMap ) { + + shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF'; + + } else if ( parameters.shadowMapType === PCFSoftShadowMap ) { + + shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT'; + + } else if ( parameters.shadowMapType === VSMShadowMap ) { + + shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM'; + + } + + return shadowMapTypeDefine; + +} + +function generateEnvMapTypeDefine( parameters ) { + + let envMapTypeDefine = 'ENVMAP_TYPE_CUBE'; + + if ( parameters.envMap ) { + + switch ( parameters.envMapMode ) { + + case CubeReflectionMapping: + case CubeRefractionMapping: + envMapTypeDefine = 'ENVMAP_TYPE_CUBE'; + break; + + case CubeUVReflectionMapping: + envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV'; + break; + + } + + } + + return envMapTypeDefine; + +} + +function generateEnvMapModeDefine( parameters ) { + + let envMapModeDefine = 'ENVMAP_MODE_REFLECTION'; + + if ( parameters.envMap ) { + + switch ( parameters.envMapMode ) { + + case CubeRefractionMapping: + + envMapModeDefine = 'ENVMAP_MODE_REFRACTION'; + break; + + } + + } + + return envMapModeDefine; + +} + +function generateEnvMapBlendingDefine( parameters ) { + + let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE'; + + if ( parameters.envMap ) { + + switch ( parameters.combine ) { + + case MultiplyOperation: + envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY'; + break; + + case MixOperation: + envMapBlendingDefine = 'ENVMAP_BLENDING_MIX'; + break; + + case AddOperation: + envMapBlendingDefine = 'ENVMAP_BLENDING_ADD'; + break; + + } + + } + + return envMapBlendingDefine; + +} + +function generateCubeUVSize( parameters ) { + + const imageHeight = parameters.envMapCubeUVHeight; + + if ( imageHeight === null ) return null; + + const maxMip = Math.log2( imageHeight ) - 2; + + const texelHeight = 1.0 / imageHeight; + + const texelWidth = 1.0 / ( 3 * Math.max( Math.pow( 2, maxMip ), 7 * 16 ) ); + + return { texelWidth, texelHeight, maxMip }; + +} + +function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { + + // TODO Send this event to Three.js DevTools + // console.log( 'WebGLProgram', cacheKey ); + + const gl = renderer.getContext(); + + const defines = parameters.defines; + + let vertexShader = parameters.vertexShader; + let fragmentShader = parameters.fragmentShader; + + const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters ); + const envMapTypeDefine = generateEnvMapTypeDefine( parameters ); + const envMapModeDefine = generateEnvMapModeDefine( parameters ); + const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters ); + const envMapCubeUVSize = generateCubeUVSize( parameters ); + + const customVertexExtensions = generateVertexExtensions( parameters ); + + const customDefines = generateDefines( defines ); + + const program = gl.createProgram(); + + let prefixVertex, prefixFragment; + let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : ''; + + if ( parameters.isRawShaderMaterial ) { + + prefixVertex = [ + + '#define SHADER_TYPE ' + parameters.shaderType, + '#define SHADER_NAME ' + parameters.shaderName, + + customDefines + + ].filter( filterEmptyLine ).join( '\n' ); + + if ( prefixVertex.length > 0 ) { + + prefixVertex += '\n'; + + } + + prefixFragment = [ + + '#define SHADER_TYPE ' + parameters.shaderType, + '#define SHADER_NAME ' + parameters.shaderName, + + customDefines + + ].filter( filterEmptyLine ).join( '\n' ); + + if ( prefixFragment.length > 0 ) { + + prefixFragment += '\n'; + + } + + } else { + + prefixVertex = [ + + generatePrecision( parameters ), + + '#define SHADER_TYPE ' + parameters.shaderType, + '#define SHADER_NAME ' + parameters.shaderName, + + customDefines, + + parameters.extensionClipCullDistance ? '#define USE_CLIP_DISTANCE' : '', + parameters.batching ? '#define USE_BATCHING' : '', + parameters.batchingColor ? '#define USE_BATCHING_COLOR' : '', + parameters.instancing ? '#define USE_INSTANCING' : '', + parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '', + parameters.instancingMorph ? '#define USE_INSTANCING_MORPH' : '', + + parameters.useFog && parameters.fog ? '#define USE_FOG' : '', + parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', + + parameters.map ? '#define USE_MAP' : '', + parameters.envMap ? '#define USE_ENVMAP' : '', + parameters.envMap ? '#define ' + envMapModeDefine : '', + parameters.lightMap ? '#define USE_LIGHTMAP' : '', + parameters.aoMap ? '#define USE_AOMAP' : '', + parameters.bumpMap ? '#define USE_BUMPMAP' : '', + parameters.normalMap ? '#define USE_NORMALMAP' : '', + parameters.normalMapObjectSpace ? '#define USE_NORMALMAP_OBJECTSPACE' : '', + parameters.normalMapTangentSpace ? '#define USE_NORMALMAP_TANGENTSPACE' : '', + parameters.displacementMap ? '#define USE_DISPLACEMENTMAP' : '', + parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', + + parameters.anisotropy ? '#define USE_ANISOTROPY' : '', + parameters.anisotropyMap ? '#define USE_ANISOTROPYMAP' : '', + + parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', + parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', + parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', + + parameters.iridescenceMap ? '#define USE_IRIDESCENCEMAP' : '', + parameters.iridescenceThicknessMap ? '#define USE_IRIDESCENCE_THICKNESSMAP' : '', + + parameters.specularMap ? '#define USE_SPECULARMAP' : '', + parameters.specularColorMap ? '#define USE_SPECULAR_COLORMAP' : '', + parameters.specularIntensityMap ? '#define USE_SPECULAR_INTENSITYMAP' : '', + + parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', + parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', + parameters.alphaMap ? '#define USE_ALPHAMAP' : '', + parameters.alphaHash ? '#define USE_ALPHAHASH' : '', + + parameters.transmission ? '#define USE_TRANSMISSION' : '', + parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', + parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '', + + parameters.sheenColorMap ? '#define USE_SHEEN_COLORMAP' : '', + parameters.sheenRoughnessMap ? '#define USE_SHEEN_ROUGHNESSMAP' : '', + + // + + parameters.mapUv ? '#define MAP_UV ' + parameters.mapUv : '', + parameters.alphaMapUv ? '#define ALPHAMAP_UV ' + parameters.alphaMapUv : '', + parameters.lightMapUv ? '#define LIGHTMAP_UV ' + parameters.lightMapUv : '', + parameters.aoMapUv ? '#define AOMAP_UV ' + parameters.aoMapUv : '', + parameters.emissiveMapUv ? '#define EMISSIVEMAP_UV ' + parameters.emissiveMapUv : '', + parameters.bumpMapUv ? '#define BUMPMAP_UV ' + parameters.bumpMapUv : '', + parameters.normalMapUv ? '#define NORMALMAP_UV ' + parameters.normalMapUv : '', + parameters.displacementMapUv ? '#define DISPLACEMENTMAP_UV ' + parameters.displacementMapUv : '', + + parameters.metalnessMapUv ? '#define METALNESSMAP_UV ' + parameters.metalnessMapUv : '', + parameters.roughnessMapUv ? '#define ROUGHNESSMAP_UV ' + parameters.roughnessMapUv : '', + + parameters.anisotropyMapUv ? '#define ANISOTROPYMAP_UV ' + parameters.anisotropyMapUv : '', + + parameters.clearcoatMapUv ? '#define CLEARCOATMAP_UV ' + parameters.clearcoatMapUv : '', + parameters.clearcoatNormalMapUv ? '#define CLEARCOAT_NORMALMAP_UV ' + parameters.clearcoatNormalMapUv : '', + parameters.clearcoatRoughnessMapUv ? '#define CLEARCOAT_ROUGHNESSMAP_UV ' + parameters.clearcoatRoughnessMapUv : '', + + parameters.iridescenceMapUv ? '#define IRIDESCENCEMAP_UV ' + parameters.iridescenceMapUv : '', + parameters.iridescenceThicknessMapUv ? '#define IRIDESCENCE_THICKNESSMAP_UV ' + parameters.iridescenceThicknessMapUv : '', + + parameters.sheenColorMapUv ? '#define SHEEN_COLORMAP_UV ' + parameters.sheenColorMapUv : '', + parameters.sheenRoughnessMapUv ? '#define SHEEN_ROUGHNESSMAP_UV ' + parameters.sheenRoughnessMapUv : '', + + parameters.specularMapUv ? '#define SPECULARMAP_UV ' + parameters.specularMapUv : '', + parameters.specularColorMapUv ? '#define SPECULAR_COLORMAP_UV ' + parameters.specularColorMapUv : '', + parameters.specularIntensityMapUv ? '#define SPECULAR_INTENSITYMAP_UV ' + parameters.specularIntensityMapUv : '', + + parameters.transmissionMapUv ? '#define TRANSMISSIONMAP_UV ' + parameters.transmissionMapUv : '', + parameters.thicknessMapUv ? '#define THICKNESSMAP_UV ' + parameters.thicknessMapUv : '', + + // + + parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '', + parameters.vertexColors ? '#define USE_COLOR' : '', + parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', + parameters.vertexUv1s ? '#define USE_UV1' : '', + parameters.vertexUv2s ? '#define USE_UV2' : '', + parameters.vertexUv3s ? '#define USE_UV3' : '', + + parameters.pointsUvs ? '#define USE_POINTS_UV' : '', + + parameters.flatShading ? '#define FLAT_SHADED' : '', + + parameters.skinning ? '#define USE_SKINNING' : '', + + parameters.morphTargets ? '#define USE_MORPHTARGETS' : '', + parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '', + ( parameters.morphColors ) ? '#define USE_MORPHCOLORS' : '', + ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_TEXTURE_STRIDE ' + parameters.morphTextureStride : '', + ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_COUNT ' + parameters.morphTargetsCount : '', + parameters.doubleSided ? '#define DOUBLE_SIDED' : '', + parameters.flipSided ? '#define FLIP_SIDED' : '', + + parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', + parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', + + parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '', + + parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '', + + parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', + parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '', + + 'uniform mat4 modelMatrix;', + 'uniform mat4 modelViewMatrix;', + 'uniform mat4 projectionMatrix;', + 'uniform mat4 viewMatrix;', + 'uniform mat3 normalMatrix;', + 'uniform vec3 cameraPosition;', + 'uniform bool isOrthographic;', + + '#ifdef USE_INSTANCING', + + ' attribute mat4 instanceMatrix;', + + '#endif', + + '#ifdef USE_INSTANCING_COLOR', + + ' attribute vec3 instanceColor;', + + '#endif', + + '#ifdef USE_INSTANCING_MORPH', + + ' uniform sampler2D morphTexture;', + + '#endif', + + 'attribute vec3 position;', + 'attribute vec3 normal;', + 'attribute vec2 uv;', + + '#ifdef USE_UV1', + + ' attribute vec2 uv1;', + + '#endif', + + '#ifdef USE_UV2', + + ' attribute vec2 uv2;', + + '#endif', + + '#ifdef USE_UV3', + + ' attribute vec2 uv3;', + + '#endif', + + '#ifdef USE_TANGENT', + + ' attribute vec4 tangent;', + + '#endif', + + '#if defined( USE_COLOR_ALPHA )', + + ' attribute vec4 color;', + + '#elif defined( USE_COLOR )', + + ' attribute vec3 color;', + + '#endif', + + '#ifdef USE_SKINNING', + + ' attribute vec4 skinIndex;', + ' attribute vec4 skinWeight;', + + '#endif', + + '\n' + + ].filter( filterEmptyLine ).join( '\n' ); + + prefixFragment = [ + + generatePrecision( parameters ), + + '#define SHADER_TYPE ' + parameters.shaderType, + '#define SHADER_NAME ' + parameters.shaderName, + + customDefines, + + parameters.useFog && parameters.fog ? '#define USE_FOG' : '', + parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', + + parameters.alphaToCoverage ? '#define ALPHA_TO_COVERAGE' : '', + parameters.map ? '#define USE_MAP' : '', + parameters.matcap ? '#define USE_MATCAP' : '', + parameters.envMap ? '#define USE_ENVMAP' : '', + parameters.envMap ? '#define ' + envMapTypeDefine : '', + parameters.envMap ? '#define ' + envMapModeDefine : '', + parameters.envMap ? '#define ' + envMapBlendingDefine : '', + envMapCubeUVSize ? '#define CUBEUV_TEXEL_WIDTH ' + envMapCubeUVSize.texelWidth : '', + envMapCubeUVSize ? '#define CUBEUV_TEXEL_HEIGHT ' + envMapCubeUVSize.texelHeight : '', + envMapCubeUVSize ? '#define CUBEUV_MAX_MIP ' + envMapCubeUVSize.maxMip + '.0' : '', + parameters.lightMap ? '#define USE_LIGHTMAP' : '', + parameters.aoMap ? '#define USE_AOMAP' : '', + parameters.bumpMap ? '#define USE_BUMPMAP' : '', + parameters.normalMap ? '#define USE_NORMALMAP' : '', + parameters.normalMapObjectSpace ? '#define USE_NORMALMAP_OBJECTSPACE' : '', + parameters.normalMapTangentSpace ? '#define USE_NORMALMAP_TANGENTSPACE' : '', + parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', + + parameters.anisotropy ? '#define USE_ANISOTROPY' : '', + parameters.anisotropyMap ? '#define USE_ANISOTROPYMAP' : '', + + parameters.clearcoat ? '#define USE_CLEARCOAT' : '', + parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', + parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', + parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', + + parameters.dispersion ? '#define USE_DISPERSION' : '', + + parameters.iridescence ? '#define USE_IRIDESCENCE' : '', + parameters.iridescenceMap ? '#define USE_IRIDESCENCEMAP' : '', + parameters.iridescenceThicknessMap ? '#define USE_IRIDESCENCE_THICKNESSMAP' : '', + + parameters.specularMap ? '#define USE_SPECULARMAP' : '', + parameters.specularColorMap ? '#define USE_SPECULAR_COLORMAP' : '', + parameters.specularIntensityMap ? '#define USE_SPECULAR_INTENSITYMAP' : '', + + parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', + parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', + + parameters.alphaMap ? '#define USE_ALPHAMAP' : '', + parameters.alphaTest ? '#define USE_ALPHATEST' : '', + parameters.alphaHash ? '#define USE_ALPHAHASH' : '', + + parameters.sheen ? '#define USE_SHEEN' : '', + parameters.sheenColorMap ? '#define USE_SHEEN_COLORMAP' : '', + parameters.sheenRoughnessMap ? '#define USE_SHEEN_ROUGHNESSMAP' : '', + + parameters.transmission ? '#define USE_TRANSMISSION' : '', + parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', + parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '', + + parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '', + parameters.vertexColors || parameters.instancingColor || parameters.batchingColor ? '#define USE_COLOR' : '', + parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '', + parameters.vertexUv1s ? '#define USE_UV1' : '', + parameters.vertexUv2s ? '#define USE_UV2' : '', + parameters.vertexUv3s ? '#define USE_UV3' : '', + + parameters.pointsUvs ? '#define USE_POINTS_UV' : '', + + parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', + + parameters.flatShading ? '#define FLAT_SHADED' : '', + + parameters.doubleSided ? '#define DOUBLE_SIDED' : '', + parameters.flipSided ? '#define FLIP_SIDED' : '', + + parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', + parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', + + parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '', + + parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '', + + parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '', + parameters.decodeVideoTextureEmissive ? '#define DECODE_VIDEO_TEXTURE_EMISSIVE' : '', + + parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', + parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '', + + 'uniform mat4 viewMatrix;', + 'uniform vec3 cameraPosition;', + 'uniform bool isOrthographic;', + + ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '', + ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below + ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '', + + parameters.dithering ? '#define DITHERING' : '', + parameters.opaque ? '#define OPAQUE' : '', + + ShaderChunk[ 'colorspace_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below + getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputColorSpace ), + getLuminanceFunction(), + + parameters.useDepthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '', + + '\n' + + ].filter( filterEmptyLine ).join( '\n' ); + + } + + vertexShader = resolveIncludes( vertexShader ); + vertexShader = replaceLightNums( vertexShader, parameters ); + vertexShader = replaceClippingPlaneNums( vertexShader, parameters ); + + fragmentShader = resolveIncludes( fragmentShader ); + fragmentShader = replaceLightNums( fragmentShader, parameters ); + fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters ); + + vertexShader = unrollLoops( vertexShader ); + fragmentShader = unrollLoops( fragmentShader ); + + if ( parameters.isRawShaderMaterial !== true ) { + + // GLSL 3.0 conversion for built-in materials and ShaderMaterial + + versionString = '#version 300 es\n'; + + prefixVertex = [ + customVertexExtensions, + '#define attribute in', + '#define varying out', + '#define texture2D texture' + ].join( '\n' ) + '\n' + prefixVertex; + + prefixFragment = [ + '#define varying in', + ( parameters.glslVersion === GLSL3 ) ? '' : 'layout(location = 0) out highp vec4 pc_fragColor;', + ( parameters.glslVersion === GLSL3 ) ? '' : '#define gl_FragColor pc_fragColor', + '#define gl_FragDepthEXT gl_FragDepth', + '#define texture2D texture', + '#define textureCube texture', + '#define texture2DProj textureProj', + '#define texture2DLodEXT textureLod', + '#define texture2DProjLodEXT textureProjLod', + '#define textureCubeLodEXT textureLod', + '#define texture2DGradEXT textureGrad', + '#define texture2DProjGradEXT textureProjGrad', + '#define textureCubeGradEXT textureGrad' + ].join( '\n' ) + '\n' + prefixFragment; + + } + + const vertexGlsl = versionString + prefixVertex + vertexShader; + const fragmentGlsl = versionString + prefixFragment + fragmentShader; + + // console.log( '*VERTEX*', vertexGlsl ); + // console.log( '*FRAGMENT*', fragmentGlsl ); + + const glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl ); + const glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl ); + + gl.attachShader( program, glVertexShader ); + gl.attachShader( program, glFragmentShader ); + + // Force a particular attribute to index 0. + + if ( parameters.index0AttributeName !== undefined ) { + + gl.bindAttribLocation( program, 0, parameters.index0AttributeName ); + + } else if ( parameters.morphTargets === true ) { + + // programs with morphTargets displace position out of attribute 0 + gl.bindAttribLocation( program, 0, 'position' ); + + } + + gl.linkProgram( program ); + + function onFirstUse( self ) { + + // check for link errors + if ( renderer.debug.checkShaderErrors ) { + + const programLog = gl.getProgramInfoLog( program ).trim(); + const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim(); + const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim(); + + let runnable = true; + let haveDiagnostics = true; + + if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) { + + runnable = false; + + if ( typeof renderer.debug.onShaderError === 'function' ) { + + renderer.debug.onShaderError( gl, program, glVertexShader, glFragmentShader ); + + } else { + + // default error reporting + + const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' ); + const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' ); + + console.error( + 'THREE.WebGLProgram: Shader Error ' + gl.getError() + ' - ' + + 'VALIDATE_STATUS ' + gl.getProgramParameter( program, gl.VALIDATE_STATUS ) + '\n\n' + + 'Material Name: ' + self.name + '\n' + + 'Material Type: ' + self.type + '\n\n' + + 'Program Info Log: ' + programLog + '\n' + + vertexErrors + '\n' + + fragmentErrors + ); + + } + + } else if ( programLog !== '' ) { + + console.warn( 'THREE.WebGLProgram: Program Info Log:', programLog ); + + } else if ( vertexLog === '' || fragmentLog === '' ) { + + haveDiagnostics = false; + + } + + if ( haveDiagnostics ) { + + self.diagnostics = { + + runnable: runnable, + + programLog: programLog, + + vertexShader: { + + log: vertexLog, + prefix: prefixVertex + + }, + + fragmentShader: { + + log: fragmentLog, + prefix: prefixFragment + + } + + }; + + } + + } + + // Clean up + + // Crashes in iOS9 and iOS10. #18402 + // gl.detachShader( program, glVertexShader ); + // gl.detachShader( program, glFragmentShader ); + + gl.deleteShader( glVertexShader ); + gl.deleteShader( glFragmentShader ); + + cachedUniforms = new WebGLUniforms( gl, program ); + cachedAttributes = fetchAttributeLocations( gl, program ); + + } + + // set up caching for uniform locations + + let cachedUniforms; + + this.getUniforms = function () { + + if ( cachedUniforms === undefined ) { + + // Populates cachedUniforms and cachedAttributes + onFirstUse( this ); + + } + + return cachedUniforms; + + }; + + // set up caching for attribute locations + + let cachedAttributes; + + this.getAttributes = function () { + + if ( cachedAttributes === undefined ) { + + // Populates cachedAttributes and cachedUniforms + onFirstUse( this ); + + } + + return cachedAttributes; + + }; + + // indicate when the program is ready to be used. if the KHR_parallel_shader_compile extension isn't supported, + // flag the program as ready immediately. It may cause a stall when it's first used. + + let programReady = ( parameters.rendererExtensionParallelShaderCompile === false ); + + this.isReady = function () { + + if ( programReady === false ) { + + programReady = gl.getProgramParameter( program, COMPLETION_STATUS_KHR ); + + } + + return programReady; + + }; + + // free resource + + this.destroy = function () { + + bindingStates.releaseStatesOfProgram( this ); + + gl.deleteProgram( program ); + this.program = undefined; + + }; + + // + + this.type = parameters.shaderType; + this.name = parameters.shaderName; + this.id = programIdCount ++; + this.cacheKey = cacheKey; + this.usedTimes = 1; + this.program = program; + this.vertexShader = glVertexShader; + this.fragmentShader = glFragmentShader; + + return this; + +} + +let _id = 0; + +class WebGLShaderCache { + + constructor() { + + this.shaderCache = new Map(); + this.materialCache = new Map(); + + } + + update( material ) { + + const vertexShader = material.vertexShader; + const fragmentShader = material.fragmentShader; + + const vertexShaderStage = this._getShaderStage( vertexShader ); + const fragmentShaderStage = this._getShaderStage( fragmentShader ); + + const materialShaders = this._getShaderCacheForMaterial( material ); + + if ( materialShaders.has( vertexShaderStage ) === false ) { + + materialShaders.add( vertexShaderStage ); + vertexShaderStage.usedTimes ++; + + } + + if ( materialShaders.has( fragmentShaderStage ) === false ) { + + materialShaders.add( fragmentShaderStage ); + fragmentShaderStage.usedTimes ++; + + } + + return this; + + } + + remove( material ) { + + const materialShaders = this.materialCache.get( material ); + + for ( const shaderStage of materialShaders ) { + + shaderStage.usedTimes --; + + if ( shaderStage.usedTimes === 0 ) this.shaderCache.delete( shaderStage.code ); + + } + + this.materialCache.delete( material ); + + return this; + + } + + getVertexShaderID( material ) { + + return this._getShaderStage( material.vertexShader ).id; + + } + + getFragmentShaderID( material ) { + + return this._getShaderStage( material.fragmentShader ).id; + + } + + dispose() { + + this.shaderCache.clear(); + this.materialCache.clear(); + + } + + _getShaderCacheForMaterial( material ) { + + const cache = this.materialCache; + let set = cache.get( material ); + + if ( set === undefined ) { + + set = new Set(); + cache.set( material, set ); + + } + + return set; + + } + + _getShaderStage( code ) { + + const cache = this.shaderCache; + let stage = cache.get( code ); + + if ( stage === undefined ) { + + stage = new WebGLShaderStage( code ); + cache.set( code, stage ); + + } + + return stage; + + } + +} + +class WebGLShaderStage { + + constructor( code ) { + + this.id = _id ++; + + this.code = code; + this.usedTimes = 0; + + } + +} + +function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping ) { + + const _programLayers = new Layers(); + const _customShaders = new WebGLShaderCache(); + const _activeChannels = new Set(); + const programs = []; + + const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer; + const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures; + + let precision = capabilities.precision; + + const shaderIDs = { + MeshDepthMaterial: 'depth', + MeshDistanceMaterial: 'distanceRGBA', + MeshNormalMaterial: 'normal', + MeshBasicMaterial: 'basic', + MeshLambertMaterial: 'lambert', + MeshPhongMaterial: 'phong', + MeshToonMaterial: 'toon', + MeshStandardMaterial: 'physical', + MeshPhysicalMaterial: 'physical', + MeshMatcapMaterial: 'matcap', + LineBasicMaterial: 'basic', + LineDashedMaterial: 'dashed', + PointsMaterial: 'points', + ShadowMaterial: 'shadow', + SpriteMaterial: 'sprite' + }; + + function getChannel( value ) { + + _activeChannels.add( value ); + + if ( value === 0 ) return 'uv'; + + return `uv${ value }`; + + } + + function getParameters( material, lights, shadows, scene, object ) { + + const fog = scene.fog; + const geometry = object.geometry; + const environment = material.isMeshStandardMaterial ? scene.environment : null; + + const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment ); + const envMapCubeUVHeight = ( !! envMap ) && ( envMap.mapping === CubeUVReflectionMapping ) ? envMap.image.height : null; + + const shaderID = shaderIDs[ material.type ]; + + // heuristics to create shader parameters according to lights in the scene + // (not to blow over maxLights budget) + + if ( material.precision !== null ) { + + precision = capabilities.getMaxPrecision( material.precision ); + + if ( precision !== material.precision ) { + + console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' ); + + } + + } + + // + + const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; + const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0; + + let morphTextureStride = 0; + + if ( geometry.morphAttributes.position !== undefined ) morphTextureStride = 1; + if ( geometry.morphAttributes.normal !== undefined ) morphTextureStride = 2; + if ( geometry.morphAttributes.color !== undefined ) morphTextureStride = 3; + + // + + let vertexShader, fragmentShader; + let customVertexShaderID, customFragmentShaderID; + + if ( shaderID ) { + + const shader = ShaderLib[ shaderID ]; + + vertexShader = shader.vertexShader; + fragmentShader = shader.fragmentShader; + + } else { + + vertexShader = material.vertexShader; + fragmentShader = material.fragmentShader; + + _customShaders.update( material ); + + customVertexShaderID = _customShaders.getVertexShaderID( material ); + customFragmentShaderID = _customShaders.getFragmentShaderID( material ); + + } + + const currentRenderTarget = renderer.getRenderTarget(); + const reverseDepthBuffer = renderer.state.buffers.depth.getReversed(); + + const IS_INSTANCEDMESH = object.isInstancedMesh === true; + const IS_BATCHEDMESH = object.isBatchedMesh === true; + + const HAS_MAP = !! material.map; + const HAS_MATCAP = !! material.matcap; + const HAS_ENVMAP = !! envMap; + const HAS_AOMAP = !! material.aoMap; + const HAS_LIGHTMAP = !! material.lightMap; + const HAS_BUMPMAP = !! material.bumpMap; + const HAS_NORMALMAP = !! material.normalMap; + const HAS_DISPLACEMENTMAP = !! material.displacementMap; + const HAS_EMISSIVEMAP = !! material.emissiveMap; + + const HAS_METALNESSMAP = !! material.metalnessMap; + const HAS_ROUGHNESSMAP = !! material.roughnessMap; + + const HAS_ANISOTROPY = material.anisotropy > 0; + const HAS_CLEARCOAT = material.clearcoat > 0; + const HAS_DISPERSION = material.dispersion > 0; + const HAS_IRIDESCENCE = material.iridescence > 0; + const HAS_SHEEN = material.sheen > 0; + const HAS_TRANSMISSION = material.transmission > 0; + + const HAS_ANISOTROPYMAP = HAS_ANISOTROPY && !! material.anisotropyMap; + + const HAS_CLEARCOATMAP = HAS_CLEARCOAT && !! material.clearcoatMap; + const HAS_CLEARCOAT_NORMALMAP = HAS_CLEARCOAT && !! material.clearcoatNormalMap; + const HAS_CLEARCOAT_ROUGHNESSMAP = HAS_CLEARCOAT && !! material.clearcoatRoughnessMap; + + const HAS_IRIDESCENCEMAP = HAS_IRIDESCENCE && !! material.iridescenceMap; + const HAS_IRIDESCENCE_THICKNESSMAP = HAS_IRIDESCENCE && !! material.iridescenceThicknessMap; + + const HAS_SHEEN_COLORMAP = HAS_SHEEN && !! material.sheenColorMap; + const HAS_SHEEN_ROUGHNESSMAP = HAS_SHEEN && !! material.sheenRoughnessMap; + + const HAS_SPECULARMAP = !! material.specularMap; + const HAS_SPECULAR_COLORMAP = !! material.specularColorMap; + const HAS_SPECULAR_INTENSITYMAP = !! material.specularIntensityMap; + + const HAS_TRANSMISSIONMAP = HAS_TRANSMISSION && !! material.transmissionMap; + const HAS_THICKNESSMAP = HAS_TRANSMISSION && !! material.thicknessMap; + + const HAS_GRADIENTMAP = !! material.gradientMap; + + const HAS_ALPHAMAP = !! material.alphaMap; + + const HAS_ALPHATEST = material.alphaTest > 0; + + const HAS_ALPHAHASH = !! material.alphaHash; + + const HAS_EXTENSIONS = !! material.extensions; + + let toneMapping = NoToneMapping; + + if ( material.toneMapped ) { + + if ( currentRenderTarget === null || currentRenderTarget.isXRRenderTarget === true ) { + + toneMapping = renderer.toneMapping; + + } + + } + + const parameters = { + + shaderID: shaderID, + shaderType: material.type, + shaderName: material.name, + + vertexShader: vertexShader, + fragmentShader: fragmentShader, + defines: material.defines, + + customVertexShaderID: customVertexShaderID, + customFragmentShaderID: customFragmentShaderID, + + isRawShaderMaterial: material.isRawShaderMaterial === true, + glslVersion: material.glslVersion, + + precision: precision, + + batching: IS_BATCHEDMESH, + batchingColor: IS_BATCHEDMESH && object._colorsTexture !== null, + instancing: IS_INSTANCEDMESH, + instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null, + instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null, + + supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES, + outputColorSpace: ( currentRenderTarget === null ) ? renderer.outputColorSpace : ( currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace ), + alphaToCoverage: !! material.alphaToCoverage, + + map: HAS_MAP, + matcap: HAS_MATCAP, + envMap: HAS_ENVMAP, + envMapMode: HAS_ENVMAP && envMap.mapping, + envMapCubeUVHeight: envMapCubeUVHeight, + aoMap: HAS_AOMAP, + lightMap: HAS_LIGHTMAP, + bumpMap: HAS_BUMPMAP, + normalMap: HAS_NORMALMAP, + displacementMap: SUPPORTS_VERTEX_TEXTURES && HAS_DISPLACEMENTMAP, + emissiveMap: HAS_EMISSIVEMAP, + + normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap, + normalMapTangentSpace: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap, + + metalnessMap: HAS_METALNESSMAP, + roughnessMap: HAS_ROUGHNESSMAP, + + anisotropy: HAS_ANISOTROPY, + anisotropyMap: HAS_ANISOTROPYMAP, + + clearcoat: HAS_CLEARCOAT, + clearcoatMap: HAS_CLEARCOATMAP, + clearcoatNormalMap: HAS_CLEARCOAT_NORMALMAP, + clearcoatRoughnessMap: HAS_CLEARCOAT_ROUGHNESSMAP, + + dispersion: HAS_DISPERSION, + + iridescence: HAS_IRIDESCENCE, + iridescenceMap: HAS_IRIDESCENCEMAP, + iridescenceThicknessMap: HAS_IRIDESCENCE_THICKNESSMAP, + + sheen: HAS_SHEEN, + sheenColorMap: HAS_SHEEN_COLORMAP, + sheenRoughnessMap: HAS_SHEEN_ROUGHNESSMAP, + + specularMap: HAS_SPECULARMAP, + specularColorMap: HAS_SPECULAR_COLORMAP, + specularIntensityMap: HAS_SPECULAR_INTENSITYMAP, + + transmission: HAS_TRANSMISSION, + transmissionMap: HAS_TRANSMISSIONMAP, + thicknessMap: HAS_THICKNESSMAP, + + gradientMap: HAS_GRADIENTMAP, + + opaque: material.transparent === false && material.blending === NormalBlending && material.alphaToCoverage === false, + + alphaMap: HAS_ALPHAMAP, + alphaTest: HAS_ALPHATEST, + alphaHash: HAS_ALPHAHASH, + + combine: material.combine, + + // + + mapUv: HAS_MAP && getChannel( material.map.channel ), + aoMapUv: HAS_AOMAP && getChannel( material.aoMap.channel ), + lightMapUv: HAS_LIGHTMAP && getChannel( material.lightMap.channel ), + bumpMapUv: HAS_BUMPMAP && getChannel( material.bumpMap.channel ), + normalMapUv: HAS_NORMALMAP && getChannel( material.normalMap.channel ), + displacementMapUv: HAS_DISPLACEMENTMAP && getChannel( material.displacementMap.channel ), + emissiveMapUv: HAS_EMISSIVEMAP && getChannel( material.emissiveMap.channel ), + + metalnessMapUv: HAS_METALNESSMAP && getChannel( material.metalnessMap.channel ), + roughnessMapUv: HAS_ROUGHNESSMAP && getChannel( material.roughnessMap.channel ), + + anisotropyMapUv: HAS_ANISOTROPYMAP && getChannel( material.anisotropyMap.channel ), + + clearcoatMapUv: HAS_CLEARCOATMAP && getChannel( material.clearcoatMap.channel ), + clearcoatNormalMapUv: HAS_CLEARCOAT_NORMALMAP && getChannel( material.clearcoatNormalMap.channel ), + clearcoatRoughnessMapUv: HAS_CLEARCOAT_ROUGHNESSMAP && getChannel( material.clearcoatRoughnessMap.channel ), + + iridescenceMapUv: HAS_IRIDESCENCEMAP && getChannel( material.iridescenceMap.channel ), + iridescenceThicknessMapUv: HAS_IRIDESCENCE_THICKNESSMAP && getChannel( material.iridescenceThicknessMap.channel ), + + sheenColorMapUv: HAS_SHEEN_COLORMAP && getChannel( material.sheenColorMap.channel ), + sheenRoughnessMapUv: HAS_SHEEN_ROUGHNESSMAP && getChannel( material.sheenRoughnessMap.channel ), + + specularMapUv: HAS_SPECULARMAP && getChannel( material.specularMap.channel ), + specularColorMapUv: HAS_SPECULAR_COLORMAP && getChannel( material.specularColorMap.channel ), + specularIntensityMapUv: HAS_SPECULAR_INTENSITYMAP && getChannel( material.specularIntensityMap.channel ), + + transmissionMapUv: HAS_TRANSMISSIONMAP && getChannel( material.transmissionMap.channel ), + thicknessMapUv: HAS_THICKNESSMAP && getChannel( material.thicknessMap.channel ), + + alphaMapUv: HAS_ALPHAMAP && getChannel( material.alphaMap.channel ), + + // + + vertexTangents: !! geometry.attributes.tangent && ( HAS_NORMALMAP || HAS_ANISOTROPY ), + vertexColors: material.vertexColors, + vertexAlphas: material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4, + + pointsUvs: object.isPoints === true && !! geometry.attributes.uv && ( HAS_MAP || HAS_ALPHAMAP ), + + fog: !! fog, + useFog: material.fog === true, + fogExp2: ( !! fog && fog.isFogExp2 ), + + flatShading: material.flatShading === true, + + sizeAttenuation: material.sizeAttenuation === true, + logarithmicDepthBuffer: logarithmicDepthBuffer, + reverseDepthBuffer: reverseDepthBuffer, + + skinning: object.isSkinnedMesh === true, + + morphTargets: geometry.morphAttributes.position !== undefined, + morphNormals: geometry.morphAttributes.normal !== undefined, + morphColors: geometry.morphAttributes.color !== undefined, + morphTargetsCount: morphTargetsCount, + morphTextureStride: morphTextureStride, + + numDirLights: lights.directional.length, + numPointLights: lights.point.length, + numSpotLights: lights.spot.length, + numSpotLightMaps: lights.spotLightMap.length, + numRectAreaLights: lights.rectArea.length, + numHemiLights: lights.hemi.length, + + numDirLightShadows: lights.directionalShadowMap.length, + numPointLightShadows: lights.pointShadowMap.length, + numSpotLightShadows: lights.spotShadowMap.length, + numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps, + + numLightProbes: lights.numLightProbes, + + numClippingPlanes: clipping.numPlanes, + numClipIntersection: clipping.numIntersection, + + dithering: material.dithering, + + shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0, + shadowMapType: renderer.shadowMap.type, + + toneMapping: toneMapping, + + decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ), + decodeVideoTextureEmissive: HAS_EMISSIVEMAP && ( material.emissiveMap.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.emissiveMap.colorSpace ) === SRGBTransfer ), + + premultipliedAlpha: material.premultipliedAlpha, + + doubleSided: material.side === DoubleSide, + flipSided: material.side === BackSide, + + useDepthPacking: material.depthPacking >= 0, + depthPacking: material.depthPacking || 0, + + index0AttributeName: material.index0AttributeName, + + extensionClipCullDistance: HAS_EXTENSIONS && material.extensions.clipCullDistance === true && extensions.has( 'WEBGL_clip_cull_distance' ), + extensionMultiDraw: ( HAS_EXTENSIONS && material.extensions.multiDraw === true || IS_BATCHEDMESH ) && extensions.has( 'WEBGL_multi_draw' ), + + rendererExtensionParallelShaderCompile: extensions.has( 'KHR_parallel_shader_compile' ), + + customProgramCacheKey: material.customProgramCacheKey() + + }; + + // the usage of getChannel() determines the active texture channels for this shader + + parameters.vertexUv1s = _activeChannels.has( 1 ); + parameters.vertexUv2s = _activeChannels.has( 2 ); + parameters.vertexUv3s = _activeChannels.has( 3 ); + + _activeChannels.clear(); + + return parameters; + + } + + function getProgramCacheKey( parameters ) { + + const array = []; + + if ( parameters.shaderID ) { + + array.push( parameters.shaderID ); + + } else { + + array.push( parameters.customVertexShaderID ); + array.push( parameters.customFragmentShaderID ); + + } + + if ( parameters.defines !== undefined ) { + + for ( const name in parameters.defines ) { + + array.push( name ); + array.push( parameters.defines[ name ] ); + + } + + } + + if ( parameters.isRawShaderMaterial === false ) { + + getProgramCacheKeyParameters( array, parameters ); + getProgramCacheKeyBooleans( array, parameters ); + array.push( renderer.outputColorSpace ); + + } + + array.push( parameters.customProgramCacheKey ); + + return array.join(); + + } + + function getProgramCacheKeyParameters( array, parameters ) { + + array.push( parameters.precision ); + array.push( parameters.outputColorSpace ); + array.push( parameters.envMapMode ); + array.push( parameters.envMapCubeUVHeight ); + array.push( parameters.mapUv ); + array.push( parameters.alphaMapUv ); + array.push( parameters.lightMapUv ); + array.push( parameters.aoMapUv ); + array.push( parameters.bumpMapUv ); + array.push( parameters.normalMapUv ); + array.push( parameters.displacementMapUv ); + array.push( parameters.emissiveMapUv ); + array.push( parameters.metalnessMapUv ); + array.push( parameters.roughnessMapUv ); + array.push( parameters.anisotropyMapUv ); + array.push( parameters.clearcoatMapUv ); + array.push( parameters.clearcoatNormalMapUv ); + array.push( parameters.clearcoatRoughnessMapUv ); + array.push( parameters.iridescenceMapUv ); + array.push( parameters.iridescenceThicknessMapUv ); + array.push( parameters.sheenColorMapUv ); + array.push( parameters.sheenRoughnessMapUv ); + array.push( parameters.specularMapUv ); + array.push( parameters.specularColorMapUv ); + array.push( parameters.specularIntensityMapUv ); + array.push( parameters.transmissionMapUv ); + array.push( parameters.thicknessMapUv ); + array.push( parameters.combine ); + array.push( parameters.fogExp2 ); + array.push( parameters.sizeAttenuation ); + array.push( parameters.morphTargetsCount ); + array.push( parameters.morphAttributeCount ); + array.push( parameters.numDirLights ); + array.push( parameters.numPointLights ); + array.push( parameters.numSpotLights ); + array.push( parameters.numSpotLightMaps ); + array.push( parameters.numHemiLights ); + array.push( parameters.numRectAreaLights ); + array.push( parameters.numDirLightShadows ); + array.push( parameters.numPointLightShadows ); + array.push( parameters.numSpotLightShadows ); + array.push( parameters.numSpotLightShadowsWithMaps ); + array.push( parameters.numLightProbes ); + array.push( parameters.shadowMapType ); + array.push( parameters.toneMapping ); + array.push( parameters.numClippingPlanes ); + array.push( parameters.numClipIntersection ); + array.push( parameters.depthPacking ); + + } + + function getProgramCacheKeyBooleans( array, parameters ) { + + _programLayers.disableAll(); + + if ( parameters.supportsVertexTextures ) + _programLayers.enable( 0 ); + if ( parameters.instancing ) + _programLayers.enable( 1 ); + if ( parameters.instancingColor ) + _programLayers.enable( 2 ); + if ( parameters.instancingMorph ) + _programLayers.enable( 3 ); + if ( parameters.matcap ) + _programLayers.enable( 4 ); + if ( parameters.envMap ) + _programLayers.enable( 5 ); + if ( parameters.normalMapObjectSpace ) + _programLayers.enable( 6 ); + if ( parameters.normalMapTangentSpace ) + _programLayers.enable( 7 ); + if ( parameters.clearcoat ) + _programLayers.enable( 8 ); + if ( parameters.iridescence ) + _programLayers.enable( 9 ); + if ( parameters.alphaTest ) + _programLayers.enable( 10 ); + if ( parameters.vertexColors ) + _programLayers.enable( 11 ); + if ( parameters.vertexAlphas ) + _programLayers.enable( 12 ); + if ( parameters.vertexUv1s ) + _programLayers.enable( 13 ); + if ( parameters.vertexUv2s ) + _programLayers.enable( 14 ); + if ( parameters.vertexUv3s ) + _programLayers.enable( 15 ); + if ( parameters.vertexTangents ) + _programLayers.enable( 16 ); + if ( parameters.anisotropy ) + _programLayers.enable( 17 ); + if ( parameters.alphaHash ) + _programLayers.enable( 18 ); + if ( parameters.batching ) + _programLayers.enable( 19 ); + if ( parameters.dispersion ) + _programLayers.enable( 20 ); + if ( parameters.batchingColor ) + _programLayers.enable( 21 ); + + array.push( _programLayers.mask ); + _programLayers.disableAll(); + + if ( parameters.fog ) + _programLayers.enable( 0 ); + if ( parameters.useFog ) + _programLayers.enable( 1 ); + if ( parameters.flatShading ) + _programLayers.enable( 2 ); + if ( parameters.logarithmicDepthBuffer ) + _programLayers.enable( 3 ); + if ( parameters.reverseDepthBuffer ) + _programLayers.enable( 4 ); + if ( parameters.skinning ) + _programLayers.enable( 5 ); + if ( parameters.morphTargets ) + _programLayers.enable( 6 ); + if ( parameters.morphNormals ) + _programLayers.enable( 7 ); + if ( parameters.morphColors ) + _programLayers.enable( 8 ); + if ( parameters.premultipliedAlpha ) + _programLayers.enable( 9 ); + if ( parameters.shadowMapEnabled ) + _programLayers.enable( 10 ); + if ( parameters.doubleSided ) + _programLayers.enable( 11 ); + if ( parameters.flipSided ) + _programLayers.enable( 12 ); + if ( parameters.useDepthPacking ) + _programLayers.enable( 13 ); + if ( parameters.dithering ) + _programLayers.enable( 14 ); + if ( parameters.transmission ) + _programLayers.enable( 15 ); + if ( parameters.sheen ) + _programLayers.enable( 16 ); + if ( parameters.opaque ) + _programLayers.enable( 17 ); + if ( parameters.pointsUvs ) + _programLayers.enable( 18 ); + if ( parameters.decodeVideoTexture ) + _programLayers.enable( 19 ); + if ( parameters.decodeVideoTextureEmissive ) + _programLayers.enable( 20 ); + if ( parameters.alphaToCoverage ) + _programLayers.enable( 21 ); + + array.push( _programLayers.mask ); + + } + + function getUniforms( material ) { + + const shaderID = shaderIDs[ material.type ]; + let uniforms; + + if ( shaderID ) { + + const shader = ShaderLib[ shaderID ]; + uniforms = UniformsUtils.clone( shader.uniforms ); + + } else { + + uniforms = material.uniforms; + + } + + return uniforms; + + } + + function acquireProgram( parameters, cacheKey ) { + + let program; + + // Check if code has been already compiled + for ( let p = 0, pl = programs.length; p < pl; p ++ ) { + + const preexistingProgram = programs[ p ]; + + if ( preexistingProgram.cacheKey === cacheKey ) { + + program = preexistingProgram; + ++ program.usedTimes; + + break; + + } + + } + + if ( program === undefined ) { + + program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates ); + programs.push( program ); + + } + + return program; + + } + + function releaseProgram( program ) { + + if ( -- program.usedTimes === 0 ) { + + // Remove from unordered set + const i = programs.indexOf( program ); + programs[ i ] = programs[ programs.length - 1 ]; + programs.pop(); + + // Free WebGL resources + program.destroy(); + + } + + } + + function releaseShaderCache( material ) { + + _customShaders.remove( material ); + + } + + function dispose() { + + _customShaders.dispose(); + + } + + return { + getParameters: getParameters, + getProgramCacheKey: getProgramCacheKey, + getUniforms: getUniforms, + acquireProgram: acquireProgram, + releaseProgram: releaseProgram, + releaseShaderCache: releaseShaderCache, + // Exposed for resource monitoring & error feedback via renderer.info: + programs: programs, + dispose: dispose + }; + +} + +function WebGLProperties() { + + let properties = new WeakMap(); + + function has( object ) { + + return properties.has( object ); + + } + + function get( object ) { + + let map = properties.get( object ); + + if ( map === undefined ) { + + map = {}; + properties.set( object, map ); + + } + + return map; + + } + + function remove( object ) { + + properties.delete( object ); + + } + + function update( object, key, value ) { + + properties.get( object )[ key ] = value; + + } + + function dispose() { + + properties = new WeakMap(); + + } + + return { + has: has, + get: get, + remove: remove, + update: update, + dispose: dispose + }; + +} + +function painterSortStable( a, b ) { + + if ( a.groupOrder !== b.groupOrder ) { + + return a.groupOrder - b.groupOrder; + + } else if ( a.renderOrder !== b.renderOrder ) { + + return a.renderOrder - b.renderOrder; + + } else if ( a.material.id !== b.material.id ) { + + return a.material.id - b.material.id; + + } else if ( a.z !== b.z ) { + + return a.z - b.z; + + } else { + + return a.id - b.id; + + } + +} + +function reversePainterSortStable( a, b ) { + + if ( a.groupOrder !== b.groupOrder ) { + + return a.groupOrder - b.groupOrder; + + } else if ( a.renderOrder !== b.renderOrder ) { + + return a.renderOrder - b.renderOrder; + + } else if ( a.z !== b.z ) { + + return b.z - a.z; + + } else { + + return a.id - b.id; + + } + +} + + +function WebGLRenderList() { + + const renderItems = []; + let renderItemsIndex = 0; + + const opaque = []; + const transmissive = []; + const transparent = []; + + function init() { + + renderItemsIndex = 0; + + opaque.length = 0; + transmissive.length = 0; + transparent.length = 0; + + } + + function getNextRenderItem( object, geometry, material, groupOrder, z, group ) { + + let renderItem = renderItems[ renderItemsIndex ]; + + if ( renderItem === undefined ) { + + renderItem = { + id: object.id, + object: object, + geometry: geometry, + material: material, + groupOrder: groupOrder, + renderOrder: object.renderOrder, + z: z, + group: group + }; + + renderItems[ renderItemsIndex ] = renderItem; + + } else { + + renderItem.id = object.id; + renderItem.object = object; + renderItem.geometry = geometry; + renderItem.material = material; + renderItem.groupOrder = groupOrder; + renderItem.renderOrder = object.renderOrder; + renderItem.z = z; + renderItem.group = group; + + } + + renderItemsIndex ++; + + return renderItem; + + } + + function push( object, geometry, material, groupOrder, z, group ) { + + const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group ); + + if ( material.transmission > 0.0 ) { + + transmissive.push( renderItem ); + + } else if ( material.transparent === true ) { + + transparent.push( renderItem ); + + } else { + + opaque.push( renderItem ); + + } + + } + + function unshift( object, geometry, material, groupOrder, z, group ) { + + const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group ); + + if ( material.transmission > 0.0 ) { + + transmissive.unshift( renderItem ); + + } else if ( material.transparent === true ) { + + transparent.unshift( renderItem ); + + } else { + + opaque.unshift( renderItem ); + + } + + } + + function sort( customOpaqueSort, customTransparentSort ) { + + if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable ); + if ( transmissive.length > 1 ) transmissive.sort( customTransparentSort || reversePainterSortStable ); + if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable ); + + } + + function finish() { + + // Clear references from inactive renderItems in the list + + for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) { + + const renderItem = renderItems[ i ]; + + if ( renderItem.id === null ) break; + + renderItem.id = null; + renderItem.object = null; + renderItem.geometry = null; + renderItem.material = null; + renderItem.group = null; + + } + + } + + return { + + opaque: opaque, + transmissive: transmissive, + transparent: transparent, + + init: init, + push: push, + unshift: unshift, + finish: finish, + + sort: sort + }; + +} + +function WebGLRenderLists() { + + let lists = new WeakMap(); + + function get( scene, renderCallDepth ) { + + const listArray = lists.get( scene ); + let list; + + if ( listArray === undefined ) { + + list = new WebGLRenderList(); + lists.set( scene, [ list ] ); + + } else { + + if ( renderCallDepth >= listArray.length ) { + + list = new WebGLRenderList(); + listArray.push( list ); + + } else { + + list = listArray[ renderCallDepth ]; + + } + + } + + return list; + + } + + function dispose() { + + lists = new WeakMap(); + + } + + return { + get: get, + dispose: dispose + }; + +} + +function UniformsCache() { + + const lights = {}; + + return { + + get: function ( light ) { + + if ( lights[ light.id ] !== undefined ) { + + return lights[ light.id ]; + + } + + let uniforms; + + switch ( light.type ) { + + case 'DirectionalLight': + uniforms = { + direction: new Vector3(), + color: new Color() + }; + break; + + case 'SpotLight': + uniforms = { + position: new Vector3(), + direction: new Vector3(), + color: new Color(), + distance: 0, + coneCos: 0, + penumbraCos: 0, + decay: 0 + }; + break; + + case 'PointLight': + uniforms = { + position: new Vector3(), + color: new Color(), + distance: 0, + decay: 0 + }; + break; + + case 'HemisphereLight': + uniforms = { + direction: new Vector3(), + skyColor: new Color(), + groundColor: new Color() + }; + break; + + case 'RectAreaLight': + uniforms = { + color: new Color(), + position: new Vector3(), + halfWidth: new Vector3(), + halfHeight: new Vector3() + }; + break; + + } + + lights[ light.id ] = uniforms; + + return uniforms; + + } + + }; + +} + +function ShadowUniformsCache() { + + const lights = {}; + + return { + + get: function ( light ) { + + if ( lights[ light.id ] !== undefined ) { + + return lights[ light.id ]; + + } + + let uniforms; + + switch ( light.type ) { + + case 'DirectionalLight': + uniforms = { + shadowIntensity: 1, + shadowBias: 0, + shadowNormalBias: 0, + shadowRadius: 1, + shadowMapSize: new Vector2() + }; + break; + + case 'SpotLight': + uniforms = { + shadowIntensity: 1, + shadowBias: 0, + shadowNormalBias: 0, + shadowRadius: 1, + shadowMapSize: new Vector2() + }; + break; + + case 'PointLight': + uniforms = { + shadowIntensity: 1, + shadowBias: 0, + shadowNormalBias: 0, + shadowRadius: 1, + shadowMapSize: new Vector2(), + shadowCameraNear: 1, + shadowCameraFar: 1000 + }; + break; + + // TODO (abelnation): set RectAreaLight shadow uniforms + + } + + lights[ light.id ] = uniforms; + + return uniforms; + + } + + }; + +} + + + +let nextVersion = 0; + +function shadowCastingAndTexturingLightsFirst( lightA, lightB ) { + + return ( lightB.castShadow ? 2 : 0 ) - ( lightA.castShadow ? 2 : 0 ) + ( lightB.map ? 1 : 0 ) - ( lightA.map ? 1 : 0 ); + +} + +function WebGLLights( extensions ) { + + const cache = new UniformsCache(); + + const shadowCache = ShadowUniformsCache(); + + const state = { + + version: 0, + + hash: { + directionalLength: - 1, + pointLength: - 1, + spotLength: - 1, + rectAreaLength: - 1, + hemiLength: - 1, + + numDirectionalShadows: - 1, + numPointShadows: - 1, + numSpotShadows: - 1, + numSpotMaps: - 1, + + numLightProbes: - 1 + }, + + ambient: [ 0, 0, 0 ], + probe: [], + directional: [], + directionalShadow: [], + directionalShadowMap: [], + directionalShadowMatrix: [], + spot: [], + spotLightMap: [], + spotShadow: [], + spotShadowMap: [], + spotLightMatrix: [], + rectArea: [], + rectAreaLTC1: null, + rectAreaLTC2: null, + point: [], + pointShadow: [], + pointShadowMap: [], + pointShadowMatrix: [], + hemi: [], + numSpotLightShadowsWithMaps: 0, + numLightProbes: 0 + + }; + + for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() ); + + const vector3 = new Vector3(); + const matrix4 = new Matrix4(); + const matrix42 = new Matrix4(); + + function setup( lights ) { + + let r = 0, g = 0, b = 0; + + for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 ); + + let directionalLength = 0; + let pointLength = 0; + let spotLength = 0; + let rectAreaLength = 0; + let hemiLength = 0; + + let numDirectionalShadows = 0; + let numPointShadows = 0; + let numSpotShadows = 0; + let numSpotMaps = 0; + let numSpotShadowsWithMaps = 0; + + let numLightProbes = 0; + + // ordering : [shadow casting + map texturing, map texturing, shadow casting, none ] + lights.sort( shadowCastingAndTexturingLightsFirst ); + + for ( let i = 0, l = lights.length; i < l; i ++ ) { + + const light = lights[ i ]; + + const color = light.color; + const intensity = light.intensity; + const distance = light.distance; + + const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null; + + if ( light.isAmbientLight ) { + + r += color.r * intensity; + g += color.g * intensity; + b += color.b * intensity; + + } else if ( light.isLightProbe ) { + + for ( let j = 0; j < 9; j ++ ) { + + state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity ); + + } + + numLightProbes ++; + + } else if ( light.isDirectionalLight ) { + + const uniforms = cache.get( light ); + + uniforms.color.copy( light.color ).multiplyScalar( light.intensity ); + + if ( light.castShadow ) { + + const shadow = light.shadow; + + const shadowUniforms = shadowCache.get( light ); + + shadowUniforms.shadowIntensity = shadow.intensity; + shadowUniforms.shadowBias = shadow.bias; + shadowUniforms.shadowNormalBias = shadow.normalBias; + shadowUniforms.shadowRadius = shadow.radius; + shadowUniforms.shadowMapSize = shadow.mapSize; + + state.directionalShadow[ directionalLength ] = shadowUniforms; + state.directionalShadowMap[ directionalLength ] = shadowMap; + state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix; + + numDirectionalShadows ++; + + } + + state.directional[ directionalLength ] = uniforms; + + directionalLength ++; + + } else if ( light.isSpotLight ) { + + const uniforms = cache.get( light ); + + uniforms.position.setFromMatrixPosition( light.matrixWorld ); + + uniforms.color.copy( color ).multiplyScalar( intensity ); + uniforms.distance = distance; + + uniforms.coneCos = Math.cos( light.angle ); + uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) ); + uniforms.decay = light.decay; + + state.spot[ spotLength ] = uniforms; + + const shadow = light.shadow; + + if ( light.map ) { + + state.spotLightMap[ numSpotMaps ] = light.map; + numSpotMaps ++; + + // make sure the lightMatrix is up to date + // TODO : do it if required only + shadow.updateMatrices( light ); + + if ( light.castShadow ) numSpotShadowsWithMaps ++; + + } + + state.spotLightMatrix[ spotLength ] = shadow.matrix; + + if ( light.castShadow ) { + + const shadowUniforms = shadowCache.get( light ); + + shadowUniforms.shadowIntensity = shadow.intensity; + shadowUniforms.shadowBias = shadow.bias; + shadowUniforms.shadowNormalBias = shadow.normalBias; + shadowUniforms.shadowRadius = shadow.radius; + shadowUniforms.shadowMapSize = shadow.mapSize; + + state.spotShadow[ spotLength ] = shadowUniforms; + state.spotShadowMap[ spotLength ] = shadowMap; + + numSpotShadows ++; + + } + + spotLength ++; + + } else if ( light.isRectAreaLight ) { + + const uniforms = cache.get( light ); + + uniforms.color.copy( color ).multiplyScalar( intensity ); + + uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 ); + uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 ); + + state.rectArea[ rectAreaLength ] = uniforms; + + rectAreaLength ++; + + } else if ( light.isPointLight ) { + + const uniforms = cache.get( light ); + + uniforms.color.copy( light.color ).multiplyScalar( light.intensity ); + uniforms.distance = light.distance; + uniforms.decay = light.decay; + + if ( light.castShadow ) { + + const shadow = light.shadow; + + const shadowUniforms = shadowCache.get( light ); + + shadowUniforms.shadowIntensity = shadow.intensity; + shadowUniforms.shadowBias = shadow.bias; + shadowUniforms.shadowNormalBias = shadow.normalBias; + shadowUniforms.shadowRadius = shadow.radius; + shadowUniforms.shadowMapSize = shadow.mapSize; + shadowUniforms.shadowCameraNear = shadow.camera.near; + shadowUniforms.shadowCameraFar = shadow.camera.far; + + state.pointShadow[ pointLength ] = shadowUniforms; + state.pointShadowMap[ pointLength ] = shadowMap; + state.pointShadowMatrix[ pointLength ] = light.shadow.matrix; + + numPointShadows ++; + + } + + state.point[ pointLength ] = uniforms; + + pointLength ++; + + } else if ( light.isHemisphereLight ) { + + const uniforms = cache.get( light ); + + uniforms.skyColor.copy( light.color ).multiplyScalar( intensity ); + uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity ); + + state.hemi[ hemiLength ] = uniforms; + + hemiLength ++; + + } + + } + + if ( rectAreaLength > 0 ) { + + if ( extensions.has( 'OES_texture_float_linear' ) === true ) { + + state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1; + state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2; + + } else { + + state.rectAreaLTC1 = UniformsLib.LTC_HALF_1; + state.rectAreaLTC2 = UniformsLib.LTC_HALF_2; + + } + + } + + state.ambient[ 0 ] = r; + state.ambient[ 1 ] = g; + state.ambient[ 2 ] = b; + + const hash = state.hash; + + if ( hash.directionalLength !== directionalLength || + hash.pointLength !== pointLength || + hash.spotLength !== spotLength || + hash.rectAreaLength !== rectAreaLength || + hash.hemiLength !== hemiLength || + hash.numDirectionalShadows !== numDirectionalShadows || + hash.numPointShadows !== numPointShadows || + hash.numSpotShadows !== numSpotShadows || + hash.numSpotMaps !== numSpotMaps || + hash.numLightProbes !== numLightProbes ) { + + state.directional.length = directionalLength; + state.spot.length = spotLength; + state.rectArea.length = rectAreaLength; + state.point.length = pointLength; + state.hemi.length = hemiLength; + + state.directionalShadow.length = numDirectionalShadows; + state.directionalShadowMap.length = numDirectionalShadows; + state.pointShadow.length = numPointShadows; + state.pointShadowMap.length = numPointShadows; + state.spotShadow.length = numSpotShadows; + state.spotShadowMap.length = numSpotShadows; + state.directionalShadowMatrix.length = numDirectionalShadows; + state.pointShadowMatrix.length = numPointShadows; + state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps; + state.spotLightMap.length = numSpotMaps; + state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps; + state.numLightProbes = numLightProbes; + + hash.directionalLength = directionalLength; + hash.pointLength = pointLength; + hash.spotLength = spotLength; + hash.rectAreaLength = rectAreaLength; + hash.hemiLength = hemiLength; + + hash.numDirectionalShadows = numDirectionalShadows; + hash.numPointShadows = numPointShadows; + hash.numSpotShadows = numSpotShadows; + hash.numSpotMaps = numSpotMaps; + + hash.numLightProbes = numLightProbes; + + state.version = nextVersion ++; + + } + + } + + function setupView( lights, camera ) { + + let directionalLength = 0; + let pointLength = 0; + let spotLength = 0; + let rectAreaLength = 0; + let hemiLength = 0; + + const viewMatrix = camera.matrixWorldInverse; + + for ( let i = 0, l = lights.length; i < l; i ++ ) { + + const light = lights[ i ]; + + if ( light.isDirectionalLight ) { + + const uniforms = state.directional[ directionalLength ]; + + uniforms.direction.setFromMatrixPosition( light.matrixWorld ); + vector3.setFromMatrixPosition( light.target.matrixWorld ); + uniforms.direction.sub( vector3 ); + uniforms.direction.transformDirection( viewMatrix ); + + directionalLength ++; + + } else if ( light.isSpotLight ) { + + const uniforms = state.spot[ spotLength ]; + + uniforms.position.setFromMatrixPosition( light.matrixWorld ); + uniforms.position.applyMatrix4( viewMatrix ); + + uniforms.direction.setFromMatrixPosition( light.matrixWorld ); + vector3.setFromMatrixPosition( light.target.matrixWorld ); + uniforms.direction.sub( vector3 ); + uniforms.direction.transformDirection( viewMatrix ); + + spotLength ++; + + } else if ( light.isRectAreaLight ) { + + const uniforms = state.rectArea[ rectAreaLength ]; + + uniforms.position.setFromMatrixPosition( light.matrixWorld ); + uniforms.position.applyMatrix4( viewMatrix ); + + // extract local rotation of light to derive width/height half vectors + matrix42.identity(); + matrix4.copy( light.matrixWorld ); + matrix4.premultiply( viewMatrix ); + matrix42.extractRotation( matrix4 ); + + uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 ); + uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 ); + + uniforms.halfWidth.applyMatrix4( matrix42 ); + uniforms.halfHeight.applyMatrix4( matrix42 ); + + rectAreaLength ++; + + } else if ( light.isPointLight ) { + + const uniforms = state.point[ pointLength ]; + + uniforms.position.setFromMatrixPosition( light.matrixWorld ); + uniforms.position.applyMatrix4( viewMatrix ); + + pointLength ++; + + } else if ( light.isHemisphereLight ) { + + const uniforms = state.hemi[ hemiLength ]; + + uniforms.direction.setFromMatrixPosition( light.matrixWorld ); + uniforms.direction.transformDirection( viewMatrix ); + + hemiLength ++; + + } + + } + + } + + return { + setup: setup, + setupView: setupView, + state: state + }; + +} + +function WebGLRenderState( extensions ) { + + const lights = new WebGLLights( extensions ); + + const lightsArray = []; + const shadowsArray = []; + + function init( camera ) { + + state.camera = camera; + + lightsArray.length = 0; + shadowsArray.length = 0; + + } + + function pushLight( light ) { + + lightsArray.push( light ); + + } + + function pushShadow( shadowLight ) { + + shadowsArray.push( shadowLight ); + + } + + function setupLights() { + + lights.setup( lightsArray ); + + } + + function setupLightsView( camera ) { + + lights.setupView( lightsArray, camera ); + + } + + const state = { + lightsArray: lightsArray, + shadowsArray: shadowsArray, + + camera: null, + + lights: lights, + + transmissionRenderTarget: {} + }; + + return { + init: init, + state: state, + setupLights: setupLights, + setupLightsView: setupLightsView, + + pushLight: pushLight, + pushShadow: pushShadow + }; + +} + +function WebGLRenderStates( extensions ) { + + let renderStates = new WeakMap(); + + function get( scene, renderCallDepth = 0 ) { + + const renderStateArray = renderStates.get( scene ); + let renderState; + + if ( renderStateArray === undefined ) { + + renderState = new WebGLRenderState( extensions ); + renderStates.set( scene, [ renderState ] ); + + } else { + + if ( renderCallDepth >= renderStateArray.length ) { + + renderState = new WebGLRenderState( extensions ); + renderStateArray.push( renderState ); + + } else { + + renderState = renderStateArray[ renderCallDepth ]; + + } + + } + + return renderState; + + } + + function dispose() { + + renderStates = new WeakMap(); + + } + + return { + get: get, + dispose: dispose + }; + +} + +const vertex = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}"; + +const fragment = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"; + +function WebGLShadowMap( renderer, objects, capabilities ) { + + let _frustum = new Frustum(); + + const _shadowMapSize = new Vector2(), + _viewportSize = new Vector2(), + + _viewport = new Vector4(), + + _depthMaterial = new MeshDepthMaterial( { depthPacking: RGBADepthPacking } ), + _distanceMaterial = new MeshDistanceMaterial(), + + _materialCache = {}, + + _maxTextureSize = capabilities.maxTextureSize; + + const shadowSide = { [ FrontSide ]: BackSide, [ BackSide ]: FrontSide, [ DoubleSide ]: DoubleSide }; + + const shadowMaterialVertical = new ShaderMaterial( { + defines: { + VSM_SAMPLES: 8 + }, + uniforms: { + shadow_pass: { value: null }, + resolution: { value: new Vector2() }, + radius: { value: 4.0 } + }, + + vertexShader: vertex, + fragmentShader: fragment + + } ); + + const shadowMaterialHorizontal = shadowMaterialVertical.clone(); + shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1; + + const fullScreenTri = new BufferGeometry(); + fullScreenTri.setAttribute( + 'position', + new BufferAttribute( + new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ), + 3 + ) + ); + + const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical ); + + const scope = this; + + this.enabled = false; + + this.autoUpdate = true; + this.needsUpdate = false; + + this.type = PCFShadowMap; + let _previousType = this.type; + + this.render = function ( lights, scene, camera ) { + + if ( scope.enabled === false ) return; + if ( scope.autoUpdate === false && scope.needsUpdate === false ) return; + + if ( lights.length === 0 ) return; + + const currentRenderTarget = renderer.getRenderTarget(); + const activeCubeFace = renderer.getActiveCubeFace(); + const activeMipmapLevel = renderer.getActiveMipmapLevel(); + + const _state = renderer.state; + + // Set GL state for depth map. + _state.setBlending( NoBlending ); + _state.buffers.color.setClear( 1, 1, 1, 1 ); + _state.buffers.depth.setTest( true ); + _state.setScissorTest( false ); + + // check for shadow map type changes + + const toVSM = ( _previousType !== VSMShadowMap && this.type === VSMShadowMap ); + const fromVSM = ( _previousType === VSMShadowMap && this.type !== VSMShadowMap ); + + // render depth map + + for ( let i = 0, il = lights.length; i < il; i ++ ) { + + const light = lights[ i ]; + const shadow = light.shadow; + + if ( shadow === undefined ) { + + console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' ); + continue; + + } + + if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue; + + _shadowMapSize.copy( shadow.mapSize ); + + const shadowFrameExtents = shadow.getFrameExtents(); + + _shadowMapSize.multiply( shadowFrameExtents ); + + _viewportSize.copy( shadow.mapSize ); + + if ( _shadowMapSize.x > _maxTextureSize || _shadowMapSize.y > _maxTextureSize ) { + + if ( _shadowMapSize.x > _maxTextureSize ) { + + _viewportSize.x = Math.floor( _maxTextureSize / shadowFrameExtents.x ); + _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x; + shadow.mapSize.x = _viewportSize.x; + + } + + if ( _shadowMapSize.y > _maxTextureSize ) { + + _viewportSize.y = Math.floor( _maxTextureSize / shadowFrameExtents.y ); + _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y; + shadow.mapSize.y = _viewportSize.y; + + } + + } + + if ( shadow.map === null || toVSM === true || fromVSM === true ) { + + const pars = ( this.type !== VSMShadowMap ) ? { minFilter: NearestFilter, magFilter: NearestFilter } : {}; + + if ( shadow.map !== null ) { + + shadow.map.dispose(); + + } + + shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars ); + shadow.map.texture.name = light.name + '.shadowMap'; + + shadow.camera.updateProjectionMatrix(); + + } + + renderer.setRenderTarget( shadow.map ); + renderer.clear(); + + const viewportCount = shadow.getViewportCount(); + + for ( let vp = 0; vp < viewportCount; vp ++ ) { + + const viewport = shadow.getViewport( vp ); + + _viewport.set( + _viewportSize.x * viewport.x, + _viewportSize.y * viewport.y, + _viewportSize.x * viewport.z, + _viewportSize.y * viewport.w + ); + + _state.viewport( _viewport ); + + shadow.updateMatrices( light, vp ); + + _frustum = shadow.getFrustum(); + + renderObject( scene, camera, shadow.camera, light, this.type ); + + } + + // do blur pass for VSM + + if ( shadow.isPointLightShadow !== true && this.type === VSMShadowMap ) { + + VSMPass( shadow, camera ); + + } + + shadow.needsUpdate = false; + + } + + _previousType = this.type; + + scope.needsUpdate = false; + + renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel ); + + }; + + function VSMPass( shadow, camera ) { + + const geometry = objects.update( fullScreenMesh ); + + if ( shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples ) { + + shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples; + shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples; + + shadowMaterialVertical.needsUpdate = true; + shadowMaterialHorizontal.needsUpdate = true; + + } + + if ( shadow.mapPass === null ) { + + shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y ); + + } + + // vertical pass + + shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture; + shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize; + shadowMaterialVertical.uniforms.radius.value = shadow.radius; + renderer.setRenderTarget( shadow.mapPass ); + renderer.clear(); + renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null ); + + // horizontal pass + + shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture; + shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize; + shadowMaterialHorizontal.uniforms.radius.value = shadow.radius; + renderer.setRenderTarget( shadow.map ); + renderer.clear(); + renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null ); + + } + + function getDepthMaterial( object, material, light, type ) { + + let result = null; + + const customMaterial = ( light.isPointLight === true ) ? object.customDistanceMaterial : object.customDepthMaterial; + + if ( customMaterial !== undefined ) { + + result = customMaterial; + + } else { + + result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial; + + if ( ( renderer.localClippingEnabled && material.clipShadows === true && Array.isArray( material.clippingPlanes ) && material.clippingPlanes.length !== 0 ) || + ( material.displacementMap && material.displacementScale !== 0 ) || + ( material.alphaMap && material.alphaTest > 0 ) || + ( material.map && material.alphaTest > 0 ) ) { + + // in this case we need a unique material instance reflecting the + // appropriate state + + const keyA = result.uuid, keyB = material.uuid; + + let materialsForVariant = _materialCache[ keyA ]; + + if ( materialsForVariant === undefined ) { + + materialsForVariant = {}; + _materialCache[ keyA ] = materialsForVariant; + + } + + let cachedMaterial = materialsForVariant[ keyB ]; + + if ( cachedMaterial === undefined ) { + + cachedMaterial = result.clone(); + materialsForVariant[ keyB ] = cachedMaterial; + material.addEventListener( 'dispose', onMaterialDispose ); + + } + + result = cachedMaterial; + + } + + } + + result.visible = material.visible; + result.wireframe = material.wireframe; + + if ( type === VSMShadowMap ) { + + result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side; + + } else { + + result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ]; + + } + + result.alphaMap = material.alphaMap; + result.alphaTest = material.alphaTest; + result.map = material.map; + + result.clipShadows = material.clipShadows; + result.clippingPlanes = material.clippingPlanes; + result.clipIntersection = material.clipIntersection; + + result.displacementMap = material.displacementMap; + result.displacementScale = material.displacementScale; + result.displacementBias = material.displacementBias; + + result.wireframeLinewidth = material.wireframeLinewidth; + result.linewidth = material.linewidth; + + if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) { + + const materialProperties = renderer.properties.get( result ); + materialProperties.light = light; + + } + + return result; + + } + + function renderObject( object, camera, shadowCamera, light, type ) { + + if ( object.visible === false ) return; + + const visible = object.layers.test( camera.layers ); + + if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) { + + if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) { + + object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld ); + + const geometry = objects.update( object ); + const material = object.material; + + if ( Array.isArray( material ) ) { + + const groups = geometry.groups; + + for ( let k = 0, kl = groups.length; k < kl; k ++ ) { + + const group = groups[ k ]; + const groupMaterial = material[ group.materialIndex ]; + + if ( groupMaterial && groupMaterial.visible ) { + + const depthMaterial = getDepthMaterial( object, groupMaterial, light, type ); + + object.onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, group ); + + renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group ); + + object.onAfterShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, group ); + + } + + } + + } else if ( material.visible ) { + + const depthMaterial = getDepthMaterial( object, material, light, type ); + + object.onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, null ); + + renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null ); + + object.onAfterShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial, null ); + + } + + } + + } + + const children = object.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + renderObject( children[ i ], camera, shadowCamera, light, type ); + + } + + } + + function onMaterialDispose( event ) { + + const material = event.target; + + material.removeEventListener( 'dispose', onMaterialDispose ); + + // make sure to remove the unique distance/depth materials used for shadow map rendering + + for ( const id in _materialCache ) { + + const cache = _materialCache[ id ]; + + const uuid = event.target.uuid; + + if ( uuid in cache ) { + + const shadowMaterial = cache[ uuid ]; + shadowMaterial.dispose(); + delete cache[ uuid ]; + + } + + } + + } + +} + +const reversedFuncs = { + [ NeverDepth ]: AlwaysDepth, + [ LessDepth ]: GreaterDepth, + [ EqualDepth ]: NotEqualDepth, + [ LessEqualDepth ]: GreaterEqualDepth, + + [ AlwaysDepth ]: NeverDepth, + [ GreaterDepth ]: LessDepth, + [ NotEqualDepth ]: EqualDepth, + [ GreaterEqualDepth ]: LessEqualDepth, +}; + +function WebGLState( gl, extensions ) { + + function ColorBuffer() { + + let locked = false; + + const color = new Vector4(); + let currentColorMask = null; + const currentColorClear = new Vector4( 0, 0, 0, 0 ); + + return { + + setMask: function ( colorMask ) { + + if ( currentColorMask !== colorMask && ! locked ) { + + gl.colorMask( colorMask, colorMask, colorMask, colorMask ); + currentColorMask = colorMask; + + } + + }, + + setLocked: function ( lock ) { + + locked = lock; + + }, + + setClear: function ( r, g, b, a, premultipliedAlpha ) { + + if ( premultipliedAlpha === true ) { + + r *= a; g *= a; b *= a; + + } + + color.set( r, g, b, a ); + + if ( currentColorClear.equals( color ) === false ) { + + gl.clearColor( r, g, b, a ); + currentColorClear.copy( color ); + + } + + }, + + reset: function () { + + locked = false; + + currentColorMask = null; + currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state + + } + + }; + + } + + function DepthBuffer() { + + let locked = false; + let reversed = false; + + let currentDepthMask = null; + let currentDepthFunc = null; + let currentDepthClear = null; + + return { + + setReversed: function ( value ) { + + if ( reversed !== value ) { + + const ext = extensions.get( 'EXT_clip_control' ); + + if ( reversed ) { + + ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT ); + + } else { + + ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT ); + + } + + const oldDepth = currentDepthClear; + currentDepthClear = null; + this.setClear( oldDepth ); + + } + + reversed = value; + + }, + + getReversed: function () { + + return reversed; + + }, + + setTest: function ( depthTest ) { + + if ( depthTest ) { + + enable( gl.DEPTH_TEST ); + + } else { + + disable( gl.DEPTH_TEST ); + + } + + }, + + setMask: function ( depthMask ) { + + if ( currentDepthMask !== depthMask && ! locked ) { + + gl.depthMask( depthMask ); + currentDepthMask = depthMask; + + } + + }, + + setFunc: function ( depthFunc ) { + + if ( reversed ) depthFunc = reversedFuncs[ depthFunc ]; + + if ( currentDepthFunc !== depthFunc ) { + + switch ( depthFunc ) { + + case NeverDepth: + + gl.depthFunc( gl.NEVER ); + break; + + case AlwaysDepth: + + gl.depthFunc( gl.ALWAYS ); + break; + + case LessDepth: + + gl.depthFunc( gl.LESS ); + break; + + case LessEqualDepth: + + gl.depthFunc( gl.LEQUAL ); + break; + + case EqualDepth: + + gl.depthFunc( gl.EQUAL ); + break; + + case GreaterEqualDepth: + + gl.depthFunc( gl.GEQUAL ); + break; + + case GreaterDepth: + + gl.depthFunc( gl.GREATER ); + break; + + case NotEqualDepth: + + gl.depthFunc( gl.NOTEQUAL ); + break; + + default: + + gl.depthFunc( gl.LEQUAL ); + + } + + currentDepthFunc = depthFunc; + + } + + }, + + setLocked: function ( lock ) { + + locked = lock; + + }, + + setClear: function ( depth ) { + + if ( currentDepthClear !== depth ) { + + if ( reversed ) { + + depth = 1 - depth; + + } + + gl.clearDepth( depth ); + currentDepthClear = depth; + + } + + }, + + reset: function () { + + locked = false; + + currentDepthMask = null; + currentDepthFunc = null; + currentDepthClear = null; + reversed = false; + + } + + }; + + } + + function StencilBuffer() { + + let locked = false; + + let currentStencilMask = null; + let currentStencilFunc = null; + let currentStencilRef = null; + let currentStencilFuncMask = null; + let currentStencilFail = null; + let currentStencilZFail = null; + let currentStencilZPass = null; + let currentStencilClear = null; + + return { + + setTest: function ( stencilTest ) { + + if ( ! locked ) { + + if ( stencilTest ) { + + enable( gl.STENCIL_TEST ); + + } else { + + disable( gl.STENCIL_TEST ); + + } + + } + + }, + + setMask: function ( stencilMask ) { + + if ( currentStencilMask !== stencilMask && ! locked ) { + + gl.stencilMask( stencilMask ); + currentStencilMask = stencilMask; + + } + + }, + + setFunc: function ( stencilFunc, stencilRef, stencilMask ) { + + if ( currentStencilFunc !== stencilFunc || + currentStencilRef !== stencilRef || + currentStencilFuncMask !== stencilMask ) { + + gl.stencilFunc( stencilFunc, stencilRef, stencilMask ); + + currentStencilFunc = stencilFunc; + currentStencilRef = stencilRef; + currentStencilFuncMask = stencilMask; + + } + + }, + + setOp: function ( stencilFail, stencilZFail, stencilZPass ) { + + if ( currentStencilFail !== stencilFail || + currentStencilZFail !== stencilZFail || + currentStencilZPass !== stencilZPass ) { + + gl.stencilOp( stencilFail, stencilZFail, stencilZPass ); + + currentStencilFail = stencilFail; + currentStencilZFail = stencilZFail; + currentStencilZPass = stencilZPass; + + } + + }, + + setLocked: function ( lock ) { + + locked = lock; + + }, + + setClear: function ( stencil ) { + + if ( currentStencilClear !== stencil ) { + + gl.clearStencil( stencil ); + currentStencilClear = stencil; + + } + + }, + + reset: function () { + + locked = false; + + currentStencilMask = null; + currentStencilFunc = null; + currentStencilRef = null; + currentStencilFuncMask = null; + currentStencilFail = null; + currentStencilZFail = null; + currentStencilZPass = null; + currentStencilClear = null; + + } + + }; + + } + + // + + const colorBuffer = new ColorBuffer(); + const depthBuffer = new DepthBuffer(); + const stencilBuffer = new StencilBuffer(); + + const uboBindings = new WeakMap(); + const uboProgramMap = new WeakMap(); + + let enabledCapabilities = {}; + + let currentBoundFramebuffers = {}; + let currentDrawbuffers = new WeakMap(); + let defaultDrawbuffers = []; + + let currentProgram = null; + + let currentBlendingEnabled = false; + let currentBlending = null; + let currentBlendEquation = null; + let currentBlendSrc = null; + let currentBlendDst = null; + let currentBlendEquationAlpha = null; + let currentBlendSrcAlpha = null; + let currentBlendDstAlpha = null; + let currentBlendColor = new Color( 0, 0, 0 ); + let currentBlendAlpha = 0; + let currentPremultipledAlpha = false; + + let currentFlipSided = null; + let currentCullFace = null; + + let currentLineWidth = null; + + let currentPolygonOffsetFactor = null; + let currentPolygonOffsetUnits = null; + + const maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS ); + + let lineWidthAvailable = false; + let version = 0; + const glVersion = gl.getParameter( gl.VERSION ); + + if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) { + + version = parseFloat( /^WebGL (\d)/.exec( glVersion )[ 1 ] ); + lineWidthAvailable = ( version >= 1.0 ); + + } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) { + + version = parseFloat( /^OpenGL ES (\d)/.exec( glVersion )[ 1 ] ); + lineWidthAvailable = ( version >= 2.0 ); + + } + + let currentTextureSlot = null; + let currentBoundTextures = {}; + + const scissorParam = gl.getParameter( gl.SCISSOR_BOX ); + const viewportParam = gl.getParameter( gl.VIEWPORT ); + + const currentScissor = new Vector4().fromArray( scissorParam ); + const currentViewport = new Vector4().fromArray( viewportParam ); + + function createTexture( type, target, count, dimensions ) { + + const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4. + const texture = gl.createTexture(); + + gl.bindTexture( type, texture ); + gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST ); + gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST ); + + for ( let i = 0; i < count; i ++ ) { + + if ( type === gl.TEXTURE_3D || type === gl.TEXTURE_2D_ARRAY ) { + + gl.texImage3D( target, 0, gl.RGBA, 1, 1, dimensions, 0, gl.RGBA, gl.UNSIGNED_BYTE, data ); + + } else { + + gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data ); + + } + + } + + return texture; + + } + + const emptyTextures = {}; + emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 ); + emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 ); + emptyTextures[ gl.TEXTURE_2D_ARRAY ] = createTexture( gl.TEXTURE_2D_ARRAY, gl.TEXTURE_2D_ARRAY, 1, 1 ); + emptyTextures[ gl.TEXTURE_3D ] = createTexture( gl.TEXTURE_3D, gl.TEXTURE_3D, 1, 1 ); + + // init + + colorBuffer.setClear( 0, 0, 0, 1 ); + depthBuffer.setClear( 1 ); + stencilBuffer.setClear( 0 ); + + enable( gl.DEPTH_TEST ); + depthBuffer.setFunc( LessEqualDepth ); + + setFlipSided( false ); + setCullFace( CullFaceBack ); + enable( gl.CULL_FACE ); + + setBlending( NoBlending ); + + // + + function enable( id ) { + + if ( enabledCapabilities[ id ] !== true ) { + + gl.enable( id ); + enabledCapabilities[ id ] = true; + + } + + } + + function disable( id ) { + + if ( enabledCapabilities[ id ] !== false ) { + + gl.disable( id ); + enabledCapabilities[ id ] = false; + + } + + } + + function bindFramebuffer( target, framebuffer ) { + + if ( currentBoundFramebuffers[ target ] !== framebuffer ) { + + gl.bindFramebuffer( target, framebuffer ); + + currentBoundFramebuffers[ target ] = framebuffer; + + // gl.DRAW_FRAMEBUFFER is equivalent to gl.FRAMEBUFFER + + if ( target === gl.DRAW_FRAMEBUFFER ) { + + currentBoundFramebuffers[ gl.FRAMEBUFFER ] = framebuffer; + + } + + if ( target === gl.FRAMEBUFFER ) { + + currentBoundFramebuffers[ gl.DRAW_FRAMEBUFFER ] = framebuffer; + + } + + return true; + + } + + return false; + + } + + function drawBuffers( renderTarget, framebuffer ) { + + let drawBuffers = defaultDrawbuffers; + + let needsUpdate = false; + + if ( renderTarget ) { + + drawBuffers = currentDrawbuffers.get( framebuffer ); + + if ( drawBuffers === undefined ) { + + drawBuffers = []; + currentDrawbuffers.set( framebuffer, drawBuffers ); + + } + + const textures = renderTarget.textures; + + if ( drawBuffers.length !== textures.length || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) { + + for ( let i = 0, il = textures.length; i < il; i ++ ) { + + drawBuffers[ i ] = gl.COLOR_ATTACHMENT0 + i; + + } + + drawBuffers.length = textures.length; + + needsUpdate = true; + + } + + } else { + + if ( drawBuffers[ 0 ] !== gl.BACK ) { + + drawBuffers[ 0 ] = gl.BACK; + + needsUpdate = true; + + } + + } + + if ( needsUpdate ) { + + gl.drawBuffers( drawBuffers ); + + } + + } + + function useProgram( program ) { + + if ( currentProgram !== program ) { + + gl.useProgram( program ); + + currentProgram = program; + + return true; + + } + + return false; + + } + + const equationToGL = { + [ AddEquation ]: gl.FUNC_ADD, + [ SubtractEquation ]: gl.FUNC_SUBTRACT, + [ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT + }; + + equationToGL[ MinEquation ] = gl.MIN; + equationToGL[ MaxEquation ] = gl.MAX; + + const factorToGL = { + [ ZeroFactor ]: gl.ZERO, + [ OneFactor ]: gl.ONE, + [ SrcColorFactor ]: gl.SRC_COLOR, + [ SrcAlphaFactor ]: gl.SRC_ALPHA, + [ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE, + [ DstColorFactor ]: gl.DST_COLOR, + [ DstAlphaFactor ]: gl.DST_ALPHA, + [ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR, + [ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA, + [ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR, + [ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA, + [ ConstantColorFactor ]: gl.CONSTANT_COLOR, + [ OneMinusConstantColorFactor ]: gl.ONE_MINUS_CONSTANT_COLOR, + [ ConstantAlphaFactor ]: gl.CONSTANT_ALPHA, + [ OneMinusConstantAlphaFactor ]: gl.ONE_MINUS_CONSTANT_ALPHA + }; + + function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, blendColor, blendAlpha, premultipliedAlpha ) { + + if ( blending === NoBlending ) { + + if ( currentBlendingEnabled === true ) { + + disable( gl.BLEND ); + currentBlendingEnabled = false; + + } + + return; + + } + + if ( currentBlendingEnabled === false ) { + + enable( gl.BLEND ); + currentBlendingEnabled = true; + + } + + if ( blending !== CustomBlending ) { + + if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) { + + if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) { + + gl.blendEquation( gl.FUNC_ADD ); + + currentBlendEquation = AddEquation; + currentBlendEquationAlpha = AddEquation; + + } + + if ( premultipliedAlpha ) { + + switch ( blending ) { + + case NormalBlending: + gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); + break; + + case AdditiveBlending: + gl.blendFunc( gl.ONE, gl.ONE ); + break; + + case SubtractiveBlending: + gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE ); + break; + + case MultiplyBlending: + gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA ); + break; + + default: + console.error( 'THREE.WebGLState: Invalid blending: ', blending ); + break; + + } + + } else { + + switch ( blending ) { + + case NormalBlending: + gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); + break; + + case AdditiveBlending: + gl.blendFunc( gl.SRC_ALPHA, gl.ONE ); + break; + + case SubtractiveBlending: + gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE ); + break; + + case MultiplyBlending: + gl.blendFunc( gl.ZERO, gl.SRC_COLOR ); + break; + + default: + console.error( 'THREE.WebGLState: Invalid blending: ', blending ); + break; + + } + + } + + currentBlendSrc = null; + currentBlendDst = null; + currentBlendSrcAlpha = null; + currentBlendDstAlpha = null; + currentBlendColor.set( 0, 0, 0 ); + currentBlendAlpha = 0; + + currentBlending = blending; + currentPremultipledAlpha = premultipliedAlpha; + + } + + return; + + } + + // custom blending + + blendEquationAlpha = blendEquationAlpha || blendEquation; + blendSrcAlpha = blendSrcAlpha || blendSrc; + blendDstAlpha = blendDstAlpha || blendDst; + + if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) { + + gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] ); + + currentBlendEquation = blendEquation; + currentBlendEquationAlpha = blendEquationAlpha; + + } + + if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) { + + gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] ); + + currentBlendSrc = blendSrc; + currentBlendDst = blendDst; + currentBlendSrcAlpha = blendSrcAlpha; + currentBlendDstAlpha = blendDstAlpha; + + } + + if ( blendColor.equals( currentBlendColor ) === false || blendAlpha !== currentBlendAlpha ) { + + gl.blendColor( blendColor.r, blendColor.g, blendColor.b, blendAlpha ); + + currentBlendColor.copy( blendColor ); + currentBlendAlpha = blendAlpha; + + } + + currentBlending = blending; + currentPremultipledAlpha = false; + + } + + function setMaterial( material, frontFaceCW ) { + + material.side === DoubleSide + ? disable( gl.CULL_FACE ) + : enable( gl.CULL_FACE ); + + let flipSided = ( material.side === BackSide ); + if ( frontFaceCW ) flipSided = ! flipSided; + + setFlipSided( flipSided ); + + ( material.blending === NormalBlending && material.transparent === false ) + ? setBlending( NoBlending ) + : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha ); + + depthBuffer.setFunc( material.depthFunc ); + depthBuffer.setTest( material.depthTest ); + depthBuffer.setMask( material.depthWrite ); + colorBuffer.setMask( material.colorWrite ); + + const stencilWrite = material.stencilWrite; + stencilBuffer.setTest( stencilWrite ); + if ( stencilWrite ) { + + stencilBuffer.setMask( material.stencilWriteMask ); + stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask ); + stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass ); + + } + + setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits ); + + material.alphaToCoverage === true + ? enable( gl.SAMPLE_ALPHA_TO_COVERAGE ) + : disable( gl.SAMPLE_ALPHA_TO_COVERAGE ); + + } + + // + + function setFlipSided( flipSided ) { + + if ( currentFlipSided !== flipSided ) { + + if ( flipSided ) { + + gl.frontFace( gl.CW ); + + } else { + + gl.frontFace( gl.CCW ); + + } + + currentFlipSided = flipSided; + + } + + } + + function setCullFace( cullFace ) { + + if ( cullFace !== CullFaceNone ) { + + enable( gl.CULL_FACE ); + + if ( cullFace !== currentCullFace ) { + + if ( cullFace === CullFaceBack ) { + + gl.cullFace( gl.BACK ); + + } else if ( cullFace === CullFaceFront ) { + + gl.cullFace( gl.FRONT ); + + } else { + + gl.cullFace( gl.FRONT_AND_BACK ); + + } + + } + + } else { + + disable( gl.CULL_FACE ); + + } + + currentCullFace = cullFace; + + } + + function setLineWidth( width ) { + + if ( width !== currentLineWidth ) { + + if ( lineWidthAvailable ) gl.lineWidth( width ); + + currentLineWidth = width; + + } + + } + + function setPolygonOffset( polygonOffset, factor, units ) { + + if ( polygonOffset ) { + + enable( gl.POLYGON_OFFSET_FILL ); + + if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) { + + gl.polygonOffset( factor, units ); + + currentPolygonOffsetFactor = factor; + currentPolygonOffsetUnits = units; + + } + + } else { + + disable( gl.POLYGON_OFFSET_FILL ); + + } + + } + + function setScissorTest( scissorTest ) { + + if ( scissorTest ) { + + enable( gl.SCISSOR_TEST ); + + } else { + + disable( gl.SCISSOR_TEST ); + + } + + } + + // texture + + function activeTexture( webglSlot ) { + + if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1; + + if ( currentTextureSlot !== webglSlot ) { + + gl.activeTexture( webglSlot ); + currentTextureSlot = webglSlot; + + } + + } + + function bindTexture( webglType, webglTexture, webglSlot ) { + + if ( webglSlot === undefined ) { + + if ( currentTextureSlot === null ) { + + webglSlot = gl.TEXTURE0 + maxTextures - 1; + + } else { + + webglSlot = currentTextureSlot; + + } + + } + + let boundTexture = currentBoundTextures[ webglSlot ]; + + if ( boundTexture === undefined ) { + + boundTexture = { type: undefined, texture: undefined }; + currentBoundTextures[ webglSlot ] = boundTexture; + + } + + if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) { + + if ( currentTextureSlot !== webglSlot ) { + + gl.activeTexture( webglSlot ); + currentTextureSlot = webglSlot; + + } + + gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] ); + + boundTexture.type = webglType; + boundTexture.texture = webglTexture; + + } + + } + + function unbindTexture() { + + const boundTexture = currentBoundTextures[ currentTextureSlot ]; + + if ( boundTexture !== undefined && boundTexture.type !== undefined ) { + + gl.bindTexture( boundTexture.type, null ); + + boundTexture.type = undefined; + boundTexture.texture = undefined; + + } + + } + + function compressedTexImage2D() { + + try { + + gl.compressedTexImage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function compressedTexImage3D() { + + try { + + gl.compressedTexImage3D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texSubImage2D() { + + try { + + gl.texSubImage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texSubImage3D() { + + try { + + gl.texSubImage3D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function compressedTexSubImage2D() { + + try { + + gl.compressedTexSubImage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function compressedTexSubImage3D() { + + try { + + gl.compressedTexSubImage3D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texStorage2D() { + + try { + + gl.texStorage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texStorage3D() { + + try { + + gl.texStorage3D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texImage2D() { + + try { + + gl.texImage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texImage3D() { + + try { + + gl.texImage3D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + // + + function scissor( scissor ) { + + if ( currentScissor.equals( scissor ) === false ) { + + gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w ); + currentScissor.copy( scissor ); + + } + + } + + function viewport( viewport ) { + + if ( currentViewport.equals( viewport ) === false ) { + + gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w ); + currentViewport.copy( viewport ); + + } + + } + + function updateUBOMapping( uniformsGroup, program ) { + + let mapping = uboProgramMap.get( program ); + + if ( mapping === undefined ) { + + mapping = new WeakMap(); + + uboProgramMap.set( program, mapping ); + + } + + let blockIndex = mapping.get( uniformsGroup ); + + if ( blockIndex === undefined ) { + + blockIndex = gl.getUniformBlockIndex( program, uniformsGroup.name ); + + mapping.set( uniformsGroup, blockIndex ); + + } + + } + + function uniformBlockBinding( uniformsGroup, program ) { + + const mapping = uboProgramMap.get( program ); + const blockIndex = mapping.get( uniformsGroup ); + + if ( uboBindings.get( program ) !== blockIndex ) { + + // bind shader specific block index to global block point + gl.uniformBlockBinding( program, blockIndex, uniformsGroup.__bindingPointIndex ); + + uboBindings.set( program, blockIndex ); + + } + + } + + // + + function reset() { + + // reset state + + gl.disable( gl.BLEND ); + gl.disable( gl.CULL_FACE ); + gl.disable( gl.DEPTH_TEST ); + gl.disable( gl.POLYGON_OFFSET_FILL ); + gl.disable( gl.SCISSOR_TEST ); + gl.disable( gl.STENCIL_TEST ); + gl.disable( gl.SAMPLE_ALPHA_TO_COVERAGE ); + + gl.blendEquation( gl.FUNC_ADD ); + gl.blendFunc( gl.ONE, gl.ZERO ); + gl.blendFuncSeparate( gl.ONE, gl.ZERO, gl.ONE, gl.ZERO ); + gl.blendColor( 0, 0, 0, 0 ); + + gl.colorMask( true, true, true, true ); + gl.clearColor( 0, 0, 0, 0 ); + + gl.depthMask( true ); + gl.depthFunc( gl.LESS ); + + depthBuffer.setReversed( false ); + + gl.clearDepth( 1 ); + + gl.stencilMask( 0xffffffff ); + gl.stencilFunc( gl.ALWAYS, 0, 0xffffffff ); + gl.stencilOp( gl.KEEP, gl.KEEP, gl.KEEP ); + gl.clearStencil( 0 ); + + gl.cullFace( gl.BACK ); + gl.frontFace( gl.CCW ); + + gl.polygonOffset( 0, 0 ); + + gl.activeTexture( gl.TEXTURE0 ); + + gl.bindFramebuffer( gl.FRAMEBUFFER, null ); + gl.bindFramebuffer( gl.DRAW_FRAMEBUFFER, null ); + gl.bindFramebuffer( gl.READ_FRAMEBUFFER, null ); + + gl.useProgram( null ); + + gl.lineWidth( 1 ); + + gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height ); + gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height ); + + // reset internals + + enabledCapabilities = {}; + + currentTextureSlot = null; + currentBoundTextures = {}; + + currentBoundFramebuffers = {}; + currentDrawbuffers = new WeakMap(); + defaultDrawbuffers = []; + + currentProgram = null; + + currentBlendingEnabled = false; + currentBlending = null; + currentBlendEquation = null; + currentBlendSrc = null; + currentBlendDst = null; + currentBlendEquationAlpha = null; + currentBlendSrcAlpha = null; + currentBlendDstAlpha = null; + currentBlendColor = new Color( 0, 0, 0 ); + currentBlendAlpha = 0; + currentPremultipledAlpha = false; + + currentFlipSided = null; + currentCullFace = null; + + currentLineWidth = null; + + currentPolygonOffsetFactor = null; + currentPolygonOffsetUnits = null; + + currentScissor.set( 0, 0, gl.canvas.width, gl.canvas.height ); + currentViewport.set( 0, 0, gl.canvas.width, gl.canvas.height ); + + colorBuffer.reset(); + depthBuffer.reset(); + stencilBuffer.reset(); + + } + + return { + + buffers: { + color: colorBuffer, + depth: depthBuffer, + stencil: stencilBuffer + }, + + enable: enable, + disable: disable, + + bindFramebuffer: bindFramebuffer, + drawBuffers: drawBuffers, + + useProgram: useProgram, + + setBlending: setBlending, + setMaterial: setMaterial, + + setFlipSided: setFlipSided, + setCullFace: setCullFace, + + setLineWidth: setLineWidth, + setPolygonOffset: setPolygonOffset, + + setScissorTest: setScissorTest, + + activeTexture: activeTexture, + bindTexture: bindTexture, + unbindTexture: unbindTexture, + compressedTexImage2D: compressedTexImage2D, + compressedTexImage3D: compressedTexImage3D, + texImage2D: texImage2D, + texImage3D: texImage3D, + + updateUBOMapping: updateUBOMapping, + uniformBlockBinding: uniformBlockBinding, + + texStorage2D: texStorage2D, + texStorage3D: texStorage3D, + texSubImage2D: texSubImage2D, + texSubImage3D: texSubImage3D, + compressedTexSubImage2D: compressedTexSubImage2D, + compressedTexSubImage3D: compressedTexSubImage3D, + + scissor: scissor, + viewport: viewport, + + reset: reset + + }; + +} + +function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) { + + const multisampledRTTExt = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null; + const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent ); + + const _imageDimensions = new Vector2(); + const _videoTextures = new WeakMap(); + let _canvas; + + const _sources = new WeakMap(); // maps WebglTexture objects to instances of Source + + // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas, + // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")! + // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d). + + let useOffscreenCanvas = false; + + try { + + useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' + // eslint-disable-next-line compat/compat + && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null; + + } catch ( err ) { + + // Ignore any errors + + } + + function createCanvas( width, height ) { + + // Use OffscreenCanvas when available. Specially needed in web workers + + return useOffscreenCanvas ? + // eslint-disable-next-line compat/compat + new OffscreenCanvas( width, height ) : createElementNS( 'canvas' ); + + } + + function resizeImage( image, needsNewCanvas, maxSize ) { + + let scale = 1; + + const dimensions = getDimensions( image ); + + // handle case if texture exceeds max size + + if ( dimensions.width > maxSize || dimensions.height > maxSize ) { + + scale = maxSize / Math.max( dimensions.width, dimensions.height ); + + } + + // only perform resize if necessary + + if ( scale < 1 ) { + + // only perform resize for certain image types + + if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || + ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) || + ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) || + ( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) ) { + + const width = Math.floor( scale * dimensions.width ); + const height = Math.floor( scale * dimensions.height ); + + if ( _canvas === undefined ) _canvas = createCanvas( width, height ); + + // cube textures can't reuse the same canvas + + const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas; + + canvas.width = width; + canvas.height = height; + + const context = canvas.getContext( '2d' ); + context.drawImage( image, 0, 0, width, height ); + + console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + dimensions.width + 'x' + dimensions.height + ') to (' + width + 'x' + height + ').' ); + + return canvas; + + } else { + + if ( 'data' in image ) { + + console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + dimensions.width + 'x' + dimensions.height + ').' ); + + } + + return image; + + } + + } + + return image; + + } + + function textureNeedsGenerateMipmaps( texture ) { + + return texture.generateMipmaps; + + } + + function generateMipmap( target ) { + + _gl.generateMipmap( target ); + + } + + function getTargetType( texture ) { + + if ( texture.isWebGLCubeRenderTarget ) return _gl.TEXTURE_CUBE_MAP; + if ( texture.isWebGL3DRenderTarget ) return _gl.TEXTURE_3D; + if ( texture.isWebGLArrayRenderTarget || texture.isCompressedArrayTexture ) return _gl.TEXTURE_2D_ARRAY; + return _gl.TEXTURE_2D; + + } + + function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) { + + if ( internalFormatName !== null ) { + + if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ]; + + console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' ); + + } + + let internalFormat = glFormat; + + if ( glFormat === _gl.RED ) { + + if ( glType === _gl.FLOAT ) internalFormat = _gl.R32F; + if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.R16F; + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8; + + } + + if ( glFormat === _gl.RED_INTEGER ) { + + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8UI; + if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.R16UI; + if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.R32UI; + if ( glType === _gl.BYTE ) internalFormat = _gl.R8I; + if ( glType === _gl.SHORT ) internalFormat = _gl.R16I; + if ( glType === _gl.INT ) internalFormat = _gl.R32I; + + } + + if ( glFormat === _gl.RG ) { + + if ( glType === _gl.FLOAT ) internalFormat = _gl.RG32F; + if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RG16F; + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8; + + } + + if ( glFormat === _gl.RG_INTEGER ) { + + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8UI; + if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RG16UI; + if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RG32UI; + if ( glType === _gl.BYTE ) internalFormat = _gl.RG8I; + if ( glType === _gl.SHORT ) internalFormat = _gl.RG16I; + if ( glType === _gl.INT ) internalFormat = _gl.RG32I; + + } + + if ( glFormat === _gl.RGB_INTEGER ) { + + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGB8UI; + if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RGB16UI; + if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RGB32UI; + if ( glType === _gl.BYTE ) internalFormat = _gl.RGB8I; + if ( glType === _gl.SHORT ) internalFormat = _gl.RGB16I; + if ( glType === _gl.INT ) internalFormat = _gl.RGB32I; + + } + + if ( glFormat === _gl.RGBA_INTEGER ) { + + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGBA8UI; + if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RGBA16UI; + if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RGBA32UI; + if ( glType === _gl.BYTE ) internalFormat = _gl.RGBA8I; + if ( glType === _gl.SHORT ) internalFormat = _gl.RGBA16I; + if ( glType === _gl.INT ) internalFormat = _gl.RGBA32I; + + } + + if ( glFormat === _gl.RGB ) { + + if ( glType === _gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = _gl.RGB9_E5; + + } + + if ( glFormat === _gl.RGBA ) { + + const transfer = forceLinearTransfer ? LinearTransfer : ColorManagement.getTransfer( colorSpace ); + + if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F; + if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F; + if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8; + if ( glType === _gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = _gl.RGBA4; + if ( glType === _gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = _gl.RGB5_A1; + + } + + if ( internalFormat === _gl.R16F || internalFormat === _gl.R32F || + internalFormat === _gl.RG16F || internalFormat === _gl.RG32F || + internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F ) { + + extensions.get( 'EXT_color_buffer_float' ); + + } + + return internalFormat; + + } + + function getInternalDepthFormat( useStencil, depthType ) { + + let glInternalFormat; + if ( useStencil ) { + + if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) { + + glInternalFormat = _gl.DEPTH24_STENCIL8; + + } else if ( depthType === FloatType ) { + + glInternalFormat = _gl.DEPTH32F_STENCIL8; + + } else if ( depthType === UnsignedShortType ) { + + glInternalFormat = _gl.DEPTH24_STENCIL8; + console.warn( 'DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.' ); + + } + + } else { + + if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) { + + glInternalFormat = _gl.DEPTH_COMPONENT24; + + } else if ( depthType === FloatType ) { + + glInternalFormat = _gl.DEPTH_COMPONENT32F; + + } else if ( depthType === UnsignedShortType ) { + + glInternalFormat = _gl.DEPTH_COMPONENT16; + + } + + } + + return glInternalFormat; + + } + + function getMipLevels( texture, image ) { + + if ( textureNeedsGenerateMipmaps( texture ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) { + + return Math.log2( Math.max( image.width, image.height ) ) + 1; + + } else if ( texture.mipmaps !== undefined && texture.mipmaps.length > 0 ) { + + // user-defined mipmaps + + return texture.mipmaps.length; + + } else if ( texture.isCompressedTexture && Array.isArray( texture.image ) ) { + + return image.mipmaps.length; + + } else { + + // texture without mipmaps (only base level) + + return 1; + + } + + } + + // + + function onTextureDispose( event ) { + + const texture = event.target; + + texture.removeEventListener( 'dispose', onTextureDispose ); + + deallocateTexture( texture ); + + if ( texture.isVideoTexture ) { + + _videoTextures.delete( texture ); + + } + + } + + function onRenderTargetDispose( event ) { + + const renderTarget = event.target; + + renderTarget.removeEventListener( 'dispose', onRenderTargetDispose ); + + deallocateRenderTarget( renderTarget ); + + } + + // + + function deallocateTexture( texture ) { + + const textureProperties = properties.get( texture ); + + if ( textureProperties.__webglInit === undefined ) return; + + // check if it's necessary to remove the WebGLTexture object + + const source = texture.source; + const webglTextures = _sources.get( source ); + + if ( webglTextures ) { + + const webglTexture = webglTextures[ textureProperties.__cacheKey ]; + webglTexture.usedTimes --; + + // the WebGLTexture object is not used anymore, remove it + + if ( webglTexture.usedTimes === 0 ) { + + deleteTexture( texture ); + + } + + // remove the weak map entry if no WebGLTexture uses the source anymore + + if ( Object.keys( webglTextures ).length === 0 ) { + + _sources.delete( source ); + + } + + } + + properties.remove( texture ); + + } + + function deleteTexture( texture ) { + + const textureProperties = properties.get( texture ); + _gl.deleteTexture( textureProperties.__webglTexture ); + + const source = texture.source; + const webglTextures = _sources.get( source ); + delete webglTextures[ textureProperties.__cacheKey ]; + + info.memory.textures --; + + } + + function deallocateRenderTarget( renderTarget ) { + + const renderTargetProperties = properties.get( renderTarget ); + + if ( renderTarget.depthTexture ) { + + renderTarget.depthTexture.dispose(); + + properties.remove( renderTarget.depthTexture ); + + } + + if ( renderTarget.isWebGLCubeRenderTarget ) { + + for ( let i = 0; i < 6; i ++ ) { + + if ( Array.isArray( renderTargetProperties.__webglFramebuffer[ i ] ) ) { + + for ( let level = 0; level < renderTargetProperties.__webglFramebuffer[ i ].length; level ++ ) _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ][ level ] ); + + } else { + + _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] ); + + } + + if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] ); + + } + + } else { + + if ( Array.isArray( renderTargetProperties.__webglFramebuffer ) ) { + + for ( let level = 0; level < renderTargetProperties.__webglFramebuffer.length; level ++ ) _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ level ] ); + + } else { + + _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer ); + + } + + if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer ); + if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer ); + + if ( renderTargetProperties.__webglColorRenderbuffer ) { + + for ( let i = 0; i < renderTargetProperties.__webglColorRenderbuffer.length; i ++ ) { + + if ( renderTargetProperties.__webglColorRenderbuffer[ i ] ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer[ i ] ); + + } + + } + + if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer ); + + } + + const textures = renderTarget.textures; + + for ( let i = 0, il = textures.length; i < il; i ++ ) { + + const attachmentProperties = properties.get( textures[ i ] ); + + if ( attachmentProperties.__webglTexture ) { + + _gl.deleteTexture( attachmentProperties.__webglTexture ); + + info.memory.textures --; + + } + + properties.remove( textures[ i ] ); + + } + + properties.remove( renderTarget ); + + } + + // + + let textureUnits = 0; + + function resetTextureUnits() { + + textureUnits = 0; + + } + + function allocateTextureUnit() { + + const textureUnit = textureUnits; + + if ( textureUnit >= capabilities.maxTextures ) { + + console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures ); + + } + + textureUnits += 1; + + return textureUnit; + + } + + function getTextureCacheKey( texture ) { + + const array = []; + + array.push( texture.wrapS ); + array.push( texture.wrapT ); + array.push( texture.wrapR || 0 ); + array.push( texture.magFilter ); + array.push( texture.minFilter ); + array.push( texture.anisotropy ); + array.push( texture.internalFormat ); + array.push( texture.format ); + array.push( texture.type ); + array.push( texture.generateMipmaps ); + array.push( texture.premultiplyAlpha ); + array.push( texture.flipY ); + array.push( texture.unpackAlignment ); + array.push( texture.colorSpace ); + + return array.join(); + + } + + // + + function setTexture2D( texture, slot ) { + + const textureProperties = properties.get( texture ); + + if ( texture.isVideoTexture ) updateVideoTexture( texture ); + + if ( texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version ) { + + const image = texture.image; + + if ( image === null ) { + + console.warn( 'THREE.WebGLRenderer: Texture marked for update but no image data found.' ); + + } else if ( image.complete === false ) { + + console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' ); + + } else { + + uploadTexture( textureProperties, texture, slot ); + return; + + } + + } + + state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); + + } + + function setTexture2DArray( texture, slot ) { + + const textureProperties = properties.get( texture ); + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + uploadTexture( textureProperties, texture, slot ); + return; + + } + + state.bindTexture( _gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); + + } + + function setTexture3D( texture, slot ) { + + const textureProperties = properties.get( texture ); + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + uploadTexture( textureProperties, texture, slot ); + return; + + } + + state.bindTexture( _gl.TEXTURE_3D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); + + } + + function setTextureCube( texture, slot ) { + + const textureProperties = properties.get( texture ); + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + uploadCubeTexture( textureProperties, texture, slot ); + return; + + } + + state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); + + } + + const wrappingToGL = { + [ RepeatWrapping ]: _gl.REPEAT, + [ ClampToEdgeWrapping ]: _gl.CLAMP_TO_EDGE, + [ MirroredRepeatWrapping ]: _gl.MIRRORED_REPEAT + }; + + const filterToGL = { + [ NearestFilter ]: _gl.NEAREST, + [ NearestMipmapNearestFilter ]: _gl.NEAREST_MIPMAP_NEAREST, + [ NearestMipmapLinearFilter ]: _gl.NEAREST_MIPMAP_LINEAR, + + [ LinearFilter ]: _gl.LINEAR, + [ LinearMipmapNearestFilter ]: _gl.LINEAR_MIPMAP_NEAREST, + [ LinearMipmapLinearFilter ]: _gl.LINEAR_MIPMAP_LINEAR + }; + + const compareToGL = { + [ NeverCompare ]: _gl.NEVER, + [ AlwaysCompare ]: _gl.ALWAYS, + [ LessCompare ]: _gl.LESS, + [ LessEqualCompare ]: _gl.LEQUAL, + [ EqualCompare ]: _gl.EQUAL, + [ GreaterEqualCompare ]: _gl.GEQUAL, + [ GreaterCompare ]: _gl.GREATER, + [ NotEqualCompare ]: _gl.NOTEQUAL + }; + + function setTextureParameters( textureType, texture ) { + + if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false && + ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter || + texture.minFilter === LinearFilter || texture.minFilter === LinearMipmapNearestFilter || texture.minFilter === NearestMipmapLinearFilter || texture.minFilter === LinearMipmapLinearFilter ) ) { + + console.warn( 'THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.' ); + + } + + _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] ); + _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] ); + + if ( textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY ) { + + _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] ); + + } + + _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] ); + _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] ); + + if ( texture.compareFunction ) { + + _gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE ); + _gl.texParameteri( textureType, _gl.TEXTURE_COMPARE_FUNC, compareToGL[ texture.compareFunction ] ); + + } + + if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) { + + if ( texture.magFilter === NearestFilter ) return; + if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return; + if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension + + if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) { + + const extension = extensions.get( 'EXT_texture_filter_anisotropic' ); + _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) ); + properties.get( texture ).__currentAnisotropy = texture.anisotropy; + + } + + } + + } + + function initTexture( textureProperties, texture ) { + + let forceUpload = false; + + if ( textureProperties.__webglInit === undefined ) { + + textureProperties.__webglInit = true; + + texture.addEventListener( 'dispose', onTextureDispose ); + + } + + // create Source <-> WebGLTextures mapping if necessary + + const source = texture.source; + let webglTextures = _sources.get( source ); + + if ( webglTextures === undefined ) { + + webglTextures = {}; + _sources.set( source, webglTextures ); + + } + + // check if there is already a WebGLTexture object for the given texture parameters + + const textureCacheKey = getTextureCacheKey( texture ); + + if ( textureCacheKey !== textureProperties.__cacheKey ) { + + // if not, create a new instance of WebGLTexture + + if ( webglTextures[ textureCacheKey ] === undefined ) { + + // create new entry + + webglTextures[ textureCacheKey ] = { + texture: _gl.createTexture(), + usedTimes: 0 + }; + + info.memory.textures ++; + + // when a new instance of WebGLTexture was created, a texture upload is required + // even if the image contents are identical + + forceUpload = true; + + } + + webglTextures[ textureCacheKey ].usedTimes ++; + + // every time the texture cache key changes, it's necessary to check if an instance of + // WebGLTexture can be deleted in order to avoid a memory leak. + + const webglTexture = webglTextures[ textureProperties.__cacheKey ]; + + if ( webglTexture !== undefined ) { + + webglTextures[ textureProperties.__cacheKey ].usedTimes --; + + if ( webglTexture.usedTimes === 0 ) { + + deleteTexture( texture ); + + } + + } + + // store references to cache key and WebGLTexture object + + textureProperties.__cacheKey = textureCacheKey; + textureProperties.__webglTexture = webglTextures[ textureCacheKey ].texture; + + } + + return forceUpload; + + } + + function uploadTexture( textureProperties, texture, slot ) { + + let textureType = _gl.TEXTURE_2D; + + if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) textureType = _gl.TEXTURE_2D_ARRAY; + if ( texture.isData3DTexture ) textureType = _gl.TEXTURE_3D; + + const forceUpload = initTexture( textureProperties, texture ); + const source = texture.source; + + state.bindTexture( textureType, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); + + const sourceProperties = properties.get( source ); + + if ( source.version !== sourceProperties.__version || forceUpload === true ) { + + state.activeTexture( _gl.TEXTURE0 + slot ); + + const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace ); + const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace ); + const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL; + + _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY ); + _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha ); + _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment ); + _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion ); + + let image = resizeImage( texture.image, false, capabilities.maxTextureSize ); + image = verifyColorSpace( texture, image ); + + const glFormat = utils.convert( texture.format, texture.colorSpace ); + + const glType = utils.convert( texture.type ); + let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture ); + + setTextureParameters( textureType, texture ); + + let mipmap; + const mipmaps = texture.mipmaps; + + const useTexStorage = ( texture.isVideoTexture !== true ); + const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true ); + const dataReady = source.dataReady; + const levels = getMipLevels( texture, image ); + + if ( texture.isDepthTexture ) { + + glInternalFormat = getInternalDepthFormat( texture.format === DepthStencilFormat, texture.type ); + + // + + if ( allocateMemory ) { + + if ( useTexStorage ) { + + state.texStorage2D( _gl.TEXTURE_2D, 1, glInternalFormat, image.width, image.height ); + + } else { + + state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null ); + + } + + } + + } else if ( texture.isDataTexture ) { + + // use manually created mipmaps if available + // if there are no manual mipmaps + // set 0 level mipmap and then use GL to generate other mipmap levels + + if ( mipmaps.length > 0 ) { + + if ( useTexStorage && allocateMemory ) { + + state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height ); + + } + + for ( let i = 0, il = mipmaps.length; i < il; i ++ ) { + + mipmap = mipmaps[ i ]; + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); + + } + + } + + texture.generateMipmaps = false; + + } else { + + if ( useTexStorage ) { + + if ( allocateMemory ) { + + state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height ); + + } + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data ); + + } + + } + + } else if ( texture.isCompressedTexture ) { + + if ( texture.isCompressedArrayTexture ) { + + if ( useTexStorage && allocateMemory ) { + + state.texStorage3D( _gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height, image.depth ); + + } + + for ( let i = 0, il = mipmaps.length; i < il; i ++ ) { + + mipmap = mipmaps[ i ]; + + if ( texture.format !== RGBAFormat ) { + + if ( glFormat !== null ) { + + if ( useTexStorage ) { + + if ( dataReady ) { + + if ( texture.layerUpdates.size > 0 ) { + + const layerByteLength = getByteLength( mipmap.width, mipmap.height, texture.format, texture.type ); + + for ( const layerIndex of texture.layerUpdates ) { + + const layerData = mipmap.data.subarray( + layerIndex * layerByteLength / mipmap.data.BYTES_PER_ELEMENT, + ( layerIndex + 1 ) * layerByteLength / mipmap.data.BYTES_PER_ELEMENT + ); + state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData ); + + } + + texture.clearLayerUpdates(); + + } else { + + state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data ); + + } + + } + + } else { + + state.compressedTexImage3D( _gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, mipmap.data, 0, 0 ); + + } + + } else { + + console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' ); + + } + + } else { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data ); + + } + + } else { + + state.texImage3D( _gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, glFormat, glType, mipmap.data ); + + } + + } + + } + + } else { + + if ( useTexStorage && allocateMemory ) { + + state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[ 0 ].width, mipmaps[ 0 ].height ); + + } + + for ( let i = 0, il = mipmaps.length; i < il; i ++ ) { + + mipmap = mipmaps[ i ]; + + if ( texture.format !== RGBAFormat ) { + + if ( glFormat !== null ) { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.compressedTexSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data ); + + } + + } else { + + state.compressedTexImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data ); + + } + + } else { + + console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' ); + + } + + } else { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); + + } + + } + + } + + } + + } else if ( texture.isDataArrayTexture ) { + + if ( useTexStorage ) { + + if ( allocateMemory ) { + + state.texStorage3D( _gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, image.width, image.height, image.depth ); + + } + + if ( dataReady ) { + + if ( texture.layerUpdates.size > 0 ) { + + const layerByteLength = getByteLength( image.width, image.height, texture.format, texture.type ); + + for ( const layerIndex of texture.layerUpdates ) { + + const layerData = image.data.subarray( + layerIndex * layerByteLength / image.data.BYTES_PER_ELEMENT, + ( layerIndex + 1 ) * layerByteLength / image.data.BYTES_PER_ELEMENT + ); + state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, layerIndex, image.width, image.height, 1, glFormat, glType, layerData ); + + } + + texture.clearLayerUpdates(); + + } else { + + state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data ); + + } + + } + + } else { + + state.texImage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data ); + + } + + } else if ( texture.isData3DTexture ) { + + if ( useTexStorage ) { + + if ( allocateMemory ) { + + state.texStorage3D( _gl.TEXTURE_3D, levels, glInternalFormat, image.width, image.height, image.depth ); + + } + + if ( dataReady ) { + + state.texSubImage3D( _gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data ); + + } + + } else { + + state.texImage3D( _gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data ); + + } + + } else if ( texture.isFramebufferTexture ) { + + if ( allocateMemory ) { + + if ( useTexStorage ) { + + state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height ); + + } else { + + let width = image.width, height = image.height; + + for ( let i = 0; i < levels; i ++ ) { + + state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, width, height, 0, glFormat, glType, null ); + + width >>= 1; + height >>= 1; + + } + + } + + } + + } else { + + // regular Texture (image, video, canvas) + + // use manually created mipmaps if available + // if there are no manual mipmaps + // set 0 level mipmap and then use GL to generate other mipmap levels + + if ( mipmaps.length > 0 ) { + + if ( useTexStorage && allocateMemory ) { + + const dimensions = getDimensions( mipmaps[ 0 ] ); + + state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height ); + + } + + for ( let i = 0, il = mipmaps.length; i < il; i ++ ) { + + mipmap = mipmaps[ i ]; + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap ); + + } + + } + + texture.generateMipmaps = false; + + } else { + + if ( useTexStorage ) { + + if ( allocateMemory ) { + + const dimensions = getDimensions( image ); + + state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, dimensions.width, dimensions.height ); + + } + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image ); + + } + + } + + } + + if ( textureNeedsGenerateMipmaps( texture ) ) { + + generateMipmap( textureType ); + + } + + sourceProperties.__version = source.version; + + if ( texture.onUpdate ) texture.onUpdate( texture ); + + } + + textureProperties.__version = texture.version; + + } + + function uploadCubeTexture( textureProperties, texture, slot ) { + + if ( texture.image.length !== 6 ) return; + + const forceUpload = initTexture( textureProperties, texture ); + const source = texture.source; + + state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot ); + + const sourceProperties = properties.get( source ); + + if ( source.version !== sourceProperties.__version || forceUpload === true ) { + + state.activeTexture( _gl.TEXTURE0 + slot ); + + const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace ); + const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace ); + const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL; + + _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY ); + _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha ); + _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment ); + _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion ); + + const isCompressed = ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ); + const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture ); + + const cubeImage = []; + + for ( let i = 0; i < 6; i ++ ) { + + if ( ! isCompressed && ! isDataTexture ) { + + cubeImage[ i ] = resizeImage( texture.image[ i ], true, capabilities.maxCubemapSize ); + + } else { + + cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ]; + + } + + cubeImage[ i ] = verifyColorSpace( texture, cubeImage[ i ] ); + + } + + const image = cubeImage[ 0 ], + glFormat = utils.convert( texture.format, texture.colorSpace ), + glType = utils.convert( texture.type ), + glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace ); + + const useTexStorage = ( texture.isVideoTexture !== true ); + const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true ); + const dataReady = source.dataReady; + let levels = getMipLevels( texture, image ); + + setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture ); + + let mipmaps; + + if ( isCompressed ) { + + if ( useTexStorage && allocateMemory ) { + + state.texStorage2D( _gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, image.width, image.height ); + + } + + for ( let i = 0; i < 6; i ++ ) { + + mipmaps = cubeImage[ i ].mipmaps; + + for ( let j = 0; j < mipmaps.length; j ++ ) { + + const mipmap = mipmaps[ j ]; + + if ( texture.format !== RGBAFormat ) { + + if ( glFormat !== null ) { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.compressedTexSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data ); + + } + + } else { + + state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data ); + + } + + } else { + + console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' ); + + } + + } else { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); + + } + + } + + } + + } + + } else { + + mipmaps = texture.mipmaps; + + if ( useTexStorage && allocateMemory ) { + + // TODO: Uniformly handle mipmap definitions + // Normal textures and compressed cube textures define base level + mips with their mipmap array + // Uncompressed cube textures use their mipmap array only for mips (no base level) + + if ( mipmaps.length > 0 ) levels ++; + + const dimensions = getDimensions( cubeImage[ 0 ] ); + + state.texStorage2D( _gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, dimensions.width, dimensions.height ); + + } + + for ( let i = 0; i < 6; i ++ ) { + + if ( isDataTexture ) { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, cubeImage[ i ].width, cubeImage[ i ].height, glFormat, glType, cubeImage[ i ].data ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data ); + + } + + for ( let j = 0; j < mipmaps.length; j ++ ) { + + const mipmap = mipmaps[ j ]; + const mipmapImage = mipmap.image[ i ].image; + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data ); + + } + + } + + } else { + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, glFormat, glType, cubeImage[ i ] ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] ); + + } + + for ( let j = 0; j < mipmaps.length; j ++ ) { + + const mipmap = mipmaps[ j ]; + + if ( useTexStorage ) { + + if ( dataReady ) { + + state.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, glFormat, glType, mipmap.image[ i ] ); + + } + + } else { + + state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] ); + + } + + } + + } + + } + + } + + if ( textureNeedsGenerateMipmaps( texture ) ) { + + // We assume images for cube map have the same size. + generateMipmap( _gl.TEXTURE_CUBE_MAP ); + + } + + sourceProperties.__version = source.version; + + if ( texture.onUpdate ) texture.onUpdate( texture ); + + } + + textureProperties.__version = texture.version; + + } + + // Render targets + + // Setup storage for target texture and bind it to correct framebuffer + function setupFrameBufferTexture( framebuffer, renderTarget, texture, attachment, textureTarget, level ) { + + const glFormat = utils.convert( texture.format, texture.colorSpace ); + const glType = utils.convert( texture.type ); + const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace ); + const renderTargetProperties = properties.get( renderTarget ); + const textureProperties = properties.get( texture ); + + textureProperties.__renderTarget = renderTarget; + + if ( ! renderTargetProperties.__hasExternalTextures ) { + + const width = Math.max( 1, renderTarget.width >> level ); + const height = Math.max( 1, renderTarget.height >> level ); + + if ( textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY ) { + + state.texImage3D( textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null ); + + } else { + + state.texImage2D( textureTarget, level, glInternalFormat, width, height, 0, glFormat, glType, null ); + + } + + } + + state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); + + if ( useMultisampledRTT( renderTarget ) ) { + + multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, 0, getRenderTargetSamples( renderTarget ) ); + + } else if ( textureTarget === _gl.TEXTURE_2D || ( textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z ) ) { // see #24753 + + _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, level ); + + } + + state.bindFramebuffer( _gl.FRAMEBUFFER, null ); + + } + + // Setup storage for internal depth/stencil buffers and bind to correct framebuffer + function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) { + + _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer ); + + if ( renderTarget.depthBuffer ) { + + // retrieve the depth attachment types + const depthTexture = renderTarget.depthTexture; + const depthType = depthTexture && depthTexture.isDepthTexture ? depthTexture.type : null; + const glInternalFormat = getInternalDepthFormat( renderTarget.stencilBuffer, depthType ); + const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; + + // set up the attachment + const samples = getRenderTargetSamples( renderTarget ); + const isUseMultisampledRTT = useMultisampledRTT( renderTarget ); + if ( isUseMultisampledRTT ) { + + multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + } else if ( isMultisample ) { + + _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + } else { + + _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height ); + + } + + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer ); + + } else { + + const textures = renderTarget.textures; + + for ( let i = 0; i < textures.length; i ++ ) { + + const texture = textures[ i ]; + + const glFormat = utils.convert( texture.format, texture.colorSpace ); + const glType = utils.convert( texture.type ); + const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace ); + const samples = getRenderTargetSamples( renderTarget ); + + if ( isMultisample && useMultisampledRTT( renderTarget ) === false ) { + + _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + } else if ( useMultisampledRTT( renderTarget ) ) { + + multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + } else { + + _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height ); + + } + + } + + } + + _gl.bindRenderbuffer( _gl.RENDERBUFFER, null ); + + } + + // Setup resources for a Depth Texture for a FBO (needs an extension) + function setupDepthTexture( framebuffer, renderTarget ) { + + const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget ); + if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' ); + + state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); + + if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) { + + throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' ); + + } + + const textureProperties = properties.get( renderTarget.depthTexture ); + textureProperties.__renderTarget = renderTarget; + + // upload an empty depth texture with framebuffer size + if ( ! textureProperties.__webglTexture || + renderTarget.depthTexture.image.width !== renderTarget.width || + renderTarget.depthTexture.image.height !== renderTarget.height ) { + + renderTarget.depthTexture.image.width = renderTarget.width; + renderTarget.depthTexture.image.height = renderTarget.height; + renderTarget.depthTexture.needsUpdate = true; + + } + + setTexture2D( renderTarget.depthTexture, 0 ); + + const webglDepthTexture = textureProperties.__webglTexture; + const samples = getRenderTargetSamples( renderTarget ); + + if ( renderTarget.depthTexture.format === DepthFormat ) { + + if ( useMultisampledRTT( renderTarget ) ) { + + multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples ); + + } else { + + _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 ); + + } + + } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) { + + if ( useMultisampledRTT( renderTarget ) ) { + + multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples ); + + } else { + + _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 ); + + } + + } else { + + throw new Error( 'Unknown depthTexture format' ); + + } + + } + + // Setup GL resources for a non-texture depth buffer + function setupDepthRenderbuffer( renderTarget ) { + + const renderTargetProperties = properties.get( renderTarget ); + const isCube = ( renderTarget.isWebGLCubeRenderTarget === true ); + + // if the bound depth texture has changed + if ( renderTargetProperties.__boundDepthTexture !== renderTarget.depthTexture ) { + + // fire the dispose event to get rid of stored state associated with the previously bound depth buffer + const depthTexture = renderTarget.depthTexture; + if ( renderTargetProperties.__depthDisposeCallback ) { + + renderTargetProperties.__depthDisposeCallback(); + + } + + // set up dispose listeners to track when the currently attached buffer is implicitly unbound + if ( depthTexture ) { + + const disposeEvent = () => { + + delete renderTargetProperties.__boundDepthTexture; + delete renderTargetProperties.__depthDisposeCallback; + depthTexture.removeEventListener( 'dispose', disposeEvent ); + + }; + + depthTexture.addEventListener( 'dispose', disposeEvent ); + renderTargetProperties.__depthDisposeCallback = disposeEvent; + + } + + renderTargetProperties.__boundDepthTexture = depthTexture; + + } + + if ( renderTarget.depthTexture && ! renderTargetProperties.__autoAllocateDepthBuffer ) { + + if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' ); + + setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget ); + + } else { + + if ( isCube ) { + + renderTargetProperties.__webglDepthbuffer = []; + + for ( let i = 0; i < 6; i ++ ) { + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] ); + + if ( renderTargetProperties.__webglDepthbuffer[ i ] === undefined ) { + + renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false ); + + } else { + + // attach buffer if it's been created already + const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; + const renderbuffer = renderTargetProperties.__webglDepthbuffer[ i ]; + _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer ); + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer ); + + } + + } + + } else { + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); + + if ( renderTargetProperties.__webglDepthbuffer === undefined ) { + + renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false ); + + } else { + + // attach buffer if it's been created already + const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; + const renderbuffer = renderTargetProperties.__webglDepthbuffer; + _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer ); + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer ); + + } + + } + + } + + state.bindFramebuffer( _gl.FRAMEBUFFER, null ); + + } + + // rebind framebuffer with external textures + function rebindTextures( renderTarget, colorTexture, depthTexture ) { + + const renderTargetProperties = properties.get( renderTarget ); + + if ( colorTexture !== undefined ) { + + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, renderTarget.texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, 0 ); + + } + + if ( depthTexture !== undefined ) { + + setupDepthRenderbuffer( renderTarget ); + + } + + } + + // Set up GL resources for the render target + function setupRenderTarget( renderTarget ) { + + const texture = renderTarget.texture; + + const renderTargetProperties = properties.get( renderTarget ); + const textureProperties = properties.get( texture ); + + renderTarget.addEventListener( 'dispose', onRenderTargetDispose ); + + const textures = renderTarget.textures; + + const isCube = ( renderTarget.isWebGLCubeRenderTarget === true ); + const isMultipleRenderTargets = ( textures.length > 1 ); + + if ( ! isMultipleRenderTargets ) { + + if ( textureProperties.__webglTexture === undefined ) { + + textureProperties.__webglTexture = _gl.createTexture(); + + } + + textureProperties.__version = texture.version; + info.memory.textures ++; + + } + + // Setup framebuffer + + if ( isCube ) { + + renderTargetProperties.__webglFramebuffer = []; + + for ( let i = 0; i < 6; i ++ ) { + + if ( texture.mipmaps && texture.mipmaps.length > 0 ) { + + renderTargetProperties.__webglFramebuffer[ i ] = []; + + for ( let level = 0; level < texture.mipmaps.length; level ++ ) { + + renderTargetProperties.__webglFramebuffer[ i ][ level ] = _gl.createFramebuffer(); + + } + + } else { + + renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer(); + + } + + } + + } else { + + if ( texture.mipmaps && texture.mipmaps.length > 0 ) { + + renderTargetProperties.__webglFramebuffer = []; + + for ( let level = 0; level < texture.mipmaps.length; level ++ ) { + + renderTargetProperties.__webglFramebuffer[ level ] = _gl.createFramebuffer(); + + } + + } else { + + renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer(); + + } + + if ( isMultipleRenderTargets ) { + + for ( let i = 0, il = textures.length; i < il; i ++ ) { + + const attachmentProperties = properties.get( textures[ i ] ); + + if ( attachmentProperties.__webglTexture === undefined ) { + + attachmentProperties.__webglTexture = _gl.createTexture(); + + info.memory.textures ++; + + } + + } + + } + + if ( ( renderTarget.samples > 0 ) && useMultisampledRTT( renderTarget ) === false ) { + + renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); + renderTargetProperties.__webglColorRenderbuffer = []; + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + + for ( let i = 0; i < textures.length; i ++ ) { + + const texture = textures[ i ]; + renderTargetProperties.__webglColorRenderbuffer[ i ] = _gl.createRenderbuffer(); + + _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] ); + + const glFormat = utils.convert( texture.format, texture.colorSpace ); + const glType = utils.convert( texture.type ); + const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, renderTarget.isXRRenderTarget === true ); + const samples = getRenderTargetSamples( renderTarget ); + _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] ); + + } + + _gl.bindRenderbuffer( _gl.RENDERBUFFER, null ); + + if ( renderTarget.depthBuffer ) { + + renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true ); + + } + + state.bindFramebuffer( _gl.FRAMEBUFFER, null ); + + } + + } + + // Setup color buffer + + if ( isCube ) { + + state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture ); + setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture ); + + for ( let i = 0; i < 6; i ++ ) { + + if ( texture.mipmaps && texture.mipmaps.length > 0 ) { + + for ( let level = 0; level < texture.mipmaps.length; level ++ ) { + + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ][ level ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level ); + + } + + } else { + + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0 ); + + } + + } + + if ( textureNeedsGenerateMipmaps( texture ) ) { + + generateMipmap( _gl.TEXTURE_CUBE_MAP ); + + } + + state.unbindTexture(); + + } else if ( isMultipleRenderTargets ) { + + for ( let i = 0, il = textures.length; i < il; i ++ ) { + + const attachment = textures[ i ]; + const attachmentProperties = properties.get( attachment ); + + state.bindTexture( _gl.TEXTURE_2D, attachmentProperties.__webglTexture ); + setTextureParameters( _gl.TEXTURE_2D, attachment ); + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0 ); + + if ( textureNeedsGenerateMipmaps( attachment ) ) { + + generateMipmap( _gl.TEXTURE_2D ); + + } + + } + + state.unbindTexture(); + + } else { + + let glTextureType = _gl.TEXTURE_2D; + + if ( renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget ) { + + glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY; + + } + + state.bindTexture( glTextureType, textureProperties.__webglTexture ); + setTextureParameters( glTextureType, texture ); + + if ( texture.mipmaps && texture.mipmaps.length > 0 ) { + + for ( let level = 0; level < texture.mipmaps.length; level ++ ) { + + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ level ], renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, level ); + + } + + } else { + + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, 0 ); + + } + + if ( textureNeedsGenerateMipmaps( texture ) ) { + + generateMipmap( glTextureType ); + + } + + state.unbindTexture(); + + } + + // Setup depth and stencil buffers + + if ( renderTarget.depthBuffer ) { + + setupDepthRenderbuffer( renderTarget ); + + } + + } + + function updateRenderTargetMipmap( renderTarget ) { + + const textures = renderTarget.textures; + + for ( let i = 0, il = textures.length; i < il; i ++ ) { + + const texture = textures[ i ]; + + if ( textureNeedsGenerateMipmaps( texture ) ) { + + const targetType = getTargetType( renderTarget ); + const webglTexture = properties.get( texture ).__webglTexture; + + state.bindTexture( targetType, webglTexture ); + generateMipmap( targetType ); + state.unbindTexture(); + + } + + } + + } + + const invalidationArrayRead = []; + const invalidationArrayDraw = []; + + function updateMultisampleRenderTarget( renderTarget ) { + + if ( renderTarget.samples > 0 ) { + + if ( useMultisampledRTT( renderTarget ) === false ) { + + const textures = renderTarget.textures; + const width = renderTarget.width; + const height = renderTarget.height; + let mask = _gl.COLOR_BUFFER_BIT; + const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; + const renderTargetProperties = properties.get( renderTarget ); + const isMultipleRenderTargets = ( textures.length > 1 ); + + // If MRT we need to remove FBO attachments + if ( isMultipleRenderTargets ) { + + for ( let i = 0; i < textures.length; i ++ ) { + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, null ); + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); + _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, null, 0 ); + + } + + } + + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); + + for ( let i = 0; i < textures.length; i ++ ) { + + if ( renderTarget.resolveDepthBuffer ) { + + if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT; + + // resolving stencil is slow with a D3D backend. disable it for all transmission render targets (see #27799) + + if ( renderTarget.stencilBuffer && renderTarget.resolveStencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT; + + } + + if ( isMultipleRenderTargets ) { + + _gl.framebufferRenderbuffer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] ); + + const webglTexture = properties.get( textures[ i ] ).__webglTexture; + _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0 ); + + } + + _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST ); + + if ( supportsInvalidateFramebuffer === true ) { + + invalidationArrayRead.length = 0; + invalidationArrayDraw.length = 0; + + invalidationArrayRead.push( _gl.COLOR_ATTACHMENT0 + i ); + + if ( renderTarget.depthBuffer && renderTarget.resolveDepthBuffer === false ) { + + invalidationArrayRead.push( depthStyle ); + invalidationArrayDraw.push( depthStyle ); + + _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, invalidationArrayDraw ); + + } + + _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArrayRead ); + + } + + } + + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null ); + + // If MRT since pre-blit we removed the FBO we need to reconstruct the attachments + if ( isMultipleRenderTargets ) { + + for ( let i = 0; i < textures.length; i ++ ) { + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[ i ] ); + + const webglTexture = properties.get( textures[ i ] ).__webglTexture; + + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); + _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, webglTexture, 0 ); + + } + + } + + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + + } else { + + if ( renderTarget.depthBuffer && renderTarget.resolveDepthBuffer === false && supportsInvalidateFramebuffer ) { + + const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; + + _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] ); + + } + + } + + } + + } + + function getRenderTargetSamples( renderTarget ) { + + return Math.min( capabilities.maxSamples, renderTarget.samples ); + + } + + function useMultisampledRTT( renderTarget ) { + + const renderTargetProperties = properties.get( renderTarget ); + + return renderTarget.samples > 0 && extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTargetProperties.__useRenderToTexture !== false; + + } + + function updateVideoTexture( texture ) { + + const frame = info.render.frame; + + // Check the last frame we updated the VideoTexture + + if ( _videoTextures.get( texture ) !== frame ) { + + _videoTextures.set( texture, frame ); + texture.update(); + + } + + } + + function verifyColorSpace( texture, image ) { + + const colorSpace = texture.colorSpace; + const format = texture.format; + const type = texture.type; + + if ( texture.isCompressedTexture === true || texture.isVideoTexture === true ) return image; + + if ( colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace ) { + + // sRGB + + if ( ColorManagement.getTransfer( colorSpace ) === SRGBTransfer ) { + + // in WebGL 2 uncompressed textures can only be sRGB encoded if they have the RGBA8 format + + if ( format !== RGBAFormat || type !== UnsignedByteType ) { + + console.warn( 'THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.' ); + + } + + } else { + + console.error( 'THREE.WebGLTextures: Unsupported texture color space:', colorSpace ); + + } + + } + + return image; + + } + + function getDimensions( image ) { + + if ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) { + + // if intrinsic data are not available, fallback to width/height + + _imageDimensions.width = image.naturalWidth || image.width; + _imageDimensions.height = image.naturalHeight || image.height; + + } else if ( typeof VideoFrame !== 'undefined' && image instanceof VideoFrame ) { + + _imageDimensions.width = image.displayWidth; + _imageDimensions.height = image.displayHeight; + + } else { + + _imageDimensions.width = image.width; + _imageDimensions.height = image.height; + + } + + return _imageDimensions; + + } + + // + + this.allocateTextureUnit = allocateTextureUnit; + this.resetTextureUnits = resetTextureUnits; + + this.setTexture2D = setTexture2D; + this.setTexture2DArray = setTexture2DArray; + this.setTexture3D = setTexture3D; + this.setTextureCube = setTextureCube; + this.rebindTextures = rebindTextures; + this.setupRenderTarget = setupRenderTarget; + this.updateRenderTargetMipmap = updateRenderTargetMipmap; + this.updateMultisampleRenderTarget = updateMultisampleRenderTarget; + this.setupDepthRenderbuffer = setupDepthRenderbuffer; + this.setupFrameBufferTexture = setupFrameBufferTexture; + this.useMultisampledRTT = useMultisampledRTT; + +} + +function WebGLUtils( gl, extensions ) { + + function convert( p, colorSpace = NoColorSpace ) { + + let extension; + + const transfer = ColorManagement.getTransfer( colorSpace ); + + if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE; + if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4; + if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1; + if ( p === UnsignedInt5999Type ) return gl.UNSIGNED_INT_5_9_9_9_REV; + + if ( p === ByteType ) return gl.BYTE; + if ( p === ShortType ) return gl.SHORT; + if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT; + if ( p === IntType ) return gl.INT; + if ( p === UnsignedIntType ) return gl.UNSIGNED_INT; + if ( p === FloatType ) return gl.FLOAT; + if ( p === HalfFloatType ) return gl.HALF_FLOAT; + + if ( p === AlphaFormat ) return gl.ALPHA; + if ( p === RGBFormat ) return gl.RGB; + if ( p === RGBAFormat ) return gl.RGBA; + if ( p === LuminanceFormat ) return gl.LUMINANCE; + if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA; + if ( p === DepthFormat ) return gl.DEPTH_COMPONENT; + if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL; + + // WebGL2 formats. + + if ( p === RedFormat ) return gl.RED; + if ( p === RedIntegerFormat ) return gl.RED_INTEGER; + if ( p === RGFormat ) return gl.RG; + if ( p === RGIntegerFormat ) return gl.RG_INTEGER; + if ( p === RGBAIntegerFormat ) return gl.RGBA_INTEGER; + + // S3TC + + if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) { + + if ( transfer === SRGBTransfer ) { + + extension = extensions.get( 'WEBGL_compressed_texture_s3tc_srgb' ); + + if ( extension !== null ) { + + if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; + if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; + + } else { + + return null; + + } + + } else { + + extension = extensions.get( 'WEBGL_compressed_texture_s3tc' ); + + if ( extension !== null ) { + + if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; + if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; + + } else { + + return null; + + } + + } + + } + + // PVRTC + + if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' ); + + if ( extension !== null ) { + + if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; + if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; + if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + + } else { + + return null; + + } + + } + + // ETC + + if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_etc' ); + + if ( extension !== null ) { + + if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2; + if ( p === RGBA_ETC2_EAC_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC; + + } else { + + return null; + + } + + } + + // ASTC + + if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || + p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || + p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || + p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || + p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_astc' ); + + if ( extension !== null ) { + + if ( p === RGBA_ASTC_4x4_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR; + if ( p === RGBA_ASTC_5x4_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR; + if ( p === RGBA_ASTC_5x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR; + if ( p === RGBA_ASTC_6x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR; + if ( p === RGBA_ASTC_6x6_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR; + if ( p === RGBA_ASTC_8x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR; + if ( p === RGBA_ASTC_8x6_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR; + if ( p === RGBA_ASTC_8x8_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR; + if ( p === RGBA_ASTC_10x5_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR; + if ( p === RGBA_ASTC_10x6_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR; + if ( p === RGBA_ASTC_10x8_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR; + if ( p === RGBA_ASTC_10x10_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR; + if ( p === RGBA_ASTC_12x10_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR; + if ( p === RGBA_ASTC_12x12_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR; + + } else { + + return null; + + } + + } + + // BPTC + + if ( p === RGBA_BPTC_Format || p === RGB_BPTC_SIGNED_Format || p === RGB_BPTC_UNSIGNED_Format ) { + + extension = extensions.get( 'EXT_texture_compression_bptc' ); + + if ( extension !== null ) { + + if ( p === RGBA_BPTC_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT; + if ( p === RGB_BPTC_SIGNED_Format ) return extension.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT; + if ( p === RGB_BPTC_UNSIGNED_Format ) return extension.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT; + + } else { + + return null; + + } + + } + + // RGTC + + if ( p === RED_RGTC1_Format || p === SIGNED_RED_RGTC1_Format || p === RED_GREEN_RGTC2_Format || p === SIGNED_RED_GREEN_RGTC2_Format ) { + + extension = extensions.get( 'EXT_texture_compression_rgtc' ); + + if ( extension !== null ) { + + if ( p === RGBA_BPTC_Format ) return extension.COMPRESSED_RED_RGTC1_EXT; + if ( p === SIGNED_RED_RGTC1_Format ) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT; + if ( p === RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT; + if ( p === SIGNED_RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT; + + } else { + + return null; + + } + + } + + // + + if ( p === UnsignedInt248Type ) return gl.UNSIGNED_INT_24_8; + + // if "p" can't be resolved, assume the user defines a WebGL constant as a string (fallback/workaround for packed RGB formats) + + return ( gl[ p ] !== undefined ) ? gl[ p ] : null; + + } + + return { convert: convert }; + +} + +const _moveEvent = { type: 'move' }; + +class WebXRController { + + constructor() { + + this._targetRay = null; + this._grip = null; + this._hand = null; + + } + + getHandSpace() { + + if ( this._hand === null ) { + + this._hand = new Group(); + this._hand.matrixAutoUpdate = false; + this._hand.visible = false; + + this._hand.joints = {}; + this._hand.inputState = { pinching: false }; + + } + + return this._hand; + + } + + getTargetRaySpace() { + + if ( this._targetRay === null ) { + + this._targetRay = new Group(); + this._targetRay.matrixAutoUpdate = false; + this._targetRay.visible = false; + this._targetRay.hasLinearVelocity = false; + this._targetRay.linearVelocity = new Vector3(); + this._targetRay.hasAngularVelocity = false; + this._targetRay.angularVelocity = new Vector3(); + + } + + return this._targetRay; + + } + + getGripSpace() { + + if ( this._grip === null ) { + + this._grip = new Group(); + this._grip.matrixAutoUpdate = false; + this._grip.visible = false; + this._grip.hasLinearVelocity = false; + this._grip.linearVelocity = new Vector3(); + this._grip.hasAngularVelocity = false; + this._grip.angularVelocity = new Vector3(); + + } + + return this._grip; + + } + + dispatchEvent( event ) { + + if ( this._targetRay !== null ) { + + this._targetRay.dispatchEvent( event ); + + } + + if ( this._grip !== null ) { + + this._grip.dispatchEvent( event ); + + } + + if ( this._hand !== null ) { + + this._hand.dispatchEvent( event ); + + } + + return this; + + } + + connect( inputSource ) { + + if ( inputSource && inputSource.hand ) { + + const hand = this._hand; + + if ( hand ) { + + for ( const inputjoint of inputSource.hand.values() ) { + + // Initialize hand with joints when connected + this._getHandJoint( hand, inputjoint ); + + } + + } + + } + + this.dispatchEvent( { type: 'connected', data: inputSource } ); + + return this; + + } + + disconnect( inputSource ) { + + this.dispatchEvent( { type: 'disconnected', data: inputSource } ); + + if ( this._targetRay !== null ) { + + this._targetRay.visible = false; + + } + + if ( this._grip !== null ) { + + this._grip.visible = false; + + } + + if ( this._hand !== null ) { + + this._hand.visible = false; + + } + + return this; + + } + + update( inputSource, frame, referenceSpace ) { + + let inputPose = null; + let gripPose = null; + let handPose = null; + + const targetRay = this._targetRay; + const grip = this._grip; + const hand = this._hand; + + if ( inputSource && frame.session.visibilityState !== 'visible-blurred' ) { + + if ( hand && inputSource.hand ) { + + handPose = true; + + for ( const inputjoint of inputSource.hand.values() ) { + + // Update the joints groups with the XRJoint poses + const jointPose = frame.getJointPose( inputjoint, referenceSpace ); + + // The transform of this joint will be updated with the joint pose on each frame + const joint = this._getHandJoint( hand, inputjoint ); + + if ( jointPose !== null ) { + + joint.matrix.fromArray( jointPose.transform.matrix ); + joint.matrix.decompose( joint.position, joint.rotation, joint.scale ); + joint.matrixWorldNeedsUpdate = true; + joint.jointRadius = jointPose.radius; + + } + + joint.visible = jointPose !== null; + + } + + // Custom events + + // Check pinchz + const indexTip = hand.joints[ 'index-finger-tip' ]; + const thumbTip = hand.joints[ 'thumb-tip' ]; + const distance = indexTip.position.distanceTo( thumbTip.position ); + + const distanceToPinch = 0.02; + const threshold = 0.005; + + if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) { + + hand.inputState.pinching = false; + this.dispatchEvent( { + type: 'pinchend', + handedness: inputSource.handedness, + target: this + } ); + + } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) { + + hand.inputState.pinching = true; + this.dispatchEvent( { + type: 'pinchstart', + handedness: inputSource.handedness, + target: this + } ); + + } + + } else { + + if ( grip !== null && inputSource.gripSpace ) { + + gripPose = frame.getPose( inputSource.gripSpace, referenceSpace ); + + if ( gripPose !== null ) { + + grip.matrix.fromArray( gripPose.transform.matrix ); + grip.matrix.decompose( grip.position, grip.rotation, grip.scale ); + grip.matrixWorldNeedsUpdate = true; + + if ( gripPose.linearVelocity ) { + + grip.hasLinearVelocity = true; + grip.linearVelocity.copy( gripPose.linearVelocity ); + + } else { + + grip.hasLinearVelocity = false; + + } + + if ( gripPose.angularVelocity ) { + + grip.hasAngularVelocity = true; + grip.angularVelocity.copy( gripPose.angularVelocity ); + + } else { + + grip.hasAngularVelocity = false; + + } + + } + + } + + } + + if ( targetRay !== null ) { + + inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace ); + + // Some runtimes (namely Vive Cosmos with Vive OpenXR Runtime) have only grip space and ray space is equal to it + if ( inputPose === null && gripPose !== null ) { + + inputPose = gripPose; + + } + + if ( inputPose !== null ) { + + targetRay.matrix.fromArray( inputPose.transform.matrix ); + targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale ); + targetRay.matrixWorldNeedsUpdate = true; + + if ( inputPose.linearVelocity ) { + + targetRay.hasLinearVelocity = true; + targetRay.linearVelocity.copy( inputPose.linearVelocity ); + + } else { + + targetRay.hasLinearVelocity = false; + + } + + if ( inputPose.angularVelocity ) { + + targetRay.hasAngularVelocity = true; + targetRay.angularVelocity.copy( inputPose.angularVelocity ); + + } else { + + targetRay.hasAngularVelocity = false; + + } + + this.dispatchEvent( _moveEvent ); + + } + + } + + + } + + if ( targetRay !== null ) { + + targetRay.visible = ( inputPose !== null ); + + } + + if ( grip !== null ) { + + grip.visible = ( gripPose !== null ); + + } + + if ( hand !== null ) { + + hand.visible = ( handPose !== null ); + + } + + return this; + + } + + // private method + + _getHandJoint( hand, inputjoint ) { + + if ( hand.joints[ inputjoint.jointName ] === undefined ) { + + const joint = new Group(); + joint.matrixAutoUpdate = false; + joint.visible = false; + hand.joints[ inputjoint.jointName ] = joint; + + hand.add( joint ); + + } + + return hand.joints[ inputjoint.jointName ]; + + } + +} + +const _occlusion_vertex = ` +void main() { + + gl_Position = vec4( position, 1.0 ); + +}`; + +const _occlusion_fragment = ` +uniform sampler2DArray depthColor; +uniform float depthWidth; +uniform float depthHeight; + +void main() { + + vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight ); + + if ( coord.x >= 1.0 ) { + + gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r; + + } else { + + gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r; + + } + +}`; + +class WebXRDepthSensing { + + constructor() { + + this.texture = null; + this.mesh = null; + + this.depthNear = 0; + this.depthFar = 0; + + } + + init( renderer, depthData, renderState ) { + + if ( this.texture === null ) { + + const texture = new Texture(); + + const texProps = renderer.properties.get( texture ); + texProps.__webglTexture = depthData.texture; + + if ( ( depthData.depthNear != renderState.depthNear ) || ( depthData.depthFar != renderState.depthFar ) ) { + + this.depthNear = depthData.depthNear; + this.depthFar = depthData.depthFar; + + } + + this.texture = texture; + + } + + } + + getMesh( cameraXR ) { + + if ( this.texture !== null ) { + + if ( this.mesh === null ) { + + const viewport = cameraXR.cameras[ 0 ].viewport; + const material = new ShaderMaterial( { + vertexShader: _occlusion_vertex, + fragmentShader: _occlusion_fragment, + uniforms: { + depthColor: { value: this.texture }, + depthWidth: { value: viewport.z }, + depthHeight: { value: viewport.w } + } + } ); + + this.mesh = new Mesh( new PlaneGeometry( 20, 20 ), material ); + + } + + } + + return this.mesh; + + } + + reset() { + + this.texture = null; + this.mesh = null; + + } + + getDepthTexture() { + + return this.texture; + + } + +} + +class WebXRManager extends EventDispatcher { + + constructor( renderer, gl ) { + + super(); + + const scope = this; + + let session = null; + + let framebufferScaleFactor = 1.0; + + let referenceSpace = null; + let referenceSpaceType = 'local-floor'; + // Set default foveation to maximum. + let foveation = 1.0; + let customReferenceSpace = null; + + let pose = null; + let glBinding = null; + let glProjLayer = null; + let glBaseLayer = null; + let xrFrame = null; + + const depthSensing = new WebXRDepthSensing(); + const attributes = gl.getContextAttributes(); + + let initialRenderTarget = null; + let newRenderTarget = null; + + const controllers = []; + const controllerInputSources = []; + + const currentSize = new Vector2(); + let currentPixelRatio = null; + + // + + const cameraL = new PerspectiveCamera(); + cameraL.viewport = new Vector4(); + + const cameraR = new PerspectiveCamera(); + cameraR.viewport = new Vector4(); + + const cameras = [ cameraL, cameraR ]; + + const cameraXR = new ArrayCamera(); + + let _currentDepthNear = null; + let _currentDepthFar = null; + + // + + this.cameraAutoUpdate = true; + this.enabled = false; + + this.isPresenting = false; + + this.getController = function ( index ) { + + let controller = controllers[ index ]; + + if ( controller === undefined ) { + + controller = new WebXRController(); + controllers[ index ] = controller; + + } + + return controller.getTargetRaySpace(); + + }; + + this.getControllerGrip = function ( index ) { + + let controller = controllers[ index ]; + + if ( controller === undefined ) { + + controller = new WebXRController(); + controllers[ index ] = controller; + + } + + return controller.getGripSpace(); + + }; + + this.getHand = function ( index ) { + + let controller = controllers[ index ]; + + if ( controller === undefined ) { + + controller = new WebXRController(); + controllers[ index ] = controller; + + } + + return controller.getHandSpace(); + + }; + + // + + function onSessionEvent( event ) { + + const controllerIndex = controllerInputSources.indexOf( event.inputSource ); + + if ( controllerIndex === - 1 ) { + + return; + + } + + const controller = controllers[ controllerIndex ]; + + if ( controller !== undefined ) { + + controller.update( event.inputSource, event.frame, customReferenceSpace || referenceSpace ); + controller.dispatchEvent( { type: event.type, data: event.inputSource } ); + + } + + } + + function onSessionEnd() { + + session.removeEventListener( 'select', onSessionEvent ); + session.removeEventListener( 'selectstart', onSessionEvent ); + session.removeEventListener( 'selectend', onSessionEvent ); + session.removeEventListener( 'squeeze', onSessionEvent ); + session.removeEventListener( 'squeezestart', onSessionEvent ); + session.removeEventListener( 'squeezeend', onSessionEvent ); + session.removeEventListener( 'end', onSessionEnd ); + session.removeEventListener( 'inputsourceschange', onInputSourcesChange ); + + for ( let i = 0; i < controllers.length; i ++ ) { + + const inputSource = controllerInputSources[ i ]; + + if ( inputSource === null ) continue; + + controllerInputSources[ i ] = null; + + controllers[ i ].disconnect( inputSource ); + + } + + _currentDepthNear = null; + _currentDepthFar = null; + + depthSensing.reset(); + + // restore framebuffer/rendering state + + renderer.setRenderTarget( initialRenderTarget ); + + glBaseLayer = null; + glProjLayer = null; + glBinding = null; + session = null; + newRenderTarget = null; + + // + + animation.stop(); + + scope.isPresenting = false; + + renderer.setPixelRatio( currentPixelRatio ); + renderer.setSize( currentSize.width, currentSize.height, false ); + + scope.dispatchEvent( { type: 'sessionend' } ); + + } + + this.setFramebufferScaleFactor = function ( value ) { + + framebufferScaleFactor = value; + + if ( scope.isPresenting === true ) { + + console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' ); + + } + + }; + + this.setReferenceSpaceType = function ( value ) { + + referenceSpaceType = value; + + if ( scope.isPresenting === true ) { + + console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' ); + + } + + }; + + this.getReferenceSpace = function () { + + return customReferenceSpace || referenceSpace; + + }; + + this.setReferenceSpace = function ( space ) { + + customReferenceSpace = space; + + }; + + this.getBaseLayer = function () { + + return glProjLayer !== null ? glProjLayer : glBaseLayer; + + }; + + this.getBinding = function () { + + return glBinding; + + }; + + this.getFrame = function () { + + return xrFrame; + + }; + + this.getSession = function () { + + return session; + + }; + + this.setSession = async function ( value ) { + + session = value; + + if ( session !== null ) { + + initialRenderTarget = renderer.getRenderTarget(); + + session.addEventListener( 'select', onSessionEvent ); + session.addEventListener( 'selectstart', onSessionEvent ); + session.addEventListener( 'selectend', onSessionEvent ); + session.addEventListener( 'squeeze', onSessionEvent ); + session.addEventListener( 'squeezestart', onSessionEvent ); + session.addEventListener( 'squeezeend', onSessionEvent ); + session.addEventListener( 'end', onSessionEnd ); + session.addEventListener( 'inputsourceschange', onInputSourcesChange ); + + if ( attributes.xrCompatible !== true ) { + + await gl.makeXRCompatible(); + + } + + currentPixelRatio = renderer.getPixelRatio(); + renderer.getSize( currentSize ); + + if ( session.renderState.layers === undefined ) { + + const layerInit = { + antialias: attributes.antialias, + alpha: true, + depth: attributes.depth, + stencil: attributes.stencil, + framebufferScaleFactor: framebufferScaleFactor + }; + + glBaseLayer = new XRWebGLLayer( session, gl, layerInit ); + + session.updateRenderState( { baseLayer: glBaseLayer } ); + + renderer.setPixelRatio( 1 ); + renderer.setSize( glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, false ); + + newRenderTarget = new WebGLRenderTarget( + glBaseLayer.framebufferWidth, + glBaseLayer.framebufferHeight, + { + format: RGBAFormat, + type: UnsignedByteType, + colorSpace: renderer.outputColorSpace, + stencilBuffer: attributes.stencil + } + ); + + } else { + + let depthFormat = null; + let depthType = null; + let glDepthFormat = null; + + if ( attributes.depth ) { + + glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24; + depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat; + depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType; + + } + + const projectionlayerInit = { + colorFormat: gl.RGBA8, + depthFormat: glDepthFormat, + scaleFactor: framebufferScaleFactor + }; + + glBinding = new XRWebGLBinding( session, gl ); + + glProjLayer = glBinding.createProjectionLayer( projectionlayerInit ); + + session.updateRenderState( { layers: [ glProjLayer ] } ); + + renderer.setPixelRatio( 1 ); + renderer.setSize( glProjLayer.textureWidth, glProjLayer.textureHeight, false ); + + newRenderTarget = new WebGLRenderTarget( + glProjLayer.textureWidth, + glProjLayer.textureHeight, + { + format: RGBAFormat, + type: UnsignedByteType, + depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ), + stencilBuffer: attributes.stencil, + colorSpace: renderer.outputColorSpace, + samples: attributes.antialias ? 4 : 0, + resolveDepthBuffer: ( glProjLayer.ignoreDepthValues === false ) + } ); + + } + + newRenderTarget.isXRRenderTarget = true; // TODO Remove this when possible, see #23278 + + this.setFoveation( foveation ); + + customReferenceSpace = null; + referenceSpace = await session.requestReferenceSpace( referenceSpaceType ); + + animation.setContext( session ); + animation.start(); + + scope.isPresenting = true; + + scope.dispatchEvent( { type: 'sessionstart' } ); + + } + + }; + + this.getEnvironmentBlendMode = function () { + + if ( session !== null ) { + + return session.environmentBlendMode; + + } + + }; + + this.getDepthTexture = function () { + + return depthSensing.getDepthTexture(); + + }; + + function onInputSourcesChange( event ) { + + // Notify disconnected + + for ( let i = 0; i < event.removed.length; i ++ ) { + + const inputSource = event.removed[ i ]; + const index = controllerInputSources.indexOf( inputSource ); + + if ( index >= 0 ) { + + controllerInputSources[ index ] = null; + controllers[ index ].disconnect( inputSource ); + + } + + } + + // Notify connected + + for ( let i = 0; i < event.added.length; i ++ ) { + + const inputSource = event.added[ i ]; + + let controllerIndex = controllerInputSources.indexOf( inputSource ); + + if ( controllerIndex === - 1 ) { + + // Assign input source a controller that currently has no input source + + for ( let i = 0; i < controllers.length; i ++ ) { + + if ( i >= controllerInputSources.length ) { + + controllerInputSources.push( inputSource ); + controllerIndex = i; + break; + + } else if ( controllerInputSources[ i ] === null ) { + + controllerInputSources[ i ] = inputSource; + controllerIndex = i; + break; + + } + + } + + // If all controllers do currently receive input we ignore new ones + + if ( controllerIndex === - 1 ) break; + + } + + const controller = controllers[ controllerIndex ]; + + if ( controller ) { + + controller.connect( inputSource ); + + } + + } + + } + + // + + const cameraLPos = new Vector3(); + const cameraRPos = new Vector3(); + + /** + * Assumes 2 cameras that are parallel and share an X-axis, and that + * the cameras' projection and world matrices have already been set. + * And that near and far planes are identical for both cameras. + * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765 + */ + function setProjectionFromUnion( camera, cameraL, cameraR ) { + + cameraLPos.setFromMatrixPosition( cameraL.matrixWorld ); + cameraRPos.setFromMatrixPosition( cameraR.matrixWorld ); + + const ipd = cameraLPos.distanceTo( cameraRPos ); + + const projL = cameraL.projectionMatrix.elements; + const projR = cameraR.projectionMatrix.elements; + + // VR systems will have identical far and near planes, and + // most likely identical top and bottom frustum extents. + // Use the left camera for these values. + const near = projL[ 14 ] / ( projL[ 10 ] - 1 ); + const far = projL[ 14 ] / ( projL[ 10 ] + 1 ); + const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ]; + const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ]; + + const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ]; + const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ]; + const left = near * leftFov; + const right = near * rightFov; + + // Calculate the new camera's position offset from the + // left camera. xOffset should be roughly half `ipd`. + const zOffset = ipd / ( - leftFov + rightFov ); + const xOffset = zOffset * - leftFov; + + // TODO: Better way to apply this offset? + cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale ); + camera.translateX( xOffset ); + camera.translateZ( zOffset ); + camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale ); + camera.matrixWorldInverse.copy( camera.matrixWorld ).invert(); + + // Check if the projection uses an infinite far plane. + if ( projL[ 10 ] === - 1.0 ) { + + // Use the projection matrix from the left eye. + // The camera offset is sufficient to include the view volumes + // of both eyes (assuming symmetric projections). + camera.projectionMatrix.copy( cameraL.projectionMatrix ); + camera.projectionMatrixInverse.copy( cameraL.projectionMatrixInverse ); + + } else { + + // Find the union of the frustum values of the cameras and scale + // the values so that the near plane's position does not change in world space, + // although must now be relative to the new union camera. + const near2 = near + zOffset; + const far2 = far + zOffset; + const left2 = left - xOffset; + const right2 = right + ( ipd - xOffset ); + const top2 = topFov * far / far2 * near2; + const bottom2 = bottomFov * far / far2 * near2; + + camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 ); + camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert(); + + } + + } + + function updateCamera( camera, parent ) { + + if ( parent === null ) { + + camera.matrixWorld.copy( camera.matrix ); + + } else { + + camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix ); + + } + + camera.matrixWorldInverse.copy( camera.matrixWorld ).invert(); + + } + + this.updateCamera = function ( camera ) { + + if ( session === null ) return; + + let depthNear = camera.near; + let depthFar = camera.far; + + if ( depthSensing.texture !== null ) { + + if ( depthSensing.depthNear > 0 ) depthNear = depthSensing.depthNear; + if ( depthSensing.depthFar > 0 ) depthFar = depthSensing.depthFar; + + } + + cameraXR.near = cameraR.near = cameraL.near = depthNear; + cameraXR.far = cameraR.far = cameraL.far = depthFar; + + if ( _currentDepthNear !== cameraXR.near || _currentDepthFar !== cameraXR.far ) { + + // Note that the new renderState won't apply until the next frame. See #18320 + + session.updateRenderState( { + depthNear: cameraXR.near, + depthFar: cameraXR.far + } ); + + _currentDepthNear = cameraXR.near; + _currentDepthFar = cameraXR.far; + + } + + cameraL.layers.mask = camera.layers.mask | 0b010; + cameraR.layers.mask = camera.layers.mask | 0b100; + cameraXR.layers.mask = cameraL.layers.mask | cameraR.layers.mask; + + const parent = camera.parent; + const cameras = cameraXR.cameras; + + updateCamera( cameraXR, parent ); + + for ( let i = 0; i < cameras.length; i ++ ) { + + updateCamera( cameras[ i ], parent ); + + } + + // update projection matrix for proper view frustum culling + + if ( cameras.length === 2 ) { + + setProjectionFromUnion( cameraXR, cameraL, cameraR ); + + } else { + + // assume single camera setup (AR) + + cameraXR.projectionMatrix.copy( cameraL.projectionMatrix ); + + } + + // update user camera and its children + + updateUserCamera( camera, cameraXR, parent ); + + }; + + function updateUserCamera( camera, cameraXR, parent ) { + + if ( parent === null ) { + + camera.matrix.copy( cameraXR.matrixWorld ); + + } else { + + camera.matrix.copy( parent.matrixWorld ); + camera.matrix.invert(); + camera.matrix.multiply( cameraXR.matrixWorld ); + + } + + camera.matrix.decompose( camera.position, camera.quaternion, camera.scale ); + camera.updateMatrixWorld( true ); + + camera.projectionMatrix.copy( cameraXR.projectionMatrix ); + camera.projectionMatrixInverse.copy( cameraXR.projectionMatrixInverse ); + + if ( camera.isPerspectiveCamera ) { + + camera.fov = RAD2DEG * 2 * Math.atan( 1 / camera.projectionMatrix.elements[ 5 ] ); + camera.zoom = 1; + + } + + } + + this.getCamera = function () { + + return cameraXR; + + }; + + this.getFoveation = function () { + + if ( glProjLayer === null && glBaseLayer === null ) { + + return undefined; + + } + + return foveation; + + }; + + this.setFoveation = function ( value ) { + + // 0 = no foveation = full resolution + // 1 = maximum foveation = the edges render at lower resolution + + foveation = value; + + if ( glProjLayer !== null ) { + + glProjLayer.fixedFoveation = value; + + } + + if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) { + + glBaseLayer.fixedFoveation = value; + + } + + }; + + this.hasDepthSensing = function () { + + return depthSensing.texture !== null; + + }; + + this.getDepthSensingMesh = function () { + + return depthSensing.getMesh( cameraXR ); + + }; + + // Animation Loop + + let onAnimationFrameCallback = null; + + function onAnimationFrame( time, frame ) { + + pose = frame.getViewerPose( customReferenceSpace || referenceSpace ); + xrFrame = frame; + + if ( pose !== null ) { + + const views = pose.views; + + if ( glBaseLayer !== null ) { + + renderer.setRenderTargetFramebuffer( newRenderTarget, glBaseLayer.framebuffer ); + renderer.setRenderTarget( newRenderTarget ); + + } + + let cameraXRNeedsUpdate = false; + + // check if it's necessary to rebuild cameraXR's camera list + + if ( views.length !== cameraXR.cameras.length ) { + + cameraXR.cameras.length = 0; + cameraXRNeedsUpdate = true; + + } + + for ( let i = 0; i < views.length; i ++ ) { + + const view = views[ i ]; + + let viewport = null; + + if ( glBaseLayer !== null ) { + + viewport = glBaseLayer.getViewport( view ); + + } else { + + const glSubImage = glBinding.getViewSubImage( glProjLayer, view ); + viewport = glSubImage.viewport; + + // For side-by-side projection, we only produce a single texture for both eyes. + if ( i === 0 ) { + + renderer.setRenderTargetTextures( + newRenderTarget, + glSubImage.colorTexture, + glProjLayer.ignoreDepthValues ? undefined : glSubImage.depthStencilTexture ); + + renderer.setRenderTarget( newRenderTarget ); + + } + + } + + let camera = cameras[ i ]; + + if ( camera === undefined ) { + + camera = new PerspectiveCamera(); + camera.layers.enable( i ); + camera.viewport = new Vector4(); + cameras[ i ] = camera; + + } + + camera.matrix.fromArray( view.transform.matrix ); + camera.matrix.decompose( camera.position, camera.quaternion, camera.scale ); + camera.projectionMatrix.fromArray( view.projectionMatrix ); + camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert(); + camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height ); + + if ( i === 0 ) { + + cameraXR.matrix.copy( camera.matrix ); + cameraXR.matrix.decompose( cameraXR.position, cameraXR.quaternion, cameraXR.scale ); + + } + + if ( cameraXRNeedsUpdate === true ) { + + cameraXR.cameras.push( camera ); + + } + + } + + // + + const enabledFeatures = session.enabledFeatures; + + if ( enabledFeatures && enabledFeatures.includes( 'depth-sensing' ) ) { + + const depthData = glBinding.getDepthInformation( views[ 0 ] ); + + if ( depthData && depthData.isValid && depthData.texture ) { + + depthSensing.init( renderer, depthData, session.renderState ); + + } + + } + + } + + // + + for ( let i = 0; i < controllers.length; i ++ ) { + + const inputSource = controllerInputSources[ i ]; + const controller = controllers[ i ]; + + if ( inputSource !== null && controller !== undefined ) { + + controller.update( inputSource, frame, customReferenceSpace || referenceSpace ); + + } + + } + + if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame ); + + if ( frame.detectedPlanes ) { + + scope.dispatchEvent( { type: 'planesdetected', data: frame } ); + + } + + xrFrame = null; + + } + + const animation = new WebGLAnimation(); + + animation.setAnimationLoop( onAnimationFrame ); + + this.setAnimationLoop = function ( callback ) { + + onAnimationFrameCallback = callback; + + }; + + this.dispose = function () {}; + + } + +} + +const _e1 = /*@__PURE__*/ new Euler(); +const _m1 = /*@__PURE__*/ new Matrix4(); + +function WebGLMaterials( renderer, properties ) { + + function refreshTransformUniform( map, uniform ) { + + if ( map.matrixAutoUpdate === true ) { + + map.updateMatrix(); + + } + + uniform.value.copy( map.matrix ); + + } + + function refreshFogUniforms( uniforms, fog ) { + + fog.color.getRGB( uniforms.fogColor.value, getUnlitUniformColorSpace( renderer ) ); + + if ( fog.isFog ) { + + uniforms.fogNear.value = fog.near; + uniforms.fogFar.value = fog.far; + + } else if ( fog.isFogExp2 ) { + + uniforms.fogDensity.value = fog.density; + + } + + } + + function refreshMaterialUniforms( uniforms, material, pixelRatio, height, transmissionRenderTarget ) { + + if ( material.isMeshBasicMaterial ) { + + refreshUniformsCommon( uniforms, material ); + + } else if ( material.isMeshLambertMaterial ) { + + refreshUniformsCommon( uniforms, material ); + + } else if ( material.isMeshToonMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsToon( uniforms, material ); + + } else if ( material.isMeshPhongMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsPhong( uniforms, material ); + + } else if ( material.isMeshStandardMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsStandard( uniforms, material ); + + if ( material.isMeshPhysicalMaterial ) { + + refreshUniformsPhysical( uniforms, material, transmissionRenderTarget ); + + } + + } else if ( material.isMeshMatcapMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsMatcap( uniforms, material ); + + } else if ( material.isMeshDepthMaterial ) { + + refreshUniformsCommon( uniforms, material ); + + } else if ( material.isMeshDistanceMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsDistance( uniforms, material ); + + } else if ( material.isMeshNormalMaterial ) { + + refreshUniformsCommon( uniforms, material ); + + } else if ( material.isLineBasicMaterial ) { + + refreshUniformsLine( uniforms, material ); + + if ( material.isLineDashedMaterial ) { + + refreshUniformsDash( uniforms, material ); + + } + + } else if ( material.isPointsMaterial ) { + + refreshUniformsPoints( uniforms, material, pixelRatio, height ); + + } else if ( material.isSpriteMaterial ) { + + refreshUniformsSprites( uniforms, material ); + + } else if ( material.isShadowMaterial ) { + + uniforms.color.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + + } else if ( material.isShaderMaterial ) { + + material.uniformsNeedUpdate = false; // #15581 + + } + + } + + function refreshUniformsCommon( uniforms, material ) { + + uniforms.opacity.value = material.opacity; + + if ( material.color ) { + + uniforms.diffuse.value.copy( material.color ); + + } + + if ( material.emissive ) { + + uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity ); + + } + + if ( material.map ) { + + uniforms.map.value = material.map; + + refreshTransformUniform( material.map, uniforms.mapTransform ); + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + refreshTransformUniform( material.alphaMap, uniforms.alphaMapTransform ); + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + + refreshTransformUniform( material.bumpMap, uniforms.bumpMapTransform ); + + uniforms.bumpScale.value = material.bumpScale; + + if ( material.side === BackSide ) { + + uniforms.bumpScale.value *= - 1; + + } + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + + refreshTransformUniform( material.normalMap, uniforms.normalMapTransform ); + + uniforms.normalScale.value.copy( material.normalScale ); + + if ( material.side === BackSide ) { + + uniforms.normalScale.value.negate(); + + } + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + + refreshTransformUniform( material.displacementMap, uniforms.displacementMapTransform ); + + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + refreshTransformUniform( material.emissiveMap, uniforms.emissiveMapTransform ); + + } + + if ( material.specularMap ) { + + uniforms.specularMap.value = material.specularMap; + + refreshTransformUniform( material.specularMap, uniforms.specularMapTransform ); + + } + + if ( material.alphaTest > 0 ) { + + uniforms.alphaTest.value = material.alphaTest; + + } + + const materialProperties = properties.get( material ); + + const envMap = materialProperties.envMap; + const envMapRotation = materialProperties.envMapRotation; + + if ( envMap ) { + + uniforms.envMap.value = envMap; + + _e1.copy( envMapRotation ); + + // accommodate left-handed frame + _e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1; + + if ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) { + + // environment maps which are not cube render targets or PMREMs follow a different convention + _e1.y *= - 1; + _e1.z *= - 1; + + } + + uniforms.envMapRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( _e1 ) ); + + uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1; + + uniforms.reflectivity.value = material.reflectivity; + uniforms.ior.value = material.ior; + uniforms.refractionRatio.value = material.refractionRatio; + + } + + if ( material.lightMap ) { + + uniforms.lightMap.value = material.lightMap; + uniforms.lightMapIntensity.value = material.lightMapIntensity; + + refreshTransformUniform( material.lightMap, uniforms.lightMapTransform ); + + } + + if ( material.aoMap ) { + + uniforms.aoMap.value = material.aoMap; + uniforms.aoMapIntensity.value = material.aoMapIntensity; + + refreshTransformUniform( material.aoMap, uniforms.aoMapTransform ); + + } + + } + + function refreshUniformsLine( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + + if ( material.map ) { + + uniforms.map.value = material.map; + + refreshTransformUniform( material.map, uniforms.mapTransform ); + + } + + } + + function refreshUniformsDash( uniforms, material ) { + + uniforms.dashSize.value = material.dashSize; + uniforms.totalSize.value = material.dashSize + material.gapSize; + uniforms.scale.value = material.scale; + + } + + function refreshUniformsPoints( uniforms, material, pixelRatio, height ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.size.value = material.size * pixelRatio; + uniforms.scale.value = height * 0.5; + + if ( material.map ) { + + uniforms.map.value = material.map; + + refreshTransformUniform( material.map, uniforms.uvTransform ); + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + refreshTransformUniform( material.alphaMap, uniforms.alphaMapTransform ); + + } + + if ( material.alphaTest > 0 ) { + + uniforms.alphaTest.value = material.alphaTest; + + } + + } + + function refreshUniformsSprites( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.rotation.value = material.rotation; + + if ( material.map ) { + + uniforms.map.value = material.map; + + refreshTransformUniform( material.map, uniforms.mapTransform ); + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + refreshTransformUniform( material.alphaMap, uniforms.alphaMapTransform ); + + } + + if ( material.alphaTest > 0 ) { + + uniforms.alphaTest.value = material.alphaTest; + + } + + } + + function refreshUniformsPhong( uniforms, material ) { + + uniforms.specular.value.copy( material.specular ); + uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) + + } + + function refreshUniformsToon( uniforms, material ) { + + if ( material.gradientMap ) { + + uniforms.gradientMap.value = material.gradientMap; + + } + + } + + function refreshUniformsStandard( uniforms, material ) { + + uniforms.metalness.value = material.metalness; + + if ( material.metalnessMap ) { + + uniforms.metalnessMap.value = material.metalnessMap; + + refreshTransformUniform( material.metalnessMap, uniforms.metalnessMapTransform ); + + } + + uniforms.roughness.value = material.roughness; + + if ( material.roughnessMap ) { + + uniforms.roughnessMap.value = material.roughnessMap; + + refreshTransformUniform( material.roughnessMap, uniforms.roughnessMapTransform ); + + } + + if ( material.envMap ) { + + //uniforms.envMap.value = material.envMap; // part of uniforms common + + uniforms.envMapIntensity.value = material.envMapIntensity; + + } + + } + + function refreshUniformsPhysical( uniforms, material, transmissionRenderTarget ) { + + uniforms.ior.value = material.ior; // also part of uniforms common + + if ( material.sheen > 0 ) { + + uniforms.sheenColor.value.copy( material.sheenColor ).multiplyScalar( material.sheen ); + + uniforms.sheenRoughness.value = material.sheenRoughness; + + if ( material.sheenColorMap ) { + + uniforms.sheenColorMap.value = material.sheenColorMap; + + refreshTransformUniform( material.sheenColorMap, uniforms.sheenColorMapTransform ); + + } + + if ( material.sheenRoughnessMap ) { + + uniforms.sheenRoughnessMap.value = material.sheenRoughnessMap; + + refreshTransformUniform( material.sheenRoughnessMap, uniforms.sheenRoughnessMapTransform ); + + } + + } + + if ( material.clearcoat > 0 ) { + + uniforms.clearcoat.value = material.clearcoat; + uniforms.clearcoatRoughness.value = material.clearcoatRoughness; + + if ( material.clearcoatMap ) { + + uniforms.clearcoatMap.value = material.clearcoatMap; + + refreshTransformUniform( material.clearcoatMap, uniforms.clearcoatMapTransform ); + + } + + if ( material.clearcoatRoughnessMap ) { + + uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; + + refreshTransformUniform( material.clearcoatRoughnessMap, uniforms.clearcoatRoughnessMapTransform ); + + } + + if ( material.clearcoatNormalMap ) { + + uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; + + refreshTransformUniform( material.clearcoatNormalMap, uniforms.clearcoatNormalMapTransform ); + + uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale ); + + if ( material.side === BackSide ) { + + uniforms.clearcoatNormalScale.value.negate(); + + } + + } + + } + + if ( material.dispersion > 0 ) { + + uniforms.dispersion.value = material.dispersion; + + } + + if ( material.iridescence > 0 ) { + + uniforms.iridescence.value = material.iridescence; + uniforms.iridescenceIOR.value = material.iridescenceIOR; + uniforms.iridescenceThicknessMinimum.value = material.iridescenceThicknessRange[ 0 ]; + uniforms.iridescenceThicknessMaximum.value = material.iridescenceThicknessRange[ 1 ]; + + if ( material.iridescenceMap ) { + + uniforms.iridescenceMap.value = material.iridescenceMap; + + refreshTransformUniform( material.iridescenceMap, uniforms.iridescenceMapTransform ); + + } + + if ( material.iridescenceThicknessMap ) { + + uniforms.iridescenceThicknessMap.value = material.iridescenceThicknessMap; + + refreshTransformUniform( material.iridescenceThicknessMap, uniforms.iridescenceThicknessMapTransform ); + + } + + } + + if ( material.transmission > 0 ) { + + uniforms.transmission.value = material.transmission; + uniforms.transmissionSamplerMap.value = transmissionRenderTarget.texture; + uniforms.transmissionSamplerSize.value.set( transmissionRenderTarget.width, transmissionRenderTarget.height ); + + if ( material.transmissionMap ) { + + uniforms.transmissionMap.value = material.transmissionMap; + + refreshTransformUniform( material.transmissionMap, uniforms.transmissionMapTransform ); + + } + + uniforms.thickness.value = material.thickness; + + if ( material.thicknessMap ) { + + uniforms.thicknessMap.value = material.thicknessMap; + + refreshTransformUniform( material.thicknessMap, uniforms.thicknessMapTransform ); + + } + + uniforms.attenuationDistance.value = material.attenuationDistance; + uniforms.attenuationColor.value.copy( material.attenuationColor ); + + } + + if ( material.anisotropy > 0 ) { + + uniforms.anisotropyVector.value.set( material.anisotropy * Math.cos( material.anisotropyRotation ), material.anisotropy * Math.sin( material.anisotropyRotation ) ); + + if ( material.anisotropyMap ) { + + uniforms.anisotropyMap.value = material.anisotropyMap; + + refreshTransformUniform( material.anisotropyMap, uniforms.anisotropyMapTransform ); + + } + + } + + uniforms.specularIntensity.value = material.specularIntensity; + uniforms.specularColor.value.copy( material.specularColor ); + + if ( material.specularColorMap ) { + + uniforms.specularColorMap.value = material.specularColorMap; + + refreshTransformUniform( material.specularColorMap, uniforms.specularColorMapTransform ); + + } + + if ( material.specularIntensityMap ) { + + uniforms.specularIntensityMap.value = material.specularIntensityMap; + + refreshTransformUniform( material.specularIntensityMap, uniforms.specularIntensityMapTransform ); + + } + + } + + function refreshUniformsMatcap( uniforms, material ) { + + if ( material.matcap ) { + + uniforms.matcap.value = material.matcap; + + } + + } + + function refreshUniformsDistance( uniforms, material ) { + + const light = properties.get( material ).light; + + uniforms.referencePosition.value.setFromMatrixPosition( light.matrixWorld ); + uniforms.nearDistance.value = light.shadow.camera.near; + uniforms.farDistance.value = light.shadow.camera.far; + + } + + return { + refreshFogUniforms: refreshFogUniforms, + refreshMaterialUniforms: refreshMaterialUniforms + }; + +} + +function WebGLUniformsGroups( gl, info, capabilities, state ) { + + let buffers = {}; + let updateList = {}; + let allocatedBindingPoints = []; + + const maxBindingPoints = gl.getParameter( gl.MAX_UNIFORM_BUFFER_BINDINGS ); // binding points are global whereas block indices are per shader program + + function bind( uniformsGroup, program ) { + + const webglProgram = program.program; + state.uniformBlockBinding( uniformsGroup, webglProgram ); + + } + + function update( uniformsGroup, program ) { + + let buffer = buffers[ uniformsGroup.id ]; + + if ( buffer === undefined ) { + + prepareUniformsGroup( uniformsGroup ); + + buffer = createBuffer( uniformsGroup ); + buffers[ uniformsGroup.id ] = buffer; + + uniformsGroup.addEventListener( 'dispose', onUniformsGroupsDispose ); + + } + + // ensure to update the binding points/block indices mapping for this program + + const webglProgram = program.program; + state.updateUBOMapping( uniformsGroup, webglProgram ); + + // update UBO once per frame + + const frame = info.render.frame; + + if ( updateList[ uniformsGroup.id ] !== frame ) { + + updateBufferData( uniformsGroup ); + + updateList[ uniformsGroup.id ] = frame; + + } + + } + + function createBuffer( uniformsGroup ) { + + // the setup of an UBO is independent of a particular shader program but global + + const bindingPointIndex = allocateBindingPointIndex(); + uniformsGroup.__bindingPointIndex = bindingPointIndex; + + const buffer = gl.createBuffer(); + const size = uniformsGroup.__size; + const usage = uniformsGroup.usage; + + gl.bindBuffer( gl.UNIFORM_BUFFER, buffer ); + gl.bufferData( gl.UNIFORM_BUFFER, size, usage ); + gl.bindBuffer( gl.UNIFORM_BUFFER, null ); + gl.bindBufferBase( gl.UNIFORM_BUFFER, bindingPointIndex, buffer ); + + return buffer; + + } + + function allocateBindingPointIndex() { + + for ( let i = 0; i < maxBindingPoints; i ++ ) { + + if ( allocatedBindingPoints.indexOf( i ) === - 1 ) { + + allocatedBindingPoints.push( i ); + return i; + + } + + } + + console.error( 'THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached.' ); + + return 0; + + } + + function updateBufferData( uniformsGroup ) { + + const buffer = buffers[ uniformsGroup.id ]; + const uniforms = uniformsGroup.uniforms; + const cache = uniformsGroup.__cache; + + gl.bindBuffer( gl.UNIFORM_BUFFER, buffer ); + + for ( let i = 0, il = uniforms.length; i < il; i ++ ) { + + const uniformArray = Array.isArray( uniforms[ i ] ) ? uniforms[ i ] : [ uniforms[ i ] ]; + + for ( let j = 0, jl = uniformArray.length; j < jl; j ++ ) { + + const uniform = uniformArray[ j ]; + + if ( hasUniformChanged( uniform, i, j, cache ) === true ) { + + const offset = uniform.__offset; + + const values = Array.isArray( uniform.value ) ? uniform.value : [ uniform.value ]; + + let arrayOffset = 0; + + for ( let k = 0; k < values.length; k ++ ) { + + const value = values[ k ]; + + const info = getUniformSize( value ); + + // TODO add integer and struct support + if ( typeof value === 'number' || typeof value === 'boolean' ) { + + uniform.__data[ 0 ] = value; + gl.bufferSubData( gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data ); + + } else if ( value.isMatrix3 ) { + + // manually converting 3x3 to 3x4 + + uniform.__data[ 0 ] = value.elements[ 0 ]; + uniform.__data[ 1 ] = value.elements[ 1 ]; + uniform.__data[ 2 ] = value.elements[ 2 ]; + uniform.__data[ 3 ] = 0; + uniform.__data[ 4 ] = value.elements[ 3 ]; + uniform.__data[ 5 ] = value.elements[ 4 ]; + uniform.__data[ 6 ] = value.elements[ 5 ]; + uniform.__data[ 7 ] = 0; + uniform.__data[ 8 ] = value.elements[ 6 ]; + uniform.__data[ 9 ] = value.elements[ 7 ]; + uniform.__data[ 10 ] = value.elements[ 8 ]; + uniform.__data[ 11 ] = 0; + + } else { + + value.toArray( uniform.__data, arrayOffset ); + + arrayOffset += info.storage / Float32Array.BYTES_PER_ELEMENT; + + } + + } + + gl.bufferSubData( gl.UNIFORM_BUFFER, offset, uniform.__data ); + + } + + } + + } + + gl.bindBuffer( gl.UNIFORM_BUFFER, null ); + + } + + function hasUniformChanged( uniform, index, indexArray, cache ) { + + const value = uniform.value; + const indexString = index + '_' + indexArray; + + if ( cache[ indexString ] === undefined ) { + + // cache entry does not exist so far + + if ( typeof value === 'number' || typeof value === 'boolean' ) { + + cache[ indexString ] = value; + + } else { + + cache[ indexString ] = value.clone(); + + } + + return true; + + } else { + + const cachedObject = cache[ indexString ]; + + // compare current value with cached entry + + if ( typeof value === 'number' || typeof value === 'boolean' ) { + + if ( cachedObject !== value ) { + + cache[ indexString ] = value; + return true; + + } + + } else { + + if ( cachedObject.equals( value ) === false ) { + + cachedObject.copy( value ); + return true; + + } + + } + + } + + return false; + + } + + function prepareUniformsGroup( uniformsGroup ) { + + // determine total buffer size according to the STD140 layout + // Hint: STD140 is the only supported layout in WebGL 2 + + const uniforms = uniformsGroup.uniforms; + + let offset = 0; // global buffer offset in bytes + const chunkSize = 16; // size of a chunk in bytes + + for ( let i = 0, l = uniforms.length; i < l; i ++ ) { + + const uniformArray = Array.isArray( uniforms[ i ] ) ? uniforms[ i ] : [ uniforms[ i ] ]; + + for ( let j = 0, jl = uniformArray.length; j < jl; j ++ ) { + + const uniform = uniformArray[ j ]; + + const values = Array.isArray( uniform.value ) ? uniform.value : [ uniform.value ]; + + for ( let k = 0, kl = values.length; k < kl; k ++ ) { + + const value = values[ k ]; + + const info = getUniformSize( value ); + + const chunkOffset = offset % chunkSize; // offset in the current chunk + const chunkPadding = chunkOffset % info.boundary; // required padding to match boundary + const chunkStart = chunkOffset + chunkPadding; // the start position in the current chunk for the data + + offset += chunkPadding; + + // Check for chunk overflow + if ( chunkStart !== 0 && ( chunkSize - chunkStart ) < info.storage ) { + + // Add padding and adjust offset + offset += ( chunkSize - chunkStart ); + + } + + // the following two properties will be used for partial buffer updates + uniform.__data = new Float32Array( info.storage / Float32Array.BYTES_PER_ELEMENT ); + uniform.__offset = offset; + + // Update the global offset + offset += info.storage; + + } + + } + + } + + // ensure correct final padding + + const chunkOffset = offset % chunkSize; + + if ( chunkOffset > 0 ) offset += ( chunkSize - chunkOffset ); + + // + + uniformsGroup.__size = offset; + uniformsGroup.__cache = {}; + + return this; + + } + + function getUniformSize( value ) { + + const info = { + boundary: 0, // bytes + storage: 0 // bytes + }; + + // determine sizes according to STD140 + + if ( typeof value === 'number' || typeof value === 'boolean' ) { + + // float/int/bool + + info.boundary = 4; + info.storage = 4; + + } else if ( value.isVector2 ) { + + // vec2 + + info.boundary = 8; + info.storage = 8; + + } else if ( value.isVector3 || value.isColor ) { + + // vec3 + + info.boundary = 16; + info.storage = 12; // evil: vec3 must start on a 16-byte boundary but it only consumes 12 bytes + + } else if ( value.isVector4 ) { + + // vec4 + + info.boundary = 16; + info.storage = 16; + + } else if ( value.isMatrix3 ) { + + // mat3 (in STD140 a 3x3 matrix is represented as 3x4) + + info.boundary = 48; + info.storage = 48; + + } else if ( value.isMatrix4 ) { + + // mat4 + + info.boundary = 64; + info.storage = 64; + + } else if ( value.isTexture ) { + + console.warn( 'THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group.' ); + + } else { + + console.warn( 'THREE.WebGLRenderer: Unsupported uniform value type.', value ); + + } + + return info; + + } + + function onUniformsGroupsDispose( event ) { + + const uniformsGroup = event.target; + + uniformsGroup.removeEventListener( 'dispose', onUniformsGroupsDispose ); + + const index = allocatedBindingPoints.indexOf( uniformsGroup.__bindingPointIndex ); + allocatedBindingPoints.splice( index, 1 ); + + gl.deleteBuffer( buffers[ uniformsGroup.id ] ); + + delete buffers[ uniformsGroup.id ]; + delete updateList[ uniformsGroup.id ]; + + } + + function dispose() { + + for ( const id in buffers ) { + + gl.deleteBuffer( buffers[ id ] ); + + } + + allocatedBindingPoints = []; + buffers = {}; + updateList = {}; + + } + + return { + + bind: bind, + update: update, + + dispose: dispose + + }; + +} + +class WebGLRenderer { + + constructor( parameters = {} ) { + + const { + canvas = createCanvasElement(), + context = null, + depth = true, + stencil = false, + alpha = false, + antialias = false, + premultipliedAlpha = true, + preserveDrawingBuffer = false, + powerPreference = 'default', + failIfMajorPerformanceCaveat = false, + reverseDepthBuffer = false, + } = parameters; + + this.isWebGLRenderer = true; + + let _alpha; + + if ( context !== null ) { + + if ( typeof WebGLRenderingContext !== 'undefined' && context instanceof WebGLRenderingContext ) { + + throw new Error( 'THREE.WebGLRenderer: WebGL 1 is not supported since r163.' ); + + } + + _alpha = context.getContextAttributes().alpha; + + } else { + + _alpha = alpha; + + } + + const uintClearColor = new Uint32Array( 4 ); + const intClearColor = new Int32Array( 4 ); + + let currentRenderList = null; + let currentRenderState = null; + + // render() can be called from within a callback triggered by another render. + // We track this so that the nested render call gets its list and state isolated from the parent render call. + + const renderListStack = []; + const renderStateStack = []; + + // public properties + + this.domElement = canvas; + + // Debug configuration container + this.debug = { + + /** + * Enables error checking and reporting when shader programs are being compiled + * @type {boolean} + */ + checkShaderErrors: true, + /** + * Callback for custom error reporting. + * @type {?Function} + */ + onShaderError: null + }; + + // clearing + + this.autoClear = true; + this.autoClearColor = true; + this.autoClearDepth = true; + this.autoClearStencil = true; + + // scene graph + + this.sortObjects = true; + + // user-defined clipping + + this.clippingPlanes = []; + this.localClippingEnabled = false; + + // physically based shading + + this._outputColorSpace = SRGBColorSpace; + + // tone mapping + + this.toneMapping = NoToneMapping; + this.toneMappingExposure = 1.0; + + // internal properties + + const _this = this; + + let _isContextLost = false; + + // internal state cache + + let _currentActiveCubeFace = 0; + let _currentActiveMipmapLevel = 0; + let _currentRenderTarget = null; + let _currentMaterialId = - 1; + + let _currentCamera = null; + + const _currentViewport = new Vector4(); + const _currentScissor = new Vector4(); + let _currentScissorTest = null; + + const _currentClearColor = new Color( 0x000000 ); + let _currentClearAlpha = 0; + + // + + let _width = canvas.width; + let _height = canvas.height; + + let _pixelRatio = 1; + let _opaqueSort = null; + let _transparentSort = null; + + const _viewport = new Vector4( 0, 0, _width, _height ); + const _scissor = new Vector4( 0, 0, _width, _height ); + let _scissorTest = false; + + // frustum + + const _frustum = new Frustum(); + + // clipping + + let _clippingEnabled = false; + let _localClippingEnabled = false; + + // camera matrices cache + + const _currentProjectionMatrix = new Matrix4(); + const _projScreenMatrix = new Matrix4(); + + const _vector3 = new Vector3(); + + const _vector4 = new Vector4(); + + const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true }; + + let _renderBackground = false; + + function getTargetPixelRatio() { + + return _currentRenderTarget === null ? _pixelRatio : 1; + + } + + // initialize + + let _gl = context; + + function getContext( contextName, contextAttributes ) { + + return canvas.getContext( contextName, contextAttributes ); + + } + + try { + + const contextAttributes = { + alpha: true, + depth, + stencil, + antialias, + premultipliedAlpha, + preserveDrawingBuffer, + powerPreference, + failIfMajorPerformanceCaveat, + }; + + // OffscreenCanvas does not have setAttribute, see #22811 + if ( 'setAttribute' in canvas ) canvas.setAttribute( 'data-engine', `three.js r${REVISION}` ); + + // event listeners must be registered before WebGL context is created, see #12753 + canvas.addEventListener( 'webglcontextlost', onContextLost, false ); + canvas.addEventListener( 'webglcontextrestored', onContextRestore, false ); + canvas.addEventListener( 'webglcontextcreationerror', onContextCreationError, false ); + + if ( _gl === null ) { + + const contextName = 'webgl2'; + + _gl = getContext( contextName, contextAttributes ); + + if ( _gl === null ) { + + if ( getContext( contextName ) ) { + + throw new Error( 'Error creating WebGL context with your selected attributes.' ); + + } else { + + throw new Error( 'Error creating WebGL context.' ); + + } + + } + + } + + } catch ( error ) { + + console.error( 'THREE.WebGLRenderer: ' + error.message ); + throw error; + + } + + let extensions, capabilities, state, info; + let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects; + let programCache, materials, renderLists, renderStates, clipping, shadowMap; + + let background, morphtargets, bufferRenderer, indexedBufferRenderer; + + let utils, bindingStates, uniformsGroups; + + function initGLContext() { + + extensions = new WebGLExtensions( _gl ); + extensions.init(); + + utils = new WebGLUtils( _gl, extensions ); + + capabilities = new WebGLCapabilities( _gl, extensions, parameters, utils ); + + state = new WebGLState( _gl, extensions ); + + if ( capabilities.reverseDepthBuffer && reverseDepthBuffer ) { + + state.buffers.depth.setReversed( true ); + + } + + info = new WebGLInfo( _gl ); + properties = new WebGLProperties(); + textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ); + cubemaps = new WebGLCubeMaps( _this ); + cubeuvmaps = new WebGLCubeUVMaps( _this ); + attributes = new WebGLAttributes( _gl ); + bindingStates = new WebGLBindingStates( _gl, attributes ); + geometries = new WebGLGeometries( _gl, attributes, info, bindingStates ); + objects = new WebGLObjects( _gl, geometries, attributes, info ); + morphtargets = new WebGLMorphtargets( _gl, capabilities, textures ); + clipping = new WebGLClipping( properties ); + programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping ); + materials = new WebGLMaterials( _this, properties ); + renderLists = new WebGLRenderLists(); + renderStates = new WebGLRenderStates( extensions ); + background = new WebGLBackground( _this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha ); + shadowMap = new WebGLShadowMap( _this, objects, capabilities ); + uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state ); + + bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info ); + indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info ); + + info.programs = programCache.programs; + + _this.capabilities = capabilities; + _this.extensions = extensions; + _this.properties = properties; + _this.renderLists = renderLists; + _this.shadowMap = shadowMap; + _this.state = state; + _this.info = info; + + } + + initGLContext(); + + // xr + + const xr = new WebXRManager( _this, _gl ); + + this.xr = xr; + + // API + + this.getContext = function () { + + return _gl; + + }; + + this.getContextAttributes = function () { + + return _gl.getContextAttributes(); + + }; + + this.forceContextLoss = function () { + + const extension = extensions.get( 'WEBGL_lose_context' ); + if ( extension ) extension.loseContext(); + + }; + + this.forceContextRestore = function () { + + const extension = extensions.get( 'WEBGL_lose_context' ); + if ( extension ) extension.restoreContext(); + + }; + + this.getPixelRatio = function () { + + return _pixelRatio; + + }; + + this.setPixelRatio = function ( value ) { + + if ( value === undefined ) return; + + _pixelRatio = value; + + this.setSize( _width, _height, false ); + + }; + + this.getSize = function ( target ) { + + return target.set( _width, _height ); + + }; + + this.setSize = function ( width, height, updateStyle = true ) { + + if ( xr.isPresenting ) { + + console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' ); + return; + + } + + _width = width; + _height = height; + + canvas.width = Math.floor( width * _pixelRatio ); + canvas.height = Math.floor( height * _pixelRatio ); + + if ( updateStyle === true ) { + + canvas.style.width = width + 'px'; + canvas.style.height = height + 'px'; + + } + + this.setViewport( 0, 0, width, height ); + + }; + + this.getDrawingBufferSize = function ( target ) { + + return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor(); + + }; + + this.setDrawingBufferSize = function ( width, height, pixelRatio ) { + + _width = width; + _height = height; + + _pixelRatio = pixelRatio; + + canvas.width = Math.floor( width * pixelRatio ); + canvas.height = Math.floor( height * pixelRatio ); + + this.setViewport( 0, 0, width, height ); + + }; + + this.getCurrentViewport = function ( target ) { + + return target.copy( _currentViewport ); + + }; + + this.getViewport = function ( target ) { + + return target.copy( _viewport ); + + }; + + this.setViewport = function ( x, y, width, height ) { + + if ( x.isVector4 ) { + + _viewport.set( x.x, x.y, x.z, x.w ); + + } else { + + _viewport.set( x, y, width, height ); + + } + + state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).round() ); + + }; + + this.getScissor = function ( target ) { + + return target.copy( _scissor ); + + }; + + this.setScissor = function ( x, y, width, height ) { + + if ( x.isVector4 ) { + + _scissor.set( x.x, x.y, x.z, x.w ); + + } else { + + _scissor.set( x, y, width, height ); + + } + + state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).round() ); + + }; + + this.getScissorTest = function () { + + return _scissorTest; + + }; + + this.setScissorTest = function ( boolean ) { + + state.setScissorTest( _scissorTest = boolean ); + + }; + + this.setOpaqueSort = function ( method ) { + + _opaqueSort = method; + + }; + + this.setTransparentSort = function ( method ) { + + _transparentSort = method; + + }; + + // Clearing + + this.getClearColor = function ( target ) { + + return target.copy( background.getClearColor() ); + + }; + + this.setClearColor = function () { + + background.setClearColor.apply( background, arguments ); + + }; + + this.getClearAlpha = function () { + + return background.getClearAlpha(); + + }; + + this.setClearAlpha = function () { + + background.setClearAlpha.apply( background, arguments ); + + }; + + this.clear = function ( color = true, depth = true, stencil = true ) { + + let bits = 0; + + if ( color ) { + + // check if we're trying to clear an integer target + let isIntegerFormat = false; + if ( _currentRenderTarget !== null ) { + + const targetFormat = _currentRenderTarget.texture.format; + isIntegerFormat = targetFormat === RGBAIntegerFormat || + targetFormat === RGIntegerFormat || + targetFormat === RedIntegerFormat; + + } + + // use the appropriate clear functions to clear the target if it's a signed + // or unsigned integer target + if ( isIntegerFormat ) { + + const targetType = _currentRenderTarget.texture.type; + const isUnsignedType = targetType === UnsignedByteType || + targetType === UnsignedIntType || + targetType === UnsignedShortType || + targetType === UnsignedInt248Type || + targetType === UnsignedShort4444Type || + targetType === UnsignedShort5551Type; + + const clearColor = background.getClearColor(); + const a = background.getClearAlpha(); + const r = clearColor.r; + const g = clearColor.g; + const b = clearColor.b; + + if ( isUnsignedType ) { + + uintClearColor[ 0 ] = r; + uintClearColor[ 1 ] = g; + uintClearColor[ 2 ] = b; + uintClearColor[ 3 ] = a; + _gl.clearBufferuiv( _gl.COLOR, 0, uintClearColor ); + + } else { + + intClearColor[ 0 ] = r; + intClearColor[ 1 ] = g; + intClearColor[ 2 ] = b; + intClearColor[ 3 ] = a; + _gl.clearBufferiv( _gl.COLOR, 0, intClearColor ); + + } + + } else { + + bits |= _gl.COLOR_BUFFER_BIT; + + } + + } + + if ( depth ) { + + bits |= _gl.DEPTH_BUFFER_BIT; + + } + + if ( stencil ) { + + bits |= _gl.STENCIL_BUFFER_BIT; + this.state.buffers.stencil.setMask( 0xffffffff ); + + } + + _gl.clear( bits ); + + }; + + this.clearColor = function () { + + this.clear( true, false, false ); + + }; + + this.clearDepth = function () { + + this.clear( false, true, false ); + + }; + + this.clearStencil = function () { + + this.clear( false, false, true ); + + }; + + // + + this.dispose = function () { + + canvas.removeEventListener( 'webglcontextlost', onContextLost, false ); + canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false ); + canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false ); + + background.dispose(); + renderLists.dispose(); + renderStates.dispose(); + properties.dispose(); + cubemaps.dispose(); + cubeuvmaps.dispose(); + objects.dispose(); + bindingStates.dispose(); + uniformsGroups.dispose(); + programCache.dispose(); + + xr.dispose(); + + xr.removeEventListener( 'sessionstart', onXRSessionStart ); + xr.removeEventListener( 'sessionend', onXRSessionEnd ); + + animation.stop(); + + }; + + // Events + + function onContextLost( event ) { + + event.preventDefault(); + + console.log( 'THREE.WebGLRenderer: Context Lost.' ); + + _isContextLost = true; + + } + + function onContextRestore( /* event */ ) { + + console.log( 'THREE.WebGLRenderer: Context Restored.' ); + + _isContextLost = false; + + const infoAutoReset = info.autoReset; + const shadowMapEnabled = shadowMap.enabled; + const shadowMapAutoUpdate = shadowMap.autoUpdate; + const shadowMapNeedsUpdate = shadowMap.needsUpdate; + const shadowMapType = shadowMap.type; + + initGLContext(); + + info.autoReset = infoAutoReset; + shadowMap.enabled = shadowMapEnabled; + shadowMap.autoUpdate = shadowMapAutoUpdate; + shadowMap.needsUpdate = shadowMapNeedsUpdate; + shadowMap.type = shadowMapType; + + } + + function onContextCreationError( event ) { + + console.error( 'THREE.WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage ); + + } + + function onMaterialDispose( event ) { + + const material = event.target; + + material.removeEventListener( 'dispose', onMaterialDispose ); + + deallocateMaterial( material ); + + } + + // Buffer deallocation + + function deallocateMaterial( material ) { + + releaseMaterialProgramReferences( material ); + + properties.remove( material ); + + } + + + function releaseMaterialProgramReferences( material ) { + + const programs = properties.get( material ).programs; + + if ( programs !== undefined ) { + + programs.forEach( function ( program ) { + + programCache.releaseProgram( program ); + + } ); + + if ( material.isShaderMaterial ) { + + programCache.releaseShaderCache( material ); + + } + + } + + } + + // Buffer rendering + + this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) { + + if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null) + + const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 ); + + const program = setProgram( camera, scene, geometry, material, object ); + + state.setMaterial( material, frontFaceCW ); + + // + + let index = geometry.index; + let rangeFactor = 1; + + if ( material.wireframe === true ) { + + index = geometries.getWireframeAttribute( geometry ); + + if ( index === undefined ) return; + + rangeFactor = 2; + + } + + // + + const drawRange = geometry.drawRange; + const position = geometry.attributes.position; + + let drawStart = drawRange.start * rangeFactor; + let drawEnd = ( drawRange.start + drawRange.count ) * rangeFactor; + + if ( group !== null ) { + + drawStart = Math.max( drawStart, group.start * rangeFactor ); + drawEnd = Math.min( drawEnd, ( group.start + group.count ) * rangeFactor ); + + } + + if ( index !== null ) { + + drawStart = Math.max( drawStart, 0 ); + drawEnd = Math.min( drawEnd, index.count ); + + } else if ( position !== undefined && position !== null ) { + + drawStart = Math.max( drawStart, 0 ); + drawEnd = Math.min( drawEnd, position.count ); + + } + + const drawCount = drawEnd - drawStart; + + if ( drawCount < 0 || drawCount === Infinity ) return; + + // + + bindingStates.setup( object, material, program, geometry, index ); + + let attribute; + let renderer = bufferRenderer; + + if ( index !== null ) { + + attribute = attributes.get( index ); + + renderer = indexedBufferRenderer; + renderer.setIndex( attribute ); + + } + + // + + if ( object.isMesh ) { + + if ( material.wireframe === true ) { + + state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() ); + renderer.setMode( _gl.LINES ); + + } else { + + renderer.setMode( _gl.TRIANGLES ); + + } + + } else if ( object.isLine ) { + + let lineWidth = material.linewidth; + + if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material + + state.setLineWidth( lineWidth * getTargetPixelRatio() ); + + if ( object.isLineSegments ) { + + renderer.setMode( _gl.LINES ); + + } else if ( object.isLineLoop ) { + + renderer.setMode( _gl.LINE_LOOP ); + + } else { + + renderer.setMode( _gl.LINE_STRIP ); + + } + + } else if ( object.isPoints ) { + + renderer.setMode( _gl.POINTS ); + + } else if ( object.isSprite ) { + + renderer.setMode( _gl.TRIANGLES ); + + } + + if ( object.isBatchedMesh ) { + + if ( object._multiDrawInstances !== null ) { + + renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances ); + + } else { + + if ( ! extensions.get( 'WEBGL_multi_draw' ) ) { + + const starts = object._multiDrawStarts; + const counts = object._multiDrawCounts; + const drawCount = object._multiDrawCount; + const bytesPerElement = index ? attributes.get( index ).bytesPerElement : 1; + const uniforms = properties.get( material ).currentProgram.getUniforms(); + for ( let i = 0; i < drawCount; i ++ ) { + + uniforms.setValue( _gl, '_gl_DrawID', i ); + renderer.render( starts[ i ] / bytesPerElement, counts[ i ] ); + + } + + } else { + + renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount ); + + } + + } + + } else if ( object.isInstancedMesh ) { + + renderer.renderInstances( drawStart, drawCount, object.count ); + + } else if ( geometry.isInstancedBufferGeometry ) { + + const maxInstanceCount = geometry._maxInstanceCount !== undefined ? geometry._maxInstanceCount : Infinity; + const instanceCount = Math.min( geometry.instanceCount, maxInstanceCount ); + + renderer.renderInstances( drawStart, drawCount, instanceCount ); + + } else { + + renderer.render( drawStart, drawCount ); + + } + + }; + + // Compile + + function prepareMaterial( material, scene, object ) { + + if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) { + + material.side = BackSide; + material.needsUpdate = true; + getProgram( material, scene, object ); + + material.side = FrontSide; + material.needsUpdate = true; + getProgram( material, scene, object ); + + material.side = DoubleSide; + + } else { + + getProgram( material, scene, object ); + + } + + } + + this.compile = function ( scene, camera, targetScene = null ) { + + if ( targetScene === null ) targetScene = scene; + + currentRenderState = renderStates.get( targetScene ); + currentRenderState.init( camera ); + + renderStateStack.push( currentRenderState ); + + // gather lights from both the target scene and the new object that will be added to the scene. + + targetScene.traverseVisible( function ( object ) { + + if ( object.isLight && object.layers.test( camera.layers ) ) { + + currentRenderState.pushLight( object ); + + if ( object.castShadow ) { + + currentRenderState.pushShadow( object ); + + } + + } + + } ); + + if ( scene !== targetScene ) { + + scene.traverseVisible( function ( object ) { + + if ( object.isLight && object.layers.test( camera.layers ) ) { + + currentRenderState.pushLight( object ); + + if ( object.castShadow ) { + + currentRenderState.pushShadow( object ); + + } + + } + + } ); + + } + + currentRenderState.setupLights(); + + // Only initialize materials in the new scene, not the targetScene. + + const materials = new Set(); + + scene.traverse( function ( object ) { + + if ( ! ( object.isMesh || object.isPoints || object.isLine || object.isSprite ) ) { + + return; + + } + + const material = object.material; + + if ( material ) { + + if ( Array.isArray( material ) ) { + + for ( let i = 0; i < material.length; i ++ ) { + + const material2 = material[ i ]; + + prepareMaterial( material2, targetScene, object ); + materials.add( material2 ); + + } + + } else { + + prepareMaterial( material, targetScene, object ); + materials.add( material ); + + } + + } + + } ); + + renderStateStack.pop(); + currentRenderState = null; + + return materials; + + }; + + // compileAsync + + this.compileAsync = function ( scene, camera, targetScene = null ) { + + const materials = this.compile( scene, camera, targetScene ); + + // Wait for all the materials in the new object to indicate that they're + // ready to be used before resolving the promise. + + return new Promise( ( resolve ) => { + + function checkMaterialsReady() { + + materials.forEach( function ( material ) { + + const materialProperties = properties.get( material ); + const program = materialProperties.currentProgram; + + if ( program.isReady() ) { + + // remove any programs that report they're ready to use from the list + materials.delete( material ); + + } + + } ); + + // once the list of compiling materials is empty, call the callback + + if ( materials.size === 0 ) { + + resolve( scene ); + return; + + } + + // if some materials are still not ready, wait a bit and check again + + setTimeout( checkMaterialsReady, 10 ); + + } + + if ( extensions.get( 'KHR_parallel_shader_compile' ) !== null ) { + + // If we can check the compilation status of the materials without + // blocking then do so right away. + + checkMaterialsReady(); + + } else { + + // Otherwise start by waiting a bit to give the materials we just + // initialized a chance to finish. + + setTimeout( checkMaterialsReady, 10 ); + + } + + } ); + + }; + + // Animation Loop + + let onAnimationFrameCallback = null; + + function onAnimationFrame( time ) { + + if ( onAnimationFrameCallback ) onAnimationFrameCallback( time ); + + } + + function onXRSessionStart() { + + animation.stop(); + + } + + function onXRSessionEnd() { + + animation.start(); + + } + + const animation = new WebGLAnimation(); + animation.setAnimationLoop( onAnimationFrame ); + + if ( typeof self !== 'undefined' ) animation.setContext( self ); + + this.setAnimationLoop = function ( callback ) { + + onAnimationFrameCallback = callback; + xr.setAnimationLoop( callback ); + + ( callback === null ) ? animation.stop() : animation.start(); + + }; + + xr.addEventListener( 'sessionstart', onXRSessionStart ); + xr.addEventListener( 'sessionend', onXRSessionEnd ); + + // Rendering + + this.render = function ( scene, camera ) { + + if ( camera !== undefined && camera.isCamera !== true ) { + + console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' ); + return; + + } + + if ( _isContextLost === true ) return; + + // update scene graph + + if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld(); + + // update camera matrices and frustum + + if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld(); + + if ( xr.enabled === true && xr.isPresenting === true ) { + + if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera ); + + camera = xr.getCamera(); // use XR camera for rendering + + } + + // + if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, _currentRenderTarget ); + + currentRenderState = renderStates.get( scene, renderStateStack.length ); + currentRenderState.init( camera ); + + renderStateStack.push( currentRenderState ); + + _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); + _frustum.setFromProjectionMatrix( _projScreenMatrix ); + + _localClippingEnabled = this.localClippingEnabled; + _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled ); + + currentRenderList = renderLists.get( scene, renderListStack.length ); + currentRenderList.init(); + + renderListStack.push( currentRenderList ); + + if ( xr.enabled === true && xr.isPresenting === true ) { + + const depthSensingMesh = _this.xr.getDepthSensingMesh(); + + if ( depthSensingMesh !== null ) { + + projectObject( depthSensingMesh, camera, - Infinity, _this.sortObjects ); + + } + + } + + projectObject( scene, camera, 0, _this.sortObjects ); + + currentRenderList.finish(); + + if ( _this.sortObjects === true ) { + + currentRenderList.sort( _opaqueSort, _transparentSort ); + + } + + _renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false; + if ( _renderBackground ) { + + background.addToRenderList( currentRenderList, scene ); + + } + + // + + this.info.render.frame ++; + + if ( _clippingEnabled === true ) clipping.beginShadows(); + + const shadowsArray = currentRenderState.state.shadowsArray; + + shadowMap.render( shadowsArray, scene, camera ); + + if ( _clippingEnabled === true ) clipping.endShadows(); + + // + + if ( this.info.autoReset === true ) this.info.reset(); + + // render scene + + const opaqueObjects = currentRenderList.opaque; + const transmissiveObjects = currentRenderList.transmissive; + + currentRenderState.setupLights(); + + if ( camera.isArrayCamera ) { + + const cameras = camera.cameras; + + if ( transmissiveObjects.length > 0 ) { + + for ( let i = 0, l = cameras.length; i < l; i ++ ) { + + const camera2 = cameras[ i ]; + + renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera2 ); + + } + + } + + if ( _renderBackground ) background.render( scene ); + + for ( let i = 0, l = cameras.length; i < l; i ++ ) { + + const camera2 = cameras[ i ]; + + renderScene( currentRenderList, scene, camera2, camera2.viewport ); + + } + + } else { + + if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera ); + + if ( _renderBackground ) background.render( scene ); + + renderScene( currentRenderList, scene, camera ); + + } + + // + + if ( _currentRenderTarget !== null ) { + + // resolve multisample renderbuffers to a single-sample texture if necessary + + textures.updateMultisampleRenderTarget( _currentRenderTarget ); + + // Generate mipmap if we're using any kind of mipmap filtering + + textures.updateRenderTargetMipmap( _currentRenderTarget ); + + } + + // + + if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera ); + + // _gl.finish(); + + bindingStates.resetDefaultState(); + _currentMaterialId = - 1; + _currentCamera = null; + + renderStateStack.pop(); + + if ( renderStateStack.length > 0 ) { + + currentRenderState = renderStateStack[ renderStateStack.length - 1 ]; + + if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, currentRenderState.state.camera ); + + } else { + + currentRenderState = null; + + } + + renderListStack.pop(); + + if ( renderListStack.length > 0 ) { + + currentRenderList = renderListStack[ renderListStack.length - 1 ]; + + } else { + + currentRenderList = null; + + } + + }; + + function projectObject( object, camera, groupOrder, sortObjects ) { + + if ( object.visible === false ) return; + + const visible = object.layers.test( camera.layers ); + + if ( visible ) { + + if ( object.isGroup ) { + + groupOrder = object.renderOrder; + + } else if ( object.isLOD ) { + + if ( object.autoUpdate === true ) object.update( camera ); + + } else if ( object.isLight ) { + + currentRenderState.pushLight( object ); + + if ( object.castShadow ) { + + currentRenderState.pushShadow( object ); + + } + + } else if ( object.isSprite ) { + + if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) { + + if ( sortObjects ) { + + _vector4.setFromMatrixPosition( object.matrixWorld ) + .applyMatrix4( _projScreenMatrix ); + + } + + const geometry = objects.update( object ); + const material = object.material; + + if ( material.visible ) { + + currentRenderList.push( object, geometry, material, groupOrder, _vector4.z, null ); + + } + + } + + } else if ( object.isMesh || object.isLine || object.isPoints ) { + + if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) { + + const geometry = objects.update( object ); + const material = object.material; + + if ( sortObjects ) { + + if ( object.boundingSphere !== undefined ) { + + if ( object.boundingSphere === null ) object.computeBoundingSphere(); + _vector4.copy( object.boundingSphere.center ); + + } else { + + if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere(); + _vector4.copy( geometry.boundingSphere.center ); + + } + + _vector4 + .applyMatrix4( object.matrixWorld ) + .applyMatrix4( _projScreenMatrix ); + + } + + if ( Array.isArray( material ) ) { + + const groups = geometry.groups; + + for ( let i = 0, l = groups.length; i < l; i ++ ) { + + const group = groups[ i ]; + const groupMaterial = material[ group.materialIndex ]; + + if ( groupMaterial && groupMaterial.visible ) { + + currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group ); + + } + + } + + } else if ( material.visible ) { + + currentRenderList.push( object, geometry, material, groupOrder, _vector4.z, null ); + + } + + } + + } + + } + + const children = object.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + projectObject( children[ i ], camera, groupOrder, sortObjects ); + + } + + } + + function renderScene( currentRenderList, scene, camera, viewport ) { + + const opaqueObjects = currentRenderList.opaque; + const transmissiveObjects = currentRenderList.transmissive; + const transparentObjects = currentRenderList.transparent; + + currentRenderState.setupLightsView( camera ); + + if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera ); + + if ( viewport ) state.viewport( _currentViewport.copy( viewport ) ); + + if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera ); + if ( transmissiveObjects.length > 0 ) renderObjects( transmissiveObjects, scene, camera ); + if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera ); + + // Ensure depth buffer writing is enabled so it can be cleared on next render + + state.buffers.depth.setTest( true ); + state.buffers.depth.setMask( true ); + state.buffers.color.setMask( true ); + + state.setPolygonOffset( false ); + + } + + function renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera ) { + + const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null; + + if ( overrideMaterial !== null ) { + + return; + + } + + if ( currentRenderState.state.transmissionRenderTarget[ camera.id ] === undefined ) { + + currentRenderState.state.transmissionRenderTarget[ camera.id ] = new WebGLRenderTarget( 1, 1, { + generateMipmaps: true, + type: ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) ) ? HalfFloatType : UnsignedByteType, + minFilter: LinearMipmapLinearFilter, + samples: 4, + stencilBuffer: stencil, + resolveDepthBuffer: false, + resolveStencilBuffer: false, + colorSpace: ColorManagement.workingColorSpace, + } ); + + // debug + + /* + const geometry = new PlaneGeometry(); + const material = new MeshBasicMaterial( { map: _transmissionRenderTarget.texture } ); + + const mesh = new Mesh( geometry, material ); + scene.add( mesh ); + */ + + } + + const transmissionRenderTarget = currentRenderState.state.transmissionRenderTarget[ camera.id ]; + + const activeViewport = camera.viewport || _currentViewport; + transmissionRenderTarget.setSize( activeViewport.z, activeViewport.w ); + + // + + const currentRenderTarget = _this.getRenderTarget(); + _this.setRenderTarget( transmissionRenderTarget ); + + _this.getClearColor( _currentClearColor ); + _currentClearAlpha = _this.getClearAlpha(); + if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 ); + + _this.clear(); + + if ( _renderBackground ) background.render( scene ); + + // Turn off the features which can affect the frag color for opaque objects pass. + // Otherwise they are applied twice in opaque objects pass and transmission objects pass. + const currentToneMapping = _this.toneMapping; + _this.toneMapping = NoToneMapping; + + // Remove viewport from camera to avoid nested render calls resetting viewport to it (e.g Reflector). + // Transmission render pass requires viewport to match the transmissionRenderTarget. + const currentCameraViewport = camera.viewport; + if ( camera.viewport !== undefined ) camera.viewport = undefined; + + currentRenderState.setupLightsView( camera ); + + if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, camera ); + + renderObjects( opaqueObjects, scene, camera ); + + textures.updateMultisampleRenderTarget( transmissionRenderTarget ); + textures.updateRenderTargetMipmap( transmissionRenderTarget ); + + if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === false ) { // see #28131 + + let renderTargetNeedsUpdate = false; + + for ( let i = 0, l = transmissiveObjects.length; i < l; i ++ ) { + + const renderItem = transmissiveObjects[ i ]; + + const object = renderItem.object; + const geometry = renderItem.geometry; + const material = renderItem.material; + const group = renderItem.group; + + if ( material.side === DoubleSide && object.layers.test( camera.layers ) ) { + + const currentSide = material.side; + + material.side = BackSide; + material.needsUpdate = true; + + renderObject( object, scene, camera, geometry, material, group ); + + material.side = currentSide; + material.needsUpdate = true; + + renderTargetNeedsUpdate = true; + + } + + } + + if ( renderTargetNeedsUpdate === true ) { + + textures.updateMultisampleRenderTarget( transmissionRenderTarget ); + textures.updateRenderTargetMipmap( transmissionRenderTarget ); + + } + + } + + _this.setRenderTarget( currentRenderTarget ); + + _this.setClearColor( _currentClearColor, _currentClearAlpha ); + + if ( currentCameraViewport !== undefined ) camera.viewport = currentCameraViewport; + + _this.toneMapping = currentToneMapping; + + } + + function renderObjects( renderList, scene, camera ) { + + const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null; + + for ( let i = 0, l = renderList.length; i < l; i ++ ) { + + const renderItem = renderList[ i ]; + + const object = renderItem.object; + const geometry = renderItem.geometry; + const material = overrideMaterial === null ? renderItem.material : overrideMaterial; + const group = renderItem.group; + + if ( object.layers.test( camera.layers ) ) { + + renderObject( object, scene, camera, geometry, material, group ); + + } + + } + + } + + function renderObject( object, scene, camera, geometry, material, group ) { + + object.onBeforeRender( _this, scene, camera, geometry, material, group ); + + object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld ); + object.normalMatrix.getNormalMatrix( object.modelViewMatrix ); + + material.onBeforeRender( _this, scene, camera, geometry, object, group ); + + if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) { + + material.side = BackSide; + material.needsUpdate = true; + _this.renderBufferDirect( camera, scene, geometry, material, object, group ); + + material.side = FrontSide; + material.needsUpdate = true; + _this.renderBufferDirect( camera, scene, geometry, material, object, group ); + + material.side = DoubleSide; + + } else { + + _this.renderBufferDirect( camera, scene, geometry, material, object, group ); + + } + + object.onAfterRender( _this, scene, camera, geometry, material, group ); + + } + + function getProgram( material, scene, object ) { + + if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ... + + const materialProperties = properties.get( material ); + + const lights = currentRenderState.state.lights; + const shadowsArray = currentRenderState.state.shadowsArray; + + const lightsStateVersion = lights.state.version; + + const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object ); + const programCacheKey = programCache.getProgramCacheKey( parameters ); + + let programs = materialProperties.programs; + + // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change + + materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null; + materialProperties.fog = scene.fog; + materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment ); + materialProperties.envMapRotation = ( materialProperties.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation; + + if ( programs === undefined ) { + + // new material + + material.addEventListener( 'dispose', onMaterialDispose ); + + programs = new Map(); + materialProperties.programs = programs; + + } + + let program = programs.get( programCacheKey ); + + if ( program !== undefined ) { + + // early out if program and light state is identical + + if ( materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion ) { + + updateCommonMaterialProperties( material, parameters ); + + return program; + + } + + } else { + + parameters.uniforms = programCache.getUniforms( material ); + + material.onBeforeCompile( parameters, _this ); + + program = programCache.acquireProgram( parameters, programCacheKey ); + programs.set( programCacheKey, program ); + + materialProperties.uniforms = parameters.uniforms; + + } + + const uniforms = materialProperties.uniforms; + + if ( ( ! material.isShaderMaterial && ! material.isRawShaderMaterial ) || material.clipping === true ) { + + uniforms.clippingPlanes = clipping.uniform; + + } + + updateCommonMaterialProperties( material, parameters ); + + // store the light setup it was created for + + materialProperties.needsLights = materialNeedsLights( material ); + materialProperties.lightsStateVersion = lightsStateVersion; + + if ( materialProperties.needsLights ) { + + // wire up the material to this renderer's lighting state + + uniforms.ambientLightColor.value = lights.state.ambient; + uniforms.lightProbe.value = lights.state.probe; + uniforms.directionalLights.value = lights.state.directional; + uniforms.directionalLightShadows.value = lights.state.directionalShadow; + uniforms.spotLights.value = lights.state.spot; + uniforms.spotLightShadows.value = lights.state.spotShadow; + uniforms.rectAreaLights.value = lights.state.rectArea; + uniforms.ltc_1.value = lights.state.rectAreaLTC1; + uniforms.ltc_2.value = lights.state.rectAreaLTC2; + uniforms.pointLights.value = lights.state.point; + uniforms.pointLightShadows.value = lights.state.pointShadow; + uniforms.hemisphereLights.value = lights.state.hemi; + + uniforms.directionalShadowMap.value = lights.state.directionalShadowMap; + uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix; + uniforms.spotShadowMap.value = lights.state.spotShadowMap; + uniforms.spotLightMatrix.value = lights.state.spotLightMatrix; + uniforms.spotLightMap.value = lights.state.spotLightMap; + uniforms.pointShadowMap.value = lights.state.pointShadowMap; + uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; + // TODO (abelnation): add area lights shadow info to uniforms + + } + + materialProperties.currentProgram = program; + materialProperties.uniformsList = null; + + return program; + + } + + function getUniformList( materialProperties ) { + + if ( materialProperties.uniformsList === null ) { + + const progUniforms = materialProperties.currentProgram.getUniforms(); + materialProperties.uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, materialProperties.uniforms ); + + } + + return materialProperties.uniformsList; + + } + + function updateCommonMaterialProperties( material, parameters ) { + + const materialProperties = properties.get( material ); + + materialProperties.outputColorSpace = parameters.outputColorSpace; + materialProperties.batching = parameters.batching; + materialProperties.batchingColor = parameters.batchingColor; + materialProperties.instancing = parameters.instancing; + materialProperties.instancingColor = parameters.instancingColor; + materialProperties.instancingMorph = parameters.instancingMorph; + materialProperties.skinning = parameters.skinning; + materialProperties.morphTargets = parameters.morphTargets; + materialProperties.morphNormals = parameters.morphNormals; + materialProperties.morphColors = parameters.morphColors; + materialProperties.morphTargetsCount = parameters.morphTargetsCount; + materialProperties.numClippingPlanes = parameters.numClippingPlanes; + materialProperties.numIntersection = parameters.numClipIntersection; + materialProperties.vertexAlphas = parameters.vertexAlphas; + materialProperties.vertexTangents = parameters.vertexTangents; + materialProperties.toneMapping = parameters.toneMapping; + + } + + function setProgram( camera, scene, geometry, material, object ) { + + if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ... + + textures.resetTextureUnits(); + + const fog = scene.fog; + const environment = material.isMeshStandardMaterial ? scene.environment : null; + const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace ); + const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment ); + const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4; + const vertexTangents = !! geometry.attributes.tangent && ( !! material.normalMap || material.anisotropy > 0 ); + const morphTargets = !! geometry.morphAttributes.position; + const morphNormals = !! geometry.morphAttributes.normal; + const morphColors = !! geometry.morphAttributes.color; + + let toneMapping = NoToneMapping; + + if ( material.toneMapped ) { + + if ( _currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true ) { + + toneMapping = _this.toneMapping; + + } + + } + + const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; + const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0; + + const materialProperties = properties.get( material ); + const lights = currentRenderState.state.lights; + + if ( _clippingEnabled === true ) { + + if ( _localClippingEnabled === true || camera !== _currentCamera ) { + + const useCache = + camera === _currentCamera && + material.id === _currentMaterialId; + + // we might want to call this function with some ClippingGroup + // object instead of the material, once it becomes feasible + // (#8465, #8379) + clipping.setState( material, camera, useCache ); + + } + + } + + // + + let needsProgramChange = false; + + if ( material.version === materialProperties.__version ) { + + if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) { + + needsProgramChange = true; + + } else if ( materialProperties.outputColorSpace !== colorSpace ) { + + needsProgramChange = true; + + } else if ( object.isBatchedMesh && materialProperties.batching === false ) { + + needsProgramChange = true; + + } else if ( ! object.isBatchedMesh && materialProperties.batching === true ) { + + needsProgramChange = true; + + } else if ( object.isBatchedMesh && materialProperties.batchingColor === true && object.colorTexture === null ) { + + needsProgramChange = true; + + } else if ( object.isBatchedMesh && materialProperties.batchingColor === false && object.colorTexture !== null ) { + + needsProgramChange = true; + + } else if ( object.isInstancedMesh && materialProperties.instancing === false ) { + + needsProgramChange = true; + + } else if ( ! object.isInstancedMesh && materialProperties.instancing === true ) { + + needsProgramChange = true; + + } else if ( object.isSkinnedMesh && materialProperties.skinning === false ) { + + needsProgramChange = true; + + } else if ( ! object.isSkinnedMesh && materialProperties.skinning === true ) { + + needsProgramChange = true; + + } else if ( object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null ) { + + needsProgramChange = true; + + } else if ( object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null ) { + + needsProgramChange = true; + + } else if ( object.isInstancedMesh && materialProperties.instancingMorph === true && object.morphTexture === null ) { + + needsProgramChange = true; + + } else if ( object.isInstancedMesh && materialProperties.instancingMorph === false && object.morphTexture !== null ) { + + needsProgramChange = true; + + } else if ( materialProperties.envMap !== envMap ) { + + needsProgramChange = true; + + } else if ( material.fog === true && materialProperties.fog !== fog ) { + + needsProgramChange = true; + + } else if ( materialProperties.numClippingPlanes !== undefined && + ( materialProperties.numClippingPlanes !== clipping.numPlanes || + materialProperties.numIntersection !== clipping.numIntersection ) ) { + + needsProgramChange = true; + + } else if ( materialProperties.vertexAlphas !== vertexAlphas ) { + + needsProgramChange = true; + + } else if ( materialProperties.vertexTangents !== vertexTangents ) { + + needsProgramChange = true; + + } else if ( materialProperties.morphTargets !== morphTargets ) { + + needsProgramChange = true; + + } else if ( materialProperties.morphNormals !== morphNormals ) { + + needsProgramChange = true; + + } else if ( materialProperties.morphColors !== morphColors ) { + + needsProgramChange = true; + + } else if ( materialProperties.toneMapping !== toneMapping ) { + + needsProgramChange = true; + + } else if ( materialProperties.morphTargetsCount !== morphTargetsCount ) { + + needsProgramChange = true; + + } + + } else { + + needsProgramChange = true; + materialProperties.__version = material.version; + + } + + // + + let program = materialProperties.currentProgram; + + if ( needsProgramChange === true ) { + + program = getProgram( material, scene, object ); + + } + + let refreshProgram = false; + let refreshMaterial = false; + let refreshLights = false; + + const p_uniforms = program.getUniforms(), + m_uniforms = materialProperties.uniforms; + + if ( state.useProgram( program.program ) ) { + + refreshProgram = true; + refreshMaterial = true; + refreshLights = true; + + } + + if ( material.id !== _currentMaterialId ) { + + _currentMaterialId = material.id; + + refreshMaterial = true; + + } + + if ( refreshProgram || _currentCamera !== camera ) { + + // common camera uniforms + + const reverseDepthBuffer = state.buffers.depth.getReversed(); + + if ( reverseDepthBuffer ) { + + _currentProjectionMatrix.copy( camera.projectionMatrix ); + + toNormalizedProjectionMatrix( _currentProjectionMatrix ); + toReversedProjectionMatrix( _currentProjectionMatrix ); + + p_uniforms.setValue( _gl, 'projectionMatrix', _currentProjectionMatrix ); + + } else { + + p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix ); + + } + + p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse ); + + const uCamPos = p_uniforms.map.cameraPosition; + + if ( uCamPos !== undefined ) { + + uCamPos.setValue( _gl, _vector3.setFromMatrixPosition( camera.matrixWorld ) ); + + } + + if ( capabilities.logarithmicDepthBuffer ) { + + p_uniforms.setValue( _gl, 'logDepthBufFC', + 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) ); + + } + + // consider moving isOrthographic to UniformLib and WebGLMaterials, see https://github.com/mrdoob/three.js/pull/26467#issuecomment-1645185067 + + if ( material.isMeshPhongMaterial || + material.isMeshToonMaterial || + material.isMeshLambertMaterial || + material.isMeshBasicMaterial || + material.isMeshStandardMaterial || + material.isShaderMaterial ) { + + p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true ); + + } + + if ( _currentCamera !== camera ) { + + _currentCamera = camera; + + // lighting uniforms depend on the camera so enforce an update + // now, in case this material supports lights - or later, when + // the next material that does gets activated: + + refreshMaterial = true; // set to true on material change + refreshLights = true; // remains set until update done + + } + + } + + // skinning and morph target uniforms must be set even if material didn't change + // auto-setting of texture unit for bone and morph texture must go before other textures + // otherwise textures used for skinning and morphing can take over texture units reserved for other material textures + + if ( object.isSkinnedMesh ) { + + p_uniforms.setOptional( _gl, object, 'bindMatrix' ); + p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' ); + + const skeleton = object.skeleton; + + if ( skeleton ) { + + if ( skeleton.boneTexture === null ) skeleton.computeBoneTexture(); + + p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures ); + + } + + } + + if ( object.isBatchedMesh ) { + + p_uniforms.setOptional( _gl, object, 'batchingTexture' ); + p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures ); + + p_uniforms.setOptional( _gl, object, 'batchingIdTexture' ); + p_uniforms.setValue( _gl, 'batchingIdTexture', object._indirectTexture, textures ); + + p_uniforms.setOptional( _gl, object, 'batchingColorTexture' ); + if ( object._colorsTexture !== null ) { + + p_uniforms.setValue( _gl, 'batchingColorTexture', object._colorsTexture, textures ); + + } + + } + + const morphAttributes = geometry.morphAttributes; + + if ( morphAttributes.position !== undefined || morphAttributes.normal !== undefined || ( morphAttributes.color !== undefined ) ) { + + morphtargets.update( object, geometry, program ); + + } + + if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) { + + materialProperties.receiveShadow = object.receiveShadow; + p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow ); + + } + + // https://github.com/mrdoob/three.js/pull/24467#issuecomment-1209031512 + + if ( material.isMeshGouraudMaterial && material.envMap !== null ) { + + m_uniforms.envMap.value = envMap; + + m_uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1; + + } + + if ( material.isMeshStandardMaterial && material.envMap === null && scene.environment !== null ) { + + m_uniforms.envMapIntensity.value = scene.environmentIntensity; + + } + + if ( refreshMaterial ) { + + p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure ); + + if ( materialProperties.needsLights ) { + + // the current material requires lighting info + + // note: all lighting uniforms are always set correctly + // they simply reference the renderer's state for their + // values + // + // use the current material's .needsUpdate flags to set + // the GL state when required + + markUniformsLightsNeedsUpdate( m_uniforms, refreshLights ); + + } + + // refresh uniforms common to several materials + + if ( fog && material.fog === true ) { + + materials.refreshFogUniforms( m_uniforms, fog ); + + } + + materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, currentRenderState.state.transmissionRenderTarget[ camera.id ] ); + + WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures ); + + } + + if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) { + + WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures ); + material.uniformsNeedUpdate = false; + + } + + if ( material.isSpriteMaterial ) { + + p_uniforms.setValue( _gl, 'center', object.center ); + + } + + // common matrices + + p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix ); + p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix ); + p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld ); + + // UBOs + + if ( material.isShaderMaterial || material.isRawShaderMaterial ) { + + const groups = material.uniformsGroups; + + for ( let i = 0, l = groups.length; i < l; i ++ ) { + + const group = groups[ i ]; + + uniformsGroups.update( group, program ); + uniformsGroups.bind( group, program ); + + } + + } + + return program; + + } + + // If uniforms are marked as clean, they don't need to be loaded to the GPU. + + function markUniformsLightsNeedsUpdate( uniforms, value ) { + + uniforms.ambientLightColor.needsUpdate = value; + uniforms.lightProbe.needsUpdate = value; + + uniforms.directionalLights.needsUpdate = value; + uniforms.directionalLightShadows.needsUpdate = value; + uniforms.pointLights.needsUpdate = value; + uniforms.pointLightShadows.needsUpdate = value; + uniforms.spotLights.needsUpdate = value; + uniforms.spotLightShadows.needsUpdate = value; + uniforms.rectAreaLights.needsUpdate = value; + uniforms.hemisphereLights.needsUpdate = value; + + } + + function materialNeedsLights( material ) { + + return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || + material.isMeshStandardMaterial || material.isShadowMaterial || + ( material.isShaderMaterial && material.lights === true ); + + } + + this.getActiveCubeFace = function () { + + return _currentActiveCubeFace; + + }; + + this.getActiveMipmapLevel = function () { + + return _currentActiveMipmapLevel; + + }; + + this.getRenderTarget = function () { + + return _currentRenderTarget; + + }; + + this.setRenderTargetTextures = function ( renderTarget, colorTexture, depthTexture ) { + + properties.get( renderTarget.texture ).__webglTexture = colorTexture; + properties.get( renderTarget.depthTexture ).__webglTexture = depthTexture; + + const renderTargetProperties = properties.get( renderTarget ); + renderTargetProperties.__hasExternalTextures = true; + + renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined; + + if ( ! renderTargetProperties.__autoAllocateDepthBuffer ) { + + // The multisample_render_to_texture extension doesn't work properly if there + // are midframe flushes and an external depth buffer. Disable use of the extension. + if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) { + + console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' ); + renderTargetProperties.__useRenderToTexture = false; + + } + + } + + }; + + this.setRenderTargetFramebuffer = function ( renderTarget, defaultFramebuffer ) { + + const renderTargetProperties = properties.get( renderTarget ); + renderTargetProperties.__webglFramebuffer = defaultFramebuffer; + renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === undefined; + + }; + + this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) { + + _currentRenderTarget = renderTarget; + _currentActiveCubeFace = activeCubeFace; + _currentActiveMipmapLevel = activeMipmapLevel; + + let useDefaultFramebuffer = true; + let framebuffer = null; + let isCube = false; + let isRenderTarget3D = false; + + if ( renderTarget ) { + + const renderTargetProperties = properties.get( renderTarget ); + + if ( renderTargetProperties.__useDefaultFramebuffer !== undefined ) { + + // We need to make sure to rebind the framebuffer. + state.bindFramebuffer( _gl.FRAMEBUFFER, null ); + useDefaultFramebuffer = false; + + } else if ( renderTargetProperties.__webglFramebuffer === undefined ) { + + textures.setupRenderTarget( renderTarget ); + + } else if ( renderTargetProperties.__hasExternalTextures ) { + + // Color and depth texture must be rebound in order for the swapchain to update. + textures.rebindTextures( renderTarget, properties.get( renderTarget.texture ).__webglTexture, properties.get( renderTarget.depthTexture ).__webglTexture ); + + } else if ( renderTarget.depthBuffer ) { + + // check if the depth texture is already bound to the frame buffer and that it's been initialized + const depthTexture = renderTarget.depthTexture; + if ( renderTargetProperties.__boundDepthTexture !== depthTexture ) { + + // check if the depth texture is compatible + if ( + depthTexture !== null && + properties.has( depthTexture ) && + ( renderTarget.width !== depthTexture.image.width || renderTarget.height !== depthTexture.image.height ) + ) { + + throw new Error( 'WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.' ); + + } + + // Swap the depth buffer to the currently attached one + textures.setupDepthRenderbuffer( renderTarget ); + + } + + } + + const texture = renderTarget.texture; + + if ( texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture ) { + + isRenderTarget3D = true; + + } + + const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer; + + if ( renderTarget.isWebGLCubeRenderTarget ) { + + if ( Array.isArray( __webglFramebuffer[ activeCubeFace ] ) ) { + + framebuffer = __webglFramebuffer[ activeCubeFace ][ activeMipmapLevel ]; + + } else { + + framebuffer = __webglFramebuffer[ activeCubeFace ]; + + } + + isCube = true; + + } else if ( ( renderTarget.samples > 0 ) && textures.useMultisampledRTT( renderTarget ) === false ) { + + framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer; + + } else { + + if ( Array.isArray( __webglFramebuffer ) ) { + + framebuffer = __webglFramebuffer[ activeMipmapLevel ]; + + } else { + + framebuffer = __webglFramebuffer; + + } + + } + + _currentViewport.copy( renderTarget.viewport ); + _currentScissor.copy( renderTarget.scissor ); + _currentScissorTest = renderTarget.scissorTest; + + } else { + + _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor(); + _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor(); + _currentScissorTest = _scissorTest; + + } + + const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); + + if ( framebufferBound && useDefaultFramebuffer ) { + + state.drawBuffers( renderTarget, framebuffer ); + + } + + state.viewport( _currentViewport ); + state.scissor( _currentScissor ); + state.setScissorTest( _currentScissorTest ); + + if ( isCube ) { + + const textureProperties = properties.get( renderTarget.texture ); + _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel ); + + } else if ( isRenderTarget3D ) { + + const textureProperties = properties.get( renderTarget.texture ); + const layer = activeCubeFace || 0; + _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel || 0, layer ); + + } + + _currentMaterialId = - 1; // reset current material to ensure correct uniform bindings + + }; + + this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) { + + if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' ); + return; + + } + + let framebuffer = properties.get( renderTarget ).__webglFramebuffer; + + if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) { + + framebuffer = framebuffer[ activeCubeFaceIndex ]; + + } + + if ( framebuffer ) { + + state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); + + try { + + const texture = renderTarget.texture; + const textureFormat = texture.format; + const textureType = texture.type; + + if ( ! capabilities.textureFormatReadable( textureFormat ) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' ); + return; + + } + + if ( ! capabilities.textureTypeReadable( textureType ) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' ); + return; + + } + + // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604) + + if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) { + + _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer ); + + } + + } finally { + + // restore framebuffer of current render target if necessary + + const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null; + state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); + + } + + } + + }; + + this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) { + + if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) { + + throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' ); + + } + + let framebuffer = properties.get( renderTarget ).__webglFramebuffer; + if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) { + + framebuffer = framebuffer[ activeCubeFaceIndex ]; + + } + + if ( framebuffer ) { + + const texture = renderTarget.texture; + const textureFormat = texture.format; + const textureType = texture.type; + + if ( ! capabilities.textureFormatReadable( textureFormat ) ) { + + throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' ); + + } + + if ( ! capabilities.textureTypeReadable( textureType ) ) { + + throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' ); + + } + + // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604) + if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) { + + // set the active frame buffer to the one we want to read + state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); + + const glBuffer = _gl.createBuffer(); + _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer ); + _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ ); + _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 ); + + // reset the frame buffer to the currently set buffer before waiting + const currFramebuffer = _currentRenderTarget !== null ? properties.get( _currentRenderTarget ).__webglFramebuffer : null; + state.bindFramebuffer( _gl.FRAMEBUFFER, currFramebuffer ); + + // check if the commands have finished every 8 ms + const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 ); + + _gl.flush(); + + await probeAsync( _gl, sync, 4 ); + + // read the data and delete the buffer + _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer ); + _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer ); + _gl.deleteBuffer( glBuffer ); + _gl.deleteSync( sync ); + + return buffer; + + } else { + + throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.' ); + + } + + } + + }; + + this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) { + + // support previous signature with position first + if ( texture.isTexture !== true ) { + + // @deprecated, r165 + warnOnce( 'WebGLRenderer: copyFramebufferToTexture function signature has changed.' ); + + position = arguments[ 0 ] || null; + texture = arguments[ 1 ]; + + } + + const levelScale = Math.pow( 2, - level ); + const width = Math.floor( texture.image.width * levelScale ); + const height = Math.floor( texture.image.height * levelScale ); + + const x = position !== null ? position.x : 0; + const y = position !== null ? position.y : 0; + + textures.setTexture2D( texture, 0 ); + + _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, x, y, width, height ); + + state.unbindTexture(); + + }; + + const _srcFramebuffer = _gl.createFramebuffer(); + const _dstFramebuffer = _gl.createFramebuffer(); + this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) { + + // support previous signature with dstPosition first + if ( srcTexture.isTexture !== true ) { + + // @deprecated, r165 + warnOnce( 'WebGLRenderer: copyTextureToTexture function signature has changed.' ); + + dstPosition = arguments[ 0 ] || null; + srcTexture = arguments[ 1 ]; + dstTexture = arguments[ 2 ]; + dstLevel = arguments[ 3 ] || 0; + srcRegion = null; + + } + + // support the previous signature with just a single dst mipmap level + if ( dstLevel === null ) { + + if ( srcLevel !== 0 ) { + + // @deprecated, r171 + warnOnce( 'WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels.' ); + dstLevel = srcLevel; + srcLevel = 0; + + } else { + + dstLevel = 0; + + } + + } + + // gather the necessary dimensions to copy + let width, height, depth, minX, minY, minZ; + let dstX, dstY, dstZ; + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image; + if ( srcRegion !== null ) { + + width = srcRegion.max.x - srcRegion.min.x; + height = srcRegion.max.y - srcRegion.min.y; + depth = srcRegion.isBox3 ? srcRegion.max.z - srcRegion.min.z : 1; + minX = srcRegion.min.x; + minY = srcRegion.min.y; + minZ = srcRegion.isBox3 ? srcRegion.min.z : 0; + + } else { + + const levelScale = Math.pow( 2, - srcLevel ); + width = Math.floor( image.width * levelScale ); + height = Math.floor( image.height * levelScale ); + if ( srcTexture.isDataArrayTexture ) { + + depth = image.depth; + + } else if ( srcTexture.isData3DTexture ) { + + depth = Math.floor( image.depth * levelScale ); + + } else { + + depth = 1; + + } + + minX = 0; + minY = 0; + minZ = 0; + + } + + if ( dstPosition !== null ) { + + dstX = dstPosition.x; + dstY = dstPosition.y; + dstZ = dstPosition.z; + + } else { + + dstX = 0; + dstY = 0; + dstZ = 0; + + } + + // Set up the destination target + const glFormat = utils.convert( dstTexture.format ); + const glType = utils.convert( dstTexture.type ); + let glTarget; + + if ( dstTexture.isData3DTexture ) { + + textures.setTexture3D( dstTexture, 0 ); + glTarget = _gl.TEXTURE_3D; + + } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) { + + textures.setTexture2DArray( dstTexture, 0 ); + glTarget = _gl.TEXTURE_2D_ARRAY; + + } else { + + textures.setTexture2D( dstTexture, 0 ); + glTarget = _gl.TEXTURE_2D; + + } + + _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY ); + _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); + _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); + + // used for copying data from cpu + const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH ); + const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT ); + const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS ); + const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS ); + const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES ); + + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height ); + _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY ); + _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ ); + + // set up the src texture + const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture; + const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture; + if ( srcTexture.isDepthTexture ) { + + const srcTextureProperties = properties.get( srcTexture ); + const dstTextureProperties = properties.get( dstTexture ); + const srcRenderTargetProperties = properties.get( srcTextureProperties.__renderTarget ); + const dstRenderTargetProperties = properties.get( dstTextureProperties.__renderTarget ); + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, srcRenderTargetProperties.__webglFramebuffer ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, dstRenderTargetProperties.__webglFramebuffer ); + + for ( let i = 0; i < depth; i ++ ) { + + // if the source or destination are a 3d target then a layer needs to be bound + if ( isSrc3D ) { + + _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( srcTexture ).__webglTexture, srcLevel, minZ + i ); + _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( dstTexture ).__webglTexture, dstLevel, dstZ + i ); + + } + + _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST ); + + } + + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null ); + + } else if ( srcLevel !== 0 || srcTexture.isRenderTargetTexture || properties.has( srcTexture ) ) { + + // get the appropriate frame buffers + const srcTextureProperties = properties.get( srcTexture ); + const dstTextureProperties = properties.get( dstTexture ); + + // bind the frame buffer targets + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, _srcFramebuffer ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, _dstFramebuffer ); + + for ( let i = 0; i < depth; i ++ ) { + + // assign the correct layers and mip maps to the frame buffers + if ( isSrc3D ) { + + _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, srcTextureProperties.__webglTexture, srcLevel, minZ + i ); + + } else { + + _gl.framebufferTexture2D( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, srcTextureProperties.__webglTexture, srcLevel ); + + } + + if ( isDst3D ) { + + _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, dstTextureProperties.__webglTexture, dstLevel, dstZ + i ); + + } else { + + _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, dstTextureProperties.__webglTexture, dstLevel ); + + } + + // copy the data using the fastest function that can achieve the copy + if ( srcLevel !== 0 ) { + + _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.COLOR_BUFFER_BIT, _gl.NEAREST ); + + } else if ( isDst3D ) { + + _gl.copyTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ + i, minX, minY, width, height ); + + } else { + + _gl.copyTexSubImage2D( glTarget, dstLevel, dstX, dstY, minX, minY, width, height ); + + } + + } + + // unbind read, draw buffers + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null ); + + } else { + + if ( isDst3D ) { + + // copy data into the 3d texture + if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) { + + _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data ); + + } else if ( dstTexture.isCompressedArrayTexture ) { + + _gl.compressedTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, image.data ); + + } else { + + _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image ); + + } + + } else { + + // copy data into the 2d texture + if ( srcTexture.isDataTexture ) { + + _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image.data ); + + } else if ( srcTexture.isCompressedTexture ) { + + _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, image.width, image.height, glFormat, image.data ); + + } else { + + _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image ); + + } + + } + + } + + // reset values + _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen ); + _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight ); + _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels ); + _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows ); + _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages ); + + // Generate mipmaps only when copying level 0 + if ( dstLevel === 0 && dstTexture.generateMipmaps ) { + + _gl.generateMipmap( glTarget ); + + } + + state.unbindTexture(); + + }; + + this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { + + // support previous signature with source box first + if ( srcTexture.isTexture !== true ) { + + // @deprecated, r165 + warnOnce( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' ); + + srcRegion = arguments[ 0 ] || null; + dstPosition = arguments[ 1 ] || null; + srcTexture = arguments[ 2 ]; + dstTexture = arguments[ 3 ]; + level = arguments[ 4 ] || 0; + + } + + // @deprecated, r170 + warnOnce( 'WebGLRenderer: copyTextureToTexture3D function has been deprecated. Use "copyTextureToTexture" instead.' ); + + return this.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level ); + + }; + + this.initRenderTarget = function ( target ) { + + if ( properties.get( target ).__webglFramebuffer === undefined ) { + + textures.setupRenderTarget( target ); + + } + + }; + + this.initTexture = function ( texture ) { + + if ( texture.isCubeTexture ) { + + textures.setTextureCube( texture, 0 ); + + } else if ( texture.isData3DTexture ) { + + textures.setTexture3D( texture, 0 ); + + } else if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) { + + textures.setTexture2DArray( texture, 0 ); + + } else { + + textures.setTexture2D( texture, 0 ); + + } + + state.unbindTexture(); + + }; + + this.resetState = function () { + + _currentActiveCubeFace = 0; + _currentActiveMipmapLevel = 0; + _currentRenderTarget = null; + + state.reset(); + bindingStates.reset(); + + }; + + if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); + + } + + } + + get coordinateSystem() { + + return WebGLCoordinateSystem; + + } + + get outputColorSpace() { + + return this._outputColorSpace; + + } + + set outputColorSpace( colorSpace ) { + + this._outputColorSpace = colorSpace; + + const gl = this.getContext(); + gl.drawingBufferColorspace = ColorManagement._getDrawingBufferColorSpace( colorSpace ); + gl.unpackColorSpace = ColorManagement._getUnpackColorSpace(); + + } + +} + +export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, ArrayCamera, BackSide, BoxGeometry, BufferAttribute, BufferGeometry, ByteType, CineonToneMapping, ClampToEdgeWrapping, Color, ColorManagement, ConstantAlphaFactor, ConstantColorFactor, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CustomToneMapping, Data3DTexture, DataArrayTexture, DepthFormat, DepthStencilFormat, DepthTexture, DoubleSide, DstAlphaFactor, DstColorFactor, EqualCompare, EqualDepth, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, FloatType, FrontSide, Frustum, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, Group, HalfFloatType, IntType, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, LuminanceAlphaFormat, LuminanceFormat, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NoBlending, NoColorSpace, NoToneMapping, NormalBlending, NotEqualCompare, NotEqualDepth, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PerspectiveCamera, Plane, PlaneGeometry, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RedFormat, RedIntegerFormat, ReinhardToneMapping, RepeatWrapping, ReverseSubtractEquation, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, ShaderChunk, ShaderLib, ShaderMaterial, ShortType, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, SubtractEquation, SubtractiveBlending, TangentSpaceNormalMap, Texture, Uint16BufferAttribute, Uint32BufferAttribute, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGLRenderer, WebGLUtils, ZeroFactor, createCanvasElement }; diff --git a/libs/three.js/r171/build/three.module.min.js b/libs/three.js/r171/build/three.module.min.js new file mode 100644 index 000000000..492e40595 --- /dev/null +++ b/libs/three.js/r171/build/three.module.min.js @@ -0,0 +1,6 @@ +/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */ +import{Color as e,Matrix3 as t,Vector2 as n,mergeUniforms as i,Vector3 as r,CubeUVReflectionMapping as a,Mesh as o,BoxGeometry as s,ShaderMaterial as l,cloneUniforms as c,BackSide as d,ColorManagement as u,SRGBTransfer as f,PlaneGeometry as p,FrontSide as m,getUnlitUniformColorSpace as h,Euler as _,Matrix4 as g,IntType as v,RGBAFormat as E,HalfFloatType as S,UnsignedByteType as T,FloatType as M,Plane as x,EquirectangularReflectionMapping as R,EquirectangularRefractionMapping as A,WebGLCubeRenderTarget as b,CubeReflectionMapping as C,CubeRefractionMapping as L,PerspectiveCamera as P,NoToneMapping as U,MeshBasicMaterial as w,BufferGeometry as D,BufferAttribute as y,WebGLRenderTarget as I,NoBlending as N,OrthographicCamera as O,LinearFilter as F,LinearSRGBColorSpace as B,warnOnce as H,arrayNeedsUint32 as G,Uint32BufferAttribute as V,Uint16BufferAttribute as z,Vector4 as k,DataArrayTexture as W,LessEqualCompare as X,Texture as Y,DepthTexture as j,Data3DTexture as K,CubeTexture as q,GLSL3 as Z,CustomToneMapping as $,NeutralToneMapping as Q,AgXToneMapping as J,ACESFilmicToneMapping as ee,CineonToneMapping as te,ReinhardToneMapping as ne,LinearToneMapping as ie,PCFShadowMap as re,PCFSoftShadowMap as ae,VSMShadowMap as oe,LinearTransfer as se,AddOperation as le,MixOperation as ce,MultiplyOperation as de,ObjectSpaceNormalMap as ue,TangentSpaceNormalMap as fe,NormalBlending as pe,DoubleSide as me,UniformsUtils as he,Layers as _e,Frustum as ge,MeshDepthMaterial as ve,RGBADepthPacking as Ee,MeshDistanceMaterial as Se,NearestFilter as Te,LessEqualDepth as Me,AddEquation as xe,SubtractEquation as Re,ReverseSubtractEquation as Ae,ZeroFactor as be,OneFactor as Ce,SrcColorFactor as Le,SrcAlphaFactor as Pe,SrcAlphaSaturateFactor as Ue,DstColorFactor as we,DstAlphaFactor as De,OneMinusSrcColorFactor as ye,OneMinusSrcAlphaFactor as Ie,OneMinusDstColorFactor as Ne,OneMinusDstAlphaFactor as Oe,ConstantColorFactor as Fe,OneMinusConstantColorFactor as Be,ConstantAlphaFactor as He,OneMinusConstantAlphaFactor as Ge,CustomBlending as Ve,MultiplyBlending as ze,SubtractiveBlending as ke,AdditiveBlending as We,CullFaceNone as Xe,CullFaceBack as Ye,CullFaceFront as je,MinEquation as Ke,MaxEquation as qe,NotEqualDepth as Ze,GreaterDepth as $e,GreaterEqualDepth as Qe,EqualDepth as Je,LessDepth as et,AlwaysDepth as tt,NeverDepth as nt,RepeatWrapping as it,ClampToEdgeWrapping as rt,MirroredRepeatWrapping as at,NearestMipmapNearestFilter as ot,NearestMipmapLinearFilter as st,LinearMipmapNearestFilter as lt,LinearMipmapLinearFilter as ct,NeverCompare as dt,AlwaysCompare as ut,LessCompare as ft,EqualCompare as pt,GreaterEqualCompare as mt,GreaterCompare as ht,NotEqualCompare as _t,NoColorSpace as gt,DepthStencilFormat as vt,getByteLength as Et,UnsignedIntType as St,UnsignedInt248Type as Tt,UnsignedShortType as Mt,DepthFormat as xt,createElementNS as Rt,UnsignedShort4444Type as At,UnsignedShort5551Type as bt,UnsignedInt5999Type as Ct,ByteType as Lt,ShortType as Pt,AlphaFormat as Ut,RGBFormat as wt,LuminanceFormat as Dt,LuminanceAlphaFormat as yt,RedFormat as It,RedIntegerFormat as Nt,RGFormat as Ot,RGIntegerFormat as Ft,RGBAIntegerFormat as Bt,RGB_S3TC_DXT1_Format as Ht,RGBA_S3TC_DXT1_Format as Gt,RGBA_S3TC_DXT3_Format as Vt,RGBA_S3TC_DXT5_Format as zt,RGB_PVRTC_4BPPV1_Format as kt,RGB_PVRTC_2BPPV1_Format as Wt,RGBA_PVRTC_4BPPV1_Format as Xt,RGBA_PVRTC_2BPPV1_Format as Yt,RGB_ETC1_Format as jt,RGB_ETC2_Format as Kt,RGBA_ETC2_EAC_Format as qt,RGBA_ASTC_4x4_Format as Zt,RGBA_ASTC_5x4_Format as $t,RGBA_ASTC_5x5_Format as Qt,RGBA_ASTC_6x5_Format as Jt,RGBA_ASTC_6x6_Format as en,RGBA_ASTC_8x5_Format as tn,RGBA_ASTC_8x6_Format as nn,RGBA_ASTC_8x8_Format as rn,RGBA_ASTC_10x5_Format as an,RGBA_ASTC_10x6_Format as on,RGBA_ASTC_10x8_Format as sn,RGBA_ASTC_10x10_Format as ln,RGBA_ASTC_12x10_Format as cn,RGBA_ASTC_12x12_Format as dn,RGBA_BPTC_Format as un,RGB_BPTC_SIGNED_Format as fn,RGB_BPTC_UNSIGNED_Format as pn,RED_RGTC1_Format as mn,SIGNED_RED_RGTC1_Format as hn,RED_GREEN_RGTC2_Format as _n,SIGNED_RED_GREEN_RGTC2_Format as gn,Group as vn,EventDispatcher as En,ArrayCamera as Sn,RAD2DEG as Tn,createCanvasElement as Mn,SRGBColorSpace as xn,REVISION as Rn,toNormalizedProjectionMatrix as An,toReversedProjectionMatrix as bn,probeAsync as Cn,WebGLCoordinateSystem as Ln}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AlwaysStencilFunc,AmbientLight,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BasicShadowMap,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,Controls,CubeCamera,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CylinderGeometry,Cylindrical,DataTexture,DataTextureLoader,DataUtils,DecrementStencilOp,DecrementWrapStencilOp,DefaultLoadingManager,DetachedBindMode,DirectionalLight,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicDrawUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,EqualStencilFunc,ExtrudeGeometry,FileLoader,Float16BufferAttribute,Float32BufferAttribute,Fog,FogExp2,FramebufferTexture,GLBufferAttribute,GLSL1,GreaterEqualStencilFunc,GreaterStencilFunc,GridHelper,HemisphereLight,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,IncrementStencilOp,IncrementWrapStencilOp,InstancedBufferAttribute,InstancedBufferGeometry,InstancedInterleavedBuffer,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,InterleavedBuffer,InterleavedBufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,InvertStencilOp,KeepStencilOp,KeyframeTrack,LOD,LatheGeometry,LessEqualStencilFunc,LessStencilFunc,Light,LightProbe,Line,Line3,LineBasicMaterial,LineCurve,LineCurve3,LineDashedMaterial,LineLoop,LineSegments,LinearInterpolant,LinearMipMapLinearFilter,LinearMipMapNearestFilter,Loader,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Material,MaterialLoader,MathUtils,Matrix2,MeshLambertMaterial,MeshMatcapMaterial,MeshNormalMaterial,MeshPhongMaterial,MeshPhysicalMaterial,MeshStandardMaterial,MeshToonMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NeverStencilFunc,NormalAnimationBlendMode,NotEqualStencilFunc,NumberKeyframeTrack,Object3D,ObjectLoader,OctahedronGeometry,Path,PlaneHelper,PointLight,PointLightHelper,Points,PointsMaterial,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBDepthPacking,RGBIntegerFormat,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RectAreaLight,RenderTarget,ReplaceStencilOp,RingGeometry,Scene,ShadowMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,SphereGeometry,Spherical,SphericalHarmonics3,SplineCurve,SpotLight,SpotLightHelper,Sprite,SpriteMaterial,StaticCopyUsage,StaticDrawUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,UVMapping,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGPUCoordinateSystem,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding,ZeroStencilOp}from"./three.core.min.js";function Pn(){let e=null,t=!1,n=null,i=null;function r(t,a){n(t,a),i=e.requestAnimationFrame(r)}return{start:function(){!0!==t&&null!==n&&(i=e.requestAnimationFrame(r),t=!0)},stop:function(){e.cancelAnimationFrame(i),t=!1},setAnimationLoop:function(e){n=e},setContext:function(t){e=t}}}function Un(e){const t=new WeakMap;return{get:function(e){return e.isInterleavedBufferAttribute&&(e=e.data),t.get(e)},remove:function(n){n.isInterleavedBufferAttribute&&(n=n.data);const i=t.get(n);i&&(e.deleteBuffer(i.buffer),t.delete(n))},update:function(n,i){if(n.isInterleavedBufferAttribute&&(n=n.data),n.isGLBufferAttribute){const e=t.get(n);return void((!e||e.versione.start-t.start));let t=0;for(let e=1;e 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\tvColor.xyz *= batchingColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment:"vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn saturate(v);\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColor;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\t#endif\n\tvec3 totalScattering = singleScattering + multiScattering;\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGDEPTHBUF )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphinstance_vertex:"#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif",morphcolor_vertex:"#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;",normal_fragment_maps:"#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif",iridescence_pars_fragment:"#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif",opaque_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * depth - far );\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\t\n\t\tfloat lightToPositionLength = length( lightToPosition );\n\t\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t\t) * ( 1.0 / 9.0 );\n\t\t\t#else\n\t\t\t\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t\n\t\t#else\n\t\t\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif",uv_pars_fragment:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_pars_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}",cube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include \n\t#include \n}",depth_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvWorldPosition = worldPosition.xyz;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include \n\t#include \n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include \n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include \n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",points_vert:"uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",shadow_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include \n\t#include \n\t#include \n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include \n\t#include \n\t#include \n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n}"},Dn={common:{diffuse:{value:new e(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new t},alphaMap:{value:null},alphaMapTransform:{value:new t},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new t}},envmap:{envMap:{value:null},envMapRotation:{value:new t},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new t}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new t}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new t},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new t},normalScale:{value:new n(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new t},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new t}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new t}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new t}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new e(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new e(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new t},alphaTest:{value:0},uvTransform:{value:new t}},sprite:{diffuse:{value:new e(16777215)},opacity:{value:1},center:{value:new n(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new t},alphaMap:{value:null},alphaMapTransform:{value:new t},alphaTest:{value:0}}},yn={basic:{uniforms:i([Dn.common,Dn.specularmap,Dn.envmap,Dn.aomap,Dn.lightmap,Dn.fog]),vertexShader:wn.meshbasic_vert,fragmentShader:wn.meshbasic_frag},lambert:{uniforms:i([Dn.common,Dn.specularmap,Dn.envmap,Dn.aomap,Dn.lightmap,Dn.emissivemap,Dn.bumpmap,Dn.normalmap,Dn.displacementmap,Dn.fog,Dn.lights,{emissive:{value:new e(0)}}]),vertexShader:wn.meshlambert_vert,fragmentShader:wn.meshlambert_frag},phong:{uniforms:i([Dn.common,Dn.specularmap,Dn.envmap,Dn.aomap,Dn.lightmap,Dn.emissivemap,Dn.bumpmap,Dn.normalmap,Dn.displacementmap,Dn.fog,Dn.lights,{emissive:{value:new e(0)},specular:{value:new e(1118481)},shininess:{value:30}}]),vertexShader:wn.meshphong_vert,fragmentShader:wn.meshphong_frag},standard:{uniforms:i([Dn.common,Dn.envmap,Dn.aomap,Dn.lightmap,Dn.emissivemap,Dn.bumpmap,Dn.normalmap,Dn.displacementmap,Dn.roughnessmap,Dn.metalnessmap,Dn.fog,Dn.lights,{emissive:{value:new e(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:wn.meshphysical_vert,fragmentShader:wn.meshphysical_frag},toon:{uniforms:i([Dn.common,Dn.aomap,Dn.lightmap,Dn.emissivemap,Dn.bumpmap,Dn.normalmap,Dn.displacementmap,Dn.gradientmap,Dn.fog,Dn.lights,{emissive:{value:new e(0)}}]),vertexShader:wn.meshtoon_vert,fragmentShader:wn.meshtoon_frag},matcap:{uniforms:i([Dn.common,Dn.bumpmap,Dn.normalmap,Dn.displacementmap,Dn.fog,{matcap:{value:null}}]),vertexShader:wn.meshmatcap_vert,fragmentShader:wn.meshmatcap_frag},points:{uniforms:i([Dn.points,Dn.fog]),vertexShader:wn.points_vert,fragmentShader:wn.points_frag},dashed:{uniforms:i([Dn.common,Dn.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:wn.linedashed_vert,fragmentShader:wn.linedashed_frag},depth:{uniforms:i([Dn.common,Dn.displacementmap]),vertexShader:wn.depth_vert,fragmentShader:wn.depth_frag},normal:{uniforms:i([Dn.common,Dn.bumpmap,Dn.normalmap,Dn.displacementmap,{opacity:{value:1}}]),vertexShader:wn.meshnormal_vert,fragmentShader:wn.meshnormal_frag},sprite:{uniforms:i([Dn.sprite,Dn.fog]),vertexShader:wn.sprite_vert,fragmentShader:wn.sprite_frag},background:{uniforms:{uvTransform:{value:new t},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:wn.background_vert,fragmentShader:wn.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new t}},vertexShader:wn.backgroundCube_vert,fragmentShader:wn.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:wn.cube_vert,fragmentShader:wn.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:wn.equirect_vert,fragmentShader:wn.equirect_frag},distanceRGBA:{uniforms:i([Dn.common,Dn.displacementmap,{referencePosition:{value:new r},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:wn.distanceRGBA_vert,fragmentShader:wn.distanceRGBA_frag},shadow:{uniforms:i([Dn.lights,Dn.fog,{color:{value:new e(0)},opacity:{value:1}}]),vertexShader:wn.shadow_vert,fragmentShader:wn.shadow_frag}};yn.physical={uniforms:i([yn.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new t},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new t},clearcoatNormalScale:{value:new n(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new t},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new t},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new t},sheen:{value:0},sheenColor:{value:new e(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new t},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new t},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new t},transmissionSamplerSize:{value:new n},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new t},attenuationDistance:{value:0},attenuationColor:{value:new e(0)},specularColor:{value:new e(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new t},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new t},anisotropyVector:{value:new n},anisotropyMap:{value:null},anisotropyMapTransform:{value:new t}}]),vertexShader:wn.meshphysical_vert,fragmentShader:wn.meshphysical_frag};const In={r:0,b:0,g:0},Nn=new _,On=new g;function Fn(t,n,i,r,_,g,v){const E=new e(0);let S,T,M=!0===g?0:1,x=null,R=0,A=null;function b(e){let t=!0===e.isScene?e.background:null;if(t&&t.isTexture){t=(e.backgroundBlurriness>0?i:n).get(t)}return t}function C(e,n){e.getRGB(In,h(t)),r.buffers.color.setClear(In.r,In.g,In.b,n,v)}return{getClearColor:function(){return E},setClearColor:function(e,t=1){E.set(e),M=t,C(E,M)},getClearAlpha:function(){return M},setClearAlpha:function(e){M=e,C(E,M)},render:function(e){let n=!1;const i=b(e);null===i?C(E,M):i&&i.isColor&&(C(i,1),n=!0);const a=t.xr.getEnvironmentBlendMode();"additive"===a?r.buffers.color.setClear(0,0,0,1,v):"alpha-blend"===a&&r.buffers.color.setClear(0,0,0,0,v),(t.autoClear||n)&&(r.buffers.depth.setTest(!0),r.buffers.depth.setMask(!0),r.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))},addToRenderList:function(e,n){const i=b(n);i&&(i.isCubeTexture||i.mapping===a)?(void 0===T&&(T=new o(new s(1,1,1),new l({name:"BackgroundCubeMaterial",uniforms:c(yn.backgroundCube.uniforms),vertexShader:yn.backgroundCube.vertexShader,fragmentShader:yn.backgroundCube.fragmentShader,side:d,depthTest:!1,depthWrite:!1,fog:!1})),T.geometry.deleteAttribute("normal"),T.geometry.deleteAttribute("uv"),T.onBeforeRender=function(e,t,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(T.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),_.update(T)),Nn.copy(n.backgroundRotation),Nn.x*=-1,Nn.y*=-1,Nn.z*=-1,i.isCubeTexture&&!1===i.isRenderTargetTexture&&(Nn.y*=-1,Nn.z*=-1),T.material.uniforms.envMap.value=i,T.material.uniforms.flipEnvMap.value=i.isCubeTexture&&!1===i.isRenderTargetTexture?-1:1,T.material.uniforms.backgroundBlurriness.value=n.backgroundBlurriness,T.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,T.material.uniforms.backgroundRotation.value.setFromMatrix4(On.makeRotationFromEuler(Nn)),T.material.toneMapped=u.getTransfer(i.colorSpace)!==f,x===i&&R===i.version&&A===t.toneMapping||(T.material.needsUpdate=!0,x=i,R=i.version,A=t.toneMapping),T.layers.enableAll(),e.unshift(T,T.geometry,T.material,0,0,null)):i&&i.isTexture&&(void 0===S&&(S=new o(new p(2,2),new l({name:"BackgroundMaterial",uniforms:c(yn.background.uniforms),vertexShader:yn.background.vertexShader,fragmentShader:yn.background.fragmentShader,side:m,depthTest:!1,depthWrite:!1,fog:!1})),S.geometry.deleteAttribute("normal"),Object.defineProperty(S.material,"map",{get:function(){return this.uniforms.t2D.value}}),_.update(S)),S.material.uniforms.t2D.value=i,S.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,S.material.toneMapped=u.getTransfer(i.colorSpace)!==f,!0===i.matrixAutoUpdate&&i.updateMatrix(),S.material.uniforms.uvTransform.value.copy(i.matrix),x===i&&R===i.version&&A===t.toneMapping||(S.material.needsUpdate=!0,x=i,R=i.version,A=t.toneMapping),S.layers.enableAll(),e.unshift(S,S.geometry,S.material,0,0,null))},dispose:function(){void 0!==T&&(T.geometry.dispose(),T.material.dispose()),void 0!==S&&(S.geometry.dispose(),S.material.dispose())}}}function Bn(e,t){const n=e.getParameter(e.MAX_VERTEX_ATTRIBS),i={},r=c(null);let a=r,o=!1;function s(t){return e.bindVertexArray(t)}function l(t){return e.deleteVertexArray(t)}function c(e){const t=[],i=[],r=[];for(let e=0;e=0){const n=r[t];let i=o[t];if(void 0===i&&("instanceMatrix"===t&&e.instanceMatrix&&(i=e.instanceMatrix),"instanceColor"===t&&e.instanceColor&&(i=e.instanceColor)),void 0===n)return!0;if(n.attribute!==i)return!0;if(i&&n.data!==i.data)return!0;s++}}return a.attributesNum!==s||a.index!==i}(n,h,l,_),g&&function(e,t,n,i){const r={},o=t.attributes;let s=0;const l=n.getAttributes();for(const t in l){if(l[t].location>=0){let n=o[t];void 0===n&&("instanceMatrix"===t&&e.instanceMatrix&&(n=e.instanceMatrix),"instanceColor"===t&&e.instanceColor&&(n=e.instanceColor));const i={};i.attribute=n,n&&n.data&&(i.data=n.data),r[t]=i,s++}}a.attributes=r,a.attributesNum=s,a.index=i}(n,h,l,_),null!==_&&t.update(_,e.ELEMENT_ARRAY_BUFFER),(g||o)&&(o=!1,function(n,i,r,a){d();const o=a.attributes,s=r.getAttributes(),l=i.defaultAttributeValues;for(const i in s){const r=s[i];if(r.location>=0){let s=o[i];if(void 0===s&&("instanceMatrix"===i&&n.instanceMatrix&&(s=n.instanceMatrix),"instanceColor"===i&&n.instanceColor&&(s=n.instanceColor)),void 0!==s){const i=s.normalized,o=s.itemSize,l=t.get(s);if(void 0===l)continue;const c=l.buffer,d=l.type,p=l.bytesPerElement,h=d===e.INT||d===e.UNSIGNED_INT||s.gpuType===v;if(s.isInterleavedBufferAttribute){const t=s.data,l=t.stride,_=s.offset;if(t.isInstancedInterleavedBuffer){for(let e=0;e0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0)return"highp";t="mediump"}return"mediump"===t&&e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.MEDIUM_FLOAT).precision>0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let o=void 0!==n.precision?n.precision:"highp";const s=a(o);s!==o&&(console.warn("THREE.WebGLRenderer:",o,"not supported, using",s,"instead."),o=s);const l=!0===n.logarithmicDepthBuffer,c=!0===n.reverseDepthBuffer&&t.has("EXT_clip_control"),d=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),u=e.getParameter(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS);return{isWebGL2:!0,getMaxAnisotropy:function(){if(void 0!==r)return r;if(!0===t.has("EXT_texture_filter_anisotropic")){const n=t.get("EXT_texture_filter_anisotropic");r=e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else r=0;return r},getMaxPrecision:a,textureFormatReadable:function(t){return t===E||i.convert(t)===e.getParameter(e.IMPLEMENTATION_COLOR_READ_FORMAT)},textureTypeReadable:function(n){const r=n===S&&(t.has("EXT_color_buffer_half_float")||t.has("EXT_color_buffer_float"));return!(n!==T&&i.convert(n)!==e.getParameter(e.IMPLEMENTATION_COLOR_READ_TYPE)&&n!==M&&!r)},precision:o,logarithmicDepthBuffer:l,reverseDepthBuffer:c,maxTextures:d,maxVertexTextures:u,maxTextureSize:e.getParameter(e.MAX_TEXTURE_SIZE),maxCubemapSize:e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),maxAttributes:e.getParameter(e.MAX_VERTEX_ATTRIBS),maxVertexUniforms:e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),maxVaryings:e.getParameter(e.MAX_VARYING_VECTORS),maxFragmentUniforms:e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),vertexTextures:u>0,maxSamples:e.getParameter(e.MAX_SAMPLES)}}function Vn(e){const n=this;let i=null,r=0,a=!1,o=!1;const s=new x,l=new t,c={value:null,needsUpdate:!1};function d(e,t,i,r){const a=null!==e?e.length:0;let o=null;if(0!==a){if(o=c.value,!0!==r||null===o){const n=i+4*a,r=t.matrixWorldInverse;l.getNormalMatrix(r),(null===o||o.length0);n.numPlanes=r,n.numIntersection=0}();else{const e=o?0:r,t=4*e;let n=m.clippingState||null;c.value=n,n=d(u,s,t,l);for(let e=0;e!==t;++e)n[e]=i[e];m.clippingState=n,this.numIntersection=f?this.numPlanes:0,this.numPlanes+=e}}}function zn(e){let t=new WeakMap;function n(e,t){return t===R?e.mapping=C:t===A&&(e.mapping=L),e}function i(e){const n=e.target;n.removeEventListener("dispose",i);const r=t.get(n);void 0!==r&&(t.delete(n),r.dispose())}return{get:function(r){if(r&&r.isTexture){const a=r.mapping;if(a===R||a===A){if(t.has(r)){return n(t.get(r).texture,r.mapping)}{const a=r.image;if(a&&a.height>0){const o=new b(a.height);return o.fromEquirectangularTexture(e,r),t.set(r,o),r.addEventListener("dispose",i),n(o.texture,r.mapping)}return null}}}return r},dispose:function(){t=new WeakMap}}}const kn=[.125,.215,.35,.446,.526,.582],Wn=20,Xn=new O,Yn=new e;let jn=null,Kn=0,qn=0,Zn=!1;const $n=(1+Math.sqrt(5))/2,Qn=1/$n,Jn=[new r(-$n,Qn,0),new r($n,Qn,0),new r(-Qn,0,$n),new r(Qn,0,$n),new r(0,$n,-Qn),new r(0,$n,Qn),new r(-1,1,-1),new r(1,1,-1),new r(-1,1,1),new r(1,1,1)];class ei{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(e,t=0,n=.1,i=100){jn=this._renderer.getRenderTarget(),Kn=this._renderer.getActiveCubeFace(),qn=this._renderer.getActiveMipmapLevel(),Zn=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(e,n,i,r),t>0&&this._blur(r,0,0,t),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=ri(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=ii(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose()}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?s=kn[o-e+4-1]:0===o&&(s=0),i.push(s);const l=1/(a-2),c=-l,d=1+l,u=[c,c,d,c,d,d,c,c,d,d,c,d],f=6,p=6,m=3,h=2,_=1,g=new Float32Array(m*p*f),v=new Float32Array(h*p*f),E=new Float32Array(_*p*f);for(let e=0;e2?0:-1,i=[t,n,0,t+2/3,n,0,t+2/3,n+1,0,t,n,0,t+2/3,n+1,0,t,n+1,0];g.set(i,m*p*e),v.set(u,h*p*e);const r=[e,e,e,e,e,e];E.set(r,_*p*e)}const S=new D;S.setAttribute("position",new y(g,m)),S.setAttribute("uv",new y(v,h)),S.setAttribute("faceIndex",new y(E,_)),t.push(S),r>4&&r--}return{lodPlanes:t,sizeLods:n,sigmas:i}}(i)),this._blurMaterial=function(e,t,n){const i=new Float32Array(Wn),a=new r(0,1,0),o=new l({name:"SphericalGaussianBlur",defines:{n:Wn,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${e}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:a}},vertexShader:ai(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include \n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:N,depthTest:!1,depthWrite:!1});return o}(i,e,t)}return i}_compileMaterial(e){const t=new o(this._lodPlanes[0],e);this._renderer.compile(t,Xn)}_sceneToCubeUV(e,t,n,i){const r=new P(90,1,t,n),a=[1,-1,1,1,1,1],l=[1,1,1,-1,-1,-1],c=this._renderer,u=c.autoClear,f=c.toneMapping;c.getClearColor(Yn),c.toneMapping=U,c.autoClear=!1;const p=new w({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1}),m=new o(new s,p);let h=!1;const _=e.background;_?_.isColor&&(p.color.copy(_),e.background=null,h=!0):(p.color.copy(Yn),h=!0);for(let t=0;t<6;t++){const n=t%3;0===n?(r.up.set(0,a[t],0),r.lookAt(l[t],0,0)):1===n?(r.up.set(0,0,a[t]),r.lookAt(0,l[t],0)):(r.up.set(0,a[t],0),r.lookAt(0,0,l[t]));const o=this._cubeSize;ni(i,n*o,t>2?o:0,o,o),c.setRenderTarget(i),h&&c.render(m,r),c.render(e,r)}m.geometry.dispose(),m.material.dispose(),c.toneMapping=f,c.autoClear=u,e.background=_}_textureToCubeUV(e,t){const n=this._renderer,i=e.mapping===C||e.mapping===L;i?(null===this._cubemapMaterial&&(this._cubemapMaterial=ri()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===e.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=ii());const r=i?this._cubemapMaterial:this._equirectMaterial,a=new o(this._lodPlanes[0],r);r.uniforms.envMap.value=e;const s=this._cubeSize;ni(t,0,0,3*s,2*s),n.setRenderTarget(t),n.render(a,Xn)}_applyPMREM(e){const t=this._renderer,n=t.autoClear;t.autoClear=!1;const i=this._lodPlanes.length;for(let t=1;tWn&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${h} samples when the maximum is set to 20`);const _=[];let g=0;for(let e=0;ev-4?i-v+4:0),4*(this._cubeSize-E),3*E,2*E),l.setRenderTarget(t),l.render(d,Xn)}}function ti(e,t,n){const i=new I(e,t,n);return i.texture.mapping=a,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function ni(e,t,n,i,r){e.viewport.set(t,n,i,r),e.scissor.set(t,n,i,r)}function ii(){return new l({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:ai(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\n\t\t\t#include \n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tgl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );\n\n\t\t\t}\n\t\t",blending:N,depthTest:!1,depthWrite:!1})}function ri(){return new l({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:ai(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tuniform float flipEnvMap;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );\n\n\t\t\t}\n\t\t",blending:N,depthTest:!1,depthWrite:!1})}function ai(){return"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"}function oi(e){let t=new WeakMap,n=null;function i(e){const n=e.target;n.removeEventListener("dispose",i);const r=t.get(n);void 0!==r&&(t.delete(n),r.dispose())}return{get:function(r){if(r&&r.isTexture){const a=r.mapping,o=a===R||a===A,s=a===C||a===L;if(o||s){let a=t.get(r);const l=void 0!==a?a.texture.pmremVersion:0;if(r.isRenderTargetTexture&&r.pmremVersion!==l)return null===n&&(n=new ei(e)),a=o?n.fromEquirectangular(r,a):n.fromCubemap(r,a),a.texture.pmremVersion=r.pmremVersion,t.set(r,a),a.texture;if(void 0!==a)return a.texture;{const l=r.image;return o&&l&&l.height>0||s&&l&&function(e){let t=0;const n=6;for(let i=0;it.maxTextureSize&&(T=Math.ceil(S/t.maxTextureSize),S=t.maxTextureSize);const x=new Float32Array(S*T*4*u),R=new W(x,S,T,u);R.type=M,R.needsUpdate=!0;const A=4*E;for(let C=0;C0)return e;const r=t*n;let a=vi[r];if(void 0===a&&(a=new Float32Array(r),vi[r]=a),0!==t){i.toArray(a,0);for(let i=1,r=0;i!==t;++i)r+=n,e[i].toArray(a,r)}return a}function Ri(e,t){if(e.length!==t.length)return!1;for(let n=0,i=e.length;n":" "} ${r}: ${n[e]}`)}return i.join("\n")}(e.getShaderSource(t),i)}return r}function xr(e,t){const n=function(e){u._getMatrix(Tr,u.workingColorSpace,e);const t=`mat3( ${Tr.elements.map((e=>e.toFixed(4)))} )`;switch(u.getTransfer(e)){case se:return[t,"LinearTransferOETF"];case f:return[t,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space: ",e),[t,"LinearTransferOETF"]}}(t);return[`vec4 ${e}( vec4 value ) {`,`\treturn ${n[1]}( vec4( value.rgb * ${n[0]}, value.a ) );`,"}"].join("\n")}function Rr(e,t){let n;switch(t){case ie:n="Linear";break;case ne:n="Reinhard";break;case te:n="Cineon";break;case ee:n="ACESFilmic";break;case J:n="AgX";break;case Q:n="Neutral";break;case $:n="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),n="Linear"}return"vec3 "+e+"( vec3 color ) { return "+n+"ToneMapping( color ); }"}const Ar=new r;function br(){u.getLuminanceCoefficients(Ar);return["float luminance( const in vec3 rgb ) {",`\tconst vec3 weights = vec3( ${Ar.x.toFixed(4)}, ${Ar.y.toFixed(4)}, ${Ar.z.toFixed(4)} );`,"\treturn dot( weights, rgb );","}"].join("\n")}function Cr(e){return""!==e}function Lr(e,t){const n=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return e.replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows)}function Pr(e,t){return e.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}const Ur=/^[ \t]*#include +<([\w\d./]+)>/gm;function wr(e){return e.replace(Ur,yr)}const Dr=new Map;function yr(e,t){let n=wn[t];if(void 0===n){const e=Dr.get(t);if(void 0===e)throw new Error("Can not resolve #include <"+t+">");n=wn[e],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,e)}return wr(n)}const Ir=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Nr(e){return e.replace(Ir,Or)}function Or(e,t,n,i){let r="";for(let e=parseInt(t);e0&&(g+="\n"),v=["#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,h].filter(Cr).join("\n"),v.length>0&&(v+="\n")):(g=[Fr(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,h,n.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",n.batching?"#define USE_BATCHING":"",n.batchingColor?"#define USE_BATCHING_COLOR":"",n.instancing?"#define USE_INSTANCING":"",n.instancingColor?"#define USE_INSTANCING_COLOR":"",n.instancingMorph?"#define USE_INSTANCING_MORPH":"",n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.map?"#define USE_MAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+u:"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.displacementMap?"#define USE_DISPLACEMENTMAP":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.mapUv?"#define MAP_UV "+n.mapUv:"",n.alphaMapUv?"#define ALPHAMAP_UV "+n.alphaMapUv:"",n.lightMapUv?"#define LIGHTMAP_UV "+n.lightMapUv:"",n.aoMapUv?"#define AOMAP_UV "+n.aoMapUv:"",n.emissiveMapUv?"#define EMISSIVEMAP_UV "+n.emissiveMapUv:"",n.bumpMapUv?"#define BUMPMAP_UV "+n.bumpMapUv:"",n.normalMapUv?"#define NORMALMAP_UV "+n.normalMapUv:"",n.displacementMapUv?"#define DISPLACEMENTMAP_UV "+n.displacementMapUv:"",n.metalnessMapUv?"#define METALNESSMAP_UV "+n.metalnessMapUv:"",n.roughnessMapUv?"#define ROUGHNESSMAP_UV "+n.roughnessMapUv:"",n.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+n.anisotropyMapUv:"",n.clearcoatMapUv?"#define CLEARCOATMAP_UV "+n.clearcoatMapUv:"",n.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+n.clearcoatNormalMapUv:"",n.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+n.clearcoatRoughnessMapUv:"",n.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+n.iridescenceMapUv:"",n.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+n.iridescenceThicknessMapUv:"",n.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+n.sheenColorMapUv:"",n.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+n.sheenRoughnessMapUv:"",n.specularMapUv?"#define SPECULARMAP_UV "+n.specularMapUv:"",n.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+n.specularColorMapUv:"",n.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+n.specularIntensityMapUv:"",n.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+n.transmissionMapUv:"",n.thicknessMapUv?"#define THICKNESSMAP_UV "+n.thicknessMapUv:"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.flatShading?"#define FLAT_SHADED":"",n.skinning?"#define USE_SKINNING":"",n.morphTargets?"#define USE_MORPHTARGETS":"",n.morphNormals&&!1===n.flatShading?"#define USE_MORPHNORMALS":"",n.morphColors?"#define USE_MORPHCOLORS":"",n.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+n.morphTextureStride:"",n.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+n.morphTargetsCount:"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+c:"",n.sizeAttenuation?"#define USE_SIZEATTENUATION":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",n.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH","\tuniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(Cr).join("\n"),v=[Fr(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,h,n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",n.map?"#define USE_MAP":"",n.matcap?"#define USE_MATCAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+d:"",n.envMap?"#define "+u:"",n.envMap?"#define "+f:"",p?"#define CUBEUV_TEXEL_WIDTH "+p.texelWidth:"",p?"#define CUBEUV_TEXEL_HEIGHT "+p.texelHeight:"",p?"#define CUBEUV_MAX_MIP "+p.maxMip+".0":"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoat?"#define USE_CLEARCOAT":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.dispersion?"#define USE_DISPERSION":"",n.iridescence?"#define USE_IRIDESCENCE":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaTest?"#define USE_ALPHATEST":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.sheen?"#define USE_SHEEN":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors||n.instancingColor||n.batchingColor?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.gradientMap?"#define USE_GRADIENTMAP":"",n.flatShading?"#define FLAT_SHADED":"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+c:"",n.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",n.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",n.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",n.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",n.toneMapping!==U?"#define TONE_MAPPING":"",n.toneMapping!==U?wn.tonemapping_pars_fragment:"",n.toneMapping!==U?Rr("toneMapping",n.toneMapping):"",n.dithering?"#define DITHERING":"",n.opaque?"#define OPAQUE":"",wn.colorspace_pars_fragment,xr("linearToOutputTexel",n.outputColorSpace),br(),n.useDepthPacking?"#define DEPTH_PACKING "+n.depthPacking:"","\n"].filter(Cr).join("\n")),s=wr(s),s=Lr(s,n),s=Pr(s,n),l=wr(l),l=Lr(l,n),l=Pr(l,n),s=Nr(s),l=Nr(l),!0!==n.isRawShaderMaterial&&(E="#version 300 es\n",g=[m,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+g,v=["#define varying in",n.glslVersion===Z?"":"layout(location = 0) out highp vec4 pc_fragColor;",n.glslVersion===Z?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+v);const S=E+g+s,T=E+v+l,M=vr(r,r.VERTEX_SHADER,S),x=vr(r,r.FRAGMENT_SHADER,T);function R(t){if(e.debug.checkShaderErrors){const n=r.getProgramInfoLog(_).trim(),i=r.getShaderInfoLog(M).trim(),a=r.getShaderInfoLog(x).trim();let o=!0,s=!0;if(!1===r.getProgramParameter(_,r.LINK_STATUS))if(o=!1,"function"==typeof e.debug.onShaderError)e.debug.onShaderError(r,_,M,x);else{const e=Mr(r,M,"vertex"),i=Mr(r,x,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(_,r.VALIDATE_STATUS)+"\n\nMaterial Name: "+t.name+"\nMaterial Type: "+t.type+"\n\nProgram Info Log: "+n+"\n"+e+"\n"+i)}else""!==n?console.warn("THREE.WebGLProgram: Program Info Log:",n):""!==i&&""!==a||(s=!1);s&&(t.diagnostics={runnable:o,programLog:n,vertexShader:{log:i,prefix:g},fragmentShader:{log:a,prefix:v}})}r.deleteShader(M),r.deleteShader(x),A=new gr(r,_),b=function(e,t){const n={},i=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r0,J=o.clearcoat>0,ee=o.dispersion>0,te=o.iridescence>0,ne=o.sheen>0,ie=o.transmission>0,re=Q&&!!o.anisotropyMap,ae=J&&!!o.clearcoatMap,oe=J&&!!o.clearcoatNormalMap,se=J&&!!o.clearcoatRoughnessMap,le=te&&!!o.iridescenceMap,ce=te&&!!o.iridescenceThicknessMap,de=ne&&!!o.sheenColorMap,he=ne&&!!o.sheenRoughnessMap,_e=!!o.specularMap,ge=!!o.specularColorMap,ve=!!o.specularIntensityMap,Ee=ie&&!!o.transmissionMap,Se=ie&&!!o.thicknessMap,Te=!!o.gradientMap,Me=!!o.alphaMap,xe=o.alphaTest>0,Re=!!o.alphaHash,Ae=!!o.extensions;let be=U;o.toneMapped&&(null!==O&&!0!==O.isXRRenderTarget||(be=e.toneMapping));const Ce={shaderID:C,shaderType:o.type,shaderName:o.name,vertexShader:w,fragmentShader:D,defines:o.defines,customVertexShaderID:y,customFragmentShaderID:I,isRawShaderMaterial:!0===o.isRawShaderMaterial,glslVersion:o.glslVersion,precision:g,batching:G,batchingColor:G&&null!==T._colorsTexture,instancing:H,instancingColor:H&&null!==T.instanceColor,instancingMorph:H&&null!==T.morphTexture,supportsVertexTextures:_,outputColorSpace:null===O?e.outputColorSpace:!0===O.isXRRenderTarget?O.texture.colorSpace:B,alphaToCoverage:!!o.alphaToCoverage,map:V,matcap:z,envMap:k,envMapMode:k&&A.mapping,envMapCubeUVHeight:b,aoMap:W,lightMap:X,bumpMap:Y,normalMap:j,displacementMap:_&&K,emissiveMap:q,normalMapObjectSpace:j&&o.normalMapType===ue,normalMapTangentSpace:j&&o.normalMapType===fe,metalnessMap:Z,roughnessMap:$,anisotropy:Q,anisotropyMap:re,clearcoat:J,clearcoatMap:ae,clearcoatNormalMap:oe,clearcoatRoughnessMap:se,dispersion:ee,iridescence:te,iridescenceMap:le,iridescenceThicknessMap:ce,sheen:ne,sheenColorMap:de,sheenRoughnessMap:he,specularMap:_e,specularColorMap:ge,specularIntensityMap:ve,transmission:ie,transmissionMap:Ee,thicknessMap:Se,gradientMap:Te,opaque:!1===o.transparent&&o.blending===pe&&!1===o.alphaToCoverage,alphaMap:Me,alphaTest:xe,alphaHash:Re,combine:o.combine,mapUv:V&&E(o.map.channel),aoMapUv:W&&E(o.aoMap.channel),lightMapUv:X&&E(o.lightMap.channel),bumpMapUv:Y&&E(o.bumpMap.channel),normalMapUv:j&&E(o.normalMap.channel),displacementMapUv:K&&E(o.displacementMap.channel),emissiveMapUv:q&&E(o.emissiveMap.channel),metalnessMapUv:Z&&E(o.metalnessMap.channel),roughnessMapUv:$&&E(o.roughnessMap.channel),anisotropyMapUv:re&&E(o.anisotropyMap.channel),clearcoatMapUv:ae&&E(o.clearcoatMap.channel),clearcoatNormalMapUv:oe&&E(o.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:se&&E(o.clearcoatRoughnessMap.channel),iridescenceMapUv:le&&E(o.iridescenceMap.channel),iridescenceThicknessMapUv:ce&&E(o.iridescenceThicknessMap.channel),sheenColorMapUv:de&&E(o.sheenColorMap.channel),sheenRoughnessMapUv:he&&E(o.sheenRoughnessMap.channel),specularMapUv:_e&&E(o.specularMap.channel),specularColorMapUv:ge&&E(o.specularColorMap.channel),specularIntensityMapUv:ve&&E(o.specularIntensityMap.channel),transmissionMapUv:Ee&&E(o.transmissionMap.channel),thicknessMapUv:Se&&E(o.thicknessMap.channel),alphaMapUv:Me&&E(o.alphaMap.channel),vertexTangents:!!x.attributes.tangent&&(j||Q),vertexColors:o.vertexColors,vertexAlphas:!0===o.vertexColors&&!!x.attributes.color&&4===x.attributes.color.itemSize,pointsUvs:!0===T.isPoints&&!!x.attributes.uv&&(V||Me),fog:!!M,useFog:!0===o.fog,fogExp2:!!M&&M.isFogExp2,flatShading:!0===o.flatShading,sizeAttenuation:!0===o.sizeAttenuation,logarithmicDepthBuffer:h,reverseDepthBuffer:F,skinning:!0===T.isSkinnedMesh,morphTargets:void 0!==x.morphAttributes.position,morphNormals:void 0!==x.morphAttributes.normal,morphColors:void 0!==x.morphAttributes.color,morphTargetsCount:P,morphTextureStride:N,numDirLights:l.directional.length,numPointLights:l.point.length,numSpotLights:l.spot.length,numSpotLightMaps:l.spotLightMap.length,numRectAreaLights:l.rectArea.length,numHemiLights:l.hemi.length,numDirLightShadows:l.directionalShadowMap.length,numPointLightShadows:l.pointShadowMap.length,numSpotLightShadows:l.spotShadowMap.length,numSpotLightShadowsWithMaps:l.numSpotLightShadowsWithMaps,numLightProbes:l.numLightProbes,numClippingPlanes:s.numPlanes,numClipIntersection:s.numIntersection,dithering:o.dithering,shadowMapEnabled:e.shadowMap.enabled&&m.length>0,shadowMapType:e.shadowMap.type,toneMapping:be,decodeVideoTexture:V&&!0===o.map.isVideoTexture&&u.getTransfer(o.map.colorSpace)===f,decodeVideoTextureEmissive:q&&!0===o.emissiveMap.isVideoTexture&&u.getTransfer(o.emissiveMap.colorSpace)===f,premultipliedAlpha:o.premultipliedAlpha,doubleSided:o.side===me,flipSided:o.side===d,useDepthPacking:o.depthPacking>=0,depthPacking:o.depthPacking||0,index0AttributeName:o.index0AttributeName,extensionClipCullDistance:Ae&&!0===o.extensions.clipCullDistance&&i.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Ae&&!0===o.extensions.multiDraw||G)&&i.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:i.has("KHR_parallel_shader_compile"),customProgramCacheKey:o.customProgramCacheKey()};return Ce.vertexUv1s=p.has(1),Ce.vertexUv2s=p.has(2),Ce.vertexUv3s=p.has(3),p.clear(),Ce},getProgramCacheKey:function(t){const n=[];if(t.shaderID?n.push(t.shaderID):(n.push(t.customVertexShaderID),n.push(t.customFragmentShaderID)),void 0!==t.defines)for(const e in t.defines)n.push(e),n.push(t.defines[e]);return!1===t.isRawShaderMaterial&&(!function(e,t){e.push(t.precision),e.push(t.outputColorSpace),e.push(t.envMapMode),e.push(t.envMapCubeUVHeight),e.push(t.mapUv),e.push(t.alphaMapUv),e.push(t.lightMapUv),e.push(t.aoMapUv),e.push(t.bumpMapUv),e.push(t.normalMapUv),e.push(t.displacementMapUv),e.push(t.emissiveMapUv),e.push(t.metalnessMapUv),e.push(t.roughnessMapUv),e.push(t.anisotropyMapUv),e.push(t.clearcoatMapUv),e.push(t.clearcoatNormalMapUv),e.push(t.clearcoatRoughnessMapUv),e.push(t.iridescenceMapUv),e.push(t.iridescenceThicknessMapUv),e.push(t.sheenColorMapUv),e.push(t.sheenRoughnessMapUv),e.push(t.specularMapUv),e.push(t.specularColorMapUv),e.push(t.specularIntensityMapUv),e.push(t.transmissionMapUv),e.push(t.thicknessMapUv),e.push(t.combine),e.push(t.fogExp2),e.push(t.sizeAttenuation),e.push(t.morphTargetsCount),e.push(t.morphAttributeCount),e.push(t.numDirLights),e.push(t.numPointLights),e.push(t.numSpotLights),e.push(t.numSpotLightMaps),e.push(t.numHemiLights),e.push(t.numRectAreaLights),e.push(t.numDirLightShadows),e.push(t.numPointLightShadows),e.push(t.numSpotLightShadows),e.push(t.numSpotLightShadowsWithMaps),e.push(t.numLightProbes),e.push(t.shadowMapType),e.push(t.toneMapping),e.push(t.numClippingPlanes),e.push(t.numClipIntersection),e.push(t.depthPacking)}(n,t),function(e,t){l.disableAll(),t.supportsVertexTextures&&l.enable(0);t.instancing&&l.enable(1);t.instancingColor&&l.enable(2);t.instancingMorph&&l.enable(3);t.matcap&&l.enable(4);t.envMap&&l.enable(5);t.normalMapObjectSpace&&l.enable(6);t.normalMapTangentSpace&&l.enable(7);t.clearcoat&&l.enable(8);t.iridescence&&l.enable(9);t.alphaTest&&l.enable(10);t.vertexColors&&l.enable(11);t.vertexAlphas&&l.enable(12);t.vertexUv1s&&l.enable(13);t.vertexUv2s&&l.enable(14);t.vertexUv3s&&l.enable(15);t.vertexTangents&&l.enable(16);t.anisotropy&&l.enable(17);t.alphaHash&&l.enable(18);t.batching&&l.enable(19);t.dispersion&&l.enable(20);t.batchingColor&&l.enable(21);e.push(l.mask),l.disableAll(),t.fog&&l.enable(0);t.useFog&&l.enable(1);t.flatShading&&l.enable(2);t.logarithmicDepthBuffer&&l.enable(3);t.reverseDepthBuffer&&l.enable(4);t.skinning&&l.enable(5);t.morphTargets&&l.enable(6);t.morphNormals&&l.enable(7);t.morphColors&&l.enable(8);t.premultipliedAlpha&&l.enable(9);t.shadowMapEnabled&&l.enable(10);t.doubleSided&&l.enable(11);t.flipSided&&l.enable(12);t.useDepthPacking&&l.enable(13);t.dithering&&l.enable(14);t.transmission&&l.enable(15);t.sheen&&l.enable(16);t.opaque&&l.enable(17);t.pointsUvs&&l.enable(18);t.decodeVideoTexture&&l.enable(19);t.decodeVideoTextureEmissive&&l.enable(20);t.alphaToCoverage&&l.enable(21);e.push(l.mask)}(n,t),n.push(e.outputColorSpace)),n.push(t.customProgramCacheKey),n.join()},getUniforms:function(e){const t=v[e.type];let n;if(t){const e=yn[t];n=he.clone(e.uniforms)}else n=e.uniforms;return n},acquireProgram:function(t,n){let i;for(let e=0,t=m.length;e0?i.push(d):!0===o.transparent?r.push(d):n.push(d)},unshift:function(e,t,o,s,l,c){const d=a(e,t,o,s,l,c);o.transmission>0?i.unshift(d):!0===o.transparent?r.unshift(d):n.unshift(d)},finish:function(){for(let n=t,i=e.length;n1&&n.sort(e||Wr),i.length>1&&i.sort(t||Xr),r.length>1&&r.sort(t||Xr)}}}function jr(){let e=new WeakMap;return{get:function(t,n){const i=e.get(t);let r;return void 0===i?(r=new Yr,e.set(t,[r])):n>=i.length?(r=new Yr,i.push(r)):r=i[n],r},dispose:function(){e=new WeakMap}}}function Kr(){const t={};return{get:function(n){if(void 0!==t[n.id])return t[n.id];let i;switch(n.type){case"DirectionalLight":i={direction:new r,color:new e};break;case"SpotLight":i={position:new r,direction:new r,color:new e,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new r,color:new e,distance:0,decay:0};break;case"HemisphereLight":i={direction:new r,skyColor:new e,groundColor:new e};break;case"RectAreaLight":i={color:new e,position:new r,halfWidth:new r,halfHeight:new r}}return t[n.id]=i,i}}}let qr=0;function Zr(e,t){return(t.castShadow?2:0)-(e.castShadow?2:0)+(t.map?1:0)-(e.map?1:0)}function $r(e){const t=new Kr,i=function(){const e={};return{get:function(t){if(void 0!==e[t.id])return e[t.id];let i;switch(t.type){case"DirectionalLight":case"SpotLight":i={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new n};break;case"PointLight":i={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new n,shadowCameraNear:1,shadowCameraFar:1e3}}return e[t.id]=i,i}}}(),a={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let e=0;e<9;e++)a.probe.push(new r);const o=new r,s=new g,l=new g;return{setup:function(n){let r=0,o=0,s=0;for(let e=0;e<9;e++)a.probe[e].set(0,0,0);let l=0,c=0,d=0,u=0,f=0,p=0,m=0,h=0,_=0,g=0,v=0;n.sort(Zr);for(let e=0,E=n.length;e0&&(!0===e.has("OES_texture_float_linear")?(a.rectAreaLTC1=Dn.LTC_FLOAT_1,a.rectAreaLTC2=Dn.LTC_FLOAT_2):(a.rectAreaLTC1=Dn.LTC_HALF_1,a.rectAreaLTC2=Dn.LTC_HALF_2)),a.ambient[0]=r,a.ambient[1]=o,a.ambient[2]=s;const E=a.hash;E.directionalLength===l&&E.pointLength===c&&E.spotLength===d&&E.rectAreaLength===u&&E.hemiLength===f&&E.numDirectionalShadows===p&&E.numPointShadows===m&&E.numSpotShadows===h&&E.numSpotMaps===_&&E.numLightProbes===v||(a.directional.length=l,a.spot.length=d,a.rectArea.length=u,a.point.length=c,a.hemi.length=f,a.directionalShadow.length=p,a.directionalShadowMap.length=p,a.pointShadow.length=m,a.pointShadowMap.length=m,a.spotShadow.length=h,a.spotShadowMap.length=h,a.directionalShadowMatrix.length=p,a.pointShadowMatrix.length=m,a.spotLightMatrix.length=h+_-g,a.spotLightMap.length=_,a.numSpotLightShadowsWithMaps=g,a.numLightProbes=v,E.directionalLength=l,E.pointLength=c,E.spotLength=d,E.rectAreaLength=u,E.hemiLength=f,E.numDirectionalShadows=p,E.numPointShadows=m,E.numSpotShadows=h,E.numSpotMaps=_,E.numLightProbes=v,a.version=qr++)},setupView:function(e,t){let n=0,i=0,r=0,c=0,d=0;const u=t.matrixWorldInverse;for(let t=0,f=e.length;t=r.length?(a=new Qr(e),r.push(a)):a=r[i],a},dispose:function(){t=new WeakMap}}}function ea(e,t,i){let r=new ge;const a=new n,s=new n,c=new k,u=new ve({depthPacking:Ee}),f=new Se,p={},h=i.maxTextureSize,_={[m]:d,[d]:m,[me]:me},g=new l({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new n},radius:{value:4}},vertexShader:"void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"}),v=g.clone();v.defines.HORIZONTAL_PASS=1;const E=new D;E.setAttribute("position",new y(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const S=new o(E,g),T=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=re;let M=this.type;function x(n,i){const r=t.update(S);g.defines.VSM_SAMPLES!==n.blurSamples&&(g.defines.VSM_SAMPLES=n.blurSamples,v.defines.VSM_SAMPLES=n.blurSamples,g.needsUpdate=!0,v.needsUpdate=!0),null===n.mapPass&&(n.mapPass=new I(a.x,a.y)),g.uniforms.shadow_pass.value=n.map.texture,g.uniforms.resolution.value=n.mapSize,g.uniforms.radius.value=n.radius,e.setRenderTarget(n.mapPass),e.clear(),e.renderBufferDirect(i,null,r,g,S,null),v.uniforms.shadow_pass.value=n.mapPass.texture,v.uniforms.resolution.value=n.mapSize,v.uniforms.radius.value=n.radius,e.setRenderTarget(n.map),e.clear(),e.renderBufferDirect(i,null,r,v,S,null)}function R(t,n,i,r){let a=null;const o=!0===i.isPointLight?t.customDistanceMaterial:t.customDepthMaterial;if(void 0!==o)a=o;else if(a=!0===i.isPointLight?f:u,e.localClippingEnabled&&!0===n.clipShadows&&Array.isArray(n.clippingPlanes)&&0!==n.clippingPlanes.length||n.displacementMap&&0!==n.displacementScale||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0){const e=a.uuid,t=n.uuid;let i=p[e];void 0===i&&(i={},p[e]=i);let r=i[t];void 0===r&&(r=a.clone(),i[t]=r,n.addEventListener("dispose",b)),a=r}if(a.visible=n.visible,a.wireframe=n.wireframe,a.side=r===oe?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:_[n.side],a.alphaMap=n.alphaMap,a.alphaTest=n.alphaTest,a.map=n.map,a.clipShadows=n.clipShadows,a.clippingPlanes=n.clippingPlanes,a.clipIntersection=n.clipIntersection,a.displacementMap=n.displacementMap,a.displacementScale=n.displacementScale,a.displacementBias=n.displacementBias,a.wireframeLinewidth=n.wireframeLinewidth,a.linewidth=n.linewidth,!0===i.isPointLight&&!0===a.isMeshDistanceMaterial){e.properties.get(a).light=i}return a}function A(n,i,a,o,s){if(!1===n.visible)return;if(n.layers.test(i.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&s===oe)&&(!n.frustumCulled||r.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(a.matrixWorldInverse,n.matrixWorld);const r=t.update(n),l=n.material;if(Array.isArray(l)){const t=r.groups;for(let c=0,d=t.length;ch||a.y>h)&&(a.x>h&&(s.x=Math.floor(h/m.x),a.x=s.x*m.x,d.mapSize.x=s.x),a.y>h&&(s.y=Math.floor(h/m.y),a.y=s.y*m.y,d.mapSize.y=s.y)),null===d.map||!0===f||!0===p){const e=this.type!==oe?{minFilter:Te,magFilter:Te}:{};null!==d.map&&d.map.dispose(),d.map=new I(a.x,a.y,e),d.map.texture.name=l.name+".shadowMap",d.camera.updateProjectionMatrix()}e.setRenderTarget(d.map),e.clear();const _=d.getViewportCount();for(let e=0;e<_;e++){const t=d.getViewport(e);c.set(s.x*t.x,s.y*t.y,s.x*t.z,s.y*t.w),u.viewport(c),d.updateMatrices(l,e),r=d.getFrustum(),A(n,i,d.camera,l,this.type)}!0!==d.isPointLightShadow&&this.type===oe&&x(d,i),d.needsUpdate=!1}M=this.type,T.needsUpdate=!1,e.setRenderTarget(o,l,d)}}const ta={[nt]:tt,[et]:$e,[Je]:Ze,[Me]:Qe,[tt]:nt,[$e]:et,[Ze]:Je,[Qe]:Me};function na(t,n){const i=new function(){let e=!1;const n=new k;let i=null;const r=new k(0,0,0,0);return{setMask:function(n){i===n||e||(t.colorMask(n,n,n,n),i=n)},setLocked:function(t){e=t},setClear:function(e,i,a,o,s){!0===s&&(e*=o,i*=o,a*=o),n.set(e,i,a,o),!1===r.equals(n)&&(t.clearColor(e,i,a,o),r.copy(n))},reset:function(){e=!1,i=null,r.set(-1,0,0,0)}}},r=new function(){let e=!1,i=!1,r=null,a=null,o=null;return{setReversed:function(e){if(i!==e){const e=n.get("EXT_clip_control");i?e.clipControlEXT(e.LOWER_LEFT_EXT,e.ZERO_TO_ONE_EXT):e.clipControlEXT(e.LOWER_LEFT_EXT,e.NEGATIVE_ONE_TO_ONE_EXT);const t=o;o=null,this.setClear(t)}i=e},getReversed:function(){return i},setTest:function(e){e?W(t.DEPTH_TEST):X(t.DEPTH_TEST)},setMask:function(n){r===n||e||(t.depthMask(n),r=n)},setFunc:function(e){if(i&&(e=ta[e]),a!==e){switch(e){case nt:t.depthFunc(t.NEVER);break;case tt:t.depthFunc(t.ALWAYS);break;case et:t.depthFunc(t.LESS);break;case Me:t.depthFunc(t.LEQUAL);break;case Je:t.depthFunc(t.EQUAL);break;case Qe:t.depthFunc(t.GEQUAL);break;case $e:t.depthFunc(t.GREATER);break;case Ze:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}a=e}},setLocked:function(t){e=t},setClear:function(e){o!==e&&(i&&(e=1-e),t.clearDepth(e),o=e)},reset:function(){e=!1,r=null,a=null,o=null,i=!1}}},a=new function(){let e=!1,n=null,i=null,r=null,a=null,o=null,s=null,l=null,c=null;return{setTest:function(n){e||(n?W(t.STENCIL_TEST):X(t.STENCIL_TEST))},setMask:function(i){n===i||e||(t.stencilMask(i),n=i)},setFunc:function(e,n,o){i===e&&r===n&&a===o||(t.stencilFunc(e,n,o),i=e,r=n,a=o)},setOp:function(e,n,i){o===e&&s===n&&l===i||(t.stencilOp(e,n,i),o=e,s=n,l=i)},setLocked:function(t){e=t},setClear:function(e){c!==e&&(t.clearStencil(e),c=e)},reset:function(){e=!1,n=null,i=null,r=null,a=null,o=null,s=null,l=null,c=null}}},o=new WeakMap,s=new WeakMap;let l={},c={},u=new WeakMap,f=[],p=null,m=!1,h=null,_=null,g=null,v=null,E=null,S=null,T=null,M=new e(0,0,0),x=0,R=!1,A=null,b=null,C=null,L=null,P=null;const U=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let w=!1,D=0;const y=t.getParameter(t.VERSION);-1!==y.indexOf("WebGL")?(D=parseFloat(/^WebGL (\d)/.exec(y)[1]),w=D>=1):-1!==y.indexOf("OpenGL ES")&&(D=parseFloat(/^OpenGL ES (\d)/.exec(y)[1]),w=D>=2);let I=null,O={};const F=t.getParameter(t.SCISSOR_BOX),B=t.getParameter(t.VIEWPORT),H=(new k).fromArray(F),G=(new k).fromArray(B);function V(e,n,i,r){const a=new Uint8Array(4),o=t.createTexture();t.bindTexture(e,o),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let o=0;on||r.height>n)&&(i=n/Math.max(r.width,r.height)),i<1){if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof VideoFrame&&e instanceof VideoFrame){const n=Math.floor(i*r.width),a=Math.floor(i*r.height);void 0===m&&(m=g(n,a));const o=t?g(n,a):m;o.width=n,o.height=a;return o.getContext("2d").drawImage(e,0,0,n,a),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+r.width+"x"+r.height+") to ("+n+"x"+a+")."),o}return"data"in e&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+r.width+"x"+r.height+")."),e}return e}function S(e){return e.generateMipmaps}function x(t){e.generateMipmap(t)}function R(t){return t.isWebGLCubeRenderTarget?e.TEXTURE_CUBE_MAP:t.isWebGL3DRenderTarget?e.TEXTURE_3D:t.isWebGLArrayRenderTarget||t.isCompressedArrayTexture?e.TEXTURE_2D_ARRAY:e.TEXTURE_2D}function A(n,i,r,a,o=!1){if(null!==n){if(void 0!==e[n])return e[n];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+n+"'")}let s=i;if(i===e.RED&&(r===e.FLOAT&&(s=e.R32F),r===e.HALF_FLOAT&&(s=e.R16F),r===e.UNSIGNED_BYTE&&(s=e.R8)),i===e.RED_INTEGER&&(r===e.UNSIGNED_BYTE&&(s=e.R8UI),r===e.UNSIGNED_SHORT&&(s=e.R16UI),r===e.UNSIGNED_INT&&(s=e.R32UI),r===e.BYTE&&(s=e.R8I),r===e.SHORT&&(s=e.R16I),r===e.INT&&(s=e.R32I)),i===e.RG&&(r===e.FLOAT&&(s=e.RG32F),r===e.HALF_FLOAT&&(s=e.RG16F),r===e.UNSIGNED_BYTE&&(s=e.RG8)),i===e.RG_INTEGER&&(r===e.UNSIGNED_BYTE&&(s=e.RG8UI),r===e.UNSIGNED_SHORT&&(s=e.RG16UI),r===e.UNSIGNED_INT&&(s=e.RG32UI),r===e.BYTE&&(s=e.RG8I),r===e.SHORT&&(s=e.RG16I),r===e.INT&&(s=e.RG32I)),i===e.RGB_INTEGER&&(r===e.UNSIGNED_BYTE&&(s=e.RGB8UI),r===e.UNSIGNED_SHORT&&(s=e.RGB16UI),r===e.UNSIGNED_INT&&(s=e.RGB32UI),r===e.BYTE&&(s=e.RGB8I),r===e.SHORT&&(s=e.RGB16I),r===e.INT&&(s=e.RGB32I)),i===e.RGBA_INTEGER&&(r===e.UNSIGNED_BYTE&&(s=e.RGBA8UI),r===e.UNSIGNED_SHORT&&(s=e.RGBA16UI),r===e.UNSIGNED_INT&&(s=e.RGBA32UI),r===e.BYTE&&(s=e.RGBA8I),r===e.SHORT&&(s=e.RGBA16I),r===e.INT&&(s=e.RGBA32I)),i===e.RGB&&r===e.UNSIGNED_INT_5_9_9_9_REV&&(s=e.RGB9_E5),i===e.RGBA){const t=o?se:u.getTransfer(a);r===e.FLOAT&&(s=e.RGBA32F),r===e.HALF_FLOAT&&(s=e.RGBA16F),r===e.UNSIGNED_BYTE&&(s=t===f?e.SRGB8_ALPHA8:e.RGBA8),r===e.UNSIGNED_SHORT_4_4_4_4&&(s=e.RGBA4),r===e.UNSIGNED_SHORT_5_5_5_1&&(s=e.RGB5_A1)}return s!==e.R16F&&s!==e.R32F&&s!==e.RG16F&&s!==e.RG32F&&s!==e.RGBA16F&&s!==e.RGBA32F||t.get("EXT_color_buffer_float"),s}function b(t,n){let i;return t?null===n||n===St||n===Tt?i=e.DEPTH24_STENCIL8:n===M?i=e.DEPTH32F_STENCIL8:n===Mt&&(i=e.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):null===n||n===St||n===Tt?i=e.DEPTH_COMPONENT24:n===M?i=e.DEPTH_COMPONENT32F:n===Mt&&(i=e.DEPTH_COMPONENT16),i}function C(e,t){return!0===S(e)||e.isFramebufferTexture&&e.minFilter!==Te&&e.minFilter!==F?Math.log2(Math.max(t.width,t.height))+1:void 0!==e.mipmaps&&e.mipmaps.length>0?e.mipmaps.length:e.isCompressedTexture&&Array.isArray(e.image)?t.mipmaps.length:1}function L(e){const t=e.target;t.removeEventListener("dispose",L),function(e){const t=r.get(e);if(void 0===t.__webglInit)return;const n=e.source,i=h.get(n);if(i){const r=i[t.__cacheKey];r.usedTimes--,0===r.usedTimes&&U(e),0===Object.keys(i).length&&h.delete(n)}r.remove(e)}(t),t.isVideoTexture&&p.delete(t)}function P(t){const n=t.target;n.removeEventListener("dispose",P),function(t){const n=r.get(t);t.depthTexture&&(t.depthTexture.dispose(),r.remove(t.depthTexture));if(t.isWebGLCubeRenderTarget)for(let t=0;t<6;t++){if(Array.isArray(n.__webglFramebuffer[t]))for(let i=0;i0&&a.__version!==t.version){const e=t.image;if(null===e)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==e.complete)return void G(a,t,n);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete")}}i.bindTexture(e.TEXTURE_2D,a.__webglTexture,e.TEXTURE0+n)}const y={[it]:e.REPEAT,[rt]:e.CLAMP_TO_EDGE,[at]:e.MIRRORED_REPEAT},I={[Te]:e.NEAREST,[ot]:e.NEAREST_MIPMAP_NEAREST,[st]:e.NEAREST_MIPMAP_LINEAR,[F]:e.LINEAR,[lt]:e.LINEAR_MIPMAP_NEAREST,[ct]:e.LINEAR_MIPMAP_LINEAR},N={[dt]:e.NEVER,[ut]:e.ALWAYS,[ft]:e.LESS,[X]:e.LEQUAL,[pt]:e.EQUAL,[mt]:e.GEQUAL,[ht]:e.GREATER,[_t]:e.NOTEQUAL};function O(n,i){if(i.type!==M||!1!==t.has("OES_texture_float_linear")||i.magFilter!==F&&i.magFilter!==lt&&i.magFilter!==st&&i.magFilter!==ct&&i.minFilter!==F&&i.minFilter!==lt&&i.minFilter!==st&&i.minFilter!==ct||console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),e.texParameteri(n,e.TEXTURE_WRAP_S,y[i.wrapS]),e.texParameteri(n,e.TEXTURE_WRAP_T,y[i.wrapT]),n!==e.TEXTURE_3D&&n!==e.TEXTURE_2D_ARRAY||e.texParameteri(n,e.TEXTURE_WRAP_R,y[i.wrapR]),e.texParameteri(n,e.TEXTURE_MAG_FILTER,I[i.magFilter]),e.texParameteri(n,e.TEXTURE_MIN_FILTER,I[i.minFilter]),i.compareFunction&&(e.texParameteri(n,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE),e.texParameteri(n,e.TEXTURE_COMPARE_FUNC,N[i.compareFunction])),!0===t.has("EXT_texture_filter_anisotropic")){if(i.magFilter===Te)return;if(i.minFilter!==st&&i.minFilter!==ct)return;if(i.type===M&&!1===t.has("OES_texture_float_linear"))return;if(i.anisotropy>1||r.get(i).__currentAnisotropy){const o=t.get("EXT_texture_filter_anisotropic");e.texParameterf(n,o.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(i.anisotropy,a.getMaxAnisotropy())),r.get(i).__currentAnisotropy=i.anisotropy}}}function H(t,n){let i=!1;void 0===t.__webglInit&&(t.__webglInit=!0,n.addEventListener("dispose",L));const r=n.source;let a=h.get(r);void 0===a&&(a={},h.set(r,a));const o=function(e){const t=[];return t.push(e.wrapS),t.push(e.wrapT),t.push(e.wrapR||0),t.push(e.magFilter),t.push(e.minFilter),t.push(e.anisotropy),t.push(e.internalFormat),t.push(e.format),t.push(e.type),t.push(e.generateMipmaps),t.push(e.premultiplyAlpha),t.push(e.flipY),t.push(e.unpackAlignment),t.push(e.colorSpace),t.join()}(n);if(o!==t.__cacheKey){void 0===a[o]&&(a[o]={texture:e.createTexture(),usedTimes:0},s.memory.textures++,i=!0),a[o].usedTimes++;const r=a[t.__cacheKey];void 0!==r&&(a[t.__cacheKey].usedTimes--,0===r.usedTimes&&U(n)),t.__cacheKey=o,t.__webglTexture=a[o].texture}return i}function G(t,n,s){let l=e.TEXTURE_2D;(n.isDataArrayTexture||n.isCompressedArrayTexture)&&(l=e.TEXTURE_2D_ARRAY),n.isData3DTexture&&(l=e.TEXTURE_3D);const c=H(t,n),d=n.source;i.bindTexture(l,t.__webglTexture,e.TEXTURE0+s);const f=r.get(d);if(d.version!==f.__version||!0===c){i.activeTexture(e.TEXTURE0+s);const t=u.getPrimaries(u.workingColorSpace),r=n.colorSpace===gt?null:u.getPrimaries(n.colorSpace),p=n.colorSpace===gt||t===r?e.NONE:e.BROWSER_DEFAULT_WEBGL;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,n.flipY),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),e.pixelStorei(e.UNPACK_ALIGNMENT,n.unpackAlignment),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,p);let m=v(n.image,!1,a.maxTextureSize);m=q(n,m);const h=o.convert(n.format,n.colorSpace),_=o.convert(n.type);let g,T=A(n.internalFormat,h,_,n.colorSpace,n.isVideoTexture);O(l,n);const M=n.mipmaps,R=!0!==n.isVideoTexture,L=void 0===f.__version||!0===c,P=d.dataReady,U=C(n,m);if(n.isDepthTexture)T=b(n.format===vt,n.type),L&&(R?i.texStorage2D(e.TEXTURE_2D,1,T,m.width,m.height):i.texImage2D(e.TEXTURE_2D,0,T,m.width,m.height,0,h,_,null));else if(n.isDataTexture)if(M.length>0){R&&L&&i.texStorage2D(e.TEXTURE_2D,U,T,M[0].width,M[0].height);for(let t=0,n=M.length;t0){const r=Et(g.width,g.height,n.format,n.type);for(const a of n.layerUpdates){const n=g.data.subarray(a*r/g.data.BYTES_PER_ELEMENT,(a+1)*r/g.data.BYTES_PER_ELEMENT);i.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,t,0,0,a,g.width,g.height,1,h,n)}n.clearLayerUpdates()}else i.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,t,0,0,0,g.width,g.height,m.depth,h,g.data)}else i.compressedTexImage3D(e.TEXTURE_2D_ARRAY,t,T,g.width,g.height,m.depth,0,g.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else R?P&&i.texSubImage3D(e.TEXTURE_2D_ARRAY,t,0,0,0,g.width,g.height,m.depth,h,_,g.data):i.texImage3D(e.TEXTURE_2D_ARRAY,t,T,g.width,g.height,m.depth,0,h,_,g.data)}else{R&&L&&i.texStorage2D(e.TEXTURE_2D,U,T,M[0].width,M[0].height);for(let t=0,r=M.length;t0){const t=Et(m.width,m.height,n.format,n.type);for(const r of n.layerUpdates){const n=m.data.subarray(r*t/m.data.BYTES_PER_ELEMENT,(r+1)*t/m.data.BYTES_PER_ELEMENT);i.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,r,m.width,m.height,1,h,_,n)}n.clearLayerUpdates()}else i.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,0,m.width,m.height,m.depth,h,_,m.data)}else i.texImage3D(e.TEXTURE_2D_ARRAY,0,T,m.width,m.height,m.depth,0,h,_,m.data);else if(n.isData3DTexture)R?(L&&i.texStorage3D(e.TEXTURE_3D,U,T,m.width,m.height,m.depth),P&&i.texSubImage3D(e.TEXTURE_3D,0,0,0,0,m.width,m.height,m.depth,h,_,m.data)):i.texImage3D(e.TEXTURE_3D,0,T,m.width,m.height,m.depth,0,h,_,m.data);else if(n.isFramebufferTexture){if(L)if(R)i.texStorage2D(e.TEXTURE_2D,U,T,m.width,m.height);else{let t=m.width,n=m.height;for(let r=0;r>=1,n>>=1}}else if(M.length>0){if(R&&L){const t=Z(M[0]);i.texStorage2D(e.TEXTURE_2D,U,T,t.width,t.height)}for(let t=0,n=M.length;t>d),r=Math.max(1,n.height>>d);c===e.TEXTURE_3D||c===e.TEXTURE_2D_ARRAY?i.texImage3D(c,d,p,t,r,n.depth,0,u,f,null):i.texImage2D(c,d,p,t,r,0,u,f,null)}i.bindFramebuffer(e.FRAMEBUFFER,t),K(n)?l.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,s,c,h.__webglTexture,0,j(n)):(c===e.TEXTURE_2D||c>=e.TEXTURE_CUBE_MAP_POSITIVE_X&&c<=e.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&e.framebufferTexture2D(e.FRAMEBUFFER,s,c,h.__webglTexture,d),i.bindFramebuffer(e.FRAMEBUFFER,null)}function z(t,n,i){if(e.bindRenderbuffer(e.RENDERBUFFER,t),n.depthBuffer){const r=n.depthTexture,a=r&&r.isDepthTexture?r.type:null,o=b(n.stencilBuffer,a),s=n.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,c=j(n);K(n)?l.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,c,o,n.width,n.height):i?e.renderbufferStorageMultisample(e.RENDERBUFFER,c,o,n.width,n.height):e.renderbufferStorage(e.RENDERBUFFER,o,n.width,n.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,s,e.RENDERBUFFER,t)}else{const t=n.textures;for(let r=0;r{delete n.__boundDepthTexture,delete n.__depthDisposeCallback,e.removeEventListener("dispose",t)};e.addEventListener("dispose",t),n.__depthDisposeCallback=t}n.__boundDepthTexture=e}if(t.depthTexture&&!n.__autoAllocateDepthBuffer){if(a)throw new Error("target.depthTexture not supported in Cube render targets");!function(t,n){if(n&&n.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(i.bindFramebuffer(e.FRAMEBUFFER,t),!n.depthTexture||!n.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");const a=r.get(n.depthTexture);a.__renderTarget=n,a.__webglTexture&&n.depthTexture.image.width===n.width&&n.depthTexture.image.height===n.height||(n.depthTexture.image.width=n.width,n.depthTexture.image.height=n.height,n.depthTexture.needsUpdate=!0),D(n.depthTexture,0);const o=a.__webglTexture,s=j(n);if(n.depthTexture.format===xt)K(n)?l.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,o,0,s):e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,o,0);else{if(n.depthTexture.format!==vt)throw new Error("Unknown depthTexture format");K(n)?l.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.TEXTURE_2D,o,0,s):e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.TEXTURE_2D,o,0)}}(n.__webglFramebuffer,t)}else if(a){n.__webglDepthbuffer=[];for(let r=0;r<6;r++)if(i.bindFramebuffer(e.FRAMEBUFFER,n.__webglFramebuffer[r]),void 0===n.__webglDepthbuffer[r])n.__webglDepthbuffer[r]=e.createRenderbuffer(),z(n.__webglDepthbuffer[r],t,!1);else{const i=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,a=n.__webglDepthbuffer[r];e.bindRenderbuffer(e.RENDERBUFFER,a),e.framebufferRenderbuffer(e.FRAMEBUFFER,i,e.RENDERBUFFER,a)}}else if(i.bindFramebuffer(e.FRAMEBUFFER,n.__webglFramebuffer),void 0===n.__webglDepthbuffer)n.__webglDepthbuffer=e.createRenderbuffer(),z(n.__webglDepthbuffer,t,!1);else{const i=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,r=n.__webglDepthbuffer;e.bindRenderbuffer(e.RENDERBUFFER,r),e.framebufferRenderbuffer(e.FRAMEBUFFER,i,e.RENDERBUFFER,r)}i.bindFramebuffer(e.FRAMEBUFFER,null)}const W=[],Y=[];function j(e){return Math.min(a.maxSamples,e.samples)}function K(e){const n=r.get(e);return e.samples>0&&!0===t.has("WEBGL_multisampled_render_to_texture")&&!1!==n.__useRenderToTexture}function q(e,t){const n=e.colorSpace,i=e.format,r=e.type;return!0===e.isCompressedTexture||!0===e.isVideoTexture||n!==B&&n!==gt&&(u.getTransfer(n)===f?i===E&&r===T||console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",n)),t}function Z(e){return"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement?(d.width=e.naturalWidth||e.width,d.height=e.naturalHeight||e.height):"undefined"!=typeof VideoFrame&&e instanceof VideoFrame?(d.width=e.displayWidth,d.height=e.displayHeight):(d.width=e.width,d.height=e.height),d}this.allocateTextureUnit=function(){const e=w;return e>=a.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+e+" texture units while this GPU supports only "+a.maxTextures),w+=1,e},this.resetTextureUnits=function(){w=0},this.setTexture2D=D,this.setTexture2DArray=function(t,n){const a=r.get(t);t.version>0&&a.__version!==t.version?G(a,t,n):i.bindTexture(e.TEXTURE_2D_ARRAY,a.__webglTexture,e.TEXTURE0+n)},this.setTexture3D=function(t,n){const a=r.get(t);t.version>0&&a.__version!==t.version?G(a,t,n):i.bindTexture(e.TEXTURE_3D,a.__webglTexture,e.TEXTURE0+n)},this.setTextureCube=function(t,n){const s=r.get(t);t.version>0&&s.__version!==t.version?function(t,n,s){if(6!==n.image.length)return;const l=H(t,n),c=n.source;i.bindTexture(e.TEXTURE_CUBE_MAP,t.__webglTexture,e.TEXTURE0+s);const d=r.get(c);if(c.version!==d.__version||!0===l){i.activeTexture(e.TEXTURE0+s);const t=u.getPrimaries(u.workingColorSpace),r=n.colorSpace===gt?null:u.getPrimaries(n.colorSpace),f=n.colorSpace===gt||t===r?e.NONE:e.BROWSER_DEFAULT_WEBGL;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,n.flipY),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),e.pixelStorei(e.UNPACK_ALIGNMENT,n.unpackAlignment),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,f);const p=n.isCompressedTexture||n.image[0].isCompressedTexture,m=n.image[0]&&n.image[0].isDataTexture,h=[];for(let e=0;e<6;e++)h[e]=p||m?m?n.image[e].image:n.image[e]:v(n.image[e],!0,a.maxCubemapSize),h[e]=q(n,h[e]);const _=h[0],g=o.convert(n.format,n.colorSpace),T=o.convert(n.type),M=A(n.internalFormat,g,T,n.colorSpace),R=!0!==n.isVideoTexture,b=void 0===d.__version||!0===l,L=c.dataReady;let P,U=C(n,_);if(O(e.TEXTURE_CUBE_MAP,n),p){R&&b&&i.texStorage2D(e.TEXTURE_CUBE_MAP,U,M,_.width,_.height);for(let t=0;t<6;t++){P=h[t].mipmaps;for(let r=0;r0&&U++;const t=Z(h[0]);i.texStorage2D(e.TEXTURE_CUBE_MAP,U,M,t.width,t.height)}for(let t=0;t<6;t++)if(m){R?L&&i.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,h[t].width,h[t].height,g,T,h[t].data):i.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,M,h[t].width,h[t].height,0,g,T,h[t].data);for(let n=0;n1;if(u||(void 0===l.__webglTexture&&(l.__webglTexture=e.createTexture()),l.__version=n.version,s.memory.textures++),d){a.__webglFramebuffer=[];for(let t=0;t<6;t++)if(n.mipmaps&&n.mipmaps.length>0){a.__webglFramebuffer[t]=[];for(let i=0;i0){a.__webglFramebuffer=[];for(let t=0;t0&&!1===K(t)){a.__webglMultisampledFramebuffer=e.createFramebuffer(),a.__webglColorRenderbuffer=[],i.bindFramebuffer(e.FRAMEBUFFER,a.__webglMultisampledFramebuffer);for(let n=0;n0)for(let r=0;r0)for(let i=0;i0)if(!1===K(t)){const n=t.textures,a=t.width,o=t.height;let s=e.COLOR_BUFFER_BIT;const l=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,d=r.get(t),u=n.length>1;if(u)for(let t=0;ts+c?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!l.inputState.pinching&&o<=s-c&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else null!==s&&e.gripSpace&&(r=t.getPose(e.gripSpace,n),null!==r&&(s.matrix.fromArray(r.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale),s.matrixWorldNeedsUpdate=!0,r.linearVelocity?(s.hasLinearVelocity=!0,s.linearVelocity.copy(r.linearVelocity)):s.hasLinearVelocity=!1,r.angularVelocity?(s.hasAngularVelocity=!0,s.angularVelocity.copy(r.angularVelocity)):s.hasAngularVelocity=!1));null!==o&&(i=t.getPose(e.targetRaySpace,n),null===i&&null!==r&&(i=r),null!==i&&(o.matrix.fromArray(i.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,i.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(i.linearVelocity)):o.hasLinearVelocity=!1,i.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(i.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(aa)))}return null!==o&&(o.visible=null!==i),null!==s&&(s.visible=null!==r),null!==l&&(l.visible=null!==a),this}_getHandJoint(e,t){if(void 0===e.joints[t.jointName]){const n=new vn;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}}class sa{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t,n){if(null===this.texture){const i=new Y;e.properties.get(i).__webglTexture=t.texture,t.depthNear==n.depthNear&&t.depthFar==n.depthFar||(this.depthNear=t.depthNear,this.depthFar=t.depthFar),this.texture=i}}getMesh(e){if(null!==this.texture&&null===this.mesh){const t=e.cameras[0].viewport,n=new l({vertexShader:"\nvoid main() {\n\n\tgl_Position = vec4( position, 1.0 );\n\n}",fragmentShader:"\nuniform sampler2DArray depthColor;\nuniform float depthWidth;\nuniform float depthHeight;\n\nvoid main() {\n\n\tvec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );\n\n\tif ( coord.x >= 1.0 ) {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;\n\n\t} else {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;\n\n\t}\n\n}",uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new o(new p(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class la extends En{constructor(e,t){super();const i=this;let a=null,o=1,s=null,l="local-floor",c=1,d=null,u=null,f=null,p=null,m=null,h=null;const _=new sa,g=t.getContextAttributes();let v=null,S=null;const M=[],x=[],R=new n;let A=null;const b=new P;b.viewport=new k;const C=new P;C.viewport=new k;const L=[b,C],U=new Sn;let w=null,D=null;function y(e){const t=x.indexOf(e.inputSource);if(-1===t)return;const n=M[t];void 0!==n&&(n.update(e.inputSource,e.frame,d||s),n.dispatchEvent({type:e.type,data:e.inputSource}))}function N(){a.removeEventListener("select",y),a.removeEventListener("selectstart",y),a.removeEventListener("selectend",y),a.removeEventListener("squeeze",y),a.removeEventListener("squeezestart",y),a.removeEventListener("squeezeend",y),a.removeEventListener("end",N),a.removeEventListener("inputsourceschange",O);for(let e=0;e=0&&(x[i]=null,M[i].disconnect(n))}for(let t=0;t=x.length){x.push(n),i=e;break}if(null===x[e]){x[e]=n,i=e;break}}if(-1===i)break}const r=M[i];r&&r.connect(n)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=M[e];return void 0===t&&(t=new oa,M[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=M[e];return void 0===t&&(t=new oa,M[e]=t),t.getGripSpace()},this.getHand=function(e){let t=M[e];return void 0===t&&(t=new oa,M[e]=t),t.getHandSpace()},this.setFramebufferScaleFactor=function(e){o=e,!0===i.isPresenting&&console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(e){l=e,!0===i.isPresenting&&console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return d||s},this.setReferenceSpace=function(e){d=e},this.getBaseLayer=function(){return null!==p?p:m},this.getBinding=function(){return f},this.getFrame=function(){return h},this.getSession=function(){return a},this.setSession=async function(n){if(a=n,null!==a){if(v=e.getRenderTarget(),a.addEventListener("select",y),a.addEventListener("selectstart",y),a.addEventListener("selectend",y),a.addEventListener("squeeze",y),a.addEventListener("squeezestart",y),a.addEventListener("squeezeend",y),a.addEventListener("end",N),a.addEventListener("inputsourceschange",O),!0!==g.xrCompatible&&await t.makeXRCompatible(),A=e.getPixelRatio(),e.getSize(R),void 0===a.renderState.layers){const n={antialias:g.antialias,alpha:!0,depth:g.depth,stencil:g.stencil,framebufferScaleFactor:o};m=new XRWebGLLayer(a,t,n),a.updateRenderState({baseLayer:m}),e.setPixelRatio(1),e.setSize(m.framebufferWidth,m.framebufferHeight,!1),S=new I(m.framebufferWidth,m.framebufferHeight,{format:E,type:T,colorSpace:e.outputColorSpace,stencilBuffer:g.stencil})}else{let n=null,i=null,r=null;g.depth&&(r=g.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,n=g.stencil?vt:xt,i=g.stencil?Tt:St);const s={colorFormat:t.RGBA8,depthFormat:r,scaleFactor:o};f=new XRWebGLBinding(a,t),p=f.createProjectionLayer(s),a.updateRenderState({layers:[p]}),e.setPixelRatio(1),e.setSize(p.textureWidth,p.textureHeight,!1),S=new I(p.textureWidth,p.textureHeight,{format:E,type:T,depthTexture:new j(p.textureWidth,p.textureHeight,i,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:g.stencil,colorSpace:e.outputColorSpace,samples:g.antialias?4:0,resolveDepthBuffer:!1===p.ignoreDepthValues})}S.isXRRenderTarget=!0,this.setFoveation(c),d=null,s=await a.requestReferenceSpace(l),V.setContext(a),V.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==a)return a.environmentBlendMode},this.getDepthTexture=function(){return _.getDepthTexture()};const F=new r,B=new r;function H(e,t){null===t?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(null===a)return;let t=e.near,n=e.far;null!==_.texture&&(_.depthNear>0&&(t=_.depthNear),_.depthFar>0&&(n=_.depthFar)),U.near=C.near=b.near=t,U.far=C.far=b.far=n,w===U.near&&D===U.far||(a.updateRenderState({depthNear:U.near,depthFar:U.far}),w=U.near,D=U.far),b.layers.mask=2|e.layers.mask,C.layers.mask=4|e.layers.mask,U.layers.mask=b.layers.mask|C.layers.mask;const i=e.parent,r=U.cameras;H(U,i);for(let e=0;e0&&(e.alphaTest.value=i.alphaTest);const r=t.get(i),a=r.envMap,o=r.envMapRotation;a&&(e.envMap.value=a,ca.copy(o),ca.x*=-1,ca.y*=-1,ca.z*=-1,a.isCubeTexture&&!1===a.isRenderTargetTexture&&(ca.y*=-1,ca.z*=-1),e.envMapRotation.value.setFromMatrix4(da.makeRotationFromEuler(ca)),e.flipEnvMap.value=a.isCubeTexture&&!1===a.isRenderTargetTexture?-1:1,e.reflectivity.value=i.reflectivity,e.ior.value=i.ior,e.refractionRatio.value=i.refractionRatio),i.lightMap&&(e.lightMap.value=i.lightMap,e.lightMapIntensity.value=i.lightMapIntensity,n(i.lightMap,e.lightMapTransform)),i.aoMap&&(e.aoMap.value=i.aoMap,e.aoMapIntensity.value=i.aoMapIntensity,n(i.aoMap,e.aoMapTransform))}return{refreshFogUniforms:function(t,n){n.color.getRGB(t.fogColor.value,h(e)),n.isFog?(t.fogNear.value=n.near,t.fogFar.value=n.far):n.isFogExp2&&(t.fogDensity.value=n.density)},refreshMaterialUniforms:function(e,r,a,o,s){r.isMeshBasicMaterial||r.isMeshLambertMaterial?i(e,r):r.isMeshToonMaterial?(i(e,r),function(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}(e,r)):r.isMeshPhongMaterial?(i(e,r),function(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}(e,r)):r.isMeshStandardMaterial?(i(e,r),function(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,n(t.metalnessMap,e.metalnessMapTransform));e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,n(t.roughnessMap,e.roughnessMapTransform));t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}(e,r),r.isMeshPhysicalMaterial&&function(e,t,i){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform)));t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===d&&e.clearcoatNormalScale.value.negate()));t.dispersion>0&&(e.dispersion.value=t.dispersion);t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform)));t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=i.texture,e.transmissionSamplerSize.value.set(i.width,i.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor));t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform)));e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform));t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}(e,r,s)):r.isMeshMatcapMaterial?(i(e,r),function(e,t){t.matcap&&(e.matcap.value=t.matcap)}(e,r)):r.isMeshDepthMaterial?i(e,r):r.isMeshDistanceMaterial?(i(e,r),function(e,n){const i=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(i.matrixWorld),e.nearDistance.value=i.shadow.camera.near,e.farDistance.value=i.shadow.camera.far}(e,r)):r.isMeshNormalMaterial?i(e,r):r.isLineBasicMaterial?(function(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}(e,r),r.isLineDashedMaterial&&function(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}(e,r)):r.isPointsMaterial?function(e,t,i,r){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*i,e.scale.value=.5*r,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform));t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform));t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}(e,r,a,o):r.isSpriteMaterial?function(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform));t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform));t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}(e,r):r.isShadowMaterial?(e.color.value.copy(r.color),e.opacity.value=r.opacity):r.isShaderMaterial&&(r.uniformsNeedUpdate=!1)}}}function fa(e,t,n,i){let r={},a={},o=[];const s=e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);function l(e,t,n,i){const r=e.value,a=t+"_"+n;if(void 0===i[a])return i[a]="number"==typeof r||"boolean"==typeof r?r:r.clone(),!0;{const e=i[a];if("number"==typeof r||"boolean"==typeof r){if(e!==r)return i[a]=r,!0}else if(!1===e.equals(r))return e.copy(r),!0}return!1}function c(e){const t={boundary:0,storage:0};return"number"==typeof e||"boolean"==typeof e?(t.boundary=4,t.storage=4):e.isVector2?(t.boundary=8,t.storage=8):e.isVector3||e.isColor?(t.boundary=16,t.storage=12):e.isVector4?(t.boundary=16,t.storage=16):e.isMatrix3?(t.boundary=48,t.storage=48):e.isMatrix4?(t.boundary=64,t.storage=64):e.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",e),t}function d(t){const n=t.target;n.removeEventListener("dispose",d);const i=o.indexOf(n.__bindingPointIndex);o.splice(i,1),e.deleteBuffer(r[n.id]),delete r[n.id],delete a[n.id]}return{bind:function(e,t){const n=t.program;i.uniformBlockBinding(e,n)},update:function(n,u){let f=r[n.id];void 0===f&&(!function(e){const t=e.uniforms;let n=0;const i=16;for(let e=0,r=t.length;e0&&(n+=i-r);e.__size=n,e.__cache={}}(n),f=function(t){const n=function(){for(let e=0;e0),u=!!n.morphAttributes.position,f=!!n.morphAttributes.normal,p=!!n.morphAttributes.color;let m=U;i.toneMapped&&(null!==D&&!0!==D.isXRRenderTarget||(m=C.toneMapping));const h=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,_=void 0!==h?h.length:0,g=fe.get(i),v=R.state.lights;if(!0===J&&(!0===ee||e!==N)){const t=e===N&&i.id===y;Ae.setState(i,e,t)}let E=!1;i.version===g.__version?g.needsLights&&g.lightsStateVersion!==v.state.version||g.outputColorSpace!==s||r.isBatchedMesh&&!1===g.batching?E=!0:r.isBatchedMesh||!0!==g.batching?r.isBatchedMesh&&!0===g.batchingColor&&null===r.colorTexture||r.isBatchedMesh&&!1===g.batchingColor&&null!==r.colorTexture||r.isInstancedMesh&&!1===g.instancing?E=!0:r.isInstancedMesh||!0!==g.instancing?r.isSkinnedMesh&&!1===g.skinning?E=!0:r.isSkinnedMesh||!0!==g.skinning?r.isInstancedMesh&&!0===g.instancingColor&&null===r.instanceColor||r.isInstancedMesh&&!1===g.instancingColor&&null!==r.instanceColor||r.isInstancedMesh&&!0===g.instancingMorph&&null===r.morphTexture||r.isInstancedMesh&&!1===g.instancingMorph&&null!==r.morphTexture||g.envMap!==l||!0===i.fog&&g.fog!==a?E=!0:void 0===g.numClippingPlanes||g.numClippingPlanes===Ae.numPlanes&&g.numIntersection===Ae.numIntersection?(g.vertexAlphas!==c||g.vertexTangents!==d||g.morphTargets!==u||g.morphNormals!==f||g.morphColors!==p||g.toneMapping!==m||g.morphTargetsCount!==_)&&(E=!0):E=!0:E=!0:E=!0:E=!0:(E=!0,g.__version=i.version);let S=g.currentProgram;!0===E&&(S=Qe(i,t,r));let T=!1,M=!1,x=!1;const A=S.getUniforms(),b=g.uniforms;de.useProgram(S.program)&&(T=!0,M=!0,x=!0);i.id!==y&&(y=i.id,M=!0);if(T||N!==e){de.buffers.depth.getReversed()?(te.copy(e.projectionMatrix),An(te),bn(te),A.setValue(Ie,"projectionMatrix",te)):A.setValue(Ie,"projectionMatrix",e.projectionMatrix),A.setValue(Ie,"viewMatrix",e.matrixWorldInverse);const t=A.map.cameraPosition;void 0!==t&&t.setValue(Ie,ie.setFromMatrixPosition(e.matrixWorld)),ce.logarithmicDepthBuffer&&A.setValue(Ie,"logDepthBufFC",2/(Math.log(e.far+1)/Math.LN2)),(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial)&&A.setValue(Ie,"isOrthographic",!0===e.isOrthographicCamera),N!==e&&(N=e,M=!0,x=!0)}if(r.isSkinnedMesh){A.setOptional(Ie,r,"bindMatrix"),A.setOptional(Ie,r,"bindMatrixInverse");const e=r.skeleton;e&&(null===e.boneTexture&&e.computeBoneTexture(),A.setValue(Ie,"boneTexture",e.boneTexture,pe))}r.isBatchedMesh&&(A.setOptional(Ie,r,"batchingTexture"),A.setValue(Ie,"batchingTexture",r._matricesTexture,pe),A.setOptional(Ie,r,"batchingIdTexture"),A.setValue(Ie,"batchingIdTexture",r._indirectTexture,pe),A.setOptional(Ie,r,"batchingColorTexture"),null!==r._colorsTexture&&A.setValue(Ie,"batchingColorTexture",r._colorsTexture,pe));const L=n.morphAttributes;void 0===L.position&&void 0===L.normal&&void 0===L.color||Le.update(r,n,S);(M||g.receiveShadow!==r.receiveShadow)&&(g.receiveShadow=r.receiveShadow,A.setValue(Ie,"receiveShadow",r.receiveShadow));i.isMeshGouraudMaterial&&null!==i.envMap&&(b.envMap.value=l,b.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1);i.isMeshStandardMaterial&&null===i.envMap&&null!==t.environment&&(b.envMapIntensity.value=t.environmentIntensity);M&&(A.setValue(Ie,"toneMappingExposure",C.toneMappingExposure),g.needsLights&&(w=x,(P=b).ambientLightColor.needsUpdate=w,P.lightProbe.needsUpdate=w,P.directionalLights.needsUpdate=w,P.directionalLightShadows.needsUpdate=w,P.pointLights.needsUpdate=w,P.pointLightShadows.needsUpdate=w,P.spotLights.needsUpdate=w,P.spotLightShadows.needsUpdate=w,P.rectAreaLights.needsUpdate=w,P.hemisphereLights.needsUpdate=w),a&&!0===i.fog&&Me.refreshFogUniforms(b,a),Me.refreshMaterialUniforms(b,i,Y,X,R.state.transmissionRenderTarget[e.id]),gr.upload(Ie,Je(g),b,pe));var P,w;i.isShaderMaterial&&!0===i.uniformsNeedUpdate&&(gr.upload(Ie,Je(g),b,pe),i.uniformsNeedUpdate=!1);i.isSpriteMaterial&&A.setValue(Ie,"center",r.center);if(A.setValue(Ie,"modelViewMatrix",r.modelViewMatrix),A.setValue(Ie,"normalMatrix",r.normalMatrix),A.setValue(Ie,"modelMatrix",r.matrixWorld),i.isShaderMaterial||i.isRawShaderMaterial){const e=i.uniformsGroups;for(let t=0,n=e.length;t{function n(){i.forEach((function(e){fe.get(e).currentProgram.isReady()&&i.delete(e)})),0!==i.size?setTimeout(n,10):t(e)}null!==le.get("KHR_parallel_shader_compile")?n():setTimeout(n,10)}))};let ke=null;function We(){Ye.stop()}function Xe(){Ye.start()}const Ye=new Pn;function je(e,t,n,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)n=e.renderOrder;else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)R.pushLight(e),e.castShadow&&R.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||Q.intersectsSprite(e)){i&&re.setFromMatrixPosition(e.matrixWorld).applyMatrix4(ne);const t=Se.update(e),r=e.material;r.visible&&x.push(e,t,r,n,re.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||Q.intersectsObject(e))){const t=Se.update(e),r=e.material;if(i&&(void 0!==e.boundingSphere?(null===e.boundingSphere&&e.computeBoundingSphere(),re.copy(e.boundingSphere.center)):(null===t.boundingSphere&&t.computeBoundingSphere(),re.copy(t.boundingSphere.center)),re.applyMatrix4(e.matrixWorld).applyMatrix4(ne)),Array.isArray(r)){const i=t.groups;for(let a=0,o=i.length;a0&&Ze(r,t,n),a.length>0&&Ze(a,t,n),o.length>0&&Ze(o,t,n),de.buffers.depth.setTest(!0),de.buffers.depth.setMask(!0),de.buffers.color.setMask(!0),de.setPolygonOffset(!1)}function qe(e,t,n,i){if(null!==(!0===n.isScene?n.overrideMaterial:null))return;void 0===R.state.transmissionRenderTarget[i.id]&&(R.state.transmissionRenderTarget[i.id]=new I(1,1,{generateMipmaps:!0,type:le.has("EXT_color_buffer_half_float")||le.has("EXT_color_buffer_float")?S:T,minFilter:ct,samples:4,stencilBuffer:o,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:u.workingColorSpace}));const r=R.state.transmissionRenderTarget[i.id],a=i.viewport||O;r.setSize(a.z,a.w);const s=C.getRenderTarget();C.setRenderTarget(r),C.getClearColor(V),z=C.getClearAlpha(),z<1&&C.setClearColor(16777215,.5),C.clear(),oe&&Ce.render(n);const l=C.toneMapping;C.toneMapping=U;const c=i.viewport;if(void 0!==i.viewport&&(i.viewport=void 0),R.setupLightsView(i),!0===J&&Ae.setGlobalState(C.clippingPlanes,i),Ze(e,n,i),pe.updateMultisampleRenderTarget(r),pe.updateRenderTargetMipmap(r),!1===le.has("WEBGL_multisampled_render_to_texture")){let e=!1;for(let r=0,a=t.length;r0)for(let t=0,a=n.length;t0&&qe(i,r,e,t),oe&&Ce.render(e),Ke(x,e,t);null!==D&&(pe.updateMultisampleRenderTarget(D),pe.updateRenderTargetMipmap(D)),!0===e.isScene&&e.onAfterRender(C,e,t),De.resetDefaultState(),y=-1,N=null,b.pop(),b.length>0?(R=b[b.length-1],!0===J&&Ae.setGlobalState(C.clippingPlanes,R.state.camera)):R=null,A.pop(),x=A.length>0?A[A.length-1]:null},this.getActiveCubeFace=function(){return P},this.getActiveMipmapLevel=function(){return w},this.getRenderTarget=function(){return D},this.setRenderTargetTextures=function(e,t,n){fe.get(e.texture).__webglTexture=t,fe.get(e.depthTexture).__webglTexture=n;const i=fe.get(e);i.__hasExternalTextures=!0,i.__autoAllocateDepthBuffer=void 0===n,i.__autoAllocateDepthBuffer||!0===le.has("WEBGL_multisampled_render_to_texture")&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),i.__useRenderToTexture=!1)},this.setRenderTargetFramebuffer=function(e,t){const n=fe.get(e);n.__webglFramebuffer=t,n.__useDefaultFramebuffer=void 0===t},this.setRenderTarget=function(e,t=0,n=0){D=e,P=t,w=n;let i=!0,r=null,a=!1,o=!1;if(e){const s=fe.get(e);if(void 0!==s.__useDefaultFramebuffer)de.bindFramebuffer(Ie.FRAMEBUFFER,null),i=!1;else if(void 0===s.__webglFramebuffer)pe.setupRenderTarget(e);else if(s.__hasExternalTextures)pe.rebindTextures(e,fe.get(e.texture).__webglTexture,fe.get(e.depthTexture).__webglTexture);else if(e.depthBuffer){const t=e.depthTexture;if(s.__boundDepthTexture!==t){if(null!==t&&fe.has(t)&&(e.width!==t.image.width||e.height!==t.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");pe.setupDepthRenderbuffer(e)}}const l=e.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(o=!0);const c=fe.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(r=Array.isArray(c[t])?c[t][n]:c[t],a=!0):r=e.samples>0&&!1===pe.useMultisampledRTT(e)?fe.get(e).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,O.copy(e.viewport),F.copy(e.scissor),G=e.scissorTest}else O.copy(q).multiplyScalar(Y).floor(),F.copy(Z).multiplyScalar(Y).floor(),G=$;if(de.bindFramebuffer(Ie.FRAMEBUFFER,r)&&i&&de.drawBuffers(e,r),de.viewport(O),de.scissor(F),de.setScissorTest(G),a){const i=fe.get(e.texture);Ie.framebufferTexture2D(Ie.FRAMEBUFFER,Ie.COLOR_ATTACHMENT0,Ie.TEXTURE_CUBE_MAP_POSITIVE_X+t,i.__webglTexture,n)}else if(o){const i=fe.get(e.texture),r=t||0;Ie.framebufferTextureLayer(Ie.FRAMEBUFFER,Ie.COLOR_ATTACHMENT0,i.__webglTexture,n||0,r)}y=-1},this.readRenderTargetPixels=function(e,t,n,i,r,a,o){if(!e||!e.isWebGLRenderTarget)return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let s=fe.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&void 0!==o&&(s=s[o]),s){de.bindFramebuffer(Ie.FRAMEBUFFER,s);try{const o=e.texture,s=o.format,l=o.type;if(!ce.textureFormatReadable(s))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!ce.textureTypeReadable(l))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");t>=0&&t<=e.width-i&&n>=0&&n<=e.height-r&&Ie.readPixels(t,n,i,r,we.convert(s),we.convert(l),a)}finally{const e=null!==D?fe.get(D).__webglFramebuffer:null;de.bindFramebuffer(Ie.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(e,t,n,i,r,a,o){if(!e||!e.isWebGLRenderTarget)throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let s=fe.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&void 0!==o&&(s=s[o]),s){const o=e.texture,l=o.format,c=o.type;if(!ce.textureFormatReadable(l))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!ce.textureTypeReadable(c))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");if(t>=0&&t<=e.width-i&&n>=0&&n<=e.height-r){de.bindFramebuffer(Ie.FRAMEBUFFER,s);const e=Ie.createBuffer();Ie.bindBuffer(Ie.PIXEL_PACK_BUFFER,e),Ie.bufferData(Ie.PIXEL_PACK_BUFFER,a.byteLength,Ie.STREAM_READ),Ie.readPixels(t,n,i,r,we.convert(l),we.convert(c),0);const o=null!==D?fe.get(D).__webglFramebuffer:null;de.bindFramebuffer(Ie.FRAMEBUFFER,o);const d=Ie.fenceSync(Ie.SYNC_GPU_COMMANDS_COMPLETE,0);return Ie.flush(),await Cn(Ie,d,4),Ie.bindBuffer(Ie.PIXEL_PACK_BUFFER,e),Ie.getBufferSubData(Ie.PIXEL_PACK_BUFFER,0,a),Ie.deleteBuffer(e),Ie.deleteSync(d),a}throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(e,t=null,n=0){!0!==e.isTexture&&(H("WebGLRenderer: copyFramebufferToTexture function signature has changed."),t=arguments[0]||null,e=arguments[1]);const i=Math.pow(2,-n),r=Math.floor(e.image.width*i),a=Math.floor(e.image.height*i),o=null!==t?t.x:0,s=null!==t?t.y:0;pe.setTexture2D(e,0),Ie.copyTexSubImage2D(Ie.TEXTURE_2D,n,0,0,o,s,r,a),de.unbindTexture()};const tt=Ie.createFramebuffer(),nt=Ie.createFramebuffer();this.copyTextureToTexture=function(e,t,n=null,i=null,r=0,a=null){let o,s,l,c,d,u,f,p,m;!0!==e.isTexture&&(H("WebGLRenderer: copyTextureToTexture function signature has changed."),i=arguments[0]||null,e=arguments[1],t=arguments[2],a=arguments[3]||0,n=null),null===a&&(0!==r?(H("WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels."),a=r,r=0):a=0);const h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(null!==n)o=n.max.x-n.min.x,s=n.max.y-n.min.y,l=n.isBox3?n.max.z-n.min.z:1,c=n.min.x,d=n.min.y,u=n.isBox3?n.min.z:0;else{const t=Math.pow(2,-r);o=Math.floor(h.width*t),s=Math.floor(h.height*t),l=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,c=0,d=0,u=0}null!==i?(f=i.x,p=i.y,m=i.z):(f=0,p=0,m=0);const _=we.convert(t.format),g=we.convert(t.type);let v;t.isData3DTexture?(pe.setTexture3D(t,0),v=Ie.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(pe.setTexture2DArray(t,0),v=Ie.TEXTURE_2D_ARRAY):(pe.setTexture2D(t,0),v=Ie.TEXTURE_2D),Ie.pixelStorei(Ie.UNPACK_FLIP_Y_WEBGL,t.flipY),Ie.pixelStorei(Ie.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),Ie.pixelStorei(Ie.UNPACK_ALIGNMENT,t.unpackAlignment);const E=Ie.getParameter(Ie.UNPACK_ROW_LENGTH),S=Ie.getParameter(Ie.UNPACK_IMAGE_HEIGHT),T=Ie.getParameter(Ie.UNPACK_SKIP_PIXELS),M=Ie.getParameter(Ie.UNPACK_SKIP_ROWS),x=Ie.getParameter(Ie.UNPACK_SKIP_IMAGES);Ie.pixelStorei(Ie.UNPACK_ROW_LENGTH,h.width),Ie.pixelStorei(Ie.UNPACK_IMAGE_HEIGHT,h.height),Ie.pixelStorei(Ie.UNPACK_SKIP_PIXELS,c),Ie.pixelStorei(Ie.UNPACK_SKIP_ROWS,d),Ie.pixelStorei(Ie.UNPACK_SKIP_IMAGES,u);const R=e.isDataArrayTexture||e.isData3DTexture,A=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){const n=fe.get(e),i=fe.get(t),h=fe.get(n.__renderTarget),_=fe.get(i.__renderTarget);de.bindFramebuffer(Ie.READ_FRAMEBUFFER,h.__webglFramebuffer),de.bindFramebuffer(Ie.DRAW_FRAMEBUFFER,_.__webglFramebuffer);for(let n=0;n 0 ) { + + const { width, height } = renderObject.context; + + data.bufferWidth = width; + data.bufferHeight = height; + + } + + this.renderObjects.set( renderObject, data ); + + } + + return data; + + } + + getAttributesData( attributes ) { + + const attributesData = {}; + + for ( const name in attributes ) { + + const attribute = attributes[ name ]; + + attributesData[ name ] = { + version: attribute.version + }; + + } + + return attributesData; + + } + + containsNode( builder ) { + + const material = builder.material; + + for ( const property in material ) { + + if ( material[ property ] && material[ property ].isNode ) + return true; + + } + + if ( builder.renderer.nodes.modelViewMatrix !== null || builder.renderer.nodes.modelNormalViewMatrix !== null ) + return true; + + return false; + + } + + getMaterialData( material ) { + + const data = {}; + + for ( const property of this.refreshUniforms ) { + + const value = material[ property ]; + + if ( value === null || value === undefined ) continue; + + if ( typeof value === 'object' && value.clone !== undefined ) { + + if ( value.isTexture === true ) { + + data[ property ] = { id: value.id, version: value.version }; + + } else { + + data[ property ] = value.clone(); + + } + + } else { + + data[ property ] = value; + + } + + } + + return data; + + } + + equals( renderObject ) { + + const { object, material, geometry } = renderObject; + + const renderObjectData = this.getRenderObjectData( renderObject ); + + // world matrix + + if ( renderObjectData.worldMatrix.equals( object.matrixWorld ) !== true ) { + + renderObjectData.worldMatrix.copy( object.matrixWorld ); + + return false; + + } + + // material + + const materialData = renderObjectData.material; + + for ( const property in materialData ) { + + const value = materialData[ property ]; + const mtlValue = material[ property ]; + + if ( value.equals !== undefined ) { + + if ( value.equals( mtlValue ) === false ) { + + value.copy( mtlValue ); + + return false; + + } + + } else if ( mtlValue.isTexture === true ) { + + if ( value.id !== mtlValue.id || value.version !== mtlValue.version ) { + + value.id = mtlValue.id; + value.version = mtlValue.version; + + return false; + + } + + } else if ( value !== mtlValue ) { + + materialData[ property ] = mtlValue; + + return false; + + } + + } + + if ( materialData.transmission > 0 ) { + + const { width, height } = renderObject.context; + + if ( renderObjectData.bufferWidth !== width || renderObjectData.bufferHeight !== height ) { + + renderObjectData.bufferWidth = width; + renderObjectData.bufferHeight = height; + + return false; + + } + + } + + // geometry + + const storedGeometryData = renderObjectData.geometry; + const attributes = geometry.attributes; + const storedAttributes = storedGeometryData.attributes; + + const storedAttributeNames = Object.keys( storedAttributes ); + const currentAttributeNames = Object.keys( attributes ); + + if ( storedAttributeNames.length !== currentAttributeNames.length ) { + + renderObjectData.geometry.attributes = this.getAttributesData( attributes ); + return false; + + } + + // compare each attribute + + for ( const name of storedAttributeNames ) { + + const storedAttributeData = storedAttributes[ name ]; + const attribute = attributes[ name ]; + + if ( attribute === undefined ) { + + // attribute was removed + delete storedAttributes[ name ]; + return false; + + } + + if ( storedAttributeData.version !== attribute.version ) { + + storedAttributeData.version = attribute.version; + return false; + + } + + } + + // check index + + const index = geometry.index; + const storedIndexVersion = storedGeometryData.indexVersion; + const currentIndexVersion = index ? index.version : null; + + if ( storedIndexVersion !== currentIndexVersion ) { + + storedGeometryData.indexVersion = currentIndexVersion; + return false; + + } + + // check drawRange + + if ( storedGeometryData.drawRange.start !== geometry.drawRange.start || storedGeometryData.drawRange.count !== geometry.drawRange.count ) { + + storedGeometryData.drawRange.start = geometry.drawRange.start; + storedGeometryData.drawRange.count = geometry.drawRange.count; + return false; + + } + + // morph targets + + if ( renderObjectData.morphTargetInfluences ) { + + let morphChanged = false; + + for ( let i = 0; i < renderObjectData.morphTargetInfluences.length; i ++ ) { + + if ( renderObjectData.morphTargetInfluences[ i ] !== object.morphTargetInfluences[ i ] ) { + + morphChanged = true; + + } + + } + + if ( morphChanged ) return true; + + } + + // center + + if ( renderObjectData.center ) { + + if ( renderObjectData.center.equals( object.center ) === false ) { + + renderObjectData.center.copy( object.center ); + + return true; + + } + + } + + // bundle + + if ( renderObject.bundle !== null ) { + + renderObjectData.version = renderObject.bundle.version; + + } + + return true; + + } + + needsRefresh( renderObject, nodeFrame ) { + + if ( this.hasNode || this.hasAnimation || this.firstInitialization( renderObject ) ) + return true; + + const { renderId } = nodeFrame; + + if ( this.renderId !== renderId ) { + + this.renderId = renderId; + + return true; + + } + + const isStatic = renderObject.object.static === true; + const isBundle = renderObject.bundle !== null && renderObject.bundle.static === true && this.getRenderObjectData( renderObject ).version === renderObject.bundle.version; + + if ( isStatic || isBundle ) + return false; + + const notEqual = this.equals( renderObject ) !== true; + + return notEqual; + + } + +} + +// cyrb53 (c) 2018 bryc (github.com/bryc). License: Public domain. Attribution appreciated. +// A fast and simple 64-bit (or 53-bit) string hash function with decent collision resistance. +// Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity. +// See https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript/52171480#52171480 +// https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js +function cyrb53( value, seed = 0 ) { + + let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed; + + if ( value instanceof Array ) { + + for ( let i = 0, val; i < value.length; i ++ ) { + + val = value[ i ]; + h1 = Math.imul( h1 ^ val, 2654435761 ); + h2 = Math.imul( h2 ^ val, 1597334677 ); + + } + + } else { + + for ( let i = 0, ch; i < value.length; i ++ ) { + + ch = value.charCodeAt( i ); + h1 = Math.imul( h1 ^ ch, 2654435761 ); + h2 = Math.imul( h2 ^ ch, 1597334677 ); + + } + + } + + h1 = Math.imul( h1 ^ ( h1 >>> 16 ), 2246822507 ); + h1 ^= Math.imul( h2 ^ ( h2 >>> 13 ), 3266489909 ); + h2 = Math.imul( h2 ^ ( h2 >>> 16 ), 2246822507 ); + h2 ^= Math.imul( h1 ^ ( h1 >>> 13 ), 3266489909 ); + + return 4294967296 * ( 2097151 & h2 ) + ( h1 >>> 0 ); + +} + +const hashString = ( str ) => cyrb53( str ); +const hashArray = ( array ) => cyrb53( array ); +const hash$1 = ( ...params ) => cyrb53( params ); + +function getCacheKey$1( object, force = false ) { + + const values = []; + + if ( object.isNode === true ) { + + values.push( object.id ); + object = object.getSelf(); + + } + + for ( const { property, childNode } of getNodeChildren( object ) ) { + + values.push( values, cyrb53( property.slice( 0, - 4 ) ), childNode.getCacheKey( force ) ); + + } + + return cyrb53( values ); + +} + +function* getNodeChildren( node, toJSON = false ) { + + for ( const property in node ) { + + // Ignore private properties. + if ( property.startsWith( '_' ) === true ) continue; + + const object = node[ property ]; + + if ( Array.isArray( object ) === true ) { + + for ( let i = 0; i < object.length; i ++ ) { + + const child = object[ i ]; + + if ( child && ( child.isNode === true || toJSON && typeof child.toJSON === 'function' ) ) { + + yield { property, index: i, childNode: child }; + + } + + } + + } else if ( object && object.isNode === true ) { + + yield { property, childNode: object }; + + } else if ( typeof object === 'object' ) { + + for ( const subProperty in object ) { + + const child = object[ subProperty ]; + + if ( child && ( child.isNode === true || toJSON && typeof child.toJSON === 'function' ) ) { + + yield { property, index: subProperty, childNode: child }; + + } + + } + + } + + } + +} + +const typeFromLength = /*@__PURE__*/ new Map( [ + [ 1, 'float' ], + [ 2, 'vec2' ], + [ 3, 'vec3' ], + [ 4, 'vec4' ], + [ 9, 'mat3' ], + [ 16, 'mat4' ] +] ); + +function getTypeFromLength( length ) { + + return typeFromLength.get( length ); + +} + +function getLengthFromType( type ) { + + if ( /float|int|uint/.test( type ) ) return 1; + if ( /vec2/.test( type ) ) return 2; + if ( /vec3/.test( type ) ) return 3; + if ( /vec4/.test( type ) ) return 4; + if ( /mat3/.test( type ) ) return 9; + if ( /mat4/.test( type ) ) return 16; + + console.error( 'THREE.TSL: Unsupported type:', type ); + +} + +function getValueType( value ) { + + if ( value === undefined || value === null ) return null; + + const typeOf = typeof value; + + if ( value.isNode === true ) { + + return 'node'; + + } else if ( typeOf === 'number' ) { + + return 'float'; + + } else if ( typeOf === 'boolean' ) { + + return 'bool'; + + } else if ( typeOf === 'string' ) { + + return 'string'; + + } else if ( typeOf === 'function' ) { + + return 'shader'; + + } else if ( value.isVector2 === true ) { + + return 'vec2'; + + } else if ( value.isVector3 === true ) { + + return 'vec3'; + + } else if ( value.isVector4 === true ) { + + return 'vec4'; + + } else if ( value.isMatrix3 === true ) { + + return 'mat3'; + + } else if ( value.isMatrix4 === true ) { + + return 'mat4'; + + } else if ( value.isColor === true ) { + + return 'color'; + + } else if ( value instanceof ArrayBuffer ) { + + return 'ArrayBuffer'; + + } + + return null; + +} + +function getValueFromType( type, ...params ) { + + const last4 = type ? type.slice( - 4 ) : undefined; + + if ( params.length === 1 ) { // ensure same behaviour as in NodeBuilder.format() + + if ( last4 === 'vec2' ) params = [ params[ 0 ], params[ 0 ] ]; + else if ( last4 === 'vec3' ) params = [ params[ 0 ], params[ 0 ], params[ 0 ] ]; + else if ( last4 === 'vec4' ) params = [ params[ 0 ], params[ 0 ], params[ 0 ], params[ 0 ] ]; + + } + + if ( type === 'color' ) { + + return new Color( ...params ); + + } else if ( last4 === 'vec2' ) { + + return new Vector2( ...params ); + + } else if ( last4 === 'vec3' ) { + + return new Vector3( ...params ); + + } else if ( last4 === 'vec4' ) { + + return new Vector4( ...params ); + + } else if ( last4 === 'mat3' ) { + + return new Matrix3( ...params ); + + } else if ( last4 === 'mat4' ) { + + return new Matrix4( ...params ); + + } else if ( type === 'bool' ) { + + return params[ 0 ] || false; + + } else if ( ( type === 'float' ) || ( type === 'int' ) || ( type === 'uint' ) ) { + + return params[ 0 ] || 0; + + } else if ( type === 'string' ) { + + return params[ 0 ] || ''; + + } else if ( type === 'ArrayBuffer' ) { + + return base64ToArrayBuffer( params[ 0 ] ); + + } + + return null; + +} + +function arrayBufferToBase64( arrayBuffer ) { + + let chars = ''; + + const array = new Uint8Array( arrayBuffer ); + + for ( let i = 0; i < array.length; i ++ ) { + + chars += String.fromCharCode( array[ i ] ); + + } + + return btoa( chars ); + +} + +function base64ToArrayBuffer( base64 ) { + + return Uint8Array.from( atob( base64 ), c => c.charCodeAt( 0 ) ).buffer; + +} + +var NodeUtils = /*#__PURE__*/Object.freeze({ + __proto__: null, + arrayBufferToBase64: arrayBufferToBase64, + base64ToArrayBuffer: base64ToArrayBuffer, + getCacheKey: getCacheKey$1, + getLengthFromType: getLengthFromType, + getNodeChildren: getNodeChildren, + getTypeFromLength: getTypeFromLength, + getValueFromType: getValueFromType, + getValueType: getValueType, + hash: hash$1, + hashArray: hashArray, + hashString: hashString +}); + +const NodeShaderStage = { + VERTEX: 'vertex', + FRAGMENT: 'fragment' +}; + +const NodeUpdateType = { + NONE: 'none', + FRAME: 'frame', + RENDER: 'render', + OBJECT: 'object' +}; + +const NodeType = { + BOOLEAN: 'bool', + INTEGER: 'int', + FLOAT: 'float', + VECTOR2: 'vec2', + VECTOR3: 'vec3', + VECTOR4: 'vec4', + MATRIX2: 'mat2', + MATRIX3: 'mat3', + MATRIX4: 'mat4' +}; + +const NodeAccess = { + READ_ONLY: 'readOnly', + WRITE_ONLY: 'writeOnly', + READ_WRITE: 'readWrite', +}; + +const defaultShaderStages = [ 'fragment', 'vertex' ]; +const defaultBuildStages = [ 'setup', 'analyze', 'generate' ]; +const shaderStages = [ ...defaultShaderStages, 'compute' ]; +const vectorComponents = [ 'x', 'y', 'z', 'w' ]; + +let _nodeId = 0; + +class Node extends EventDispatcher { + + static get type() { + + return 'Node'; + + } + + constructor( nodeType = null ) { + + super(); + + this.nodeType = nodeType; + + this.updateType = NodeUpdateType.NONE; + this.updateBeforeType = NodeUpdateType.NONE; + this.updateAfterType = NodeUpdateType.NONE; + + this.uuid = MathUtils.generateUUID(); + + this.version = 0; + + this._cacheKey = null; + this._cacheKeyVersion = 0; + + this.global = false; + + this.isNode = true; + + Object.defineProperty( this, 'id', { value: _nodeId ++ } ); + + } + + set needsUpdate( value ) { + + if ( value === true ) { + + this.version ++; + + } + + } + + get type() { + + return this.constructor.type; + + } + + onUpdate( callback, updateType ) { + + this.updateType = updateType; + this.update = callback.bind( this.getSelf() ); + + return this; + + } + + onFrameUpdate( callback ) { + + return this.onUpdate( callback, NodeUpdateType.FRAME ); + + } + + onRenderUpdate( callback ) { + + return this.onUpdate( callback, NodeUpdateType.RENDER ); + + } + + onObjectUpdate( callback ) { + + return this.onUpdate( callback, NodeUpdateType.OBJECT ); + + } + + onReference( callback ) { + + this.updateReference = callback.bind( this.getSelf() ); + + return this; + + } + + getSelf() { + + // Returns non-node object. + + return this.self || this; + + } + + updateReference( /*state*/ ) { + + return this; + + } + + isGlobal( /*builder*/ ) { + + return this.global; + + } + + * getChildren() { + + for ( const { childNode } of getNodeChildren( this ) ) { + + yield childNode; + + } + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + traverse( callback ) { + + callback( this ); + + for ( const childNode of this.getChildren() ) { + + childNode.traverse( callback ); + + } + + } + + getCacheKey( force = false ) { + + force = force || this.version !== this._cacheKeyVersion; + + if ( force === true || this._cacheKey === null ) { + + this._cacheKey = getCacheKey$1( this, force ); + this._cacheKeyVersion = this.version; + + } + + return this._cacheKey; + + } + + getScope() { + + return this; + + } + + getHash( /*builder*/ ) { + + return this.uuid; + + } + + getUpdateType() { + + return this.updateType; + + } + + getUpdateBeforeType() { + + return this.updateBeforeType; + + } + + getUpdateAfterType() { + + return this.updateAfterType; + + } + + getElementType( builder ) { + + const type = this.getNodeType( builder ); + const elementType = builder.getElementType( type ); + + return elementType; + + } + + getNodeType( builder ) { + + const nodeProperties = builder.getNodeProperties( this ); + + if ( nodeProperties.outputNode ) { + + return nodeProperties.outputNode.getNodeType( builder ); + + } + + return this.nodeType; + + } + + getShared( builder ) { + + const hash = this.getHash( builder ); + const nodeFromHash = builder.getNodeFromHash( hash ); + + return nodeFromHash || this; + + } + + setup( builder ) { + + const nodeProperties = builder.getNodeProperties( this ); + + let index = 0; + + for ( const childNode of this.getChildren() ) { + + nodeProperties[ 'node' + index ++ ] = childNode; + + } + + // return a outputNode if exists + return null; + + } + + analyze( builder ) { + + const usageCount = builder.increaseUsage( this ); + + if ( usageCount === 1 ) { + + // node flow children + + const nodeProperties = builder.getNodeProperties( this ); + + for ( const childNode of Object.values( nodeProperties ) ) { + + if ( childNode && childNode.isNode === true ) { + + childNode.build( builder ); + + } + + } + + } + + } + + generate( builder, output ) { + + const { outputNode } = builder.getNodeProperties( this ); + + if ( outputNode && outputNode.isNode === true ) { + + return outputNode.build( builder, output ); + + } + + } + + updateBefore( /*frame*/ ) { + + console.warn( 'Abstract function.' ); + + } + + updateAfter( /*frame*/ ) { + + console.warn( 'Abstract function.' ); + + } + + update( /*frame*/ ) { + + console.warn( 'Abstract function.' ); + + } + + build( builder, output = null ) { + + const refNode = this.getShared( builder ); + + if ( this !== refNode ) { + + return refNode.build( builder, output ); + + } + + builder.addNode( this ); + builder.addChain( this ); + + /* Build stages expected results: + - "setup" -> Node + - "analyze" -> null + - "generate" -> String + */ + let result = null; + + const buildStage = builder.getBuildStage(); + + if ( buildStage === 'setup' ) { + + this.updateReference( builder ); + + const properties = builder.getNodeProperties( this ); + + if ( properties.initialized !== true ) { + + const stackNodesBeforeSetup = builder.stack.nodes.length; + + properties.initialized = true; + properties.outputNode = this.setup( builder ); + + if ( properties.outputNode !== null && builder.stack.nodes.length !== stackNodesBeforeSetup ) ; + + for ( const childNode of Object.values( properties ) ) { + + if ( childNode && childNode.isNode === true ) { + + childNode.build( builder ); + + } + + } + + } + + } else if ( buildStage === 'analyze' ) { + + this.analyze( builder ); + + } else if ( buildStage === 'generate' ) { + + const isGenerateOnce = this.generate.length === 1; + + if ( isGenerateOnce ) { + + const type = this.getNodeType( builder ); + const nodeData = builder.getDataFromNode( this ); + + result = nodeData.snippet; + + if ( result === undefined ) { + + result = this.generate( builder ) || ''; + + nodeData.snippet = result; + + } else if ( nodeData.flowCodes !== undefined && builder.context.nodeBlock !== undefined ) { + + builder.addFlowCodeHierarchy( this, builder.context.nodeBlock ); + + } + + result = builder.format( result, type, output ); + + } else { + + result = this.generate( builder, output ) || ''; + + } + + } + + builder.removeChain( this ); + builder.addSequentialNode( this ); + + return result; + + } + + getSerializeChildren() { + + return getNodeChildren( this ); + + } + + serialize( json ) { + + const nodeChildren = this.getSerializeChildren(); + + const inputNodes = {}; + + for ( const { property, index, childNode } of nodeChildren ) { + + if ( index !== undefined ) { + + if ( inputNodes[ property ] === undefined ) { + + inputNodes[ property ] = Number.isInteger( index ) ? [] : {}; + + } + + inputNodes[ property ][ index ] = childNode.toJSON( json.meta ).uuid; + + } else { + + inputNodes[ property ] = childNode.toJSON( json.meta ).uuid; + + } + + } + + if ( Object.keys( inputNodes ).length > 0 ) { + + json.inputNodes = inputNodes; + + } + + } + + deserialize( json ) { + + if ( json.inputNodes !== undefined ) { + + const nodes = json.meta.nodes; + + for ( const property in json.inputNodes ) { + + if ( Array.isArray( json.inputNodes[ property ] ) ) { + + const inputArray = []; + + for ( const uuid of json.inputNodes[ property ] ) { + + inputArray.push( nodes[ uuid ] ); + + } + + this[ property ] = inputArray; + + } else if ( typeof json.inputNodes[ property ] === 'object' ) { + + const inputObject = {}; + + for ( const subProperty in json.inputNodes[ property ] ) { + + const uuid = json.inputNodes[ property ][ subProperty ]; + + inputObject[ subProperty ] = nodes[ uuid ]; + + } + + this[ property ] = inputObject; + + } else { + + const uuid = json.inputNodes[ property ]; + + this[ property ] = nodes[ uuid ]; + + } + + } + + } + + } + + toJSON( meta ) { + + const { uuid, type } = this; + const isRoot = ( meta === undefined || typeof meta === 'string' ); + + if ( isRoot ) { + + meta = { + textures: {}, + images: {}, + nodes: {} + }; + + } + + // serialize + + let data = meta.nodes[ uuid ]; + + if ( data === undefined ) { + + data = { + uuid, + type, + meta, + metadata: { + version: 4.6, + type: 'Node', + generator: 'Node.toJSON' + } + }; + + if ( isRoot !== true ) meta.nodes[ data.uuid ] = data; + + this.serialize( data ); + + delete data.meta; + + } + + // TODO: Copied from Object3D.toJSON + + function extractFromCache( cache ) { + + const values = []; + + for ( const key in cache ) { + + const data = cache[ key ]; + delete data.metadata; + values.push( data ); + + } + + return values; + + } + + if ( isRoot ) { + + const textures = extractFromCache( meta.textures ); + const images = extractFromCache( meta.images ); + const nodes = extractFromCache( meta.nodes ); + + if ( textures.length > 0 ) data.textures = textures; + if ( images.length > 0 ) data.images = images; + if ( nodes.length > 0 ) data.nodes = nodes; + + } + + return data; + + } + +} + +class ArrayElementNode extends Node { + + static get type() { + + return 'ArrayElementNode'; + + } // @TODO: If extending from TempNode it breaks webgpu_compute + + constructor( node, indexNode ) { + + super(); + + this.node = node; + this.indexNode = indexNode; + + this.isArrayElementNode = true; + + } + + getNodeType( builder ) { + + return this.node.getElementType( builder ); + + } + + generate( builder ) { + + const nodeSnippet = this.node.build( builder ); + const indexSnippet = this.indexNode.build( builder, 'uint' ); + + return `${nodeSnippet}[ ${indexSnippet} ]`; + + } + +} + +class ConvertNode extends Node { + + static get type() { + + return 'ConvertNode'; + + } + + constructor( node, convertTo ) { + + super(); + + this.node = node; + this.convertTo = convertTo; + + } + + getNodeType( builder ) { + + const requestType = this.node.getNodeType( builder ); + + let convertTo = null; + + for ( const overloadingType of this.convertTo.split( '|' ) ) { + + if ( convertTo === null || builder.getTypeLength( requestType ) === builder.getTypeLength( overloadingType ) ) { + + convertTo = overloadingType; + + } + + } + + return convertTo; + + } + + serialize( data ) { + + super.serialize( data ); + + data.convertTo = this.convertTo; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.convertTo = data.convertTo; + + } + + generate( builder, output ) { + + const node = this.node; + const type = this.getNodeType( builder ); + + const snippet = node.build( builder, type ); + + return builder.format( snippet, type, output ); + + } + +} + +class TempNode extends Node { + + static get type() { + + return 'TempNode'; + + } + + constructor( type ) { + + super( type ); + + this.isTempNode = true; + + } + + hasDependencies( builder ) { + + return builder.getDataFromNode( this ).usageCount > 1; + + } + + build( builder, output ) { + + const buildStage = builder.getBuildStage(); + + if ( buildStage === 'generate' ) { + + const type = builder.getVectorType( this.getNodeType( builder, output ) ); + const nodeData = builder.getDataFromNode( this ); + + if ( nodeData.propertyName !== undefined ) { + + return builder.format( nodeData.propertyName, type, output ); + + } else if ( type !== 'void' && output !== 'void' && this.hasDependencies( builder ) ) { + + const snippet = super.build( builder, type ); + + const nodeVar = builder.getVarFromNode( this, null, type ); + const propertyName = builder.getPropertyName( nodeVar ); + + builder.addLineFlowCode( `${propertyName} = ${snippet}`, this ); + + nodeData.snippet = snippet; + nodeData.propertyName = propertyName; + + return builder.format( nodeData.propertyName, type, output ); + + } + + } + + return super.build( builder, output ); + + } + +} + +class JoinNode extends TempNode { + + static get type() { + + return 'JoinNode'; + + } + + constructor( nodes = [], nodeType = null ) { + + super( nodeType ); + + this.nodes = nodes; + + } + + getNodeType( builder ) { + + if ( this.nodeType !== null ) { + + return builder.getVectorType( this.nodeType ); + + } + + return builder.getTypeFromLength( this.nodes.reduce( ( count, cur ) => count + builder.getTypeLength( cur.getNodeType( builder ) ), 0 ) ); + + } + + generate( builder, output ) { + + const type = this.getNodeType( builder ); + const nodes = this.nodes; + + const primitiveType = builder.getComponentType( type ); + + const snippetValues = []; + + for ( const input of nodes ) { + + let inputSnippet = input.build( builder ); + + const inputPrimitiveType = builder.getComponentType( input.getNodeType( builder ) ); + + if ( inputPrimitiveType !== primitiveType ) { + + inputSnippet = builder.format( inputSnippet, inputPrimitiveType, primitiveType ); + + } + + snippetValues.push( inputSnippet ); + + } + + const snippet = `${ builder.getType( type ) }( ${ snippetValues.join( ', ' ) } )`; + + return builder.format( snippet, type, output ); + + } + +} + +const stringVectorComponents = vectorComponents.join( '' ); + +class SplitNode extends Node { + + static get type() { + + return 'SplitNode'; + + } + + constructor( node, components = 'x' ) { + + super(); + + this.node = node; + this.components = components; + + this.isSplitNode = true; + + } + + getVectorLength() { + + let vectorLength = this.components.length; + + for ( const c of this.components ) { + + vectorLength = Math.max( vectorComponents.indexOf( c ) + 1, vectorLength ); + + } + + return vectorLength; + + } + + getComponentType( builder ) { + + return builder.getComponentType( this.node.getNodeType( builder ) ); + + } + + getNodeType( builder ) { + + return builder.getTypeFromLength( this.components.length, this.getComponentType( builder ) ); + + } + + generate( builder, output ) { + + const node = this.node; + const nodeTypeLength = builder.getTypeLength( node.getNodeType( builder ) ); + + let snippet = null; + + if ( nodeTypeLength > 1 ) { + + let type = null; + + const componentsLength = this.getVectorLength(); + + if ( componentsLength >= nodeTypeLength ) { + + // needed expand the input node + + type = builder.getTypeFromLength( this.getVectorLength(), this.getComponentType( builder ) ); + + } + + const nodeSnippet = node.build( builder, type ); + + if ( this.components.length === nodeTypeLength && this.components === stringVectorComponents.slice( 0, this.components.length ) ) { + + // unnecessary swizzle + + snippet = builder.format( nodeSnippet, type, output ); + + } else { + + snippet = builder.format( `${nodeSnippet}.${this.components}`, this.getNodeType( builder ), output ); + + } + + } else { + + // ignore .components if .node returns float/integer + + snippet = node.build( builder, output ); + + } + + return snippet; + + } + + serialize( data ) { + + super.serialize( data ); + + data.components = this.components; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.components = data.components; + + } + +} + +class SetNode extends TempNode { + + static get type() { + + return 'SetNode'; + + } + + constructor( sourceNode, components, targetNode ) { + + super(); + + this.sourceNode = sourceNode; + this.components = components; + this.targetNode = targetNode; + + } + + getNodeType( builder ) { + + return this.sourceNode.getNodeType( builder ); + + } + + generate( builder ) { + + const { sourceNode, components, targetNode } = this; + + const sourceType = this.getNodeType( builder ); + const targetType = builder.getTypeFromLength( components.length, targetNode.getNodeType( builder ) ); + + const targetSnippet = targetNode.build( builder, targetType ); + const sourceSnippet = sourceNode.build( builder, sourceType ); + + const length = builder.getTypeLength( sourceType ); + const snippetValues = []; + + for ( let i = 0; i < length; i ++ ) { + + const component = vectorComponents[ i ]; + + if ( component === components[ 0 ] ) { + + snippetValues.push( targetSnippet ); + + i += components.length - 1; + + } else { + + snippetValues.push( sourceSnippet + '.' + component ); + + } + + } + + return `${ builder.getType( sourceType ) }( ${ snippetValues.join( ', ' ) } )`; + + } + +} + +class FlipNode extends TempNode { + + static get type() { + + return 'FlipNode'; + + } + + constructor( sourceNode, components ) { + + super(); + + this.sourceNode = sourceNode; + this.components = components; + + } + + getNodeType( builder ) { + + return this.sourceNode.getNodeType( builder ); + + } + + generate( builder ) { + + const { components, sourceNode } = this; + + const sourceType = this.getNodeType( builder ); + const sourceSnippet = sourceNode.build( builder ); + + const sourceCache = builder.getVarFromNode( this ); + const sourceProperty = builder.getPropertyName( sourceCache ); + + builder.addLineFlowCode( sourceProperty + ' = ' + sourceSnippet, this ); + + const length = builder.getTypeLength( sourceType ); + const snippetValues = []; + + let componentIndex = 0; + + for ( let i = 0; i < length; i ++ ) { + + const component = vectorComponents[ i ]; + + if ( component === components[ componentIndex ] ) { + + snippetValues.push( '1.0 - ' + ( sourceProperty + '.' + component ) ); + + componentIndex ++; + + } else { + + snippetValues.push( sourceProperty + '.' + component ); + + } + + } + + return `${ builder.getType( sourceType ) }( ${ snippetValues.join( ', ' ) } )`; + + } + +} + +class InputNode extends Node { + + static get type() { + + return 'InputNode'; + + } + + constructor( value, nodeType = null ) { + + super( nodeType ); + + this.isInputNode = true; + + this.value = value; + this.precision = null; + + } + + getNodeType( /*builder*/ ) { + + if ( this.nodeType === null ) { + + return getValueType( this.value ); + + } + + return this.nodeType; + + } + + getInputType( builder ) { + + return this.getNodeType( builder ); + + } + + setPrecision( precision ) { + + this.precision = precision; + + return this; + + } + + serialize( data ) { + + super.serialize( data ); + + data.value = this.value; + + if ( this.value && this.value.toArray ) data.value = this.value.toArray(); + + data.valueType = getValueType( this.value ); + data.nodeType = this.nodeType; + + if ( data.valueType === 'ArrayBuffer' ) data.value = arrayBufferToBase64( data.value ); + + data.precision = this.precision; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.nodeType = data.nodeType; + this.value = Array.isArray( data.value ) ? getValueFromType( data.valueType, ...data.value ) : data.value; + + this.precision = data.precision || null; + + if ( this.value && this.value.fromArray ) this.value = this.value.fromArray( data.value ); + + } + + generate( /*builder, output*/ ) { + + console.warn( 'Abstract function.' ); + + } + +} + +class ConstNode extends InputNode { + + static get type() { + + return 'ConstNode'; + + } + + constructor( value, nodeType = null ) { + + super( value, nodeType ); + + this.isConstNode = true; + + } + + generateConst( builder ) { + + return builder.generateConst( this.getNodeType( builder ), this.value ); + + } + + generate( builder, output ) { + + const type = this.getNodeType( builder ); + + return builder.format( this.generateConst( builder ), type, output ); + + } + +} + +// + +let currentStack = null; + +const NodeElements = new Map(); + +function addMethodChaining( name, nodeElement ) { + + if ( NodeElements.has( name ) ) { + + console.warn( `Redefinition of method chaining ${ name }` ); + return; + + } + + if ( typeof nodeElement !== 'function' ) throw new Error( `Node element ${ name } is not a function` ); + + NodeElements.set( name, nodeElement ); + +} + +const parseSwizzle = ( props ) => props.replace( /r|s/g, 'x' ).replace( /g|t/g, 'y' ).replace( /b|p/g, 'z' ).replace( /a|q/g, 'w' ); +const parseSwizzleAndSort = ( props ) => parseSwizzle( props ).split( '' ).sort().join( '' ); + +const shaderNodeHandler = { + + setup( NodeClosure, params ) { + + const inputs = params.shift(); + + return NodeClosure( nodeObjects( inputs ), ...params ); + + }, + + get( node, prop, nodeObj ) { + + if ( typeof prop === 'string' && node[ prop ] === undefined ) { + + if ( node.isStackNode !== true && prop === 'assign' ) { + + return ( ...params ) => { + + currentStack.assign( nodeObj, ...params ); + + return nodeObj; + + }; + + } else if ( NodeElements.has( prop ) ) { + + const nodeElement = NodeElements.get( prop ); + + return node.isStackNode ? ( ...params ) => nodeObj.add( nodeElement( ...params ) ) : ( ...params ) => nodeElement( nodeObj, ...params ); + + } else if ( prop === 'self' ) { + + return node; + + } else if ( prop.endsWith( 'Assign' ) && NodeElements.has( prop.slice( 0, prop.length - 'Assign'.length ) ) ) { + + const nodeElement = NodeElements.get( prop.slice( 0, prop.length - 'Assign'.length ) ); + + return node.isStackNode ? ( ...params ) => nodeObj.assign( params[ 0 ], nodeElement( ...params ) ) : ( ...params ) => nodeObj.assign( nodeElement( nodeObj, ...params ) ); + + } else if ( /^[xyzwrgbastpq]{1,4}$/.test( prop ) === true ) { + + // accessing properties ( swizzle ) + + prop = parseSwizzle( prop ); + + return nodeObject( new SplitNode( nodeObj, prop ) ); + + } else if ( /^set[XYZWRGBASTPQ]{1,4}$/.test( prop ) === true ) { + + // set properties ( swizzle ) and sort to xyzw sequence + + prop = parseSwizzleAndSort( prop.slice( 3 ).toLowerCase() ); + + return ( value ) => nodeObject( new SetNode( node, prop, value ) ); + + } else if ( /^flip[XYZWRGBASTPQ]{1,4}$/.test( prop ) === true ) { + + // set properties ( swizzle ) and sort to xyzw sequence + + prop = parseSwizzleAndSort( prop.slice( 4 ).toLowerCase() ); + + return () => nodeObject( new FlipNode( nodeObject( node ), prop ) ); + + } else if ( prop === 'width' || prop === 'height' || prop === 'depth' ) { + + // accessing property + + if ( prop === 'width' ) prop = 'x'; + else if ( prop === 'height' ) prop = 'y'; + else if ( prop === 'depth' ) prop = 'z'; + + return nodeObject( new SplitNode( node, prop ) ); + + } else if ( /^\d+$/.test( prop ) === true ) { + + // accessing array + + return nodeObject( new ArrayElementNode( nodeObj, new ConstNode( Number( prop ), 'uint' ) ) ); + + } + + } + + return Reflect.get( node, prop, nodeObj ); + + }, + + set( node, prop, value, nodeObj ) { + + if ( typeof prop === 'string' && node[ prop ] === undefined ) { + + // setting properties + + if ( /^[xyzwrgbastpq]{1,4}$/.test( prop ) === true || prop === 'width' || prop === 'height' || prop === 'depth' || /^\d+$/.test( prop ) === true ) { + + nodeObj[ prop ].assign( value ); + + return true; + + } + + } + + return Reflect.set( node, prop, value, nodeObj ); + + } + +}; + +const nodeObjectsCacheMap = new WeakMap(); +const nodeBuilderFunctionsCacheMap = new WeakMap(); + +const ShaderNodeObject = function ( obj, altType = null ) { + + const type = getValueType( obj ); + + if ( type === 'node' ) { + + let nodeObject = nodeObjectsCacheMap.get( obj ); + + if ( nodeObject === undefined ) { + + nodeObject = new Proxy( obj, shaderNodeHandler ); + + nodeObjectsCacheMap.set( obj, nodeObject ); + nodeObjectsCacheMap.set( nodeObject, nodeObject ); + + } + + return nodeObject; + + } else if ( ( altType === null && ( type === 'float' || type === 'boolean' ) ) || ( type && type !== 'shader' && type !== 'string' ) ) { + + return nodeObject( getConstNode( obj, altType ) ); + + } else if ( type === 'shader' ) { + + return Fn( obj ); + + } + + return obj; + +}; + +const ShaderNodeObjects = function ( objects, altType = null ) { + + for ( const name in objects ) { + + objects[ name ] = nodeObject( objects[ name ], altType ); + + } + + return objects; + +}; + +const ShaderNodeArray = function ( array, altType = null ) { + + const len = array.length; + + for ( let i = 0; i < len; i ++ ) { + + array[ i ] = nodeObject( array[ i ], altType ); + + } + + return array; + +}; + +const ShaderNodeProxy = function ( NodeClass, scope = null, factor = null, settings = null ) { + + const assignNode = ( node ) => nodeObject( settings !== null ? Object.assign( node, settings ) : node ); + + if ( scope === null ) { + + return ( ...params ) => { + + return assignNode( new NodeClass( ...nodeArray( params ) ) ); + + }; + + } else if ( factor !== null ) { + + factor = nodeObject( factor ); + + return ( ...params ) => { + + return assignNode( new NodeClass( scope, ...nodeArray( params ), factor ) ); + + }; + + } else { + + return ( ...params ) => { + + return assignNode( new NodeClass( scope, ...nodeArray( params ) ) ); + + }; + + } + +}; + +const ShaderNodeImmutable = function ( NodeClass, ...params ) { + + return nodeObject( new NodeClass( ...nodeArray( params ) ) ); + +}; + +class ShaderCallNodeInternal extends Node { + + constructor( shaderNode, inputNodes ) { + + super(); + + this.shaderNode = shaderNode; + this.inputNodes = inputNodes; + + } + + getNodeType( builder ) { + + return this.shaderNode.nodeType || this.getOutputNode( builder ).getNodeType( builder ); + + } + + call( builder ) { + + const { shaderNode, inputNodes } = this; + + const properties = builder.getNodeProperties( shaderNode ); + if ( properties.onceOutput ) return properties.onceOutput; + + // + + let result = null; + + if ( shaderNode.layout ) { + + let functionNodesCacheMap = nodeBuilderFunctionsCacheMap.get( builder.constructor ); + + if ( functionNodesCacheMap === undefined ) { + + functionNodesCacheMap = new WeakMap(); + + nodeBuilderFunctionsCacheMap.set( builder.constructor, functionNodesCacheMap ); + + } + + let functionNode = functionNodesCacheMap.get( shaderNode ); + + if ( functionNode === undefined ) { + + functionNode = nodeObject( builder.buildFunctionNode( shaderNode ) ); + + functionNodesCacheMap.set( shaderNode, functionNode ); + + } + + if ( builder.currentFunctionNode !== null ) { + + builder.currentFunctionNode.includes.push( functionNode ); + + } + + result = nodeObject( functionNode.call( inputNodes ) ); + + } else { + + const jsFunc = shaderNode.jsFunc; + const outputNode = inputNodes !== null ? jsFunc( inputNodes, builder ) : jsFunc( builder ); + + result = nodeObject( outputNode ); + + } + + if ( shaderNode.once ) { + + properties.onceOutput = result; + + } + + return result; + + } + + getOutputNode( builder ) { + + const properties = builder.getNodeProperties( this ); + + if ( properties.outputNode === null ) { + + properties.outputNode = this.setupOutput( builder ); + + } + + return properties.outputNode; + + } + + setup( builder ) { + + return this.getOutputNode( builder ); + + } + + setupOutput( builder ) { + + builder.addStack(); + + builder.stack.outputNode = this.call( builder ); + + return builder.removeStack(); + + } + + generate( builder, output ) { + + const outputNode = this.getOutputNode( builder ); + + return outputNode.build( builder, output ); + + } + +} + +class ShaderNodeInternal extends Node { + + constructor( jsFunc, nodeType ) { + + super( nodeType ); + + this.jsFunc = jsFunc; + this.layout = null; + + this.global = true; + + this.once = false; + + } + + setLayout( layout ) { + + this.layout = layout; + + return this; + + } + + call( inputs = null ) { + + nodeObjects( inputs ); + + return nodeObject( new ShaderCallNodeInternal( this, inputs ) ); + + } + + setup() { + + return this.call(); + + } + +} + +const bools = [ false, true ]; +const uints = [ 0, 1, 2, 3 ]; +const ints = [ - 1, - 2 ]; +const floats = [ 0.5, 1.5, 1 / 3, 1e-6, 1e6, Math.PI, Math.PI * 2, 1 / Math.PI, 2 / Math.PI, 1 / ( Math.PI * 2 ), Math.PI / 2 ]; + +const boolsCacheMap = new Map(); +for ( const bool of bools ) boolsCacheMap.set( bool, new ConstNode( bool ) ); + +const uintsCacheMap = new Map(); +for ( const uint of uints ) uintsCacheMap.set( uint, new ConstNode( uint, 'uint' ) ); + +const intsCacheMap = new Map( [ ...uintsCacheMap ].map( el => new ConstNode( el.value, 'int' ) ) ); +for ( const int of ints ) intsCacheMap.set( int, new ConstNode( int, 'int' ) ); + +const floatsCacheMap = new Map( [ ...intsCacheMap ].map( el => new ConstNode( el.value ) ) ); +for ( const float of floats ) floatsCacheMap.set( float, new ConstNode( float ) ); +for ( const float of floats ) floatsCacheMap.set( - float, new ConstNode( - float ) ); + +const cacheMaps = { bool: boolsCacheMap, uint: uintsCacheMap, ints: intsCacheMap, float: floatsCacheMap }; + +const constNodesCacheMap = new Map( [ ...boolsCacheMap, ...floatsCacheMap ] ); + +const getConstNode = ( value, type ) => { + + if ( constNodesCacheMap.has( value ) ) { + + return constNodesCacheMap.get( value ); + + } else if ( value.isNode === true ) { + + return value; + + } else { + + return new ConstNode( value, type ); + + } + +}; + +const safeGetNodeType = ( node ) => { + + try { + + return node.getNodeType(); + + } catch ( _ ) { + + return undefined; + + } + +}; + +const ConvertType = function ( type, cacheMap = null ) { + + return ( ...params ) => { + + if ( params.length === 0 || ( ! [ 'bool', 'float', 'int', 'uint' ].includes( type ) && params.every( param => typeof param !== 'object' ) ) ) { + + params = [ getValueFromType( type, ...params ) ]; + + } + + if ( params.length === 1 && cacheMap !== null && cacheMap.has( params[ 0 ] ) ) { + + return nodeObject( cacheMap.get( params[ 0 ] ) ); + + } + + if ( params.length === 1 ) { + + const node = getConstNode( params[ 0 ], type ); + if ( safeGetNodeType( node ) === type ) return nodeObject( node ); + return nodeObject( new ConvertNode( node, type ) ); + + } + + const nodes = params.map( param => getConstNode( param ) ); + return nodeObject( new JoinNode( nodes, type ) ); + + }; + +}; + +// exports + +const defined = ( v ) => typeof v === 'object' && v !== null ? v.value : v; // TODO: remove boolean conversion and defined function + +// utils + +const getConstNodeType = ( value ) => ( value !== undefined && value !== null ) ? ( value.nodeType || value.convertTo || ( typeof value === 'string' ? value : null ) ) : null; + +// shader node base + +function ShaderNode( jsFunc, nodeType ) { + + return new Proxy( new ShaderNodeInternal( jsFunc, nodeType ), shaderNodeHandler ); + +} + +const nodeObject = ( val, altType = null ) => /* new */ ShaderNodeObject( val, altType ); +const nodeObjects = ( val, altType = null ) => new ShaderNodeObjects( val, altType ); +const nodeArray = ( val, altType = null ) => new ShaderNodeArray( val, altType ); +const nodeProxy = ( ...params ) => new ShaderNodeProxy( ...params ); +const nodeImmutable = ( ...params ) => new ShaderNodeImmutable( ...params ); + +const Fn = ( jsFunc, nodeType ) => { + + const shaderNode = new ShaderNode( jsFunc, nodeType ); + + const fn = ( ...params ) => { + + let inputs; + + nodeObjects( params ); + + if ( params[ 0 ] && params[ 0 ].isNode ) { + + inputs = [ ...params ]; + + } else { + + inputs = params[ 0 ]; + + } + + return shaderNode.call( inputs ); + + }; + + fn.shaderNode = shaderNode; + + fn.setLayout = ( layout ) => { + + shaderNode.setLayout( layout ); + + return fn; + + }; + + fn.once = () => { + + shaderNode.once = true; + + return fn; + + }; + + return fn; + +}; + +const tslFn = ( ...params ) => { // @deprecated, r168 + + console.warn( 'TSL.ShaderNode: tslFn() has been renamed to Fn().' ); + return Fn( ...params ); + +}; + +// + +addMethodChaining( 'toGlobal', ( node ) => { + + node.global = true; + + return node; + +} ); + +// + +const setCurrentStack = ( stack ) => { + + currentStack = stack; + +}; + +const getCurrentStack = () => currentStack; + +const If = ( ...params ) => currentStack.If( ...params ); + +function append( node ) { + + if ( currentStack ) currentStack.add( node ); + + return node; + +} + +addMethodChaining( 'append', append ); + +// types + +const color = new ConvertType( 'color' ); + +const float = new ConvertType( 'float', cacheMaps.float ); +const int = new ConvertType( 'int', cacheMaps.ints ); +const uint = new ConvertType( 'uint', cacheMaps.uint ); +const bool = new ConvertType( 'bool', cacheMaps.bool ); + +const vec2 = new ConvertType( 'vec2' ); +const ivec2 = new ConvertType( 'ivec2' ); +const uvec2 = new ConvertType( 'uvec2' ); +const bvec2 = new ConvertType( 'bvec2' ); + +const vec3 = new ConvertType( 'vec3' ); +const ivec3 = new ConvertType( 'ivec3' ); +const uvec3 = new ConvertType( 'uvec3' ); +const bvec3 = new ConvertType( 'bvec3' ); + +const vec4 = new ConvertType( 'vec4' ); +const ivec4 = new ConvertType( 'ivec4' ); +const uvec4 = new ConvertType( 'uvec4' ); +const bvec4 = new ConvertType( 'bvec4' ); + +const mat2 = new ConvertType( 'mat2' ); +const mat3 = new ConvertType( 'mat3' ); +const mat4 = new ConvertType( 'mat4' ); + +const string = ( value = '' ) => nodeObject( new ConstNode( value, 'string' ) ); +const arrayBuffer = ( value ) => nodeObject( new ConstNode( value, 'ArrayBuffer' ) ); + +addMethodChaining( 'toColor', color ); +addMethodChaining( 'toFloat', float ); +addMethodChaining( 'toInt', int ); +addMethodChaining( 'toUint', uint ); +addMethodChaining( 'toBool', bool ); +addMethodChaining( 'toVec2', vec2 ); +addMethodChaining( 'toIVec2', ivec2 ); +addMethodChaining( 'toUVec2', uvec2 ); +addMethodChaining( 'toBVec2', bvec2 ); +addMethodChaining( 'toVec3', vec3 ); +addMethodChaining( 'toIVec3', ivec3 ); +addMethodChaining( 'toUVec3', uvec3 ); +addMethodChaining( 'toBVec3', bvec3 ); +addMethodChaining( 'toVec4', vec4 ); +addMethodChaining( 'toIVec4', ivec4 ); +addMethodChaining( 'toUVec4', uvec4 ); +addMethodChaining( 'toBVec4', bvec4 ); +addMethodChaining( 'toMat2', mat2 ); +addMethodChaining( 'toMat3', mat3 ); +addMethodChaining( 'toMat4', mat4 ); + +// basic nodes + +const element = /*@__PURE__*/ nodeProxy( ArrayElementNode ); +const convert = ( node, types ) => nodeObject( new ConvertNode( nodeObject( node ), types ) ); +const split = ( node, channels ) => nodeObject( new SplitNode( nodeObject( node ), channels ) ); + +addMethodChaining( 'element', element ); +addMethodChaining( 'convert', convert ); + +class UniformGroupNode extends Node { + + static get type() { + + return 'UniformGroupNode'; + + } + + constructor( name, shared = false, order = 1 ) { + + super( 'string' ); + + this.name = name; + this.version = 0; + + this.shared = shared; + this.order = order; + this.isUniformGroup = true; + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + serialize( data ) { + + super.serialize( data ); + + data.name = this.name; + data.version = this.version; + data.shared = this.shared; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.name = data.name; + this.version = data.version; + this.shared = data.shared; + + } + +} + +const uniformGroup = ( name ) => new UniformGroupNode( name ); +const sharedUniformGroup = ( name, order = 0 ) => new UniformGroupNode( name, true, order ); + +const frameGroup = /*@__PURE__*/ sharedUniformGroup( 'frame' ); +const renderGroup = /*@__PURE__*/ sharedUniformGroup( 'render' ); +const objectGroup = /*@__PURE__*/ uniformGroup( 'object' ); + +class UniformNode extends InputNode { + + static get type() { + + return 'UniformNode'; + + } + + constructor( value, nodeType = null ) { + + super( value, nodeType ); + + this.isUniformNode = true; + + this.name = ''; + this.groupNode = objectGroup; + + } + + label( name ) { + + this.name = name; + + return this; + + } + + setGroup( group ) { + + this.groupNode = group; + + return this; + + } + + getGroup() { + + return this.groupNode; + + } + + getUniformHash( builder ) { + + return this.getHash( builder ); + + } + + onUpdate( callback, updateType ) { + + const self = this.getSelf(); + + callback = callback.bind( self ); + + return super.onUpdate( ( frame ) => { + + const value = callback( frame, self ); + + if ( value !== undefined ) { + + this.value = value; + + } + + }, updateType ); + + } + + generate( builder, output ) { + + const type = this.getNodeType( builder ); + + const hash = this.getUniformHash( builder ); + + let sharedNode = builder.getNodeFromHash( hash ); + + if ( sharedNode === undefined ) { + + builder.setHashNode( this, hash ); + + sharedNode = this; + + } + + const sharedNodeType = sharedNode.getInputType( builder ); + + const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.label ); + const propertyName = builder.getPropertyName( nodeUniform ); + + if ( builder.context.label !== undefined ) delete builder.context.label; + + return builder.format( propertyName, type, output ); + + } + +} + +const uniform = ( arg1, arg2 ) => { + + const nodeType = getConstNodeType( arg2 || arg1 ); + + // @TODO: get ConstNode from .traverse() in the future + const value = ( arg1 && arg1.isNode === true ) ? ( arg1.node && arg1.node.value ) || arg1.value : arg1; + + return nodeObject( new UniformNode( value, nodeType ) ); + +}; + +class PropertyNode extends Node { + + static get type() { + + return 'PropertyNode'; + + } + + constructor( nodeType, name = null, varying = false ) { + + super( nodeType ); + + this.name = name; + this.varying = varying; + + this.isPropertyNode = true; + + } + + getHash( builder ) { + + return this.name || super.getHash( builder ); + + } + + isGlobal( /*builder*/ ) { + + return true; + + } + + generate( builder ) { + + let nodeVar; + + if ( this.varying === true ) { + + nodeVar = builder.getVaryingFromNode( this, this.name ); + nodeVar.needsInterpolation = true; + + } else { + + nodeVar = builder.getVarFromNode( this, this.name ); + + } + + return builder.getPropertyName( nodeVar ); + + } + +} + +const property = ( type, name ) => nodeObject( new PropertyNode( type, name ) ); +const varyingProperty = ( type, name ) => nodeObject( new PropertyNode( type, name, true ) ); + +const diffuseColor = /*@__PURE__*/ nodeImmutable( PropertyNode, 'vec4', 'DiffuseColor' ); +const emissive = /*@__PURE__*/ nodeImmutable( PropertyNode, 'vec3', 'EmissiveColor' ); +const roughness = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Roughness' ); +const metalness = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Metalness' ); +const clearcoat = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Clearcoat' ); +const clearcoatRoughness = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'ClearcoatRoughness' ); +const sheen = /*@__PURE__*/ nodeImmutable( PropertyNode, 'vec3', 'Sheen' ); +const sheenRoughness = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'SheenRoughness' ); +const iridescence = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Iridescence' ); +const iridescenceIOR = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'IridescenceIOR' ); +const iridescenceThickness = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'IridescenceThickness' ); +const alphaT = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'AlphaT' ); +const anisotropy = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Anisotropy' ); +const anisotropyT = /*@__PURE__*/ nodeImmutable( PropertyNode, 'vec3', 'AnisotropyT' ); +const anisotropyB = /*@__PURE__*/ nodeImmutable( PropertyNode, 'vec3', 'AnisotropyB' ); +const specularColor = /*@__PURE__*/ nodeImmutable( PropertyNode, 'color', 'SpecularColor' ); +const specularF90 = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'SpecularF90' ); +const shininess = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Shininess' ); +const output = /*@__PURE__*/ nodeImmutable( PropertyNode, 'vec4', 'Output' ); +const dashSize = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'dashSize' ); +const gapSize = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'gapSize' ); +const pointWidth = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'pointWidth' ); +const ior = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'IOR' ); +const transmission = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Transmission' ); +const thickness = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Thickness' ); +const attenuationDistance = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'AttenuationDistance' ); +const attenuationColor = /*@__PURE__*/ nodeImmutable( PropertyNode, 'color', 'AttenuationColor' ); +const dispersion = /*@__PURE__*/ nodeImmutable( PropertyNode, 'float', 'Dispersion' ); + +class AssignNode extends TempNode { + + static get type() { + + return 'AssignNode'; + + } + + constructor( targetNode, sourceNode ) { + + super(); + + this.targetNode = targetNode; + this.sourceNode = sourceNode; + + } + + hasDependencies() { + + return false; + + } + + getNodeType( builder, output ) { + + return output !== 'void' ? this.targetNode.getNodeType( builder ) : 'void'; + + } + + needsSplitAssign( builder ) { + + const { targetNode } = this; + + if ( builder.isAvailable( 'swizzleAssign' ) === false && targetNode.isSplitNode && targetNode.components.length > 1 ) { + + const targetLength = builder.getTypeLength( targetNode.node.getNodeType( builder ) ); + const assignDiferentVector = vectorComponents.join( '' ).slice( 0, targetLength ) !== targetNode.components; + + return assignDiferentVector; + + } + + return false; + + } + + generate( builder, output ) { + + const { targetNode, sourceNode } = this; + + const needsSplitAssign = this.needsSplitAssign( builder ); + + const targetType = targetNode.getNodeType( builder ); + + const target = targetNode.context( { assign: true } ).build( builder ); + const source = sourceNode.build( builder, targetType ); + + const sourceType = sourceNode.getNodeType( builder ); + + const nodeData = builder.getDataFromNode( this ); + + // + + let snippet; + + if ( nodeData.initialized === true ) { + + if ( output !== 'void' ) { + + snippet = target; + + } + + } else if ( needsSplitAssign ) { + + const sourceVar = builder.getVarFromNode( this, null, targetType ); + const sourceProperty = builder.getPropertyName( sourceVar ); + + builder.addLineFlowCode( `${ sourceProperty } = ${ source }`, this ); + + const targetRoot = targetNode.node.context( { assign: true } ).build( builder ); + + for ( let i = 0; i < targetNode.components.length; i ++ ) { + + const component = targetNode.components[ i ]; + + builder.addLineFlowCode( `${ targetRoot }.${ component } = ${ sourceProperty }[ ${ i } ]`, this ); + + } + + if ( output !== 'void' ) { + + snippet = target; + + } + + } else { + + snippet = `${ target } = ${ source }`; + + if ( output === 'void' || sourceType === 'void' ) { + + builder.addLineFlowCode( snippet, this ); + + if ( output !== 'void' ) { + + snippet = target; + + } + + } + + } + + nodeData.initialized = true; + + return builder.format( snippet, targetType, output ); + + } + +} + +const assign = /*@__PURE__*/ nodeProxy( AssignNode ); + +addMethodChaining( 'assign', assign ); + +class FunctionCallNode extends TempNode { + + static get type() { + + return 'FunctionCallNode'; + + } + + constructor( functionNode = null, parameters = {} ) { + + super(); + + this.functionNode = functionNode; + this.parameters = parameters; + + } + + setParameters( parameters ) { + + this.parameters = parameters; + + return this; + + } + + getParameters() { + + return this.parameters; + + } + + getNodeType( builder ) { + + return this.functionNode.getNodeType( builder ); + + } + + generate( builder ) { + + const params = []; + + const functionNode = this.functionNode; + + const inputs = functionNode.getInputs( builder ); + const parameters = this.parameters; + + const generateInput = ( node, inputNode ) => { + + const type = inputNode.type; + const pointer = type === 'pointer'; + + let output; + + if ( pointer ) output = '&' + node.build( builder ); + else output = node.build( builder, type ); + + return output; + + }; + + if ( Array.isArray( parameters ) ) { + + for ( let i = 0; i < parameters.length; i ++ ) { + + params.push( generateInput( parameters[ i ], inputs[ i ] ) ); + + } + + } else { + + for ( const inputNode of inputs ) { + + const node = parameters[ inputNode.name ]; + + if ( node !== undefined ) { + + params.push( generateInput( node, inputNode ) ); + + } else { + + throw new Error( `FunctionCallNode: Input '${inputNode.name}' not found in FunctionNode.` ); + + } + + } + + } + + const functionName = functionNode.build( builder, 'property' ); + + return `${functionName}( ${params.join( ', ' )} )`; + + } + +} + +const call = ( func, ...params ) => { + + params = params.length > 1 || ( params[ 0 ] && params[ 0 ].isNode === true ) ? nodeArray( params ) : nodeObjects( params[ 0 ] ); + + return nodeObject( new FunctionCallNode( nodeObject( func ), params ) ); + +}; + +addMethodChaining( 'call', call ); + +class OperatorNode extends TempNode { + + static get type() { + + return 'OperatorNode'; + + } + + constructor( op, aNode, bNode, ...params ) { + + super(); + + if ( params.length > 0 ) { + + let finalOp = new OperatorNode( op, aNode, bNode ); + + for ( let i = 0; i < params.length - 1; i ++ ) { + + finalOp = new OperatorNode( op, finalOp, params[ i ] ); + + } + + aNode = finalOp; + bNode = params[ params.length - 1 ]; + + } + + this.op = op; + this.aNode = aNode; + this.bNode = bNode; + + } + + getNodeType( builder, output ) { + + const op = this.op; + + const aNode = this.aNode; + const bNode = this.bNode; + + const typeA = aNode.getNodeType( builder ); + const typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null; + + if ( typeA === 'void' || typeB === 'void' ) { + + return 'void'; + + } else if ( op === '%' ) { + + return typeA; + + } else if ( op === '~' || op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) { + + return builder.getIntegerType( typeA ); + + } else if ( op === '!' || op === '==' || op === '&&' || op === '||' || op === '^^' ) { + + return 'bool'; + + } else if ( op === '<' || op === '>' || op === '<=' || op === '>=' ) { + + const typeLength = output ? builder.getTypeLength( output ) : Math.max( builder.getTypeLength( typeA ), builder.getTypeLength( typeB ) ); + + return typeLength > 1 ? `bvec${ typeLength }` : 'bool'; + + } else { + + if ( typeA === 'float' && builder.isMatrix( typeB ) ) { + + return typeB; + + } else if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) { + + // matrix x vector + + return builder.getVectorFromMatrix( typeA ); + + } else if ( builder.isVector( typeA ) && builder.isMatrix( typeB ) ) { + + // vector x matrix + + return builder.getVectorFromMatrix( typeB ); + + } else if ( builder.getTypeLength( typeB ) > builder.getTypeLength( typeA ) ) { + + // anytype x anytype: use the greater length vector + + return typeB; + + } + + return typeA; + + } + + } + + generate( builder, output ) { + + const op = this.op; + + const aNode = this.aNode; + const bNode = this.bNode; + + const type = this.getNodeType( builder, output ); + + let typeA = null; + let typeB = null; + + if ( type !== 'void' ) { + + typeA = aNode.getNodeType( builder ); + typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null; + + if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) { + + if ( builder.isVector( typeA ) ) { + + typeB = typeA; + + } else if ( typeA !== typeB ) { + + typeA = typeB = 'float'; + + } + + } else if ( op === '>>' || op === '<<' ) { + + typeA = type; + typeB = builder.changeComponentType( typeB, 'uint' ); + + } else if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) { + + // matrix x vector + + typeB = builder.getVectorFromMatrix( typeA ); + + } else if ( builder.isVector( typeA ) && builder.isMatrix( typeB ) ) { + + // vector x matrix + + typeA = builder.getVectorFromMatrix( typeB ); + + } else { + + // anytype x anytype + + typeA = typeB = type; + + } + + } else { + + typeA = typeB = type; + + } + + const a = aNode.build( builder, typeA ); + const b = typeof bNode !== 'undefined' ? bNode.build( builder, typeB ) : null; + + const outputLength = builder.getTypeLength( output ); + const fnOpSnippet = builder.getFunctionOperator( op ); + + if ( output !== 'void' ) { + + if ( op === '<' && outputLength > 1 ) { + + if ( builder.useComparisonMethod ) { + + return builder.format( `${ builder.getMethod( 'lessThan', output ) }( ${ a }, ${ b } )`, type, output ); + + } else { + + return builder.format( `( ${ a } < ${ b } )`, type, output ); + + } + + } else if ( op === '<=' && outputLength > 1 ) { + + if ( builder.useComparisonMethod ) { + + return builder.format( `${ builder.getMethod( 'lessThanEqual', output ) }( ${ a }, ${ b } )`, type, output ); + + } else { + + return builder.format( `( ${ a } <= ${ b } )`, type, output ); + + } + + } else if ( op === '>' && outputLength > 1 ) { + + if ( builder.useComparisonMethod ) { + + return builder.format( `${ builder.getMethod( 'greaterThan', output ) }( ${ a }, ${ b } )`, type, output ); + + } else { + + return builder.format( `( ${ a } > ${ b } )`, type, output ); + + } + + } else if ( op === '>=' && outputLength > 1 ) { + + if ( builder.useComparisonMethod ) { + + return builder.format( `${ builder.getMethod( 'greaterThanEqual', output ) }( ${ a }, ${ b } )`, type, output ); + + } else { + + return builder.format( `( ${ a } >= ${ b } )`, type, output ); + + } + + } else if ( op === '!' || op === '~' ) { + + return builder.format( `(${op}${a})`, typeA, output ); + + } else if ( fnOpSnippet ) { + + return builder.format( `${ fnOpSnippet }( ${ a }, ${ b } )`, type, output ); + + } else { + + return builder.format( `( ${ a } ${ op } ${ b } )`, type, output ); + + } + + } else if ( typeA !== 'void' ) { + + if ( fnOpSnippet ) { + + return builder.format( `${ fnOpSnippet }( ${ a }, ${ b } )`, type, output ); + + } else { + + return builder.format( `${ a } ${ op } ${ b }`, type, output ); + + } + + } + + } + + serialize( data ) { + + super.serialize( data ); + + data.op = this.op; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.op = data.op; + + } + +} + +const add = /*@__PURE__*/ nodeProxy( OperatorNode, '+' ); +const sub = /*@__PURE__*/ nodeProxy( OperatorNode, '-' ); +const mul = /*@__PURE__*/ nodeProxy( OperatorNode, '*' ); +const div = /*@__PURE__*/ nodeProxy( OperatorNode, '/' ); +const modInt = /*@__PURE__*/ nodeProxy( OperatorNode, '%' ); +const equal = /*@__PURE__*/ nodeProxy( OperatorNode, '==' ); +const notEqual = /*@__PURE__*/ nodeProxy( OperatorNode, '!=' ); +const lessThan = /*@__PURE__*/ nodeProxy( OperatorNode, '<' ); +const greaterThan = /*@__PURE__*/ nodeProxy( OperatorNode, '>' ); +const lessThanEqual = /*@__PURE__*/ nodeProxy( OperatorNode, '<=' ); +const greaterThanEqual = /*@__PURE__*/ nodeProxy( OperatorNode, '>=' ); +const and = /*@__PURE__*/ nodeProxy( OperatorNode, '&&' ); +const or = /*@__PURE__*/ nodeProxy( OperatorNode, '||' ); +const not = /*@__PURE__*/ nodeProxy( OperatorNode, '!' ); +const xor = /*@__PURE__*/ nodeProxy( OperatorNode, '^^' ); +const bitAnd = /*@__PURE__*/ nodeProxy( OperatorNode, '&' ); +const bitNot = /*@__PURE__*/ nodeProxy( OperatorNode, '~' ); +const bitOr = /*@__PURE__*/ nodeProxy( OperatorNode, '|' ); +const bitXor = /*@__PURE__*/ nodeProxy( OperatorNode, '^' ); +const shiftLeft = /*@__PURE__*/ nodeProxy( OperatorNode, '<<' ); +const shiftRight = /*@__PURE__*/ nodeProxy( OperatorNode, '>>' ); + +addMethodChaining( 'add', add ); +addMethodChaining( 'sub', sub ); +addMethodChaining( 'mul', mul ); +addMethodChaining( 'div', div ); +addMethodChaining( 'modInt', modInt ); +addMethodChaining( 'equal', equal ); +addMethodChaining( 'notEqual', notEqual ); +addMethodChaining( 'lessThan', lessThan ); +addMethodChaining( 'greaterThan', greaterThan ); +addMethodChaining( 'lessThanEqual', lessThanEqual ); +addMethodChaining( 'greaterThanEqual', greaterThanEqual ); +addMethodChaining( 'and', and ); +addMethodChaining( 'or', or ); +addMethodChaining( 'not', not ); +addMethodChaining( 'xor', xor ); +addMethodChaining( 'bitAnd', bitAnd ); +addMethodChaining( 'bitNot', bitNot ); +addMethodChaining( 'bitOr', bitOr ); +addMethodChaining( 'bitXor', bitXor ); +addMethodChaining( 'shiftLeft', shiftLeft ); +addMethodChaining( 'shiftRight', shiftRight ); + + +const remainder = ( ...params ) => { // @deprecated, r168 + + console.warn( 'TSL.OperatorNode: .remainder() has been renamed to .modInt().' ); + return modInt( ...params ); + +}; + +addMethodChaining( 'remainder', remainder ); + +class MathNode extends TempNode { + + static get type() { + + return 'MathNode'; + + } + + constructor( method, aNode, bNode = null, cNode = null ) { + + super(); + + this.method = method; + + this.aNode = aNode; + this.bNode = bNode; + this.cNode = cNode; + + } + + getInputType( builder ) { + + const aType = this.aNode.getNodeType( builder ); + const bType = this.bNode ? this.bNode.getNodeType( builder ) : null; + const cType = this.cNode ? this.cNode.getNodeType( builder ) : null; + + const aLen = builder.isMatrix( aType ) ? 0 : builder.getTypeLength( aType ); + const bLen = builder.isMatrix( bType ) ? 0 : builder.getTypeLength( bType ); + const cLen = builder.isMatrix( cType ) ? 0 : builder.getTypeLength( cType ); + + if ( aLen > bLen && aLen > cLen ) { + + return aType; + + } else if ( bLen > cLen ) { + + return bType; + + } else if ( cLen > aLen ) { + + return cType; + + } + + return aType; + + } + + getNodeType( builder ) { + + const method = this.method; + + if ( method === MathNode.LENGTH || method === MathNode.DISTANCE || method === MathNode.DOT ) { + + return 'float'; + + } else if ( method === MathNode.CROSS ) { + + return 'vec3'; + + } else if ( method === MathNode.ALL ) { + + return 'bool'; + + } else if ( method === MathNode.EQUALS ) { + + return builder.changeComponentType( this.aNode.getNodeType( builder ), 'bool' ); + + } else if ( method === MathNode.MOD ) { + + return this.aNode.getNodeType( builder ); + + } else { + + return this.getInputType( builder ); + + } + + } + + generate( builder, output ) { + + const method = this.method; + + const type = this.getNodeType( builder ); + const inputType = this.getInputType( builder ); + + const a = this.aNode; + const b = this.bNode; + const c = this.cNode; + + const isWebGL = builder.renderer.isWebGLRenderer === true; + + if ( method === MathNode.TRANSFORM_DIRECTION ) { + + // dir can be either a direction vector or a normal vector + // upper-left 3x3 of matrix is assumed to be orthogonal + + let tA = a; + let tB = b; + + if ( builder.isMatrix( tA.getNodeType( builder ) ) ) { + + tB = vec4( vec3( tB ), 0.0 ); + + } else { + + tA = vec4( vec3( tA ), 0.0 ); + + } + + const mulNode = mul( tA, tB ).xyz; + + return normalize( mulNode ).build( builder, output ); + + } else if ( method === MathNode.NEGATE ) { + + return builder.format( '( - ' + a.build( builder, inputType ) + ' )', type, output ); + + } else if ( method === MathNode.ONE_MINUS ) { + + return sub( 1.0, a ).build( builder, output ); + + } else if ( method === MathNode.RECIPROCAL ) { + + return div( 1.0, a ).build( builder, output ); + + } else if ( method === MathNode.DIFFERENCE ) { + + return abs( sub( a, b ) ).build( builder, output ); + + } else { + + const params = []; + + if ( method === MathNode.CROSS || method === MathNode.MOD ) { + + params.push( + a.build( builder, type ), + b.build( builder, type ) + ); + + } else if ( isWebGL && method === MathNode.STEP ) { + + params.push( + a.build( builder, builder.getTypeLength( a.getNodeType( builder ) ) === 1 ? 'float' : inputType ), + b.build( builder, inputType ) + ); + + } else if ( ( isWebGL && ( method === MathNode.MIN || method === MathNode.MAX ) ) || method === MathNode.MOD ) { + + params.push( + a.build( builder, inputType ), + b.build( builder, builder.getTypeLength( b.getNodeType( builder ) ) === 1 ? 'float' : inputType ) + ); + + } else if ( method === MathNode.REFRACT ) { + + params.push( + a.build( builder, inputType ), + b.build( builder, inputType ), + c.build( builder, 'float' ) + ); + + } else if ( method === MathNode.MIX ) { + + params.push( + a.build( builder, inputType ), + b.build( builder, inputType ), + c.build( builder, builder.getTypeLength( c.getNodeType( builder ) ) === 1 ? 'float' : inputType ) + ); + + } else { + + params.push( a.build( builder, inputType ) ); + if ( b !== null ) params.push( b.build( builder, inputType ) ); + if ( c !== null ) params.push( c.build( builder, inputType ) ); + + } + + return builder.format( `${ builder.getMethod( method, type ) }( ${params.join( ', ' )} )`, type, output ); + + } + + } + + serialize( data ) { + + super.serialize( data ); + + data.method = this.method; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.method = data.method; + + } + +} + +// 1 input + +MathNode.ALL = 'all'; +MathNode.ANY = 'any'; +MathNode.EQUALS = 'equals'; + +MathNode.RADIANS = 'radians'; +MathNode.DEGREES = 'degrees'; +MathNode.EXP = 'exp'; +MathNode.EXP2 = 'exp2'; +MathNode.LOG = 'log'; +MathNode.LOG2 = 'log2'; +MathNode.SQRT = 'sqrt'; +MathNode.INVERSE_SQRT = 'inversesqrt'; +MathNode.FLOOR = 'floor'; +MathNode.CEIL = 'ceil'; +MathNode.NORMALIZE = 'normalize'; +MathNode.FRACT = 'fract'; +MathNode.SIN = 'sin'; +MathNode.COS = 'cos'; +MathNode.TAN = 'tan'; +MathNode.ASIN = 'asin'; +MathNode.ACOS = 'acos'; +MathNode.ATAN = 'atan'; +MathNode.ABS = 'abs'; +MathNode.SIGN = 'sign'; +MathNode.LENGTH = 'length'; +MathNode.NEGATE = 'negate'; +MathNode.ONE_MINUS = 'oneMinus'; +MathNode.DFDX = 'dFdx'; +MathNode.DFDY = 'dFdy'; +MathNode.ROUND = 'round'; +MathNode.RECIPROCAL = 'reciprocal'; +MathNode.TRUNC = 'trunc'; +MathNode.FWIDTH = 'fwidth'; +MathNode.BITCAST = 'bitcast'; +MathNode.TRANSPOSE = 'transpose'; + +// 2 inputs + +MathNode.ATAN2 = 'atan2'; +MathNode.MIN = 'min'; +MathNode.MAX = 'max'; +MathNode.MOD = 'mod'; +MathNode.STEP = 'step'; +MathNode.REFLECT = 'reflect'; +MathNode.DISTANCE = 'distance'; +MathNode.DIFFERENCE = 'difference'; +MathNode.DOT = 'dot'; +MathNode.CROSS = 'cross'; +MathNode.POW = 'pow'; +MathNode.TRANSFORM_DIRECTION = 'transformDirection'; + +// 3 inputs + +MathNode.MIX = 'mix'; +MathNode.CLAMP = 'clamp'; +MathNode.REFRACT = 'refract'; +MathNode.SMOOTHSTEP = 'smoothstep'; +MathNode.FACEFORWARD = 'faceforward'; + +const EPSILON = /*@__PURE__*/ float( 1e-6 ); +const INFINITY = /*@__PURE__*/ float( 1e6 ); +const PI = /*@__PURE__*/ float( Math.PI ); +const PI2 = /*@__PURE__*/ float( Math.PI * 2 ); + +const all = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ALL ); +const any = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ANY ); +const equals = /*@__PURE__*/ nodeProxy( MathNode, MathNode.EQUALS ); + +const radians = /*@__PURE__*/ nodeProxy( MathNode, MathNode.RADIANS ); +const degrees = /*@__PURE__*/ nodeProxy( MathNode, MathNode.DEGREES ); +const exp = /*@__PURE__*/ nodeProxy( MathNode, MathNode.EXP ); +const exp2 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.EXP2 ); +const log = /*@__PURE__*/ nodeProxy( MathNode, MathNode.LOG ); +const log2 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.LOG2 ); +const sqrt = /*@__PURE__*/ nodeProxy( MathNode, MathNode.SQRT ); +const inverseSqrt = /*@__PURE__*/ nodeProxy( MathNode, MathNode.INVERSE_SQRT ); +const floor = /*@__PURE__*/ nodeProxy( MathNode, MathNode.FLOOR ); +const ceil = /*@__PURE__*/ nodeProxy( MathNode, MathNode.CEIL ); +const normalize = /*@__PURE__*/ nodeProxy( MathNode, MathNode.NORMALIZE ); +const fract = /*@__PURE__*/ nodeProxy( MathNode, MathNode.FRACT ); +const sin = /*@__PURE__*/ nodeProxy( MathNode, MathNode.SIN ); +const cos = /*@__PURE__*/ nodeProxy( MathNode, MathNode.COS ); +const tan = /*@__PURE__*/ nodeProxy( MathNode, MathNode.TAN ); +const asin = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ASIN ); +const acos = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ACOS ); +const atan = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ATAN ); +const abs = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ABS ); +const sign = /*@__PURE__*/ nodeProxy( MathNode, MathNode.SIGN ); +const length = /*@__PURE__*/ nodeProxy( MathNode, MathNode.LENGTH ); +const negate = /*@__PURE__*/ nodeProxy( MathNode, MathNode.NEGATE ); +const oneMinus = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ONE_MINUS ); +const dFdx = /*@__PURE__*/ nodeProxy( MathNode, MathNode.DFDX ); +const dFdy = /*@__PURE__*/ nodeProxy( MathNode, MathNode.DFDY ); +const round = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ROUND ); +const reciprocal = /*@__PURE__*/ nodeProxy( MathNode, MathNode.RECIPROCAL ); +const trunc = /*@__PURE__*/ nodeProxy( MathNode, MathNode.TRUNC ); +const fwidth = /*@__PURE__*/ nodeProxy( MathNode, MathNode.FWIDTH ); +const bitcast = /*@__PURE__*/ nodeProxy( MathNode, MathNode.BITCAST ); +const transpose = /*@__PURE__*/ nodeProxy( MathNode, MathNode.TRANSPOSE ); + +const atan2 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ATAN2 ); +const min$1 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MIN ); +const max$1 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MAX ); +const mod = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MOD ); +const step = /*@__PURE__*/ nodeProxy( MathNode, MathNode.STEP ); +const reflect = /*@__PURE__*/ nodeProxy( MathNode, MathNode.REFLECT ); +const distance = /*@__PURE__*/ nodeProxy( MathNode, MathNode.DISTANCE ); +const difference = /*@__PURE__*/ nodeProxy( MathNode, MathNode.DIFFERENCE ); +const dot = /*@__PURE__*/ nodeProxy( MathNode, MathNode.DOT ); +const cross = /*@__PURE__*/ nodeProxy( MathNode, MathNode.CROSS ); +const pow = /*@__PURE__*/ nodeProxy( MathNode, MathNode.POW ); +const pow2 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.POW, 2 ); +const pow3 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.POW, 3 ); +const pow4 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.POW, 4 ); +const transformDirection = /*@__PURE__*/ nodeProxy( MathNode, MathNode.TRANSFORM_DIRECTION ); + +const cbrt = ( a ) => mul( sign( a ), pow( abs( a ), 1.0 / 3.0 ) ); +const lengthSq = ( a ) => dot( a, a ); +const mix = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MIX ); +const clamp = ( value, low = 0, high = 1 ) => nodeObject( new MathNode( MathNode.CLAMP, nodeObject( value ), nodeObject( low ), nodeObject( high ) ) ); +const saturate = ( value ) => clamp( value ); +const refract = /*@__PURE__*/ nodeProxy( MathNode, MathNode.REFRACT ); +const smoothstep = /*@__PURE__*/ nodeProxy( MathNode, MathNode.SMOOTHSTEP ); +const faceForward = /*@__PURE__*/ nodeProxy( MathNode, MathNode.FACEFORWARD ); + +const rand = /*@__PURE__*/ Fn( ( [ uv ] ) => { + + const a = 12.9898, b = 78.233, c = 43758.5453; + const dt = dot( uv.xy, vec2( a, b ) ), sn = mod( dt, PI ); + + return fract( sin( sn ).mul( c ) ); + +} ); + +const mixElement = ( t, e1, e2 ) => mix( e1, e2, t ); +const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x ); + +addMethodChaining( 'all', all ); +addMethodChaining( 'any', any ); +addMethodChaining( 'equals', equals ); + +addMethodChaining( 'radians', radians ); +addMethodChaining( 'degrees', degrees ); +addMethodChaining( 'exp', exp ); +addMethodChaining( 'exp2', exp2 ); +addMethodChaining( 'log', log ); +addMethodChaining( 'log2', log2 ); +addMethodChaining( 'sqrt', sqrt ); +addMethodChaining( 'inverseSqrt', inverseSqrt ); +addMethodChaining( 'floor', floor ); +addMethodChaining( 'ceil', ceil ); +addMethodChaining( 'normalize', normalize ); +addMethodChaining( 'fract', fract ); +addMethodChaining( 'sin', sin ); +addMethodChaining( 'cos', cos ); +addMethodChaining( 'tan', tan ); +addMethodChaining( 'asin', asin ); +addMethodChaining( 'acos', acos ); +addMethodChaining( 'atan', atan ); +addMethodChaining( 'abs', abs ); +addMethodChaining( 'sign', sign ); +addMethodChaining( 'length', length ); +addMethodChaining( 'lengthSq', lengthSq ); +addMethodChaining( 'negate', negate ); +addMethodChaining( 'oneMinus', oneMinus ); +addMethodChaining( 'dFdx', dFdx ); +addMethodChaining( 'dFdy', dFdy ); +addMethodChaining( 'round', round ); +addMethodChaining( 'reciprocal', reciprocal ); +addMethodChaining( 'trunc', trunc ); +addMethodChaining( 'fwidth', fwidth ); +addMethodChaining( 'atan2', atan2 ); +addMethodChaining( 'min', min$1 ); +addMethodChaining( 'max', max$1 ); +addMethodChaining( 'mod', mod ); +addMethodChaining( 'step', step ); +addMethodChaining( 'reflect', reflect ); +addMethodChaining( 'distance', distance ); +addMethodChaining( 'dot', dot ); +addMethodChaining( 'cross', cross ); +addMethodChaining( 'pow', pow ); +addMethodChaining( 'pow2', pow2 ); +addMethodChaining( 'pow3', pow3 ); +addMethodChaining( 'pow4', pow4 ); +addMethodChaining( 'transformDirection', transformDirection ); +addMethodChaining( 'mix', mixElement ); +addMethodChaining( 'clamp', clamp ); +addMethodChaining( 'refract', refract ); +addMethodChaining( 'smoothstep', smoothstepElement ); +addMethodChaining( 'faceForward', faceForward ); +addMethodChaining( 'difference', difference ); +addMethodChaining( 'saturate', saturate ); +addMethodChaining( 'cbrt', cbrt ); +addMethodChaining( 'transpose', transpose ); +addMethodChaining( 'rand', rand ); + +class ConditionalNode extends Node { + + static get type() { + + return 'ConditionalNode'; + + } + + constructor( condNode, ifNode, elseNode = null ) { + + super(); + + this.condNode = condNode; + + this.ifNode = ifNode; + this.elseNode = elseNode; + + } + + getNodeType( builder ) { + + const ifType = this.ifNode.getNodeType( builder ); + + if ( this.elseNode !== null ) { + + const elseType = this.elseNode.getNodeType( builder ); + + if ( builder.getTypeLength( elseType ) > builder.getTypeLength( ifType ) ) { + + return elseType; + + } + + } + + return ifType; + + } + + setup( builder ) { + + const condNode = this.condNode.cache(); + const ifNode = this.ifNode.cache(); + const elseNode = this.elseNode ? this.elseNode.cache() : null; + + // + + const currentNodeBlock = builder.context.nodeBlock; + + builder.getDataFromNode( ifNode ).parentNodeBlock = currentNodeBlock; + if ( elseNode !== null ) builder.getDataFromNode( elseNode ).parentNodeBlock = currentNodeBlock; + + // + + const properties = builder.getNodeProperties( this ); + properties.condNode = condNode; + properties.ifNode = ifNode.context( { nodeBlock: ifNode } ); + properties.elseNode = elseNode ? elseNode.context( { nodeBlock: elseNode } ) : null; + + } + + generate( builder, output ) { + + const type = this.getNodeType( builder ); + + const nodeData = builder.getDataFromNode( this ); + + if ( nodeData.nodeProperty !== undefined ) { + + return nodeData.nodeProperty; + + } + + const { condNode, ifNode, elseNode } = builder.getNodeProperties( this ); + + const needsOutput = output !== 'void'; + const nodeProperty = needsOutput ? property( type ).build( builder ) : ''; + + nodeData.nodeProperty = nodeProperty; + + const nodeSnippet = condNode.build( builder, 'bool' ); + + builder.addFlowCode( `\n${ builder.tab }if ( ${ nodeSnippet } ) {\n\n` ).addFlowTab(); + + let ifSnippet = ifNode.build( builder, type ); + + if ( ifSnippet ) { + + if ( needsOutput ) { + + ifSnippet = nodeProperty + ' = ' + ifSnippet + ';'; + + } else { + + ifSnippet = 'return ' + ifSnippet + ';'; + + } + + } + + builder.removeFlowTab().addFlowCode( builder.tab + '\t' + ifSnippet + '\n\n' + builder.tab + '}' ); + + if ( elseNode !== null ) { + + builder.addFlowCode( ' else {\n\n' ).addFlowTab(); + + let elseSnippet = elseNode.build( builder, type ); + + if ( elseSnippet ) { + + if ( needsOutput ) { + + elseSnippet = nodeProperty + ' = ' + elseSnippet + ';'; + + } else { + + elseSnippet = 'return ' + elseSnippet + ';'; + + } + + } + + builder.removeFlowTab().addFlowCode( builder.tab + '\t' + elseSnippet + '\n\n' + builder.tab + '}\n\n' ); + + } else { + + builder.addFlowCode( '\n\n' ); + + } + + return builder.format( nodeProperty, type, output ); + + } + +} + +const select = /*@__PURE__*/ nodeProxy( ConditionalNode ); + +addMethodChaining( 'select', select ); + +// + +const cond = ( ...params ) => { // @deprecated, r168 + + console.warn( 'TSL.ConditionalNode: cond() has been renamed to select().' ); + return select( ...params ); + +}; + +addMethodChaining( 'cond', cond ); + +class ContextNode extends Node { + + static get type() { + + return 'ContextNode'; + + } + + constructor( node, value = {} ) { + + super(); + + this.isContextNode = true; + + this.node = node; + this.value = value; + + } + + getScope() { + + return this.node.getScope(); + + } + + getNodeType( builder ) { + + return this.node.getNodeType( builder ); + + } + + analyze( builder ) { + + this.node.build( builder ); + + } + + setup( builder ) { + + const previousContext = builder.getContext(); + + builder.setContext( { ...builder.context, ...this.value } ); + + const node = this.node.build( builder ); + + builder.setContext( previousContext ); + + return node; + + } + + generate( builder, output ) { + + const previousContext = builder.getContext(); + + builder.setContext( { ...builder.context, ...this.value } ); + + const snippet = this.node.build( builder, output ); + + builder.setContext( previousContext ); + + return snippet; + + } + +} + +const context = /*@__PURE__*/ nodeProxy( ContextNode ); +const label = ( node, name ) => context( node, { label: name } ); + +addMethodChaining( 'context', context ); +addMethodChaining( 'label', label ); + +class VarNode extends Node { + + static get type() { + + return 'VarNode'; + + } + + constructor( node, name = null ) { + + super(); + + this.node = node; + this.name = name; + + this.global = true; + + this.isVarNode = true; + + } + + getHash( builder ) { + + return this.name || super.getHash( builder ); + + } + + getNodeType( builder ) { + + return this.node.getNodeType( builder ); + + } + + generate( builder ) { + + const { node, name } = this; + + const nodeVar = builder.getVarFromNode( this, name, builder.getVectorType( this.getNodeType( builder ) ) ); + + const propertyName = builder.getPropertyName( nodeVar ); + + const snippet = node.build( builder, nodeVar.type ); + + builder.addLineFlowCode( `${propertyName} = ${snippet}`, this ); + + return propertyName; + + } + +} + +const createVar = /*@__PURE__*/ nodeProxy( VarNode ); + +addMethodChaining( 'toVar', ( ...params ) => createVar( ...params ).append() ); + +// Deprecated + +const temp = ( node ) => { // @deprecated, r170 + + console.warn( 'TSL: "temp" is deprecated. Use ".toVar()" instead.' ); + + return createVar( node ); + +}; + +addMethodChaining( 'temp', temp ); + +class VaryingNode extends Node { + + static get type() { + + return 'VaryingNode'; + + } + + constructor( node, name = null ) { + + super(); + + this.node = node; + this.name = name; + + this.isVaryingNode = true; + + } + + isGlobal() { + + return true; + + } + + getHash( builder ) { + + return this.name || super.getHash( builder ); + + } + + getNodeType( builder ) { + + // VaryingNode is auto type + + return this.node.getNodeType( builder ); + + } + + setupVarying( builder ) { + + const properties = builder.getNodeProperties( this ); + + let varying = properties.varying; + + if ( varying === undefined ) { + + const name = this.name; + const type = this.getNodeType( builder ); + + properties.varying = varying = builder.getVaryingFromNode( this, name, type ); + properties.node = this.node; + + } + + // this property can be used to check if the varying can be optimized for a variable + varying.needsInterpolation || ( varying.needsInterpolation = ( builder.shaderStage === 'fragment' ) ); + + return varying; + + } + + setup( builder ) { + + this.setupVarying( builder ); + + } + + analyze( builder ) { + + this.setupVarying( builder ); + + return this.node.analyze( builder ); + + } + + generate( builder ) { + + const properties = builder.getNodeProperties( this ); + const varying = this.setupVarying( builder ); + + if ( properties.propertyName === undefined ) { + + const type = this.getNodeType( builder ); + const propertyName = builder.getPropertyName( varying, NodeShaderStage.VERTEX ); + + // force node run in vertex stage + builder.flowNodeFromShaderStage( NodeShaderStage.VERTEX, this.node, type, propertyName ); + + properties.propertyName = propertyName; + + } + + return builder.getPropertyName( varying ); + + } + +} + +const varying = /*@__PURE__*/ nodeProxy( VaryingNode ); + +addMethodChaining( 'varying', varying ); + +const sRGBTransferEOTF = /*@__PURE__*/ Fn( ( [ color ] ) => { + + const a = color.mul( 0.9478672986 ).add( 0.0521327014 ).pow( 2.4 ); + const b = color.mul( 0.0773993808 ); + const factor = color.lessThanEqual( 0.04045 ); + + const rgbResult = mix( a, b, factor ); + + return rgbResult; + +} ).setLayout( { + name: 'sRGBTransferEOTF', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' } + ] +} ); + +const sRGBTransferOETF = /*@__PURE__*/ Fn( ( [ color ] ) => { + + const a = color.pow( 0.41666 ).mul( 1.055 ).sub( 0.055 ); + const b = color.mul( 12.92 ); + const factor = color.lessThanEqual( 0.0031308 ); + + const rgbResult = mix( a, b, factor ); + + return rgbResult; + +} ).setLayout( { + name: 'sRGBTransferOETF', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' } + ] +} ); + +const WORKING_COLOR_SPACE = 'WorkingColorSpace'; +const OUTPUT_COLOR_SPACE = 'OutputColorSpace'; + +class ColorSpaceNode extends TempNode { + + static get type() { + + return 'ColorSpaceNode'; + + } + + constructor( colorNode, source, target ) { + + super( 'vec4' ); + + this.colorNode = colorNode; + this.source = source; + this.target = target; + + } + + resolveColorSpace( builder, colorSpace ) { + + if ( colorSpace === WORKING_COLOR_SPACE ) { + + return ColorManagement.workingColorSpace; + + } else if ( colorSpace === OUTPUT_COLOR_SPACE ) { + + return builder.context.outputColorSpace || builder.renderer.outputColorSpace; + + } + + return colorSpace; + + } + + setup( builder ) { + + const { colorNode } = this; + + const source = this.resolveColorSpace( builder, this.source ); + const target = this.resolveColorSpace( builder, this.target ); + + let outputNode = colorNode; + + if ( ColorManagement.enabled === false || source === target || ! source || ! target ) { + + return outputNode; + + } + + if ( ColorManagement.getTransfer( source ) === SRGBTransfer ) { + + outputNode = vec4( sRGBTransferEOTF( outputNode.rgb ), outputNode.a ); + + } + + if ( ColorManagement.getPrimaries( source ) !== ColorManagement.getPrimaries( target ) ) { + + outputNode = vec4( + mat3( ColorManagement._getMatrix( new Matrix3(), source, target ) ).mul( outputNode.rgb ), + outputNode.a + ); + + } + + if ( ColorManagement.getTransfer( target ) === SRGBTransfer ) { + + outputNode = vec4( sRGBTransferOETF( outputNode.rgb ), outputNode.a ); + + } + + return outputNode; + + } + +} + +const toOutputColorSpace = ( node ) => nodeObject( new ColorSpaceNode( nodeObject( node ), WORKING_COLOR_SPACE, OUTPUT_COLOR_SPACE ) ); +const toWorkingColorSpace = ( node ) => nodeObject( new ColorSpaceNode( nodeObject( node ), OUTPUT_COLOR_SPACE, WORKING_COLOR_SPACE ) ); + +const workingToColorSpace = ( node, colorSpace ) => nodeObject( new ColorSpaceNode( nodeObject( node ), WORKING_COLOR_SPACE, colorSpace ) ); +const colorSpaceToWorking = ( node, colorSpace ) => nodeObject( new ColorSpaceNode( nodeObject( node ), colorSpace, WORKING_COLOR_SPACE ) ); + +const convertColorSpace = ( node, sourceColorSpace, targetColorSpace ) => nodeObject( new ColorSpaceNode( nodeObject( node ), sourceColorSpace, targetColorSpace ) ); + +addMethodChaining( 'toOutputColorSpace', toOutputColorSpace ); +addMethodChaining( 'toWorkingColorSpace', toWorkingColorSpace ); + +addMethodChaining( 'workingToColorSpace', workingToColorSpace ); +addMethodChaining( 'colorSpaceToWorking', colorSpaceToWorking ); + +let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode { + + static get type() { + + return 'ReferenceElementNode'; + + } + + constructor( referenceNode, indexNode ) { + + super( referenceNode, indexNode ); + + this.referenceNode = referenceNode; + + this.isReferenceElementNode = true; + + } + + getNodeType() { + + return this.referenceNode.uniformType; + + } + + generate( builder ) { + + const snippet = super.generate( builder ); + const arrayType = this.referenceNode.getNodeType(); + const elementType = this.getNodeType(); + + return builder.format( snippet, arrayType, elementType ); + + } + +}; + +class ReferenceBaseNode extends Node { + + static get type() { + + return 'ReferenceBaseNode'; + + } + + constructor( property, uniformType, object = null, count = null ) { + + super(); + + this.property = property; + this.uniformType = uniformType; + this.object = object; + this.count = count; + + this.properties = property.split( '.' ); + this.reference = object; + this.node = null; + this.group = null; + + this.updateType = NodeUpdateType.OBJECT; + + } + + setGroup( group ) { + + this.group = group; + + return this; + + } + + element( indexNode ) { + + return nodeObject( new ReferenceElementNode$1( this, nodeObject( indexNode ) ) ); + + } + + setNodeType( uniformType ) { + + const node = uniform( null, uniformType ).getSelf(); + + if ( this.group !== null ) { + + node.setGroup( this.group ); + + } + + this.node = node; + + } + + getNodeType( builder ) { + + if ( this.node === null ) { + + this.updateReference( builder ); + this.updateValue(); + + } + + return this.node.getNodeType( builder ); + + } + + getValueFromReference( object = this.reference ) { + + const { properties } = this; + + let value = object[ properties[ 0 ] ]; + + for ( let i = 1; i < properties.length; i ++ ) { + + value = value[ properties[ i ] ]; + + } + + return value; + + } + + updateReference( state ) { + + this.reference = this.object !== null ? this.object : state.object; + + return this.reference; + + } + + setup() { + + this.updateValue(); + + return this.node; + + } + + update( /*frame*/ ) { + + this.updateValue(); + + } + + updateValue() { + + if ( this.node === null ) this.setNodeType( this.uniformType ); + + const value = this.getValueFromReference(); + + if ( Array.isArray( value ) ) { + + this.node.array = value; + + } else { + + this.node.value = value; + + } + + } + +} + +const reference$1 = ( name, type, object ) => nodeObject( new ReferenceBaseNode( name, type, object ) ); + +class RendererReferenceNode extends ReferenceBaseNode { + + static get type() { + + return 'RendererReferenceNode'; + + } + + constructor( property, inputType, renderer = null ) { + + super( property, inputType, renderer ); + + this.renderer = renderer; + + this.setGroup( renderGroup ); + + } + + updateReference( state ) { + + this.reference = this.renderer !== null ? this.renderer : state.renderer; + + return this.reference; + + } + +} + +const rendererReference = ( name, type, renderer ) => nodeObject( new RendererReferenceNode( name, type, renderer ) ); + +class ToneMappingNode extends TempNode { + + static get type() { + + return 'ToneMappingNode'; + + } + + constructor( toneMapping, exposureNode = toneMappingExposure, colorNode = null ) { + + super( 'vec3' ); + + this.toneMapping = toneMapping; + + this.exposureNode = exposureNode; + this.colorNode = colorNode; + + } + + getCacheKey() { + + return hash$1( super.getCacheKey(), this.toneMapping ); + + } + + setup( builder ) { + + const colorNode = this.colorNode || builder.context.color; + const toneMapping = this.toneMapping; + + if ( toneMapping === NoToneMapping ) return colorNode; + + let outputNode = null; + + const toneMappingFn = builder.renderer.library.getToneMappingFunction( toneMapping ); + + if ( toneMappingFn !== null ) { + + outputNode = vec4( toneMappingFn( colorNode.rgb, this.exposureNode ), colorNode.a ); + + } else { + + console.error( 'ToneMappingNode: Unsupported Tone Mapping configuration.', toneMapping ); + + outputNode = colorNode; + + } + + return outputNode; + + } + +} + +const toneMapping = ( mapping, exposure, color ) => nodeObject( new ToneMappingNode( mapping, nodeObject( exposure ), nodeObject( color ) ) ); +const toneMappingExposure = /*@__PURE__*/ rendererReference( 'toneMappingExposure', 'float' ); + +addMethodChaining( 'toneMapping', ( color, mapping, exposure ) => toneMapping( mapping, exposure, color ) ); + +class BufferAttributeNode extends InputNode { + + static get type() { + + return 'BufferAttributeNode'; + + } + + constructor( value, bufferType = null, bufferStride = 0, bufferOffset = 0 ) { + + super( value, bufferType ); + + this.isBufferNode = true; + + this.bufferType = bufferType; + this.bufferStride = bufferStride; + this.bufferOffset = bufferOffset; + + this.usage = StaticDrawUsage; + this.instanced = false; + + this.attribute = null; + + this.global = true; + + if ( value && value.isBufferAttribute === true ) { + + this.attribute = value; + this.usage = value.usage; + this.instanced = value.isInstancedBufferAttribute; + + } + + } + + getHash( builder ) { + + if ( this.bufferStride === 0 && this.bufferOffset === 0 ) { + + let bufferData = builder.globalCache.getData( this.value ); + + if ( bufferData === undefined ) { + + bufferData = { + node: this + }; + + builder.globalCache.setData( this.value, bufferData ); + + } + + return bufferData.node.uuid; + + } + + return this.uuid; + + } + + getNodeType( builder ) { + + if ( this.bufferType === null ) { + + this.bufferType = builder.getTypeFromAttribute( this.attribute ); + + } + + return this.bufferType; + + } + + setup( builder ) { + + if ( this.attribute !== null ) return; + + const type = this.getNodeType( builder ); + const array = this.value; + const itemSize = builder.getTypeLength( type ); + const stride = this.bufferStride || itemSize; + const offset = this.bufferOffset; + + const buffer = array.isInterleavedBuffer === true ? array : new InterleavedBuffer( array, stride ); + const bufferAttribute = new InterleavedBufferAttribute( buffer, itemSize, offset ); + + buffer.setUsage( this.usage ); + + this.attribute = bufferAttribute; + this.attribute.isInstancedBufferAttribute = this.instanced; // @TODO: Add a possible: InstancedInterleavedBufferAttribute + + } + + generate( builder ) { + + const nodeType = this.getNodeType( builder ); + + const nodeAttribute = builder.getBufferAttributeFromNode( this, nodeType ); + const propertyName = builder.getPropertyName( nodeAttribute ); + + let output = null; + + if ( builder.shaderStage === 'vertex' || builder.shaderStage === 'compute' ) { + + this.name = propertyName; + + output = propertyName; + + } else { + + const nodeVarying = varying( this ); + + output = nodeVarying.build( builder, nodeType ); + + } + + return output; + + } + + getInputType( /*builder*/ ) { + + return 'bufferAttribute'; + + } + + setUsage( value ) { + + this.usage = value; + + if ( this.attribute && this.attribute.isBufferAttribute === true ) { + + this.attribute.usage = value; + + } + + return this; + + } + + setInstanced( value ) { + + this.instanced = value; + + return this; + + } + +} + +const bufferAttribute = ( array, type, stride, offset ) => nodeObject( new BufferAttributeNode( array, type, stride, offset ) ); +const dynamicBufferAttribute = ( array, type, stride, offset ) => bufferAttribute( array, type, stride, offset ).setUsage( DynamicDrawUsage ); + +const instancedBufferAttribute = ( array, type, stride, offset ) => bufferAttribute( array, type, stride, offset ).setInstanced( true ); +const instancedDynamicBufferAttribute = ( array, type, stride, offset ) => dynamicBufferAttribute( array, type, stride, offset ).setInstanced( true ); + +addMethodChaining( 'toAttribute', ( bufferNode ) => bufferAttribute( bufferNode.value ) ); + +class ComputeNode extends Node { + + static get type() { + + return 'ComputeNode'; + + } + + constructor( computeNode, count, workgroupSize = [ 64 ] ) { + + super( 'void' ); + + this.isComputeNode = true; + + this.computeNode = computeNode; + + this.count = count; + this.workgroupSize = workgroupSize; + this.dispatchCount = 0; + + this.version = 1; + this.updateBeforeType = NodeUpdateType.OBJECT; + + this.onInitFunction = null; + + this.updateDispatchCount(); + + } + + dispose() { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + + updateDispatchCount() { + + const { count, workgroupSize } = this; + + let size = workgroupSize[ 0 ]; + + for ( let i = 1; i < workgroupSize.length; i ++ ) + size *= workgroupSize[ i ]; + + this.dispatchCount = Math.ceil( count / size ); + + } + + onInit( callback ) { + + this.onInitFunction = callback; + + return this; + + } + + updateBefore( { renderer } ) { + + renderer.compute( this ); + + } + + generate( builder ) { + + const { shaderStage } = builder; + + if ( shaderStage === 'compute' ) { + + const snippet = this.computeNode.build( builder, 'void' ); + + if ( snippet !== '' ) { + + builder.addLineFlowCode( snippet, this ); + + } + + } + + } + +} + +const compute = ( node, count, workgroupSize ) => nodeObject( new ComputeNode( nodeObject( node ), count, workgroupSize ) ); + +addMethodChaining( 'compute', compute ); + +class CacheNode extends Node { + + static get type() { + + return 'CacheNode'; + + } + + constructor( node, parent = true ) { + + super(); + + this.node = node; + this.parent = parent; + + this.isCacheNode = true; + + } + + getNodeType( builder ) { + + return this.node.getNodeType( builder ); + + } + + build( builder, ...params ) { + + const previousCache = builder.getCache(); + const cache = builder.getCacheFromNode( this, this.parent ); + + builder.setCache( cache ); + + const data = this.node.build( builder, ...params ); + + builder.setCache( previousCache ); + + return data; + + } + +} + +const cache = ( node, ...params ) => nodeObject( new CacheNode( nodeObject( node ), ...params ) ); + +addMethodChaining( 'cache', cache ); + +class BypassNode extends Node { + + static get type() { + + return 'BypassNode'; + + } + + constructor( returnNode, callNode ) { + + super(); + + this.isBypassNode = true; + + this.outputNode = returnNode; + this.callNode = callNode; + + } + + getNodeType( builder ) { + + return this.outputNode.getNodeType( builder ); + + } + + generate( builder ) { + + const snippet = this.callNode.build( builder, 'void' ); + + if ( snippet !== '' ) { + + builder.addLineFlowCode( snippet, this ); + + } + + return this.outputNode.build( builder ); + + } + +} + +const bypass = /*@__PURE__*/ nodeProxy( BypassNode ); + +addMethodChaining( 'bypass', bypass ); + +class RemapNode extends Node { + + static get type() { + + return 'RemapNode'; + + } + + constructor( node, inLowNode, inHighNode, outLowNode = float( 0 ), outHighNode = float( 1 ) ) { + + super(); + + this.node = node; + this.inLowNode = inLowNode; + this.inHighNode = inHighNode; + this.outLowNode = outLowNode; + this.outHighNode = outHighNode; + + this.doClamp = true; + + } + + setup() { + + const { node, inLowNode, inHighNode, outLowNode, outHighNode, doClamp } = this; + + let t = node.sub( inLowNode ).div( inHighNode.sub( inLowNode ) ); + + if ( doClamp === true ) t = t.clamp(); + + return t.mul( outHighNode.sub( outLowNode ) ).add( outLowNode ); + + } + +} + +const remap = /*@__PURE__*/ nodeProxy( RemapNode, null, null, { doClamp: false } ); +const remapClamp = /*@__PURE__*/ nodeProxy( RemapNode ); + +addMethodChaining( 'remap', remap ); +addMethodChaining( 'remapClamp', remapClamp ); + +class ExpressionNode extends Node { + + static get type() { + + return 'ExpressionNode'; + + } + + constructor( snippet = '', nodeType = 'void' ) { + + super( nodeType ); + + this.snippet = snippet; + + } + + generate( builder, output ) { + + const type = this.getNodeType( builder ); + const snippet = this.snippet; + + if ( type === 'void' ) { + + builder.addLineFlowCode( snippet, this ); + + } else { + + return builder.format( `( ${ snippet } )`, type, output ); + + } + + } + +} + +const expression = /*@__PURE__*/ nodeProxy( ExpressionNode ); + +const Discard = ( conditional ) => ( conditional ? select( conditional, expression( 'discard' ) ) : expression( 'discard' ) ).append(); +const Return = () => expression( 'return' ).append(); + +addMethodChaining( 'discard', Discard ); + +class RenderOutputNode extends TempNode { + + static get type() { + + return 'RenderOutputNode'; + + } + + constructor( colorNode, toneMapping, outputColorSpace ) { + + super( 'vec4' ); + + this.colorNode = colorNode; + this.toneMapping = toneMapping; + this.outputColorSpace = outputColorSpace; + + this.isRenderOutput = true; + + } + + setup( { context } ) { + + let outputNode = this.colorNode || context.color; + + // tone mapping + + const toneMapping = ( this.toneMapping !== null ? this.toneMapping : context.toneMapping ) || NoToneMapping; + const outputColorSpace = ( this.outputColorSpace !== null ? this.outputColorSpace : context.outputColorSpace ) || NoColorSpace; + + if ( toneMapping !== NoToneMapping ) { + + outputNode = outputNode.toneMapping( toneMapping ); + + } + + // working to output color space + + if ( outputColorSpace !== NoColorSpace && outputColorSpace !== ColorManagement.workingColorSpace ) { + + outputNode = outputNode.workingToColorSpace( outputColorSpace ); + + } + + return outputNode; + + } + +} + +const renderOutput = ( color, toneMapping = null, outputColorSpace = null ) => nodeObject( new RenderOutputNode( nodeObject( color ), toneMapping, outputColorSpace ) ); + +addMethodChaining( 'renderOutput', renderOutput ); + +// Non-PURE exports list, side-effects are required here. +// TSL Base Syntax + + +function addNodeElement( name/*, nodeElement*/ ) { + + console.warn( 'THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add', name ); + +} + +class AttributeNode extends Node { + + static get type() { + + return 'AttributeNode'; + + } + + constructor( attributeName, nodeType = null ) { + + super( nodeType ); + + this.global = true; + + this._attributeName = attributeName; + + } + + getHash( builder ) { + + return this.getAttributeName( builder ); + + } + + getNodeType( builder ) { + + let nodeType = this.nodeType; + + if ( nodeType === null ) { + + const attributeName = this.getAttributeName( builder ); + + if ( builder.hasGeometryAttribute( attributeName ) ) { + + const attribute = builder.geometry.getAttribute( attributeName ); + + nodeType = builder.getTypeFromAttribute( attribute ); + + } else { + + nodeType = 'float'; + + } + + } + + return nodeType; + + } + + setAttributeName( attributeName ) { + + this._attributeName = attributeName; + + return this; + + } + + getAttributeName( /*builder*/ ) { + + return this._attributeName; + + } + + generate( builder ) { + + const attributeName = this.getAttributeName( builder ); + const nodeType = this.getNodeType( builder ); + const geometryAttribute = builder.hasGeometryAttribute( attributeName ); + + if ( geometryAttribute === true ) { + + const attribute = builder.geometry.getAttribute( attributeName ); + const attributeType = builder.getTypeFromAttribute( attribute ); + + const nodeAttribute = builder.getAttribute( attributeName, attributeType ); + + if ( builder.shaderStage === 'vertex' ) { + + return builder.format( nodeAttribute.name, attributeType, nodeType ); + + } else { + + const nodeVarying = varying( this ); + + return nodeVarying.build( builder, nodeType ); + + } + + } else { + + console.warn( `AttributeNode: Vertex attribute "${ attributeName }" not found on geometry.` ); + + return builder.generateConst( nodeType ); + + } + + } + + serialize( data ) { + + super.serialize( data ); + + data.global = this.global; + data._attributeName = this._attributeName; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.global = data.global; + this._attributeName = data._attributeName; + + } + +} + +const attribute = ( name, nodeType ) => nodeObject( new AttributeNode( name, nodeType ) ); + +const uv = ( index ) => attribute( 'uv' + ( index > 0 ? index : '' ), 'vec2' ); + +class TextureSizeNode extends Node { + + static get type() { + + return 'TextureSizeNode'; + + } + + constructor( textureNode, levelNode = null ) { + + super( 'uvec2' ); + + this.isTextureSizeNode = true; + + this.textureNode = textureNode; + this.levelNode = levelNode; + + } + + generate( builder, output ) { + + const textureProperty = this.textureNode.build( builder, 'property' ); + const level = this.levelNode === null ? '0' : this.levelNode.build( builder, 'int' ); + + return builder.format( `${ builder.getMethod( 'textureDimensions' ) }( ${ textureProperty }, ${ level } )`, this.getNodeType( builder ), output ); + + } + +} + +const textureSize = /*@__PURE__*/ nodeProxy( TextureSizeNode ); + +class MaxMipLevelNode extends UniformNode { + + static get type() { + + return 'MaxMipLevelNode'; + + } + + constructor( textureNode ) { + + super( 0 ); + + this._textureNode = textureNode; + + this.updateType = NodeUpdateType.FRAME; + + } + + get textureNode() { + + return this._textureNode; + + } + + get texture() { + + return this._textureNode.value; + + } + + update() { + + const texture = this.texture; + const images = texture.images; + const image = ( images && images.length > 0 ) ? ( ( images[ 0 ] && images[ 0 ].image ) || images[ 0 ] ) : texture.image; + + if ( image && image.width !== undefined ) { + + const { width, height } = image; + + this.value = Math.log2( Math.max( width, height ) ); + + } + + } + +} + +const maxMipLevel = /*@__PURE__*/ nodeProxy( MaxMipLevelNode ); + +class TextureNode extends UniformNode { + + static get type() { + + return 'TextureNode'; + + } + + constructor( value, uvNode = null, levelNode = null, biasNode = null ) { + + super( value ); + + this.isTextureNode = true; + + this.uvNode = uvNode; + this.levelNode = levelNode; + this.biasNode = biasNode; + this.compareNode = null; + this.depthNode = null; + this.gradNode = null; + + this.sampler = true; + this.updateMatrix = false; + this.updateType = NodeUpdateType.NONE; + + this.referenceNode = null; + + this._value = value; + this._matrixUniform = null; + + this.setUpdateMatrix( uvNode === null ); + + } + + set value( value ) { + + if ( this.referenceNode ) { + + this.referenceNode.value = value; + + } else { + + this._value = value; + + } + + } + + get value() { + + return this.referenceNode ? this.referenceNode.value : this._value; + + } + + getUniformHash( /*builder*/ ) { + + return this.value.uuid; + + } + + getNodeType( /*builder*/ ) { + + if ( this.value.isDepthTexture === true ) return 'float'; + + if ( this.value.type === UnsignedIntType ) { + + return 'uvec4'; + + } else if ( this.value.type === IntType ) { + + return 'ivec4'; + + } + + return 'vec4'; + + } + + getInputType( /*builder*/ ) { + + return 'texture'; + + } + + getDefaultUV() { + + return uv( this.value.channel ); + + } + + updateReference( /*state*/ ) { + + return this.value; + + } + + getTransformedUV( uvNode ) { + + if ( this._matrixUniform === null ) this._matrixUniform = uniform( this.value.matrix ); + + return this._matrixUniform.mul( vec3( uvNode, 1 ) ).xy; + + } + + setUpdateMatrix( value ) { + + this.updateMatrix = value; + this.updateType = value ? NodeUpdateType.FRAME : NodeUpdateType.NONE; + + return this; + + } + + setupUV( builder, uvNode ) { + + const texture = this.value; + + if ( builder.isFlipY() && ( ( texture.image instanceof ImageBitmap && texture.flipY === true ) || texture.isRenderTargetTexture === true || texture.isFramebufferTexture === true || texture.isDepthTexture === true ) ) { + + if ( this.sampler ) { + + uvNode = uvNode.flipY(); + + } else { + + uvNode = uvNode.setY( int( textureSize( this, this.levelNode ).y ).sub( uvNode.y ).sub( 1 ) ); + + } + + } + + return uvNode; + + } + + setup( builder ) { + + const properties = builder.getNodeProperties( this ); + properties.referenceNode = this.referenceNode; + + // + + let uvNode = this.uvNode; + + if ( ( uvNode === null || builder.context.forceUVContext === true ) && builder.context.getUV ) { + + uvNode = builder.context.getUV( this ); + + } + + if ( ! uvNode ) uvNode = this.getDefaultUV(); + + if ( this.updateMatrix === true ) { + + uvNode = this.getTransformedUV( uvNode ); + + } + + uvNode = this.setupUV( builder, uvNode ); + + // + + let levelNode = this.levelNode; + + if ( levelNode === null && builder.context.getTextureLevel ) { + + levelNode = builder.context.getTextureLevel( this ); + + } + + // + + properties.uvNode = uvNode; + properties.levelNode = levelNode; + properties.biasNode = this.biasNode; + properties.compareNode = this.compareNode; + properties.gradNode = this.gradNode; + properties.depthNode = this.depthNode; + + } + + generateUV( builder, uvNode ) { + + return uvNode.build( builder, this.sampler === true ? 'vec2' : 'ivec2' ); + + } + + generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet ) { + + const texture = this.value; + + let snippet; + + if ( levelSnippet ) { + + snippet = builder.generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet ); + + } else if ( biasSnippet ) { + + snippet = builder.generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet ); + + } else if ( gradSnippet ) { + + snippet = builder.generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet ); + + } else if ( compareSnippet ) { + + snippet = builder.generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet ); + + } else if ( this.sampler === false ) { + + snippet = builder.generateTextureLoad( texture, textureProperty, uvSnippet, depthSnippet ); + + } else { + + snippet = builder.generateTexture( texture, textureProperty, uvSnippet, depthSnippet ); + + } + + return snippet; + + } + + generate( builder, output ) { + + const properties = builder.getNodeProperties( this ); + + const texture = this.value; + + if ( ! texture || texture.isTexture !== true ) { + + throw new Error( 'TextureNode: Need a three.js texture.' ); + + } + + const textureProperty = super.generate( builder, 'property' ); + + if ( output === 'sampler' ) { + + return textureProperty + '_sampler'; + + } else if ( builder.isReference( output ) ) { + + return textureProperty; + + } else { + + const nodeData = builder.getDataFromNode( this ); + + let propertyName = nodeData.propertyName; + + if ( propertyName === undefined ) { + + const { uvNode, levelNode, biasNode, compareNode, depthNode, gradNode } = properties; + + const uvSnippet = this.generateUV( builder, uvNode ); + const levelSnippet = levelNode ? levelNode.build( builder, 'float' ) : null; + const biasSnippet = biasNode ? biasNode.build( builder, 'float' ) : null; + const depthSnippet = depthNode ? depthNode.build( builder, 'int' ) : null; + const compareSnippet = compareNode ? compareNode.build( builder, 'float' ) : null; + const gradSnippet = gradNode ? [ gradNode[ 0 ].build( builder, 'vec2' ), gradNode[ 1 ].build( builder, 'vec2' ) ] : null; + + const nodeVar = builder.getVarFromNode( this ); + + propertyName = builder.getPropertyName( nodeVar ); + + const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet ); + + builder.addLineFlowCode( `${propertyName} = ${snippet}`, this ); + + nodeData.snippet = snippet; + nodeData.propertyName = propertyName; + + } + + let snippet = propertyName; + const nodeType = this.getNodeType( builder ); + + if ( builder.needsToWorkingColorSpace( texture ) ) { + + snippet = colorSpaceToWorking( expression( snippet, nodeType ), texture.colorSpace ).setup( builder ).build( builder, nodeType ); + + } + + return builder.format( snippet, nodeType, output ); + + } + + } + + setSampler( value ) { + + this.sampler = value; + + return this; + + } + + getSampler() { + + return this.sampler; + + } + + // @TODO: Move to TSL + + uv( uvNode ) { + + const textureNode = this.clone(); + textureNode.uvNode = nodeObject( uvNode ); + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + blur( amountNode ) { + + const textureNode = this.clone(); + textureNode.biasNode = nodeObject( amountNode ).mul( maxMipLevel( textureNode ) ); + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + level( levelNode ) { + + const textureNode = this.clone(); + textureNode.levelNode = nodeObject( levelNode ); + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + size( levelNode ) { + + return textureSize( this, levelNode ); + + } + + bias( biasNode ) { + + const textureNode = this.clone(); + textureNode.biasNode = nodeObject( biasNode ); + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + compare( compareNode ) { + + const textureNode = this.clone(); + textureNode.compareNode = nodeObject( compareNode ); + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + grad( gradNodeX, gradNodeY ) { + + const textureNode = this.clone(); + textureNode.gradNode = [ nodeObject( gradNodeX ), nodeObject( gradNodeY ) ]; + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + depth( depthNode ) { + + const textureNode = this.clone(); + textureNode.depthNode = nodeObject( depthNode ); + textureNode.referenceNode = this.getSelf(); + + return nodeObject( textureNode ); + + } + + // -- + + serialize( data ) { + + super.serialize( data ); + + data.value = this.value.toJSON( data.meta ).uuid; + data.sampler = this.sampler; + data.updateMatrix = this.updateMatrix; + data.updateType = this.updateType; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.value = data.meta.textures[ data.value ]; + this.sampler = data.sampler; + this.updateMatrix = data.updateMatrix; + this.updateType = data.updateType; + + } + + update() { + + const texture = this.value; + const matrixUniform = this._matrixUniform; + + if ( matrixUniform !== null ) matrixUniform.value = texture.matrix; + + if ( texture.matrixAutoUpdate === true ) { + + texture.updateMatrix(); + + } + + } + + clone() { + + const newNode = new this.constructor( this.value, this.uvNode, this.levelNode, this.biasNode ); + newNode.sampler = this.sampler; + + return newNode; + + } + +} + +const texture = /*@__PURE__*/ nodeProxy( TextureNode ); +const textureLoad = ( ...params ) => texture( ...params ).setSampler( false ); + +//export const textureLevel = ( value, uv, level ) => texture( value, uv ).level( level ); + +const sampler = ( aTexture ) => ( aTexture.isNode === true ? aTexture : texture( aTexture ) ).convert( 'sampler' ); + +const cameraNear = /*@__PURE__*/ uniform( 'float' ).label( 'cameraNear' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.near ); +const cameraFar = /*@__PURE__*/ uniform( 'float' ).label( 'cameraFar' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.far ); +const cameraProjectionMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrix ); +const cameraProjectionMatrixInverse = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrixInverse' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrixInverse ); +const cameraViewMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraViewMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorldInverse ); +const cameraWorldMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraWorldMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorld ); +const cameraNormalMatrix = /*@__PURE__*/ uniform( 'mat3' ).label( 'cameraNormalMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.normalMatrix ); +const cameraPosition = /*@__PURE__*/ uniform( new Vector3() ).label( 'cameraPosition' ).setGroup( renderGroup ).onRenderUpdate( ( { camera }, self ) => self.value.setFromMatrixPosition( camera.matrixWorld ) ); + +class Object3DNode extends Node { + + static get type() { + + return 'Object3DNode'; + + } + + constructor( scope, object3d = null ) { + + super(); + + this.scope = scope; + this.object3d = object3d; + + this.updateType = NodeUpdateType.OBJECT; + + this._uniformNode = new UniformNode( null ); + + } + + getNodeType() { + + const scope = this.scope; + + if ( scope === Object3DNode.WORLD_MATRIX ) { + + return 'mat4'; + + } else if ( scope === Object3DNode.POSITION || scope === Object3DNode.VIEW_POSITION || scope === Object3DNode.DIRECTION || scope === Object3DNode.SCALE ) { + + return 'vec3'; + + } + + } + + update( frame ) { + + const object = this.object3d; + const uniformNode = this._uniformNode; + const scope = this.scope; + + if ( scope === Object3DNode.WORLD_MATRIX ) { + + uniformNode.value = object.matrixWorld; + + } else if ( scope === Object3DNode.POSITION ) { + + uniformNode.value = uniformNode.value || new Vector3(); + + uniformNode.value.setFromMatrixPosition( object.matrixWorld ); + + } else if ( scope === Object3DNode.SCALE ) { + + uniformNode.value = uniformNode.value || new Vector3(); + + uniformNode.value.setFromMatrixScale( object.matrixWorld ); + + } else if ( scope === Object3DNode.DIRECTION ) { + + uniformNode.value = uniformNode.value || new Vector3(); + + object.getWorldDirection( uniformNode.value ); + + } else if ( scope === Object3DNode.VIEW_POSITION ) { + + const camera = frame.camera; + + uniformNode.value = uniformNode.value || new Vector3(); + uniformNode.value.setFromMatrixPosition( object.matrixWorld ); + + uniformNode.value.applyMatrix4( camera.matrixWorldInverse ); + + } + + } + + generate( builder ) { + + const scope = this.scope; + + if ( scope === Object3DNode.WORLD_MATRIX ) { + + this._uniformNode.nodeType = 'mat4'; + + } else if ( scope === Object3DNode.POSITION || scope === Object3DNode.VIEW_POSITION || scope === Object3DNode.DIRECTION || scope === Object3DNode.SCALE ) { + + this._uniformNode.nodeType = 'vec3'; + + } + + return this._uniformNode.build( builder ); + + } + + serialize( data ) { + + super.serialize( data ); + + data.scope = this.scope; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.scope = data.scope; + + } + +} + +Object3DNode.WORLD_MATRIX = 'worldMatrix'; +Object3DNode.POSITION = 'position'; +Object3DNode.SCALE = 'scale'; +Object3DNode.VIEW_POSITION = 'viewPosition'; +Object3DNode.DIRECTION = 'direction'; + +const objectDirection = /*@__PURE__*/ nodeProxy( Object3DNode, Object3DNode.DIRECTION ); +const objectWorldMatrix = /*@__PURE__*/ nodeProxy( Object3DNode, Object3DNode.WORLD_MATRIX ); +const objectPosition = /*@__PURE__*/ nodeProxy( Object3DNode, Object3DNode.POSITION ); +const objectScale = /*@__PURE__*/ nodeProxy( Object3DNode, Object3DNode.SCALE ); +const objectViewPosition = /*@__PURE__*/ nodeProxy( Object3DNode, Object3DNode.VIEW_POSITION ); + +class ModelNode extends Object3DNode { + + static get type() { + + return 'ModelNode'; + + } + + constructor( scope ) { + + super( scope ); + + } + + update( frame ) { + + this.object3d = frame.object; + + super.update( frame ); + + } + +} + +const modelDirection = /*@__PURE__*/ nodeImmutable( ModelNode, ModelNode.DIRECTION ); +const modelWorldMatrix = /*@__PURE__*/ nodeImmutable( ModelNode, ModelNode.WORLD_MATRIX ); +const modelPosition = /*@__PURE__*/ nodeImmutable( ModelNode, ModelNode.POSITION ); +const modelScale = /*@__PURE__*/ nodeImmutable( ModelNode, ModelNode.SCALE ); +const modelViewPosition = /*@__PURE__*/ nodeImmutable( ModelNode, ModelNode.VIEW_POSITION ); +const modelNormalMatrix = /*@__PURE__*/ uniform( new Matrix3() ).onObjectUpdate( ( { object }, self ) => self.value.getNormalMatrix( object.matrixWorld ) ); +const modelWorldMatrixInverse = /*@__PURE__*/ uniform( new Matrix4() ).onObjectUpdate( ( { object }, self ) => self.value.copy( object.matrixWorld ).invert() ); +const modelViewMatrix = /*@__PURE__*/ cameraViewMatrix.mul( modelWorldMatrix ).toVar( 'modelViewMatrix' ); + +const highPrecisionModelViewMatrix = /*@__PURE__*/ ( Fn( ( builder ) => { + + builder.context.isHighPrecisionModelViewMatrix = true; + + return uniform( 'mat4' ).onObjectUpdate( ( { object, camera } ) => { + + return object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld ); + + } ); + +} ).once() )().toVar( 'highPrecisionModelViewMatrix' ); + +const highPrecisionModelNormalViewMatrix = /*@__PURE__*/ ( Fn( ( builder ) => { + + const isHighPrecisionModelViewMatrix = builder.context.isHighPrecisionModelViewMatrix; + + return uniform( 'mat3' ).onObjectUpdate( ( { object, camera } ) => { + + if ( isHighPrecisionModelViewMatrix !== true ) { + + object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld ); + + } + + return object.normalMatrix.getNormalMatrix( object.modelViewMatrix ); + + } ); + +} ).once() )().toVar( 'highPrecisionModelNormalMatrix' ); + +const positionGeometry = /*@__PURE__*/ attribute( 'position', 'vec3' ); +const positionLocal = /*@__PURE__*/ positionGeometry.varying( 'positionLocal' ); +const positionPrevious = /*@__PURE__*/ positionGeometry.varying( 'positionPrevious' ); +const positionWorld = /*@__PURE__*/ modelWorldMatrix.mul( positionLocal ).xyz.varying( 'v_positionWorld' ); +const positionWorldDirection = /*@__PURE__*/ positionLocal.transformDirection( modelWorldMatrix ).varying( 'v_positionWorldDirection' ).normalize().toVar( 'positionWorldDirection' ); +const positionView = /*@__PURE__*/ modelViewMatrix.mul( positionLocal ).xyz.varying( 'v_positionView' ); +const positionViewDirection = /*@__PURE__*/ positionView.negate().varying( 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' ); + +class FrontFacingNode extends Node { + + static get type() { + + return 'FrontFacingNode'; + + } + + constructor() { + + super( 'bool' ); + + this.isFrontFacingNode = true; + + } + + generate( builder ) { + + const { renderer, material } = builder; + + if ( renderer.coordinateSystem === WebGLCoordinateSystem ) { + + if ( material.side === BackSide ) { + + return 'false'; + + } + + } + + return builder.getFrontFacing(); + + } + +} + +const frontFacing = /*@__PURE__*/ nodeImmutable( FrontFacingNode ); +const faceDirection = /*@__PURE__*/ float( frontFacing ).mul( 2.0 ).sub( 1.0 ); + +const normalGeometry = /*@__PURE__*/ attribute( 'normal', 'vec3' ); + +const normalLocal = /*@__PURE__*/ ( Fn( ( builder ) => { + + if ( builder.geometry.hasAttribute( 'normal' ) === false ) { + + console.warn( 'TSL.NormalNode: Vertex attribute "normal" not found on geometry.' ); + + return vec3( 0, 1, 0 ); + + } + + return normalGeometry; + +}, 'vec3' ).once() )().toVar( 'normalLocal' ); + +const normalFlat = /*@__PURE__*/ positionView.dFdx().cross( positionView.dFdy() ).normalize().toVar( 'normalFlat' ); + +const normalView = /*@__PURE__*/ ( Fn( ( builder ) => { + + let node; + + if ( builder.material.flatShading === true ) { + + node = normalFlat; + + } else { + + node = varying( transformNormalToView( normalLocal ), 'v_normalView' ).normalize(); + + } + + return node; + +}, 'vec3' ).once() )().toVar( 'normalView' ); + +const normalWorld = /*@__PURE__*/ varying( normalView.transformDirection( cameraViewMatrix ), 'v_normalWorld' ).normalize().toVar( 'normalWorld' ); + +const transformedNormalView = /*@__PURE__*/ ( Fn( ( builder ) => { + + return builder.context.setupNormal(); + +}, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedNormalView' ); + + +const transformedNormalWorld = /*@__PURE__*/ transformedNormalView.transformDirection( cameraViewMatrix ).toVar( 'transformedNormalWorld' ); + +const transformedClearcoatNormalView = /*@__PURE__*/ ( Fn( ( builder ) => { + + return builder.context.setupClearcoatNormal(); + +}, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedClearcoatNormalView' ); + +const transformNormal = /*@__PURE__*/ Fn( ( [ normal, matrix = modelWorldMatrix ] ) => { + + const m = mat3( matrix ); + + const transformedNormal = normal.div( vec3( m[ 0 ].dot( m[ 0 ] ), m[ 1 ].dot( m[ 1 ] ), m[ 2 ].dot( m[ 2 ] ) ) ); + + return m.mul( transformedNormal ).xyz; + +} ); + +const transformNormalToView = /*@__PURE__*/ Fn( ( [ normal ], builder ) => { + + const modelNormalViewMatrix = builder.renderer.nodes.modelNormalViewMatrix; + + if ( modelNormalViewMatrix !== null ) { + + return modelNormalViewMatrix.transformDirection( normal ); + + } + + // + + const transformedNormal = modelNormalMatrix.mul( normal ); + + return cameraViewMatrix.transformDirection( transformedNormal ); + +} ); + +const materialRefractionRatio = /*@__PURE__*/ uniform( 0 ).onReference( ( { material } ) => material ).onRenderUpdate( ( { material } ) => material.refractionRatio ); + +const reflectView = /*@__PURE__*/ positionViewDirection.negate().reflect( transformedNormalView ); +const refractView = /*@__PURE__*/ positionViewDirection.negate().refract( transformedNormalView, materialRefractionRatio ); + +const reflectVector = /*@__PURE__*/ reflectView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' ); +const refractVector = /*@__PURE__*/ refractView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' ); + +class CubeTextureNode extends TextureNode { + + static get type() { + + return 'CubeTextureNode'; + + } + + constructor( value, uvNode = null, levelNode = null, biasNode = null ) { + + super( value, uvNode, levelNode, biasNode ); + + this.isCubeTextureNode = true; + + } + + getInputType( /*builder*/ ) { + + return 'cubeTexture'; + + } + + getDefaultUV() { + + const texture = this.value; + + if ( texture.mapping === CubeReflectionMapping ) { + + return reflectVector; + + } else if ( texture.mapping === CubeRefractionMapping ) { + + return refractVector; + + } else { + + console.error( 'THREE.CubeTextureNode: Mapping "%s" not supported.', texture.mapping ); + + return vec3( 0, 0, 0 ); + + } + + } + + setUpdateMatrix( /*updateMatrix*/ ) { } // Ignore .updateMatrix for CubeTextureNode + + setupUV( builder, uvNode ) { + + const texture = this.value; + + if ( builder.renderer.coordinateSystem === WebGPUCoordinateSystem || ! texture.isRenderTargetTexture ) { + + return vec3( uvNode.x.negate(), uvNode.yz ); + + } else { + + return uvNode; + + } + + } + + generateUV( builder, cubeUV ) { + + return cubeUV.build( builder, 'vec3' ); + + } + +} + +const cubeTexture = /*@__PURE__*/ nodeProxy( CubeTextureNode ); + +class BufferNode extends UniformNode { + + static get type() { + + return 'BufferNode'; + + } + + constructor( value, bufferType, bufferCount = 0 ) { + + super( value, bufferType ); + + this.isBufferNode = true; + + this.bufferType = bufferType; + this.bufferCount = bufferCount; + + } + + getElementType( builder ) { + + return this.getNodeType( builder ); + + } + + getInputType( /*builder*/ ) { + + return 'buffer'; + + } + +} + +const buffer = ( value, type, count ) => nodeObject( new BufferNode( value, type, count ) ); + +class UniformArrayElementNode extends ArrayElementNode { + + static get type() { + + return 'UniformArrayElementNode'; + + } + + constructor( arrayBuffer, indexNode ) { + + super( arrayBuffer, indexNode ); + + this.isArrayBufferElementNode = true; + + } + + generate( builder ) { + + const snippet = super.generate( builder ); + const type = this.getNodeType(); + + return builder.format( snippet, 'vec4', type ); + + } + +} + +class UniformArrayNode extends BufferNode { + + static get type() { + + return 'UniformArrayNode'; + + } + + constructor( value, elementType = null ) { + + super( null, 'vec4' ); + + this.array = value; + this.elementType = elementType; + + this._elementType = null; + this._elementLength = 0; + + this.updateType = NodeUpdateType.RENDER; + + this.isArrayBufferNode = true; + + } + + getElementType() { + + return this.elementType || this._elementType; + + } + + getElementLength() { + + return this._elementLength; + + } + + update( /*frame*/ ) { + + const { array, value } = this; + + const elementLength = this.getElementLength(); + const elementType = this.getElementType(); + + if ( elementLength === 1 ) { + + for ( let i = 0; i < array.length; i ++ ) { + + const index = i * 4; + + value[ index ] = array[ i ]; + + } + + } else if ( elementType === 'color' ) { + + for ( let i = 0; i < array.length; i ++ ) { + + const index = i * 4; + const vector = array[ i ]; + + value[ index ] = vector.r; + value[ index + 1 ] = vector.g; + value[ index + 2 ] = vector.b || 0; + //value[ index + 3 ] = vector.a || 0; + + } + + } else { + + for ( let i = 0; i < array.length; i ++ ) { + + const index = i * 4; + const vector = array[ i ]; + + value[ index ] = vector.x; + value[ index + 1 ] = vector.y; + value[ index + 2 ] = vector.z || 0; + value[ index + 3 ] = vector.w || 0; + + } + + } + + } + + setup( builder ) { + + const length = this.array.length; + + this._elementType = this.elementType === null ? getValueType( this.array[ 0 ] ) : this.elementType; + this._elementLength = builder.getTypeLength( this._elementType ); + + let arrayType = Float32Array; + + if ( this._elementType.charAt( 0 ) === 'i' ) arrayType = Int32Array; + else if ( this._elementType.charAt( 0 ) === 'u' ) arrayType = Uint32Array; + + this.value = new arrayType( length * 4 ); + this.bufferCount = length; + this.bufferType = builder.changeComponentType( 'vec4', builder.getComponentType( this._elementType ) ); + + return super.setup( builder ); + + } + + element( indexNode ) { + + return nodeObject( new UniformArrayElementNode( this, nodeObject( indexNode ) ) ); + + } + +} + +const uniformArray = ( values, nodeType ) => nodeObject( new UniformArrayNode( values, nodeType ) ); + +// + +const uniforms = ( values, nodeType ) => { // @deprecated, r168 + + console.warn( 'TSL.UniformArrayNode: uniforms() has been renamed to uniformArray().' ); + return nodeObject( new UniformArrayNode( values, nodeType ) ); + +}; + +class ReferenceElementNode extends ArrayElementNode { + + static get type() { + + return 'ReferenceElementNode'; + + } + + constructor( referenceNode, indexNode ) { + + super( referenceNode, indexNode ); + + this.referenceNode = referenceNode; + + this.isReferenceElementNode = true; + + } + + getNodeType() { + + return this.referenceNode.uniformType; + + } + + generate( builder ) { + + const snippet = super.generate( builder ); + const arrayType = this.referenceNode.getNodeType(); + const elementType = this.getNodeType(); + + return builder.format( snippet, arrayType, elementType ); + + } + +} + +// TODO: Extends this from ReferenceBaseNode +class ReferenceNode extends Node { + + static get type() { + + return 'ReferenceNode'; + + } + + constructor( property, uniformType, object = null, count = null ) { + + super(); + + this.property = property; + this.uniformType = uniformType; + this.object = object; + this.count = count; + + this.properties = property.split( '.' ); + this.reference = object; + this.node = null; + this.group = null; + this.name = null; + + this.updateType = NodeUpdateType.OBJECT; + + } + + element( indexNode ) { + + return nodeObject( new ReferenceElementNode( this, nodeObject( indexNode ) ) ); + + } + + setGroup( group ) { + + this.group = group; + + return this; + + } + + label( name ) { + + this.name = name; + + return this; + + } + + setNodeType( uniformType ) { + + let node = null; + + if ( this.count !== null ) { + + node = buffer( null, uniformType, this.count ); + + } else if ( Array.isArray( this.getValueFromReference() ) ) { + + node = uniformArray( null, uniformType ); + + } else if ( uniformType === 'texture' ) { + + node = texture( null ); + + } else if ( uniformType === 'cubeTexture' ) { + + node = cubeTexture( null ); + + } else { + + node = uniform( null, uniformType ); + + } + + if ( this.group !== null ) { + + node.setGroup( this.group ); + + } + + if ( this.name !== null ) node.label( this.name ); + + this.node = node.getSelf(); + + } + + getNodeType( builder ) { + + if ( this.node === null ) { + + this.updateReference( builder ); + this.updateValue(); + + } + + return this.node.getNodeType( builder ); + + } + + getValueFromReference( object = this.reference ) { + + const { properties } = this; + + let value = object[ properties[ 0 ] ]; + + for ( let i = 1; i < properties.length; i ++ ) { + + value = value[ properties[ i ] ]; + + } + + return value; + + } + + updateReference( state ) { + + this.reference = this.object !== null ? this.object : state.object; + + return this.reference; + + } + + setup() { + + this.updateValue(); + + return this.node; + + } + + update( /*frame*/ ) { + + this.updateValue(); + + } + + updateValue() { + + if ( this.node === null ) this.setNodeType( this.uniformType ); + + const value = this.getValueFromReference(); + + if ( Array.isArray( value ) ) { + + this.node.array = value; + + } else { + + this.node.value = value; + + } + + } + +} + +const reference = ( name, type, object ) => nodeObject( new ReferenceNode( name, type, object ) ); +const referenceBuffer = ( name, type, count, object ) => nodeObject( new ReferenceNode( name, type, object, count ) ); + +class MaterialReferenceNode extends ReferenceNode { + + static get type() { + + return 'MaterialReferenceNode'; + + } + + constructor( property, inputType, material = null ) { + + super( property, inputType, material ); + + this.material = material; + + //this.updateType = NodeUpdateType.RENDER; + + this.isMaterialReferenceNode = true; + + } + + /*setNodeType( node ) { + + super.setNodeType( node ); + + this.node.groupNode = renderGroup; + + }*/ + + updateReference( state ) { + + this.reference = this.material !== null ? this.material : state.material; + + return this.reference; + + } + +} + +const materialReference = ( name, type, material ) => nodeObject( new MaterialReferenceNode( name, type, material ) ); + +const tangentGeometry = /*@__PURE__*/ Fn( ( builder ) => { + + if ( builder.geometry.hasAttribute( 'tangent' ) === false ) { + + builder.geometry.computeTangents(); + + } + + return attribute( 'tangent', 'vec4' ); + +} )(); + +const tangentLocal = /*@__PURE__*/ tangentGeometry.xyz.toVar( 'tangentLocal' ); +const tangentView = /*@__PURE__*/ modelViewMatrix.mul( vec4( tangentLocal, 0 ) ).xyz.varying( 'v_tangentView' ).normalize().toVar( 'tangentView' ); +const tangentWorld = /*@__PURE__*/ tangentView.transformDirection( cameraViewMatrix ).varying( 'v_tangentWorld' ).normalize().toVar( 'tangentWorld' ); +const transformedTangentView = /*@__PURE__*/ tangentView.toVar( 'transformedTangentView' ); +const transformedTangentWorld = /*@__PURE__*/ transformedTangentView.transformDirection( cameraViewMatrix ).normalize().toVar( 'transformedTangentWorld' ); + +const getBitangent = ( crossNormalTangent ) => crossNormalTangent.mul( tangentGeometry.w ).xyz; + +const bitangentGeometry = /*@__PURE__*/ varying( getBitangent( normalGeometry.cross( tangentGeometry ) ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' ); +const bitangentLocal = /*@__PURE__*/ varying( getBitangent( normalLocal.cross( tangentLocal ) ), 'v_bitangentLocal' ).normalize().toVar( 'bitangentLocal' ); +const bitangentView = /*@__PURE__*/ varying( getBitangent( normalView.cross( tangentView ) ), 'v_bitangentView' ).normalize().toVar( 'bitangentView' ); +const bitangentWorld = /*@__PURE__*/ varying( getBitangent( normalWorld.cross( tangentWorld ) ), 'v_bitangentWorld' ).normalize().toVar( 'bitangentWorld' ); +const transformedBitangentView = /*@__PURE__*/ getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize().toVar( 'transformedBitangentView' ); +const transformedBitangentWorld = /*@__PURE__*/ transformedBitangentView.transformDirection( cameraViewMatrix ).normalize().toVar( 'transformedBitangentWorld' ); + +const TBNViewMatrix = /*@__PURE__*/ mat3( tangentView, bitangentView, normalView ); + +const parallaxDirection = /*@__PURE__*/ positionViewDirection.mul( TBNViewMatrix )/*.normalize()*/; +const parallaxUV = ( uv, scale ) => uv.sub( parallaxDirection.mul( scale ) ); + +const transformedBentNormalView = /*@__PURE__*/ ( () => { + + // https://google.github.io/filament/Filament.md.html#lighting/imagebasedlights/anisotropy + + let bentNormal = anisotropyB.cross( positionViewDirection ); + bentNormal = bentNormal.cross( anisotropyB ).normalize(); + bentNormal = mix( bentNormal, transformedNormalView, anisotropy.mul( roughness.oneMinus() ).oneMinus().pow2().pow2() ).normalize(); + + return bentNormal; + + +} )(); + +// Normal Mapping Without Precomputed Tangents +// http://www.thetenthplanet.de/archives/1180 + +const perturbNormal2Arb = /*@__PURE__*/ Fn( ( inputs ) => { + + const { eye_pos, surf_norm, mapN, uv } = inputs; + + const q0 = eye_pos.dFdx(); + const q1 = eye_pos.dFdy(); + const st0 = uv.dFdx(); + const st1 = uv.dFdy(); + + const N = surf_norm; // normalized + + const q1perp = q1.cross( N ); + const q0perp = N.cross( q0 ); + + const T = q1perp.mul( st0.x ).add( q0perp.mul( st1.x ) ); + const B = q1perp.mul( st0.y ).add( q0perp.mul( st1.y ) ); + + const det = T.dot( T ).max( B.dot( B ) ); + const scale = faceDirection.mul( det.inverseSqrt() ); + + return add( T.mul( mapN.x, scale ), B.mul( mapN.y, scale ), N.mul( mapN.z ) ).normalize(); + +} ); + +class NormalMapNode extends TempNode { + + static get type() { + + return 'NormalMapNode'; + + } + + constructor( node, scaleNode = null ) { + + super( 'vec3' ); + + this.node = node; + this.scaleNode = scaleNode; + + this.normalMapType = TangentSpaceNormalMap; + + } + + setup( builder ) { + + const { normalMapType, scaleNode } = this; + + let normalMap = this.node.mul( 2.0 ).sub( 1.0 ); + + if ( scaleNode !== null ) { + + normalMap = vec3( normalMap.xy.mul( scaleNode ), normalMap.z ); + + } + + let outputNode = null; + + if ( normalMapType === ObjectSpaceNormalMap ) { + + outputNode = transformNormalToView( normalMap ); + + } else if ( normalMapType === TangentSpaceNormalMap ) { + + const tangent = builder.hasGeometryAttribute( 'tangent' ); + + if ( tangent === true ) { + + outputNode = TBNViewMatrix.mul( normalMap ).normalize(); + + } else { + + outputNode = perturbNormal2Arb( { + eye_pos: positionView, + surf_norm: normalView, + mapN: normalMap, + uv: uv() + } ); + + } + + } + + return outputNode; + + } + +} + +const normalMap = /*@__PURE__*/ nodeProxy( NormalMapNode ); + +// Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen +// https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf + +const dHdxy_fwd = Fn( ( { textureNode, bumpScale } ) => { + + // It's used to preserve the same TextureNode instance + const sampleTexture = ( callback ) => textureNode.cache().context( { getUV: ( texNode ) => callback( texNode.uvNode || uv() ), forceUVContext: true } ); + + const Hll = float( sampleTexture( ( uvNode ) => uvNode ) ); + + return vec2( + float( sampleTexture( ( uvNode ) => uvNode.add( uvNode.dFdx() ) ) ).sub( Hll ), + float( sampleTexture( ( uvNode ) => uvNode.add( uvNode.dFdy() ) ) ).sub( Hll ) + ).mul( bumpScale ); + +} ); + +// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2) + +const perturbNormalArb = Fn( ( inputs ) => { + + const { surf_pos, surf_norm, dHdxy } = inputs; + + // normalize is done to ensure that the bump map looks the same regardless of the texture's scale + const vSigmaX = surf_pos.dFdx().normalize(); + const vSigmaY = surf_pos.dFdy().normalize(); + const vN = surf_norm; // normalized + + const R1 = vSigmaY.cross( vN ); + const R2 = vN.cross( vSigmaX ); + + const fDet = vSigmaX.dot( R1 ).mul( faceDirection ); + + const vGrad = fDet.sign().mul( dHdxy.x.mul( R1 ).add( dHdxy.y.mul( R2 ) ) ); + + return fDet.abs().mul( surf_norm ).sub( vGrad ).normalize(); + +} ); + +class BumpMapNode extends TempNode { + + static get type() { + + return 'BumpMapNode'; + + } + + constructor( textureNode, scaleNode = null ) { + + super( 'vec3' ); + + this.textureNode = textureNode; + this.scaleNode = scaleNode; + + } + + setup() { + + const bumpScale = this.scaleNode !== null ? this.scaleNode : 1; + const dHdxy = dHdxy_fwd( { textureNode: this.textureNode, bumpScale } ); + + return perturbNormalArb( { + surf_pos: positionView, + surf_norm: normalView, + dHdxy + } ); + + } + +} + +const bumpMap = /*@__PURE__*/ nodeProxy( BumpMapNode ); + +const _propertyCache = new Map(); + +class MaterialNode extends Node { + + static get type() { + + return 'MaterialNode'; + + } + + constructor( scope ) { + + super(); + + this.scope = scope; + + } + + getCache( property, type ) { + + let node = _propertyCache.get( property ); + + if ( node === undefined ) { + + node = materialReference( property, type ); + + _propertyCache.set( property, node ); + + } + + return node; + + } + + getFloat( property ) { + + return this.getCache( property, 'float' ); + + } + + getColor( property ) { + + return this.getCache( property, 'color' ); + + } + + getTexture( property ) { + + return this.getCache( property === 'map' ? 'map' : property + 'Map', 'texture' ); + + } + + setup( builder ) { + + const material = builder.context.material; + const scope = this.scope; + + let node = null; + + if ( scope === MaterialNode.COLOR ) { + + const colorNode = material.color !== undefined ? this.getColor( scope ) : vec3(); + + if ( material.map && material.map.isTexture === true ) { + + node = colorNode.mul( this.getTexture( 'map' ) ); + + } else { + + node = colorNode; + + } + + } else if ( scope === MaterialNode.OPACITY ) { + + const opacityNode = this.getFloat( scope ); + + if ( material.alphaMap && material.alphaMap.isTexture === true ) { + + node = opacityNode.mul( this.getTexture( 'alpha' ) ); + + } else { + + node = opacityNode; + + } + + } else if ( scope === MaterialNode.SPECULAR_STRENGTH ) { + + if ( material.specularMap && material.specularMap.isTexture === true ) { + + node = this.getTexture( 'specular' ).r; + + } else { + + node = float( 1 ); + + } + + } else if ( scope === MaterialNode.SPECULAR_INTENSITY ) { + + const specularIntensity = this.getFloat( scope ); + + if ( material.specularMap ) { + + node = specularIntensity.mul( this.getTexture( scope ).a ); + + } else { + + node = specularIntensity; + + } + + } else if ( scope === MaterialNode.SPECULAR_COLOR ) { + + const specularColorNode = this.getColor( scope ); + + if ( material.specularColorMap && material.specularColorMap.isTexture === true ) { + + node = specularColorNode.mul( this.getTexture( scope ).rgb ); + + } else { + + node = specularColorNode; + + } + + } else if ( scope === MaterialNode.ROUGHNESS ) { // TODO: cleanup similar branches + + const roughnessNode = this.getFloat( scope ); + + if ( material.roughnessMap && material.roughnessMap.isTexture === true ) { + + node = roughnessNode.mul( this.getTexture( scope ).g ); + + } else { + + node = roughnessNode; + + } + + } else if ( scope === MaterialNode.METALNESS ) { + + const metalnessNode = this.getFloat( scope ); + + if ( material.metalnessMap && material.metalnessMap.isTexture === true ) { + + node = metalnessNode.mul( this.getTexture( scope ).b ); + + } else { + + node = metalnessNode; + + } + + } else if ( scope === MaterialNode.EMISSIVE ) { + + const emissiveIntensityNode = this.getFloat( 'emissiveIntensity' ); + const emissiveNode = this.getColor( scope ).mul( emissiveIntensityNode ); + + if ( material.emissiveMap && material.emissiveMap.isTexture === true ) { + + node = emissiveNode.mul( this.getTexture( scope ) ); + + } else { + + node = emissiveNode; + + } + + } else if ( scope === MaterialNode.NORMAL ) { + + if ( material.normalMap ) { + + node = normalMap( this.getTexture( 'normal' ), this.getCache( 'normalScale', 'vec2' ) ); + node.normalMapType = material.normalMapType; + + } else if ( material.bumpMap ) { + + node = bumpMap( this.getTexture( 'bump' ).r, this.getFloat( 'bumpScale' ) ); + + } else { + + node = normalView; + + } + + } else if ( scope === MaterialNode.CLEARCOAT ) { + + const clearcoatNode = this.getFloat( scope ); + + if ( material.clearcoatMap && material.clearcoatMap.isTexture === true ) { + + node = clearcoatNode.mul( this.getTexture( scope ).r ); + + } else { + + node = clearcoatNode; + + } + + } else if ( scope === MaterialNode.CLEARCOAT_ROUGHNESS ) { + + const clearcoatRoughnessNode = this.getFloat( scope ); + + if ( material.clearcoatRoughnessMap && material.clearcoatRoughnessMap.isTexture === true ) { + + node = clearcoatRoughnessNode.mul( this.getTexture( scope ).r ); + + } else { + + node = clearcoatRoughnessNode; + + } + + } else if ( scope === MaterialNode.CLEARCOAT_NORMAL ) { + + if ( material.clearcoatNormalMap ) { + + node = normalMap( this.getTexture( scope ), this.getCache( scope + 'Scale', 'vec2' ) ); + + } else { + + node = normalView; + + } + + } else if ( scope === MaterialNode.SHEEN ) { + + const sheenNode = this.getColor( 'sheenColor' ).mul( this.getFloat( 'sheen' ) ); // Move this mul() to CPU + + if ( material.sheenColorMap && material.sheenColorMap.isTexture === true ) { + + node = sheenNode.mul( this.getTexture( 'sheenColor' ).rgb ); + + } else { + + node = sheenNode; + + } + + } else if ( scope === MaterialNode.SHEEN_ROUGHNESS ) { + + const sheenRoughnessNode = this.getFloat( scope ); + + if ( material.sheenRoughnessMap && material.sheenRoughnessMap.isTexture === true ) { + + node = sheenRoughnessNode.mul( this.getTexture( scope ).a ); + + } else { + + node = sheenRoughnessNode; + + } + + node = node.clamp( 0.07, 1.0 ); + + } else if ( scope === MaterialNode.ANISOTROPY ) { + + if ( material.anisotropyMap && material.anisotropyMap.isTexture === true ) { + + const anisotropyPolar = this.getTexture( scope ); + const anisotropyMat = mat2( materialAnisotropyVector.x, materialAnisotropyVector.y, materialAnisotropyVector.y.negate(), materialAnisotropyVector.x ); + + node = anisotropyMat.mul( anisotropyPolar.rg.mul( 2.0 ).sub( vec2( 1.0 ) ).normalize().mul( anisotropyPolar.b ) ); + + } else { + + node = materialAnisotropyVector; + + } + + } else if ( scope === MaterialNode.IRIDESCENCE_THICKNESS ) { + + const iridescenceThicknessMaximum = reference( '1', 'float', material.iridescenceThicknessRange ); + + if ( material.iridescenceThicknessMap ) { + + const iridescenceThicknessMinimum = reference( '0', 'float', material.iridescenceThicknessRange ); + + node = iridescenceThicknessMaximum.sub( iridescenceThicknessMinimum ).mul( this.getTexture( scope ).g ).add( iridescenceThicknessMinimum ); + + } else { + + node = iridescenceThicknessMaximum; + + } + + } else if ( scope === MaterialNode.TRANSMISSION ) { + + const transmissionNode = this.getFloat( scope ); + + if ( material.transmissionMap ) { + + node = transmissionNode.mul( this.getTexture( scope ).r ); + + } else { + + node = transmissionNode; + + } + + } else if ( scope === MaterialNode.THICKNESS ) { + + const thicknessNode = this.getFloat( scope ); + + if ( material.thicknessMap ) { + + node = thicknessNode.mul( this.getTexture( scope ).g ); + + } else { + + node = thicknessNode; + + } + + } else if ( scope === MaterialNode.IOR ) { + + node = this.getFloat( scope ); + + } else if ( scope === MaterialNode.LIGHT_MAP ) { + + node = this.getTexture( scope ).rgb.mul( this.getFloat( 'lightMapIntensity' ) ); + + } else if ( scope === MaterialNode.AO_MAP ) { + + node = this.getTexture( scope ).r.sub( 1.0 ).mul( this.getFloat( 'aoMapIntensity' ) ).add( 1.0 ); + + } else { + + const outputType = this.getNodeType( builder ); + + node = this.getCache( scope, outputType ); + + } + + return node; + + } + +} + +MaterialNode.ALPHA_TEST = 'alphaTest'; +MaterialNode.COLOR = 'color'; +MaterialNode.OPACITY = 'opacity'; +MaterialNode.SHININESS = 'shininess'; +MaterialNode.SPECULAR = 'specular'; +MaterialNode.SPECULAR_STRENGTH = 'specularStrength'; +MaterialNode.SPECULAR_INTENSITY = 'specularIntensity'; +MaterialNode.SPECULAR_COLOR = 'specularColor'; +MaterialNode.REFLECTIVITY = 'reflectivity'; +MaterialNode.ROUGHNESS = 'roughness'; +MaterialNode.METALNESS = 'metalness'; +MaterialNode.NORMAL = 'normal'; +MaterialNode.CLEARCOAT = 'clearcoat'; +MaterialNode.CLEARCOAT_ROUGHNESS = 'clearcoatRoughness'; +MaterialNode.CLEARCOAT_NORMAL = 'clearcoatNormal'; +MaterialNode.EMISSIVE = 'emissive'; +MaterialNode.ROTATION = 'rotation'; +MaterialNode.SHEEN = 'sheen'; +MaterialNode.SHEEN_ROUGHNESS = 'sheenRoughness'; +MaterialNode.ANISOTROPY = 'anisotropy'; +MaterialNode.IRIDESCENCE = 'iridescence'; +MaterialNode.IRIDESCENCE_IOR = 'iridescenceIOR'; +MaterialNode.IRIDESCENCE_THICKNESS = 'iridescenceThickness'; +MaterialNode.IOR = 'ior'; +MaterialNode.TRANSMISSION = 'transmission'; +MaterialNode.THICKNESS = 'thickness'; +MaterialNode.ATTENUATION_DISTANCE = 'attenuationDistance'; +MaterialNode.ATTENUATION_COLOR = 'attenuationColor'; +MaterialNode.LINE_SCALE = 'scale'; +MaterialNode.LINE_DASH_SIZE = 'dashSize'; +MaterialNode.LINE_GAP_SIZE = 'gapSize'; +MaterialNode.LINE_WIDTH = 'linewidth'; +MaterialNode.LINE_DASH_OFFSET = 'dashOffset'; +MaterialNode.POINT_WIDTH = 'pointWidth'; +MaterialNode.DISPERSION = 'dispersion'; +MaterialNode.LIGHT_MAP = 'light'; +MaterialNode.AO_MAP = 'ao'; + +const materialAlphaTest = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ALPHA_TEST ); +const materialColor = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.COLOR ); +const materialShininess = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SHININESS ); +const materialEmissive = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.EMISSIVE ); +const materialOpacity = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.OPACITY ); +const materialSpecular = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR ); + +const materialSpecularIntensity = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR_INTENSITY ); +const materialSpecularColor = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR_COLOR ); + +const materialSpecularStrength = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR_STRENGTH ); +const materialReflectivity = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.REFLECTIVITY ); +const materialRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ROUGHNESS ); +const materialMetalness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.METALNESS ); +const materialNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.NORMAL ).context( { getUV: null } ); +const materialClearcoat = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT ); +const materialClearcoatRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_ROUGHNESS ); +const materialClearcoatNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_NORMAL ).context( { getUV: null } ); +const materialRotation = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ROTATION ); +const materialSheen = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SHEEN ); +const materialSheenRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SHEEN_ROUGHNESS ); +const materialAnisotropy = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ANISOTROPY ); +const materialIridescence = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE ); +const materialIridescenceIOR = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_IOR ); +const materialIridescenceThickness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_THICKNESS ); +const materialTransmission = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.TRANSMISSION ); +const materialThickness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.THICKNESS ); +const materialIOR = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IOR ); +const materialAttenuationDistance = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_DISTANCE ); +const materialAttenuationColor = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_COLOR ); +const materialLineScale = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_SCALE ); +const materialLineDashSize = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_SIZE ); +const materialLineGapSize = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_GAP_SIZE ); +const materialLineWidth = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_WIDTH ); +const materialLineDashOffset = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_OFFSET ); +const materialPointWidth = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.POINT_WIDTH ); +const materialDispersion = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.DISPERSION ); +const materialLightMap = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LIGHT_MAP ); +const materialAOMap = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.AO_MAP ); +const materialAnisotropyVector = /*@__PURE__*/ uniform( new Vector2() ).onReference( function ( frame ) { + + return frame.material; + +} ).onRenderUpdate( function ( { material } ) { + + this.value.set( material.anisotropy * Math.cos( material.anisotropyRotation ), material.anisotropy * Math.sin( material.anisotropyRotation ) ); + +} ); + +class ModelViewProjectionNode extends TempNode { + + static get type() { + + return 'ModelViewProjectionNode'; + + } + + constructor( positionNode = null ) { + + super( 'vec4' ); + + this.positionNode = positionNode; + + } + + setup( builder ) { + + if ( builder.shaderStage === 'fragment' ) { + + return varying( builder.context.mvp ); + + } + + const position = this.positionNode || positionLocal; + const viewMatrix = builder.renderer.nodes.modelViewMatrix || modelViewMatrix; + + return cameraProjectionMatrix.mul( viewMatrix ).mul( position ); + + } + +} + +const modelViewProjection = /*@__PURE__*/ nodeProxy( ModelViewProjectionNode ); + +class IndexNode extends Node { + + static get type() { + + return 'IndexNode'; + + } + + constructor( scope ) { + + super( 'uint' ); + + this.scope = scope; + + this.isInstanceIndexNode = true; + + } + + generate( builder ) { + + const nodeType = this.getNodeType( builder ); + const scope = this.scope; + + let propertyName; + + if ( scope === IndexNode.VERTEX ) { + + // The index of a vertex within a mesh. + propertyName = builder.getVertexIndex(); + + } else if ( scope === IndexNode.INSTANCE ) { + + // The index of either a mesh instance or an invocation of a compute shader. + propertyName = builder.getInstanceIndex(); + + } else if ( scope === IndexNode.DRAW ) { + + // The index of a draw call. + propertyName = builder.getDrawIndex(); + + } else if ( scope === IndexNode.INVOCATION_LOCAL ) { + + // The index of a compute invocation within the scope of a workgroup load. + propertyName = builder.getInvocationLocalIndex(); + + } else if ( scope === IndexNode.INVOCATION_SUBGROUP ) { + + // The index of a compute invocation within the scope of a subgroup. + propertyName = builder.getInvocationSubgroupIndex(); + + } else if ( scope === IndexNode.SUBGROUP ) { + + // The index of the subgroup the current compute invocation belongs to. + propertyName = builder.getSubgroupIndex(); + + } else { + + throw new Error( 'THREE.IndexNode: Unknown scope: ' + scope ); + + } + + let output; + + if ( builder.shaderStage === 'vertex' || builder.shaderStage === 'compute' ) { + + output = propertyName; + + } else { + + const nodeVarying = varying( this ); + + output = nodeVarying.build( builder, nodeType ); + + } + + return output; + + } + +} + +IndexNode.VERTEX = 'vertex'; +IndexNode.INSTANCE = 'instance'; +IndexNode.SUBGROUP = 'subgroup'; +IndexNode.INVOCATION_LOCAL = 'invocationLocal'; +IndexNode.INVOCATION_SUBGROUP = 'invocationSubgroup'; +IndexNode.DRAW = 'draw'; + +const vertexIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.VERTEX ); +const instanceIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.INSTANCE ); +const subgroupIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.SUBGROUP ); +const invocationSubgroupIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.INVOCATION_SUBGROUP ); +const invocationLocalIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.INVOCATION_LOCAL ); +const drawIndex = /*@__PURE__*/ nodeImmutable( IndexNode, IndexNode.DRAW ); + +class InstanceNode extends Node { + + static get type() { + + return 'InstanceNode'; + + } + + constructor( count, instanceMatrix, instanceColor ) { + + super( 'void' ); + + this.count = count; + this.instanceMatrix = instanceMatrix; + this.instanceColor = instanceColor; + + this.instanceMatrixNode = null; + + this.instanceColorNode = null; + + this.updateType = NodeUpdateType.FRAME; + + this.buffer = null; + this.bufferColor = null; + + } + + setup( builder ) { + + const { count, instanceMatrix, instanceColor } = this; + + let { instanceMatrixNode, instanceColorNode } = this; + + if ( instanceMatrixNode === null ) { + + // Both WebGPU and WebGL backends have UBO max limited to 64kb. Matrix count number bigger than 1000 ( 16 * 4 * 1000 = 64kb ) will fallback to attribute. + + if ( count <= 1000 ) { + + instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex ); + + } else { + + const buffer = new InstancedInterleavedBuffer( instanceMatrix.array, 16, 1 ); + + this.buffer = buffer; + + const bufferFn = instanceMatrix.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute; + + const instanceBuffers = [ + // F.Signature -> bufferAttribute( array, type, stride, offset ) + bufferFn( buffer, 'vec4', 16, 0 ), + bufferFn( buffer, 'vec4', 16, 4 ), + bufferFn( buffer, 'vec4', 16, 8 ), + bufferFn( buffer, 'vec4', 16, 12 ) + ]; + + instanceMatrixNode = mat4( ...instanceBuffers ); + + } + + this.instanceMatrixNode = instanceMatrixNode; + + } + + if ( instanceColor && instanceColorNode === null ) { + + const buffer = new InstancedBufferAttribute( instanceColor.array, 3 ); + + const bufferFn = instanceColor.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute; + + this.bufferColor = buffer; + + instanceColorNode = vec3( bufferFn( buffer, 'vec3', 3, 0 ) ); + + this.instanceColorNode = instanceColorNode; + + } + + // POSITION + + const instancePosition = instanceMatrixNode.mul( positionLocal ).xyz; + positionLocal.assign( instancePosition ); + + // NORMAL + + if ( builder.hasGeometryAttribute( 'normal' ) ) { + + const instanceNormal = transformNormal( normalLocal, instanceMatrixNode ); + + // ASSIGNS + + normalLocal.assign( instanceNormal ); + + } + + // COLOR + + if ( this.instanceColorNode !== null ) { + + varyingProperty( 'vec3', 'vInstanceColor' ).assign( this.instanceColorNode ); + + } + + } + + update( /*frame*/ ) { + + if ( this.instanceMatrix.usage !== DynamicDrawUsage && this.buffer != null && this.instanceMatrix.version !== this.buffer.version ) { + + this.buffer.version = this.instanceMatrix.version; + + } + + if ( this.instanceColor && this.instanceColor.usage !== DynamicDrawUsage && this.bufferColor != null && this.instanceColor.version !== this.bufferColor.version ) { + + this.bufferColor.version = this.instanceColor.version; + + } + + } + +} + +const instance = /*@__PURE__*/ nodeProxy( InstanceNode ); + +class InstancedMeshNode extends InstanceNode { + + static get type() { + + return 'InstancedMeshNode'; + + } + + constructor( instanceMesh ) { + + const { count, instanceMatrix, instanceColor } = instanceMesh; + + super( count, instanceMatrix, instanceColor ); + + this.instanceMesh = instanceMesh; + + } + +} + +const instancedMesh = /*@__PURE__*/ nodeProxy( InstancedMeshNode ); + +class BatchNode extends Node { + + static get type() { + + return 'BatchNode'; + + } + + constructor( batchMesh ) { + + super( 'void' ); + + this.batchMesh = batchMesh; + + + this.batchingIdNode = null; + + } + + setup( builder ) { + + // POSITION + + if ( this.batchingIdNode === null ) { + + if ( builder.getDrawIndex() === null ) { + + this.batchingIdNode = instanceIndex; + + } else { + + this.batchingIdNode = drawIndex; + + } + + } + + const getIndirectIndex = Fn( ( [ id ] ) => { + + const size = textureSize( textureLoad( this.batchMesh._indirectTexture ), 0 ); + const x = int( id ).modInt( int( size ) ); + const y = int( id ).div( int( size ) ); + return textureLoad( this.batchMesh._indirectTexture, ivec2( x, y ) ).x; + + } ).setLayout( { + name: 'getIndirectIndex', + type: 'uint', + inputs: [ + { name: 'id', type: 'int' } + ] + } ); + + const indirectId = getIndirectIndex( int( this.batchingIdNode ) ); + + const matricesTexture = this.batchMesh._matricesTexture; + + const size = textureSize( textureLoad( matricesTexture ), 0 ); + const j = float( indirectId ).mul( 4 ).toInt().toVar(); + + const x = j.modInt( size ); + const y = j.div( int( size ) ); + const batchingMatrix = mat4( + textureLoad( matricesTexture, ivec2( x, y ) ), + textureLoad( matricesTexture, ivec2( x.add( 1 ), y ) ), + textureLoad( matricesTexture, ivec2( x.add( 2 ), y ) ), + textureLoad( matricesTexture, ivec2( x.add( 3 ), y ) ) + ); + + + const colorsTexture = this.batchMesh._colorsTexture; + + if ( colorsTexture !== null ) { + + const getBatchingColor = Fn( ( [ id ] ) => { + + const size = textureSize( textureLoad( colorsTexture ), 0 ).x; + const j = id; + const x = j.modInt( size ); + const y = j.div( size ); + return textureLoad( colorsTexture, ivec2( x, y ) ).rgb; + + } ).setLayout( { + name: 'getBatchingColor', + type: 'vec3', + inputs: [ + { name: 'id', type: 'int' } + ] + } ); + + const color = getBatchingColor( indirectId ); + + varyingProperty( 'vec3', 'vBatchColor' ).assign( color ); + + } + + const bm = mat3( batchingMatrix ); + + positionLocal.assign( batchingMatrix.mul( positionLocal ) ); + + const transformedNormal = normalLocal.div( vec3( bm[ 0 ].dot( bm[ 0 ] ), bm[ 1 ].dot( bm[ 1 ] ), bm[ 2 ].dot( bm[ 2 ] ) ) ); + + const batchingNormal = bm.mul( transformedNormal ).xyz; + + normalLocal.assign( batchingNormal ); + + if ( builder.hasGeometryAttribute( 'tangent' ) ) { + + tangentLocal.mulAssign( bm ); + + } + + } + +} + +const batch = /*@__PURE__*/ nodeProxy( BatchNode ); + +const _frameId = new WeakMap(); + +class SkinningNode extends Node { + + static get type() { + + return 'SkinningNode'; + + } + + constructor( skinnedMesh, useReference = false ) { + + super( 'void' ); + + this.skinnedMesh = skinnedMesh; + this.useReference = useReference; + + this.updateType = NodeUpdateType.OBJECT; + + // + + this.skinIndexNode = attribute( 'skinIndex', 'uvec4' ); + this.skinWeightNode = attribute( 'skinWeight', 'vec4' ); + + let bindMatrixNode, bindMatrixInverseNode, boneMatricesNode; + + if ( useReference ) { + + bindMatrixNode = reference( 'bindMatrix', 'mat4' ); + bindMatrixInverseNode = reference( 'bindMatrixInverse', 'mat4' ); + boneMatricesNode = referenceBuffer( 'skeleton.boneMatrices', 'mat4', skinnedMesh.skeleton.bones.length ); + + } else { + + bindMatrixNode = uniform( skinnedMesh.bindMatrix, 'mat4' ); + bindMatrixInverseNode = uniform( skinnedMesh.bindMatrixInverse, 'mat4' ); + boneMatricesNode = buffer( skinnedMesh.skeleton.boneMatrices, 'mat4', skinnedMesh.skeleton.bones.length ); + + } + + this.bindMatrixNode = bindMatrixNode; + this.bindMatrixInverseNode = bindMatrixInverseNode; + this.boneMatricesNode = boneMatricesNode; + this.previousBoneMatricesNode = null; + + } + + getSkinnedPosition( boneMatrices = this.boneMatricesNode, position = positionLocal ) { + + const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this; + + const boneMatX = boneMatrices.element( skinIndexNode.x ); + const boneMatY = boneMatrices.element( skinIndexNode.y ); + const boneMatZ = boneMatrices.element( skinIndexNode.z ); + const boneMatW = boneMatrices.element( skinIndexNode.w ); + + // POSITION + + const skinVertex = bindMatrixNode.mul( position ); + + const skinned = add( + boneMatX.mul( skinWeightNode.x ).mul( skinVertex ), + boneMatY.mul( skinWeightNode.y ).mul( skinVertex ), + boneMatZ.mul( skinWeightNode.z ).mul( skinVertex ), + boneMatW.mul( skinWeightNode.w ).mul( skinVertex ) + ); + + return bindMatrixInverseNode.mul( skinned ).xyz; + + } + + getSkinnedNormal( boneMatrices = this.boneMatricesNode, normal = normalLocal ) { + + const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode } = this; + + const boneMatX = boneMatrices.element( skinIndexNode.x ); + const boneMatY = boneMatrices.element( skinIndexNode.y ); + const boneMatZ = boneMatrices.element( skinIndexNode.z ); + const boneMatW = boneMatrices.element( skinIndexNode.w ); + + // NORMAL + + let skinMatrix = add( + skinWeightNode.x.mul( boneMatX ), + skinWeightNode.y.mul( boneMatY ), + skinWeightNode.z.mul( boneMatZ ), + skinWeightNode.w.mul( boneMatW ) + ); + + skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode ); + + return skinMatrix.transformDirection( normal ).xyz; + + } + + getPreviousSkinnedPosition( builder ) { + + const skinnedMesh = builder.object; + + if ( this.previousBoneMatricesNode === null ) { + + skinnedMesh.skeleton.previousBoneMatrices = new Float32Array( skinnedMesh.skeleton.boneMatrices ); + + this.previousBoneMatricesNode = referenceBuffer( 'skeleton.previousBoneMatrices', 'mat4', skinnedMesh.skeleton.bones.length ); + + } + + return this.getSkinnedPosition( this.previousBoneMatricesNode, positionPrevious ); + + } + + needsPreviousBoneMatrices( builder ) { + + const mrt = builder.renderer.getMRT(); + + return mrt && mrt.has( 'velocity' ); + + } + + setup( builder ) { + + if ( this.needsPreviousBoneMatrices( builder ) ) { + + positionPrevious.assign( this.getPreviousSkinnedPosition( builder ) ); + + } + + const skinPosition = this.getSkinnedPosition(); + + + positionLocal.assign( skinPosition ); + + if ( builder.hasGeometryAttribute( 'normal' ) ) { + + const skinNormal = this.getSkinnedNormal(); + + normalLocal.assign( skinNormal ); + + if ( builder.hasGeometryAttribute( 'tangent' ) ) { + + tangentLocal.assign( skinNormal ); + + } + + } + + } + + generate( builder, output ) { + + if ( output !== 'void' ) { + + return positionLocal.build( builder, output ); + + } + + } + + update( frame ) { + + const object = this.useReference ? frame.object : this.skinnedMesh; + const skeleton = object.skeleton; + + if ( _frameId.get( skeleton ) === frame.frameId ) return; + + _frameId.set( skeleton, frame.frameId ); + + if ( this.previousBoneMatricesNode !== null ) skeleton.previousBoneMatrices.set( skeleton.boneMatrices ); + + skeleton.update(); + + } + +} + +const skinning = ( skinnedMesh ) => nodeObject( new SkinningNode( skinnedMesh ) ); +const skinningReference = ( skinnedMesh ) => nodeObject( new SkinningNode( skinnedMesh, true ) ); + +class LoopNode extends Node { + + static get type() { + + return 'LoopNode'; + + } + + constructor( params = [] ) { + + super(); + + this.params = params; + + } + + getVarName( index ) { + + return String.fromCharCode( 'i'.charCodeAt() + index ); + + } + + getProperties( builder ) { + + const properties = builder.getNodeProperties( this ); + + if ( properties.stackNode !== undefined ) return properties; + + // + + const inputs = {}; + + for ( let i = 0, l = this.params.length - 1; i < l; i ++ ) { + + const param = this.params[ i ]; + + const name = ( param.isNode !== true && param.name ) || this.getVarName( i ); + const type = ( param.isNode !== true && param.type ) || 'int'; + + inputs[ name ] = expression( name, type ); + + } + + const stack = builder.addStack(); // TODO: cache() it + + properties.returnsNode = this.params[ this.params.length - 1 ]( inputs, stack, builder ); + properties.stackNode = stack; + + builder.removeStack(); + + return properties; + + } + + getNodeType( builder ) { + + const { returnsNode } = this.getProperties( builder ); + + return returnsNode ? returnsNode.getNodeType( builder ) : 'void'; + + } + + setup( builder ) { + + // setup properties + + this.getProperties( builder ); + + } + + generate( builder ) { + + const properties = this.getProperties( builder ); + + const params = this.params; + const stackNode = properties.stackNode; + + for ( let i = 0, l = params.length - 1; i < l; i ++ ) { + + const param = params[ i ]; + + let start = null, end = null, name = null, type = null, condition = null, update = null; + + if ( param.isNode ) { + + type = 'int'; + name = this.getVarName( i ); + start = '0'; + end = param.build( builder, type ); + condition = '<'; + + } else { + + type = param.type || 'int'; + name = param.name || this.getVarName( i ); + start = param.start; + end = param.end; + condition = param.condition; + update = param.update; + + if ( typeof start === 'number' ) start = builder.generateConst( type, start ); + else if ( start && start.isNode ) start = start.build( builder, type ); + + if ( typeof end === 'number' ) end = builder.generateConst( type, end ); + else if ( end && end.isNode ) end = end.build( builder, type ); + + if ( start !== undefined && end === undefined ) { + + start = start + ' - 1'; + end = '0'; + condition = '>='; + + } else if ( end !== undefined && start === undefined ) { + + start = '0'; + condition = '<'; + + } + + if ( condition === undefined ) { + + if ( Number( start ) > Number( end ) ) { + + condition = '>='; + + } else { + + condition = '<'; + + } + + } + + } + + const internalParam = { start, end, condition }; + + // + + const startSnippet = internalParam.start; + const endSnippet = internalParam.end; + + let declarationSnippet = ''; + let conditionalSnippet = ''; + let updateSnippet = ''; + + if ( ! update ) { + + if ( type === 'int' || type === 'uint' ) { + + if ( condition.includes( '<' ) ) update = '++'; + else update = '--'; + + } else { + + if ( condition.includes( '<' ) ) update = '+= 1.'; + else update = '-= 1.'; + + } + + } + + declarationSnippet += builder.getVar( type, name ) + ' = ' + startSnippet; + + conditionalSnippet += name + ' ' + condition + ' ' + endSnippet; + updateSnippet += name + ' ' + update; + + const forSnippet = `for ( ${ declarationSnippet }; ${ conditionalSnippet }; ${ updateSnippet } )`; + + builder.addFlowCode( ( i === 0 ? '\n' : '' ) + builder.tab + forSnippet + ' {\n\n' ).addFlowTab(); + + } + + const stackSnippet = stackNode.build( builder, 'void' ); + + const returnsSnippet = properties.returnsNode ? properties.returnsNode.build( builder ) : ''; + + builder.removeFlowTab().addFlowCode( '\n' + builder.tab + stackSnippet ); + + for ( let i = 0, l = this.params.length - 1; i < l; i ++ ) { + + builder.addFlowCode( ( i === 0 ? '' : builder.tab ) + '}\n\n' ).removeFlowTab(); + + } + + builder.addFlowTab(); + + return returnsSnippet; + + } + +} + +const Loop = ( ...params ) => nodeObject( new LoopNode( nodeArray( params, 'int' ) ) ).append(); +const Continue = () => expression( 'continue' ).append(); +const Break = () => expression( 'break' ).append(); + +// + +const loop = ( ...params ) => { // @deprecated, r168 + + console.warn( 'TSL.LoopNode: loop() has been renamed to Loop().' ); + return Loop( ...params ); + +}; + +const _morphTextures = /*@__PURE__*/ new WeakMap(); +const _morphVec4 = /*@__PURE__*/ new Vector4(); + +const getMorph = /*@__PURE__*/ Fn( ( { bufferMap, influence, stride, width, depth, offset } ) => { + + const texelIndex = int( vertexIndex ).mul( stride ).add( offset ); + + const y = texelIndex.div( width ); + const x = texelIndex.sub( y.mul( width ) ); + + const bufferAttrib = textureLoad( bufferMap, ivec2( x, y ) ).depth( depth ); + + return bufferAttrib.mul( influence ); + +} ); + +function getEntry( geometry ) { + + const hasMorphPosition = geometry.morphAttributes.position !== undefined; + const hasMorphNormals = geometry.morphAttributes.normal !== undefined; + const hasMorphColors = geometry.morphAttributes.color !== undefined; + + // instead of using attributes, the WebGL 2 code path encodes morph targets + // into an array of data textures. Each layer represents a single morph target. + + const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; + const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0; + + let entry = _morphTextures.get( geometry ); + + if ( entry === undefined || entry.count !== morphTargetsCount ) { + + if ( entry !== undefined ) entry.texture.dispose(); + + const morphTargets = geometry.morphAttributes.position || []; + const morphNormals = geometry.morphAttributes.normal || []; + const morphColors = geometry.morphAttributes.color || []; + + let vertexDataCount = 0; + + if ( hasMorphPosition === true ) vertexDataCount = 1; + if ( hasMorphNormals === true ) vertexDataCount = 2; + if ( hasMorphColors === true ) vertexDataCount = 3; + + let width = geometry.attributes.position.count * vertexDataCount; + let height = 1; + + const maxTextureSize = 4096; // @TODO: Use 'capabilities.maxTextureSize' + + if ( width > maxTextureSize ) { + + height = Math.ceil( width / maxTextureSize ); + width = maxTextureSize; + + } + + const buffer = new Float32Array( width * height * 4 * morphTargetsCount ); + + const bufferTexture = new DataArrayTexture( buffer, width, height, morphTargetsCount ); + bufferTexture.type = FloatType; + bufferTexture.needsUpdate = true; + + // fill buffer + + const vertexDataStride = vertexDataCount * 4; + + for ( let i = 0; i < morphTargetsCount; i ++ ) { + + const morphTarget = morphTargets[ i ]; + const morphNormal = morphNormals[ i ]; + const morphColor = morphColors[ i ]; + + const offset = width * height * 4 * i; + + for ( let j = 0; j < morphTarget.count; j ++ ) { + + const stride = j * vertexDataStride; + + if ( hasMorphPosition === true ) { + + _morphVec4.fromBufferAttribute( morphTarget, j ); + + buffer[ offset + stride + 0 ] = _morphVec4.x; + buffer[ offset + stride + 1 ] = _morphVec4.y; + buffer[ offset + stride + 2 ] = _morphVec4.z; + buffer[ offset + stride + 3 ] = 0; + + } + + if ( hasMorphNormals === true ) { + + _morphVec4.fromBufferAttribute( morphNormal, j ); + + buffer[ offset + stride + 4 ] = _morphVec4.x; + buffer[ offset + stride + 5 ] = _morphVec4.y; + buffer[ offset + stride + 6 ] = _morphVec4.z; + buffer[ offset + stride + 7 ] = 0; + + } + + if ( hasMorphColors === true ) { + + _morphVec4.fromBufferAttribute( morphColor, j ); + + buffer[ offset + stride + 8 ] = _morphVec4.x; + buffer[ offset + stride + 9 ] = _morphVec4.y; + buffer[ offset + stride + 10 ] = _morphVec4.z; + buffer[ offset + stride + 11 ] = ( morphColor.itemSize === 4 ) ? _morphVec4.w : 1; + + } + + } + + } + + entry = { + count: morphTargetsCount, + texture: bufferTexture, + stride: vertexDataCount, + size: new Vector2( width, height ) + }; + + _morphTextures.set( geometry, entry ); + + function disposeTexture() { + + bufferTexture.dispose(); + + _morphTextures.delete( geometry ); + + geometry.removeEventListener( 'dispose', disposeTexture ); + + } + + geometry.addEventListener( 'dispose', disposeTexture ); + + } + + return entry; + +} + + +class MorphNode extends Node { + + static get type() { + + return 'MorphNode'; + + } + + constructor( mesh ) { + + super( 'void' ); + + this.mesh = mesh; + this.morphBaseInfluence = uniform( 1 ); + + this.updateType = NodeUpdateType.OBJECT; + + } + + setup( builder ) { + + const { geometry } = builder; + + const hasMorphPosition = geometry.morphAttributes.position !== undefined; + const hasMorphNormals = geometry.hasAttribute( 'normal' ) && geometry.morphAttributes.normal !== undefined; + + const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; + const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0; + + // nodes + + const { texture: bufferMap, stride, size } = getEntry( geometry ); + + if ( hasMorphPosition === true ) positionLocal.mulAssign( this.morphBaseInfluence ); + if ( hasMorphNormals === true ) normalLocal.mulAssign( this.morphBaseInfluence ); + + const width = int( size.width ); + + Loop( morphTargetsCount, ( { i } ) => { + + const influence = float( 0 ).toVar(); + + if ( this.mesh.count > 1 && ( this.mesh.morphTexture !== null && this.mesh.morphTexture !== undefined ) ) { + + influence.assign( textureLoad( this.mesh.morphTexture, ivec2( int( i ).add( 1 ), int( instanceIndex ) ) ).r ); + + } else { + + influence.assign( reference( 'morphTargetInfluences', 'float' ).element( i ).toVar() ); + + } + + if ( hasMorphPosition === true ) { + + positionLocal.addAssign( getMorph( { + bufferMap, + influence, + stride, + width, + depth: i, + offset: int( 0 ) + } ) ); + + } + + if ( hasMorphNormals === true ) { + + normalLocal.addAssign( getMorph( { + bufferMap, + influence, + stride, + width, + depth: i, + offset: int( 1 ) + } ) ); + + } + + } ); + + } + + update() { + + const morphBaseInfluence = this.morphBaseInfluence; + + if ( this.mesh.geometry.morphTargetsRelative ) { + + morphBaseInfluence.value = 1; + + } else { + + morphBaseInfluence.value = 1 - this.mesh.morphTargetInfluences.reduce( ( a, b ) => a + b, 0 ); + + } + + } + +} + +const morphReference = /*@__PURE__*/ nodeProxy( MorphNode ); + +class LightingNode extends Node { + + static get type() { + + return 'LightingNode'; + + } + + constructor() { + + super( 'vec3' ); + + this.isLightingNode = true; + + } + + generate( /*builder*/ ) { + + console.warn( 'Abstract function.' ); + + } + +} + +class AONode extends LightingNode { + + static get type() { + + return 'AONode'; + + } + + constructor( aoNode = null ) { + + super(); + + this.aoNode = aoNode; + + } + + setup( builder ) { + + builder.context.ambientOcclusion.mulAssign( this.aoNode ); + + } + +} + +class LightingContextNode extends ContextNode { + + static get type() { + + return 'LightingContextNode'; + + } + + constructor( node, lightingModel = null, backdropNode = null, backdropAlphaNode = null ) { + + super( node ); + + this.lightingModel = lightingModel; + this.backdropNode = backdropNode; + this.backdropAlphaNode = backdropAlphaNode; + + this._value = null; + + } + + getContext() { + + const { backdropNode, backdropAlphaNode } = this; + + const directDiffuse = vec3().toVar( 'directDiffuse' ), + directSpecular = vec3().toVar( 'directSpecular' ), + indirectDiffuse = vec3().toVar( 'indirectDiffuse' ), + indirectSpecular = vec3().toVar( 'indirectSpecular' ); + + const reflectedLight = { + directDiffuse, + directSpecular, + indirectDiffuse, + indirectSpecular + }; + + const context = { + radiance: vec3().toVar( 'radiance' ), + irradiance: vec3().toVar( 'irradiance' ), + iblIrradiance: vec3().toVar( 'iblIrradiance' ), + ambientOcclusion: float( 1 ).toVar( 'ambientOcclusion' ), + reflectedLight, + backdrop: backdropNode, + backdropAlpha: backdropAlphaNode + }; + + return context; + + } + + setup( builder ) { + + this.value = this._value || ( this._value = this.getContext() ); + this.value.lightingModel = this.lightingModel || builder.context.lightingModel; + + return super.setup( builder ); + + } + +} + +const lightingContext = /*@__PURE__*/ nodeProxy( LightingContextNode ); + +class IrradianceNode extends LightingNode { + + static get type() { + + return 'IrradianceNode'; + + } + + constructor( node ) { + + super(); + + this.node = node; + + } + + setup( builder ) { + + builder.context.irradiance.addAssign( this.node ); + + } + +} + +let screenSizeVec, viewportVec; + +class ScreenNode extends Node { + + static get type() { + + return 'ScreenNode'; + + } + + constructor( scope ) { + + super(); + + this.scope = scope; + + this.isViewportNode = true; + + } + + getNodeType() { + + if ( this.scope === ScreenNode.VIEWPORT ) return 'vec4'; + else return 'vec2'; + + } + + getUpdateType() { + + let updateType = NodeUpdateType.NONE; + + if ( this.scope === ScreenNode.SIZE || this.scope === ScreenNode.VIEWPORT ) { + + updateType = NodeUpdateType.RENDER; + + } + + this.updateType = updateType; + + return updateType; + + } + + update( { renderer } ) { + + const renderTarget = renderer.getRenderTarget(); + + if ( this.scope === ScreenNode.VIEWPORT ) { + + if ( renderTarget !== null ) { + + viewportVec.copy( renderTarget.viewport ); + + } else { + + renderer.getViewport( viewportVec ); + + viewportVec.multiplyScalar( renderer.getPixelRatio() ); + + } + + } else { + + if ( renderTarget !== null ) { + + screenSizeVec.width = renderTarget.width; + screenSizeVec.height = renderTarget.height; + + } else { + + renderer.getDrawingBufferSize( screenSizeVec ); + + } + + } + + } + + setup( /*builder*/ ) { + + const scope = this.scope; + + let output = null; + + if ( scope === ScreenNode.SIZE ) { + + output = uniform( screenSizeVec || ( screenSizeVec = new Vector2() ) ); + + } else if ( scope === ScreenNode.VIEWPORT ) { + + output = uniform( viewportVec || ( viewportVec = new Vector4() ) ); + + } else { + + output = vec2( screenCoordinate.div( screenSize ) ); + + } + + return output; + + } + + generate( builder ) { + + if ( this.scope === ScreenNode.COORDINATE ) { + + let coord = builder.getFragCoord(); + + if ( builder.isFlipY() ) { + + // follow webgpu standards + + const size = builder.getNodeProperties( screenSize ).outputNode.build( builder ); + + coord = `${ builder.getType( 'vec2' ) }( ${ coord }.x, ${ size }.y - ${ coord }.y )`; + + } + + return coord; + + } + + return super.generate( builder ); + + } + +} + +ScreenNode.COORDINATE = 'coordinate'; +ScreenNode.VIEWPORT = 'viewport'; +ScreenNode.SIZE = 'size'; +ScreenNode.UV = 'uv'; + +// Screen + +const screenUV = /*@__PURE__*/ nodeImmutable( ScreenNode, ScreenNode.UV ); +const screenSize = /*@__PURE__*/ nodeImmutable( ScreenNode, ScreenNode.SIZE ); +const screenCoordinate = /*@__PURE__*/ nodeImmutable( ScreenNode, ScreenNode.COORDINATE ); + +// Viewport + +const viewport = /*@__PURE__*/ nodeImmutable( ScreenNode, ScreenNode.VIEWPORT ); +const viewportSize = viewport.zw; +const viewportCoordinate = /*@__PURE__*/ screenCoordinate.sub( viewport.xy ); +const viewportUV = /*@__PURE__*/ viewportCoordinate.div( viewportSize ); + +// Deprecated + +const viewportResolution = /*@__PURE__*/ ( Fn( () => { // @deprecated, r169 + + console.warn( 'TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.' ); + + return screenSize; + +}, 'vec2' ).once() )(); + +const viewportTopLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168 + + console.warn( 'TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.' ); + + return screenUV; + +}, 'vec2' ).once() )(); + +const viewportBottomLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168 + + console.warn( 'TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.' ); + + return screenUV.flipY(); + +}, 'vec2' ).once() )(); + +const _size$4 = /*@__PURE__*/ new Vector2(); + +class ViewportTextureNode extends TextureNode { + + static get type() { + + return 'ViewportTextureNode'; + + } + + constructor( uvNode = screenUV, levelNode = null, framebufferTexture = null ) { + + if ( framebufferTexture === null ) { + + framebufferTexture = new FramebufferTexture(); + framebufferTexture.minFilter = LinearMipmapLinearFilter; + + } + + super( framebufferTexture, uvNode, levelNode ); + + this.generateMipmaps = false; + + this.isOutputTextureNode = true; + + this.updateBeforeType = NodeUpdateType.FRAME; + + } + + updateBefore( frame ) { + + const renderer = frame.renderer; + renderer.getDrawingBufferSize( _size$4 ); + + // + + const framebufferTexture = this.value; + + if ( framebufferTexture.image.width !== _size$4.width || framebufferTexture.image.height !== _size$4.height ) { + + framebufferTexture.image.width = _size$4.width; + framebufferTexture.image.height = _size$4.height; + framebufferTexture.needsUpdate = true; + + } + + // + + const currentGenerateMipmaps = framebufferTexture.generateMipmaps; + framebufferTexture.generateMipmaps = this.generateMipmaps; + + renderer.copyFramebufferToTexture( framebufferTexture ); + + framebufferTexture.generateMipmaps = currentGenerateMipmaps; + + } + + clone() { + + const viewportTextureNode = new this.constructor( this.uvNode, this.levelNode, this.value ); + viewportTextureNode.generateMipmaps = this.generateMipmaps; + + return viewportTextureNode; + + } + +} + +const viewportTexture = /*@__PURE__*/ nodeProxy( ViewportTextureNode ); +const viewportMipTexture = /*@__PURE__*/ nodeProxy( ViewportTextureNode, null, null, { generateMipmaps: true } ); + +let sharedDepthbuffer = null; + +class ViewportDepthTextureNode extends ViewportTextureNode { + + static get type() { + + return 'ViewportDepthTextureNode'; + + } + + constructor( uvNode = screenUV, levelNode = null ) { + + if ( sharedDepthbuffer === null ) { + + sharedDepthbuffer = new DepthTexture(); + + } + + super( uvNode, levelNode, sharedDepthbuffer ); + + } + +} + +const viewportDepthTexture = /*@__PURE__*/ nodeProxy( ViewportDepthTextureNode ); + +class ViewportDepthNode extends Node { + + static get type() { + + return 'ViewportDepthNode'; + + } + + constructor( scope, valueNode = null ) { + + super( 'float' ); + + this.scope = scope; + this.valueNode = valueNode; + + this.isViewportDepthNode = true; + + } + + generate( builder ) { + + const { scope } = this; + + if ( scope === ViewportDepthNode.DEPTH_BASE ) { + + return builder.getFragDepth(); + + } + + return super.generate( builder ); + + } + + setup( { camera } ) { + + const { scope } = this; + const value = this.valueNode; + + let node = null; + + if ( scope === ViewportDepthNode.DEPTH_BASE ) { + + if ( value !== null ) { + + node = depthBase().assign( value ); + + } + + } else if ( scope === ViewportDepthNode.DEPTH ) { + + if ( camera.isPerspectiveCamera ) { + + node = viewZToPerspectiveDepth( positionView.z, cameraNear, cameraFar ); + + } else { + + node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar ); + + } + + } else if ( scope === ViewportDepthNode.LINEAR_DEPTH ) { + + if ( value !== null ) { + + if ( camera.isPerspectiveCamera ) { + + const viewZ = perspectiveDepthToViewZ( value, cameraNear, cameraFar ); + + node = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar ); + + } else { + + node = value; + + } + + } else { + + node = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar ); + + } + + } + + return node; + + } + +} + +ViewportDepthNode.DEPTH_BASE = 'depthBase'; +ViewportDepthNode.DEPTH = 'depth'; +ViewportDepthNode.LINEAR_DEPTH = 'linearDepth'; + +// NOTE: viewZ, the z-coordinate in camera space, is negative for points in front of the camera + +// -near maps to 0; -far maps to 1 +const viewZToOrthographicDepth = ( viewZ, near, far ) => viewZ.add( near ).div( near.sub( far ) ); + +// maps orthographic depth in [ 0, 1 ] to viewZ +const orthographicDepthToViewZ = ( depth, near, far ) => near.sub( far ).mul( depth ).sub( near ); + +// NOTE: https://twitter.com/gonnavis/status/1377183786949959682 + +// -near maps to 0; -far maps to 1 +const viewZToPerspectiveDepth = ( viewZ, near, far ) => near.add( viewZ ).mul( far ).div( far.sub( near ).mul( viewZ ) ); + +// maps perspective depth in [ 0, 1 ] to viewZ +const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) ); + +// -near maps to 0; -far maps to 1 +const viewZToLogarithmicDepth = ( viewZ, near, far ) => { + + // NOTE: viewZ must be negative--see explanation at the end of this comment block. + // The final logarithmic depth formula used here is adapted from one described in an + // article by Thatcher Ulrich (see http://tulrich.com/geekstuff/log_depth_buffer.txt), + // which was an improvement upon an earlier formula one described in an + // Outerra article (https://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html). + // Ulrich's formula is the following: + // z = K * log( w / cameraNear ) / log( cameraFar / cameraNear ) + // where K = 2^k - 1, and k is the number of bits in the depth buffer. + // The Outerra variant ignored the camera near plane (it assumed it was 0) and instead + // opted for a "C-constant" for resolution adjustment of objects near the camera. + // Outerra states: "Notice that the 'C' variant doesn’t use a near plane distance, it has it + // set at 0" (quote from https://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html). + // Ulrich's variant has the benefit of constant relative precision over the whole near-far range. + // It was debated here whether Outerra's "C-constant" or Ulrich's "near plane" variant should + // be used, and ultimately Ulrich's "near plane" version was chosen. + // Outerra eventually made another improvement to their original "C-constant" variant, + // but it still does not incorporate the camera near plane (for this version, + // see https://outerra.blogspot.com/2013/07/logarithmic-depth-buffer-optimizations.html). + // Here we make 4 changes to Ulrich's formula: + // 1. Clamp the camera near plane so we don't divide by 0. + // 2. Use log2 instead of log to avoid an extra multiply (shaders implement log using log2). + // 3. Assume K is 1 (K = maximum value in depth buffer; see Ulrich's formula above). + // 4. To maintain consistency with the functions "viewZToOrthographicDepth" and "viewZToPerspectiveDepth", + // we modify the formula here to use 'viewZ' instead of 'w'. The other functions expect a negative viewZ, + // so we do the same here, hence the 'viewZ.negate()' call. + // For visual representation of this depth curve, see https://www.desmos.com/calculator/uyqk0vex1u + near = near.max( 1e-6 ).toVar(); + const numerator = log2( viewZ.negate().div( near ) ); + const denominator = log2( far.div( near ) ); + return numerator.div( denominator ); + +}; + +// maps logarithmic depth in [ 0, 1 ] to viewZ +const logarithmicDepthToViewZ = ( depth, near, far ) => { + + // NOTE: we add a 'negate()' call to the return value here to maintain consistency with + // the functions "orthographicDepthToViewZ" and "perspectiveDepthToViewZ" (they return + // a negative viewZ). + const exponent = depth.mul( log( far.div( near ) ) ); + return float( Math.E ).pow( exponent ).mul( near ).negate(); + +}; + +const depthBase = /*@__PURE__*/ nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_BASE ); + +const depth = /*@__PURE__*/ nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH ); +const linearDepth = /*@__PURE__*/ nodeProxy( ViewportDepthNode, ViewportDepthNode.LINEAR_DEPTH ); +const viewportLinearDepth = /*@__PURE__*/ linearDepth( viewportDepthTexture() ); + +depth.assign = ( value ) => depthBase( value ); + +class BuiltinNode extends Node { + + constructor( name ) { + + super( 'float' ); + + this.name = name; + + this.isBuiltinNode = true; + + } + + generate( /* builder */ ) { + + return this.name; + + } + +} + +const builtin = nodeProxy( BuiltinNode ); + +class ClippingNode extends Node { + + static get type() { + + return 'ClippingNode'; + + } + + constructor( scope = ClippingNode.DEFAULT ) { + + super(); + + this.scope = scope; + + } + + setup( builder ) { + + super.setup( builder ); + + const clippingContext = builder.clippingContext; + const { intersectionPlanes, unionPlanes } = clippingContext; + + this.hardwareClipping = builder.material.hardwareClipping; + + if ( this.scope === ClippingNode.ALPHA_TO_COVERAGE ) { + + return this.setupAlphaToCoverage( intersectionPlanes, unionPlanes ); + + } else if ( this.scope === ClippingNode.HARDWARE ) { + + return this.setupHardwareClipping( unionPlanes, builder ); + + } else { + + return this.setupDefault( intersectionPlanes, unionPlanes ); + + } + + } + + setupAlphaToCoverage( intersectionPlanes, unionPlanes ) { + + return Fn( () => { + + const distanceToPlane = float().toVar( 'distanceToPlane' ); + const distanceGradient = float().toVar( 'distanceToGradient' ); + + const clipOpacity = float( 1 ).toVar( 'clipOpacity' ); + + const numUnionPlanes = unionPlanes.length; + + if ( ! this.hardwareClipping && numUnionPlanes > 0 ) { + + const clippingPlanes = uniformArray( unionPlanes ); + + Loop( numUnionPlanes, ( { i } ) => { + + const plane = clippingPlanes.element( i ); + + distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) ); + distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) ); + + clipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ) ); + + } ); + + } + + const numIntersectionPlanes = intersectionPlanes.length; + + if ( numIntersectionPlanes > 0 ) { + + const clippingPlanes = uniformArray( intersectionPlanes ); + const intersectionClipOpacity = float( 1 ).toVar( 'intersectionClipOpacity' ); + + Loop( numIntersectionPlanes, ( { i } ) => { + + const plane = clippingPlanes.element( i ); + + distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) ); + distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) ); + + intersectionClipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ).oneMinus() ); + + } ); + + clipOpacity.mulAssign( intersectionClipOpacity.oneMinus() ); + + } + + diffuseColor.a.mulAssign( clipOpacity ); + + diffuseColor.a.equal( 0.0 ).discard(); + + } )(); + + } + + setupDefault( intersectionPlanes, unionPlanes ) { + + return Fn( () => { + + const numUnionPlanes = unionPlanes.length; + + if ( ! this.hardwareClipping && numUnionPlanes > 0 ) { + + const clippingPlanes = uniformArray( unionPlanes ); + + Loop( numUnionPlanes, ( { i } ) => { + + const plane = clippingPlanes.element( i ); + positionView.dot( plane.xyz ).greaterThan( plane.w ).discard(); + + } ); + + } + + const numIntersectionPlanes = intersectionPlanes.length; + + if ( numIntersectionPlanes > 0 ) { + + const clippingPlanes = uniformArray( intersectionPlanes ); + const clipped = bool( true ).toVar( 'clipped' ); + + Loop( numIntersectionPlanes, ( { i } ) => { + + const plane = clippingPlanes.element( i ); + clipped.assign( positionView.dot( plane.xyz ).greaterThan( plane.w ).and( clipped ) ); + + } ); + + clipped.discard(); + + } + + } )(); + + } + + setupHardwareClipping( unionPlanes, builder ) { + + const numUnionPlanes = unionPlanes.length; + + builder.enableHardwareClipping( numUnionPlanes ); + + return Fn( () => { + + const clippingPlanes = uniformArray( unionPlanes ); + const hw_clip_distances = builtin( builder.getClipDistance() ); + + Loop( numUnionPlanes, ( { i } ) => { + + const plane = clippingPlanes.element( i ); + + const distance = positionView.dot( plane.xyz ).sub( plane.w ).negate(); + hw_clip_distances.element( i ).assign( distance ); + + } ); + + } )(); + + } + +} + +ClippingNode.ALPHA_TO_COVERAGE = 'alphaToCoverage'; +ClippingNode.DEFAULT = 'default'; +ClippingNode.HARDWARE = 'hardware'; + +const clipping = () => nodeObject( new ClippingNode() ); +const clippingAlpha = () => nodeObject( new ClippingNode( ClippingNode.ALPHA_TO_COVERAGE ) ); +const hardwareClipping = () => nodeObject( new ClippingNode( ClippingNode.HARDWARE ) ); + +/** + * See: https://casual-effects.com/research/Wyman2017Hashed/index.html + */ + +const ALPHA_HASH_SCALE = 0.05; // Derived from trials only, and may be changed. + +const hash2D = /*@__PURE__*/ Fn( ( [ value ] ) => { + + return fract( mul( 1.0e4, sin( mul( 17.0, value.x ).add( mul( 0.1, value.y ) ) ) ).mul( add( 0.1, abs( sin( mul( 13.0, value.y ).add( value.x ) ) ) ) ) ); + +} ); + +const hash3D = /*@__PURE__*/ Fn( ( [ value ] ) => { + + return hash2D( vec2( hash2D( value.xy ), value.z ) ); + +} ); + +const getAlphaHashThreshold = /*@__PURE__*/ Fn( ( [ position ] ) => { + + // Find the discretized derivatives of our coordinates + const maxDeriv = max$1( + length( dFdx( position.xyz ) ), + length( dFdy( position.xyz ) ) + ); + + const pixScale = float( 1 ).div( float( ALPHA_HASH_SCALE ).mul( maxDeriv ) ).toVar( 'pixScale' ); + + // Find two nearest log-discretized noise scales + const pixScales = vec2( + exp2( floor( log2( pixScale ) ) ), + exp2( ceil( log2( pixScale ) ) ) + ); + + // Compute alpha thresholds at our two noise scales + const alpha = vec2( + hash3D( floor( pixScales.x.mul( position.xyz ) ) ), + hash3D( floor( pixScales.y.mul( position.xyz ) ) ), + ); + + // Factor to interpolate lerp with + const lerpFactor = fract( log2( pixScale ) ); + + // Interpolate alpha threshold from noise at two scales + const x = add( mul( lerpFactor.oneMinus(), alpha.x ), mul( lerpFactor, alpha.y ) ); + + // Pass into CDF to compute uniformly distrib threshold + const a = min$1( lerpFactor, lerpFactor.oneMinus() ); + const cases = vec3( + x.mul( x ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ), + x.sub( mul( 0.5, a ) ).div( sub( 1.0, a ) ), + sub( 1.0, sub( 1.0, x ).mul( sub( 1.0, x ) ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ) ) ); + + // Find our final, uniformly distributed alpha threshold (ατ) + const threshold = x.lessThan( a.oneMinus() ).select( x.lessThan( a ).select( cases.x, cases.y ), cases.z ); + + // Avoids ατ == 0. Could also do ατ =1-ατ + return clamp( threshold, 1.0e-6, 1.0 ); + +} ).setLayout( { + name: 'getAlphaHashThreshold', + type: 'float', + inputs: [ + { name: 'position', type: 'vec3' } + ] +} ); + +class NodeMaterial extends Material { + + static get type() { + + return 'NodeMaterial'; + + } + + get type() { + + return this.constructor.type; + + } + + set type( _value ) { /* */ } + + constructor() { + + super(); + + this.isNodeMaterial = true; + + this.forceSinglePass = false; + + this.fog = true; + this.lights = false; + this.hardwareClipping = false; + + this.lightsNode = null; + this.envNode = null; + this.aoNode = null; + + this.colorNode = null; + this.normalNode = null; + this.opacityNode = null; + this.backdropNode = null; + this.backdropAlphaNode = null; + this.alphaTestNode = null; + + this.positionNode = null; + this.geometryNode = null; + + this.depthNode = null; + this.shadowPositionNode = null; + this.receivedShadowNode = null; + this.castShadowNode = null; + + this.outputNode = null; + this.mrtNode = null; + + this.fragmentNode = null; + this.vertexNode = null; + + } + + customProgramCacheKey() { + + return this.type + getCacheKey$1( this ); + + } + + build( builder ) { + + this.setup( builder ); + + } + + setupObserver( builder ) { + + return new NodeMaterialObserver( builder ); + + } + + setup( builder ) { + + builder.context.setupNormal = () => this.setupNormal( builder ); + + const renderer = builder.renderer; + const renderTarget = renderer.getRenderTarget(); + + // < VERTEX STAGE > + + builder.addStack(); + + builder.stack.outputNode = this.vertexNode || this.setupPosition( builder ); + + if ( this.geometryNode !== null ) { + + builder.stack.outputNode = builder.stack.outputNode.bypass( this.geometryNode ); + + } + + builder.addFlow( 'vertex', builder.removeStack() ); + + // < FRAGMENT STAGE > + + builder.addStack(); + + let resultNode; + + const clippingNode = this.setupClipping( builder ); + + if ( this.depthWrite === true ) { + + // only write depth if depth buffer is configured + + if ( renderTarget !== null ) { + + if ( renderTarget.depthBuffer === true ) this.setupDepth( builder ); + + } else { + + if ( renderer.depth === true ) this.setupDepth( builder ); + + } + + } + + if ( this.fragmentNode === null ) { + + this.setupDiffuseColor( builder ); + this.setupVariants( builder ); + + const outgoingLightNode = this.setupLighting( builder ); + + if ( clippingNode !== null ) builder.stack.add( clippingNode ); + + // force unsigned floats - useful for RenderTargets + + const basicOutput = vec4( outgoingLightNode, diffuseColor.a ).max( 0 ); + + resultNode = this.setupOutput( builder, basicOutput ); + + // OUTPUT NODE + + output.assign( resultNode ); + + // + + if ( this.outputNode !== null ) resultNode = this.outputNode; + + // MRT + + if ( renderTarget !== null ) { + + const mrt = renderer.getMRT(); + const materialMRT = this.mrtNode; + + if ( mrt !== null ) { + + resultNode = mrt; + + if ( materialMRT !== null ) { + + resultNode = mrt.merge( materialMRT ); + + } + + } else if ( materialMRT !== null ) { + + resultNode = materialMRT; + + } + + } + + } else { + + let fragmentNode = this.fragmentNode; + + if ( fragmentNode.isOutputStructNode !== true ) { + + fragmentNode = vec4( fragmentNode ); + + } + + resultNode = this.setupOutput( builder, fragmentNode ); + + } + + builder.stack.outputNode = resultNode; + + builder.addFlow( 'fragment', builder.removeStack() ); + + // < MONITOR > + + builder.monitor = this.setupObserver( builder ); + + } + + setupClipping( builder ) { + + if ( builder.clippingContext === null ) return null; + + const { unionPlanes, intersectionPlanes } = builder.clippingContext; + + let result = null; + + if ( unionPlanes.length > 0 || intersectionPlanes.length > 0 ) { + + const samples = builder.renderer.samples; + + if ( this.alphaToCoverage && samples > 1 ) { + + // to be added to flow when the color/alpha value has been determined + result = clippingAlpha(); + + } else { + + builder.stack.add( clipping() ); + + } + + } + + return result; + + } + + setupHardwareClipping( builder ) { + + this.hardwareClipping = false; + + if ( builder.clippingContext === null ) return; + + const candidateCount = builder.clippingContext.unionPlanes.length; + + // 8 planes supported by WebGL ANGLE_clip_cull_distance and WebGPU clip-distances + + if ( candidateCount > 0 && candidateCount <= 8 && builder.isAvailable( 'clipDistance' ) ) { + + builder.stack.add( hardwareClipping() ); + + this.hardwareClipping = true; + + } + + return; + + } + + setupDepth( builder ) { + + const { renderer, camera } = builder; + + // Depth + + let depthNode = this.depthNode; + + if ( depthNode === null ) { + + const mrt = renderer.getMRT(); + + if ( mrt && mrt.has( 'depth' ) ) { + + depthNode = mrt.get( 'depth' ); + + } else if ( renderer.logarithmicDepthBuffer === true ) { + + if ( camera.isPerspectiveCamera ) { + + depthNode = viewZToLogarithmicDepth( positionView.z, cameraNear, cameraFar ); + + } else { + + depthNode = viewZToOrthographicDepth( positionView.z, cameraNear, cameraFar ); + + } + + } + + } + + if ( depthNode !== null ) { + + depth.assign( depthNode ).append(); + + } + + } + + setupPosition( builder ) { + + const { object } = builder; + const geometry = object.geometry; + + builder.addStack(); + + // Vertex + + if ( geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color ) { + + morphReference( object ).append(); + + } + + if ( object.isSkinnedMesh === true ) { + + skinningReference( object ).append(); + + } + + if ( this.displacementMap ) { + + const displacementMap = materialReference( 'displacementMap', 'texture' ); + const displacementScale = materialReference( 'displacementScale', 'float' ); + const displacementBias = materialReference( 'displacementBias', 'float' ); + + positionLocal.addAssign( normalLocal.normalize().mul( ( displacementMap.x.mul( displacementScale ).add( displacementBias ) ) ) ); + + } + + if ( object.isBatchedMesh ) { + + batch( object ).append(); + + } + + if ( ( object.isInstancedMesh && object.instanceMatrix && object.instanceMatrix.isInstancedBufferAttribute === true ) ) { + + instancedMesh( object ).append(); + + } + + if ( this.positionNode !== null ) { + + positionLocal.assign( this.positionNode ); + + } + + this.setupHardwareClipping( builder ); + + const mvp = modelViewProjection(); + + builder.context.vertex = builder.removeStack(); + builder.context.mvp = mvp; + + return mvp; + + } + + setupDiffuseColor( { object, geometry } ) { + + let colorNode = this.colorNode ? vec4( this.colorNode ) : materialColor; + + // VERTEX COLORS + + if ( this.vertexColors === true && geometry.hasAttribute( 'color' ) ) { + + colorNode = vec4( colorNode.xyz.mul( attribute( 'color', 'vec3' ) ), colorNode.a ); + + } + + // Instanced colors + + if ( object.instanceColor ) { + + const instanceColor = varyingProperty( 'vec3', 'vInstanceColor' ); + + colorNode = instanceColor.mul( colorNode ); + + } + + if ( object.isBatchedMesh && object._colorsTexture ) { + + const batchColor = varyingProperty( 'vec3', 'vBatchColor' ); + + colorNode = batchColor.mul( colorNode ); + + } + + + // COLOR + + diffuseColor.assign( colorNode ); + + // OPACITY + + const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity; + diffuseColor.a.assign( diffuseColor.a.mul( opacityNode ) ); + + // ALPHA TEST + + if ( this.alphaTestNode !== null || this.alphaTest > 0 ) { + + const alphaTestNode = this.alphaTestNode !== null ? float( this.alphaTestNode ) : materialAlphaTest; + + diffuseColor.a.lessThanEqual( alphaTestNode ).discard(); + + } + + // ALPHA HASH + + if ( this.alphaHash === true ) { + + diffuseColor.a.lessThan( getAlphaHashThreshold( positionLocal ) ).discard(); + + } + + if ( this.transparent === false && this.blending === NormalBlending && this.alphaToCoverage === false ) { + + diffuseColor.a.assign( 1.0 ); + + } + + } + + setupVariants( /*builder*/ ) { + + // Interface function. + + } + + setupOutgoingLight() { + + return ( this.lights === true ) ? vec3( 0 ) : diffuseColor.rgb; + + } + + setupNormal() { + + return this.normalNode ? vec3( this.normalNode ) : materialNormal; + + } + + setupEnvironment( /*builder*/ ) { + + let node = null; + + if ( this.envNode ) { + + node = this.envNode; + + } else if ( this.envMap ) { + + node = this.envMap.isCubeTexture ? materialReference( 'envMap', 'cubeTexture' ) : materialReference( 'envMap', 'texture' ); + + } + + return node; + + } + + setupLightMap( builder ) { + + let node = null; + + if ( builder.material.lightMap ) { + + node = new IrradianceNode( materialLightMap ); + + } + + return node; + + } + + setupLights( builder ) { + + const materialLightsNode = []; + + // + + const envNode = this.setupEnvironment( builder ); + + if ( envNode && envNode.isLightingNode ) { + + materialLightsNode.push( envNode ); + + } + + const lightMapNode = this.setupLightMap( builder ); + + if ( lightMapNode && lightMapNode.isLightingNode ) { + + materialLightsNode.push( lightMapNode ); + + } + + if ( this.aoNode !== null || builder.material.aoMap ) { + + const aoNode = this.aoNode !== null ? this.aoNode : materialAOMap; + + materialLightsNode.push( new AONode( aoNode ) ); + + } + + let lightsN = this.lightsNode || builder.lightsNode; + + if ( materialLightsNode.length > 0 ) { + + lightsN = builder.renderer.lighting.createNode( [ ...lightsN.getLights(), ...materialLightsNode ] ); + + } + + return lightsN; + + } + + setupLightingModel( /*builder*/ ) { + + // Interface function. + + } + + setupLighting( builder ) { + + const { material } = builder; + const { backdropNode, backdropAlphaNode, emissiveNode } = this; + + // OUTGOING LIGHT + + const lights = this.lights === true || this.lightsNode !== null; + + const lightsNode = lights ? this.setupLights( builder ) : null; + + let outgoingLightNode = this.setupOutgoingLight( builder ); + + if ( lightsNode && lightsNode.getScope().hasLights ) { + + const lightingModel = this.setupLightingModel( builder ); + + outgoingLightNode = lightingContext( lightsNode, lightingModel, backdropNode, backdropAlphaNode ); + + } else if ( backdropNode !== null ) { + + outgoingLightNode = vec3( backdropAlphaNode !== null ? mix( outgoingLightNode, backdropNode, backdropAlphaNode ) : backdropNode ); + + } + + // EMISSIVE + + if ( ( emissiveNode && emissiveNode.isNode === true ) || ( material.emissive && material.emissive.isColor === true ) ) { + + emissive.assign( vec3( emissiveNode ? emissiveNode : materialEmissive ) ); + + outgoingLightNode = outgoingLightNode.add( emissive ); + + } + + return outgoingLightNode; + + } + + setupOutput( builder, outputNode ) { + + // FOG + + if ( this.fog === true ) { + + const fogNode = builder.fogNode; + + if ( fogNode ) outputNode = vec4( fogNode.mix( outputNode.rgb, fogNode.colorNode ), outputNode.a ); + + } + + return outputNode; + + } + + setDefaultValues( material ) { + + // This approach is to reuse the native refreshUniforms* + // and turn available the use of features like transmission and environment in core + + for ( const property in material ) { + + const value = material[ property ]; + + if ( this[ property ] === undefined ) { + + this[ property ] = value; + + if ( value && value.clone ) this[ property ] = value.clone(); + + } + + } + + const descriptors = Object.getOwnPropertyDescriptors( material.constructor.prototype ); + + for ( const key in descriptors ) { + + if ( Object.getOwnPropertyDescriptor( this.constructor.prototype, key ) === undefined && + descriptors[ key ].get !== undefined ) { + + Object.defineProperty( this.constructor.prototype, key, descriptors[ key ] ); + + } + + } + + } + + toJSON( meta ) { + + const isRoot = ( meta === undefined || typeof meta === 'string' ); + + if ( isRoot ) { + + meta = { + textures: {}, + images: {}, + nodes: {} + }; + + } + + const data = Material.prototype.toJSON.call( this, meta ); + const nodeChildren = getNodeChildren( this ); + + data.inputNodes = {}; + + for ( const { property, childNode } of nodeChildren ) { + + data.inputNodes[ property ] = childNode.toJSON( meta ).uuid; + + } + + // TODO: Copied from Object3D.toJSON + + function extractFromCache( cache ) { + + const values = []; + + for ( const key in cache ) { + + const data = cache[ key ]; + delete data.metadata; + values.push( data ); + + } + + return values; + + } + + if ( isRoot ) { + + const textures = extractFromCache( meta.textures ); + const images = extractFromCache( meta.images ); + const nodes = extractFromCache( meta.nodes ); + + if ( textures.length > 0 ) data.textures = textures; + if ( images.length > 0 ) data.images = images; + if ( nodes.length > 0 ) data.nodes = nodes; + + } + + return data; + + } + + copy( source ) { + + this.lightsNode = source.lightsNode; + this.envNode = source.envNode; + + this.colorNode = source.colorNode; + this.normalNode = source.normalNode; + this.opacityNode = source.opacityNode; + this.backdropNode = source.backdropNode; + this.backdropAlphaNode = source.backdropAlphaNode; + this.alphaTestNode = source.alphaTestNode; + + this.positionNode = source.positionNode; + this.geometryNode = source.geometryNode; + + this.depthNode = source.depthNode; + this.shadowPositionNode = source.shadowPositionNode; + this.receivedShadowNode = source.receivedShadowNode; + this.castShadowNode = source.castShadowNode; + + this.outputNode = source.outputNode; + this.mrtNode = source.mrtNode; + + this.fragmentNode = source.fragmentNode; + this.vertexNode = source.vertexNode; + + return super.copy( source ); + + } + +} + +const _defaultValues$e = /*@__PURE__*/ new PointsMaterial(); + +class InstancedPointsNodeMaterial extends NodeMaterial { + + static get type() { + + return 'InstancedPointsNodeMaterial'; + + } + + constructor( params = {} ) { + + super(); + + this.lights = false; + + this.useAlphaToCoverage = true; + + this.useColor = params.vertexColors; + + this.pointWidth = 1; + + this.pointColorNode = null; + + this.pointWidthNode = null; + + this.setDefaultValues( _defaultValues$e ); + + this.setValues( params ); + + } + + setup( builder ) { + + this.setupShaders( builder ); + + super.setup( builder ); + + } + + setupShaders( { renderer } ) { + + const useAlphaToCoverage = this.alphaToCoverage; + const useColor = this.useColor; + + this.vertexNode = Fn( () => { + + const instancePosition = attribute( 'instancePosition' ).xyz; + + // camera space + const mvPos = vec4( modelViewMatrix.mul( vec4( instancePosition, 1.0 ) ) ); + + const aspect = viewport.z.div( viewport.w ); + + // clip space + const clipPos = cameraProjectionMatrix.mul( mvPos ); + + // offset in ndc space + const offset = positionGeometry.xy.toVar(); + + offset.mulAssign( this.pointWidthNode ? this.pointWidthNode : materialPointWidth ); + + offset.assign( offset.div( viewport.z ) ); + offset.y.assign( offset.y.mul( aspect ) ); + + // back to clip space + offset.assign( offset.mul( clipPos.w ) ); + + //clipPos.xy += offset; + clipPos.addAssign( vec4( offset, 0, 0 ) ); + + return clipPos; + + } )(); + + this.fragmentNode = Fn( () => { + + const alpha = float( 1 ).toVar(); + + const len2 = lengthSq( uv().mul( 2 ).sub( 1 ) ); + + if ( useAlphaToCoverage && renderer.samples > 1 ) { + + const dlen = float( len2.fwidth() ).toVar(); + + alpha.assign( smoothstep( dlen.oneMinus(), dlen.add( 1 ), len2 ).oneMinus() ); + + } else { + + len2.greaterThan( 1.0 ).discard(); + + } + + let pointColorNode; + + if ( this.pointColorNode ) { + + pointColorNode = this.pointColorNode; + + } else { + + if ( useColor ) { + + const instanceColor = attribute( 'instanceColor' ); + + pointColorNode = instanceColor.mul( materialColor ); + + } else { + + pointColorNode = materialColor; + + } + + } + + alpha.mulAssign( materialOpacity ); + + return vec4( pointColorNode, alpha ); + + } )(); + + } + + get alphaToCoverage() { + + return this.useAlphaToCoverage; + + } + + set alphaToCoverage( value ) { + + if ( this.useAlphaToCoverage !== value ) { + + this.useAlphaToCoverage = value; + this.needsUpdate = true; + + } + + } + +} + +const _defaultValues$d = /*@__PURE__*/ new LineBasicMaterial(); + +class LineBasicNodeMaterial extends NodeMaterial { + + static get type() { + + return 'LineBasicNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isLineBasicNodeMaterial = true; + + this.lights = false; + + this.setDefaultValues( _defaultValues$d ); + + this.setValues( parameters ); + + } + +} + +const _defaultValues$c = /*@__PURE__*/ new LineDashedMaterial(); + +class LineDashedNodeMaterial extends NodeMaterial { + + static get type() { + + return 'LineDashedNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isLineDashedNodeMaterial = true; + + this.lights = false; + + this.setDefaultValues( _defaultValues$c ); + + this.dashOffset = 0; + + this.offsetNode = null; + this.dashScaleNode = null; + this.dashSizeNode = null; + this.gapSizeNode = null; + + this.setValues( parameters ); + + } + + setupVariants() { + + const offsetNode = this.offsetNode ? float( this.offsetNodeNode ) : materialLineDashOffset; + const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale; + const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize; + const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize; + + dashSize.assign( dashSizeNode ); + gapSize.assign( gapSizeNode ); + + const vLineDistance = varying( attribute( 'lineDistance' ).mul( dashScaleNode ) ); + const vLineDistanceOffset = offsetNode ? vLineDistance.add( offsetNode ) : vLineDistance; + + vLineDistanceOffset.mod( dashSize.add( gapSize ) ).greaterThan( dashSize ).discard(); + + } + +} + +let _sharedFramebuffer = null; + +class ViewportSharedTextureNode extends ViewportTextureNode { + + static get type() { + + return 'ViewportSharedTextureNode'; + + } + + constructor( uvNode = screenUV, levelNode = null ) { + + if ( _sharedFramebuffer === null ) { + + _sharedFramebuffer = new FramebufferTexture(); + + } + + super( uvNode, levelNode, _sharedFramebuffer ); + + } + + updateReference() { + + return this; + + } + +} + +const viewportSharedTexture = /*@__PURE__*/ nodeProxy( ViewportSharedTextureNode ); + +const _defaultValues$b = /*@__PURE__*/ new LineDashedMaterial(); + +class Line2NodeMaterial extends NodeMaterial { + + static get type() { + + return 'Line2NodeMaterial'; + + } + + constructor( params = {} ) { + + super(); + + this.lights = false; + + this.setDefaultValues( _defaultValues$b ); + + this.useAlphaToCoverage = true; + this.useColor = params.vertexColors; + this.useDash = params.dashed; + this.useWorldUnits = false; + + this.dashOffset = 0; + this.lineWidth = 1; + + this.lineColorNode = null; + + this.offsetNode = null; + this.dashScaleNode = null; + this.dashSizeNode = null; + this.gapSizeNode = null; + + this.blending = NoBlending; + + this.setValues( params ); + + } + + setup( builder ) { + + this.setupShaders( builder ); + + super.setup( builder ); + + } + + setupShaders( { renderer } ) { + + const useAlphaToCoverage = this.alphaToCoverage; + const useColor = this.useColor; + const useDash = this.dashed; + const useWorldUnits = this.worldUnits; + + const trimSegment = Fn( ( { start, end } ) => { + + const a = cameraProjectionMatrix.element( 2 ).element( 2 ); // 3nd entry in 3th column + const b = cameraProjectionMatrix.element( 3 ).element( 2 ); // 3nd entry in 4th column + const nearEstimate = b.mul( - 0.5 ).div( a ); + + const alpha = nearEstimate.sub( start.z ).div( end.z.sub( start.z ) ); + + return vec4( mix( start.xyz, end.xyz, alpha ), end.w ); + + } ).setLayout( { + name: 'trimSegment', + type: 'vec4', + inputs: [ + { name: 'start', type: 'vec4' }, + { name: 'end', type: 'vec4' } + ] + } ); + + this.vertexNode = Fn( () => { + + const instanceStart = attribute( 'instanceStart' ); + const instanceEnd = attribute( 'instanceEnd' ); + + // camera space + + const start = vec4( modelViewMatrix.mul( vec4( instanceStart, 1.0 ) ) ).toVar( 'start' ); + const end = vec4( modelViewMatrix.mul( vec4( instanceEnd, 1.0 ) ) ).toVar( 'end' ); + + if ( useDash ) { + + const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale; + const offsetNode = this.offsetNode ? float( this.offsetNodeNode ) : materialLineDashOffset; + + const instanceDistanceStart = attribute( 'instanceDistanceStart' ); + const instanceDistanceEnd = attribute( 'instanceDistanceEnd' ); + + let lineDistance = positionGeometry.y.lessThan( 0.5 ).select( dashScaleNode.mul( instanceDistanceStart ), dashScaleNode.mul( instanceDistanceEnd ) ); + lineDistance = lineDistance.add( offsetNode ); + + varyingProperty( 'float', 'lineDistance' ).assign( lineDistance ); + + } + + if ( useWorldUnits ) { + + varyingProperty( 'vec3', 'worldStart' ).assign( start.xyz ); + varyingProperty( 'vec3', 'worldEnd' ).assign( end.xyz ); + + } + + const aspect = viewport.z.div( viewport.w ); + + // special case for perspective projection, and segments that terminate either in, or behind, the camera plane + // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space + // but we need to perform ndc-space calculations in the shader, so we must address this issue directly + // perhaps there is a more elegant solution -- WestLangley + + const perspective = cameraProjectionMatrix.element( 2 ).element( 3 ).equal( - 1.0 ); // 4th entry in the 3rd column + + If( perspective, () => { + + If( start.z.lessThan( 0.0 ).and( end.z.greaterThan( 0.0 ) ), () => { + + end.assign( trimSegment( { start: start, end: end } ) ); + + } ).ElseIf( end.z.lessThan( 0.0 ).and( start.z.greaterThanEqual( 0.0 ) ), () => { + + start.assign( trimSegment( { start: end, end: start } ) ); + + } ); + + } ); + + // clip space + const clipStart = cameraProjectionMatrix.mul( start ); + const clipEnd = cameraProjectionMatrix.mul( end ); + + // ndc space + const ndcStart = clipStart.xyz.div( clipStart.w ); + const ndcEnd = clipEnd.xyz.div( clipEnd.w ); + + // direction + const dir = ndcEnd.xy.sub( ndcStart.xy ).toVar(); + + // account for clip-space aspect ratio + dir.x.assign( dir.x.mul( aspect ) ); + dir.assign( dir.normalize() ); + + const clip = vec4().toVar(); + + if ( useWorldUnits ) { + + // get the offset direction as perpendicular to the view vector + + const worldDir = end.xyz.sub( start.xyz ).normalize(); + const tmpFwd = mix( start.xyz, end.xyz, 0.5 ).normalize(); + const worldUp = worldDir.cross( tmpFwd ).normalize(); + const worldFwd = worldDir.cross( worldUp ); + + const worldPos = varyingProperty( 'vec4', 'worldPos' ); + + worldPos.assign( positionGeometry.y.lessThan( 0.5 ).select( start, end ) ); + + // height offset + const hw = materialLineWidth.mul( 0.5 ); + worldPos.addAssign( vec4( positionGeometry.x.lessThan( 0.0 ).select( worldUp.mul( hw ), worldUp.mul( hw ).negate() ), 0 ) ); + + // don't extend the line if we're rendering dashes because we + // won't be rendering the endcaps + if ( ! useDash ) { + + // cap extension + worldPos.addAssign( vec4( positionGeometry.y.lessThan( 0.5 ).select( worldDir.mul( hw ).negate(), worldDir.mul( hw ) ), 0 ) ); + + // add width to the box + worldPos.addAssign( vec4( worldFwd.mul( hw ), 0 ) ); + + // endcaps + If( positionGeometry.y.greaterThan( 1.0 ).or( positionGeometry.y.lessThan( 0.0 ) ), () => { + + worldPos.subAssign( vec4( worldFwd.mul( 2.0 ).mul( hw ), 0 ) ); + + } ); + + } + + // project the worldpos + clip.assign( cameraProjectionMatrix.mul( worldPos ) ); + + // shift the depth of the projected points so the line + // segments overlap neatly + const clipPose = vec3().toVar(); + + clipPose.assign( positionGeometry.y.lessThan( 0.5 ).select( ndcStart, ndcEnd ) ); + clip.z.assign( clipPose.z.mul( clip.w ) ); + + } else { + + const offset = vec2( dir.y, dir.x.negate() ).toVar( 'offset' ); + + // undo aspect ratio adjustment + dir.x.assign( dir.x.div( aspect ) ); + offset.x.assign( offset.x.div( aspect ) ); + + // sign flip + offset.assign( positionGeometry.x.lessThan( 0.0 ).select( offset.negate(), offset ) ); + + // endcaps + If( positionGeometry.y.lessThan( 0.0 ), () => { + + offset.assign( offset.sub( dir ) ); + + } ).ElseIf( positionGeometry.y.greaterThan( 1.0 ), () => { + + offset.assign( offset.add( dir ) ); + + } ); + + // adjust for linewidth + offset.assign( offset.mul( materialLineWidth ) ); + + // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ... + offset.assign( offset.div( viewport.w ) ); + + // select end + clip.assign( positionGeometry.y.lessThan( 0.5 ).select( clipStart, clipEnd ) ); + + // back to clip space + offset.assign( offset.mul( clip.w ) ); + + clip.assign( clip.add( vec4( offset, 0, 0 ) ) ); + + } + + return clip; + + } )(); + + const closestLineToLine = Fn( ( { p1, p2, p3, p4 } ) => { + + const p13 = p1.sub( p3 ); + const p43 = p4.sub( p3 ); + + const p21 = p2.sub( p1 ); + + const d1343 = p13.dot( p43 ); + const d4321 = p43.dot( p21 ); + const d1321 = p13.dot( p21 ); + const d4343 = p43.dot( p43 ); + const d2121 = p21.dot( p21 ); + + const denom = d2121.mul( d4343 ).sub( d4321.mul( d4321 ) ); + const numer = d1343.mul( d4321 ).sub( d1321.mul( d4343 ) ); + + const mua = numer.div( denom ).clamp(); + const mub = d1343.add( d4321.mul( mua ) ).div( d4343 ).clamp(); + + return vec2( mua, mub ); + + } ); + + this.colorNode = Fn( () => { + + const vUv = uv(); + + if ( useDash ) { + + const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize; + const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize; + + dashSize.assign( dashSizeNode ); + gapSize.assign( gapSizeNode ); + + const vLineDistance = varyingProperty( 'float', 'lineDistance' ); + + vUv.y.lessThan( - 1.0 ).or( vUv.y.greaterThan( 1.0 ) ).discard(); // discard endcaps + vLineDistance.mod( dashSize.add( gapSize ) ).greaterThan( dashSize ).discard(); // todo - FIX + + } + + const alpha = float( 1 ).toVar( 'alpha' ); + + if ( useWorldUnits ) { + + const worldStart = varyingProperty( 'vec3', 'worldStart' ); + const worldEnd = varyingProperty( 'vec3', 'worldEnd' ); + + // Find the closest points on the view ray and the line segment + const rayEnd = varyingProperty( 'vec4', 'worldPos' ).xyz.normalize().mul( 1e5 ); + const lineDir = worldEnd.sub( worldStart ); + const params = closestLineToLine( { p1: worldStart, p2: worldEnd, p3: vec3( 0.0, 0.0, 0.0 ), p4: rayEnd } ); + + const p1 = worldStart.add( lineDir.mul( params.x ) ); + const p2 = rayEnd.mul( params.y ); + const delta = p1.sub( p2 ); + const len = delta.length(); + const norm = len.div( materialLineWidth ); + + if ( ! useDash ) { + + if ( useAlphaToCoverage && renderer.samples > 1 ) { + + const dnorm = norm.fwidth(); + alpha.assign( smoothstep( dnorm.negate().add( 0.5 ), dnorm.add( 0.5 ), norm ).oneMinus() ); + + } else { + + norm.greaterThan( 0.5 ).discard(); + + } + + } + + } else { + + // round endcaps + + if ( useAlphaToCoverage && renderer.samples > 1 ) { + + const a = vUv.x; + const b = vUv.y.greaterThan( 0.0 ).select( vUv.y.sub( 1.0 ), vUv.y.add( 1.0 ) ); + + const len2 = a.mul( a ).add( b.mul( b ) ); + + const dlen = float( len2.fwidth() ).toVar( 'dlen' ); + + If( vUv.y.abs().greaterThan( 1.0 ), () => { + + alpha.assign( smoothstep( dlen.oneMinus(), dlen.add( 1 ), len2 ).oneMinus() ); + + } ); + + } else { + + If( vUv.y.abs().greaterThan( 1.0 ), () => { + + const a = vUv.x; + const b = vUv.y.greaterThan( 0.0 ).select( vUv.y.sub( 1.0 ), vUv.y.add( 1.0 ) ); + const len2 = a.mul( a ).add( b.mul( b ) ); + + len2.greaterThan( 1.0 ).discard(); + + } ); + + } + + } + + let lineColorNode; + + if ( this.lineColorNode ) { + + lineColorNode = this.lineColorNode; + + } else { + + if ( useColor ) { + + const instanceColorStart = attribute( 'instanceColorStart' ); + const instanceColorEnd = attribute( 'instanceColorEnd' ); + + const instanceColor = positionGeometry.y.lessThan( 0.5 ).select( instanceColorStart, instanceColorEnd ); + + lineColorNode = instanceColor.mul( materialColor ); + + } else { + + lineColorNode = materialColor; + + } + + } + + return vec4( lineColorNode, alpha ); + + } )(); + + if ( this.transparent ) { + + const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity; + + this.outputNode = vec4( this.colorNode.rgb.mul( opacityNode ).add( viewportSharedTexture().rgb.mul( opacityNode.oneMinus() ) ), this.colorNode.a ); + + } + + } + + + get worldUnits() { + + return this.useWorldUnits; + + } + + set worldUnits( value ) { + + if ( this.useWorldUnits !== value ) { + + this.useWorldUnits = value; + this.needsUpdate = true; + + } + + } + + + get dashed() { + + return this.useDash; + + } + + set dashed( value ) { + + if ( this.useDash !== value ) { + + this.useDash = value; + this.needsUpdate = true; + + } + + } + + + get alphaToCoverage() { + + return this.useAlphaToCoverage; + + } + + set alphaToCoverage( value ) { + + if ( this.useAlphaToCoverage !== value ) { + + this.useAlphaToCoverage = value; + this.needsUpdate = true; + + } + + } + +} + +const directionToColor = ( node ) => nodeObject( node ).mul( 0.5 ).add( 0.5 ); +const colorToDirection = ( node ) => nodeObject( node ).mul( 2.0 ).sub( 1 ); + +const _defaultValues$a = /*@__PURE__*/ new MeshNormalMaterial(); + +class MeshNormalNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshNormalNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.lights = false; + + this.isMeshNormalNodeMaterial = true; + + this.setDefaultValues( _defaultValues$a ); + + this.setValues( parameters ); + + } + + setupDiffuseColor() { + + const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity; + + diffuseColor.assign( vec4( directionToColor( transformedNormalView ), opacityNode ) ); + + } + +} + +class EquirectUVNode extends TempNode { + + static get type() { + + return 'EquirectUVNode'; + + } + + constructor( dirNode = positionWorldDirection ) { + + super( 'vec2' ); + + this.dirNode = dirNode; + + } + + setup() { + + const dir = this.dirNode; + + const u = dir.z.atan2( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 ); + const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 ); + + return vec2( u, v ); + + } + +} + +const equirectUV = /*@__PURE__*/ nodeProxy( EquirectUVNode ); + +// @TODO: Consider rename WebGLCubeRenderTarget to just CubeRenderTarget + +class CubeRenderTarget extends WebGLCubeRenderTarget { + + constructor( size = 1, options = {} ) { + + super( size, options ); + + this.isCubeRenderTarget = true; + + } + + fromEquirectangularTexture( renderer, texture$1 ) { + + const currentMinFilter = texture$1.minFilter; + const currentGenerateMipmaps = texture$1.generateMipmaps; + + texture$1.generateMipmaps = true; + + this.texture.type = texture$1.type; + this.texture.colorSpace = texture$1.colorSpace; + + this.texture.generateMipmaps = texture$1.generateMipmaps; + this.texture.minFilter = texture$1.minFilter; + this.texture.magFilter = texture$1.magFilter; + + const geometry = new BoxGeometry( 5, 5, 5 ); + + const uvNode = equirectUV( positionWorldDirection ); + + const material = new NodeMaterial(); + material.colorNode = texture( texture$1, uvNode, 0 ); + material.side = BackSide; + material.blending = NoBlending; + + const mesh = new Mesh( geometry, material ); + + const scene = new Scene(); + scene.add( mesh ); + + // Avoid blurred poles + if ( texture$1.minFilter === LinearMipmapLinearFilter ) texture$1.minFilter = LinearFilter; + + const camera = new CubeCamera( 1, 10, this ); + + const currentMRT = renderer.getMRT(); + renderer.setMRT( null ); + + camera.update( renderer, scene ); + + renderer.setMRT( currentMRT ); + + texture$1.minFilter = currentMinFilter; + texture$1.currentGenerateMipmaps = currentGenerateMipmaps; + + mesh.geometry.dispose(); + mesh.material.dispose(); + + return this; + + } + +} + +const _cache$1 = new WeakMap(); + +class CubeMapNode extends TempNode { + + static get type() { + + return 'CubeMapNode'; + + } + + constructor( envNode ) { + + super( 'vec3' ); + + this.envNode = envNode; + + this._cubeTexture = null; + this._cubeTextureNode = cubeTexture(); + + const defaultTexture = new CubeTexture(); + defaultTexture.isRenderTargetTexture = true; + + this._defaultTexture = defaultTexture; + + this.updateBeforeType = NodeUpdateType.RENDER; + + } + + updateBefore( frame ) { + + const { renderer, material } = frame; + + const envNode = this.envNode; + + if ( envNode.isTextureNode || envNode.isMaterialReferenceNode ) { + + const texture = ( envNode.isTextureNode ) ? envNode.value : material[ envNode.property ]; + + if ( texture && texture.isTexture ) { + + const mapping = texture.mapping; + + if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) { + + // check for converted cubemap map + + if ( _cache$1.has( texture ) ) { + + const cubeMap = _cache$1.get( texture ); + + mapTextureMapping( cubeMap, texture.mapping ); + this._cubeTexture = cubeMap; + + } else { + + // create cube map from equirectangular map + + const image = texture.image; + + if ( isEquirectangularMapReady$1( image ) ) { + + const renderTarget = new CubeRenderTarget( image.height ); + renderTarget.fromEquirectangularTexture( renderer, texture ); + + mapTextureMapping( renderTarget.texture, texture.mapping ); + this._cubeTexture = renderTarget.texture; + + _cache$1.set( texture, renderTarget.texture ); + + texture.addEventListener( 'dispose', onTextureDispose ); + + } else { + + // default cube texture as fallback when equirectangular texture is not yet loaded + + this._cubeTexture = this._defaultTexture; + + } + + } + + // + + this._cubeTextureNode.value = this._cubeTexture; + + } else { + + // envNode already refers to a cube map + + this._cubeTextureNode = this.envNode; + + } + + } + + } + + } + + setup( builder ) { + + this.updateBefore( builder ); + + return this._cubeTextureNode; + + } + +} + +function isEquirectangularMapReady$1( image ) { + + if ( image === null || image === undefined ) return false; + + return image.height > 0; + +} + +function onTextureDispose( event ) { + + const texture = event.target; + + texture.removeEventListener( 'dispose', onTextureDispose ); + + const renderTarget = _cache$1.get( texture ); + + if ( renderTarget !== undefined ) { + + _cache$1.delete( texture ); + + renderTarget.dispose(); + + } + +} + +function mapTextureMapping( texture, mapping ) { + + if ( mapping === EquirectangularReflectionMapping ) { + + texture.mapping = CubeReflectionMapping; + + } else if ( mapping === EquirectangularRefractionMapping ) { + + texture.mapping = CubeRefractionMapping; + + } + +} + +const cubeMapNode = /*@__PURE__*/ nodeProxy( CubeMapNode ); + +class BasicEnvironmentNode extends LightingNode { + + static get type() { + + return 'BasicEnvironmentNode'; + + } + + constructor( envNode = null ) { + + super(); + + this.envNode = envNode; + + } + + setup( builder ) { + + // environment property is used in the finish() method of BasicLightingModel + + builder.context.environment = cubeMapNode( this.envNode ); + + } + +} + +class BasicLightMapNode extends LightingNode { + + static get type() { + + return 'BasicLightMapNode'; + + } + + constructor( lightMapNode = null ) { + + super(); + + this.lightMapNode = lightMapNode; + + } + + setup( builder ) { + + // irradianceLightMap property is used in the indirectDiffuse() method of BasicLightingModel + + const RECIPROCAL_PI = float( 1 / Math.PI ); + + builder.context.irradianceLightMap = this.lightMapNode.mul( RECIPROCAL_PI ); + + } + +} + +class LightingModel { + + start( /*input, stack, builder*/ ) { } + + finish( /*input, stack, builder*/ ) { } + + direct( /*input, stack, builder*/ ) { } + + directRectArea( /*input, stack, builder*/ ) {} + + indirect( /*input, stack, builder*/ ) { } + + ambientOcclusion( /*input, stack, builder*/ ) { } + +} + +class BasicLightingModel extends LightingModel { + + constructor() { + + super(); + + } + + indirect( context, stack, builder ) { + + const ambientOcclusion = context.ambientOcclusion; + const reflectedLight = context.reflectedLight; + const irradianceLightMap = builder.context.irradianceLightMap; + + reflectedLight.indirectDiffuse.assign( vec4( 0.0 ) ); + + // accumulation (baked indirect lighting only) + + if ( irradianceLightMap ) { + + reflectedLight.indirectDiffuse.addAssign( irradianceLightMap ); + + } else { + + reflectedLight.indirectDiffuse.addAssign( vec4( 1.0, 1.0, 1.0, 0.0 ) ); + + } + + // modulation + + reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion ); + + reflectedLight.indirectDiffuse.mulAssign( diffuseColor.rgb ); + + } + + finish( context, stack, builder ) { + + const material = builder.material; + const outgoingLight = context.outgoingLight; + const envNode = builder.context.environment; + + if ( envNode ) { + + switch ( material.combine ) { + + case MultiplyOperation: + outgoingLight.rgb.assign( mix( outgoingLight.rgb, outgoingLight.rgb.mul( envNode.rgb ), materialSpecularStrength.mul( materialReflectivity ) ) ); + break; + + case MixOperation: + outgoingLight.rgb.assign( mix( outgoingLight.rgb, envNode.rgb, materialSpecularStrength.mul( materialReflectivity ) ) ); + break; + + case AddOperation: + outgoingLight.rgb.addAssign( envNode.rgb.mul( materialSpecularStrength.mul( materialReflectivity ) ) ); + break; + + default: + console.warn( 'THREE.BasicLightingModel: Unsupported .combine value:', material.combine ); + break; + + } + + } + + } + +} + +const _defaultValues$9 = /*@__PURE__*/ new MeshBasicMaterial(); + +class MeshBasicNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshBasicNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isMeshBasicNodeMaterial = true; + + this.lights = true; + + this.setDefaultValues( _defaultValues$9 ); + + this.setValues( parameters ); + + } + + setupNormal() { + + return normalView; // see #28839 + + } + + setupEnvironment( builder ) { + + const envNode = super.setupEnvironment( builder ); + + return envNode ? new BasicEnvironmentNode( envNode ) : null; + + } + + setupLightMap( builder ) { + + let node = null; + + if ( builder.material.lightMap ) { + + node = new BasicLightMapNode( materialLightMap ); + + } + + return node; + + } + + setupOutgoingLight() { + + return diffuseColor.rgb; + + } + + setupLightingModel() { + + return new BasicLightingModel(); + + } + +} + +const F_Schlick = /*@__PURE__*/ Fn( ( { f0, f90, dotVH } ) => { + + // Original approximation by Christophe Schlick '94 + // float fresnel = pow( 1.0 - dotVH, 5.0 ); + + // Optimized variant (presented by Epic at SIGGRAPH '13) + // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf + const fresnel = dotVH.mul( - 5.55473 ).sub( 6.98316 ).mul( dotVH ).exp2(); + + return f0.mul( fresnel.oneMinus() ).add( f90.mul( fresnel ) ); + +} ); // validated + +const BRDF_Lambert = /*@__PURE__*/ Fn( ( inputs ) => { + + return inputs.diffuseColor.mul( 1 / Math.PI ); // punctual light + +} ); // validated + +const G_BlinnPhong_Implicit = () => float( 0.25 ); + +const D_BlinnPhong = /*@__PURE__*/ Fn( ( { dotNH } ) => { + + return shininess.mul( float( 0.5 ) ).add( 1.0 ).mul( float( 1 / Math.PI ) ).mul( dotNH.pow( shininess ) ); + +} ); + +const BRDF_BlinnPhong = /*@__PURE__*/ Fn( ( { lightDirection } ) => { + + const halfDir = lightDirection.add( positionViewDirection ).normalize(); + + const dotNH = transformedNormalView.dot( halfDir ).clamp(); + const dotVH = positionViewDirection.dot( halfDir ).clamp(); + + const F = F_Schlick( { f0: specularColor, f90: 1.0, dotVH } ); + const G = G_BlinnPhong_Implicit(); + const D = D_BlinnPhong( { dotNH } ); + + return F.mul( G ).mul( D ); + +} ); + +class PhongLightingModel extends BasicLightingModel { + + constructor( specular = true ) { + + super(); + + this.specular = specular; + + } + + direct( { lightDirection, lightColor, reflectedLight } ) { + + const dotNL = transformedNormalView.dot( lightDirection ).clamp(); + const irradiance = dotNL.mul( lightColor ); + + reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) ); + + if ( this.specular === true ) { + + reflectedLight.directSpecular.addAssign( irradiance.mul( BRDF_BlinnPhong( { lightDirection } ) ).mul( materialSpecularStrength ) ); + + } + + } + + indirect( { ambientOcclusion, irradiance, reflectedLight } ) { + + reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) ); + + reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion ); + + } + +} + +const _defaultValues$8 = /*@__PURE__*/ new MeshLambertMaterial(); + +class MeshLambertNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshLambertNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isMeshLambertNodeMaterial = true; + + this.lights = true; + + this.setDefaultValues( _defaultValues$8 ); + + this.setValues( parameters ); + + } + + setupEnvironment( builder ) { + + const envNode = super.setupEnvironment( builder ); + + return envNode ? new BasicEnvironmentNode( envNode ) : null; + + } + + setupLightingModel( /*builder*/ ) { + + return new PhongLightingModel( false ); // ( specular ) -> force lambert + + } + +} + +const _defaultValues$7 = /*@__PURE__*/ new MeshPhongMaterial(); + +class MeshPhongNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshPhongNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isMeshPhongNodeMaterial = true; + + this.lights = true; + + this.shininessNode = null; + this.specularNode = null; + + this.setDefaultValues( _defaultValues$7 ); + + this.setValues( parameters ); + + } + + setupEnvironment( builder ) { + + const envNode = super.setupEnvironment( builder ); + + return envNode ? new BasicEnvironmentNode( envNode ) : null; + + } + + setupLightingModel( /*builder*/ ) { + + return new PhongLightingModel(); + + } + + setupVariants() { + + // SHININESS + + const shininessNode = ( this.shininessNode ? float( this.shininessNode ) : materialShininess ).max( 1e-4 ); // to prevent pow( 0.0, 0.0 ) + + shininess.assign( shininessNode ); + + // SPECULAR COLOR + + const specularNode = this.specularNode || materialSpecular; + + specularColor.assign( specularNode ); + + } + + copy( source ) { + + this.shininessNode = source.shininessNode; + this.specularNode = source.specularNode; + + return super.copy( source ); + + } + +} + +const getGeometryRoughness = /*@__PURE__*/ Fn( ( builder ) => { + + if ( builder.geometry.hasAttribute( 'normal' ) === false ) { + + return float( 0 ); + + } + + const dxy = normalView.dFdx().abs().max( normalView.dFdy().abs() ); + const geometryRoughness = dxy.x.max( dxy.y ).max( dxy.z ); + + return geometryRoughness; + +} ); + +const getRoughness = /*@__PURE__*/ Fn( ( inputs ) => { + + const { roughness } = inputs; + + const geometryRoughness = getGeometryRoughness(); + + let roughnessFactor = roughness.max( 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap. + roughnessFactor = roughnessFactor.add( geometryRoughness ); + roughnessFactor = roughnessFactor.min( 1.0 ); + + return roughnessFactor; + +} ); + +// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2 +// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf +const V_GGX_SmithCorrelated = /*@__PURE__*/ Fn( ( { alpha, dotNL, dotNV } ) => { + + const a2 = alpha.pow2(); + + const gv = dotNL.mul( a2.add( a2.oneMinus().mul( dotNV.pow2() ) ).sqrt() ); + const gl = dotNV.mul( a2.add( a2.oneMinus().mul( dotNL.pow2() ) ).sqrt() ); + + return div( 0.5, gv.add( gl ).max( EPSILON ) ); + +} ).setLayout( { + name: 'V_GGX_SmithCorrelated', + type: 'float', + inputs: [ + { name: 'alpha', type: 'float' }, + { name: 'dotNL', type: 'float' }, + { name: 'dotNV', type: 'float' } + ] +} ); // validated + +// https://google.github.io/filament/Filament.md.html#materialsystem/anisotropicmodel/anisotropicspecularbrdf + +const V_GGX_SmithCorrelated_Anisotropic = /*@__PURE__*/ Fn( ( { alphaT, alphaB, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL } ) => { + + const gv = dotNL.mul( vec3( alphaT.mul( dotTV ), alphaB.mul( dotBV ), dotNV ).length() ); + const gl = dotNV.mul( vec3( alphaT.mul( dotTL ), alphaB.mul( dotBL ), dotNL ).length() ); + const v = div( 0.5, gv.add( gl ) ); + + return v.saturate(); + +} ).setLayout( { + name: 'V_GGX_SmithCorrelated_Anisotropic', + type: 'float', + inputs: [ + { name: 'alphaT', type: 'float', qualifier: 'in' }, + { name: 'alphaB', type: 'float', qualifier: 'in' }, + { name: 'dotTV', type: 'float', qualifier: 'in' }, + { name: 'dotBV', type: 'float', qualifier: 'in' }, + { name: 'dotTL', type: 'float', qualifier: 'in' }, + { name: 'dotBL', type: 'float', qualifier: 'in' }, + { name: 'dotNV', type: 'float', qualifier: 'in' }, + { name: 'dotNL', type: 'float', qualifier: 'in' } + ] +} ); + +// Microfacet Models for Refraction through Rough Surfaces - equation (33) +// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html +// alpha is "roughness squared" in Disney’s reparameterization +const D_GGX = /*@__PURE__*/ Fn( ( { alpha, dotNH } ) => { + + const a2 = alpha.pow2(); + + const denom = dotNH.pow2().mul( a2.oneMinus() ).oneMinus(); // avoid alpha = 0 with dotNH = 1 + + return a2.div( denom.pow2() ).mul( 1 / Math.PI ); + +} ).setLayout( { + name: 'D_GGX', + type: 'float', + inputs: [ + { name: 'alpha', type: 'float' }, + { name: 'dotNH', type: 'float' } + ] +} ); // validated + +const RECIPROCAL_PI = /*@__PURE__*/ float( 1 / Math.PI ); + +// https://google.github.io/filament/Filament.md.html#materialsystem/anisotropicmodel/anisotropicspecularbrdf + +const D_GGX_Anisotropic = /*@__PURE__*/ Fn( ( { alphaT, alphaB, dotNH, dotTH, dotBH } ) => { + + const a2 = alphaT.mul( alphaB ); + const v = vec3( alphaB.mul( dotTH ), alphaT.mul( dotBH ), a2.mul( dotNH ) ); + const v2 = v.dot( v ); + const w2 = a2.div( v2 ); + + return RECIPROCAL_PI.mul( a2.mul( w2.pow2() ) ); + +} ).setLayout( { + name: 'D_GGX_Anisotropic', + type: 'float', + inputs: [ + { name: 'alphaT', type: 'float', qualifier: 'in' }, + { name: 'alphaB', type: 'float', qualifier: 'in' }, + { name: 'dotNH', type: 'float', qualifier: 'in' }, + { name: 'dotTH', type: 'float', qualifier: 'in' }, + { name: 'dotBH', type: 'float', qualifier: 'in' } + ] +} ); + +// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility +const BRDF_GGX = /*@__PURE__*/ Fn( ( inputs ) => { + + const { lightDirection, f0, f90, roughness, f, USE_IRIDESCENCE, USE_ANISOTROPY } = inputs; + + const normalView = inputs.normalView || transformedNormalView; + + const alpha = roughness.pow2(); // UE4's roughness + + const halfDir = lightDirection.add( positionViewDirection ).normalize(); + + const dotNL = normalView.dot( lightDirection ).clamp(); + const dotNV = normalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV + const dotNH = normalView.dot( halfDir ).clamp(); + const dotVH = positionViewDirection.dot( halfDir ).clamp(); + + let F = F_Schlick( { f0, f90, dotVH } ); + let V, D; + + if ( defined( USE_IRIDESCENCE ) ) { + + F = iridescence.mix( F, f ); + + } + + if ( defined( USE_ANISOTROPY ) ) { + + const dotTL = anisotropyT.dot( lightDirection ); + const dotTV = anisotropyT.dot( positionViewDirection ); + const dotTH = anisotropyT.dot( halfDir ); + const dotBL = anisotropyB.dot( lightDirection ); + const dotBV = anisotropyB.dot( positionViewDirection ); + const dotBH = anisotropyB.dot( halfDir ); + + V = V_GGX_SmithCorrelated_Anisotropic( { alphaT, alphaB: alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL } ); + D = D_GGX_Anisotropic( { alphaT, alphaB: alpha, dotNH, dotTH, dotBH } ); + + } else { + + V = V_GGX_SmithCorrelated( { alpha, dotNL, dotNV } ); + D = D_GGX( { alpha, dotNH } ); + + } + + return F.mul( V ).mul( D ); + +} ); // validated + +// Analytical approximation of the DFG LUT, one half of the +// split-sum approximation used in indirect specular lighting. +// via 'environmentBRDF' from "Physically Based Shading on Mobile" +// https://www.unrealengine.com/blog/physically-based-shading-on-mobile +const DFGApprox = /*@__PURE__*/ Fn( ( { roughness, dotNV } ) => { + + const c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); + + const c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); + + const r = roughness.mul( c0 ).add( c1 ); + + const a004 = r.x.mul( r.x ).min( dotNV.mul( - 9.28 ).exp2() ).mul( r.x ).add( r.y ); + + const fab = vec2( - 1.04, 1.04 ).mul( a004 ).add( r.zw ); + + return fab; + +} ).setLayout( { + name: 'DFGApprox', + type: 'vec2', + inputs: [ + { name: 'roughness', type: 'float' }, + { name: 'dotNV', type: 'vec3' } + ] +} ); + +const EnvironmentBRDF = /*@__PURE__*/ Fn( ( inputs ) => { + + const { dotNV, specularColor, specularF90, roughness } = inputs; + + const fab = DFGApprox( { dotNV, roughness } ); + return specularColor.mul( fab.x ).add( specularF90.mul( fab.y ) ); + +} ); + +const Schlick_to_F0 = /*@__PURE__*/ Fn( ( { f, f90, dotVH } ) => { + + const x = dotVH.oneMinus().saturate(); + const x2 = x.mul( x ); + const x5 = x.mul( x2, x2 ).clamp( 0, .9999 ); + + return f.sub( vec3( f90 ).mul( x5 ) ).div( x5.oneMinus() ); + +} ).setLayout( { + name: 'Schlick_to_F0', + type: 'vec3', + inputs: [ + { name: 'f', type: 'vec3' }, + { name: 'f90', type: 'float' }, + { name: 'dotVH', type: 'float' } + ] +} ); + +// https://github.com/google/filament/blob/master/shaders/src/brdf.fs +const D_Charlie = /*@__PURE__*/ Fn( ( { roughness, dotNH } ) => { + + const alpha = roughness.pow2(); + + // Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF" + const invAlpha = float( 1.0 ).div( alpha ); + const cos2h = dotNH.pow2(); + const sin2h = cos2h.oneMinus().max( 0.0078125 ); // 2^(-14/2), so sin2h^2 > 0 in fp16 + + return float( 2.0 ).add( invAlpha ).mul( sin2h.pow( invAlpha.mul( 0.5 ) ) ).div( 2.0 * Math.PI ); + +} ).setLayout( { + name: 'D_Charlie', + type: 'float', + inputs: [ + { name: 'roughness', type: 'float' }, + { name: 'dotNH', type: 'float' } + ] +} ); + +// https://github.com/google/filament/blob/master/shaders/src/brdf.fs +const V_Neubelt = /*@__PURE__*/ Fn( ( { dotNV, dotNL } ) => { + + // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886" + return float( 1.0 ).div( float( 4.0 ).mul( dotNL.add( dotNV ).sub( dotNL.mul( dotNV ) ) ) ); + +} ).setLayout( { + name: 'V_Neubelt', + type: 'float', + inputs: [ + { name: 'dotNV', type: 'float' }, + { name: 'dotNL', type: 'float' } + ] +} ); + +const BRDF_Sheen = /*@__PURE__*/ Fn( ( { lightDirection } ) => { + + const halfDir = lightDirection.add( positionViewDirection ).normalize(); + + const dotNL = transformedNormalView.dot( lightDirection ).clamp(); + const dotNV = transformedNormalView.dot( positionViewDirection ).clamp(); + const dotNH = transformedNormalView.dot( halfDir ).clamp(); + + const D = D_Charlie( { roughness: sheenRoughness, dotNH } ); + const V = V_Neubelt( { dotNV, dotNL } ); + + return sheen.mul( D ).mul( V ); + +} ); + +// Rect Area Light + +// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines +// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt +// code: https://github.com/selfshadow/ltc_code/ + +const LTC_Uv = /*@__PURE__*/ Fn( ( { N, V, roughness } ) => { + + const LUT_SIZE = 64.0; + const LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; + const LUT_BIAS = 0.5 / LUT_SIZE; + + const dotNV = N.dot( V ).saturate(); + + // texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) ) + const uv = vec2( roughness, dotNV.oneMinus().sqrt() ); + + uv.assign( uv.mul( LUT_SCALE ).add( LUT_BIAS ) ); + + return uv; + +} ).setLayout( { + name: 'LTC_Uv', + type: 'vec2', + inputs: [ + { name: 'N', type: 'vec3' }, + { name: 'V', type: 'vec3' }, + { name: 'roughness', type: 'float' } + ] +} ); + +const LTC_ClippedSphereFormFactor = /*@__PURE__*/ Fn( ( { f } ) => { + + // Real-Time Area Lighting: a Journey from Research to Production (p.102) + // An approximation of the form factor of a horizon-clipped rectangle. + + const l = f.length(); + + return max$1( l.mul( l ).add( f.z ).div( l.add( 1.0 ) ), 0 ); + +} ).setLayout( { + name: 'LTC_ClippedSphereFormFactor', + type: 'float', + inputs: [ + { name: 'f', type: 'vec3' } + ] +} ); + +const LTC_EdgeVectorFormFactor = /*@__PURE__*/ Fn( ( { v1, v2 } ) => { + + const x = v1.dot( v2 ); + const y = x.abs().toVar(); + + // rational polynomial approximation to theta / sin( theta ) / 2PI + const a = y.mul( 0.0145206 ).add( 0.4965155 ).mul( y ).add( 0.8543985 ).toVar(); + const b = y.add( 4.1616724 ).mul( y ).add( 3.4175940 ).toVar(); + const v = a.div( b ); + + const theta_sintheta = x.greaterThan( 0.0 ).select( v, max$1( x.mul( x ).oneMinus(), 1e-7 ).inverseSqrt().mul( 0.5 ).sub( v ) ); + + return v1.cross( v2 ).mul( theta_sintheta ); + +} ).setLayout( { + name: 'LTC_EdgeVectorFormFactor', + type: 'vec3', + inputs: [ + { name: 'v1', type: 'vec3' }, + { name: 'v2', type: 'vec3' } + ] +} ); + +const LTC_Evaluate = /*@__PURE__*/ Fn( ( { N, V, P, mInv, p0, p1, p2, p3 } ) => { + + // bail if point is on back side of plane of light + // assumes ccw winding order of light vertices + const v1 = p1.sub( p0 ).toVar(); + const v2 = p3.sub( p0 ).toVar(); + + const lightNormal = v1.cross( v2 ); + const result = vec3().toVar(); + + If( lightNormal.dot( P.sub( p0 ) ).greaterThanEqual( 0.0 ), () => { + + // construct orthonormal basis around N + const T1 = V.sub( N.mul( V.dot( N ) ) ).normalize(); + const T2 = N.cross( T1 ).negate(); // negated from paper; possibly due to a different handedness of world coordinate system + + // compute transform + const mat = mInv.mul( mat3( T1, T2, N ).transpose() ).toVar(); + + // transform rect + // & project rect onto sphere + const coords0 = mat.mul( p0.sub( P ) ).normalize().toVar(); + const coords1 = mat.mul( p1.sub( P ) ).normalize().toVar(); + const coords2 = mat.mul( p2.sub( P ) ).normalize().toVar(); + const coords3 = mat.mul( p3.sub( P ) ).normalize().toVar(); + + // calculate vector form factor + const vectorFormFactor = vec3( 0 ).toVar(); + vectorFormFactor.addAssign( LTC_EdgeVectorFormFactor( { v1: coords0, v2: coords1 } ) ); + vectorFormFactor.addAssign( LTC_EdgeVectorFormFactor( { v1: coords1, v2: coords2 } ) ); + vectorFormFactor.addAssign( LTC_EdgeVectorFormFactor( { v1: coords2, v2: coords3 } ) ); + vectorFormFactor.addAssign( LTC_EdgeVectorFormFactor( { v1: coords3, v2: coords0 } ) ); + + // adjust for horizon clipping + result.assign( vec3( LTC_ClippedSphereFormFactor( { f: vectorFormFactor } ) ) ); + + } ); + + return result; + +} ).setLayout( { + name: 'LTC_Evaluate', + type: 'vec3', + inputs: [ + { name: 'N', type: 'vec3' }, + { name: 'V', type: 'vec3' }, + { name: 'P', type: 'vec3' }, + { name: 'mInv', type: 'mat3' }, + { name: 'p0', type: 'vec3' }, + { name: 'p1', type: 'vec3' }, + { name: 'p2', type: 'vec3' }, + { name: 'p3', type: 'vec3' } + ] +} ); + +// Mipped Bicubic Texture Filtering by N8 +// https://www.shadertoy.com/view/Dl2SDW + +const bC = 1.0 / 6.0; + +const w0 = ( a ) => mul( bC, mul( a, mul( a, a.negate().add( 3.0 ) ).sub( 3.0 ) ).add( 1.0 ) ); + +const w1 = ( a ) => mul( bC, mul( a, mul( a, mul( 3.0, a ).sub( 6.0 ) ) ).add( 4.0 ) ); + +const w2 = ( a ) => mul( bC, mul( a, mul( a, mul( - 3.0, a ).add( 3.0 ) ).add( 3.0 ) ).add( 1.0 ) ); + +const w3 = ( a ) => mul( bC, pow( a, 3 ) ); + +const g0 = ( a ) => w0( a ).add( w1( a ) ); + +const g1 = ( a ) => w2( a ).add( w3( a ) ); + +// h0 and h1 are the two offset functions +const h0 = ( a ) => add( - 1.0, w1( a ).div( w0( a ).add( w1( a ) ) ) ); + +const h1 = ( a ) => add( 1.0, w3( a ).div( w2( a ).add( w3( a ) ) ) ); + +const bicubic = ( textureNode, texelSize, lod ) => { + + const uv = textureNode.uvNode; + const uvScaled = mul( uv, texelSize.zw ).add( 0.5 ); + + const iuv = floor( uvScaled ); + const fuv = fract( uvScaled ); + + const g0x = g0( fuv.x ); + const g1x = g1( fuv.x ); + const h0x = h0( fuv.x ); + const h1x = h1( fuv.x ); + const h0y = h0( fuv.y ); + const h1y = h1( fuv.y ); + + const p0 = vec2( iuv.x.add( h0x ), iuv.y.add( h0y ) ).sub( 0.5 ).mul( texelSize.xy ); + const p1 = vec2( iuv.x.add( h1x ), iuv.y.add( h0y ) ).sub( 0.5 ).mul( texelSize.xy ); + const p2 = vec2( iuv.x.add( h0x ), iuv.y.add( h1y ) ).sub( 0.5 ).mul( texelSize.xy ); + const p3 = vec2( iuv.x.add( h1x ), iuv.y.add( h1y ) ).sub( 0.5 ).mul( texelSize.xy ); + + const a = g0( fuv.y ).mul( add( g0x.mul( textureNode.uv( p0 ).level( lod ) ), g1x.mul( textureNode.uv( p1 ).level( lod ) ) ) ); + const b = g1( fuv.y ).mul( add( g0x.mul( textureNode.uv( p2 ).level( lod ) ), g1x.mul( textureNode.uv( p3 ).level( lod ) ) ) ); + + return a.add( b ); + +}; + +const textureBicubic = /*@__PURE__*/ Fn( ( [ textureNode, lodNode = float( 3 ) ] ) => { + + const fLodSize = vec2( textureNode.size( int( lodNode ) ) ); + const cLodSize = vec2( textureNode.size( int( lodNode.add( 1.0 ) ) ) ); + const fLodSizeInv = div( 1.0, fLodSize ); + const cLodSizeInv = div( 1.0, cLodSize ); + const fSample = bicubic( textureNode, vec4( fLodSizeInv, fLodSize ), floor( lodNode ) ); + const cSample = bicubic( textureNode, vec4( cLodSizeInv, cLodSize ), ceil( lodNode ) ); + + return fract( lodNode ).mix( fSample, cSample ); + +} ); + +// +// Transmission +// + +const getVolumeTransmissionRay = /*@__PURE__*/ Fn( ( [ n, v, thickness, ior, modelMatrix ] ) => { + + // Direction of refracted light. + const refractionVector = vec3( refract( v.negate(), normalize( n ), div( 1.0, ior ) ) ); + + // Compute rotation-independant scaling of the model matrix. + const modelScale = vec3( + length( modelMatrix[ 0 ].xyz ), + length( modelMatrix[ 1 ].xyz ), + length( modelMatrix[ 2 ].xyz ) + ); + + // The thickness is specified in local space. + return normalize( refractionVector ).mul( thickness.mul( modelScale ) ); + +} ).setLayout( { + name: 'getVolumeTransmissionRay', + type: 'vec3', + inputs: [ + { name: 'n', type: 'vec3' }, + { name: 'v', type: 'vec3' }, + { name: 'thickness', type: 'float' }, + { name: 'ior', type: 'float' }, + { name: 'modelMatrix', type: 'mat4' } + ] +} ); + +const applyIorToRoughness = /*@__PURE__*/ Fn( ( [ roughness, ior ] ) => { + + // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and + // an IOR of 1.5 results in the default amount of microfacet refraction. + return roughness.mul( clamp( ior.mul( 2.0 ).sub( 2.0 ), 0.0, 1.0 ) ); + +} ).setLayout( { + name: 'applyIorToRoughness', + type: 'float', + inputs: [ + { name: 'roughness', type: 'float' }, + { name: 'ior', type: 'float' } + ] +} ); + +const viewportBackSideTexture = /*@__PURE__*/ viewportMipTexture(); +const viewportFrontSideTexture = /*@__PURE__*/ viewportMipTexture(); + +const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ], { material } ) => { + + const vTexture = material.side == BackSide ? viewportBackSideTexture : viewportFrontSideTexture; + + const transmissionSample = vTexture.uv( fragCoord ); + //const transmissionSample = viewportMipTexture( fragCoord ); + + const lod = log2( screenSize.x ).mul( applyIorToRoughness( roughness, ior ) ); + + return textureBicubic( transmissionSample, lod ); + +} ); + +const volumeAttenuation = /*@__PURE__*/ Fn( ( [ transmissionDistance, attenuationColor, attenuationDistance ] ) => { + + If( attenuationDistance.notEqual( 0 ), () => { + + // Compute light attenuation using Beer's law. + const attenuationCoefficient = log( attenuationColor ).negate().div( attenuationDistance ); + const transmittance = exp( attenuationCoefficient.negate().mul( transmissionDistance ) ); + + return transmittance; + + } ); + + // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all. + return vec3( 1.0 ); + +} ).setLayout( { + name: 'volumeAttenuation', + type: 'vec3', + inputs: [ + { name: 'transmissionDistance', type: 'float' }, + { name: 'attenuationColor', type: 'vec3' }, + { name: 'attenuationDistance', type: 'float' } + ] +} ); + +const getIBLVolumeRefraction = /*@__PURE__*/ Fn( ( [ n, v, roughness, diffuseColor, specularColor, specularF90, position, modelMatrix, viewMatrix, projMatrix, ior, thickness, attenuationColor, attenuationDistance, dispersion ] ) => { + + let transmittedLight, transmittance; + + if ( dispersion ) { + + transmittedLight = vec4().toVar(); + transmittance = vec3().toVar(); + + const halfSpread = ior.sub( 1.0 ).mul( dispersion.mul( 0.025 ) ); + const iors = vec3( ior.sub( halfSpread ), ior, ior.add( halfSpread ) ); + + Loop( { start: 0, end: 3 }, ( { i } ) => { + + const ior = iors.element( i ); + + const transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); + const refractedRayExit = position.add( transmissionRay ); + + // Project refracted vector on the framebuffer, while mapping to normalized device coordinates. + const ndcPos = projMatrix.mul( viewMatrix.mul( vec4( refractedRayExit, 1.0 ) ) ); + const refractionCoords = vec2( ndcPos.xy.div( ndcPos.w ) ).toVar(); + refractionCoords.addAssign( 1.0 ); + refractionCoords.divAssign( 2.0 ); + refractionCoords.assign( vec2( refractionCoords.x, refractionCoords.y.oneMinus() ) ); // webgpu + + // Sample framebuffer to get pixel the refracted ray hits. + const transmissionSample = getTransmissionSample( refractionCoords, roughness, ior ); + + transmittedLight.element( i ).assign( transmissionSample.element( i ) ); + transmittedLight.a.addAssign( transmissionSample.a ); + + transmittance.element( i ).assign( diffuseColor.element( i ).mul( volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ).element( i ) ) ); + + } ); + + transmittedLight.a.divAssign( 3.0 ); + + } else { + + const transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); + const refractedRayExit = position.add( transmissionRay ); + + // Project refracted vector on the framebuffer, while mapping to normalized device coordinates. + const ndcPos = projMatrix.mul( viewMatrix.mul( vec4( refractedRayExit, 1.0 ) ) ); + const refractionCoords = vec2( ndcPos.xy.div( ndcPos.w ) ).toVar(); + refractionCoords.addAssign( 1.0 ); + refractionCoords.divAssign( 2.0 ); + refractionCoords.assign( vec2( refractionCoords.x, refractionCoords.y.oneMinus() ) ); // webgpu + + // Sample framebuffer to get pixel the refracted ray hits. + transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); + transmittance = diffuseColor.mul( volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ) ); + + } + + const attenuatedColor = transmittance.rgb.mul( transmittedLight.rgb ); + const dotNV = n.dot( v ).clamp(); + + // Get the specular component. + const F = vec3( EnvironmentBRDF( { // n, v, specularColor, specularF90, roughness + dotNV, + specularColor, + specularF90, + roughness + } ) ); + + // As less light is transmitted, the opacity should be increased. This simple approximation does a decent job + // of modulating a CSS background, and has no effect when the buffer is opaque, due to a solid object or clear color. + const transmittanceFactor = transmittance.r.add( transmittance.g, transmittance.b ).div( 3.0 ); + + return vec4( F.oneMinus().mul( attenuatedColor ), transmittedLight.a.oneMinus().mul( transmittanceFactor ).oneMinus() ); + +} ); + +// +// Iridescence +// + +// XYZ to linear-sRGB color space +const XYZ_TO_REC709 = /*@__PURE__*/ mat3( + 3.2404542, - 0.9692660, 0.0556434, + - 1.5371385, 1.8760108, - 0.2040259, + - 0.4985314, 0.0415560, 1.0572252 +); + +// Assume air interface for top +// Note: We don't handle the case fresnel0 == 1 +const Fresnel0ToIor = ( fresnel0 ) => { + + const sqrtF0 = fresnel0.sqrt(); + return vec3( 1.0 ).add( sqrtF0 ).div( vec3( 1.0 ).sub( sqrtF0 ) ); + +}; + +// ior is a value between 1.0 and 3.0. 1.0 is air interface +const IorToFresnel0 = ( transmittedIor, incidentIor ) => { + + return transmittedIor.sub( incidentIor ).div( transmittedIor.add( incidentIor ) ).pow2(); + +}; + +// Fresnel equations for dielectric/dielectric interfaces. +// Ref: https://belcour.github.io/blog/research/2017/05/01/brdf-thin-film.html +// Evaluation XYZ sensitivity curves in Fourier space +const evalSensitivity = ( OPD, shift ) => { + + const phase = OPD.mul( 2.0 * Math.PI * 1.0e-9 ); + const val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 ); + const pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 ); + const VAR = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 ); + + const x = float( 9.7470e-14 * Math.sqrt( 2.0 * Math.PI * 4.5282e+09 ) ).mul( phase.mul( 2.2399e+06 ).add( shift.x ).cos() ).mul( phase.pow2().mul( - 4.5282e+09 ).exp() ); + + let xyz = val.mul( VAR.mul( 2.0 * Math.PI ).sqrt() ).mul( pos.mul( phase ).add( shift ).cos() ).mul( phase.pow2().negate().mul( VAR ).exp() ); + xyz = vec3( xyz.x.add( x ), xyz.y, xyz.z ).div( 1.0685e-7 ); + + const rgb = XYZ_TO_REC709.mul( xyz ); + + return rgb; + +}; + +const evalIridescence = /*@__PURE__*/ Fn( ( { outsideIOR, eta2, cosTheta1, thinFilmThickness, baseF0 } ) => { + + // Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0 + const iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) ); + // Evaluate the cosTheta on the base layer (Snell law) + const sinTheta2Sq = outsideIOR.div( iridescenceIOR ).pow2().mul( cosTheta1.pow2().oneMinus() ); + + // Handle TIR: + const cosTheta2Sq = sinTheta2Sq.oneMinus(); + + If( cosTheta2Sq.lessThan( 0 ), () => { + + return vec3( 1.0 ); + + } ); + + const cosTheta2 = cosTheta2Sq.sqrt(); + + // First interface + const R0 = IorToFresnel0( iridescenceIOR, outsideIOR ); + const R12 = F_Schlick( { f0: R0, f90: 1.0, dotVH: cosTheta1 } ); + //const R21 = R12; + const T121 = R12.oneMinus(); + const phi12 = iridescenceIOR.lessThan( outsideIOR ).select( Math.PI, 0.0 ); + const phi21 = float( Math.PI ).sub( phi12 ); + + // Second interface + const baseIOR = Fresnel0ToIor( baseF0.clamp( 0.0, 0.9999 ) ); // guard against 1.0 + const R1 = IorToFresnel0( baseIOR, iridescenceIOR.toVec3() ); + const R23 = F_Schlick( { f0: R1, f90: 1.0, dotVH: cosTheta2 } ); + const phi23 = vec3( + baseIOR.x.lessThan( iridescenceIOR ).select( Math.PI, 0.0 ), + baseIOR.y.lessThan( iridescenceIOR ).select( Math.PI, 0.0 ), + baseIOR.z.lessThan( iridescenceIOR ).select( Math.PI, 0.0 ) + ); + + // Phase shift + const OPD = iridescenceIOR.mul( thinFilmThickness, cosTheta2, 2.0 ); + const phi = vec3( phi21 ).add( phi23 ); + + // Compound terms + const R123 = R12.mul( R23 ).clamp( 1e-5, 0.9999 ); + const r123 = R123.sqrt(); + const Rs = T121.pow2().mul( R23 ).div( vec3( 1.0 ).sub( R123 ) ); + + // Reflectance term for m = 0 (DC term amplitude) + const C0 = R12.add( Rs ); + const I = C0.toVar(); + + // Reflectance term for m > 0 (pairs of diracs) + const Cm = Rs.sub( T121 ).toVar(); + + Loop( { start: 1, end: 2, condition: '<=', name: 'm' }, ( { m } ) => { + + Cm.mulAssign( r123 ); + const Sm = evalSensitivity( float( m ).mul( OPD ), float( m ).mul( phi ) ).mul( 2.0 ); + I.addAssign( Cm.mul( Sm ) ); + + } ); + + // Since out of gamut colors might be produced, negative color values are clamped to 0. + return I.max( vec3( 0.0 ) ); + +} ).setLayout( { + name: 'evalIridescence', + type: 'vec3', + inputs: [ + { name: 'outsideIOR', type: 'float' }, + { name: 'eta2', type: 'float' }, + { name: 'cosTheta1', type: 'float' }, + { name: 'thinFilmThickness', type: 'float' }, + { name: 'baseF0', type: 'vec3' } + ] +} ); + +// +// Sheen +// + +// This is a curve-fit approxmation to the "Charlie sheen" BRDF integrated over the hemisphere from +// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF". The analysis can be found +// in the Sheen section of https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing +const IBLSheenBRDF = /*@__PURE__*/ Fn( ( { normal, viewDir, roughness } ) => { + + const dotNV = normal.dot( viewDir ).saturate(); + + const r2 = roughness.pow2(); + + const a = select( + roughness.lessThan( 0.25 ), + float( - 339.2 ).mul( r2 ).add( float( 161.4 ).mul( roughness ) ).sub( 25.9 ), + float( - 8.48 ).mul( r2 ).add( float( 14.3 ).mul( roughness ) ).sub( 9.95 ) + ); + + const b = select( + roughness.lessThan( 0.25 ), + float( 44.0 ).mul( r2 ).sub( float( 23.7 ).mul( roughness ) ).add( 3.26 ), + float( 1.97 ).mul( r2 ).sub( float( 3.27 ).mul( roughness ) ).add( 0.72 ) + ); + + const DG = select( roughness.lessThan( 0.25 ), 0.0, float( 0.1 ).mul( roughness ).sub( 0.025 ) ).add( a.mul( dotNV ).add( b ).exp() ); + + return DG.mul( 1.0 / Math.PI ).saturate(); + +} ); + +const clearcoatF0 = vec3( 0.04 ); +const clearcoatF90 = float( 1 ); + +// + +class PhysicalLightingModel extends LightingModel { + + constructor( clearcoat = false, sheen = false, iridescence = false, anisotropy = false, transmission = false, dispersion = false ) { + + super(); + + this.clearcoat = clearcoat; + this.sheen = sheen; + this.iridescence = iridescence; + this.anisotropy = anisotropy; + this.transmission = transmission; + this.dispersion = dispersion; + + this.clearcoatRadiance = null; + this.clearcoatSpecularDirect = null; + this.clearcoatSpecularIndirect = null; + this.sheenSpecularDirect = null; + this.sheenSpecularIndirect = null; + this.iridescenceFresnel = null; + this.iridescenceF0 = null; + + } + + start( context ) { + + if ( this.clearcoat === true ) { + + this.clearcoatRadiance = vec3().toVar( 'clearcoatRadiance' ); + this.clearcoatSpecularDirect = vec3().toVar( 'clearcoatSpecularDirect' ); + this.clearcoatSpecularIndirect = vec3().toVar( 'clearcoatSpecularIndirect' ); + + } + + if ( this.sheen === true ) { + + this.sheenSpecularDirect = vec3().toVar( 'sheenSpecularDirect' ); + this.sheenSpecularIndirect = vec3().toVar( 'sheenSpecularIndirect' ); + + } + + if ( this.iridescence === true ) { + + const dotNVi = transformedNormalView.dot( positionViewDirection ).clamp(); + + this.iridescenceFresnel = evalIridescence( { + outsideIOR: float( 1.0 ), + eta2: iridescenceIOR, + cosTheta1: dotNVi, + thinFilmThickness: iridescenceThickness, + baseF0: specularColor + } ); + + this.iridescenceF0 = Schlick_to_F0( { f: this.iridescenceFresnel, f90: 1.0, dotVH: dotNVi } ); + + } + + if ( this.transmission === true ) { + + const position = positionWorld; + const v = cameraPosition.sub( positionWorld ).normalize(); // TODO: Create Node for this, same issue in MaterialX + const n = transformedNormalWorld; + + context.backdrop = getIBLVolumeRefraction( + n, + v, + roughness, + diffuseColor, + specularColor, + specularF90, // specularF90 + position, // positionWorld + modelWorldMatrix, // modelMatrix + cameraViewMatrix, // viewMatrix + cameraProjectionMatrix, // projMatrix + ior, + thickness, + attenuationColor, + attenuationDistance, + this.dispersion ? dispersion : null + ); + + context.backdropAlpha = transmission; + + diffuseColor.a.mulAssign( mix( 1, context.backdrop.a, transmission ) ); + + } + + } + + // Fdez-Agüera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting" + // Approximates multiscattering in order to preserve energy. + // http://www.jcgt.org/published/0008/01/03/ + + computeMultiscattering( singleScatter, multiScatter, specularF90 ) { + + const dotNV = transformedNormalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV + + const fab = DFGApprox( { roughness, dotNV } ); + + const Fr = this.iridescenceF0 ? iridescence.mix( specularColor, this.iridescenceF0 ) : specularColor; + + const FssEss = Fr.mul( fab.x ).add( specularF90.mul( fab.y ) ); + + const Ess = fab.x.add( fab.y ); + const Ems = Ess.oneMinus(); + + const Favg = specularColor.add( specularColor.oneMinus().mul( 0.047619 ) ); // 1/21 + const Fms = FssEss.mul( Favg ).div( Ems.mul( Favg ).oneMinus() ); + + singleScatter.addAssign( FssEss ); + multiScatter.addAssign( Fms.mul( Ems ) ); + + } + + direct( { lightDirection, lightColor, reflectedLight } ) { + + const dotNL = transformedNormalView.dot( lightDirection ).clamp(); + const irradiance = dotNL.mul( lightColor ); + + if ( this.sheen === true ) { + + this.sheenSpecularDirect.addAssign( irradiance.mul( BRDF_Sheen( { lightDirection } ) ) ); + + } + + if ( this.clearcoat === true ) { + + const dotNLcc = transformedClearcoatNormalView.dot( lightDirection ).clamp(); + const ccIrradiance = dotNLcc.mul( lightColor ); + + this.clearcoatSpecularDirect.addAssign( ccIrradiance.mul( BRDF_GGX( { lightDirection, f0: clearcoatF0, f90: clearcoatF90, roughness: clearcoatRoughness, normalView: transformedClearcoatNormalView } ) ) ); + + } + + reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) ); + + reflectedLight.directSpecular.addAssign( irradiance.mul( BRDF_GGX( { lightDirection, f0: specularColor, f90: 1, roughness, iridescence: this.iridescence, f: this.iridescenceFresnel, USE_IRIDESCENCE: this.iridescence, USE_ANISOTROPY: this.anisotropy } ) ) ); + + } + + directRectArea( { lightColor, lightPosition, halfWidth, halfHeight, reflectedLight, ltc_1, ltc_2 } ) { + + const p0 = lightPosition.add( halfWidth ).sub( halfHeight ); // counterclockwise; light shines in local neg z direction + const p1 = lightPosition.sub( halfWidth ).sub( halfHeight ); + const p2 = lightPosition.sub( halfWidth ).add( halfHeight ); + const p3 = lightPosition.add( halfWidth ).add( halfHeight ); + + const N = transformedNormalView; + const V = positionViewDirection; + const P = positionView.toVar(); + + const uv = LTC_Uv( { N, V, roughness } ); + + const t1 = ltc_1.uv( uv ).toVar(); + const t2 = ltc_2.uv( uv ).toVar(); + + const mInv = mat3( + vec3( t1.x, 0, t1.y ), + vec3( 0, 1, 0 ), + vec3( t1.z, 0, t1.w ) + ).toVar(); + + // LTC Fresnel Approximation by Stephen Hill + // http://blog.selfshadow.com/publications/s2016-advances/s2016_ltc_fresnel.pdf + const fresnel = specularColor.mul( t2.x ).add( specularColor.oneMinus().mul( t2.y ) ).toVar(); + + reflectedLight.directSpecular.addAssign( lightColor.mul( fresnel ).mul( LTC_Evaluate( { N, V, P, mInv, p0, p1, p2, p3 } ) ) ); + + reflectedLight.directDiffuse.addAssign( lightColor.mul( diffuseColor ).mul( LTC_Evaluate( { N, V, P, mInv: mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1 ), p0, p1, p2, p3 } ) ) ); + + } + + indirect( context, stack, builder ) { + + this.indirectDiffuse( context, stack, builder ); + this.indirectSpecular( context, stack, builder ); + this.ambientOcclusion( context, stack, builder ); + + } + + indirectDiffuse( { irradiance, reflectedLight } ) { + + reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) ); + + } + + indirectSpecular( { radiance, iblIrradiance, reflectedLight } ) { + + if ( this.sheen === true ) { + + this.sheenSpecularIndirect.addAssign( iblIrradiance.mul( + sheen, + IBLSheenBRDF( { + normal: transformedNormalView, + viewDir: positionViewDirection, + roughness: sheenRoughness + } ) + ) ); + + } + + if ( this.clearcoat === true ) { + + const dotNVcc = transformedClearcoatNormalView.dot( positionViewDirection ).clamp(); + + const clearcoatEnv = EnvironmentBRDF( { + dotNV: dotNVcc, + specularColor: clearcoatF0, + specularF90: clearcoatF90, + roughness: clearcoatRoughness + } ); + + this.clearcoatSpecularIndirect.addAssign( this.clearcoatRadiance.mul( clearcoatEnv ) ); + + } + + // Both indirect specular and indirect diffuse light accumulate here + + const singleScattering = vec3().toVar( 'singleScattering' ); + const multiScattering = vec3().toVar( 'multiScattering' ); + const cosineWeightedIrradiance = iblIrradiance.mul( 1 / Math.PI ); + + this.computeMultiscattering( singleScattering, multiScattering, specularF90 ); + + const totalScattering = singleScattering.add( multiScattering ); + + const diffuse = diffuseColor.mul( totalScattering.r.max( totalScattering.g ).max( totalScattering.b ).oneMinus() ); + + reflectedLight.indirectSpecular.addAssign( radiance.mul( singleScattering ) ); + reflectedLight.indirectSpecular.addAssign( multiScattering.mul( cosineWeightedIrradiance ) ); + + reflectedLight.indirectDiffuse.addAssign( diffuse.mul( cosineWeightedIrradiance ) ); + + } + + ambientOcclusion( { ambientOcclusion, reflectedLight } ) { + + const dotNV = transformedNormalView.dot( positionViewDirection ).clamp(); // @ TODO: Move to core dotNV + + const aoNV = dotNV.add( ambientOcclusion ); + const aoExp = roughness.mul( - 16.0 ).oneMinus().negate().exp2(); + + const aoNode = ambientOcclusion.sub( aoNV.pow( aoExp ).oneMinus() ).clamp(); + + if ( this.clearcoat === true ) { + + this.clearcoatSpecularIndirect.mulAssign( ambientOcclusion ); + + } + + if ( this.sheen === true ) { + + this.sheenSpecularIndirect.mulAssign( ambientOcclusion ); + + } + + reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion ); + reflectedLight.indirectSpecular.mulAssign( aoNode ); + + } + + finish( context ) { + + const { outgoingLight } = context; + + if ( this.clearcoat === true ) { + + const dotNVcc = transformedClearcoatNormalView.dot( positionViewDirection ).clamp(); + + const Fcc = F_Schlick( { + dotVH: dotNVcc, + f0: clearcoatF0, + f90: clearcoatF90 + } ); + + const clearcoatLight = outgoingLight.mul( clearcoat.mul( Fcc ).oneMinus() ).add( this.clearcoatSpecularDirect.add( this.clearcoatSpecularIndirect ).mul( clearcoat ) ); + + outgoingLight.assign( clearcoatLight ); + + } + + if ( this.sheen === true ) { + + const sheenEnergyComp = sheen.r.max( sheen.g ).max( sheen.b ).mul( 0.157 ).oneMinus(); + const sheenLight = outgoingLight.mul( sheenEnergyComp ).add( this.sheenSpecularDirect, this.sheenSpecularIndirect ); + + outgoingLight.assign( sheenLight ); + + } + + } + +} + +// These defines must match with PMREMGenerator + +const cubeUV_r0 = /*@__PURE__*/ float( 1.0 ); +const cubeUV_m0 = /*@__PURE__*/ float( - 2.0 ); +const cubeUV_r1 = /*@__PURE__*/ float( 0.8 ); +const cubeUV_m1 = /*@__PURE__*/ float( - 1.0 ); +const cubeUV_r4 = /*@__PURE__*/ float( 0.4 ); +const cubeUV_m4 = /*@__PURE__*/ float( 2.0 ); +const cubeUV_r5 = /*@__PURE__*/ float( 0.305 ); +const cubeUV_m5 = /*@__PURE__*/ float( 3.0 ); +const cubeUV_r6 = /*@__PURE__*/ float( 0.21 ); +const cubeUV_m6 = /*@__PURE__*/ float( 4.0 ); + +const cubeUV_minMipLevel = /*@__PURE__*/ float( 4.0 ); +const cubeUV_minTileSize = /*@__PURE__*/ float( 16.0 ); + +// These shader functions convert between the UV coordinates of a single face of +// a cubemap, the 0-5 integer index of a cube face, and the direction vector for +// sampling a textureCube (not generally normalized ). + +const getFace = /*@__PURE__*/ Fn( ( [ direction ] ) => { + + const absDirection = vec3( abs( direction ) ).toVar(); + const face = float( - 1.0 ).toVar(); + + If( absDirection.x.greaterThan( absDirection.z ), () => { + + If( absDirection.x.greaterThan( absDirection.y ), () => { + + face.assign( select( direction.x.greaterThan( 0.0 ), 0.0, 3.0 ) ); + + } ).Else( () => { + + face.assign( select( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) ); + + } ); + + } ).Else( () => { + + If( absDirection.z.greaterThan( absDirection.y ), () => { + + face.assign( select( direction.z.greaterThan( 0.0 ), 2.0, 5.0 ) ); + + } ).Else( () => { + + face.assign( select( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) ); + + } ); + + } ); + + return face; + +} ).setLayout( { + name: 'getFace', + type: 'float', + inputs: [ + { name: 'direction', type: 'vec3' } + ] +} ); + +// RH coordinate system; PMREM face-indexing convention +const getUV = /*@__PURE__*/ Fn( ( [ direction, face ] ) => { + + const uv = vec2().toVar(); + + If( face.equal( 0.0 ), () => { + + uv.assign( vec2( direction.z, direction.y ).div( abs( direction.x ) ) ); // pos x + + } ).ElseIf( face.equal( 1.0 ), () => { + + uv.assign( vec2( direction.x.negate(), direction.z.negate() ).div( abs( direction.y ) ) ); // pos y + + } ).ElseIf( face.equal( 2.0 ), () => { + + uv.assign( vec2( direction.x.negate(), direction.y ).div( abs( direction.z ) ) ); // pos z + + } ).ElseIf( face.equal( 3.0 ), () => { + + uv.assign( vec2( direction.z.negate(), direction.y ).div( abs( direction.x ) ) ); // neg x + + } ).ElseIf( face.equal( 4.0 ), () => { + + uv.assign( vec2( direction.x.negate(), direction.z ).div( abs( direction.y ) ) ); // neg y + + } ).Else( () => { + + uv.assign( vec2( direction.x, direction.y ).div( abs( direction.z ) ) ); // neg z + + } ); + + return mul( 0.5, uv.add( 1.0 ) ); + +} ).setLayout( { + name: 'getUV', + type: 'vec2', + inputs: [ + { name: 'direction', type: 'vec3' }, + { name: 'face', type: 'float' } + ] +} ); + +const roughnessToMip = /*@__PURE__*/ Fn( ( [ roughness ] ) => { + + const mip = float( 0.0 ).toVar(); + + If( roughness.greaterThanEqual( cubeUV_r1 ), () => { + + mip.assign( cubeUV_r0.sub( roughness ).mul( cubeUV_m1.sub( cubeUV_m0 ) ).div( cubeUV_r0.sub( cubeUV_r1 ) ).add( cubeUV_m0 ) ); + + } ).ElseIf( roughness.greaterThanEqual( cubeUV_r4 ), () => { + + mip.assign( cubeUV_r1.sub( roughness ).mul( cubeUV_m4.sub( cubeUV_m1 ) ).div( cubeUV_r1.sub( cubeUV_r4 ) ).add( cubeUV_m1 ) ); + + } ).ElseIf( roughness.greaterThanEqual( cubeUV_r5 ), () => { + + mip.assign( cubeUV_r4.sub( roughness ).mul( cubeUV_m5.sub( cubeUV_m4 ) ).div( cubeUV_r4.sub( cubeUV_r5 ) ).add( cubeUV_m4 ) ); + + } ).ElseIf( roughness.greaterThanEqual( cubeUV_r6 ), () => { + + mip.assign( cubeUV_r5.sub( roughness ).mul( cubeUV_m6.sub( cubeUV_m5 ) ).div( cubeUV_r5.sub( cubeUV_r6 ) ).add( cubeUV_m5 ) ); + + } ).Else( () => { + + mip.assign( float( - 2.0 ).mul( log2( mul( 1.16, roughness ) ) ) ); // 1.16 = 1.79^0.25 + + } ); + + return mip; + +} ).setLayout( { + name: 'roughnessToMip', + type: 'float', + inputs: [ + { name: 'roughness', type: 'float' } + ] +} ); + +// RH coordinate system; PMREM face-indexing convention +const getDirection = /*@__PURE__*/ Fn( ( [ uv_immutable, face ] ) => { + + const uv = uv_immutable.toVar(); + uv.assign( mul( 2.0, uv ).sub( 1.0 ) ); + const direction = vec3( uv, 1.0 ).toVar(); + + If( face.equal( 0.0 ), () => { + + direction.assign( direction.zyx ); // ( 1, v, u ) pos x + + } ).ElseIf( face.equal( 1.0 ), () => { + + direction.assign( direction.xzy ); + direction.xz.mulAssign( - 1.0 ); // ( -u, 1, -v ) pos y + + } ).ElseIf( face.equal( 2.0 ), () => { + + direction.x.mulAssign( - 1.0 ); // ( -u, v, 1 ) pos z + + } ).ElseIf( face.equal( 3.0 ), () => { + + direction.assign( direction.zyx ); + direction.xz.mulAssign( - 1.0 ); // ( -1, v, -u ) neg x + + } ).ElseIf( face.equal( 4.0 ), () => { + + direction.assign( direction.xzy ); + direction.xy.mulAssign( - 1.0 ); // ( -u, -1, v ) neg y + + } ).ElseIf( face.equal( 5.0 ), () => { + + direction.z.mulAssign( - 1.0 ); // ( u, v, -1 ) neg zS + + } ); + + return direction; + +} ).setLayout( { + name: 'getDirection', + type: 'vec3', + inputs: [ + { name: 'uv', type: 'vec2' }, + { name: 'face', type: 'float' } + ] +} ); + +// + +const textureCubeUV = /*@__PURE__*/ Fn( ( [ envMap, sampleDir_immutable, roughness_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => { + + const roughness = float( roughness_immutable ); + const sampleDir = vec3( sampleDir_immutable ); + + const mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); + const mipF = fract( mip ); + const mipInt = floor( mip ); + const color0 = vec3( bilinearCubeUV( envMap, sampleDir, mipInt, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ) ).toVar(); + + If( mipF.notEqual( 0.0 ), () => { + + const color1 = vec3( bilinearCubeUV( envMap, sampleDir, mipInt.add( 1.0 ), CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ) ).toVar(); + + color0.assign( mix( color0, color1, mipF ) ); + + } ); + + return color0; + +} ); + +const bilinearCubeUV = /*@__PURE__*/ Fn( ( [ envMap, direction_immutable, mipInt_immutable, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ] ) => { + + const mipInt = float( mipInt_immutable ).toVar(); + const direction = vec3( direction_immutable ); + const face = float( getFace( direction ) ).toVar(); + const filterInt = float( max$1( cubeUV_minMipLevel.sub( mipInt ), 0.0 ) ).toVar(); + mipInt.assign( max$1( mipInt, cubeUV_minMipLevel ) ); + const faceSize = float( exp2( mipInt ) ).toVar(); + const uv = vec2( getUV( direction, face ).mul( faceSize.sub( 2.0 ) ).add( 1.0 ) ).toVar(); + + If( face.greaterThan( 2.0 ), () => { + + uv.y.addAssign( faceSize ); + face.subAssign( 3.0 ); + + } ); + + uv.x.addAssign( face.mul( faceSize ) ); + uv.x.addAssign( filterInt.mul( mul( 3.0, cubeUV_minTileSize ) ) ); + uv.y.addAssign( mul( 4.0, exp2( CUBEUV_MAX_MIP ).sub( faceSize ) ) ); + uv.x.mulAssign( CUBEUV_TEXEL_WIDTH ); + uv.y.mulAssign( CUBEUV_TEXEL_HEIGHT ); + + return envMap.uv( uv ).grad( vec2(), vec2() ); // disable anisotropic filtering + +} ); + +const getSample = /*@__PURE__*/ Fn( ( { envMap, mipInt, outputDirection, theta, axis, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => { + + const cosTheta = cos( theta ); + + // Rodrigues' axis-angle rotation + const sampleDirection = outputDirection.mul( cosTheta ) + .add( axis.cross( outputDirection ).mul( sin( theta ) ) ) + .add( axis.mul( axis.dot( outputDirection ).mul( cosTheta.oneMinus() ) ) ); + + return bilinearCubeUV( envMap, sampleDirection, mipInt, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP ); + +} ); + +const blur = /*@__PURE__*/ Fn( ( { n, latitudinal, poleAxis, outputDirection, weights, samples, dTheta, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => { + + const axis = vec3( select( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar(); + + If( all( axis.equals( vec3( 0.0 ) ) ), () => { + + axis.assign( vec3( outputDirection.z, 0.0, outputDirection.x.negate() ) ); + + } ); + + axis.assign( normalize( axis ) ); + + const gl_FragColor = vec3().toVar(); + gl_FragColor.addAssign( weights.element( int( 0 ) ).mul( getSample( { theta: 0.0, axis, outputDirection, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) ) ); + + Loop( { start: int( 1 ), end: n }, ( { i } ) => { + + If( i.greaterThanEqual( samples ), () => { + + Break(); + + } ); + + const theta = float( dTheta.mul( float( i ) ) ).toVar(); + gl_FragColor.addAssign( weights.element( i ).mul( getSample( { theta: theta.mul( - 1.0 ), axis, outputDirection, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) ) ); + gl_FragColor.addAssign( weights.element( i ).mul( getSample( { theta, axis, outputDirection, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) ) ); + + } ); + + return vec4( gl_FragColor, 1 ); + +} ); + +let _generator = null; + +const _cache = new WeakMap(); + +function _generateCubeUVSize( imageHeight ) { + + const maxMip = Math.log2( imageHeight ) - 2; + + const texelHeight = 1.0 / imageHeight; + + const texelWidth = 1.0 / ( 3 * Math.max( Math.pow( 2, maxMip ), 7 * 16 ) ); + + return { texelWidth, texelHeight, maxMip }; + +} + +function _getPMREMFromTexture( texture ) { + + let cacheTexture = _cache.get( texture ); + + const pmremVersion = cacheTexture !== undefined ? cacheTexture.pmremVersion : - 1; + + if ( pmremVersion !== texture.pmremVersion ) { + + const image = texture.image; + + if ( texture.isCubeTexture ) { + + if ( isCubeMapReady( image ) ) { + + cacheTexture = _generator.fromCubemap( texture, cacheTexture ); + + } else { + + return null; + + } + + + } else { + + if ( isEquirectangularMapReady( image ) ) { + + cacheTexture = _generator.fromEquirectangular( texture, cacheTexture ); + + } else { + + return null; + + } + + } + + cacheTexture.pmremVersion = texture.pmremVersion; + + _cache.set( texture, cacheTexture ); + + } + + return cacheTexture.texture; + +} + +class PMREMNode extends TempNode { + + static get type() { + + return 'PMREMNode'; + + } + + constructor( value, uvNode = null, levelNode = null ) { + + super( 'vec3' ); + + this._value = value; + this._pmrem = null; + + this.uvNode = uvNode; + this.levelNode = levelNode; + + this._generator = null; + + const defaultTexture = new Texture(); + defaultTexture.isRenderTargetTexture = true; + + this._texture = texture( defaultTexture ); + + this._width = uniform( 0 ); + this._height = uniform( 0 ); + this._maxMip = uniform( 0 ); + + this.updateBeforeType = NodeUpdateType.RENDER; + + } + + set value( value ) { + + this._value = value; + this._pmrem = null; + + } + + get value() { + + return this._value; + + } + + updateFromTexture( texture ) { + + const cubeUVSize = _generateCubeUVSize( texture.image.height ); + + this._texture.value = texture; + this._width.value = cubeUVSize.texelWidth; + this._height.value = cubeUVSize.texelHeight; + this._maxMip.value = cubeUVSize.maxMip; + + } + + updateBefore() { + + let pmrem = this._pmrem; + + const pmremVersion = pmrem ? pmrem.pmremVersion : - 1; + const texture = this._value; + + if ( pmremVersion !== texture.pmremVersion ) { + + if ( texture.isPMREMTexture === true ) { + + pmrem = texture; + + } else { + + pmrem = _getPMREMFromTexture( texture ); + + } + + if ( pmrem !== null ) { + + this._pmrem = pmrem; + + this.updateFromTexture( pmrem ); + + } + + } + + } + + setup( builder ) { + + if ( _generator === null ) { + + _generator = builder.createPMREMGenerator(); + + } + + // + + this.updateBefore( builder ); + + // + + let uvNode = this.uvNode; + + if ( uvNode === null && builder.context.getUV ) { + + uvNode = builder.context.getUV( this ); + + } + + // + + const texture = this.value; + + if ( builder.renderer.coordinateSystem === WebGLCoordinateSystem && texture.isPMREMTexture !== true && texture.isRenderTargetTexture === true ) { + + uvNode = vec3( uvNode.x.negate(), uvNode.yz ); + + } + + // + + let levelNode = this.levelNode; + + if ( levelNode === null && builder.context.getTextureLevel ) { + + levelNode = builder.context.getTextureLevel( this ); + + } + + // + + return textureCubeUV( this._texture, uvNode, levelNode, this._width, this._height, this._maxMip ); + + } + +} + +function isCubeMapReady( image ) { + + if ( image === null || image === undefined ) return false; + + let count = 0; + const length = 6; + + for ( let i = 0; i < length; i ++ ) { + + if ( image[ i ] !== undefined ) count ++; + + } + + return count === length; + + +} + +function isEquirectangularMapReady( image ) { + + if ( image === null || image === undefined ) return false; + + return image.height > 0; + +} + +const pmremTexture = /*@__PURE__*/ nodeProxy( PMREMNode ); + +const _envNodeCache = new WeakMap(); + +class EnvironmentNode extends LightingNode { + + static get type() { + + return 'EnvironmentNode'; + + } + + constructor( envNode = null ) { + + super(); + + this.envNode = envNode; + + } + + setup( builder ) { + + const { material } = builder; + + let envNode = this.envNode; + + if ( envNode.isTextureNode || envNode.isMaterialReferenceNode ) { + + const value = ( envNode.isTextureNode ) ? envNode.value : material[ envNode.property ]; + + let cacheEnvNode = _envNodeCache.get( value ); + + if ( cacheEnvNode === undefined ) { + + cacheEnvNode = pmremTexture( value ); + + _envNodeCache.set( value, cacheEnvNode ); + + } + + envNode = cacheEnvNode; + + } + + // + + const envMap = material.envMap; + const intensity = envMap ? reference( 'envMapIntensity', 'float', builder.material ) : reference( 'environmentIntensity', 'float', builder.scene ); // @TODO: Add materialEnvIntensity in MaterialNode + + const useAnisotropy = material.useAnisotropy === true || material.anisotropy > 0; + const radianceNormalView = useAnisotropy ? transformedBentNormalView : transformedNormalView; + + const radiance = envNode.context( createRadianceContext( roughness, radianceNormalView ) ).mul( intensity ); + const irradiance = envNode.context( createIrradianceContext( transformedNormalWorld ) ).mul( Math.PI ).mul( intensity ); + + const isolateRadiance = cache( radiance ); + const isolateIrradiance = cache( irradiance ); + + // + + builder.context.radiance.addAssign( isolateRadiance ); + + builder.context.iblIrradiance.addAssign( isolateIrradiance ); + + // + + const clearcoatRadiance = builder.context.lightingModel.clearcoatRadiance; + + if ( clearcoatRadiance ) { + + const clearcoatRadianceContext = envNode.context( createRadianceContext( clearcoatRoughness, transformedClearcoatNormalView ) ).mul( intensity ); + const isolateClearcoatRadiance = cache( clearcoatRadianceContext ); + + clearcoatRadiance.addAssign( isolateClearcoatRadiance ); + + } + + } + +} + +const createRadianceContext = ( roughnessNode, normalViewNode ) => { + + let reflectVec = null; + + return { + getUV: () => { + + if ( reflectVec === null ) { + + reflectVec = positionViewDirection.negate().reflect( normalViewNode ); + + // Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane. + reflectVec = roughnessNode.mul( roughnessNode ).mix( reflectVec, normalViewNode ).normalize(); + + reflectVec = reflectVec.transformDirection( cameraViewMatrix ); + + } + + return reflectVec; + + }, + getTextureLevel: () => { + + return roughnessNode; + + } + }; + +}; + +const createIrradianceContext = ( normalWorldNode ) => { + + return { + getUV: () => { + + return normalWorldNode; + + }, + getTextureLevel: () => { + + return float( 1.0 ); + + } + }; + +}; + +const _defaultValues$6 = /*@__PURE__*/ new MeshStandardMaterial(); + +class MeshStandardNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshStandardNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isMeshStandardNodeMaterial = true; + + this.lights = true; + + this.emissiveNode = null; + + this.metalnessNode = null; + this.roughnessNode = null; + + this.setDefaultValues( _defaultValues$6 ); + + this.setValues( parameters ); + + } + + setupEnvironment( builder ) { + + let envNode = super.setupEnvironment( builder ); + + if ( envNode === null && builder.environmentNode ) { + + envNode = builder.environmentNode; + + } + + return envNode ? new EnvironmentNode( envNode ) : null; + + } + + setupLightingModel( /*builder*/ ) { + + return new PhysicalLightingModel(); + + } + + setupSpecular() { + + const specularColorNode = mix( vec3( 0.04 ), diffuseColor.rgb, metalness ); + + specularColor.assign( specularColorNode ); + specularF90.assign( 1.0 ); + + } + + setupVariants() { + + // METALNESS + + const metalnessNode = this.metalnessNode ? float( this.metalnessNode ) : materialMetalness; + + metalness.assign( metalnessNode ); + + // ROUGHNESS + + let roughnessNode = this.roughnessNode ? float( this.roughnessNode ) : materialRoughness; + roughnessNode = getRoughness( { roughness: roughnessNode } ); + + roughness.assign( roughnessNode ); + + // SPECULAR COLOR + + this.setupSpecular(); + + // DIFFUSE COLOR + + diffuseColor.assign( vec4( diffuseColor.rgb.mul( metalnessNode.oneMinus() ), diffuseColor.a ) ); + + } + + copy( source ) { + + this.emissiveNode = source.emissiveNode; + + this.metalnessNode = source.metalnessNode; + this.roughnessNode = source.roughnessNode; + + return super.copy( source ); + + } + +} + +const _defaultValues$5 = /*@__PURE__*/ new MeshPhysicalMaterial(); + +class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial { + + static get type() { + + return 'MeshPhysicalNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isMeshPhysicalNodeMaterial = true; + + this.clearcoatNode = null; + this.clearcoatRoughnessNode = null; + this.clearcoatNormalNode = null; + + this.sheenNode = null; + this.sheenRoughnessNode = null; + + this.iridescenceNode = null; + this.iridescenceIORNode = null; + this.iridescenceThicknessNode = null; + + this.specularIntensityNode = null; + this.specularColorNode = null; + + this.iorNode = null; + this.transmissionNode = null; + this.thicknessNode = null; + this.attenuationDistanceNode = null; + this.attenuationColorNode = null; + this.dispersionNode = null; + + this.anisotropyNode = null; + + this.setDefaultValues( _defaultValues$5 ); + + this.setValues( parameters ); + + } + + get useClearcoat() { + + return this.clearcoat > 0 || this.clearcoatNode !== null; + + } + + get useIridescence() { + + return this.iridescence > 0 || this.iridescenceNode !== null; + + } + + get useSheen() { + + return this.sheen > 0 || this.sheenNode !== null; + + } + + get useAnisotropy() { + + return this.anisotropy > 0 || this.anisotropyNode !== null; + + } + + get useTransmission() { + + return this.transmission > 0 || this.transmissionNode !== null; + + } + + get useDispersion() { + + return this.dispersion > 0 || this.dispersionNode !== null; + + } + + setupSpecular() { + + const iorNode = this.iorNode ? float( this.iorNode ) : materialIOR; + + ior.assign( iorNode ); + specularColor.assign( mix( min$1( pow2( ior.sub( 1.0 ).div( ior.add( 1.0 ) ) ).mul( materialSpecularColor ), vec3( 1.0 ) ).mul( materialSpecularIntensity ), diffuseColor.rgb, metalness ) ); + specularF90.assign( mix( materialSpecularIntensity, 1.0, metalness ) ); + + } + + setupLightingModel( /*builder*/ ) { + + return new PhysicalLightingModel( this.useClearcoat, this.useSheen, this.useIridescence, this.useAnisotropy, this.useTransmission, this.useDispersion ); + + } + + setupVariants( builder ) { + + super.setupVariants( builder ); + + // CLEARCOAT + + if ( this.useClearcoat ) { + + const clearcoatNode = this.clearcoatNode ? float( this.clearcoatNode ) : materialClearcoat; + const clearcoatRoughnessNode = this.clearcoatRoughnessNode ? float( this.clearcoatRoughnessNode ) : materialClearcoatRoughness; + + clearcoat.assign( clearcoatNode ); + clearcoatRoughness.assign( getRoughness( { roughness: clearcoatRoughnessNode } ) ); + + } + + // SHEEN + + if ( this.useSheen ) { + + const sheenNode = this.sheenNode ? vec3( this.sheenNode ) : materialSheen; + const sheenRoughnessNode = this.sheenRoughnessNode ? float( this.sheenRoughnessNode ) : materialSheenRoughness; + + sheen.assign( sheenNode ); + sheenRoughness.assign( sheenRoughnessNode ); + + } + + // IRIDESCENCE + + if ( this.useIridescence ) { + + const iridescenceNode = this.iridescenceNode ? float( this.iridescenceNode ) : materialIridescence; + const iridescenceIORNode = this.iridescenceIORNode ? float( this.iridescenceIORNode ) : materialIridescenceIOR; + const iridescenceThicknessNode = this.iridescenceThicknessNode ? float( this.iridescenceThicknessNode ) : materialIridescenceThickness; + + iridescence.assign( iridescenceNode ); + iridescenceIOR.assign( iridescenceIORNode ); + iridescenceThickness.assign( iridescenceThicknessNode ); + + } + + // ANISOTROPY + + if ( this.useAnisotropy ) { + + const anisotropyV = ( this.anisotropyNode ? vec2( this.anisotropyNode ) : materialAnisotropy ).toVar(); + + anisotropy.assign( anisotropyV.length() ); + + If( anisotropy.equal( 0.0 ), () => { + + anisotropyV.assign( vec2( 1.0, 0.0 ) ); + + } ).Else( () => { + + anisotropyV.divAssign( vec2( anisotropy ) ); + anisotropy.assign( anisotropy.saturate() ); + + } ); + + // Roughness along the anisotropy bitangent is the material roughness, while the tangent roughness increases with anisotropy. + alphaT.assign( anisotropy.pow2().mix( roughness.pow2(), 1.0 ) ); + + anisotropyT.assign( TBNViewMatrix[ 0 ].mul( anisotropyV.x ).add( TBNViewMatrix[ 1 ].mul( anisotropyV.y ) ) ); + anisotropyB.assign( TBNViewMatrix[ 1 ].mul( anisotropyV.x ).sub( TBNViewMatrix[ 0 ].mul( anisotropyV.y ) ) ); + + } + + // TRANSMISSION + + if ( this.useTransmission ) { + + const transmissionNode = this.transmissionNode ? float( this.transmissionNode ) : materialTransmission; + const thicknessNode = this.thicknessNode ? float( this.thicknessNode ) : materialThickness; + const attenuationDistanceNode = this.attenuationDistanceNode ? float( this.attenuationDistanceNode ) : materialAttenuationDistance; + const attenuationColorNode = this.attenuationColorNode ? vec3( this.attenuationColorNode ) : materialAttenuationColor; + + transmission.assign( transmissionNode ); + thickness.assign( thicknessNode ); + attenuationDistance.assign( attenuationDistanceNode ); + attenuationColor.assign( attenuationColorNode ); + + if ( this.useDispersion ) { + + const dispersionNode = this.dispersionNode ? float( this.dispersionNode ) : materialDispersion; + + dispersion.assign( dispersionNode ); + + } + + } + + } + + setupClearcoatNormal() { + + return this.clearcoatNormalNode ? vec3( this.clearcoatNormalNode ) : materialClearcoatNormal; + + } + + setup( builder ) { + + builder.context.setupClearcoatNormal = () => this.setupClearcoatNormal( builder ); + + super.setup( builder ); + + } + + copy( source ) { + + this.clearcoatNode = source.clearcoatNode; + this.clearcoatRoughnessNode = source.clearcoatRoughnessNode; + this.clearcoatNormalNode = source.clearcoatNormalNode; + + this.sheenNode = source.sheenNode; + this.sheenRoughnessNode = source.sheenRoughnessNode; + + this.iridescenceNode = source.iridescenceNode; + this.iridescenceIORNode = source.iridescenceIORNode; + this.iridescenceThicknessNode = source.iridescenceThicknessNode; + + this.specularIntensityNode = source.specularIntensityNode; + this.specularColorNode = source.specularColorNode; + + this.transmissionNode = source.transmissionNode; + this.thicknessNode = source.thicknessNode; + this.attenuationDistanceNode = source.attenuationDistanceNode; + this.attenuationColorNode = source.attenuationColorNode; + this.dispersionNode = source.dispersionNode; + + this.anisotropyNode = source.anisotropyNode; + + return super.copy( source ); + + } + +} + +class SSSLightingModel extends PhysicalLightingModel { + + constructor( useClearcoat, useSheen, useIridescence, useSSS ) { + + super( useClearcoat, useSheen, useIridescence ); + + this.useSSS = useSSS; + + } + + direct( { lightDirection, lightColor, reflectedLight }, stack, builder ) { + + if ( this.useSSS === true ) { + + const material = builder.material; + + const { thicknessColorNode, thicknessDistortionNode, thicknessAmbientNode, thicknessAttenuationNode, thicknessPowerNode, thicknessScaleNode } = material; + + const scatteringHalf = lightDirection.add( transformedNormalView.mul( thicknessDistortionNode ) ).normalize(); + const scatteringDot = float( positionViewDirection.dot( scatteringHalf.negate() ).saturate().pow( thicknessPowerNode ).mul( thicknessScaleNode ) ); + const scatteringIllu = vec3( scatteringDot.add( thicknessAmbientNode ).mul( thicknessColorNode ) ); + + reflectedLight.directDiffuse.addAssign( scatteringIllu.mul( thicknessAttenuationNode.mul( lightColor ) ) ); + + } + + super.direct( { lightDirection, lightColor, reflectedLight }, stack, builder ); + + } + +} + +class MeshSSSNodeMaterial extends MeshPhysicalNodeMaterial { + + static get type() { + + return 'MeshSSSNodeMaterial'; + + } + + constructor( parameters ) { + + super( parameters ); + + this.thicknessColorNode = null; + this.thicknessDistortionNode = float( 0.1 ); + this.thicknessAmbientNode = float( 0.0 ); + this.thicknessAttenuationNode = float( .1 ); + this.thicknessPowerNode = float( 2.0 ); + this.thicknessScaleNode = float( 10.0 ); + + } + + get useSSS() { + + return this.thicknessColorNode !== null; + + } + + setupLightingModel( /*builder*/ ) { + + return new SSSLightingModel( this.useClearcoat, this.useSheen, this.useIridescence, this.useSSS ); + + } + + copy( source ) { + + this.thicknessColorNode = source.thicknessColorNode; + this.thicknessDistortionNode = source.thicknessDistortionNode; + this.thicknessAmbientNode = source.thicknessAmbientNode; + this.thicknessAttenuationNode = source.thicknessAttenuationNode; + this.thicknessPowerNode = source.thicknessPowerNode; + this.thicknessScaleNode = source.thicknessScaleNode; + + return super.copy( source ); + + } + +} + +const getGradientIrradiance = /*@__PURE__*/ Fn( ( { normal, lightDirection, builder } ) => { + + // dotNL will be from -1.0 to 1.0 + const dotNL = normal.dot( lightDirection ); + const coord = vec2( dotNL.mul( 0.5 ).add( 0.5 ), 0.0 ); + + if ( builder.material.gradientMap ) { + + const gradientMap = materialReference( 'gradientMap', 'texture' ).context( { getUV: () => coord } ); + + return vec3( gradientMap.r ); + + } else { + + const fw = coord.fwidth().mul( 0.5 ); + + return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( float( 0.7 ).sub( fw.x ), float( 0.7 ).add( fw.x ), coord.x ) ); + + } + +} ); + +class ToonLightingModel extends LightingModel { + + direct( { lightDirection, lightColor, reflectedLight }, stack, builder ) { + + const irradiance = getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul( lightColor ); + + reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) ); + + } + + indirect( { ambientOcclusion, irradiance, reflectedLight } ) { + + reflectedLight.indirectDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor } ) ) ); + + reflectedLight.indirectDiffuse.mulAssign( ambientOcclusion ); + + } + +} + +const _defaultValues$4 = /*@__PURE__*/ new MeshToonMaterial(); + +class MeshToonNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshToonNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isMeshToonNodeMaterial = true; + + this.lights = true; + + this.setDefaultValues( _defaultValues$4 ); + + this.setValues( parameters ); + + } + + setupLightingModel( /*builder*/ ) { + + return new ToonLightingModel(); + + } + +} + +class MatcapUVNode extends TempNode { + + static get type() { + + return 'MatcapUVNode'; + + } + + constructor() { + + super( 'vec2' ); + + } + + setup() { + + const x = vec3( positionViewDirection.z, 0, positionViewDirection.x.negate() ).normalize(); + const y = positionViewDirection.cross( x ); + + return vec2( x.dot( transformedNormalView ), y.dot( transformedNormalView ) ).mul( 0.495 ).add( 0.5 ); // 0.495 to remove artifacts caused by undersized matcap disks + + } + +} + +const matcapUV = /*@__PURE__*/ nodeImmutable( MatcapUVNode ); + +const _defaultValues$3 = /*@__PURE__*/ new MeshMatcapMaterial(); + +class MeshMatcapNodeMaterial extends NodeMaterial { + + static get type() { + + return 'MeshMatcapNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.lights = false; + + this.isMeshMatcapNodeMaterial = true; + + this.setDefaultValues( _defaultValues$3 ); + + this.setValues( parameters ); + + } + + setupVariants( builder ) { + + const uv = matcapUV; + + let matcapColor; + + if ( builder.material.matcap ) { + + matcapColor = materialReference( 'matcap', 'texture' ).context( { getUV: () => uv } ); + + } else { + + matcapColor = vec3( mix( 0.2, 0.8, uv.y ) ); // default if matcap is missing + + } + + diffuseColor.rgb.mulAssign( matcapColor.rgb ); + + } + +} + +const _defaultValues$2 = /*@__PURE__*/ new PointsMaterial(); + +class PointsNodeMaterial extends NodeMaterial { + + static get type() { + + return 'PointsNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isPointsNodeMaterial = true; + + this.lights = false; + this.transparent = true; + + this.sizeNode = null; + + this.setDefaultValues( _defaultValues$2 ); + + this.setValues( parameters ); + + } + + copy( source ) { + + this.sizeNode = source.sizeNode; + + return super.copy( source ); + + } + +} + +class RotateNode extends TempNode { + + static get type() { + + return 'RotateNode'; + + } + + constructor( positionNode, rotationNode ) { + + super(); + + this.positionNode = positionNode; + this.rotationNode = rotationNode; + + } + + getNodeType( builder ) { + + return this.positionNode.getNodeType( builder ); + + } + + setup( builder ) { + + const { rotationNode, positionNode } = this; + + const nodeType = this.getNodeType( builder ); + + if ( nodeType === 'vec2' ) { + + const cosAngle = rotationNode.cos(); + const sinAngle = rotationNode.sin(); + + const rotationMatrix = mat2( + cosAngle, sinAngle, + sinAngle.negate(), cosAngle + ); + + return rotationMatrix.mul( positionNode ); + + } else { + + const rotation = rotationNode; + const rotationXMatrix = mat4( vec4( 1.0, 0.0, 0.0, 0.0 ), vec4( 0.0, cos( rotation.x ), sin( rotation.x ).negate(), 0.0 ), vec4( 0.0, sin( rotation.x ), cos( rotation.x ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) ); + const rotationYMatrix = mat4( vec4( cos( rotation.y ), 0.0, sin( rotation.y ), 0.0 ), vec4( 0.0, 1.0, 0.0, 0.0 ), vec4( sin( rotation.y ).negate(), 0.0, cos( rotation.y ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) ); + const rotationZMatrix = mat4( vec4( cos( rotation.z ), sin( rotation.z ).negate(), 0.0, 0.0 ), vec4( sin( rotation.z ), cos( rotation.z ), 0.0, 0.0 ), vec4( 0.0, 0.0, 1.0, 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) ); + + return rotationXMatrix.mul( rotationYMatrix ).mul( rotationZMatrix ).mul( vec4( positionNode, 1.0 ) ).xyz; + + } + + } + +} + +const rotate = /*@__PURE__*/ nodeProxy( RotateNode ); + +const _defaultValues$1 = /*@__PURE__*/ new SpriteMaterial(); + +class SpriteNodeMaterial extends NodeMaterial { + + static get type() { + + return 'SpriteNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isSpriteNodeMaterial = true; + + this.lights = false; + this._useSizeAttenuation = true; + + this.positionNode = null; + this.rotationNode = null; + this.scaleNode = null; + + this.setDefaultValues( _defaultValues$1 ); + + this.setValues( parameters ); + + } + + setupPosition( { object, camera, context } ) { + + const sizeAttenuation = this.sizeAttenuation; + + // < VERTEX STAGE > + + const { positionNode, rotationNode, scaleNode } = this; + + const vertex = positionLocal; + + let mvPosition = modelViewMatrix.mul( vec3( positionNode || 0 ) ); + + let scale = vec2( modelWorldMatrix[ 0 ].xyz.length(), modelWorldMatrix[ 1 ].xyz.length() ); + + if ( scaleNode !== null ) { + + scale = scale.mul( scaleNode ); + + } + + + if ( ! sizeAttenuation ) { + + if ( camera.isPerspectiveCamera ) { + + scale = scale.mul( mvPosition.z.negate() ); + + } else { + + const orthoScale = float( 2.0 ).div( cameraProjectionMatrix.element( 1 ).element( 1 ) ); + scale = scale.mul( orthoScale.mul( 2 ) ); + + } + + } + + let alignedPosition = vertex.xy; + + if ( object.center && object.center.isVector2 === true ) { + + const center = reference$1( 'center', 'vec2' ); + + alignedPosition = alignedPosition.sub( center.sub( 0.5 ) ); + + } + + alignedPosition = alignedPosition.mul( scale ); + + const rotation = float( rotationNode || materialRotation ); + + const rotatedPosition = rotate( alignedPosition, rotation ); + + mvPosition = vec4( mvPosition.xy.add( rotatedPosition ), mvPosition.zw ); + + const modelViewProjection = cameraProjectionMatrix.mul( mvPosition ); + + context.vertex = vertex; + + return modelViewProjection; + + } + + copy( source ) { + + this.positionNode = source.positionNode; + this.rotationNode = source.rotationNode; + this.scaleNode = source.scaleNode; + + return super.copy( source ); + + } + + get sizeAttenuation() { + + return this._useSizeAttenuation; + + } + + set sizeAttenuation( value ) { + + if ( this._useSizeAttenuation !== value ) { + + this._useSizeAttenuation = value; + this.needsUpdate = true; + + } + + } + +} + +class ShadowMaskModel extends LightingModel { + + constructor() { + + super(); + + this.shadowNode = float( 1 ).toVar( 'shadowMask' ); + + } + + direct( { shadowMask } ) { + + this.shadowNode.mulAssign( shadowMask ); + + } + + finish( context ) { + + diffuseColor.a.mulAssign( this.shadowNode.oneMinus() ); + + context.outgoingLight.rgb.assign( diffuseColor.rgb ); // TODO: Optimize LightsNode to avoid this assignment + + } + +} + +const _defaultValues = /*@__PURE__*/ new ShadowMaterial(); + +class ShadowNodeMaterial extends NodeMaterial { + + static get type() { + + return 'ShadowNodeMaterial'; + + } + + constructor( parameters ) { + + super(); + + this.isShadowNodeMaterial = true; + + this.lights = true; + + this.setDefaultValues( _defaultValues ); + + this.setValues( parameters ); + + } + + setupLightingModel( /*builder*/ ) { + + return new ShadowMaskModel(); + + } + +} + +const normal = Fn( ( { texture, uv } ) => { + + const epsilon = 0.0001; + + const ret = vec3().toVar(); + + If( uv.x.lessThan( epsilon ), () => { + + ret.assign( vec3( 1, 0, 0 ) ); + + } ).ElseIf( uv.y.lessThan( epsilon ), () => { + + ret.assign( vec3( 0, 1, 0 ) ); + + } ).ElseIf( uv.z.lessThan( epsilon ), () => { + + ret.assign( vec3( 0, 0, 1 ) ); + + } ).ElseIf( uv.x.greaterThan( 1 - epsilon ), () => { + + ret.assign( vec3( - 1, 0, 0 ) ); + + } ).ElseIf( uv.y.greaterThan( 1 - epsilon ), () => { + + ret.assign( vec3( 0, - 1, 0 ) ); + + } ).ElseIf( uv.z.greaterThan( 1 - epsilon ), () => { + + ret.assign( vec3( 0, 0, - 1 ) ); + + } ).Else( () => { + + const step = 0.01; + + const x = texture.uv( uv.add( vec3( - step, 0.0, 0.0 ) ) ).r.sub( texture.uv( uv.add( vec3( step, 0.0, 0.0 ) ) ).r ); + const y = texture.uv( uv.add( vec3( 0.0, - step, 0.0 ) ) ).r.sub( texture.uv( uv.add( vec3( 0.0, step, 0.0 ) ) ).r ); + const z = texture.uv( uv.add( vec3( 0.0, 0.0, - step ) ) ).r.sub( texture.uv( uv.add( vec3( 0.0, 0.0, step ) ) ).r ); + + ret.assign( vec3( x, y, z ) ); + + } ); + + return ret.normalize(); + +} ); + + +class Texture3DNode extends TextureNode { + + static get type() { + + return 'Texture3DNode'; + + } + + constructor( value, uvNode = null, levelNode = null ) { + + super( value, uvNode, levelNode ); + + this.isTexture3DNode = true; + + } + + getInputType( /*builder*/ ) { + + return 'texture3D'; + + } + + getDefaultUV() { + + return vec3( 0.5, 0.5, 0.5 ); + + } + + setUpdateMatrix( /*updateMatrix*/ ) { } // Ignore .updateMatrix for 3d TextureNode + + setupUV( builder, uvNode ) { + + return uvNode; + + } + + generateUV( builder, uvNode ) { + + return uvNode.build( builder, 'vec3' ); + + } + + normal( uvNode ) { + + return normal( { texture: this, uv: uvNode } ); + + } + +} + +const texture3D = /*@__PURE__*/ nodeProxy( Texture3DNode ); + +class VolumeNodeMaterial extends NodeMaterial { + + static get type() { + + return 'VolumeNodeMaterial'; + + } + + constructor( params = {} ) { + + super(); + + this.lights = false; + this.isVolumeNodeMaterial = true; + this.testNode = null; + + this.setValues( params ); + + } + + setup( builder ) { + + const map = texture3D( this.map, null, 0 ); + + const hitBox = Fn( ( { orig, dir } ) => { + + const box_min = vec3( - 0.5 ); + const box_max = vec3( 0.5 ); + + const inv_dir = dir.reciprocal(); + + const tmin_tmp = box_min.sub( orig ).mul( inv_dir ); + const tmax_tmp = box_max.sub( orig ).mul( inv_dir ); + + const tmin = min$1( tmin_tmp, tmax_tmp ); + const tmax = max$1( tmin_tmp, tmax_tmp ); + + const t0 = max$1( tmin.x, max$1( tmin.y, tmin.z ) ); + const t1 = min$1( tmax.x, min$1( tmax.y, tmax.z ) ); + + return vec2( t0, t1 ); + + } ); + + this.fragmentNode = Fn( () => { + + const vOrigin = varying( vec3( modelWorldMatrixInverse.mul( vec4( cameraPosition, 1.0 ) ) ) ); + const vDirection = varying( positionGeometry.sub( vOrigin ) ); + + const rayDir = vDirection.normalize(); + const bounds = vec2( hitBox( { orig: vOrigin, dir: rayDir } ) ).toVar(); + + bounds.x.greaterThan( bounds.y ).discard(); + + bounds.assign( vec2( max$1( bounds.x, 0.0 ), bounds.y ) ); + + const p = vec3( vOrigin.add( bounds.x.mul( rayDir ) ) ).toVar(); + const inc = vec3( rayDir.abs().reciprocal() ).toVar(); + const delta = float( min$1( inc.x, min$1( inc.y, inc.z ) ) ).toVar( 'delta' ); // used 'delta' name in loop + + delta.divAssign( materialReference( 'steps', 'float' ) ); + + const ac = vec4( materialReference( 'base', 'color' ), 0.0 ).toVar(); + + Loop( { type: 'float', start: bounds.x, end: bounds.y, update: '+= delta' }, () => { + + const d = property( 'float', 'd' ).assign( map.uv( p.add( 0.5 ) ).r ); + + if ( this.testNode !== null ) { + + this.testNode( { map: map, mapValue: d, probe: p, finalColor: ac } ).append(); + + } else { + + // default to show surface of mesh + ac.a.assign( 1 ); + Break(); + + } + + p.addAssign( rayDir.mul( delta ) ); + + } ); + + ac.a.equal( 0 ).discard(); + + return vec4( ac ); + + } )(); + + super.setup( builder ); + + } + +} + +class Animation { + + constructor( nodes, info ) { + + this.nodes = nodes; + this.info = info; + + this._context = self; + this._animationLoop = null; + this._requestId = null; + + } + + start() { + + const update = ( time, frame ) => { + + this._requestId = this._context.requestAnimationFrame( update ); + + if ( this.info.autoReset === true ) this.info.reset(); + + this.nodes.nodeFrame.update(); + + this.info.frame = this.nodes.nodeFrame.frameId; + + if ( this._animationLoop !== null ) this._animationLoop( time, frame ); + + }; + + update(); + + } + + stop() { + + this._context.cancelAnimationFrame( this._requestId ); + + this._requestId = null; + + } + + setAnimationLoop( callback ) { + + this._animationLoop = callback; + + } + + setContext( context ) { + + this._context = context; + + } + + dispose() { + + this.stop(); + + } + +} + +class ChainMap { + + constructor() { + + this.weakMap = new WeakMap(); + + } + + get( keys ) { + + let map = this.weakMap; + + for ( let i = 0; i < keys.length; i ++ ) { + + map = map.get( keys[ i ] ); + + if ( map === undefined ) return undefined; + + } + + return map.get( keys[ keys.length - 1 ] ); + + } + + set( keys, value ) { + + let map = this.weakMap; + + for ( let i = 0; i < keys.length; i ++ ) { + + const key = keys[ i ]; + + if ( map.has( key ) === false ) map.set( key, new WeakMap() ); + + map = map.get( key ); + + } + + return map.set( keys[ keys.length - 1 ], value ); + + } + + delete( keys ) { + + let map = this.weakMap; + + for ( let i = 0; i < keys.length; i ++ ) { + + map = map.get( keys[ i ] ); + + if ( map === undefined ) return false; + + } + + return map.delete( keys[ keys.length - 1 ] ); + + } + +} + +let _id$7 = 0; + +function getKeys( obj ) { + + const keys = Object.keys( obj ); + + let proto = Object.getPrototypeOf( obj ); + + while ( proto ) { + + const descriptors = Object.getOwnPropertyDescriptors( proto ); + + for ( const key in descriptors ) { + + if ( descriptors[ key ] !== undefined ) { + + const descriptor = descriptors[ key ]; + + if ( descriptor && typeof descriptor.get === 'function' ) { + + keys.push( key ); + + } + + } + + } + + proto = Object.getPrototypeOf( proto ); + + } + + return keys; + +} + +class RenderObject { + + constructor( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext ) { + + this._nodes = nodes; + this._geometries = geometries; + + this.id = _id$7 ++; + + this.renderer = renderer; + this.object = object; + this.material = material; + this.scene = scene; + this.camera = camera; + this.lightsNode = lightsNode; + this.context = renderContext; + + this.geometry = object.geometry; + this.version = material.version; + + this.drawRange = null; + + this.attributes = null; + this.pipeline = null; + this.vertexBuffers = null; + this.drawParams = null; + + this.bundle = null; + + this.clippingContext = clippingContext; + this.clippingContextCacheKey = clippingContext !== null ? clippingContext.cacheKey : ''; + + this.initialNodesCacheKey = this.getDynamicCacheKey(); + this.initialCacheKey = this.getCacheKey(); + + this._nodeBuilderState = null; + this._bindings = null; + this._monitor = null; + + this.onDispose = null; + + this.isRenderObject = true; + + this.onMaterialDispose = () => { + + this.dispose(); + + }; + + this.material.addEventListener( 'dispose', this.onMaterialDispose ); + + } + + updateClipping( parent ) { + + this.clippingContext = parent; + + } + + get clippingNeedsUpdate() { + + if ( this.clippingContext === null || this.clippingContext.cacheKey === this.clippingContextCacheKey ) return false; + + this.clippingContextCacheKey = this.clippingContext.cacheKey; + + return true; + + } + + get hardwareClippingPlanes() { + + return this.material.hardwareClipping === true ? this.clippingContext.unionClippingCount : 0; + + } + + getNodeBuilderState() { + + return this._nodeBuilderState || ( this._nodeBuilderState = this._nodes.getForRender( this ) ); + + } + + getMonitor() { + + return this._monitor || ( this._monitor = this.getNodeBuilderState().monitor ); + + } + + getBindings() { + + return this._bindings || ( this._bindings = this.getNodeBuilderState().createBindings() ); + + } + + getIndex() { + + return this._geometries.getIndex( this ); + + } + + getIndirect() { + + return this._geometries.getIndirect( this ); + + } + + getChainArray() { + + return [ this.object, this.material, this.context, this.lightsNode ]; + + } + + setGeometry( geometry ) { + + this.geometry = geometry; + this.attributes = null; + + } + + getAttributes() { + + if ( this.attributes !== null ) return this.attributes; + + const nodeAttributes = this.getNodeBuilderState().nodeAttributes; + const geometry = this.geometry; + + const attributes = []; + const vertexBuffers = new Set(); + + for ( const nodeAttribute of nodeAttributes ) { + + const attribute = nodeAttribute.node && nodeAttribute.node.attribute ? nodeAttribute.node.attribute : geometry.getAttribute( nodeAttribute.name ); + + if ( attribute === undefined ) continue; + + attributes.push( attribute ); + + const bufferAttribute = attribute.isInterleavedBufferAttribute ? attribute.data : attribute; + vertexBuffers.add( bufferAttribute ); + + } + + this.attributes = attributes; + this.vertexBuffers = Array.from( vertexBuffers.values() ); + + return attributes; + + } + + getVertexBuffers() { + + if ( this.vertexBuffers === null ) this.getAttributes(); + + return this.vertexBuffers; + + } + + getDrawParameters() { + + const { object, material, geometry, group, drawRange } = this; + + const drawParams = this.drawParams || ( this.drawParams = { + vertexCount: 0, + firstVertex: 0, + instanceCount: 0, + firstInstance: 0 + } ); + + const index = this.getIndex(); + const hasIndex = ( index !== null ); + const instanceCount = geometry.isInstancedBufferGeometry ? geometry.instanceCount : ( object.count > 1 ? object.count : 1 ); + + if ( instanceCount === 0 ) return null; + + drawParams.instanceCount = instanceCount; + + if ( object.isBatchedMesh === true ) return drawParams; + + let rangeFactor = 1; + + if ( material.wireframe === true && ! object.isPoints && ! object.isLineSegments && ! object.isLine && ! object.isLineLoop ) { + + rangeFactor = 2; + + } + + let firstVertex = drawRange.start * rangeFactor; + let lastVertex = ( drawRange.start + drawRange.count ) * rangeFactor; + + if ( group !== null ) { + + firstVertex = Math.max( firstVertex, group.start * rangeFactor ); + lastVertex = Math.min( lastVertex, ( group.start + group.count ) * rangeFactor ); + + } + + const position = geometry.attributes.position; + let itemCount = Infinity; + + if ( hasIndex ) { + + itemCount = index.count; + + } else if ( position !== undefined && position !== null ) { + + itemCount = position.count; + + } + + firstVertex = Math.max( firstVertex, 0 ); + lastVertex = Math.min( lastVertex, itemCount ); + + const count = lastVertex - firstVertex; + + if ( count < 0 || count === Infinity ) return null; + + drawParams.vertexCount = count; + drawParams.firstVertex = firstVertex; + + return drawParams; + + } + + getGeometryCacheKey() { + + const { geometry } = this; + + let cacheKey = ''; + + for ( const name of Object.keys( geometry.attributes ).sort() ) { + + const attribute = geometry.attributes[ name ]; + + cacheKey += name + ','; + + if ( attribute.data ) cacheKey += attribute.data.stride + ','; + if ( attribute.offset ) cacheKey += attribute.offset + ','; + if ( attribute.itemSize ) cacheKey += attribute.itemSize + ','; + if ( attribute.normalized ) cacheKey += 'n,'; + + } + + if ( geometry.index ) { + + cacheKey += 'index,'; + + } + + return cacheKey; + + } + + getMaterialCacheKey() { + + const { object, material } = this; + + let cacheKey = material.customProgramCacheKey(); + + for ( const property of getKeys( material ) ) { + + if ( /^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test( property ) ) continue; + + const value = material[ property ]; + + let valueKey; + + if ( value !== null ) { + + // some material values require a formatting + + const type = typeof value; + + if ( type === 'number' ) { + + valueKey = value !== 0 ? '1' : '0'; // Convert to on/off, important for clearcoat, transmission, etc + + } else if ( type === 'object' ) { + + valueKey = '{'; + + if ( value.isTexture ) { + + valueKey += value.mapping; + + } + + valueKey += '}'; + + } else { + + valueKey = String( value ); + + } + + } else { + + valueKey = String( value ); + + } + + cacheKey += /*property + ':' +*/ valueKey + ','; + + } + + cacheKey += this.clippingContextCacheKey + ','; + + if ( object.geometry ) { + + cacheKey += this.getGeometryCacheKey(); + + } + + if ( object.skeleton ) { + + cacheKey += object.skeleton.bones.length + ','; + + } + + if ( object.morphTargetInfluences ) { + + cacheKey += object.morphTargetInfluences.length + ','; + + } + + if ( object.isBatchedMesh ) { + + cacheKey += object._matricesTexture.uuid + ','; + + if ( object._colorsTexture !== null ) { + + cacheKey += object._colorsTexture.uuid + ','; + + } + + } + + if ( object.count > 1 ) { + + // TODO: https://github.com/mrdoob/three.js/pull/29066#issuecomment-2269400850 + + cacheKey += object.uuid + ','; + + } + + cacheKey += object.receiveShadow + ','; + + return hashString( cacheKey ); + + } + + get needsGeometryUpdate() { + + return this.geometry.id !== this.object.geometry.id; + + } + + get needsUpdate() { + + return /*this.object.static !== true &&*/ ( this.initialNodesCacheKey !== this.getDynamicCacheKey() || this.clippingNeedsUpdate ); + + } + + getDynamicCacheKey() { + + // Environment Nodes Cache Key + + let cacheKey = this._nodes.getCacheKey( this.scene, this.lightsNode ); + + if ( this.object.receiveShadow ) { + + cacheKey += 1; + + } + + return cacheKey; + + } + + getCacheKey() { + + return this.getMaterialCacheKey() + this.getDynamicCacheKey(); + + } + + dispose() { + + this.material.removeEventListener( 'dispose', this.onMaterialDispose ); + + this.onDispose(); + + } + +} + +const chainArray = []; + +class RenderObjects { + + constructor( renderer, nodes, geometries, pipelines, bindings, info ) { + + this.renderer = renderer; + this.nodes = nodes; + this.geometries = geometries; + this.pipelines = pipelines; + this.bindings = bindings; + this.info = info; + + this.chainMaps = {}; + + } + + get( object, material, scene, camera, lightsNode, renderContext, clippingContext, passId ) { + + const chainMap = this.getChainMap( passId ); + + // reuse chainArray + chainArray[ 0 ] = object; + chainArray[ 1 ] = material; + chainArray[ 2 ] = renderContext; + chainArray[ 3 ] = lightsNode; + + let renderObject = chainMap.get( chainArray ); + + if ( renderObject === undefined ) { + + renderObject = this.createRenderObject( this.nodes, this.geometries, this.renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext, passId ); + + chainMap.set( chainArray, renderObject ); + + } else { + + renderObject.updateClipping( clippingContext ); + + if ( renderObject.needsGeometryUpdate ) { + + renderObject.setGeometry( object.geometry ); + + } + + if ( renderObject.version !== material.version || renderObject.needsUpdate ) { + + if ( renderObject.initialCacheKey !== renderObject.getCacheKey() ) { + + renderObject.dispose(); + + renderObject = this.get( object, material, scene, camera, lightsNode, renderContext, clippingContext, passId ); + + } else { + + renderObject.version = material.version; + + } + + } + + } + + return renderObject; + + } + + getChainMap( passId = 'default' ) { + + return this.chainMaps[ passId ] || ( this.chainMaps[ passId ] = new ChainMap() ); + + } + + dispose() { + + this.chainMaps = {}; + + } + + createRenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext, passId ) { + + const chainMap = this.getChainMap( passId ); + + const renderObject = new RenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext ); + + renderObject.onDispose = () => { + + this.pipelines.delete( renderObject ); + this.bindings.delete( renderObject ); + this.nodes.delete( renderObject ); + + chainMap.delete( renderObject.getChainArray() ); + + }; + + return renderObject; + + } + + +} + +class DataMap { + + constructor() { + + this.data = new WeakMap(); + + } + + get( object ) { + + let map = this.data.get( object ); + + if ( map === undefined ) { + + map = {}; + this.data.set( object, map ); + + } + + return map; + + } + + delete( object ) { + + let map; + + if ( this.data.has( object ) ) { + + map = this.data.get( object ); + + this.data.delete( object ); + + } + + return map; + + } + + has( object ) { + + return this.data.has( object ); + + } + + dispose() { + + this.data = new WeakMap(); + + } + +} + +const AttributeType = { + VERTEX: 1, + INDEX: 2, + STORAGE: 3, + INDIRECT: 4 +}; + +// size of a chunk in bytes (STD140 layout) + +const GPU_CHUNK_BYTES = 16; + +// @TODO: Move to src/constants.js + +const BlendColorFactor = 211; +const OneMinusBlendColorFactor = 212; + +class Attributes extends DataMap { + + constructor( backend ) { + + super(); + + this.backend = backend; + + } + + delete( attribute ) { + + const attributeData = super.delete( attribute ); + + if ( attributeData !== undefined ) { + + this.backend.destroyAttribute( attribute ); + + } + + return attributeData; + + } + + update( attribute, type ) { + + const data = this.get( attribute ); + + if ( data.version === undefined ) { + + if ( type === AttributeType.VERTEX ) { + + this.backend.createAttribute( attribute ); + + } else if ( type === AttributeType.INDEX ) { + + this.backend.createIndexAttribute( attribute ); + + } else if ( type === AttributeType.STORAGE ) { + + this.backend.createStorageAttribute( attribute ); + + } else if ( type === AttributeType.INDIRECT ) { + + this.backend.createIndirectStorageAttribute( attribute ); + + } + + data.version = this._getBufferAttribute( attribute ).version; + + } else { + + const bufferAttribute = this._getBufferAttribute( attribute ); + + if ( data.version < bufferAttribute.version || bufferAttribute.usage === DynamicDrawUsage ) { + + this.backend.updateAttribute( attribute ); + + data.version = bufferAttribute.version; + + } + + } + + } + + _getBufferAttribute( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; + + return attribute; + + } + +} + +function arrayNeedsUint32( array ) { + + // assumes larger values usually on last + + for ( let i = array.length - 1; i >= 0; -- i ) { + + if ( array[ i ] >= 65535 ) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565 + + } + + return false; + +} + +function getWireframeVersion( geometry ) { + + return ( geometry.index !== null ) ? geometry.index.version : geometry.attributes.position.version; + +} + +function getWireframeIndex( geometry ) { + + const indices = []; + + const geometryIndex = geometry.index; + const geometryPosition = geometry.attributes.position; + + if ( geometryIndex !== null ) { + + const array = geometryIndex.array; + + for ( let i = 0, l = array.length; i < l; i += 3 ) { + + const a = array[ i + 0 ]; + const b = array[ i + 1 ]; + const c = array[ i + 2 ]; + + indices.push( a, b, b, c, c, a ); + + } + + } else { + + const array = geometryPosition.array; + + for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) { + + const a = i + 0; + const b = i + 1; + const c = i + 2; + + indices.push( a, b, b, c, c, a ); + + } + + } + + const attribute = new ( arrayNeedsUint32( indices ) ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ); + attribute.version = getWireframeVersion( geometry ); + + return attribute; + +} + +class Geometries extends DataMap { + + constructor( attributes, info ) { + + super(); + + this.attributes = attributes; + this.info = info; + + this.wireframes = new WeakMap(); + + this.attributeCall = new WeakMap(); + + } + + has( renderObject ) { + + const geometry = renderObject.geometry; + + return super.has( geometry ) && this.get( geometry ).initialized === true; + + } + + updateForRender( renderObject ) { + + if ( this.has( renderObject ) === false ) this.initGeometry( renderObject ); + + this.updateAttributes( renderObject ); + + } + + initGeometry( renderObject ) { + + const geometry = renderObject.geometry; + const geometryData = this.get( geometry ); + + geometryData.initialized = true; + + this.info.memory.geometries ++; + + const onDispose = () => { + + this.info.memory.geometries --; + + const index = geometry.index; + const geometryAttributes = renderObject.getAttributes(); + + if ( index !== null ) { + + this.attributes.delete( index ); + + } + + for ( const geometryAttribute of geometryAttributes ) { + + this.attributes.delete( geometryAttribute ); + + } + + const wireframeAttribute = this.wireframes.get( geometry ); + + if ( wireframeAttribute !== undefined ) { + + this.attributes.delete( wireframeAttribute ); + + } + + geometry.removeEventListener( 'dispose', onDispose ); + + }; + + geometry.addEventListener( 'dispose', onDispose ); + + } + + updateAttributes( renderObject ) { + + // attributes + + const attributes = renderObject.getAttributes(); + + for ( const attribute of attributes ) { + + if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) { + + this.updateAttribute( attribute, AttributeType.STORAGE ); + + } else { + + this.updateAttribute( attribute, AttributeType.VERTEX ); + + } + + } + + // indexes + + const index = this.getIndex( renderObject ); + + if ( index !== null ) { + + this.updateAttribute( index, AttributeType.INDEX ); + + } + + // indirect + + const indirect = renderObject.geometry.indirect; + + if ( indirect !== null ) { + + this.updateAttribute( indirect, AttributeType.INDIRECT ); + + } + + } + + updateAttribute( attribute, type ) { + + const callId = this.info.render.calls; + + if ( ! attribute.isInterleavedBufferAttribute ) { + + if ( this.attributeCall.get( attribute ) !== callId ) { + + this.attributes.update( attribute, type ); + + this.attributeCall.set( attribute, callId ); + + } + + } else { + + if ( this.attributeCall.get( attribute ) === undefined ) { + + this.attributes.update( attribute, type ); + + this.attributeCall.set( attribute, callId ); + + } else if ( this.attributeCall.get( attribute.data ) !== callId ) { + + this.attributes.update( attribute, type ); + + this.attributeCall.set( attribute.data, callId ); + + this.attributeCall.set( attribute, callId ); + + } + + } + + } + + getIndirect( renderObject ) { + + return renderObject.geometry.indirect; + + } + + getIndex( renderObject ) { + + const { geometry, material } = renderObject; + + let index = geometry.index; + + if ( material.wireframe === true ) { + + const wireframes = this.wireframes; + + let wireframeAttribute = wireframes.get( geometry ); + + if ( wireframeAttribute === undefined ) { + + wireframeAttribute = getWireframeIndex( geometry ); + + wireframes.set( geometry, wireframeAttribute ); + + } else if ( wireframeAttribute.version !== getWireframeVersion( geometry ) ) { + + this.attributes.delete( wireframeAttribute ); + + wireframeAttribute = getWireframeIndex( geometry ); + + wireframes.set( geometry, wireframeAttribute ); + + } + + index = wireframeAttribute; + + } + + return index; + + } + +} + +class Info { + + constructor() { + + this.autoReset = true; + + this.frame = 0; + this.calls = 0; + + this.render = { + calls: 0, + frameCalls: 0, + drawCalls: 0, + triangles: 0, + points: 0, + lines: 0, + timestamp: 0, + previousFrameCalls: 0, + timestampCalls: 0 + }; + + this.compute = { + calls: 0, + frameCalls: 0, + timestamp: 0, + previousFrameCalls: 0, + timestampCalls: 0 + }; + + this.memory = { + geometries: 0, + textures: 0 + }; + + } + + update( object, count, instanceCount ) { + + this.render.drawCalls ++; + + if ( object.isMesh || object.isSprite ) { + + this.render.triangles += instanceCount * ( count / 3 ); + + } else if ( object.isPoints ) { + + this.render.points += instanceCount * count; + + } else if ( object.isLineSegments ) { + + this.render.lines += instanceCount * ( count / 2 ); + + } else if ( object.isLine ) { + + this.render.lines += instanceCount * ( count - 1 ); + + } else { + + console.error( 'THREE.WebGPUInfo: Unknown object type.' ); + + } + + } + + updateTimestamp( type, time ) { + + if ( this[ type ].timestampCalls === 0 ) { + + this[ type ].timestamp = 0; + + } + + + this[ type ].timestamp += time; + + this[ type ].timestampCalls ++; + + + if ( this[ type ].timestampCalls >= this[ type ].previousFrameCalls ) { + + this[ type ].timestampCalls = 0; + + } + + + } + + reset() { + + const previousRenderFrameCalls = this.render.frameCalls; + this.render.previousFrameCalls = previousRenderFrameCalls; + + const previousComputeFrameCalls = this.compute.frameCalls; + this.compute.previousFrameCalls = previousComputeFrameCalls; + + + this.render.drawCalls = 0; + this.render.frameCalls = 0; + this.compute.frameCalls = 0; + + this.render.triangles = 0; + this.render.points = 0; + this.render.lines = 0; + + + } + + dispose() { + + this.reset(); + + this.calls = 0; + + this.render.calls = 0; + this.compute.calls = 0; + + this.render.timestamp = 0; + this.compute.timestamp = 0; + this.memory.geometries = 0; + this.memory.textures = 0; + + } + +} + +class Pipeline { + + constructor( cacheKey ) { + + this.cacheKey = cacheKey; + + this.usedTimes = 0; + + } + +} + +class RenderPipeline extends Pipeline { + + constructor( cacheKey, vertexProgram, fragmentProgram ) { + + super( cacheKey ); + + this.vertexProgram = vertexProgram; + this.fragmentProgram = fragmentProgram; + + } + +} + +class ComputePipeline extends Pipeline { + + constructor( cacheKey, computeProgram ) { + + super( cacheKey ); + + this.computeProgram = computeProgram; + + this.isComputePipeline = true; + + } + +} + +let _id$6 = 0; + +class ProgrammableStage { + + constructor( code, type, transforms = null, attributes = null ) { + + this.id = _id$6 ++; + + this.code = code; + this.stage = type; + this.transforms = transforms; + this.attributes = attributes; + + this.usedTimes = 0; + + } + +} + +class Pipelines extends DataMap { + + constructor( backend, nodes ) { + + super(); + + this.backend = backend; + this.nodes = nodes; + + this.bindings = null; // set by the bindings + + this.caches = new Map(); + this.programs = { + vertex: new Map(), + fragment: new Map(), + compute: new Map() + }; + + } + + getForCompute( computeNode, bindings ) { + + const { backend } = this; + + const data = this.get( computeNode ); + + if ( this._needsComputeUpdate( computeNode ) ) { + + const previousPipeline = data.pipeline; + + if ( previousPipeline ) { + + previousPipeline.usedTimes --; + previousPipeline.computeProgram.usedTimes --; + + } + + // get shader + + const nodeBuilderState = this.nodes.getForCompute( computeNode ); + + // programmable stage + + let stageCompute = this.programs.compute.get( nodeBuilderState.computeShader ); + + if ( stageCompute === undefined ) { + + if ( previousPipeline && previousPipeline.computeProgram.usedTimes === 0 ) this._releaseProgram( previousPipeline.computeProgram ); + + stageCompute = new ProgrammableStage( nodeBuilderState.computeShader, 'compute', nodeBuilderState.transforms, nodeBuilderState.nodeAttributes ); + this.programs.compute.set( nodeBuilderState.computeShader, stageCompute ); + + backend.createProgram( stageCompute ); + + } + + // determine compute pipeline + + const cacheKey = this._getComputeCacheKey( computeNode, stageCompute ); + + let pipeline = this.caches.get( cacheKey ); + + if ( pipeline === undefined ) { + + if ( previousPipeline && previousPipeline.usedTimes === 0 ) this._releasePipeline( previousPipeline ); + + pipeline = this._getComputePipeline( computeNode, stageCompute, cacheKey, bindings ); + + } + + // keep track of all used times + + pipeline.usedTimes ++; + stageCompute.usedTimes ++; + + // + + data.version = computeNode.version; + data.pipeline = pipeline; + + } + + return data.pipeline; + + } + + getForRender( renderObject, promises = null ) { + + const { backend } = this; + + const data = this.get( renderObject ); + + if ( this._needsRenderUpdate( renderObject ) ) { + + const previousPipeline = data.pipeline; + + if ( previousPipeline ) { + + previousPipeline.usedTimes --; + previousPipeline.vertexProgram.usedTimes --; + previousPipeline.fragmentProgram.usedTimes --; + + } + + // get shader + + const nodeBuilderState = renderObject.getNodeBuilderState(); + + // programmable stages + + let stageVertex = this.programs.vertex.get( nodeBuilderState.vertexShader ); + + if ( stageVertex === undefined ) { + + if ( previousPipeline && previousPipeline.vertexProgram.usedTimes === 0 ) this._releaseProgram( previousPipeline.vertexProgram ); + + stageVertex = new ProgrammableStage( nodeBuilderState.vertexShader, 'vertex' ); + this.programs.vertex.set( nodeBuilderState.vertexShader, stageVertex ); + + backend.createProgram( stageVertex ); + + } + + let stageFragment = this.programs.fragment.get( nodeBuilderState.fragmentShader ); + + if ( stageFragment === undefined ) { + + if ( previousPipeline && previousPipeline.fragmentProgram.usedTimes === 0 ) this._releaseProgram( previousPipeline.fragmentProgram ); + + stageFragment = new ProgrammableStage( nodeBuilderState.fragmentShader, 'fragment' ); + this.programs.fragment.set( nodeBuilderState.fragmentShader, stageFragment ); + + backend.createProgram( stageFragment ); + + } + + // determine render pipeline + + const cacheKey = this._getRenderCacheKey( renderObject, stageVertex, stageFragment ); + + let pipeline = this.caches.get( cacheKey ); + + if ( pipeline === undefined ) { + + if ( previousPipeline && previousPipeline.usedTimes === 0 ) this._releasePipeline( previousPipeline ); + + pipeline = this._getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey, promises ); + + } else { + + renderObject.pipeline = pipeline; + + } + + // keep track of all used times + + pipeline.usedTimes ++; + stageVertex.usedTimes ++; + stageFragment.usedTimes ++; + + // + + data.pipeline = pipeline; + + } + + return data.pipeline; + + } + + delete( object ) { + + const pipeline = this.get( object ).pipeline; + + if ( pipeline ) { + + // pipeline + + pipeline.usedTimes --; + + if ( pipeline.usedTimes === 0 ) this._releasePipeline( pipeline ); + + // programs + + if ( pipeline.isComputePipeline ) { + + pipeline.computeProgram.usedTimes --; + + if ( pipeline.computeProgram.usedTimes === 0 ) this._releaseProgram( pipeline.computeProgram ); + + } else { + + pipeline.fragmentProgram.usedTimes --; + pipeline.vertexProgram.usedTimes --; + + if ( pipeline.vertexProgram.usedTimes === 0 ) this._releaseProgram( pipeline.vertexProgram ); + if ( pipeline.fragmentProgram.usedTimes === 0 ) this._releaseProgram( pipeline.fragmentProgram ); + + } + + } + + return super.delete( object ); + + } + + dispose() { + + super.dispose(); + + this.caches = new Map(); + this.programs = { + vertex: new Map(), + fragment: new Map(), + compute: new Map() + }; + + } + + updateForRender( renderObject ) { + + this.getForRender( renderObject ); + + } + + _getComputePipeline( computeNode, stageCompute, cacheKey, bindings ) { + + // check for existing pipeline + + cacheKey = cacheKey || this._getComputeCacheKey( computeNode, stageCompute ); + + let pipeline = this.caches.get( cacheKey ); + + if ( pipeline === undefined ) { + + pipeline = new ComputePipeline( cacheKey, stageCompute ); + + this.caches.set( cacheKey, pipeline ); + + this.backend.createComputePipeline( pipeline, bindings ); + + } + + return pipeline; + + } + + _getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey, promises ) { + + // check for existing pipeline + + cacheKey = cacheKey || this._getRenderCacheKey( renderObject, stageVertex, stageFragment ); + + let pipeline = this.caches.get( cacheKey ); + + if ( pipeline === undefined ) { + + pipeline = new RenderPipeline( cacheKey, stageVertex, stageFragment ); + + this.caches.set( cacheKey, pipeline ); + + renderObject.pipeline = pipeline; + + this.backend.createRenderPipeline( renderObject, promises ); + + } + + return pipeline; + + } + + _getComputeCacheKey( computeNode, stageCompute ) { + + return computeNode.id + ',' + stageCompute.id; + + } + + _getRenderCacheKey( renderObject, stageVertex, stageFragment ) { + + return stageVertex.id + ',' + stageFragment.id + ',' + this.backend.getRenderCacheKey( renderObject ); + + } + + _releasePipeline( pipeline ) { + + this.caches.delete( pipeline.cacheKey ); + + } + + _releaseProgram( program ) { + + const code = program.code; + const stage = program.stage; + + this.programs[ stage ].delete( code ); + + } + + _needsComputeUpdate( computeNode ) { + + const data = this.get( computeNode ); + + return data.pipeline === undefined || data.version !== computeNode.version; + + } + + _needsRenderUpdate( renderObject ) { + + const data = this.get( renderObject ); + + return data.pipeline === undefined || this.backend.needsRenderUpdate( renderObject ); + + } + +} + +class Bindings extends DataMap { + + constructor( backend, nodes, textures, attributes, pipelines, info ) { + + super(); + + this.backend = backend; + this.textures = textures; + this.pipelines = pipelines; + this.attributes = attributes; + this.nodes = nodes; + this.info = info; + + this.pipelines.bindings = this; // assign bindings to pipelines + + } + + getForRender( renderObject ) { + + const bindings = renderObject.getBindings(); + + for ( const bindGroup of bindings ) { + + const groupData = this.get( bindGroup ); + + if ( groupData.bindGroup === undefined ) { + + // each object defines an array of bindings (ubos, textures, samplers etc.) + + this._init( bindGroup ); + + this.backend.createBindings( bindGroup, bindings, 0 ); + + groupData.bindGroup = bindGroup; + + } + + } + + return bindings; + + } + + getForCompute( computeNode ) { + + const bindings = this.nodes.getForCompute( computeNode ).bindings; + + for ( const bindGroup of bindings ) { + + const groupData = this.get( bindGroup ); + + if ( groupData.bindGroup === undefined ) { + + this._init( bindGroup ); + + this.backend.createBindings( bindGroup, bindings, 0 ); + + groupData.bindGroup = bindGroup; + + } + + } + + return bindings; + + } + + updateForCompute( computeNode ) { + + this._updateBindings( this.getForCompute( computeNode ) ); + + } + + updateForRender( renderObject ) { + + this._updateBindings( this.getForRender( renderObject ) ); + + } + + _updateBindings( bindings ) { + + for ( const bindGroup of bindings ) { + + this._update( bindGroup, bindings ); + + } + + } + + _init( bindGroup ) { + + for ( const binding of bindGroup.bindings ) { + + if ( binding.isSampledTexture ) { + + this.textures.updateTexture( binding.texture ); + + } else if ( binding.isStorageBuffer ) { + + const attribute = binding.attribute; + const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE; + + this.attributes.update( attribute, attributeType ); + + } + + } + + } + + _update( bindGroup, bindings ) { + + const { backend } = this; + + let needsBindingsUpdate = false; + let cacheBindings = true; + let cacheIndex = 0; + let version = 0; + + // iterate over all bindings and check if buffer updates or a new binding group is required + + for ( const binding of bindGroup.bindings ) { + + if ( binding.isNodeUniformsGroup ) { + + const updated = this.nodes.updateGroup( binding ); + + if ( ! updated ) continue; + + } + + if ( binding.isUniformBuffer ) { + + const updated = binding.update(); + + if ( updated ) { + + backend.updateBinding( binding ); + + } + + } else if ( binding.isSampler ) { + + binding.update(); + + } else if ( binding.isSampledTexture ) { + + const texturesTextureData = this.textures.get( binding.texture ); + + if ( binding.needsBindingsUpdate( texturesTextureData.generation ) ) needsBindingsUpdate = true; + + const updated = binding.update(); + + const texture = binding.texture; + + if ( updated ) { + + this.textures.updateTexture( texture ); + + } + + const textureData = backend.get( texture ); + + if ( textureData.externalTexture !== undefined || texturesTextureData.isDefaultTexture ) { + + cacheBindings = false; + + } else { + + cacheIndex = cacheIndex * 10 + texture.id; + version += texture.version; + + } + + if ( backend.isWebGPUBackend === true && textureData.texture === undefined && textureData.externalTexture === undefined ) { + + // TODO: Remove this once we found why updated === false isn't bound to a texture in the WebGPU backend + console.error( 'Bindings._update: binding should be available:', binding, updated, texture, binding.textureNode.value, needsBindingsUpdate ); + + this.textures.updateTexture( texture ); + needsBindingsUpdate = true; + + } + + if ( texture.isStorageTexture === true ) { + + const textureData = this.get( texture ); + + if ( binding.store === true ) { + + textureData.needsMipmap = true; + + } else if ( this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) { + + this.backend.generateMipmaps( texture ); + + textureData.needsMipmap = false; + + } + + } + + } + + } + + if ( needsBindingsUpdate === true ) { + + this.backend.updateBindings( bindGroup, bindings, cacheBindings ? cacheIndex : 0, version ); + + } + + } + +} + +function painterSortStable( a, b ) { + + if ( a.groupOrder !== b.groupOrder ) { + + return a.groupOrder - b.groupOrder; + + } else if ( a.renderOrder !== b.renderOrder ) { + + return a.renderOrder - b.renderOrder; + + } else if ( a.material.id !== b.material.id ) { + + return a.material.id - b.material.id; + + } else if ( a.z !== b.z ) { + + return a.z - b.z; + + } else { + + return a.id - b.id; + + } + +} + +function reversePainterSortStable( a, b ) { + + if ( a.groupOrder !== b.groupOrder ) { + + return a.groupOrder - b.groupOrder; + + } else if ( a.renderOrder !== b.renderOrder ) { + + return a.renderOrder - b.renderOrder; + + } else if ( a.z !== b.z ) { + + return b.z - a.z; + + } else { + + return a.id - b.id; + + } + +} + +function needsDoublePass( material ) { + + const hasTransmission = material.transmission > 0 || material.transmissionNode; + + return hasTransmission && material.side === DoubleSide && material.forceSinglePass === false; + +} + +class RenderList { + + constructor( lighting, scene, camera ) { + + this.renderItems = []; + this.renderItemsIndex = 0; + + this.opaque = []; + this.transparentDoublePass = []; + this.transparent = []; + this.bundles = []; + + this.lightsNode = lighting.getNode( scene, camera ); + this.lightsArray = []; + + this.scene = scene; + this.camera = camera; + + this.occlusionQueryCount = 0; + + } + + begin() { + + this.renderItemsIndex = 0; + + this.opaque.length = 0; + this.transparentDoublePass.length = 0; + this.transparent.length = 0; + this.bundles.length = 0; + + this.lightsArray.length = 0; + + this.occlusionQueryCount = 0; + + return this; + + } + + getNextRenderItem( object, geometry, material, groupOrder, z, group, clippingContext ) { + + let renderItem = this.renderItems[ this.renderItemsIndex ]; + + if ( renderItem === undefined ) { + + renderItem = { + id: object.id, + object: object, + geometry: geometry, + material: material, + groupOrder: groupOrder, + renderOrder: object.renderOrder, + z: z, + group: group, + clippingContext: clippingContext + }; + + this.renderItems[ this.renderItemsIndex ] = renderItem; + + } else { + + renderItem.id = object.id; + renderItem.object = object; + renderItem.geometry = geometry; + renderItem.material = material; + renderItem.groupOrder = groupOrder; + renderItem.renderOrder = object.renderOrder; + renderItem.z = z; + renderItem.group = group; + renderItem.clippingContext = clippingContext; + + } + + this.renderItemsIndex ++; + + return renderItem; + + } + + push( object, geometry, material, groupOrder, z, group, clippingContext ) { + + const renderItem = this.getNextRenderItem( object, geometry, material, groupOrder, z, group, clippingContext ); + + if ( object.occlusionTest === true ) this.occlusionQueryCount ++; + + if ( material.transparent === true || material.transmission > 0 ) { + + if ( needsDoublePass( material ) ) this.transparentDoublePass.push( renderItem ); + + this.transparent.push( renderItem ); + + } else { + + this.opaque.push( renderItem ); + + } + + } + + unshift( object, geometry, material, groupOrder, z, group, clippingContext ) { + + const renderItem = this.getNextRenderItem( object, geometry, material, groupOrder, z, group, clippingContext ); + + if ( material.transparent === true || material.transmission > 0 ) { + + if ( needsDoublePass( material ) ) this.transparentDoublePass.unshift( renderItem ); + + this.transparent.unshift( renderItem ); + + } else { + + this.opaque.unshift( renderItem ); + + } + + } + + pushBundle( group ) { + + this.bundles.push( group ); + + } + + pushLight( light ) { + + this.lightsArray.push( light ); + + } + + sort( customOpaqueSort, customTransparentSort ) { + + if ( this.opaque.length > 1 ) this.opaque.sort( customOpaqueSort || painterSortStable ); + if ( this.transparentDoublePass.length > 1 ) this.transparentDoublePass.sort( customTransparentSort || reversePainterSortStable ); + if ( this.transparent.length > 1 ) this.transparent.sort( customTransparentSort || reversePainterSortStable ); + + } + + finish() { + + // update lights + + this.lightsNode.setLights( this.lightsArray ); + + // Clear references from inactive renderItems in the list + + for ( let i = this.renderItemsIndex, il = this.renderItems.length; i < il; i ++ ) { + + const renderItem = this.renderItems[ i ]; + + if ( renderItem.id === null ) break; + + renderItem.id = null; + renderItem.object = null; + renderItem.geometry = null; + renderItem.material = null; + renderItem.groupOrder = null; + renderItem.renderOrder = null; + renderItem.z = null; + renderItem.group = null; + renderItem.clippingContext = null; + + } + + } + +} + +class RenderLists { + + constructor( lighting ) { + + this.lighting = lighting; + + this.lists = new ChainMap(); + + } + + get( scene, camera ) { + + const lists = this.lists; + const keys = [ scene, camera ]; + + let list = lists.get( keys ); + + if ( list === undefined ) { + + list = new RenderList( this.lighting, scene, camera ); + lists.set( keys, list ); + + } + + return list; + + } + + dispose() { + + this.lists = new ChainMap(); + + } + +} + +let id$1 = 0; + +class RenderContext { + + constructor() { + + this.id = id$1 ++; + + this.color = true; + this.clearColor = true; + this.clearColorValue = { r: 0, g: 0, b: 0, a: 1 }; + + this.depth = true; + this.clearDepth = true; + this.clearDepthValue = 1; + + this.stencil = false; + this.clearStencil = true; + this.clearStencilValue = 1; + + this.viewport = false; + this.viewportValue = new Vector4(); + + this.scissor = false; + this.scissorValue = new Vector4(); + + this.textures = null; + this.depthTexture = null; + this.activeCubeFace = 0; + this.sampleCount = 1; + + this.width = 0; + this.height = 0; + + this.isRenderContext = true; + + } + + getCacheKey() { + + return getCacheKey( this ); + + } + +} + +function getCacheKey( renderContext ) { + + const { textures, activeCubeFace } = renderContext; + + const values = [ activeCubeFace ]; + + for ( const texture of textures ) { + + values.push( texture.id ); + + } + + return hashArray( values ); + +} + +class RenderContexts { + + constructor() { + + this.chainMaps = {}; + + } + + get( scene, camera, renderTarget = null ) { + + const chainKey = [ scene, camera ]; + + let attachmentState; + + if ( renderTarget === null ) { + + attachmentState = 'default'; + + } else { + + const format = renderTarget.texture.format; + const count = renderTarget.textures.length; + + attachmentState = `${ count }:${ format }:${ renderTarget.samples }:${ renderTarget.depthBuffer }:${ renderTarget.stencilBuffer }`; + + } + + const chainMap = this.getChainMap( attachmentState ); + + let renderState = chainMap.get( chainKey ); + + if ( renderState === undefined ) { + + renderState = new RenderContext(); + + chainMap.set( chainKey, renderState ); + + } + + if ( renderTarget !== null ) renderState.sampleCount = renderTarget.samples === 0 ? 1 : renderTarget.samples; + + return renderState; + + } + + getChainMap( attachmentState ) { + + return this.chainMaps[ attachmentState ] || ( this.chainMaps[ attachmentState ] = new ChainMap() ); + + } + + dispose() { + + this.chainMaps = {}; + + } + +} + +const _size$3 = /*@__PURE__*/ new Vector3(); + +class Textures extends DataMap { + + constructor( renderer, backend, info ) { + + super(); + + this.renderer = renderer; + this.backend = backend; + this.info = info; + + } + + updateRenderTarget( renderTarget, activeMipmapLevel = 0 ) { + + const renderTargetData = this.get( renderTarget ); + + const sampleCount = renderTarget.samples === 0 ? 1 : renderTarget.samples; + const depthTextureMips = renderTargetData.depthTextureMips || ( renderTargetData.depthTextureMips = {} ); + + const textures = renderTarget.textures; + + const size = this.getSize( textures[ 0 ] ); + + const mipWidth = size.width >> activeMipmapLevel; + const mipHeight = size.height >> activeMipmapLevel; + + let depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ]; + const useDepthTexture = renderTarget.depthBuffer === true || renderTarget.stencilBuffer === true; + + let textureNeedsUpdate = false; + + if ( depthTexture === undefined && useDepthTexture ) { + + depthTexture = new DepthTexture(); + depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat; + depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType + depthTexture.image.width = mipWidth; + depthTexture.image.height = mipHeight; + + depthTextureMips[ activeMipmapLevel ] = depthTexture; + + } + + if ( renderTargetData.width !== size.width || size.height !== renderTargetData.height ) { + + textureNeedsUpdate = true; + + if ( depthTexture ) { + + depthTexture.needsUpdate = true; + depthTexture.image.width = mipWidth; + depthTexture.image.height = mipHeight; + + } + + } + + renderTargetData.width = size.width; + renderTargetData.height = size.height; + renderTargetData.textures = textures; + renderTargetData.depthTexture = depthTexture || null; + renderTargetData.depth = renderTarget.depthBuffer; + renderTargetData.stencil = renderTarget.stencilBuffer; + renderTargetData.renderTarget = renderTarget; + + if ( renderTargetData.sampleCount !== sampleCount ) { + + textureNeedsUpdate = true; + + if ( depthTexture ) { + + depthTexture.needsUpdate = true; + + } + + renderTargetData.sampleCount = sampleCount; + + } + + // + + const options = { sampleCount }; + + for ( let i = 0; i < textures.length; i ++ ) { + + const texture = textures[ i ]; + + if ( textureNeedsUpdate ) texture.needsUpdate = true; + + this.updateTexture( texture, options ); + + } + + if ( depthTexture ) { + + this.updateTexture( depthTexture, options ); + + } + + // dispose handler + + if ( renderTargetData.initialized !== true ) { + + renderTargetData.initialized = true; + + // dispose + + const onDispose = () => { + + renderTarget.removeEventListener( 'dispose', onDispose ); + + for ( let i = 0; i < textures.length; i ++ ) { + + this._destroyTexture( textures[ i ] ); + + } + + if ( depthTexture ) { + + this._destroyTexture( depthTexture ); + + } + + this.delete( renderTarget ); + + }; + + renderTarget.addEventListener( 'dispose', onDispose ); + + } + + } + + updateTexture( texture, options = {} ) { + + const textureData = this.get( texture ); + if ( textureData.initialized === true && textureData.version === texture.version ) return; + + const isRenderTarget = texture.isRenderTargetTexture || texture.isDepthTexture || texture.isFramebufferTexture; + const backend = this.backend; + + if ( isRenderTarget && textureData.initialized === true ) { + + // it's an update + + backend.destroySampler( texture ); + backend.destroyTexture( texture ); + + } + + // + + if ( texture.isFramebufferTexture ) { + + const renderTarget = this.renderer.getRenderTarget(); + + if ( renderTarget ) { + + texture.type = renderTarget.texture.type; + + } else { + + texture.type = UnsignedByteType; + + } + + } + + // + + const { width, height, depth } = this.getSize( texture ); + + options.width = width; + options.height = height; + options.depth = depth; + options.needsMipmaps = this.needsMipmaps( texture ); + options.levels = options.needsMipmaps ? this.getMipLevels( texture, width, height ) : 1; + + // + + if ( isRenderTarget || texture.isStorageTexture === true ) { + + backend.createSampler( texture ); + backend.createTexture( texture, options ); + + textureData.generation = texture.version; + + } else { + + const needsCreate = textureData.initialized !== true; + + if ( needsCreate ) backend.createSampler( texture ); + + if ( texture.version > 0 ) { + + const image = texture.image; + + if ( image === undefined ) { + + console.warn( 'THREE.Renderer: Texture marked for update but image is undefined.' ); + + } else if ( image.complete === false ) { + + console.warn( 'THREE.Renderer: Texture marked for update but image is incomplete.' ); + + } else { + + if ( texture.images ) { + + const images = []; + + for ( const image of texture.images ) { + + images.push( image ); + + } + + options.images = images; + + } else { + + options.image = image; + + } + + if ( textureData.isDefaultTexture === undefined || textureData.isDefaultTexture === true ) { + + backend.createTexture( texture, options ); + + textureData.isDefaultTexture = false; + textureData.generation = texture.version; + + } + + if ( texture.source.dataReady === true ) backend.updateTexture( texture, options ); + + if ( options.needsMipmaps && texture.mipmaps.length === 0 ) backend.generateMipmaps( texture ); + + } + + } else { + + // async update + + backend.createDefaultTexture( texture ); + + textureData.isDefaultTexture = true; + textureData.generation = texture.version; + + } + + } + + // dispose handler + + if ( textureData.initialized !== true ) { + + textureData.initialized = true; + textureData.generation = texture.version; + + // + + this.info.memory.textures ++; + + // dispose + + const onDispose = () => { + + texture.removeEventListener( 'dispose', onDispose ); + + this._destroyTexture( texture ); + + this.info.memory.textures --; + + }; + + texture.addEventListener( 'dispose', onDispose ); + + } + + // + + textureData.version = texture.version; + + } + + getSize( texture, target = _size$3 ) { + + let image = texture.images ? texture.images[ 0 ] : texture.image; + + if ( image ) { + + if ( image.image !== undefined ) image = image.image; + + target.width = image.width || 1; + target.height = image.height || 1; + target.depth = texture.isCubeTexture ? 6 : ( image.depth || 1 ); + + } else { + + target.width = target.height = target.depth = 1; + + } + + return target; + + } + + getMipLevels( texture, width, height ) { + + let mipLevelCount; + + if ( texture.isCompressedTexture ) { + + if ( texture.mipmaps ) { + + mipLevelCount = texture.mipmaps.length; + + } else { + + mipLevelCount = 1; + + } + + } else { + + mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1; + + } + + return mipLevelCount; + + } + + needsMipmaps( texture ) { + + return this.isEnvironmentTexture( texture ) || texture.isCompressedTexture === true || texture.generateMipmaps; + + } + + isEnvironmentTexture( texture ) { + + const mapping = texture.mapping; + + return ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) || ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping ); + + } + + _destroyTexture( texture ) { + + this.backend.destroySampler( texture ); + this.backend.destroyTexture( texture ); + + this.delete( texture ); + + } + +} + +class Color4 extends Color { + + constructor( r, g, b, a = 1 ) { + + super( r, g, b ); + + this.a = a; + + } + + set( r, g, b, a = 1 ) { + + this.a = a; + + return super.set( r, g, b ); + + } + + copy( color ) { + + if ( color.a !== undefined ) this.a = color.a; + + return super.copy( color ); + + } + + clone() { + + return new this.constructor( this.r, this.g, this.b, this.a ); + + } + +} + +class ParameterNode extends PropertyNode { + + static get type() { + + return 'ParameterNode'; + + } + + constructor( nodeType, name = null ) { + + super( nodeType, name ); + + this.isParameterNode = true; + + } + + getHash() { + + return this.uuid; + + } + + generate() { + + return this.name; + + } + +} + +const parameter = ( type, name ) => nodeObject( new ParameterNode( type, name ) ); + +class StackNode extends Node { + + static get type() { + + return 'StackNode'; + + } + + constructor( parent = null ) { + + super(); + + this.nodes = []; + this.outputNode = null; + + this.parent = parent; + + this._currentCond = null; + + this.isStackNode = true; + + } + + getNodeType( builder ) { + + return this.outputNode ? this.outputNode.getNodeType( builder ) : 'void'; + + } + + add( node ) { + + this.nodes.push( node ); + + return this; + + } + + If( boolNode, method ) { + + const methodNode = new ShaderNode( method ); + this._currentCond = select( boolNode, methodNode ); + + return this.add( this._currentCond ); + + } + + ElseIf( boolNode, method ) { + + const methodNode = new ShaderNode( method ); + const ifNode = select( boolNode, methodNode ); + + this._currentCond.elseNode = ifNode; + this._currentCond = ifNode; + + return this; + + } + + Else( method ) { + + this._currentCond.elseNode = new ShaderNode( method ); + + return this; + + } + + build( builder, ...params ) { + + const previousStack = getCurrentStack(); + + setCurrentStack( this ); + + for ( const node of this.nodes ) { + + node.build( builder, 'void' ); + + } + + setCurrentStack( previousStack ); + + return this.outputNode ? this.outputNode.build( builder, ...params ) : super.build( builder, ...params ); + + } + + // + + else( ...params ) { // @deprecated, r168 + + console.warn( 'TSL.StackNode: .else() has been renamed to .Else().' ); + return this.Else( ...params ); + + } + + elseif( ...params ) { // @deprecated, r168 + + console.warn( 'TSL.StackNode: .elseif() has been renamed to .ElseIf().' ); + return this.ElseIf( ...params ); + + } + +} + +const stack = /*@__PURE__*/ nodeProxy( StackNode ); + +class StructTypeNode extends Node { + + static get type() { + + return 'StructTypeNode'; + + } + + constructor( types ) { + + super(); + + this.types = types; + this.isStructTypeNode = true; + + } + + getMemberTypes() { + + return this.types; + + } + +} + +class OutputStructNode extends Node { + + static get type() { + + return 'OutputStructNode'; + + } + + constructor( ...members ) { + + super(); + + this.members = members; + + this.isOutputStructNode = true; + + } + + setup( builder ) { + + super.setup( builder ); + + const members = this.members; + const types = []; + + for ( let i = 0; i < members.length; i ++ ) { + + types.push( members[ i ].getNodeType( builder ) ); + + } + + this.nodeType = builder.getStructTypeFromNode( new StructTypeNode( types ) ).name; + + } + + generate( builder, output ) { + + const propertyName = builder.getOutputStructName(); + const members = this.members; + + const structPrefix = propertyName !== '' ? propertyName + '.' : ''; + + for ( let i = 0; i < members.length; i ++ ) { + + const snippet = members[ i ].build( builder, output ); + + builder.addLineFlowCode( `${ structPrefix }m${ i } = ${ snippet }`, this ); + + } + + return propertyName; + + } + +} + +const outputStruct = /*@__PURE__*/ nodeProxy( OutputStructNode ); + +function getTextureIndex( textures, name ) { + + for ( let i = 0; i < textures.length; i ++ ) { + + if ( textures[ i ].name === name ) { + + return i; + + } + + } + + return - 1; + +} + +class MRTNode extends OutputStructNode { + + static get type() { + + return 'MRTNode'; + + } + + constructor( outputNodes ) { + + super(); + + this.outputNodes = outputNodes; + + this.isMRTNode = true; + + } + + has( name ) { + + return this.outputNodes[ name ] !== undefined; + + } + + get( name ) { + + return this.outputNodes[ name ]; + + } + + merge( mrtNode ) { + + const outputs = { ...this.outputNodes, ...mrtNode.outputNodes }; + + return mrt( outputs ); + + } + + setup( builder ) { + + const outputNodes = this.outputNodes; + const mrt = builder.renderer.getRenderTarget(); + + const members = []; + + const textures = mrt.textures; + + for ( const name in outputNodes ) { + + const index = getTextureIndex( textures, name ); + + members[ index ] = vec4( outputNodes[ name ] ); + + } + + this.members = members; + + return super.setup( builder ); + + } + +} + +const mrt = /*@__PURE__*/ nodeProxy( MRTNode ); + +const hash = /*@__PURE__*/ Fn( ( [ seed ] ) => { + + // Taken from https://www.shadertoy.com/view/XlGcRh, originally from pcg-random.org + + const state = seed.toUint().mul( 747796405 ).add( 2891336453 ); + const word = state.shiftRight( state.shiftRight( 28 ).add( 4 ) ).bitXor( state ).mul( 277803737 ); + const result = word.shiftRight( 22 ).bitXor( word ); + + return result.toFloat().mul( 1 / 2 ** 32 ); // Convert to range [0, 1) + +} ); + +// remapping functions https://iquilezles.org/articles/functions/ +const parabola = ( x, k ) => pow( mul( 4.0, x.mul( sub( 1.0, x ) ) ), k ); +const gain = ( x, k ) => x.lessThan( 0.5 ) ? parabola( x.mul( 2.0 ), k ).div( 2.0 ) : sub( 1.0, parabola( mul( sub( 1.0, x ), 2.0 ), k ).div( 2.0 ) ); +const pcurve = ( x, a, b ) => pow( div( pow( x, a ), add( pow( x, a ), pow( sub( 1.0, x ), b ) ) ), 1.0 / a ); +const sinc = ( x, k ) => sin( PI.mul( k.mul( x ).sub( 1.0 ) ) ).div( PI.mul( k.mul( x ).sub( 1.0 ) ) ); + +// https://github.com/cabbibo/glsl-tri-noise-3d + + +const tri = /*@__PURE__*/ Fn( ( [ x ] ) => { + + return x.fract().sub( .5 ).abs(); + +} ).setLayout( { + name: 'tri', + type: 'float', + inputs: [ + { name: 'x', type: 'float' } + ] +} ); + +const tri3 = /*@__PURE__*/ Fn( ( [ p ] ) => { + + return vec3( tri( p.z.add( tri( p.y.mul( 1. ) ) ) ), tri( p.z.add( tri( p.x.mul( 1. ) ) ) ), tri( p.y.add( tri( p.x.mul( 1. ) ) ) ) ); + +} ).setLayout( { + name: 'tri3', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec3' } + ] +} ); + +const triNoise3D = /*@__PURE__*/ Fn( ( [ p_immutable, spd, time ] ) => { + + const p = vec3( p_immutable ).toVar(); + const z = float( 1.4 ).toVar(); + const rz = float( 0.0 ).toVar(); + const bp = vec3( p ).toVar(); + + Loop( { start: float( 0.0 ), end: float( 3.0 ), type: 'float', condition: '<=' }, () => { + + const dg = vec3( tri3( bp.mul( 2.0 ) ) ).toVar(); + p.addAssign( dg.add( time.mul( float( 0.1 ).mul( spd ) ) ) ); + bp.mulAssign( 1.8 ); + z.mulAssign( 1.5 ); + p.mulAssign( 1.2 ); + + const t = float( tri( p.z.add( tri( p.x.add( tri( p.y ) ) ) ) ) ).toVar(); + rz.addAssign( t.div( z ) ); + bp.addAssign( 0.14 ); + + } ); + + return rz; + +} ).setLayout( { + name: 'triNoise3D', + type: 'float', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'spd', type: 'float' }, + { name: 'time', type: 'float' } + ] +} ); + +class FunctionOverloadingNode extends Node { + + static get type() { + + return 'FunctionOverloadingNode'; + + } + + constructor( functionNodes = [], ...parametersNodes ) { + + super(); + + this.functionNodes = functionNodes; + this.parametersNodes = parametersNodes; + + this._candidateFnCall = null; + + this.global = true; + + } + + getNodeType() { + + return this.functionNodes[ 0 ].shaderNode.layout.type; + + } + + setup( builder ) { + + const params = this.parametersNodes; + + let candidateFnCall = this._candidateFnCall; + + if ( candidateFnCall === null ) { + + let candidateFn = null; + let candidateScore = - 1; + + for ( const functionNode of this.functionNodes ) { + + const shaderNode = functionNode.shaderNode; + const layout = shaderNode.layout; + + if ( layout === null ) { + + throw new Error( 'FunctionOverloadingNode: FunctionNode must be a layout.' ); + + } + + const inputs = layout.inputs; + + if ( params.length === inputs.length ) { + + let score = 0; + + for ( let i = 0; i < params.length; i ++ ) { + + const param = params[ i ]; + const input = inputs[ i ]; + + if ( param.getNodeType( builder ) === input.type ) { + + score ++; + + } else { + + score = 0; + + } + + } + + if ( score > candidateScore ) { + + candidateFn = functionNode; + candidateScore = score; + + } + + } + + } + + this._candidateFnCall = candidateFnCall = candidateFn( ...params ); + + } + + return candidateFnCall; + + } + +} + +const overloadingBaseFn = /*@__PURE__*/ nodeProxy( FunctionOverloadingNode ); + +const overloadingFn = ( functionNodes ) => ( ...params ) => overloadingBaseFn( functionNodes, ...params ); + +const time = /*@__PURE__*/ uniform( 0 ).setGroup( renderGroup ).onRenderUpdate( ( frame ) => frame.time ); +const deltaTime = /*@__PURE__*/ uniform( 0 ).setGroup( renderGroup ).onRenderUpdate( ( frame ) => frame.deltaTime ); +const frameId = /*@__PURE__*/ uniform( 0, 'uint' ).setGroup( renderGroup ).onRenderUpdate( ( frame ) => frame.frameId ); + +// Deprecated + +const timerLocal = ( timeScale = 1 ) => { // @deprecated, r170 + + console.warn( 'TSL: timerLocal() is deprecated. Use "time" instead.' ); + return time.mul( timeScale ); + +}; + +const timerGlobal = ( timeScale = 1 ) => { // @deprecated, r170 + + console.warn( 'TSL: timerGlobal() is deprecated. Use "time" instead.' ); + return time.mul( timeScale ); + +}; + +const timerDelta = ( timeScale = 1 ) => { // @deprecated, r170 + + console.warn( 'TSL: timerDelta() is deprecated. Use "deltaTime" instead.' ); + return deltaTime.mul( timeScale ); + +}; + +const oscSine = ( t = time ) => t.add( 0.75 ).mul( Math.PI * 2 ).sin().mul( 0.5 ).add( 0.5 ); +const oscSquare = ( t = time ) => t.fract().round(); +const oscTriangle = ( t = time ) => t.add( 0.5 ).fract().mul( 2 ).sub( 1 ).abs(); +const oscSawtooth = ( t = time ) => t.fract(); + +const rotateUV = /*@__PURE__*/ Fn( ( [ uv, rotation, center = vec2( 0.5 ) ] ) => { + + return rotate( uv.sub( center ), rotation ).add( center ); + +} ); + +const spherizeUV = /*@__PURE__*/ Fn( ( [ uv, strength, center = vec2( 0.5 ) ] ) => { + + const delta = uv.sub( center ); + const delta2 = delta.dot( delta ); + const delta4 = delta2.mul( delta2 ); + const deltaOffset = delta4.mul( strength ); + + return uv.add( delta.mul( deltaOffset ) ); + +} ); + +const billboarding = /*@__PURE__*/ Fn( ( { position = null, horizontal = true, vertical = false } ) => { + + let worldMatrix; + + if ( position !== null ) { + + worldMatrix = modelWorldMatrix.toVar(); + worldMatrix[ 3 ][ 0 ] = position.x; + worldMatrix[ 3 ][ 1 ] = position.y; + worldMatrix[ 3 ][ 2 ] = position.z; + + } else { + + worldMatrix = modelWorldMatrix; + + } + + const modelViewMatrix = cameraViewMatrix.mul( worldMatrix ); + + if ( defined( horizontal ) ) { + + modelViewMatrix[ 0 ][ 0 ] = modelWorldMatrix[ 0 ].length(); + modelViewMatrix[ 0 ][ 1 ] = 0; + modelViewMatrix[ 0 ][ 2 ] = 0; + + } + + if ( defined( vertical ) ) { + + modelViewMatrix[ 1 ][ 0 ] = 0; + modelViewMatrix[ 1 ][ 1 ] = modelWorldMatrix[ 1 ].length(); + modelViewMatrix[ 1 ][ 2 ] = 0; + + } + + modelViewMatrix[ 2 ][ 0 ] = 0; + modelViewMatrix[ 2 ][ 1 ] = 0; + modelViewMatrix[ 2 ][ 2 ] = 1; + + return cameraProjectionMatrix.mul( modelViewMatrix ).mul( positionLocal ); + +} ); + +const viewportSafeUV = /*@__PURE__*/ Fn( ( [ uv = null ] ) => { + + const depth = linearDepth(); + const depthDiff = linearDepth( viewportDepthTexture( uv ) ).sub( depth ); + const finalUV = depthDiff.lessThan( 0 ).select( screenUV, uv ); + + return finalUV; + +} ); + +class SpriteSheetUVNode extends Node { + + static get type() { + + return 'SpriteSheetUVNode'; + + } + + constructor( countNode, uvNode = uv(), frameNode = float( 0 ) ) { + + super( 'vec2' ); + + this.countNode = countNode; + this.uvNode = uvNode; + this.frameNode = frameNode; + + } + + setup() { + + const { frameNode, uvNode, countNode } = this; + + const { width, height } = countNode; + + const frameNum = frameNode.mod( width.mul( height ) ).floor(); + + const column = frameNum.mod( width ); + const row = height.sub( frameNum.add( 1 ).div( width ).ceil() ); + + const scale = countNode.reciprocal(); + const uvFrameOffset = vec2( column, row ); + + return uvNode.add( uvFrameOffset ).mul( scale ); + + } + +} + +const spritesheetUV = /*@__PURE__*/ nodeProxy( SpriteSheetUVNode ); + +class TriplanarTexturesNode extends Node { + + static get type() { + + return 'TriplanarTexturesNode'; + + } + + constructor( textureXNode, textureYNode = null, textureZNode = null, scaleNode = float( 1 ), positionNode = positionLocal, normalNode = normalLocal ) { + + super( 'vec4' ); + + this.textureXNode = textureXNode; + this.textureYNode = textureYNode; + this.textureZNode = textureZNode; + + this.scaleNode = scaleNode; + + this.positionNode = positionNode; + this.normalNode = normalNode; + + } + + setup() { + + const { textureXNode, textureYNode, textureZNode, scaleNode, positionNode, normalNode } = this; + + // Ref: https://github.com/keijiro/StandardTriplanar + + // Blending factor of triplanar mapping + let bf = normalNode.abs().normalize(); + bf = bf.div( bf.dot( vec3( 1.0 ) ) ); + + // Triplanar mapping + const tx = positionNode.yz.mul( scaleNode ); + const ty = positionNode.zx.mul( scaleNode ); + const tz = positionNode.xy.mul( scaleNode ); + + // Base color + const textureX = textureXNode.value; + const textureY = textureYNode !== null ? textureYNode.value : textureX; + const textureZ = textureZNode !== null ? textureZNode.value : textureX; + + const cx = texture( textureX, tx ).mul( bf.x ); + const cy = texture( textureY, ty ).mul( bf.y ); + const cz = texture( textureZ, tz ).mul( bf.z ); + + return add( cx, cy, cz ); + + } + +} + +const triplanarTextures = /*@__PURE__*/ nodeProxy( TriplanarTexturesNode ); +const triplanarTexture = ( ...params ) => triplanarTextures( ...params ); + +const _reflectorPlane = new Plane(); +const _normal = new Vector3(); +const _reflectorWorldPosition = new Vector3(); +const _cameraWorldPosition = new Vector3(); +const _rotationMatrix = new Matrix4(); +const _lookAtPosition = new Vector3( 0, 0, - 1 ); +const clipPlane = new Vector4(); + +const _view = new Vector3(); +const _target = new Vector3(); +const _q = new Vector4(); + +const _size$2 = new Vector2(); + +const _defaultRT = new RenderTarget(); +const _defaultUV = screenUV.flipX(); + +_defaultRT.depthTexture = new DepthTexture( 1, 1 ); + +let _inReflector = false; + +class ReflectorNode extends TextureNode { + + static get type() { + + return 'ReflectorNode'; + + } + + constructor( parameters = {} ) { + + super( parameters.defaultTexture || _defaultRT.texture, _defaultUV ); + + this._reflectorBaseNode = parameters.reflector || new ReflectorBaseNode( this, parameters ); + this._depthNode = null; + + this.setUpdateMatrix( false ); + + } + + get reflector() { + + return this._reflectorBaseNode; + + } + + get target() { + + return this._reflectorBaseNode.target; + + } + + getDepthNode() { + + if ( this._depthNode === null ) { + + if ( this._reflectorBaseNode.depth !== true ) { + + throw new Error( 'THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ' ); + + } + + this._depthNode = nodeObject( new ReflectorNode( { + defaultTexture: _defaultRT.depthTexture, + reflector: this._reflectorBaseNode + } ) ); + + } + + return this._depthNode; + + } + + setup( builder ) { + + // ignore if used in post-processing + if ( ! builder.object.isQuadMesh ) this._reflectorBaseNode.build( builder ); + + return super.setup( builder ); + + } + + clone() { + + const texture = new this.constructor( this.reflectorNode ); + texture._reflectorBaseNode = this._reflectorBaseNode; + + return texture; + + } + +} + + +class ReflectorBaseNode extends Node { + + static get type() { + + return 'ReflectorBaseNode'; + + } + + constructor( textureNode, parameters = {} ) { + + super(); + + const { + target = new Object3D(), + resolution = 1, + generateMipmaps = false, + bounces = true, + depth = false + } = parameters; + + // + + this.textureNode = textureNode; + + this.target = target; + this.resolution = resolution; + this.generateMipmaps = generateMipmaps; + this.bounces = bounces; + this.depth = depth; + + this.updateBeforeType = bounces ? NodeUpdateType.RENDER : NodeUpdateType.FRAME; + + this.virtualCameras = new WeakMap(); + this.renderTargets = new WeakMap(); + + } + + _updateResolution( renderTarget, renderer ) { + + const resolution = this.resolution; + + renderer.getDrawingBufferSize( _size$2 ); + + renderTarget.setSize( Math.round( _size$2.width * resolution ), Math.round( _size$2.height * resolution ) ); + + } + + setup( builder ) { + + this._updateResolution( _defaultRT, builder.renderer ); + + return super.setup( builder ); + + } + + getVirtualCamera( camera ) { + + let virtualCamera = this.virtualCameras.get( camera ); + + if ( virtualCamera === undefined ) { + + virtualCamera = camera.clone(); + + this.virtualCameras.set( camera, virtualCamera ); + + } + + return virtualCamera; + + } + + getRenderTarget( camera ) { + + let renderTarget = this.renderTargets.get( camera ); + + if ( renderTarget === undefined ) { + + renderTarget = new RenderTarget( 0, 0, { type: HalfFloatType } ); + + if ( this.generateMipmaps === true ) { + + renderTarget.texture.minFilter = LinearMipMapLinearFilter; + renderTarget.texture.generateMipmaps = true; + + } + + if ( this.depth === true ) { + + renderTarget.depthTexture = new DepthTexture(); + + } + + this.renderTargets.set( camera, renderTarget ); + + } + + return renderTarget; + + } + + updateBefore( frame ) { + + if ( this.bounces === false && _inReflector ) return; + + _inReflector = true; + + const { scene, camera, renderer, material } = frame; + const { target } = this; + + const virtualCamera = this.getVirtualCamera( camera ); + const renderTarget = this.getRenderTarget( virtualCamera ); + + renderer.getDrawingBufferSize( _size$2 ); + + this._updateResolution( renderTarget, renderer ); + + // + + _reflectorWorldPosition.setFromMatrixPosition( target.matrixWorld ); + _cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld ); + + _rotationMatrix.extractRotation( target.matrixWorld ); + + _normal.set( 0, 0, 1 ); + _normal.applyMatrix4( _rotationMatrix ); + + _view.subVectors( _reflectorWorldPosition, _cameraWorldPosition ); + + // Avoid rendering when reflector is facing away + + if ( _view.dot( _normal ) > 0 ) return; + + _view.reflect( _normal ).negate(); + _view.add( _reflectorWorldPosition ); + + _rotationMatrix.extractRotation( camera.matrixWorld ); + + _lookAtPosition.set( 0, 0, - 1 ); + _lookAtPosition.applyMatrix4( _rotationMatrix ); + _lookAtPosition.add( _cameraWorldPosition ); + + _target.subVectors( _reflectorWorldPosition, _lookAtPosition ); + _target.reflect( _normal ).negate(); + _target.add( _reflectorWorldPosition ); + + // + + virtualCamera.coordinateSystem = camera.coordinateSystem; + virtualCamera.position.copy( _view ); + virtualCamera.up.set( 0, 1, 0 ); + virtualCamera.up.applyMatrix4( _rotationMatrix ); + virtualCamera.up.reflect( _normal ); + virtualCamera.lookAt( _target ); + + virtualCamera.near = camera.near; + virtualCamera.far = camera.far; + + virtualCamera.updateMatrixWorld(); + virtualCamera.projectionMatrix.copy( camera.projectionMatrix ); + + // Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html + // Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf + _reflectorPlane.setFromNormalAndCoplanarPoint( _normal, _reflectorWorldPosition ); + _reflectorPlane.applyMatrix4( virtualCamera.matrixWorldInverse ); + + clipPlane.set( _reflectorPlane.normal.x, _reflectorPlane.normal.y, _reflectorPlane.normal.z, _reflectorPlane.constant ); + + const projectionMatrix = virtualCamera.projectionMatrix; + + _q.x = ( Math.sign( clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ]; + _q.y = ( Math.sign( clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ]; + _q.z = - 1.0; + _q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ]; + + // Calculate the scaled plane vector + clipPlane.multiplyScalar( 1.0 / clipPlane.dot( _q ) ); + + const clipBias = 0; + + // Replacing the third row of the projection matrix + projectionMatrix.elements[ 2 ] = clipPlane.x; + projectionMatrix.elements[ 6 ] = clipPlane.y; + projectionMatrix.elements[ 10 ] = ( renderer.coordinateSystem === WebGPUCoordinateSystem ) ? ( clipPlane.z - clipBias ) : ( clipPlane.z + 1.0 - clipBias ); + projectionMatrix.elements[ 14 ] = clipPlane.w; + + // + + this.textureNode.value = renderTarget.texture; + + if ( this.depth === true ) { + + this.textureNode.getDepthNode().value = renderTarget.depthTexture; + + } + + material.visible = false; + + const currentRenderTarget = renderer.getRenderTarget(); + const currentMRT = renderer.getMRT(); + + renderer.setMRT( null ); + renderer.setRenderTarget( renderTarget ); + + renderer.render( scene, virtualCamera ); + + renderer.setMRT( currentMRT ); + renderer.setRenderTarget( currentRenderTarget ); + + material.visible = true; + + _inReflector = false; + + } + +} + +const reflector = ( parameters ) => nodeObject( new ReflectorNode( parameters ) ); + +// Helper for passes that need to fill the viewport with a single quad. + +const _camera = /*@__PURE__*/ new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); + +// https://github.com/mrdoob/three.js/pull/21358 + +class QuadGeometry extends BufferGeometry { + + constructor( flipY = false ) { + + super(); + + const uv = flipY === false ? [ 0, - 1, 0, 1, 2, 1 ] : [ 0, 2, 0, 0, 2, 0 ]; + + this.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uv, 2 ) ); + + } + +} + +const _geometry = /*@__PURE__*/ new QuadGeometry(); + +class QuadMesh extends Mesh { + + constructor( material = null ) { + + super( _geometry, material ); + + this.camera = _camera; + + this.isQuadMesh = true; + + } + + renderAsync( renderer ) { + + return renderer.renderAsync( this, _camera ); + + } + + render( renderer ) { + + renderer.render( this, _camera ); + + } + +} + +const _size$1 = /*@__PURE__*/ new Vector2(); + +class RTTNode extends TextureNode { + + static get type() { + + return 'RTTNode'; + + } + + constructor( node, width = null, height = null, options = { type: HalfFloatType } ) { + + const renderTarget = new RenderTarget( width, height, options ); + + super( renderTarget.texture, uv() ); + + this.node = node; + this.width = width; + this.height = height; + + this.renderTarget = renderTarget; + + this.textureNeedsUpdate = true; + this.autoUpdate = true; + + this.updateMap = new WeakMap(); + + this._rttNode = null; + this._quadMesh = new QuadMesh( new NodeMaterial() ); + + this.updateBeforeType = NodeUpdateType.RENDER; + + } + + get autoSize() { + + return this.width === null; + + } + + setup( builder ) { + + this._rttNode = this.node.context( builder.getSharedContext() ); + this._quadMesh.material.name = 'RTT'; + this._quadMesh.material.needsUpdate = true; + + return super.setup( builder ); + + } + + setSize( width, height ) { + + this.width = width; + this.height = height; + + const effectiveWidth = width * this.pixelRatio; + const effectiveHeight = height * this.pixelRatio; + + this.renderTarget.setSize( effectiveWidth, effectiveHeight ); + + this.textureNeedsUpdate = true; + + } + + setPixelRatio( pixelRatio ) { + + this.pixelRatio = pixelRatio; + + this.setSize( this.width, this.height ); + + } + + updateBefore( { renderer } ) { + + if ( this.textureNeedsUpdate === false && this.autoUpdate === false ) return; + + this.textureNeedsUpdate = false; + + // + + if ( this.autoSize === true ) { + + this.pixelRatio = renderer.getPixelRatio(); + + const size = renderer.getSize( _size$1 ); + + this.setSize( size.width, size.height ); + + } + + // + + this._quadMesh.material.fragmentNode = this._rttNode; + + // + + const currentRenderTarget = renderer.getRenderTarget(); + + renderer.setRenderTarget( this.renderTarget ); + + this._quadMesh.render( renderer ); + + renderer.setRenderTarget( currentRenderTarget ); + + } + + clone() { + + const newNode = new TextureNode( this.value, this.uvNode, this.levelNode ); + newNode.sampler = this.sampler; + newNode.referenceNode = this; + + return newNode; + + } + +} + +const rtt = ( node, ...params ) => nodeObject( new RTTNode( nodeObject( node ), ...params ) ); + +const convertToTexture = ( node, ...params ) => { + + if ( node.isTextureNode ) return node; + if ( node.isPassNode ) return node.getTextureNode(); + + return rtt( node, ...params ); + +}; + +/** +* Computes a position in view space based on a fragment's screen position expressed as uv coordinates, the fragments +* depth value and the camera's inverse projection matrix. +* +* @param {vec2} screenPosition - The fragment's screen position expressed as uv coordinates. +* @param {float} depth - The fragment's depth value. +* @param {mat4} projectionMatrixInverse - The camera's inverse projection matrix. +* @return {vec3} The fragments position in view space. +*/ +const getViewPosition = /*@__PURE__*/ Fn( ( [ screenPosition, depth, projectionMatrixInverse ], builder ) => { + + let clipSpacePosition; + + if ( builder.renderer.coordinateSystem === WebGPUCoordinateSystem ) { + + screenPosition = vec2( screenPosition.x, screenPosition.y.oneMinus() ).mul( 2.0 ).sub( 1.0 ); + clipSpacePosition = vec4( vec3( screenPosition, depth ), 1.0 ); + + } else { + + clipSpacePosition = vec4( vec3( screenPosition.x, screenPosition.y.oneMinus(), depth ).mul( 2.0 ).sub( 1.0 ), 1.0 ); + + } + + const viewSpacePosition = vec4( projectionMatrixInverse.mul( clipSpacePosition ) ); + + return viewSpacePosition.xyz.div( viewSpacePosition.w ); + +} ); + +/** +* Computes a screen position expressed as uv coordinates based on a fragment's position in view space +* and the camera's projection matrix +* +* @param {vec3} viewPosition - The fragments position in view space. +* @param {mat4} projectionMatrix - The camera's projection matrix. +* @return {vec2} The fragment's screen position expressed as uv coordinates. +*/ +const getScreenPosition = /*@__PURE__*/ Fn( ( [ viewPosition, projectionMatrix ] ) => { + + const sampleClipPos = projectionMatrix.mul( vec4( viewPosition, 1.0 ) ); + const sampleUv = sampleClipPos.xy.div( sampleClipPos.w ).mul( 0.5 ).add( 0.5 ).toVar(); + return vec2( sampleUv.x, sampleUv.y.oneMinus() ); + +} ); + +/** +* Computes a normal vector based on depth data. Can be used as a fallback when no normal render +* target is available or if flat surface normals are required. +* +* @param {vec2} uv - The texture coordinate. +* @param {DepthTexture} depthTexture - The depth texture. +* @param {mat4} projectionMatrixInverse - The camera's inverse projection matrix. +* @return {vec3} The computed normal vector. +*/ +const getNormalFromDepth = /*@__PURE__*/ Fn( ( [ uv, depthTexture, projectionMatrixInverse ] ) => { + + const size = textureSize( textureLoad( depthTexture ) ); + const p = ivec2( uv.mul( size ) ).toVar(); + + const c0 = textureLoad( depthTexture, p ).toVar(); + + const l2 = textureLoad( depthTexture, p.sub( ivec2( 2, 0 ) ) ).toVar(); + const l1 = textureLoad( depthTexture, p.sub( ivec2( 1, 0 ) ) ).toVar(); + const r1 = textureLoad( depthTexture, p.add( ivec2( 1, 0 ) ) ).toVar(); + const r2 = textureLoad( depthTexture, p.add( ivec2( 2, 0 ) ) ).toVar(); + const b2 = textureLoad( depthTexture, p.add( ivec2( 0, 2 ) ) ).toVar(); + const b1 = textureLoad( depthTexture, p.add( ivec2( 0, 1 ) ) ).toVar(); + const t1 = textureLoad( depthTexture, p.sub( ivec2( 0, 1 ) ) ).toVar(); + const t2 = textureLoad( depthTexture, p.sub( ivec2( 0, 2 ) ) ).toVar(); + + const dl = abs( sub( float( 2 ).mul( l1 ).sub( l2 ), c0 ) ).toVar(); + const dr = abs( sub( float( 2 ).mul( r1 ).sub( r2 ), c0 ) ).toVar(); + const db = abs( sub( float( 2 ).mul( b1 ).sub( b2 ), c0 ) ).toVar(); + const dt = abs( sub( float( 2 ).mul( t1 ).sub( t2 ), c0 ) ).toVar(); + + const ce = getViewPosition( uv, c0, projectionMatrixInverse ).toVar(); + + const dpdx = dl.lessThan( dr ).select( ce.sub( getViewPosition( uv.sub( vec2( float( 1 ).div( size.x ), 0 ) ), l1, projectionMatrixInverse ) ), ce.negate().add( getViewPosition( uv.add( vec2( float( 1 ).div( size.x ), 0 ) ), r1, projectionMatrixInverse ) ) ); + const dpdy = db.lessThan( dt ).select( ce.sub( getViewPosition( uv.add( vec2( 0, float( 1 ).div( size.y ) ) ), b1, projectionMatrixInverse ) ), ce.negate().add( getViewPosition( uv.sub( vec2( 0, float( 1 ).div( size.y ) ) ), t1, projectionMatrixInverse ) ) ); + + return normalize( cross( dpdx, dpdy ) ); + +} ); + +class StorageInstancedBufferAttribute extends InstancedBufferAttribute { + + constructor( array, itemSize, typeClass = Float32Array ) { + + if ( ArrayBuffer.isView( array ) === false ) array = new typeClass( array * itemSize ); + + super( array, itemSize ); + + this.isStorageInstancedBufferAttribute = true; + + } + +} + +class StorageBufferAttribute extends BufferAttribute { + + constructor( array, itemSize, typeClass = Float32Array ) { + + if ( ArrayBuffer.isView( array ) === false ) array = new typeClass( array * itemSize ); + + super( array, itemSize ); + + this.isStorageBufferAttribute = true; + + } + +} + +class StorageArrayElementNode extends ArrayElementNode { + + static get type() { + + return 'StorageArrayElementNode'; + + } + + constructor( storageBufferNode, indexNode ) { + + super( storageBufferNode, indexNode ); + + this.isStorageArrayElementNode = true; + + } + + set storageBufferNode( value ) { + + this.node = value; + + } + + get storageBufferNode() { + + return this.node; + + } + + setup( builder ) { + + if ( builder.isAvailable( 'storageBuffer' ) === false ) { + + if ( this.node.isPBO === true ) { + + builder.setupPBO( this.node ); + + } + + } + + return super.setup( builder ); + + } + + generate( builder, output ) { + + let snippet; + + const isAssignContext = builder.context.assign; + + // + + if ( builder.isAvailable( 'storageBuffer' ) === false ) { + + if ( this.node.isPBO === true && isAssignContext !== true && ( this.node.value.isInstancedBufferAttribute || builder.shaderStage !== 'compute' ) ) { + + snippet = builder.generatePBO( this ); + + } else { + + snippet = this.node.build( builder ); + + } + + } else { + + snippet = super.generate( builder ); + + } + + if ( isAssignContext !== true ) { + + const type = this.getNodeType( builder ); + + snippet = builder.format( snippet, type, output ); + + } + + return snippet; + + } + +} + +const storageElement = /*@__PURE__*/ nodeProxy( StorageArrayElementNode ); + +class StorageBufferNode extends BufferNode { + + static get type() { + + return 'StorageBufferNode'; + + } + + constructor( value, bufferType = null, bufferCount = 0 ) { + + if ( bufferType === null && ( value.isStorageBufferAttribute || value.isStorageInstancedBufferAttribute ) ) { + + bufferType = getTypeFromLength( value.itemSize ); + bufferCount = value.count; + + } + + super( value, bufferType, bufferCount ); + + this.isStorageBufferNode = true; + + this.access = NodeAccess.READ_WRITE; + this.isAtomic = false; + this.isPBO = false; + + this.bufferCount = bufferCount; + + this._attribute = null; + this._varying = null; + + this.global = true; + + if ( value.isStorageBufferAttribute !== true && value.isStorageInstancedBufferAttribute !== true ) { + + // TOOD: Improve it, possibly adding a new property to the BufferAttribute to identify it as a storage buffer read-only attribute in Renderer + + if ( value.isInstancedBufferAttribute ) value.isStorageInstancedBufferAttribute = true; + else value.isStorageBufferAttribute = true; + + } + + } + + getHash( builder ) { + + if ( this.bufferCount === 0 ) { + + let bufferData = builder.globalCache.getData( this.value ); + + if ( bufferData === undefined ) { + + bufferData = { + node: this + }; + + builder.globalCache.setData( this.value, bufferData ); + + } + + return bufferData.node.uuid; + + } + + return this.uuid; + + } + + getInputType( /*builder*/ ) { + + return this.value.isIndirectStorageBufferAttribute ? 'indirectStorageBuffer' : 'storageBuffer'; + + } + + element( indexNode ) { + + return storageElement( this, indexNode ); + + } + + setPBO( value ) { + + this.isPBO = value; + + return this; + + } + + getPBO() { + + return this.isPBO; + + } + + setAccess( value ) { + + this.access = value; + + return this; + + } + + toReadOnly() { + + return this.setAccess( NodeAccess.READ_ONLY ); + + } + + setAtomic( value ) { + + this.isAtomic = value; + + return this; + + } + + toAtomic() { + + return this.setAtomic( true ); + + } + + getAttributeData() { + + if ( this._attribute === null ) { + + this._attribute = bufferAttribute( this.value ); + this._varying = varying( this._attribute ); + + } + + return { + attribute: this._attribute, + varying: this._varying + }; + + } + + getNodeType( builder ) { + + if ( builder.isAvailable( 'storageBuffer' ) || builder.isAvailable( 'indirectStorageBuffer' ) ) { + + return super.getNodeType( builder ); + + } + + const { attribute } = this.getAttributeData(); + + return attribute.getNodeType( builder ); + + } + + generate( builder ) { + + if ( builder.isAvailable( 'storageBuffer' ) || builder.isAvailable( 'indirectStorageBuffer' ) ) { + + return super.generate( builder ); + + } + + const { attribute, varying } = this.getAttributeData(); + + const output = varying.build( builder ); + + builder.registerTransform( output, attribute ); + + return output; + + } + +} + +const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) ); + +const storageObject = ( value, type, count ) => { // @deprecated, r171 + + console.warn( 'THREE.TSL: "storageObject()" is deprecated. Use "storage().setPBO( true )" instead.' ); + + return storage( value, type, count ).setPBO( true ); + +}; + +const attributeArray = ( count, type = 'float' ) => { + + const itemSize = getLengthFromType( type ); + + const buffer = new StorageBufferAttribute( count, itemSize ); + const node = storage( buffer, type, count ); + + return node; + +}; + + +const instancedArray = ( count, type = 'float' ) => { + + const itemSize = getLengthFromType( type ); + + const buffer = new StorageInstancedBufferAttribute( count, itemSize ); + const node = storage( buffer, type, count ); + + return node; + +}; + +class VertexColorNode extends AttributeNode { + + static get type() { + + return 'VertexColorNode'; + + } + + constructor( index = 0 ) { + + super( null, 'vec4' ); + + this.isVertexColorNode = true; + + this.index = index; + + } + + getAttributeName( /*builder*/ ) { + + const index = this.index; + + return 'color' + ( index > 0 ? index : '' ); + + } + + generate( builder ) { + + const attributeName = this.getAttributeName( builder ); + const geometryAttribute = builder.hasGeometryAttribute( attributeName ); + + let result; + + if ( geometryAttribute === true ) { + + result = super.generate( builder ); + + } else { + + // Vertex color fallback should be white + result = builder.generateConst( this.nodeType, new Vector4( 1, 1, 1, 1 ) ); + + } + + return result; + + } + + serialize( data ) { + + super.serialize( data ); + + data.index = this.index; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.index = data.index; + + } + +} + +const vertexColor = ( ...params ) => nodeObject( new VertexColorNode( ...params ) ); + +class PointUVNode extends Node { + + static get type() { + + return 'PointUVNode'; + + } + + constructor() { + + super( 'vec2' ); + + this.isPointUVNode = true; + + } + + generate( /*builder*/ ) { + + return 'vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )'; + + } + +} + +const pointUV = /*@__PURE__*/ nodeImmutable( PointUVNode ); + +const _e1 = /*@__PURE__*/ new Euler(); +const _m1 = /*@__PURE__*/ new Matrix4(); + +class SceneNode extends Node { + + static get type() { + + return 'SceneNode'; + + } + + constructor( scope = SceneNode.BACKGROUND_BLURRINESS, scene = null ) { + + super(); + + this.scope = scope; + this.scene = scene; + + } + + setup( builder ) { + + const scope = this.scope; + const scene = this.scene !== null ? this.scene : builder.scene; + + let output; + + if ( scope === SceneNode.BACKGROUND_BLURRINESS ) { + + output = reference( 'backgroundBlurriness', 'float', scene ); + + } else if ( scope === SceneNode.BACKGROUND_INTENSITY ) { + + output = reference( 'backgroundIntensity', 'float', scene ); + + } else if ( scope === SceneNode.BACKGROUND_ROTATION ) { + + output = uniform( 'mat4' ).label( 'backgroundRotation' ).setGroup( renderGroup ).onRenderUpdate( () => { + + const background = scene.background; + + if ( background !== null && background.isTexture && background.mapping !== UVMapping ) { + + _e1.copy( scene.backgroundRotation ); + + // accommodate left-handed frame + _e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1; + + _m1.makeRotationFromEuler( _e1 ); + + } else { + + _m1.identity(); + + } + + return _m1; + + } ); + + } else { + + console.error( 'THREE.SceneNode: Unknown scope:', scope ); + + } + + return output; + + } + +} + +SceneNode.BACKGROUND_BLURRINESS = 'backgroundBlurriness'; +SceneNode.BACKGROUND_INTENSITY = 'backgroundIntensity'; +SceneNode.BACKGROUND_ROTATION = 'backgroundRotation'; + +const backgroundBlurriness = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_BLURRINESS ); +const backgroundIntensity = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_INTENSITY ); +const backgroundRotation = /*@__PURE__*/ nodeImmutable( SceneNode, SceneNode.BACKGROUND_ROTATION ); + +class StorageTextureNode extends TextureNode { + + static get type() { + + return 'StorageTextureNode'; + + } + + constructor( value, uvNode, storeNode = null ) { + + super( value, uvNode ); + + this.storeNode = storeNode; + + this.isStorageTextureNode = true; + + this.access = NodeAccess.WRITE_ONLY; + + } + + getInputType( /*builder*/ ) { + + return 'storageTexture'; + + } + + setup( builder ) { + + super.setup( builder ); + + const properties = builder.getNodeProperties( this ); + properties.storeNode = this.storeNode; + + } + + setAccess( value ) { + + this.access = value; + return this; + + } + + generate( builder, output ) { + + let snippet; + + if ( this.storeNode !== null ) { + + snippet = this.generateStore( builder ); + + } else { + + snippet = super.generate( builder, output ); + + } + + return snippet; + + } + + toReadWrite() { + + return this.setAccess( NodeAccess.READ_WRITE ); + + } + + toReadOnly() { + + return this.setAccess( NodeAccess.READ_ONLY ); + + } + + toWriteOnly() { + + return this.setAccess( NodeAccess.WRITE_ONLY ); + + } + + generateStore( builder ) { + + const properties = builder.getNodeProperties( this ); + + const { uvNode, storeNode } = properties; + + const textureProperty = super.generate( builder, 'property' ); + const uvSnippet = uvNode.build( builder, 'uvec2' ); + const storeSnippet = storeNode.build( builder, 'vec4' ); + + const snippet = builder.generateTextureStore( builder, textureProperty, uvSnippet, storeSnippet ); + + builder.addLineFlowCode( snippet, this ); + + } + +} + +const storageTexture = /*@__PURE__*/ nodeProxy( StorageTextureNode ); + +const textureStore = ( value, uvNode, storeNode ) => { + + const node = storageTexture( value, uvNode, storeNode ); + + if ( storeNode !== null ) node.append(); + + return node; + +}; + +class UserDataNode extends ReferenceNode { + + static get type() { + + return 'UserDataNode'; + + } + + constructor( property, inputType, userData = null ) { + + super( property, inputType, userData ); + + this.userData = userData; + + } + + updateReference( state ) { + + this.reference = this.userData !== null ? this.userData : state.object.userData; + + return this.reference; + + } + +} + +const userData = ( name, inputType, userData ) => nodeObject( new UserDataNode( name, inputType, userData ) ); + +const _objectData = new WeakMap(); + +class VelocityNode extends TempNode { + + static get type() { + + return 'VelocityNode'; + + } + + constructor() { + + super( 'vec2' ); + + this.projectionMatrix = null; + + this.updateType = NodeUpdateType.OBJECT; + this.updateAfterType = NodeUpdateType.OBJECT; + + this.previousModelWorldMatrix = uniform( new Matrix4() ); + this.previousProjectionMatrix = uniform( new Matrix4() ).setGroup( renderGroup ); + this.previousCameraViewMatrix = uniform( new Matrix4() ); + + } + + setProjectionMatrix( projectionMatrix ) { + + this.projectionMatrix = projectionMatrix; + + } + + update( { frameId, camera, object } ) { + + const previousModelMatrix = getPreviousMatrix( object ); + + this.previousModelWorldMatrix.value.copy( previousModelMatrix ); + + // + + const cameraData = getData( camera ); + + if ( cameraData.frameId !== frameId ) { + + cameraData.frameId = frameId; + + if ( cameraData.previousProjectionMatrix === undefined ) { + + cameraData.previousProjectionMatrix = new Matrix4(); + cameraData.previousCameraViewMatrix = new Matrix4(); + + cameraData.currentProjectionMatrix = new Matrix4(); + cameraData.currentCameraViewMatrix = new Matrix4(); + + cameraData.previousProjectionMatrix.copy( this.projectionMatrix || camera.projectionMatrix ); + cameraData.previousCameraViewMatrix.copy( camera.matrixWorldInverse ); + + } else { + + cameraData.previousProjectionMatrix.copy( cameraData.currentProjectionMatrix ); + cameraData.previousCameraViewMatrix.copy( cameraData.currentCameraViewMatrix ); + + } + + cameraData.currentProjectionMatrix.copy( this.projectionMatrix || camera.projectionMatrix ); + cameraData.currentCameraViewMatrix.copy( camera.matrixWorldInverse ); + + this.previousProjectionMatrix.value.copy( cameraData.previousProjectionMatrix ); + this.previousCameraViewMatrix.value.copy( cameraData.previousCameraViewMatrix ); + + } + + } + + updateAfter( { object } ) { + + getPreviousMatrix( object ).copy( object.matrixWorld ); + + } + + setup( /*builder*/ ) { + + const projectionMatrix = ( this.projectionMatrix === null ) ? cameraProjectionMatrix : uniform( this.projectionMatrix ); + + const previousModelViewMatrix = this.previousCameraViewMatrix.mul( this.previousModelWorldMatrix ); + + const clipPositionCurrent = projectionMatrix.mul( modelViewMatrix ).mul( positionLocal ); + const clipPositionPrevious = this.previousProjectionMatrix.mul( previousModelViewMatrix ).mul( positionPrevious ); + + const ndcPositionCurrent = clipPositionCurrent.xy.div( clipPositionCurrent.w ); + const ndcPositionPrevious = clipPositionPrevious.xy.div( clipPositionPrevious.w ); + + const velocity = sub( ndcPositionCurrent, ndcPositionPrevious ); + + return velocity; + + } + +} + +function getData( object ) { + + let objectData = _objectData.get( object ); + + if ( objectData === undefined ) { + + objectData = {}; + _objectData.set( object, objectData ); + + } + + return objectData; + +} + +function getPreviousMatrix( object, index = 0 ) { + + const objectData = getData( object ); + + let matrix = objectData[ index ]; + + if ( matrix === undefined ) { + + objectData[ index ] = matrix = new Matrix4(); + + } + + return matrix; + +} + +const velocity = /*@__PURE__*/ nodeImmutable( VelocityNode ); + +const blendBurn = /*@__PURE__*/ Fn( ( [ base, blend ] ) => { + + return min$1( 1.0, base.oneMinus().div( blend ) ).oneMinus(); + +} ).setLayout( { + name: 'blendBurn', + type: 'vec3', + inputs: [ + { name: 'base', type: 'vec3' }, + { name: 'blend', type: 'vec3' } + ] +} ); + +const blendDodge = /*@__PURE__*/ Fn( ( [ base, blend ] ) => { + + return min$1( base.div( blend.oneMinus() ), 1.0 ); + +} ).setLayout( { + name: 'blendDodge', + type: 'vec3', + inputs: [ + { name: 'base', type: 'vec3' }, + { name: 'blend', type: 'vec3' } + ] +} ); + +const blendScreen = /*@__PURE__*/ Fn( ( [ base, blend ] ) => { + + return base.oneMinus().mul( blend.oneMinus() ).oneMinus(); + +} ).setLayout( { + name: 'blendScreen', + type: 'vec3', + inputs: [ + { name: 'base', type: 'vec3' }, + { name: 'blend', type: 'vec3' } + ] +} ); + +const blendOverlay = /*@__PURE__*/ Fn( ( [ base, blend ] ) => { + + return mix( base.mul( 2.0 ).mul( blend ), base.oneMinus().mul( 2.0 ).mul( blend.oneMinus() ).oneMinus(), step( 0.5, base ) ); + +} ).setLayout( { + name: 'blendOverlay', + type: 'vec3', + inputs: [ + { name: 'base', type: 'vec3' }, + { name: 'blend', type: 'vec3' } + ] +} ); + +const blendColor = /*@__PURE__*/ Fn( ( [ base, blend ] ) => { + + const outAlpha = blend.a.add( base.a.mul( blend.a.oneMinus() ) ); + + return vec4( blend.rgb.mul( blend.a ).add( base.rgb.mul( base.a ).mul( blend.a.oneMinus() ) ).div( outAlpha ), outAlpha ); + +} ).setLayout( { + name: 'blendColor', + type: 'vec4', + inputs: [ + { name: 'base', type: 'vec4' }, + { name: 'blend', type: 'vec4' } + ] +} ); + +// deprecated + +const burn = ( ...params ) => { // @deprecated, r171 + + console.warn( 'THREE.TSL: "burn" has been renamed. Use "blendBurn" instead.' ); + return blendBurn( params ); + +}; + +const dodge = ( ...params ) => { // @deprecated, r171 + + console.warn( 'THREE.TSL: "dodge" has been renamed. Use "blendDodge" instead.' ); + return blendDodge( params ); + +}; + +const screen = ( ...params ) => { // @deprecated, r171 + + console.warn( 'THREE.TSL: "screen" has been renamed. Use "blendScreen" instead.' ); + return blendScreen( params ); + +}; + +const overlay = ( ...params ) => { // @deprecated, r171 + + console.warn( 'THREE.TSL: "overlay" has been renamed. Use "blendOverlay" instead.' ); + return blendOverlay( params ); + +}; + +const grayscale = /*@__PURE__*/ Fn( ( [ color ] ) => { + + return luminance( color.rgb ); + +} ); + +const saturation = /*@__PURE__*/ Fn( ( [ color, adjustment = float( 1 ) ] ) => { + + return adjustment.mix( luminance( color.rgb ), color.rgb ); + +} ); + +const vibrance = /*@__PURE__*/ Fn( ( [ color, adjustment = float( 1 ) ] ) => { + + const average = add( color.r, color.g, color.b ).div( 3.0 ); + + const mx = color.r.max( color.g.max( color.b ) ); + const amt = mx.sub( average ).mul( adjustment ).mul( - 3.0 ); + + return mix( color.rgb, mx, amt ); + +} ); + +const hue = /*@__PURE__*/ Fn( ( [ color, adjustment = float( 1 ) ] ) => { + + const k = vec3( 0.57735, 0.57735, 0.57735 ); + + const cosAngle = adjustment.cos(); + + return vec3( color.rgb.mul( cosAngle ).add( k.cross( color.rgb ).mul( adjustment.sin() ).add( k.mul( dot( k, color.rgb ).mul( cosAngle.oneMinus() ) ) ) ) ); + +} ); + +const luminance = ( + color, + luminanceCoefficients = vec3( ColorManagement.getLuminanceCoefficients( new Vector3() ) ) +) => dot( color, luminanceCoefficients ); + +const threshold = ( color, threshold ) => mix( vec3( 0.0 ), color, luminance( color ).sub( threshold ).max( 0 ) ); + +/** + * Color Decision List (CDL) v1.2 + * + * Compact representation of color grading information, defined by slope, offset, power, and + * saturation. The CDL should be typically be given input in a log space (such as LogC, ACEScc, + * or AgX Log), and will return output in the same space. Output may require clamping >=0. + * + * @param {vec4} color Input (-Infinity < input < +Infinity) + * @param {number | vec3} slope Slope (0 ≤ slope < +Infinity) + * @param {number | vec3} offset Offset (-Infinity < offset < +Infinity; typically -1 < offset < 1) + * @param {number | vec3} power Power (0 < power < +Infinity) + * @param {number} saturation Saturation (0 ≤ saturation < +Infinity; typically 0 ≤ saturation < 4) + * @param {vec3} luminanceCoefficients Luminance coefficients for saturation term, typically Rec. 709 + * @return Output, -Infinity < output < +Infinity + * + * References: + * - ASC CDL v1.2 + * - https://blender.stackexchange.com/a/55239/43930 + * - https://docs.acescentral.com/specifications/acescc/ + */ +const cdl = /*@__PURE__*/ Fn( ( [ + color, + slope = vec3( 1 ), + offset = vec3( 0 ), + power = vec3( 1 ), + saturation = float( 1 ), + // ASC CDL v1.2 explicitly requires Rec. 709 luminance coefficients. + luminanceCoefficients = vec3( ColorManagement.getLuminanceCoefficients( new Vector3(), LinearSRGBColorSpace ) ) +] ) => { + + // NOTE: The ASC CDL v1.2 defines a [0, 1] clamp on the slope+offset term, and another on the + // saturation term. Per the ACEScc specification and Filament, limits may be omitted to support + // values outside [0, 1], requiring a workaround for negative values in the power expression. + + const luma = color.rgb.dot( vec3( luminanceCoefficients ) ); + + const v = max$1( color.rgb.mul( slope ).add( offset ), 0.0 ).toVar(); + const pv = v.pow( power ).toVar(); + + If( v.r.greaterThan( 0.0 ), () => { v.r.assign( pv.r ); } ); // eslint-disable-line + If( v.g.greaterThan( 0.0 ), () => { v.g.assign( pv.g ); } ); // eslint-disable-line + If( v.b.greaterThan( 0.0 ), () => { v.b.assign( pv.b ); } ); // eslint-disable-line + + v.assign( luma.add( v.sub( luma ).mul( saturation ) ) ); + + return vec4( v.rgb, color.a ); + +} ); + +class PosterizeNode extends TempNode { + + static get type() { + + return 'PosterizeNode'; + + } + + constructor( sourceNode, stepsNode ) { + + super(); + + this.sourceNode = sourceNode; + this.stepsNode = stepsNode; + + } + + setup() { + + const { sourceNode, stepsNode } = this; + + return sourceNode.mul( stepsNode ).floor().div( stepsNode ); + + } + +} + +const posterize = /*@__PURE__*/ nodeProxy( PosterizeNode ); + +const _size = /*@__PURE__*/ new Vector2(); + +class PassTextureNode extends TextureNode { + + static get type() { + + return 'PassTextureNode'; + + } + + constructor( passNode, texture ) { + + super( texture ); + + this.passNode = passNode; + + this.setUpdateMatrix( false ); + + } + + setup( builder ) { + + if ( builder.object.isQuadMesh ) this.passNode.build( builder ); + + return super.setup( builder ); + + } + + clone() { + + return new this.constructor( this.passNode, this.value ); + + } + +} + +class PassMultipleTextureNode extends PassTextureNode { + + static get type() { + + return 'PassMultipleTextureNode'; + + } + + constructor( passNode, textureName, previousTexture = false ) { + + super( passNode, null ); + + this.textureName = textureName; + this.previousTexture = previousTexture; + + } + + updateTexture() { + + this.value = this.previousTexture ? this.passNode.getPreviousTexture( this.textureName ) : this.passNode.getTexture( this.textureName ); + + } + + setup( builder ) { + + this.updateTexture(); + + return super.setup( builder ); + + } + + clone() { + + return new this.constructor( this.passNode, this.textureName, this.previousTexture ); + + } + +} + +class PassNode extends TempNode { + + static get type() { + + return 'PassNode'; + + } + + constructor( scope, scene, camera, options = {} ) { + + super( 'vec4' ); + + this.scope = scope; + this.scene = scene; + this.camera = camera; + this.options = options; + + this._pixelRatio = 1; + this._width = 1; + this._height = 1; + + const depthTexture = new DepthTexture(); + depthTexture.isRenderTargetTexture = true; + //depthTexture.type = FloatType; + depthTexture.name = 'depth'; + + const renderTarget = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType, ...options, } ); + renderTarget.texture.name = 'output'; + renderTarget.depthTexture = depthTexture; + + this.renderTarget = renderTarget; + + this.updateBeforeType = NodeUpdateType.FRAME; + + this._textures = { + output: renderTarget.texture, + depth: depthTexture + }; + + this._textureNodes = {}; + this._linearDepthNodes = {}; + this._viewZNodes = {}; + + this._previousTextures = {}; + this._previousTextureNodes = {}; + + this._cameraNear = uniform( 0 ); + this._cameraFar = uniform( 0 ); + + this._mrt = null; + + this.isPassNode = true; + + } + + setMRT( mrt ) { + + this._mrt = mrt; + + return this; + + } + + getMRT() { + + return this._mrt; + + } + + isGlobal() { + + return true; + + } + + getTexture( name ) { + + let texture = this._textures[ name ]; + + if ( texture === undefined ) { + + const refTexture = this.renderTarget.texture; + + texture = refTexture.clone(); + texture.isRenderTargetTexture = true; + texture.name = name; + + this._textures[ name ] = texture; + + this.renderTarget.textures.push( texture ); + + } + + return texture; + + } + + getPreviousTexture( name ) { + + let texture = this._previousTextures[ name ]; + + if ( texture === undefined ) { + + texture = this.getTexture( name ).clone(); + texture.isRenderTargetTexture = true; + + this._previousTextures[ name ] = texture; + + } + + return texture; + + } + + toggleTexture( name ) { + + const prevTexture = this._previousTextures[ name ]; + + if ( prevTexture !== undefined ) { + + const texture = this._textures[ name ]; + + const index = this.renderTarget.textures.indexOf( texture ); + this.renderTarget.textures[ index ] = prevTexture; + + this._textures[ name ] = prevTexture; + this._previousTextures[ name ] = texture; + + this._textureNodes[ name ].updateTexture(); + this._previousTextureNodes[ name ].updateTexture(); + + } + + } + + getTextureNode( name = 'output' ) { + + let textureNode = this._textureNodes[ name ]; + + if ( textureNode === undefined ) { + + textureNode = nodeObject( new PassMultipleTextureNode( this, name ) ); + textureNode.updateTexture(); + this._textureNodes[ name ] = textureNode; + + } + + return textureNode; + + } + + getPreviousTextureNode( name = 'output' ) { + + let textureNode = this._previousTextureNodes[ name ]; + + if ( textureNode === undefined ) { + + if ( this._textureNodes[ name ] === undefined ) this.getTextureNode( name ); + + textureNode = nodeObject( new PassMultipleTextureNode( this, name, true ) ); + textureNode.updateTexture(); + this._previousTextureNodes[ name ] = textureNode; + + } + + return textureNode; + + } + + getViewZNode( name = 'depth' ) { + + let viewZNode = this._viewZNodes[ name ]; + + if ( viewZNode === undefined ) { + + const cameraNear = this._cameraNear; + const cameraFar = this._cameraFar; + + this._viewZNodes[ name ] = viewZNode = perspectiveDepthToViewZ( this.getTextureNode( name ), cameraNear, cameraFar ); + + } + + return viewZNode; + + } + + getLinearDepthNode( name = 'depth' ) { + + let linearDepthNode = this._linearDepthNodes[ name ]; + + if ( linearDepthNode === undefined ) { + + const cameraNear = this._cameraNear; + const cameraFar = this._cameraFar; + const viewZNode = this.getViewZNode( name ); + + // TODO: just if ( builder.camera.isPerspectiveCamera ) + + this._linearDepthNodes[ name ] = linearDepthNode = viewZToOrthographicDepth( viewZNode, cameraNear, cameraFar ); + + } + + return linearDepthNode; + + } + + setup( { renderer } ) { + + this.renderTarget.samples = this.options.samples === undefined ? renderer.samples : this.options.samples; + + // Disable MSAA for WebGL backend for now + if ( renderer.backend.isWebGLBackend === true ) { + + this.renderTarget.samples = 0; + + } + + this.renderTarget.depthTexture.isMultisampleRenderTargetTexture = this.renderTarget.samples > 1; + + return this.scope === PassNode.COLOR ? this.getTextureNode() : this.getLinearDepthNode(); + + } + + updateBefore( frame ) { + + const { renderer } = frame; + const { scene, camera } = this; + + this._pixelRatio = renderer.getPixelRatio(); + + const size = renderer.getSize( _size ); + + this.setSize( size.width, size.height ); + + const currentRenderTarget = renderer.getRenderTarget(); + const currentMRT = renderer.getMRT(); + + this._cameraNear.value = camera.near; + this._cameraFar.value = camera.far; + + for ( const name in this._previousTextures ) { + + this.toggleTexture( name ); + + } + + renderer.setRenderTarget( this.renderTarget ); + renderer.setMRT( this._mrt ); + + renderer.render( scene, camera ); + + renderer.setRenderTarget( currentRenderTarget ); + renderer.setMRT( currentMRT ); + + } + + setSize( width, height ) { + + this._width = width; + this._height = height; + + const effectiveWidth = this._width * this._pixelRatio; + const effectiveHeight = this._height * this._pixelRatio; + + this.renderTarget.setSize( effectiveWidth, effectiveHeight ); + + } + + setPixelRatio( pixelRatio ) { + + this._pixelRatio = pixelRatio; + + this.setSize( this._width, this._height ); + + } + + dispose() { + + this.renderTarget.dispose(); + + } + + +} + +PassNode.COLOR = 'color'; +PassNode.DEPTH = 'depth'; + +const pass = ( scene, camera, options ) => nodeObject( new PassNode( PassNode.COLOR, scene, camera, options ) ); +const passTexture = ( pass, texture ) => nodeObject( new PassTextureNode( pass, texture ) ); +const depthPass = ( scene, camera ) => nodeObject( new PassNode( PassNode.DEPTH, scene, camera ) ); + +class ToonOutlinePassNode extends PassNode { + + static get type() { + + return 'ToonOutlinePassNode'; + + } + + constructor( scene, camera, colorNode, thicknessNode, alphaNode ) { + + super( PassNode.COLOR, scene, camera ); + + this.colorNode = colorNode; + this.thicknessNode = thicknessNode; + this.alphaNode = alphaNode; + + this._materialCache = new WeakMap(); + + } + + updateBefore( frame ) { + + const { renderer } = frame; + + const currentRenderObjectFunction = renderer.getRenderObjectFunction(); + + renderer.setRenderObjectFunction( ( object, scene, camera, geometry, material, group, lightsNode, clippingContext ) => { + + // only render outline for supported materials + + if ( material.isMeshToonMaterial || material.isMeshToonNodeMaterial ) { + + if ( material.wireframe === false ) { + + const outlineMaterial = this._getOutlineMaterial( material ); + renderer.renderObject( object, scene, camera, geometry, outlineMaterial, group, lightsNode, clippingContext ); + + } + + } + + // default + + renderer.renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext ); + + } ); + + super.updateBefore( frame ); + + renderer.setRenderObjectFunction( currentRenderObjectFunction ); + + } + + _createMaterial() { + + const material = new NodeMaterial(); + material.isMeshToonOutlineMaterial = true; + material.name = 'Toon_Outline'; + material.side = BackSide; + + // vertex node + + const outlineNormal = normalLocal.negate(); + const mvp = cameraProjectionMatrix.mul( modelViewMatrix ); + + const ratio = float( 1.0 ); // TODO: support outline thickness ratio for each vertex + const pos = mvp.mul( vec4( positionLocal, 1.0 ) ); + const pos2 = mvp.mul( vec4( positionLocal.add( outlineNormal ), 1.0 ) ); + const norm = normalize( pos.sub( pos2 ) ); // NOTE: subtract pos2 from pos because BackSide objectNormal is negative + + material.vertexNode = pos.add( norm.mul( this.thicknessNode ).mul( pos.w ).mul( ratio ) ); + + // color node + + material.colorNode = vec4( this.colorNode, this.alphaNode ); + + return material; + + } + + _getOutlineMaterial( originalMaterial ) { + + let outlineMaterial = this._materialCache.get( originalMaterial ); + + if ( outlineMaterial === undefined ) { + + outlineMaterial = this._createMaterial(); + + this._materialCache.set( originalMaterial, outlineMaterial ); + + } + + return outlineMaterial; + + } + +} + +const toonOutlinePass = ( scene, camera, color = new Color( 0, 0, 0 ), thickness = 0.003, alpha = 1 ) => nodeObject( new ToonOutlinePassNode( scene, camera, nodeObject( color ), nodeObject( thickness ), nodeObject( alpha ) ) ); + +// exposure only + +const linearToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => { + + return color.mul( exposure ).clamp(); + +} ).setLayout( { + name: 'linearToneMapping', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' }, + { name: 'exposure', type: 'float' } + ] +} ); + +// source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf + +const reinhardToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => { + + color = color.mul( exposure ); + + return color.div( color.add( 1.0 ) ).clamp(); + +} ).setLayout( { + name: 'reinhardToneMapping', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' }, + { name: 'exposure', type: 'float' } + ] +} ); + +// source: http://filmicworlds.com/blog/filmic-tonemapping-operators/ + +const cineonToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => { + + // filmic operator by Jim Hejl and Richard Burgess-Dawson + color = color.mul( exposure ); + color = color.sub( 0.004 ).max( 0.0 ); + + const a = color.mul( color.mul( 6.2 ).add( 0.5 ) ); + const b = color.mul( color.mul( 6.2 ).add( 1.7 ) ).add( 0.06 ); + + return a.div( b ).pow( 2.2 ); + +} ).setLayout( { + name: 'cineonToneMapping', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' }, + { name: 'exposure', type: 'float' } + ] +} ); + +// source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs + +const RRTAndODTFit = /*@__PURE__*/ Fn( ( [ color ] ) => { + + const a = color.mul( color.add( 0.0245786 ) ).sub( 0.000090537 ); + const b = color.mul( color.add( 0.4329510 ).mul( 0.983729 ) ).add( 0.238081 ); + + return a.div( b ); + +} ); + +// source: https://github.com/selfshadow/ltc_code/blob/master/webgl/shaders/ltc/ltc_blit.fs + +const acesFilmicToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => { + + // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT + const ACESInputMat = mat3( + 0.59719, 0.35458, 0.04823, + 0.07600, 0.90834, 0.01566, + 0.02840, 0.13383, 0.83777 + ); + + // ODT_SAT => XYZ => D60_2_D65 => sRGB + const ACESOutputMat = mat3( + 1.60475, - 0.53108, - 0.07367, + - 0.10208, 1.10813, - 0.00605, + - 0.00327, - 0.07276, 1.07602 + ); + + color = color.mul( exposure ).div( 0.6 ); + + color = ACESInputMat.mul( color ); + + // Apply RRT and ODT + color = RRTAndODTFit( color ); + + color = ACESOutputMat.mul( color ); + + // Clamp to [0, 1] + return color.clamp(); + +} ).setLayout( { + name: 'acesFilmicToneMapping', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' }, + { name: 'exposure', type: 'float' } + ] +} ); + +const LINEAR_REC2020_TO_LINEAR_SRGB = /*@__PURE__*/ mat3( vec3( 1.6605, - 0.1246, - 0.0182 ), vec3( - 0.5876, 1.1329, - 0.1006 ), vec3( - 0.0728, - 0.0083, 1.1187 ) ); +const LINEAR_SRGB_TO_LINEAR_REC2020 = /*@__PURE__*/ mat3( vec3( 0.6274, 0.0691, 0.0164 ), vec3( 0.3293, 0.9195, 0.0880 ), vec3( 0.0433, 0.0113, 0.8956 ) ); + +const agxDefaultContrastApprox = /*@__PURE__*/ Fn( ( [ x_immutable ] ) => { + + const x = vec3( x_immutable ).toVar(); + const x2 = vec3( x.mul( x ) ).toVar(); + const x4 = vec3( x2.mul( x2 ) ).toVar(); + + return float( 15.5 ).mul( x4.mul( x2 ) ).sub( mul( 40.14, x4.mul( x ) ) ).add( mul( 31.96, x4 ).sub( mul( 6.868, x2.mul( x ) ) ).add( mul( 0.4298, x2 ).add( mul( 0.1191, x ).sub( 0.00232 ) ) ) ); + +} ); + +const agxToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => { + + const colortone = vec3( color ).toVar(); + const AgXInsetMatrix = mat3( vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) ); + const AgXOutsetMatrix = mat3( vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) ); + const AgxMinEv = float( - 12.47393 ); + const AgxMaxEv = float( 4.026069 ); + colortone.mulAssign( exposure ); + colortone.assign( LINEAR_SRGB_TO_LINEAR_REC2020.mul( colortone ) ); + colortone.assign( AgXInsetMatrix.mul( colortone ) ); + colortone.assign( max$1( colortone, 1e-10 ) ); + colortone.assign( log2( colortone ) ); + colortone.assign( colortone.sub( AgxMinEv ).div( AgxMaxEv.sub( AgxMinEv ) ) ); + colortone.assign( clamp( colortone, 0.0, 1.0 ) ); + colortone.assign( agxDefaultContrastApprox( colortone ) ); + colortone.assign( AgXOutsetMatrix.mul( colortone ) ); + colortone.assign( pow( max$1( vec3( 0.0 ), colortone ), vec3( 2.2 ) ) ); + colortone.assign( LINEAR_REC2020_TO_LINEAR_SRGB.mul( colortone ) ); + colortone.assign( clamp( colortone, 0.0, 1.0 ) ); + + return colortone; + +} ).setLayout( { + name: 'agxToneMapping', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' }, + { name: 'exposure', type: 'float' } + ] +} ); + +// https://modelviewer.dev/examples/tone-mapping + +const neutralToneMapping = /*@__PURE__*/ Fn( ( [ color, exposure ] ) => { + + const StartCompression = float( 0.8 - 0.04 ); + const Desaturation = float( 0.15 ); + + color = color.mul( exposure ); + + const x = min$1( color.r, min$1( color.g, color.b ) ); + const offset = select( x.lessThan( 0.08 ), x.sub( mul( 6.25, x.mul( x ) ) ), 0.04 ); + + color.subAssign( offset ); + + const peak = max$1( color.r, max$1( color.g, color.b ) ); + + If( peak.lessThan( StartCompression ), () => { + + return color; + + } ); + + const d = sub( 1, StartCompression ); + const newPeak = sub( 1, d.mul( d ).div( peak.add( d.sub( StartCompression ) ) ) ); + color.mulAssign( newPeak.div( peak ) ); + const g = sub( 1, div( 1, Desaturation.mul( peak.sub( newPeak ) ).add( 1 ) ) ); + + return mix( color, vec3( newPeak ), g ); + +} ).setLayout( { + name: 'neutralToneMapping', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' }, + { name: 'exposure', type: 'float' } + ] +} ); + +class CodeNode extends Node { + + static get type() { + + return 'CodeNode'; + + } + + constructor( code = '', includes = [], language = '' ) { + + super( 'code' ); + + this.isCodeNode = true; + + this.code = code; + this.language = language; + + this.includes = includes; + + } + + isGlobal() { + + return true; + + } + + setIncludes( includes ) { + + this.includes = includes; + + return this; + + } + + getIncludes( /*builder*/ ) { + + return this.includes; + + } + + generate( builder ) { + + const includes = this.getIncludes( builder ); + + for ( const include of includes ) { + + include.build( builder ); + + } + + const nodeCode = builder.getCodeFromNode( this, this.getNodeType( builder ) ); + nodeCode.code = this.code; + + return nodeCode.code; + + } + + serialize( data ) { + + super.serialize( data ); + + data.code = this.code; + data.language = this.language; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.code = data.code; + this.language = data.language; + + } + +} + +const code = /*@__PURE__*/ nodeProxy( CodeNode ); + +const js = ( src, includes ) => code( src, includes, 'js' ); +const wgsl = ( src, includes ) => code( src, includes, 'wgsl' ); +const glsl = ( src, includes ) => code( src, includes, 'glsl' ); + +class FunctionNode extends CodeNode { + + static get type() { + + return 'FunctionNode'; + + } + + constructor( code = '', includes = [], language = '' ) { + + super( code, includes, language ); + + } + + getNodeType( builder ) { + + return this.getNodeFunction( builder ).type; + + } + + getInputs( builder ) { + + return this.getNodeFunction( builder ).inputs; + + } + + getNodeFunction( builder ) { + + const nodeData = builder.getDataFromNode( this ); + + let nodeFunction = nodeData.nodeFunction; + + if ( nodeFunction === undefined ) { + + nodeFunction = builder.parser.parseFunction( this.code ); + + nodeData.nodeFunction = nodeFunction; + + } + + return nodeFunction; + + } + + generate( builder, output ) { + + super.generate( builder ); + + const nodeFunction = this.getNodeFunction( builder ); + + const name = nodeFunction.name; + const type = nodeFunction.type; + + const nodeCode = builder.getCodeFromNode( this, type ); + + if ( name !== '' ) { + + // use a custom property name + + nodeCode.name = name; + + } + + const propertyName = builder.getPropertyName( nodeCode ); + + const code = this.getNodeFunction( builder ).getCode( propertyName ); + + nodeCode.code = code + '\n'; + + if ( output === 'property' ) { + + return propertyName; + + } else { + + return builder.format( `${ propertyName }()`, type, output ); + + } + + } + +} + +const nativeFn = ( code, includes = [], language = '' ) => { + + for ( let i = 0; i < includes.length; i ++ ) { + + const include = includes[ i ]; + + // TSL Function: glslFn, wgslFn + + if ( typeof include === 'function' ) { + + includes[ i ] = include.functionNode; + + } + + } + + const functionNode = nodeObject( new FunctionNode( code, includes, language ) ); + + const fn = ( ...params ) => functionNode.call( ...params ); + fn.functionNode = functionNode; + + return fn; + +}; + +const glslFn = ( code, includes ) => nativeFn( code, includes, 'glsl' ); +const wgslFn = ( code, includes ) => nativeFn( code, includes, 'wgsl' ); + +class ScriptableValueNode extends Node { + + static get type() { + + return 'ScriptableValueNode'; + + } + + constructor( value = null ) { + + super(); + + this._value = value; + this._cache = null; + + this.inputType = null; + this.outpuType = null; + + this.events = new EventDispatcher(); + + this.isScriptableValueNode = true; + + } + + get isScriptableOutputNode() { + + return this.outputType !== null; + + } + + set value( val ) { + + if ( this._value === val ) return; + + if ( this._cache && this.inputType === 'URL' && this.value.value instanceof ArrayBuffer ) { + + URL.revokeObjectURL( this._cache ); + + this._cache = null; + + } + + this._value = val; + + this.events.dispatchEvent( { type: 'change' } ); + + this.refresh(); + + } + + get value() { + + return this._value; + + } + + refresh() { + + this.events.dispatchEvent( { type: 'refresh' } ); + + } + + getValue() { + + const value = this.value; + + if ( value && this._cache === null && this.inputType === 'URL' && value.value instanceof ArrayBuffer ) { + + this._cache = URL.createObjectURL( new Blob( [ value.value ] ) ); + + } else if ( value && value.value !== null && value.value !== undefined && ( + ( ( this.inputType === 'URL' || this.inputType === 'String' ) && typeof value.value === 'string' ) || + ( this.inputType === 'Number' && typeof value.value === 'number' ) || + ( this.inputType === 'Vector2' && value.value.isVector2 ) || + ( this.inputType === 'Vector3' && value.value.isVector3 ) || + ( this.inputType === 'Vector4' && value.value.isVector4 ) || + ( this.inputType === 'Color' && value.value.isColor ) || + ( this.inputType === 'Matrix3' && value.value.isMatrix3 ) || + ( this.inputType === 'Matrix4' && value.value.isMatrix4 ) + ) ) { + + return value.value; + + } + + return this._cache || value; + + } + + getNodeType( builder ) { + + return this.value && this.value.isNode ? this.value.getNodeType( builder ) : 'float'; + + } + + setup() { + + return this.value && this.value.isNode ? this.value : float(); + + } + + serialize( data ) { + + super.serialize( data ); + + if ( this.value !== null ) { + + if ( this.inputType === 'ArrayBuffer' ) { + + data.value = arrayBufferToBase64( this.value ); + + } else { + + data.value = this.value ? this.value.toJSON( data.meta ).uuid : null; + + } + + } else { + + data.value = null; + + } + + data.inputType = this.inputType; + data.outputType = this.outputType; + + } + + deserialize( data ) { + + super.deserialize( data ); + + let value = null; + + if ( data.value !== null ) { + + if ( data.inputType === 'ArrayBuffer' ) { + + value = base64ToArrayBuffer( data.value ); + + } else if ( data.inputType === 'Texture' ) { + + value = data.meta.textures[ data.value ]; + + } else { + + value = data.meta.nodes[ data.value ] || null; + + } + + } + + this.value = value; + + this.inputType = data.inputType; + this.outputType = data.outputType; + + } + +} + +const scriptableValue = /*@__PURE__*/ nodeProxy( ScriptableValueNode ); + +class Resources extends Map { + + get( key, callback = null, ...params ) { + + if ( this.has( key ) ) return super.get( key ); + + if ( callback !== null ) { + + const value = callback( ...params ); + this.set( key, value ); + return value; + + } + + } + +} + +class Parameters { + + constructor( scriptableNode ) { + + this.scriptableNode = scriptableNode; + + } + + get parameters() { + + return this.scriptableNode.parameters; + + } + + get layout() { + + return this.scriptableNode.getLayout(); + + } + + getInputLayout( id ) { + + return this.scriptableNode.getInputLayout( id ); + + } + + get( name ) { + + const param = this.parameters[ name ]; + const value = param ? param.getValue() : null; + + return value; + + } + +} + +const ScriptableNodeResources = new Resources(); + +class ScriptableNode extends Node { + + static get type() { + + return 'ScriptableNode'; + + } + + constructor( codeNode = null, parameters = {} ) { + + super(); + + this.codeNode = codeNode; + this.parameters = parameters; + + this._local = new Resources(); + this._output = scriptableValue(); + this._outputs = {}; + this._source = this.source; + this._method = null; + this._object = null; + this._value = null; + this._needsOutputUpdate = true; + + this.onRefresh = this.onRefresh.bind( this ); + + this.isScriptableNode = true; + + } + + get source() { + + return this.codeNode ? this.codeNode.code : ''; + + } + + setLocal( name, value ) { + + return this._local.set( name, value ); + + } + + getLocal( name ) { + + return this._local.get( name ); + + } + + onRefresh() { + + this._refresh(); + + } + + getInputLayout( id ) { + + for ( const element of this.getLayout() ) { + + if ( element.inputType && ( element.id === id || element.name === id ) ) { + + return element; + + } + + } + + } + + getOutputLayout( id ) { + + for ( const element of this.getLayout() ) { + + if ( element.outputType && ( element.id === id || element.name === id ) ) { + + return element; + + } + + } + + } + + setOutput( name, value ) { + + const outputs = this._outputs; + + if ( outputs[ name ] === undefined ) { + + outputs[ name ] = scriptableValue( value ); + + } else { + + outputs[ name ].value = value; + + } + + return this; + + } + + getOutput( name ) { + + return this._outputs[ name ]; + + } + + getParameter( name ) { + + return this.parameters[ name ]; + + } + + setParameter( name, value ) { + + const parameters = this.parameters; + + if ( value && value.isScriptableNode ) { + + this.deleteParameter( name ); + + parameters[ name ] = value; + parameters[ name ].getDefaultOutput().events.addEventListener( 'refresh', this.onRefresh ); + + } else if ( value && value.isScriptableValueNode ) { + + this.deleteParameter( name ); + + parameters[ name ] = value; + parameters[ name ].events.addEventListener( 'refresh', this.onRefresh ); + + } else if ( parameters[ name ] === undefined ) { + + parameters[ name ] = scriptableValue( value ); + parameters[ name ].events.addEventListener( 'refresh', this.onRefresh ); + + } else { + + parameters[ name ].value = value; + + } + + return this; + + } + + getValue() { + + return this.getDefaultOutput().getValue(); + + } + + deleteParameter( name ) { + + let valueNode = this.parameters[ name ]; + + if ( valueNode ) { + + if ( valueNode.isScriptableNode ) valueNode = valueNode.getDefaultOutput(); + + valueNode.events.removeEventListener( 'refresh', this.onRefresh ); + + } + + return this; + + } + + clearParameters() { + + for ( const name of Object.keys( this.parameters ) ) { + + this.deleteParameter( name ); + + } + + this.needsUpdate = true; + + return this; + + } + + call( name, ...params ) { + + const object = this.getObject(); + const method = object[ name ]; + + if ( typeof method === 'function' ) { + + return method( ...params ); + + } + + } + + async callAsync( name, ...params ) { + + const object = this.getObject(); + const method = object[ name ]; + + if ( typeof method === 'function' ) { + + return method.constructor.name === 'AsyncFunction' ? await method( ...params ) : method( ...params ); + + } + + } + + getNodeType( builder ) { + + return this.getDefaultOutputNode().getNodeType( builder ); + + } + + refresh( output = null ) { + + if ( output !== null ) { + + this.getOutput( output ).refresh(); + + } else { + + this._refresh(); + + } + + } + + getObject() { + + if ( this.needsUpdate ) this.dispose(); + if ( this._object !== null ) return this._object; + + // + + const refresh = () => this.refresh(); + const setOutput = ( id, value ) => this.setOutput( id, value ); + + const parameters = new Parameters( this ); + + const THREE = ScriptableNodeResources.get( 'THREE' ); + const TSL = ScriptableNodeResources.get( 'TSL' ); + + const method = this.getMethod( this.codeNode ); + const params = [ parameters, this._local, ScriptableNodeResources, refresh, setOutput, THREE, TSL ]; + + this._object = method( ...params ); + + const layout = this._object.layout; + + if ( layout ) { + + if ( layout.cache === false ) { + + this._local.clear(); + + } + + // default output + this._output.outputType = layout.outputType || null; + + if ( Array.isArray( layout.elements ) ) { + + for ( const element of layout.elements ) { + + const id = element.id || element.name; + + if ( element.inputType ) { + + if ( this.getParameter( id ) === undefined ) this.setParameter( id, null ); + + this.getParameter( id ).inputType = element.inputType; + + } + + if ( element.outputType ) { + + if ( this.getOutput( id ) === undefined ) this.setOutput( id, null ); + + this.getOutput( id ).outputType = element.outputType; + + } + + } + + } + + } + + return this._object; + + } + + deserialize( data ) { + + super.deserialize( data ); + + for ( const name in this.parameters ) { + + let valueNode = this.parameters[ name ]; + + if ( valueNode.isScriptableNode ) valueNode = valueNode.getDefaultOutput(); + + valueNode.events.addEventListener( 'refresh', this.onRefresh ); + + } + + } + + getLayout() { + + return this.getObject().layout; + + } + + getDefaultOutputNode() { + + const output = this.getDefaultOutput().value; + + if ( output && output.isNode ) { + + return output; + + } + + return float(); + + } + + getDefaultOutput() { + + return this._exec()._output; + + } + + getMethod() { + + if ( this.needsUpdate ) this.dispose(); + if ( this._method !== null ) return this._method; + + // + + const parametersProps = [ 'parameters', 'local', 'global', 'refresh', 'setOutput', 'THREE', 'TSL' ]; + const interfaceProps = [ 'layout', 'init', 'main', 'dispose' ]; + + const properties = interfaceProps.join( ', ' ); + const declarations = 'var ' + properties + '; var output = {};\n'; + const returns = '\nreturn { ...output, ' + properties + ' };'; + + const code = declarations + this.codeNode.code + returns; + + // + + this._method = new Function( ...parametersProps, code ); + + return this._method; + + } + + dispose() { + + if ( this._method === null ) return; + + if ( this._object && typeof this._object.dispose === 'function' ) { + + this._object.dispose(); + + } + + this._method = null; + this._object = null; + this._source = null; + this._value = null; + this._needsOutputUpdate = true; + this._output.value = null; + this._outputs = {}; + + } + + setup() { + + return this.getDefaultOutputNode(); + + } + + getCacheKey( force ) { + + const values = [ hashString( this.source ), this.getDefaultOutputNode().getCacheKey( force ) ]; + + for ( const param in this.parameters ) { + + values.push( this.parameters[ param ].getCacheKey( force ) ); + + } + + return hashArray( values ); + + } + + set needsUpdate( value ) { + + if ( value === true ) this.dispose(); + + } + + get needsUpdate() { + + return this.source !== this._source; + + } + + _exec() { + + if ( this.codeNode === null ) return this; + + if ( this._needsOutputUpdate === true ) { + + this._value = this.call( 'main' ); + + this._needsOutputUpdate = false; + + } + + this._output.value = this._value; + + return this; + + } + + _refresh() { + + this.needsUpdate = true; + + this._exec(); + + this._output.refresh(); + + } + +} + +const scriptable = /*@__PURE__*/ nodeProxy( ScriptableNode ); + +class FogNode extends Node { + + static get type() { + + return 'FogNode'; + + } + + constructor( colorNode, factorNode ) { + + super( 'float' ); + + this.isFogNode = true; + + this.colorNode = colorNode; + this.factorNode = factorNode; + + } + + getViewZNode( builder ) { + + let viewZ; + + const getViewZ = builder.context.getViewZ; + + if ( getViewZ !== undefined ) { + + viewZ = getViewZ( this ); + + } + + return ( viewZ || positionView.z ).negate(); + + } + + setup() { + + return this.factorNode; + + } + +} + +const fog = /*@__PURE__*/ nodeProxy( FogNode ); + +class FogRangeNode extends FogNode { + + static get type() { + + return 'FogRangeNode'; + + } + + constructor( colorNode, nearNode, farNode ) { + + super( colorNode ); + + this.isFogRangeNode = true; + + this.nearNode = nearNode; + this.farNode = farNode; + + } + + setup( builder ) { + + const viewZ = this.getViewZNode( builder ); + + return smoothstep( this.nearNode, this.farNode, viewZ ); + + } + +} + +const rangeFog = /*@__PURE__*/ nodeProxy( FogRangeNode ); + +class FogExp2Node extends FogNode { + + static get type() { + + return 'FogExp2Node'; + + } + + constructor( colorNode, densityNode ) { + + super( colorNode ); + + this.isFogExp2Node = true; + + this.densityNode = densityNode; + + } + + setup( builder ) { + + const viewZ = this.getViewZNode( builder ); + const density = this.densityNode; + + return density.mul( density, viewZ, viewZ ).negate().exp().oneMinus(); + + } + +} + +const densityFog = /*@__PURE__*/ nodeProxy( FogExp2Node ); + +let min = null; +let max = null; + +class RangeNode extends Node { + + static get type() { + + return 'RangeNode'; + + } + + constructor( minNode = float(), maxNode = float() ) { + + super(); + + this.minNode = minNode; + this.maxNode = maxNode; + + } + + getVectorLength( builder ) { + + const minLength = builder.getTypeLength( getValueType( this.minNode.value ) ); + const maxLength = builder.getTypeLength( getValueType( this.maxNode.value ) ); + + return minLength > maxLength ? minLength : maxLength; + + } + + getNodeType( builder ) { + + return builder.object.count > 1 ? builder.getTypeFromLength( this.getVectorLength( builder ) ) : 'float'; + + } + + setup( builder ) { + + const object = builder.object; + + let output = null; + + if ( object.count > 1 ) { + + const minValue = this.minNode.value; + const maxValue = this.maxNode.value; + + const minLength = builder.getTypeLength( getValueType( minValue ) ); + const maxLength = builder.getTypeLength( getValueType( maxValue ) ); + + min = min || new Vector4(); + max = max || new Vector4(); + + min.setScalar( 0 ); + max.setScalar( 0 ); + + if ( minLength === 1 ) min.setScalar( minValue ); + else if ( minValue.isColor ) min.set( minValue.r, minValue.g, minValue.b ); + else min.set( minValue.x, minValue.y, minValue.z || 0, minValue.w || 0 ); + + if ( maxLength === 1 ) max.setScalar( maxValue ); + else if ( maxValue.isColor ) max.set( maxValue.r, maxValue.g, maxValue.b ); + else max.set( maxValue.x, maxValue.y, maxValue.z || 0, maxValue.w || 0 ); + + const stride = 4; + + const length = stride * object.count; + const array = new Float32Array( length ); + + for ( let i = 0; i < length; i ++ ) { + + const index = i % stride; + + const minElementValue = min.getComponent( index ); + const maxElementValue = max.getComponent( index ); + + array[ i ] = MathUtils.lerp( minElementValue, maxElementValue, Math.random() ); + + } + + const nodeType = this.getNodeType( builder ); + + if ( object.count <= 4096 ) { + + output = buffer( array, 'vec4', object.count ).element( instanceIndex ).convert( nodeType ); + + } else { + + // TODO: Improve anonymous buffer attribute creation removing this part + const bufferAttribute = new InstancedBufferAttribute( array, 4 ); + builder.geometry.setAttribute( '__range' + this.id, bufferAttribute ); + + output = instancedBufferAttribute( bufferAttribute ).convert( nodeType ); + + } + + } else { + + output = float( 0 ); + + } + + return output; + + } + +} + +const range = /*@__PURE__*/ nodeProxy( RangeNode ); + +class ComputeBuiltinNode extends Node { + + static get type() { + + return 'ComputeBuiltinNode'; + + } + + constructor( builtinName, nodeType ) { + + super( nodeType ); + + this._builtinName = builtinName; + + } + + getHash( builder ) { + + return this.getBuiltinName( builder ); + + } + + getNodeType( /*builder*/ ) { + + return this.nodeType; + + } + + setBuiltinName( builtinName ) { + + this._builtinName = builtinName; + + return this; + + } + + getBuiltinName( /*builder*/ ) { + + return this._builtinName; + + } + + hasBuiltin( builder ) { + + builder.hasBuiltin( this._builtinName ); + + } + + generate( builder, output ) { + + const builtinName = this.getBuiltinName( builder ); + const nodeType = this.getNodeType( builder ); + + if ( builder.shaderStage === 'compute' ) { + + return builder.format( builtinName, nodeType, output ); + + } else { + + console.warn( `ComputeBuiltinNode: Compute built-in value ${builtinName} can not be accessed in the ${builder.shaderStage} stage` ); + return builder.generateConst( nodeType ); + + } + + } + + serialize( data ) { + + super.serialize( data ); + + data.global = this.global; + data._builtinName = this._builtinName; + + } + + deserialize( data ) { + + super.deserialize( data ); + + this.global = data.global; + this._builtinName = data._builtinName; + + } + +} + +const computeBuiltin = ( name, nodeType ) => nodeObject( new ComputeBuiltinNode( name, nodeType ) ); + +const numWorkgroups = /*@__PURE__*/ computeBuiltin( 'numWorkgroups', 'uvec3' ); +const workgroupId = /*@__PURE__*/ computeBuiltin( 'workgroupId', 'uvec3' ); +const localId = /*@__PURE__*/ computeBuiltin( 'localId', 'uvec3' ); +const subgroupSize = /*@__PURE__*/ computeBuiltin( 'subgroupSize', 'uint' ); + +class BarrierNode extends Node { + + constructor( scope ) { + + super(); + + this.scope = scope; + + } + + generate( builder ) { + + const { scope } = this; + const { renderer } = builder; + + if ( renderer.backend.isWebGLBackend === true ) { + + builder.addFlowCode( `\t// ${scope}Barrier \n` ); + + } else { + + builder.addLineFlowCode( `${scope}Barrier()`, this ); + + } + + } + +} + +const barrier = nodeProxy( BarrierNode ); + +const workgroupBarrier = () => barrier( 'workgroup' ).append(); +const storageBarrier = () => barrier( 'storage' ).append(); +const textureBarrier = () => barrier( 'texture' ).append(); + +class WorkgroupInfoElementNode extends ArrayElementNode { + + constructor( workgroupInfoNode, indexNode ) { + + super( workgroupInfoNode, indexNode ); + + this.isWorkgroupInfoElementNode = true; + + } + + generate( builder, output ) { + + let snippet; + + const isAssignContext = builder.context.assign; + snippet = super.generate( builder ); + + if ( isAssignContext !== true ) { + + const type = this.getNodeType( builder ); + + snippet = builder.format( snippet, type, output ); + + } + + // TODO: Possibly activate clip distance index on index access rather than from clipping context + + return snippet; + + } + +} + + +class WorkgroupInfoNode extends Node { + + constructor( scope, bufferType, bufferCount = 0 ) { + + super( bufferType ); + + this.bufferType = bufferType; + this.bufferCount = bufferCount; + + this.isWorkgroupInfoNode = true; + + this.scope = scope; + + } + + label( name ) { + + this.name = name; + + return this; + + } + + getHash() { + + return this.uuid; + + } + + setScope( scope ) { + + this.scope = scope; + + return this; + + } + + getInputType( /*builder*/ ) { + + return `${this.scope}Array`; + + } + + element( indexNode ) { + + return nodeObject( new WorkgroupInfoElementNode( this, indexNode ) ); + + } + + generate( builder ) { + + return builder.getScopedArray( this.name || `${this.scope}Array_${this.id}`, this.scope.toLowerCase(), this.bufferType, this.bufferCount ); + + } + +} + +const workgroupArray = ( type, count ) => nodeObject( new WorkgroupInfoNode( 'Workgroup', type, count ) ); + +class AtomicFunctionNode extends TempNode { + + static get type() { + + return 'AtomicFunctionNode'; + + } + + constructor( method, pointerNode, valueNode, storeNode = null ) { + + super( 'uint' ); + + this.method = method; + + this.pointerNode = pointerNode; + this.valueNode = valueNode; + this.storeNode = storeNode; + + } + + getInputType( builder ) { + + return this.pointerNode.getNodeType( builder ); + + } + + getNodeType( builder ) { + + return this.getInputType( builder ); + + } + + generate( builder ) { + + const method = this.method; + + const type = this.getNodeType( builder ); + const inputType = this.getInputType( builder ); + + const a = this.pointerNode; + const b = this.valueNode; + + const params = []; + + params.push( `&${ a.build( builder, inputType ) }` ); + params.push( b.build( builder, inputType ) ); + + const methodSnippet = `${ builder.getMethod( method, type ) }( ${params.join( ', ' )} )`; + + if ( this.storeNode !== null ) { + + const varSnippet = this.storeNode.build( builder, inputType ); + + builder.addLineFlowCode( `${varSnippet} = ${methodSnippet}`, this ); + + } else { + + builder.addLineFlowCode( methodSnippet, this ); + + } + + } + +} + +AtomicFunctionNode.ATOMIC_LOAD = 'atomicLoad'; +AtomicFunctionNode.ATOMIC_STORE = 'atomicStore'; +AtomicFunctionNode.ATOMIC_ADD = 'atomicAdd'; +AtomicFunctionNode.ATOMIC_SUB = 'atomicSub'; +AtomicFunctionNode.ATOMIC_MAX = 'atomicMax'; +AtomicFunctionNode.ATOMIC_MIN = 'atomicMin'; +AtomicFunctionNode.ATOMIC_AND = 'atomicAnd'; +AtomicFunctionNode.ATOMIC_OR = 'atomicOr'; +AtomicFunctionNode.ATOMIC_XOR = 'atomicXor'; + +const atomicNode = nodeProxy( AtomicFunctionNode ); + +const atomicFunc = ( method, pointerNode, valueNode, storeNode ) => { + + const node = atomicNode( method, pointerNode, valueNode, storeNode ); + node.append(); + + return node; + +}; + +const atomicStore = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_STORE, pointerNode, valueNode, storeNode ); +const atomicAdd = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_ADD, pointerNode, valueNode, storeNode ); +const atomicSub = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_SUB, pointerNode, valueNode, storeNode ); +const atomicMax = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_MAX, pointerNode, valueNode, storeNode ); +const atomicMin = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_MIN, pointerNode, valueNode, storeNode ); +const atomicAnd = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_AND, pointerNode, valueNode, storeNode ); +const atomicOr = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_OR, pointerNode, valueNode, storeNode ); +const atomicXor = ( pointerNode, valueNode, storeNode = null ) => atomicFunc( AtomicFunctionNode.ATOMIC_XOR, pointerNode, valueNode, storeNode ); + +let uniformsLib; + +function getLightData( light ) { + + uniformsLib = uniformsLib || new WeakMap(); + + let uniforms = uniformsLib.get( light ); + + if ( uniforms === undefined ) uniformsLib.set( light, uniforms = {} ); + + return uniforms; + +} + +function lightShadowMatrix( light ) { + + const data = getLightData( light ); + + return data.shadowMatrix || ( data.shadowMatrix = uniform( 'mat4' ).setGroup( renderGroup ).onRenderUpdate( () => { + + light.shadow.updateMatrices( light ); + + return light.shadow.matrix; + + } ) ); + +} + +function lightProjectionUV( light ) { + + const data = getLightData( light ); + + if ( data.projectionUV === undefined ) { + + const spotLightCoord = lightShadowMatrix( light ).mul( positionWorld ); + + data.projectionUV = spotLightCoord.xyz.div( spotLightCoord.w ); + + + } + + return data.projectionUV; + +} + +function lightPosition( light ) { + + const data = getLightData( light ); + + return data.position || ( data.position = uniform( new Vector3() ).setGroup( renderGroup ).onRenderUpdate( ( _, self ) => self.value.setFromMatrixPosition( light.matrixWorld ) ) ); + +} + +function lightTargetPosition( light ) { + + const data = getLightData( light ); + + return data.targetPosition || ( data.targetPosition = uniform( new Vector3() ).setGroup( renderGroup ).onRenderUpdate( ( _, self ) => self.value.setFromMatrixPosition( light.target.matrixWorld ) ) ); + +} + +function lightViewPosition( light ) { + + const data = getLightData( light ); + + return data.viewPosition || ( data.viewPosition = uniform( new Vector3() ).setGroup( renderGroup ).onRenderUpdate( ( { camera }, self ) => { + + self.value = self.value || new Vector3(); + self.value.setFromMatrixPosition( light.matrixWorld ); + + self.value.applyMatrix4( camera.matrixWorldInverse ); + + } ) ); + +} + +const lightTargetDirection = ( light ) => cameraViewMatrix.transformDirection( lightPosition( light ).sub( lightTargetPosition( light ) ) ); + +const sortLights = ( lights ) => { + + return lights.sort( ( a, b ) => a.id - b.id ); + +}; + +const getLightNodeById = ( id, lightNodes ) => { + + for ( const lightNode of lightNodes ) { + + if ( lightNode.isAnalyticLightNode && lightNode.light.id === id ) { + + return lightNode; + + } + + } + + return null; + +}; + +const _lightsNodeRef = /*@__PURE__*/ new WeakMap(); + +class LightsNode extends Node { + + static get type() { + + return 'LightsNode'; + + } + + constructor() { + + super( 'vec3' ); + + this.totalDiffuseNode = vec3().toVar( 'totalDiffuse' ); + this.totalSpecularNode = vec3().toVar( 'totalSpecular' ); + + this.outgoingLightNode = vec3().toVar( 'outgoingLight' ); + + this._lights = []; + + this._lightNodes = null; + this._lightNodesHash = null; + + this.global = true; + + } + + getHash( builder ) { + + if ( this._lightNodesHash === null ) { + + if ( this._lightNodes === null ) this.setupLightsNode( builder ); + + const hash = []; + + for ( const lightNode of this._lightNodes ) { + + hash.push( lightNode.getSelf().getHash() ); + + } + + this._lightNodesHash = 'lights-' + hash.join( ',' ); + + } + + return this._lightNodesHash; + + } + + analyze( builder ) { + + const properties = builder.getDataFromNode( this ); + + for ( const node of properties.nodes ) { + + node.build( builder ); + + } + + } + + setupLightsNode( builder ) { + + const lightNodes = []; + + const previousLightNodes = this._lightNodes; + + const lights = sortLights( this._lights ); + const nodeLibrary = builder.renderer.library; + + for ( const light of lights ) { + + if ( light.isNode ) { + + lightNodes.push( nodeObject( light ) ); + + } else { + + let lightNode = null; + + if ( previousLightNodes !== null ) { + + lightNode = getLightNodeById( light.id, previousLightNodes ); // resuse existing light node + + } + + if ( lightNode === null ) { + + const lightNodeClass = nodeLibrary.getLightNodeClass( light.constructor ); + + if ( lightNodeClass === null ) { + + console.warn( `LightsNode.setupNodeLights: Light node not found for ${ light.constructor.name }` ); + continue; + + } + + let lightNode = null; + + if ( ! _lightsNodeRef.has( light ) ) { + + lightNode = nodeObject( new lightNodeClass( light ) ); + _lightsNodeRef.set( light, lightNode ); + + } else { + + lightNode = _lightsNodeRef.get( light ); + + } + + lightNodes.push( lightNode ); + + } + + } + + } + + this._lightNodes = lightNodes; + + } + + setupLights( builder, lightNodes ) { + + for ( const lightNode of lightNodes ) { + + lightNode.build( builder ); + + } + + } + + setup( builder ) { + + if ( this._lightNodes === null ) this.setupLightsNode( builder ); + + const context = builder.context; + const lightingModel = context.lightingModel; + + let outgoingLightNode = this.outgoingLightNode; + + if ( lightingModel ) { + + const { _lightNodes, totalDiffuseNode, totalSpecularNode } = this; + + context.outgoingLight = outgoingLightNode; + + const stack = builder.addStack(); + + // + + const properties = builder.getDataFromNode( this ); + properties.nodes = stack.nodes; + + // + + lightingModel.start( context, stack, builder ); + + // lights + + this.setupLights( builder, _lightNodes ); + + // + + lightingModel.indirect( context, stack, builder ); + + // + + const { backdrop, backdropAlpha } = context; + const { directDiffuse, directSpecular, indirectDiffuse, indirectSpecular } = context.reflectedLight; + + let totalDiffuse = directDiffuse.add( indirectDiffuse ); + + if ( backdrop !== null ) { + + if ( backdropAlpha !== null ) { + + totalDiffuse = vec3( backdropAlpha.mix( totalDiffuse, backdrop ) ); + + } else { + + totalDiffuse = vec3( backdrop ); + + } + + context.material.transparent = true; + + } + + totalDiffuseNode.assign( totalDiffuse ); + totalSpecularNode.assign( directSpecular.add( indirectSpecular ) ); + + outgoingLightNode.assign( totalDiffuseNode.add( totalSpecularNode ) ); + + // + + lightingModel.finish( context, stack, builder ); + + // + + outgoingLightNode = outgoingLightNode.bypass( builder.removeStack() ); + + } + + return outgoingLightNode; + + } + + setLights( lights ) { + + this._lights = lights; + + this._lightNodes = null; + this._lightNodesHash = null; + + return this; + + } + + getLights() { + + return this._lights; + + } + + get hasLights() { + + return this._lights.length > 0; + + } + +} + +const lights = ( lights = [] ) => nodeObject( new LightsNode() ).setLights( lights ); + +const shadowMaterialLib = /*@__PURE__*/ new WeakMap(); +const shadowWorldPosition = /*@__PURE__*/ vec3().toVar( 'shadowWorldPosition' ); + +const linearDistance = /*@__PURE__*/ Fn( ( [ position, cameraNear, cameraFar ] ) => { + + let dist = positionWorld.sub( position ).length(); + dist = dist.sub( cameraNear ).div( cameraFar.sub( cameraNear ) ); + dist = dist.saturate(); // clamp to [ 0, 1 ] + + return dist; + +} ); + +const linearShadowDistance = ( light ) => { + + const camera = light.shadow.camera; + + const nearDistance = reference( 'near', 'float', camera ).setGroup( renderGroup ); + const farDistance = reference( 'far', 'float', camera ).setGroup( renderGroup ); + + const referencePosition = objectPosition( light ); + + return linearDistance( referencePosition, nearDistance, farDistance ); + +}; + +const getShadowMaterial = ( light ) => { + + let material = shadowMaterialLib.get( light ); + + if ( material === undefined ) { + + const depthNode = light.isPointLight ? linearShadowDistance( light ) : null; + + material = new NodeMaterial(); + material.colorNode = vec4( 0, 0, 0, 1 ); + material.depthNode = depthNode; + material.isShadowNodeMaterial = true; // Use to avoid other overrideMaterial override material.colorNode unintentionally when using material.shadowNode + material.blending = NoBlending; + material.name = 'ShadowMaterial'; + + shadowMaterialLib.set( light, material ); + + } + + return material; + +}; + +const BasicShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord } ) => { + + return texture( depthTexture, shadowCoord.xy ).compare( shadowCoord.z ); + +} ); + +const PCFShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, shadow } ) => { + + const depthCompare = ( uv, compare ) => texture( depthTexture, uv ).compare( compare ); + + const mapSize = reference( 'mapSize', 'vec2', shadow ).setGroup( renderGroup ); + const radius = reference( 'radius', 'float', shadow ).setGroup( renderGroup ); + + const texelSize = vec2( 1 ).div( mapSize ); + const dx0 = texelSize.x.negate().mul( radius ); + const dy0 = texelSize.y.negate().mul( radius ); + const dx1 = texelSize.x.mul( radius ); + const dy1 = texelSize.y.mul( radius ); + const dx2 = dx0.div( 2 ); + const dy2 = dy0.div( 2 ); + const dx3 = dx1.div( 2 ); + const dy3 = dy1.div( 2 ); + + return add( + depthCompare( shadowCoord.xy.add( vec2( dx0, dy0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( 0, dy0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx1, dy0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx2, dy2 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( 0, dy2 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx3, dy2 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx0, 0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx2, 0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy, shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx3, 0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx1, 0 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx2, dy3 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( 0, dy3 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx3, dy3 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx0, dy1 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( 0, dy1 ) ), shadowCoord.z ), + depthCompare( shadowCoord.xy.add( vec2( dx1, dy1 ) ), shadowCoord.z ) + ).mul( 1 / 17 ); + +} ); + +const PCFSoftShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord, shadow } ) => { + + const depthCompare = ( uv, compare ) => texture( depthTexture, uv ).compare( compare ); + + const mapSize = reference( 'mapSize', 'vec2', shadow ).setGroup( renderGroup ); + + const texelSize = vec2( 1 ).div( mapSize ); + const dx = texelSize.x; + const dy = texelSize.y; + + const uv = shadowCoord.xy; + const f = fract( uv.mul( mapSize ).add( 0.5 ) ); + uv.subAssign( f.mul( texelSize ) ); + + return add( + depthCompare( uv, shadowCoord.z ), + depthCompare( uv.add( vec2( dx, 0 ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( 0, dy ) ), shadowCoord.z ), + depthCompare( uv.add( texelSize ), shadowCoord.z ), + mix( + depthCompare( uv.add( vec2( dx.negate(), 0 ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( dx.mul( 2 ), 0 ) ), shadowCoord.z ), + f.x + ), + mix( + depthCompare( uv.add( vec2( dx.negate(), dy ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( dx.mul( 2 ), dy ) ), shadowCoord.z ), + f.x + ), + mix( + depthCompare( uv.add( vec2( 0, dy.negate() ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( 0, dy.mul( 2 ) ) ), shadowCoord.z ), + f.y + ), + mix( + depthCompare( uv.add( vec2( dx, dy.negate() ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( dx, dy.mul( 2 ) ) ), shadowCoord.z ), + f.y + ), + mix( + mix( + depthCompare( uv.add( vec2( dx.negate(), dy.negate() ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( dx.mul( 2 ), dy.negate() ) ), shadowCoord.z ), + f.x + ), + mix( + depthCompare( uv.add( vec2( dx.negate(), dy.mul( 2 ) ) ), shadowCoord.z ), + depthCompare( uv.add( vec2( dx.mul( 2 ), dy.mul( 2 ) ) ), shadowCoord.z ), + f.x + ), + f.y + ) + ).mul( 1 / 9 ); + +} ); + +// VSM + +const VSMShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, shadowCoord } ) => { + + const occlusion = float( 1 ).toVar(); + + const distribution = texture( depthTexture ).uv( shadowCoord.xy ).rg; + + const hardShadow = step( shadowCoord.z, distribution.x ); + + If( hardShadow.notEqual( float( 1.0 ) ), () => { + + const distance = shadowCoord.z.sub( distribution.x ); + const variance = max$1( 0, distribution.y.mul( distribution.y ) ); + let softnessProbability = variance.div( variance.add( distance.mul( distance ) ) ); // Chebeyshevs inequality + softnessProbability = clamp( sub( softnessProbability, 0.3 ).div( 0.95 - 0.3 ) ); + occlusion.assign( clamp( max$1( hardShadow, softnessProbability ) ) ); + + } ); + + return occlusion; + +} ); + +const VSMPassVertical = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPass } ) => { + + const mean = float( 0 ).toVar(); + const squaredMean = float( 0 ).toVar(); + + const uvStride = samples.lessThanEqual( float( 1 ) ).select( float( 0 ), float( 2 ).div( samples.sub( 1 ) ) ); + const uvStart = samples.lessThanEqual( float( 1 ) ).select( float( 0 ), float( - 1 ) ); + + Loop( { start: int( 0 ), end: int( samples ), type: 'int', condition: '<' }, ( { i } ) => { + + const uvOffset = uvStart.add( float( i ).mul( uvStride ) ); + + const depth = shadowPass.uv( add( screenCoordinate.xy, vec2( 0, uvOffset ).mul( radius ) ).div( size ) ).x; + mean.addAssign( depth ); + squaredMean.addAssign( depth.mul( depth ) ); + + } ); + + mean.divAssign( samples ); + squaredMean.divAssign( samples ); + + const std_dev = sqrt( squaredMean.sub( mean.mul( mean ) ) ); + return vec2( mean, std_dev ); + +} ); + +const VSMPassHorizontal = /*@__PURE__*/ Fn( ( { samples, radius, size, shadowPass } ) => { + + const mean = float( 0 ).toVar(); + const squaredMean = float( 0 ).toVar(); + + const uvStride = samples.lessThanEqual( float( 1 ) ).select( float( 0 ), float( 2 ).div( samples.sub( 1 ) ) ); + const uvStart = samples.lessThanEqual( float( 1 ) ).select( float( 0 ), float( - 1 ) ); + + Loop( { start: int( 0 ), end: int( samples ), type: 'int', condition: '<' }, ( { i } ) => { + + const uvOffset = uvStart.add( float( i ).mul( uvStride ) ); + + const distribution = shadowPass.uv( add( screenCoordinate.xy, vec2( uvOffset, 0 ).mul( radius ) ).div( size ) ); + mean.addAssign( distribution.x ); + squaredMean.addAssign( add( distribution.y.mul( distribution.y ), distribution.x.mul( distribution.x ) ) ); + + } ); + + mean.divAssign( samples ); + squaredMean.divAssign( samples ); + + const std_dev = sqrt( squaredMean.sub( mean.mul( mean ) ) ); + return vec2( mean, std_dev ); + +} ); + +const _shadowFilterLib = [ BasicShadowFilter, PCFShadowFilter, PCFSoftShadowFilter, VSMShadowFilter ]; + +// + +const _quadMesh$1 = /*@__PURE__*/ new QuadMesh(); + +class ShadowNode extends Node { + + static get type() { + + return 'ShadowNode'; + + } + + constructor( light, shadow = null ) { + + super(); + + this.light = light; + this.shadow = shadow || light.shadow; + + this.shadowMap = null; + + this.vsmShadowMapVertical = null; + this.vsmShadowMapHorizontal = null; + + this.vsmMaterialVertical = null; + this.vsmMaterialHorizontal = null; + + this.updateBeforeType = NodeUpdateType.RENDER; + this._node = null; + + this.isShadowNode = true; + + } + + setupShadowFilter( builder, { filterFn, depthTexture, shadowCoord, shadow } ) { + + const frustumTest = shadowCoord.x.greaterThanEqual( 0 ) + .and( shadowCoord.x.lessThanEqual( 1 ) ) + .and( shadowCoord.y.greaterThanEqual( 0 ) ) + .and( shadowCoord.y.lessThanEqual( 1 ) ) + .and( shadowCoord.z.lessThanEqual( 1 ) ); + + const shadowNode = filterFn( { depthTexture, shadowCoord, shadow } ); + + return frustumTest.select( shadowNode, float( 1 ) ); + + } + + setupShadowCoord( builder, shadowPosition ) { + + const { shadow } = this; + const { renderer } = builder; + + const bias = reference( 'bias', 'float', shadow ).setGroup( renderGroup ); + + let shadowCoord = shadowPosition; + let coordZ; + + if ( shadow.camera.isOrthographicCamera || renderer.logarithmicDepthBuffer !== true ) { + + shadowCoord = shadowCoord.xyz.div( shadowCoord.w ); + + coordZ = shadowCoord.z; + + if ( renderer.coordinateSystem === WebGPUCoordinateSystem ) { + + coordZ = coordZ.mul( 2 ).sub( 1 ); // WebGPU: Conversion [ 0, 1 ] to [ - 1, 1 ] + + } + + } else { + + const w = shadowCoord.w; + shadowCoord = shadowCoord.xy.div( w ); // <-- Only divide X/Y coords since we don't need Z + + // The normally available "cameraNear" and "cameraFar" nodes cannot be used here because they do not get + // updated to use the shadow camera. So, we have to declare our own "local" ones here. + // TODO: How do we get the cameraNear/cameraFar nodes to use the shadow camera so we don't have to declare local ones here? + const cameraNearLocal = reference( 'near', 'float', shadow.camera ).setGroup( renderGroup ); + const cameraFarLocal = reference( 'far', 'float', shadow.camera ).setGroup( renderGroup ); + + coordZ = viewZToLogarithmicDepth( w.negate(), cameraNearLocal, cameraFarLocal ); + + } + + shadowCoord = vec3( + shadowCoord.x, + shadowCoord.y.oneMinus(), // follow webgpu standards + coordZ.add( bias ) + ); + + return shadowCoord; + + } + + getShadowFilterFn( type ) { + + return _shadowFilterLib[ type ]; + + } + + setupShadow( builder ) { + + const { renderer } = builder; + + const { light, shadow } = this; + + const shadowMapType = renderer.shadowMap.type; + + const depthTexture = new DepthTexture( shadow.mapSize.width, shadow.mapSize.height ); + depthTexture.compareFunction = LessCompare; + + const shadowMap = builder.createRenderTarget( shadow.mapSize.width, shadow.mapSize.height ); + shadowMap.depthTexture = depthTexture; + + shadow.camera.updateProjectionMatrix(); + + // VSM + + if ( shadowMapType === VSMShadowMap ) { + + depthTexture.compareFunction = null; // VSM does not use textureSampleCompare()/texture2DCompare() + + this.vsmShadowMapVertical = builder.createRenderTarget( shadow.mapSize.width, shadow.mapSize.height, { format: RGFormat, type: HalfFloatType } ); + this.vsmShadowMapHorizontal = builder.createRenderTarget( shadow.mapSize.width, shadow.mapSize.height, { format: RGFormat, type: HalfFloatType } ); + + const shadowPassVertical = texture( depthTexture ); + const shadowPassHorizontal = texture( this.vsmShadowMapVertical.texture ); + + const samples = reference( 'blurSamples', 'float', shadow ).setGroup( renderGroup ); + const radius = reference( 'radius', 'float', shadow ).setGroup( renderGroup ); + const size = reference( 'mapSize', 'vec2', shadow ).setGroup( renderGroup ); + + let material = this.vsmMaterialVertical || ( this.vsmMaterialVertical = new NodeMaterial() ); + material.fragmentNode = VSMPassVertical( { samples, radius, size, shadowPass: shadowPassVertical } ).context( builder.getSharedContext() ); + material.name = 'VSMVertical'; + + material = this.vsmMaterialHorizontal || ( this.vsmMaterialHorizontal = new NodeMaterial() ); + material.fragmentNode = VSMPassHorizontal( { samples, radius, size, shadowPass: shadowPassHorizontal } ).context( builder.getSharedContext() ); + material.name = 'VSMHorizontal'; + + } + + // + + const shadowIntensity = reference( 'intensity', 'float', shadow ).setGroup( renderGroup ); + const normalBias = reference( 'normalBias', 'float', shadow ).setGroup( renderGroup ); + + const shadowPosition = lightShadowMatrix( light ).mul( shadowWorldPosition.add( transformedNormalWorld.mul( normalBias ) ) ); + const shadowCoord = this.setupShadowCoord( builder, shadowPosition ); + + // + + const filterFn = shadow.filterNode || this.getShadowFilterFn( renderer.shadowMap.type ) || null; + + if ( filterFn === null ) { + + throw new Error( 'THREE.WebGPURenderer: Shadow map type not supported yet.' ); + + } + + const shadowDepthTexture = ( shadowMapType === VSMShadowMap ) ? this.vsmShadowMapHorizontal.texture : depthTexture; + + const shadowNode = this.setupShadowFilter( builder, { filterFn, shadowTexture: shadowMap.texture, depthTexture: shadowDepthTexture, shadowCoord, shadow } ); + + const shadowColor = texture( shadowMap.texture, shadowCoord ); + const shadowOutput = mix( 1, shadowNode.rgb.mix( shadowColor, 1 ), shadowIntensity.mul( shadowColor.a ) ).toVar(); + + this.shadowMap = shadowMap; + this.shadow.map = shadowMap; + + return shadowOutput; + + } + + setup( builder ) { + + if ( builder.renderer.shadowMap.enabled === false ) return; + + return Fn( ( { material } ) => { + + shadowWorldPosition.assign( material.shadowPositionNode || positionWorld ); + + let node = this._node; + + if ( node === null ) { + + this._node = node = this.setupShadow( builder ); + + } + + if ( builder.material.shadowNode ) { // @deprecated, r171 + + console.warn( 'THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.' ); + + } + + if ( builder.material.receivedShadowNode ) { + + node = builder.material.receivedShadowNode( node ); + + } + + return node; + + } )(); + + } + + renderShadow( frame ) { + + const { shadow, shadowMap } = this; + const { renderer, scene } = frame; + + shadowMap.setSize( shadow.mapSize.width, shadow.mapSize.height ); + + renderer.render( scene, shadow.camera ); + + } + + updateShadow( frame ) { + + const { shadowMap, light, shadow } = this; + const { renderer, scene, camera } = frame; + + const shadowType = renderer.shadowMap.type; + + const depthVersion = shadowMap.depthTexture.version; + this._depthVersionCached = depthVersion; + + const currentOverrideMaterial = scene.overrideMaterial; + + scene.overrideMaterial = getShadowMaterial( light ); + + shadow.camera.layers.mask = camera.layers.mask; + + const currentRenderTarget = renderer.getRenderTarget(); + const currentRenderObjectFunction = renderer.getRenderObjectFunction(); + const currentMRT = renderer.getMRT(); + + renderer.setMRT( null ); + + renderer.setRenderObjectFunction( ( object, ...params ) => { + + if ( object.castShadow === true || ( object.receiveShadow && shadowType === VSMShadowMap ) ) { + + renderer.renderObject( object, ...params ); + + } + + } ); + + renderer.setRenderTarget( shadowMap ); + + this.renderShadow( frame ); + + renderer.setRenderObjectFunction( currentRenderObjectFunction ); + + // vsm blur pass + + if ( light.isPointLight !== true && shadowType === VSMShadowMap ) { + + this.vsmPass( renderer ); + + } + + renderer.setRenderTarget( currentRenderTarget ); + + renderer.setMRT( currentMRT ); + + scene.overrideMaterial = currentOverrideMaterial; + + } + + vsmPass( renderer ) { + + const { shadow } = this; + + this.vsmShadowMapVertical.setSize( shadow.mapSize.width, shadow.mapSize.height ); + this.vsmShadowMapHorizontal.setSize( shadow.mapSize.width, shadow.mapSize.height ); + + renderer.setRenderTarget( this.vsmShadowMapVertical ); + _quadMesh$1.material = this.vsmMaterialVertical; + _quadMesh$1.render( renderer ); + + renderer.setRenderTarget( this.vsmShadowMapHorizontal ); + _quadMesh$1.material = this.vsmMaterialHorizontal; + _quadMesh$1.render( renderer ); + + } + + dispose() { + + this.shadowMap.dispose(); + this.shadowMap = null; + + if ( this.vsmShadowMapVertical !== null ) { + + this.vsmShadowMapVertical.dispose(); + this.vsmShadowMapVertical = null; + + this.vsmMaterialVertical.dispose(); + this.vsmMaterialVertical = null; + + } + + if ( this.vsmShadowMapHorizontal !== null ) { + + this.vsmShadowMapHorizontal.dispose(); + this.vsmShadowMapHorizontal = null; + + this.vsmMaterialHorizontal.dispose(); + this.vsmMaterialHorizontal = null; + + } + + this.updateBeforeType = NodeUpdateType.NONE; + + } + + updateBefore( frame ) { + + const { shadow } = this; + + const needsUpdate = shadow.needsUpdate || shadow.autoUpdate; + + if ( needsUpdate ) { + + this.updateShadow( frame ); + + if ( this.shadowMap.depthTexture.version === this._depthVersionCached ) { + + shadow.needsUpdate = false; + + } + + } + + } + +} + +const shadow = ( light, shadow ) => nodeObject( new ShadowNode( light, shadow ) ); + +class AnalyticLightNode extends LightingNode { + + static get type() { + + return 'AnalyticLightNode'; + + } + + constructor( light = null ) { + + super(); + + this.light = light; + + this.color = new Color(); + this.colorNode = ( light && light.colorNode ) || uniform( this.color ).setGroup( renderGroup ); + + this.baseColorNode = null; + + this.shadowNode = null; + this.shadowColorNode = null; + + this.isAnalyticLightNode = true; + + this.updateType = NodeUpdateType.FRAME; + + } + + getCacheKey() { + + return hash$1( super.getCacheKey(), this.light.id, this.light.castShadow ? 1 : 0 ); + + } + + getHash() { + + return this.light.uuid; + + } + + setupShadowNode() { + + return shadow( this.light ); + + } + + setupShadow( builder ) { + + const { renderer } = builder; + + if ( renderer.shadowMap.enabled === false ) return; + + let shadowColorNode = this.shadowColorNode; + + if ( shadowColorNode === null ) { + + const customShadowNode = this.light.shadow.shadowNode; + + let shadowNode; + + if ( customShadowNode !== undefined ) { + + shadowNode = nodeObject( customShadowNode ); + + } else { + + shadowNode = this.setupShadowNode( builder ); + + } + + this.shadowNode = shadowNode; + + this.shadowColorNode = shadowColorNode = this.colorNode.mul( shadowNode ); + + this.baseColorNode = this.colorNode; + + } + + // + + this.colorNode = shadowColorNode; + + } + + setup( builder ) { + + this.colorNode = this.baseColorNode || this.colorNode; + + if ( this.light.castShadow ) { + + if ( builder.object.receiveShadow ) { + + this.setupShadow( builder ); + + } + + } else if ( this.shadowNode !== null ) { + + this.shadowNode.dispose(); + this.shadowNode = null; + this.shadowColorNode = null; + + } + + } + + update( /*frame*/ ) { + + const { light } = this; + + this.color.copy( light.color ).multiplyScalar( light.intensity ); + + } + +} + +const getDistanceAttenuation = /*@__PURE__*/ Fn( ( inputs ) => { + + const { lightDistance, cutoffDistance, decayExponent } = inputs; + + // based upon Frostbite 3 Moving to Physically-based Rendering + // page 32, equation 26: E[window1] + // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + const distanceFalloff = lightDistance.pow( decayExponent ).max( 0.01 ).reciprocal(); + + return cutoffDistance.greaterThan( 0 ).select( + distanceFalloff.mul( lightDistance.div( cutoffDistance ).pow4().oneMinus().clamp().pow2() ), + distanceFalloff + ); + +} ); // validated + +const _clearColor$2 = /*@__PURE__*/ new Color(); + +// cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D +// vector suitable for 2D texture mapping. This code uses the following layout for the +// 2D texture: +// +// xzXZ +// y Y +// +// Y - Positive y direction +// y - Negative y direction +// X - Positive x direction +// x - Negative x direction +// Z - Positive z direction +// z - Negative z direction +// +// Source and test bed: +// https://gist.github.com/tschw/da10c43c467ce8afd0c4 + +const cubeToUV = /*@__PURE__*/ Fn( ( [ pos, texelSizeY ] ) => { + + const v = pos.toVar(); + + // Number of texels to avoid at the edge of each square + + const absV = abs( v ); + + // Intersect unit cube + + const scaleToCube = div( 1.0, max$1( absV.x, max$1( absV.y, absV.z ) ) ); + absV.mulAssign( scaleToCube ); + + // Apply scale to avoid seams + + // two texels less per square (one texel will do for NEAREST) + v.mulAssign( scaleToCube.mul( texelSizeY.mul( 2 ).oneMinus() ) ); + + // Unwrap + + // space: -1 ... 1 range for each square + // + // #X## dim := ( 4 , 2 ) + // # # center := ( 1 , 1 ) + + const planar = vec2( v.xy ).toVar(); + + const almostATexel = texelSizeY.mul( 1.5 ); + const almostOne = almostATexel.oneMinus(); + + If( absV.z.greaterThanEqual( almostOne ), () => { + + If( v.z.greaterThan( 0.0 ), () => { + + planar.x.assign( sub( 4.0, v.x ) ); + + } ); + + } ).ElseIf( absV.x.greaterThanEqual( almostOne ), () => { + + const signX = sign( v.x ); + planar.x.assign( v.z.mul( signX ).add( signX.mul( 2.0 ) ) ); + + } ).ElseIf( absV.y.greaterThanEqual( almostOne ), () => { + + const signY = sign( v.y ); + planar.x.assign( v.x.add( signY.mul( 2.0 ) ).add( 2.0 ) ); + planar.y.assign( v.z.mul( signY ).sub( 2.0 ) ); + + } ); + + // Transform to UV space + + // scale := 0.5 / dim + // translate := ( center + 0.5 ) / dim + return vec2( 0.125, 0.25 ).mul( planar ).add( vec2( 0.375, 0.75 ) ).flipY(); + +} ).setLayout( { + name: 'cubeToUV', + type: 'vec2', + inputs: [ + { name: 'pos', type: 'vec3' }, + { name: 'texelSizeY', type: 'float' } + ] +} ); + +const BasicPointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp, texelSize } ) => { + + return texture( depthTexture, cubeToUV( bd3D, texelSize.y ) ).compare( dp ); + +} ); + +const PointShadowFilter = /*@__PURE__*/ Fn( ( { depthTexture, bd3D, dp, texelSize, shadow } ) => { + + const radius = reference( 'radius', 'float', shadow ).setGroup( renderGroup ); + const offset = vec2( - 1.0, 1.0 ).mul( radius ).mul( texelSize.y ); + + return texture( depthTexture, cubeToUV( bd3D.add( offset.xyy ), texelSize.y ) ).compare( dp ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.yyy ), texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.xyx ), texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.yyx ), texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D, texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.xxy ), texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.yxy ), texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.xxx ), texelSize.y ) ).compare( dp ) ) + .add( texture( depthTexture, cubeToUV( bd3D.add( offset.yxx ), texelSize.y ) ).compare( dp ) ) + .mul( 1.0 / 9.0 ); + +} ); + +const pointShadowFilter = /*@__PURE__*/ Fn( ( { filterFn, depthTexture, shadowCoord, shadow } ) => { + + // for point lights, the uniform @vShadowCoord is re-purposed to hold + // the vector from the light to the world-space position of the fragment. + const lightToPosition = shadowCoord.xyz.toVar(); + const lightToPositionLength = lightToPosition.length(); + + const cameraNearLocal = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.near ); + const cameraFarLocal = uniform( 'float' ).setGroup( renderGroup ).onRenderUpdate( () => shadow.camera.far ); + const bias = reference( 'bias', 'float', shadow ).setGroup( renderGroup ); + const mapSize = uniform( shadow.mapSize ).setGroup( renderGroup ); + + const result = float( 1.0 ).toVar(); + + If( lightToPositionLength.sub( cameraFarLocal ).lessThanEqual( 0.0 ).and( lightToPositionLength.sub( cameraNearLocal ).greaterThanEqual( 0.0 ) ), () => { + + // dp = normalized distance from light to fragment position + const dp = lightToPositionLength.sub( cameraNearLocal ).div( cameraFarLocal.sub( cameraNearLocal ) ).toVar(); // need to clamp? + dp.addAssign( bias ); + + // bd3D = base direction 3D + const bd3D = lightToPosition.normalize(); + const texelSize = vec2( 1.0 ).div( mapSize.mul( vec2( 4.0, 2.0 ) ) ); + + // percentage-closer filtering + result.assign( filterFn( { depthTexture, bd3D, dp, texelSize, shadow } ) ); + + } ); + + return result; + +} ); + +const _viewport = /*@__PURE__*/ new Vector4(); +const _viewportSize = /*@__PURE__*/ new Vector2(); +const _shadowMapSize = /*@__PURE__*/ new Vector2(); + +// + +class PointShadowNode extends ShadowNode { + + static get type() { + + return 'PointShadowNode'; + + } + + constructor( light, shadow = null ) { + + super( light, shadow ); + + } + + getShadowFilterFn( type ) { + + return type === BasicShadowMap ? BasicPointShadowFilter : PointShadowFilter; + + } + + setupShadowCoord( builder, shadowPosition ) { + + return shadowPosition; + + } + + setupShadowFilter( builder, { filterFn, shadowTexture, depthTexture, shadowCoord, shadow } ) { + + return pointShadowFilter( { filterFn, shadowTexture, depthTexture, shadowCoord, shadow } ); + + } + + renderShadow( frame ) { + + const { shadow, shadowMap, light } = this; + const { renderer, scene } = frame; + + const shadowFrameExtents = shadow.getFrameExtents(); + + _shadowMapSize.copy( shadow.mapSize ); + _shadowMapSize.multiply( shadowFrameExtents ); + + shadowMap.setSize( _shadowMapSize.width, _shadowMapSize.height ); + + _viewportSize.copy( shadow.mapSize ); + + // + + const previousAutoClear = renderer.autoClear; + + const previousClearColor = renderer.getClearColor( _clearColor$2 ); + const previousClearAlpha = renderer.getClearAlpha(); + + renderer.autoClear = false; + renderer.setClearColor( shadow.clearColor, shadow.clearAlpha ); + renderer.clear(); + + const viewportCount = shadow.getViewportCount(); + + for ( let vp = 0; vp < viewportCount; vp ++ ) { + + const viewport = shadow.getViewport( vp ); + + const x = _viewportSize.x * viewport.x; + const y = _shadowMapSize.y - _viewportSize.y - ( _viewportSize.y * viewport.y ); + + _viewport.set( + x, + y, + _viewportSize.x * viewport.z, + _viewportSize.y * viewport.w + ); + + shadowMap.viewport.copy( _viewport ); + + shadow.updateMatrices( light, vp ); + + renderer.render( scene, shadow.camera ); + + } + + // + + renderer.autoClear = previousAutoClear; + renderer.setClearColor( previousClearColor, previousClearAlpha ); + + } + +} + +const pointShadow = ( light, shadow ) => nodeObject( new PointShadowNode( light, shadow ) ); + +const directPointLight = Fn( ( { color, lightViewPosition, cutoffDistance, decayExponent }, builder ) => { + + const lightingModel = builder.context.lightingModel; + + const lVector = lightViewPosition.sub( positionView ); // @TODO: Add it into LightNode + + const lightDirection = lVector.normalize(); + const lightDistance = lVector.length(); + + const lightAttenuation = getDistanceAttenuation( { + lightDistance, + cutoffDistance, + decayExponent + } ); + + const lightColor = color.mul( lightAttenuation ); + + const reflectedLight = builder.context.reflectedLight; + + lightingModel.direct( { + lightDirection, + lightColor, + reflectedLight + }, builder.stack, builder ); + +} ); + +class PointLightNode extends AnalyticLightNode { + + static get type() { + + return 'PointLightNode'; + + } + + constructor( light = null ) { + + super( light ); + + this.cutoffDistanceNode = uniform( 0 ).setGroup( renderGroup ); + this.decayExponentNode = uniform( 0 ).setGroup( renderGroup ); + + } + + update( frame ) { + + const { light } = this; + + super.update( frame ); + + this.cutoffDistanceNode.value = light.distance; + this.decayExponentNode.value = light.decay; + + } + + setupShadowNode() { + + return pointShadow( this.light ); + + } + + setup( builder ) { + + super.setup( builder ); + + directPointLight( { + color: this.colorNode, + lightViewPosition: lightViewPosition( this.light ), + cutoffDistance: this.cutoffDistanceNode, + decayExponent: this.decayExponentNode + } ).append(); + + } + +} + +const checker = /*@__PURE__*/ Fn( ( [ coord = uv() ] ) => { + + const uv = coord.mul( 2.0 ); + + const cx = uv.x.floor(); + const cy = uv.y.floor(); + const result = cx.add( cy ).mod( 2.0 ); + + return result.sign(); + +} ); + +// Three.js Transpiler +// https://raw.githubusercontent.com/AcademySoftwareFoundation/MaterialX/main/libraries/stdlib/genglsl/lib/mx_noise.glsl + + + +const mx_select = /*@__PURE__*/ Fn( ( [ b_immutable, t_immutable, f_immutable ] ) => { + + const f = float( f_immutable ).toVar(); + const t = float( t_immutable ).toVar(); + const b = bool( b_immutable ).toVar(); + + return select( b, t, f ); + +} ).setLayout( { + name: 'mx_select', + type: 'float', + inputs: [ + { name: 'b', type: 'bool' }, + { name: 't', type: 'float' }, + { name: 'f', type: 'float' } + ] +} ); + +const mx_negate_if = /*@__PURE__*/ Fn( ( [ val_immutable, b_immutable ] ) => { + + const b = bool( b_immutable ).toVar(); + const val = float( val_immutable ).toVar(); + + return select( b, val.negate(), val ); + +} ).setLayout( { + name: 'mx_negate_if', + type: 'float', + inputs: [ + { name: 'val', type: 'float' }, + { name: 'b', type: 'bool' } + ] +} ); + +const mx_floor = /*@__PURE__*/ Fn( ( [ x_immutable ] ) => { + + const x = float( x_immutable ).toVar(); + + return int( floor( x ) ); + +} ).setLayout( { + name: 'mx_floor', + type: 'int', + inputs: [ + { name: 'x', type: 'float' } + ] +} ); + +const mx_floorfrac = /*@__PURE__*/ Fn( ( [ x_immutable, i ] ) => { + + const x = float( x_immutable ).toVar(); + i.assign( mx_floor( x ) ); + + return x.sub( float( i ) ); + +} ); + +const mx_bilerp_0 = /*@__PURE__*/ Fn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, s_immutable, t_immutable ] ) => { + + const t = float( t_immutable ).toVar(); + const s = float( s_immutable ).toVar(); + const v3 = float( v3_immutable ).toVar(); + const v2 = float( v2_immutable ).toVar(); + const v1 = float( v1_immutable ).toVar(); + const v0 = float( v0_immutable ).toVar(); + const s1 = float( sub( 1.0, s ) ).toVar(); + + return sub( 1.0, t ).mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) ); + +} ).setLayout( { + name: 'mx_bilerp_0', + type: 'float', + inputs: [ + { name: 'v0', type: 'float' }, + { name: 'v1', type: 'float' }, + { name: 'v2', type: 'float' }, + { name: 'v3', type: 'float' }, + { name: 's', type: 'float' }, + { name: 't', type: 'float' } + ] +} ); + +const mx_bilerp_1 = /*@__PURE__*/ Fn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, s_immutable, t_immutable ] ) => { + + const t = float( t_immutable ).toVar(); + const s = float( s_immutable ).toVar(); + const v3 = vec3( v3_immutable ).toVar(); + const v2 = vec3( v2_immutable ).toVar(); + const v1 = vec3( v1_immutable ).toVar(); + const v0 = vec3( v0_immutable ).toVar(); + const s1 = float( sub( 1.0, s ) ).toVar(); + + return sub( 1.0, t ).mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) ); + +} ).setLayout( { + name: 'mx_bilerp_1', + type: 'vec3', + inputs: [ + { name: 'v0', type: 'vec3' }, + { name: 'v1', type: 'vec3' }, + { name: 'v2', type: 'vec3' }, + { name: 'v3', type: 'vec3' }, + { name: 's', type: 'float' }, + { name: 't', type: 'float' } + ] +} ); + +const mx_bilerp = /*@__PURE__*/ overloadingFn( [ mx_bilerp_0, mx_bilerp_1 ] ); + +const mx_trilerp_0 = /*@__PURE__*/ Fn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, v4_immutable, v5_immutable, v6_immutable, v7_immutable, s_immutable, t_immutable, r_immutable ] ) => { + + const r = float( r_immutable ).toVar(); + const t = float( t_immutable ).toVar(); + const s = float( s_immutable ).toVar(); + const v7 = float( v7_immutable ).toVar(); + const v6 = float( v6_immutable ).toVar(); + const v5 = float( v5_immutable ).toVar(); + const v4 = float( v4_immutable ).toVar(); + const v3 = float( v3_immutable ).toVar(); + const v2 = float( v2_immutable ).toVar(); + const v1 = float( v1_immutable ).toVar(); + const v0 = float( v0_immutable ).toVar(); + const s1 = float( sub( 1.0, s ) ).toVar(); + const t1 = float( sub( 1.0, t ) ).toVar(); + const r1 = float( sub( 1.0, r ) ).toVar(); + + return r1.mul( t1.mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) ) ).add( r.mul( t1.mul( v4.mul( s1 ).add( v5.mul( s ) ) ).add( t.mul( v6.mul( s1 ).add( v7.mul( s ) ) ) ) ) ); + +} ).setLayout( { + name: 'mx_trilerp_0', + type: 'float', + inputs: [ + { name: 'v0', type: 'float' }, + { name: 'v1', type: 'float' }, + { name: 'v2', type: 'float' }, + { name: 'v3', type: 'float' }, + { name: 'v4', type: 'float' }, + { name: 'v5', type: 'float' }, + { name: 'v6', type: 'float' }, + { name: 'v7', type: 'float' }, + { name: 's', type: 'float' }, + { name: 't', type: 'float' }, + { name: 'r', type: 'float' } + ] +} ); + +const mx_trilerp_1 = /*@__PURE__*/ Fn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, v4_immutable, v5_immutable, v6_immutable, v7_immutable, s_immutable, t_immutable, r_immutable ] ) => { + + const r = float( r_immutable ).toVar(); + const t = float( t_immutable ).toVar(); + const s = float( s_immutable ).toVar(); + const v7 = vec3( v7_immutable ).toVar(); + const v6 = vec3( v6_immutable ).toVar(); + const v5 = vec3( v5_immutable ).toVar(); + const v4 = vec3( v4_immutable ).toVar(); + const v3 = vec3( v3_immutable ).toVar(); + const v2 = vec3( v2_immutable ).toVar(); + const v1 = vec3( v1_immutable ).toVar(); + const v0 = vec3( v0_immutable ).toVar(); + const s1 = float( sub( 1.0, s ) ).toVar(); + const t1 = float( sub( 1.0, t ) ).toVar(); + const r1 = float( sub( 1.0, r ) ).toVar(); + + return r1.mul( t1.mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) ) ).add( r.mul( t1.mul( v4.mul( s1 ).add( v5.mul( s ) ) ).add( t.mul( v6.mul( s1 ).add( v7.mul( s ) ) ) ) ) ); + +} ).setLayout( { + name: 'mx_trilerp_1', + type: 'vec3', + inputs: [ + { name: 'v0', type: 'vec3' }, + { name: 'v1', type: 'vec3' }, + { name: 'v2', type: 'vec3' }, + { name: 'v3', type: 'vec3' }, + { name: 'v4', type: 'vec3' }, + { name: 'v5', type: 'vec3' }, + { name: 'v6', type: 'vec3' }, + { name: 'v7', type: 'vec3' }, + { name: 's', type: 'float' }, + { name: 't', type: 'float' }, + { name: 'r', type: 'float' } + ] +} ); + +const mx_trilerp = /*@__PURE__*/ overloadingFn( [ mx_trilerp_0, mx_trilerp_1 ] ); + +const mx_gradient_float_0 = /*@__PURE__*/ Fn( ( [ hash_immutable, x_immutable, y_immutable ] ) => { + + const y = float( y_immutable ).toVar(); + const x = float( x_immutable ).toVar(); + const hash = uint( hash_immutable ).toVar(); + const h = uint( hash.bitAnd( uint( 7 ) ) ).toVar(); + const u = float( mx_select( h.lessThan( uint( 4 ) ), x, y ) ).toVar(); + const v = float( mul( 2.0, mx_select( h.lessThan( uint( 4 ) ), y, x ) ) ).toVar(); + + return mx_negate_if( u, bool( h.bitAnd( uint( 1 ) ) ) ).add( mx_negate_if( v, bool( h.bitAnd( uint( 2 ) ) ) ) ); + +} ).setLayout( { + name: 'mx_gradient_float_0', + type: 'float', + inputs: [ + { name: 'hash', type: 'uint' }, + { name: 'x', type: 'float' }, + { name: 'y', type: 'float' } + ] +} ); + +const mx_gradient_float_1 = /*@__PURE__*/ Fn( ( [ hash_immutable, x_immutable, y_immutable, z_immutable ] ) => { + + const z = float( z_immutable ).toVar(); + const y = float( y_immutable ).toVar(); + const x = float( x_immutable ).toVar(); + const hash = uint( hash_immutable ).toVar(); + const h = uint( hash.bitAnd( uint( 15 ) ) ).toVar(); + const u = float( mx_select( h.lessThan( uint( 8 ) ), x, y ) ).toVar(); + const v = float( mx_select( h.lessThan( uint( 4 ) ), y, mx_select( h.equal( uint( 12 ) ).or( h.equal( uint( 14 ) ) ), x, z ) ) ).toVar(); + + return mx_negate_if( u, bool( h.bitAnd( uint( 1 ) ) ) ).add( mx_negate_if( v, bool( h.bitAnd( uint( 2 ) ) ) ) ); + +} ).setLayout( { + name: 'mx_gradient_float_1', + type: 'float', + inputs: [ + { name: 'hash', type: 'uint' }, + { name: 'x', type: 'float' }, + { name: 'y', type: 'float' }, + { name: 'z', type: 'float' } + ] +} ); + +const mx_gradient_float = /*@__PURE__*/ overloadingFn( [ mx_gradient_float_0, mx_gradient_float_1 ] ); + +const mx_gradient_vec3_0 = /*@__PURE__*/ Fn( ( [ hash_immutable, x_immutable, y_immutable ] ) => { + + const y = float( y_immutable ).toVar(); + const x = float( x_immutable ).toVar(); + const hash = uvec3( hash_immutable ).toVar(); + + return vec3( mx_gradient_float( hash.x, x, y ), mx_gradient_float( hash.y, x, y ), mx_gradient_float( hash.z, x, y ) ); + +} ).setLayout( { + name: 'mx_gradient_vec3_0', + type: 'vec3', + inputs: [ + { name: 'hash', type: 'uvec3' }, + { name: 'x', type: 'float' }, + { name: 'y', type: 'float' } + ] +} ); + +const mx_gradient_vec3_1 = /*@__PURE__*/ Fn( ( [ hash_immutable, x_immutable, y_immutable, z_immutable ] ) => { + + const z = float( z_immutable ).toVar(); + const y = float( y_immutable ).toVar(); + const x = float( x_immutable ).toVar(); + const hash = uvec3( hash_immutable ).toVar(); + + return vec3( mx_gradient_float( hash.x, x, y, z ), mx_gradient_float( hash.y, x, y, z ), mx_gradient_float( hash.z, x, y, z ) ); + +} ).setLayout( { + name: 'mx_gradient_vec3_1', + type: 'vec3', + inputs: [ + { name: 'hash', type: 'uvec3' }, + { name: 'x', type: 'float' }, + { name: 'y', type: 'float' }, + { name: 'z', type: 'float' } + ] +} ); + +const mx_gradient_vec3 = /*@__PURE__*/ overloadingFn( [ mx_gradient_vec3_0, mx_gradient_vec3_1 ] ); + +const mx_gradient_scale2d_0 = /*@__PURE__*/ Fn( ( [ v_immutable ] ) => { + + const v = float( v_immutable ).toVar(); + + return mul( 0.6616, v ); + +} ).setLayout( { + name: 'mx_gradient_scale2d_0', + type: 'float', + inputs: [ + { name: 'v', type: 'float' } + ] +} ); + +const mx_gradient_scale3d_0 = /*@__PURE__*/ Fn( ( [ v_immutable ] ) => { + + const v = float( v_immutable ).toVar(); + + return mul( 0.9820, v ); + +} ).setLayout( { + name: 'mx_gradient_scale3d_0', + type: 'float', + inputs: [ + { name: 'v', type: 'float' } + ] +} ); + +const mx_gradient_scale2d_1 = /*@__PURE__*/ Fn( ( [ v_immutable ] ) => { + + const v = vec3( v_immutable ).toVar(); + + return mul( 0.6616, v ); + +} ).setLayout( { + name: 'mx_gradient_scale2d_1', + type: 'vec3', + inputs: [ + { name: 'v', type: 'vec3' } + ] +} ); + +const mx_gradient_scale2d = /*@__PURE__*/ overloadingFn( [ mx_gradient_scale2d_0, mx_gradient_scale2d_1 ] ); + +const mx_gradient_scale3d_1 = /*@__PURE__*/ Fn( ( [ v_immutable ] ) => { + + const v = vec3( v_immutable ).toVar(); + + return mul( 0.9820, v ); + +} ).setLayout( { + name: 'mx_gradient_scale3d_1', + type: 'vec3', + inputs: [ + { name: 'v', type: 'vec3' } + ] +} ); + +const mx_gradient_scale3d = /*@__PURE__*/ overloadingFn( [ mx_gradient_scale3d_0, mx_gradient_scale3d_1 ] ); + +const mx_rotl32 = /*@__PURE__*/ Fn( ( [ x_immutable, k_immutable ] ) => { + + const k = int( k_immutable ).toVar(); + const x = uint( x_immutable ).toVar(); + + return x.shiftLeft( k ).bitOr( x.shiftRight( int( 32 ).sub( k ) ) ); + +} ).setLayout( { + name: 'mx_rotl32', + type: 'uint', + inputs: [ + { name: 'x', type: 'uint' }, + { name: 'k', type: 'int' } + ] +} ); + +const mx_bjmix = /*@__PURE__*/ Fn( ( [ a, b, c ] ) => { + + a.subAssign( c ); + a.bitXorAssign( mx_rotl32( c, int( 4 ) ) ); + c.addAssign( b ); + b.subAssign( a ); + b.bitXorAssign( mx_rotl32( a, int( 6 ) ) ); + a.addAssign( c ); + c.subAssign( b ); + c.bitXorAssign( mx_rotl32( b, int( 8 ) ) ); + b.addAssign( a ); + a.subAssign( c ); + a.bitXorAssign( mx_rotl32( c, int( 16 ) ) ); + c.addAssign( b ); + b.subAssign( a ); + b.bitXorAssign( mx_rotl32( a, int( 19 ) ) ); + a.addAssign( c ); + c.subAssign( b ); + c.bitXorAssign( mx_rotl32( b, int( 4 ) ) ); + b.addAssign( a ); + +} ); + +const mx_bjfinal = /*@__PURE__*/ Fn( ( [ a_immutable, b_immutable, c_immutable ] ) => { + + const c = uint( c_immutable ).toVar(); + const b = uint( b_immutable ).toVar(); + const a = uint( a_immutable ).toVar(); + c.bitXorAssign( b ); + c.subAssign( mx_rotl32( b, int( 14 ) ) ); + a.bitXorAssign( c ); + a.subAssign( mx_rotl32( c, int( 11 ) ) ); + b.bitXorAssign( a ); + b.subAssign( mx_rotl32( a, int( 25 ) ) ); + c.bitXorAssign( b ); + c.subAssign( mx_rotl32( b, int( 16 ) ) ); + a.bitXorAssign( c ); + a.subAssign( mx_rotl32( c, int( 4 ) ) ); + b.bitXorAssign( a ); + b.subAssign( mx_rotl32( a, int( 14 ) ) ); + c.bitXorAssign( b ); + c.subAssign( mx_rotl32( b, int( 24 ) ) ); + + return c; + +} ).setLayout( { + name: 'mx_bjfinal', + type: 'uint', + inputs: [ + { name: 'a', type: 'uint' }, + { name: 'b', type: 'uint' }, + { name: 'c', type: 'uint' } + ] +} ); + +const mx_bits_to_01 = /*@__PURE__*/ Fn( ( [ bits_immutable ] ) => { + + const bits = uint( bits_immutable ).toVar(); + + return float( bits ).div( float( uint( int( 0xffffffff ) ) ) ); + +} ).setLayout( { + name: 'mx_bits_to_01', + type: 'float', + inputs: [ + { name: 'bits', type: 'uint' } + ] +} ); + +const mx_fade = /*@__PURE__*/ Fn( ( [ t_immutable ] ) => { + + const t = float( t_immutable ).toVar(); + + return t.mul( t ).mul( t ).mul( t.mul( t.mul( 6.0 ).sub( 15.0 ) ).add( 10.0 ) ); + +} ).setLayout( { + name: 'mx_fade', + type: 'float', + inputs: [ + { name: 't', type: 'float' } + ] +} ); + +const mx_hash_int_0 = /*@__PURE__*/ Fn( ( [ x_immutable ] ) => { + + const x = int( x_immutable ).toVar(); + const len = uint( uint( 1 ) ).toVar(); + const seed = uint( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ).toVar(); + + return mx_bjfinal( seed.add( uint( x ) ), seed, seed ); + +} ).setLayout( { + name: 'mx_hash_int_0', + type: 'uint', + inputs: [ + { name: 'x', type: 'int' } + ] +} ); + +const mx_hash_int_1 = /*@__PURE__*/ Fn( ( [ x_immutable, y_immutable ] ) => { + + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const len = uint( uint( 2 ) ).toVar(); + const a = uint().toVar(), b = uint().toVar(), c = uint().toVar(); + a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) ); + a.addAssign( uint( x ) ); + b.addAssign( uint( y ) ); + + return mx_bjfinal( a, b, c ); + +} ).setLayout( { + name: 'mx_hash_int_1', + type: 'uint', + inputs: [ + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' } + ] +} ); + +const mx_hash_int_2 = /*@__PURE__*/ Fn( ( [ x_immutable, y_immutable, z_immutable ] ) => { + + const z = int( z_immutable ).toVar(); + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const len = uint( uint( 3 ) ).toVar(); + const a = uint().toVar(), b = uint().toVar(), c = uint().toVar(); + a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) ); + a.addAssign( uint( x ) ); + b.addAssign( uint( y ) ); + c.addAssign( uint( z ) ); + + return mx_bjfinal( a, b, c ); + +} ).setLayout( { + name: 'mx_hash_int_2', + type: 'uint', + inputs: [ + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' }, + { name: 'z', type: 'int' } + ] +} ); + +const mx_hash_int_3 = /*@__PURE__*/ Fn( ( [ x_immutable, y_immutable, z_immutable, xx_immutable ] ) => { + + const xx = int( xx_immutable ).toVar(); + const z = int( z_immutable ).toVar(); + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const len = uint( uint( 4 ) ).toVar(); + const a = uint().toVar(), b = uint().toVar(), c = uint().toVar(); + a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) ); + a.addAssign( uint( x ) ); + b.addAssign( uint( y ) ); + c.addAssign( uint( z ) ); + mx_bjmix( a, b, c ); + a.addAssign( uint( xx ) ); + + return mx_bjfinal( a, b, c ); + +} ).setLayout( { + name: 'mx_hash_int_3', + type: 'uint', + inputs: [ + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' }, + { name: 'z', type: 'int' }, + { name: 'xx', type: 'int' } + ] +} ); + +const mx_hash_int_4 = /*@__PURE__*/ Fn( ( [ x_immutable, y_immutable, z_immutable, xx_immutable, yy_immutable ] ) => { + + const yy = int( yy_immutable ).toVar(); + const xx = int( xx_immutable ).toVar(); + const z = int( z_immutable ).toVar(); + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const len = uint( uint( 5 ) ).toVar(); + const a = uint().toVar(), b = uint().toVar(), c = uint().toVar(); + a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) ); + a.addAssign( uint( x ) ); + b.addAssign( uint( y ) ); + c.addAssign( uint( z ) ); + mx_bjmix( a, b, c ); + a.addAssign( uint( xx ) ); + b.addAssign( uint( yy ) ); + + return mx_bjfinal( a, b, c ); + +} ).setLayout( { + name: 'mx_hash_int_4', + type: 'uint', + inputs: [ + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' }, + { name: 'z', type: 'int' }, + { name: 'xx', type: 'int' }, + { name: 'yy', type: 'int' } + ] +} ); + +const mx_hash_int = /*@__PURE__*/ overloadingFn( [ mx_hash_int_0, mx_hash_int_1, mx_hash_int_2, mx_hash_int_3, mx_hash_int_4 ] ); + +const mx_hash_vec3_0 = /*@__PURE__*/ Fn( ( [ x_immutable, y_immutable ] ) => { + + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const h = uint( mx_hash_int( x, y ) ).toVar(); + const result = uvec3().toVar(); + result.x.assign( h.bitAnd( int( 0xFF ) ) ); + result.y.assign( h.shiftRight( int( 8 ) ).bitAnd( int( 0xFF ) ) ); + result.z.assign( h.shiftRight( int( 16 ) ).bitAnd( int( 0xFF ) ) ); + + return result; + +} ).setLayout( { + name: 'mx_hash_vec3_0', + type: 'uvec3', + inputs: [ + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' } + ] +} ); + +const mx_hash_vec3_1 = /*@__PURE__*/ Fn( ( [ x_immutable, y_immutable, z_immutable ] ) => { + + const z = int( z_immutable ).toVar(); + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const h = uint( mx_hash_int( x, y, z ) ).toVar(); + const result = uvec3().toVar(); + result.x.assign( h.bitAnd( int( 0xFF ) ) ); + result.y.assign( h.shiftRight( int( 8 ) ).bitAnd( int( 0xFF ) ) ); + result.z.assign( h.shiftRight( int( 16 ) ).bitAnd( int( 0xFF ) ) ); + + return result; + +} ).setLayout( { + name: 'mx_hash_vec3_1', + type: 'uvec3', + inputs: [ + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' }, + { name: 'z', type: 'int' } + ] +} ); + +const mx_hash_vec3 = /*@__PURE__*/ overloadingFn( [ mx_hash_vec3_0, mx_hash_vec3_1 ] ); + +const mx_perlin_noise_float_0 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec2( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(); + const fx = float( mx_floorfrac( p.x, X ) ).toVar(); + const fy = float( mx_floorfrac( p.y, Y ) ).toVar(); + const u = float( mx_fade( fx ) ).toVar(); + const v = float( mx_fade( fy ) ).toVar(); + const result = float( mx_bilerp( mx_gradient_float( mx_hash_int( X, Y ), fx, fy ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y ), fx.sub( 1.0 ), fy ), mx_gradient_float( mx_hash_int( X, Y.add( int( 1 ) ) ), fx, fy.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ) ), u, v ) ).toVar(); + + return mx_gradient_scale2d( result ); + +} ).setLayout( { + name: 'mx_perlin_noise_float_0', + type: 'float', + inputs: [ + { name: 'p', type: 'vec2' } + ] +} ); + +const mx_perlin_noise_float_1 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec3( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(), Z = int().toVar(); + const fx = float( mx_floorfrac( p.x, X ) ).toVar(); + const fy = float( mx_floorfrac( p.y, Y ) ).toVar(); + const fz = float( mx_floorfrac( p.z, Z ) ).toVar(); + const u = float( mx_fade( fx ) ).toVar(); + const v = float( mx_fade( fy ) ).toVar(); + const w = float( mx_fade( fz ) ).toVar(); + const result = float( mx_trilerp( mx_gradient_float( mx_hash_int( X, Y, Z ), fx, fy, fz ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y, Z ), fx.sub( 1.0 ), fy, fz ), mx_gradient_float( mx_hash_int( X, Y.add( int( 1 ) ), Z ), fx, fy.sub( 1.0 ), fz ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz ), mx_gradient_float( mx_hash_int( X, Y, Z.add( int( 1 ) ) ), fx, fy, fz.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y, Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy, fz.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X, Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx, fy.sub( 1.0 ), fz.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz.sub( 1.0 ) ), u, v, w ) ).toVar(); + + return mx_gradient_scale3d( result ); + +} ).setLayout( { + name: 'mx_perlin_noise_float_1', + type: 'float', + inputs: [ + { name: 'p', type: 'vec3' } + ] +} ); + +const mx_perlin_noise_float = /*@__PURE__*/ overloadingFn( [ mx_perlin_noise_float_0, mx_perlin_noise_float_1 ] ); + +const mx_perlin_noise_vec3_0 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec2( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(); + const fx = float( mx_floorfrac( p.x, X ) ).toVar(); + const fy = float( mx_floorfrac( p.y, Y ) ).toVar(); + const u = float( mx_fade( fx ) ).toVar(); + const v = float( mx_fade( fy ) ).toVar(); + const result = vec3( mx_bilerp( mx_gradient_vec3( mx_hash_vec3( X, Y ), fx, fy ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y ), fx.sub( 1.0 ), fy ), mx_gradient_vec3( mx_hash_vec3( X, Y.add( int( 1 ) ) ), fx, fy.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ) ), u, v ) ).toVar(); + + return mx_gradient_scale2d( result ); + +} ).setLayout( { + name: 'mx_perlin_noise_vec3_0', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec2' } + ] +} ); + +const mx_perlin_noise_vec3_1 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec3( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(), Z = int().toVar(); + const fx = float( mx_floorfrac( p.x, X ) ).toVar(); + const fy = float( mx_floorfrac( p.y, Y ) ).toVar(); + const fz = float( mx_floorfrac( p.z, Z ) ).toVar(); + const u = float( mx_fade( fx ) ).toVar(); + const v = float( mx_fade( fy ) ).toVar(); + const w = float( mx_fade( fz ) ).toVar(); + const result = vec3( mx_trilerp( mx_gradient_vec3( mx_hash_vec3( X, Y, Z ), fx, fy, fz ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y, Z ), fx.sub( 1.0 ), fy, fz ), mx_gradient_vec3( mx_hash_vec3( X, Y.add( int( 1 ) ), Z ), fx, fy.sub( 1.0 ), fz ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz ), mx_gradient_vec3( mx_hash_vec3( X, Y, Z.add( int( 1 ) ) ), fx, fy, fz.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y, Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy, fz.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X, Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx, fy.sub( 1.0 ), fz.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz.sub( 1.0 ) ), u, v, w ) ).toVar(); + + return mx_gradient_scale3d( result ); + +} ).setLayout( { + name: 'mx_perlin_noise_vec3_1', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec3' } + ] +} ); + +const mx_perlin_noise_vec3 = /*@__PURE__*/ overloadingFn( [ mx_perlin_noise_vec3_0, mx_perlin_noise_vec3_1 ] ); + +const mx_cell_noise_float_0 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = float( p_immutable ).toVar(); + const ix = int( mx_floor( p ) ).toVar(); + + return mx_bits_to_01( mx_hash_int( ix ) ); + +} ).setLayout( { + name: 'mx_cell_noise_float_0', + type: 'float', + inputs: [ + { name: 'p', type: 'float' } + ] +} ); + +const mx_cell_noise_float_1 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec2( p_immutable ).toVar(); + const ix = int( mx_floor( p.x ) ).toVar(); + const iy = int( mx_floor( p.y ) ).toVar(); + + return mx_bits_to_01( mx_hash_int( ix, iy ) ); + +} ).setLayout( { + name: 'mx_cell_noise_float_1', + type: 'float', + inputs: [ + { name: 'p', type: 'vec2' } + ] +} ); + +const mx_cell_noise_float_2 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec3( p_immutable ).toVar(); + const ix = int( mx_floor( p.x ) ).toVar(); + const iy = int( mx_floor( p.y ) ).toVar(); + const iz = int( mx_floor( p.z ) ).toVar(); + + return mx_bits_to_01( mx_hash_int( ix, iy, iz ) ); + +} ).setLayout( { + name: 'mx_cell_noise_float_2', + type: 'float', + inputs: [ + { name: 'p', type: 'vec3' } + ] +} ); + +const mx_cell_noise_float_3 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec4( p_immutable ).toVar(); + const ix = int( mx_floor( p.x ) ).toVar(); + const iy = int( mx_floor( p.y ) ).toVar(); + const iz = int( mx_floor( p.z ) ).toVar(); + const iw = int( mx_floor( p.w ) ).toVar(); + + return mx_bits_to_01( mx_hash_int( ix, iy, iz, iw ) ); + +} ).setLayout( { + name: 'mx_cell_noise_float_3', + type: 'float', + inputs: [ + { name: 'p', type: 'vec4' } + ] +} ); + +const mx_cell_noise_float$1 = /*@__PURE__*/ overloadingFn( [ mx_cell_noise_float_0, mx_cell_noise_float_1, mx_cell_noise_float_2, mx_cell_noise_float_3 ] ); + +const mx_cell_noise_vec3_0 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = float( p_immutable ).toVar(); + const ix = int( mx_floor( p ) ).toVar(); + + return vec3( mx_bits_to_01( mx_hash_int( ix, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, int( 2 ) ) ) ); + +} ).setLayout( { + name: 'mx_cell_noise_vec3_0', + type: 'vec3', + inputs: [ + { name: 'p', type: 'float' } + ] +} ); + +const mx_cell_noise_vec3_1 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec2( p_immutable ).toVar(); + const ix = int( mx_floor( p.x ) ).toVar(); + const iy = int( mx_floor( p.y ) ).toVar(); + + return vec3( mx_bits_to_01( mx_hash_int( ix, iy, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, int( 2 ) ) ) ); + +} ).setLayout( { + name: 'mx_cell_noise_vec3_1', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec2' } + ] +} ); + +const mx_cell_noise_vec3_2 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec3( p_immutable ).toVar(); + const ix = int( mx_floor( p.x ) ).toVar(); + const iy = int( mx_floor( p.y ) ).toVar(); + const iz = int( mx_floor( p.z ) ).toVar(); + + return vec3( mx_bits_to_01( mx_hash_int( ix, iy, iz, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, int( 2 ) ) ) ); + +} ).setLayout( { + name: 'mx_cell_noise_vec3_2', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec3' } + ] +} ); + +const mx_cell_noise_vec3_3 = /*@__PURE__*/ Fn( ( [ p_immutable ] ) => { + + const p = vec4( p_immutable ).toVar(); + const ix = int( mx_floor( p.x ) ).toVar(); + const iy = int( mx_floor( p.y ) ).toVar(); + const iz = int( mx_floor( p.z ) ).toVar(); + const iw = int( mx_floor( p.w ) ).toVar(); + + return vec3( mx_bits_to_01( mx_hash_int( ix, iy, iz, iw, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, iw, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, iw, int( 2 ) ) ) ); + +} ).setLayout( { + name: 'mx_cell_noise_vec3_3', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec4' } + ] +} ); + +const mx_cell_noise_vec3 = /*@__PURE__*/ overloadingFn( [ mx_cell_noise_vec3_0, mx_cell_noise_vec3_1, mx_cell_noise_vec3_2, mx_cell_noise_vec3_3 ] ); + +const mx_fractal_noise_float$1 = /*@__PURE__*/ Fn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => { + + const diminish = float( diminish_immutable ).toVar(); + const lacunarity = float( lacunarity_immutable ).toVar(); + const octaves = int( octaves_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const result = float( 0.0 ).toVar(); + const amplitude = float( 1.0 ).toVar(); + + Loop( octaves, () => { + + result.addAssign( amplitude.mul( mx_perlin_noise_float( p ) ) ); + amplitude.mulAssign( diminish ); + p.mulAssign( lacunarity ); + + } ); + + return result; + +} ).setLayout( { + name: 'mx_fractal_noise_float', + type: 'float', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'octaves', type: 'int' }, + { name: 'lacunarity', type: 'float' }, + { name: 'diminish', type: 'float' } + ] +} ); + +const mx_fractal_noise_vec3$1 = /*@__PURE__*/ Fn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => { + + const diminish = float( diminish_immutable ).toVar(); + const lacunarity = float( lacunarity_immutable ).toVar(); + const octaves = int( octaves_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const result = vec3( 0.0 ).toVar(); + const amplitude = float( 1.0 ).toVar(); + + Loop( octaves, () => { + + result.addAssign( amplitude.mul( mx_perlin_noise_vec3( p ) ) ); + amplitude.mulAssign( diminish ); + p.mulAssign( lacunarity ); + + } ); + + return result; + +} ).setLayout( { + name: 'mx_fractal_noise_vec3', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'octaves', type: 'int' }, + { name: 'lacunarity', type: 'float' }, + { name: 'diminish', type: 'float' } + ] +} ); + +const mx_fractal_noise_vec2$1 = /*@__PURE__*/ Fn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => { + + const diminish = float( diminish_immutable ).toVar(); + const lacunarity = float( lacunarity_immutable ).toVar(); + const octaves = int( octaves_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + + return vec2( mx_fractal_noise_float$1( p, octaves, lacunarity, diminish ), mx_fractal_noise_float$1( p.add( vec3( int( 19 ), int( 193 ), int( 17 ) ) ), octaves, lacunarity, diminish ) ); + +} ).setLayout( { + name: 'mx_fractal_noise_vec2', + type: 'vec2', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'octaves', type: 'int' }, + { name: 'lacunarity', type: 'float' }, + { name: 'diminish', type: 'float' } + ] +} ); + +const mx_fractal_noise_vec4$1 = /*@__PURE__*/ Fn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => { + + const diminish = float( diminish_immutable ).toVar(); + const lacunarity = float( lacunarity_immutable ).toVar(); + const octaves = int( octaves_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const c = vec3( mx_fractal_noise_vec3$1( p, octaves, lacunarity, diminish ) ).toVar(); + const f = float( mx_fractal_noise_float$1( p.add( vec3( int( 19 ), int( 193 ), int( 17 ) ) ), octaves, lacunarity, diminish ) ).toVar(); + + return vec4( c, f ); + +} ).setLayout( { + name: 'mx_fractal_noise_vec4', + type: 'vec4', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'octaves', type: 'int' }, + { name: 'lacunarity', type: 'float' }, + { name: 'diminish', type: 'float' } + ] +} ); + +const mx_worley_distance_0 = /*@__PURE__*/ Fn( ( [ p_immutable, x_immutable, y_immutable, xoff_immutable, yoff_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const yoff = int( yoff_immutable ).toVar(); + const xoff = int( xoff_immutable ).toVar(); + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const p = vec2( p_immutable ).toVar(); + const tmp = vec3( mx_cell_noise_vec3( vec2( x.add( xoff ), y.add( yoff ) ) ) ).toVar(); + const off = vec2( tmp.x, tmp.y ).toVar(); + off.subAssign( 0.5 ); + off.mulAssign( jitter ); + off.addAssign( 0.5 ); + const cellpos = vec2( vec2( float( x ), float( y ) ).add( off ) ).toVar(); + const diff = vec2( cellpos.sub( p ) ).toVar(); + + If( metric.equal( int( 2 ) ), () => { + + return abs( diff.x ).add( abs( diff.y ) ); + + } ); + + If( metric.equal( int( 3 ) ), () => { + + return max$1( abs( diff.x ), abs( diff.y ) ); + + } ); + + return dot( diff, diff ); + +} ).setLayout( { + name: 'mx_worley_distance_0', + type: 'float', + inputs: [ + { name: 'p', type: 'vec2' }, + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' }, + { name: 'xoff', type: 'int' }, + { name: 'yoff', type: 'int' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_distance_1 = /*@__PURE__*/ Fn( ( [ p_immutable, x_immutable, y_immutable, z_immutable, xoff_immutable, yoff_immutable, zoff_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const zoff = int( zoff_immutable ).toVar(); + const yoff = int( yoff_immutable ).toVar(); + const xoff = int( xoff_immutable ).toVar(); + const z = int( z_immutable ).toVar(); + const y = int( y_immutable ).toVar(); + const x = int( x_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const off = vec3( mx_cell_noise_vec3( vec3( x.add( xoff ), y.add( yoff ), z.add( zoff ) ) ) ).toVar(); + off.subAssign( 0.5 ); + off.mulAssign( jitter ); + off.addAssign( 0.5 ); + const cellpos = vec3( vec3( float( x ), float( y ), float( z ) ).add( off ) ).toVar(); + const diff = vec3( cellpos.sub( p ) ).toVar(); + + If( metric.equal( int( 2 ) ), () => { + + return abs( diff.x ).add( abs( diff.y ) ).add( abs( diff.z ) ); + + } ); + + If( metric.equal( int( 3 ) ), () => { + + return max$1( max$1( abs( diff.x ), abs( diff.y ) ), abs( diff.z ) ); + + } ); + + return dot( diff, diff ); + +} ).setLayout( { + name: 'mx_worley_distance_1', + type: 'float', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'x', type: 'int' }, + { name: 'y', type: 'int' }, + { name: 'z', type: 'int' }, + { name: 'xoff', type: 'int' }, + { name: 'yoff', type: 'int' }, + { name: 'zoff', type: 'int' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_distance = /*@__PURE__*/ overloadingFn( [ mx_worley_distance_0, mx_worley_distance_1 ] ); + +const mx_worley_noise_float_0 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const p = vec2( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(); + const localpos = vec2( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ) ).toVar(); + const sqdist = float( 1e6 ).toVar(); + + Loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => { + + const dist = float( mx_worley_distance( localpos, x, y, X, Y, jitter, metric ) ).toVar(); + sqdist.assign( min$1( sqdist, dist ) ); + + } ); + + } ); + + If( metric.equal( int( 0 ) ), () => { + + sqdist.assign( sqrt( sqdist ) ); + + } ); + + return sqdist; + +} ).setLayout( { + name: 'mx_worley_noise_float_0', + type: 'float', + inputs: [ + { name: 'p', type: 'vec2' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_noise_vec2_0 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const p = vec2( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(); + const localpos = vec2( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ) ).toVar(); + const sqdist = vec2( 1e6, 1e6 ).toVar(); + + Loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => { + + const dist = float( mx_worley_distance( localpos, x, y, X, Y, jitter, metric ) ).toVar(); + + If( dist.lessThan( sqdist.x ), () => { + + sqdist.y.assign( sqdist.x ); + sqdist.x.assign( dist ); + + } ).ElseIf( dist.lessThan( sqdist.y ), () => { + + sqdist.y.assign( dist ); + + } ); + + } ); + + } ); + + If( metric.equal( int( 0 ) ), () => { + + sqdist.assign( sqrt( sqdist ) ); + + } ); + + return sqdist; + +} ).setLayout( { + name: 'mx_worley_noise_vec2_0', + type: 'vec2', + inputs: [ + { name: 'p', type: 'vec2' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_noise_vec3_0 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const p = vec2( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(); + const localpos = vec2( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ) ).toVar(); + const sqdist = vec3( 1e6, 1e6, 1e6 ).toVar(); + + Loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => { + + const dist = float( mx_worley_distance( localpos, x, y, X, Y, jitter, metric ) ).toVar(); + + If( dist.lessThan( sqdist.x ), () => { + + sqdist.z.assign( sqdist.y ); + sqdist.y.assign( sqdist.x ); + sqdist.x.assign( dist ); + + } ).ElseIf( dist.lessThan( sqdist.y ), () => { + + sqdist.z.assign( sqdist.y ); + sqdist.y.assign( dist ); + + } ).ElseIf( dist.lessThan( sqdist.z ), () => { + + sqdist.z.assign( dist ); + + } ); + + } ); + + } ); + + If( metric.equal( int( 0 ) ), () => { + + sqdist.assign( sqrt( sqdist ) ); + + } ); + + return sqdist; + +} ).setLayout( { + name: 'mx_worley_noise_vec3_0', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec2' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_noise_float_1 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(), Z = int().toVar(); + const localpos = vec3( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ), mx_floorfrac( p.z, Z ) ).toVar(); + const sqdist = float( 1e6 ).toVar(); + + Loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'z', condition: '<=' }, ( { z } ) => { + + const dist = float( mx_worley_distance( localpos, x, y, z, X, Y, Z, jitter, metric ) ).toVar(); + sqdist.assign( min$1( sqdist, dist ) ); + + } ); + + } ); + + } ); + + If( metric.equal( int( 0 ) ), () => { + + sqdist.assign( sqrt( sqdist ) ); + + } ); + + return sqdist; + +} ).setLayout( { + name: 'mx_worley_noise_float_1', + type: 'float', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_noise_float$1 = /*@__PURE__*/ overloadingFn( [ mx_worley_noise_float_0, mx_worley_noise_float_1 ] ); + +const mx_worley_noise_vec2_1 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(), Z = int().toVar(); + const localpos = vec3( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ), mx_floorfrac( p.z, Z ) ).toVar(); + const sqdist = vec2( 1e6, 1e6 ).toVar(); + + Loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'z', condition: '<=' }, ( { z } ) => { + + const dist = float( mx_worley_distance( localpos, x, y, z, X, Y, Z, jitter, metric ) ).toVar(); + + If( dist.lessThan( sqdist.x ), () => { + + sqdist.y.assign( sqdist.x ); + sqdist.x.assign( dist ); + + } ).ElseIf( dist.lessThan( sqdist.y ), () => { + + sqdist.y.assign( dist ); + + } ); + + } ); + + } ); + + } ); + + If( metric.equal( int( 0 ) ), () => { + + sqdist.assign( sqrt( sqdist ) ); + + } ); + + return sqdist; + +} ).setLayout( { + name: 'mx_worley_noise_vec2_1', + type: 'vec2', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_noise_vec2$1 = /*@__PURE__*/ overloadingFn( [ mx_worley_noise_vec2_0, mx_worley_noise_vec2_1 ] ); + +const mx_worley_noise_vec3_1 = /*@__PURE__*/ Fn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => { + + const metric = int( metric_immutable ).toVar(); + const jitter = float( jitter_immutable ).toVar(); + const p = vec3( p_immutable ).toVar(); + const X = int().toVar(), Y = int().toVar(), Z = int().toVar(); + const localpos = vec3( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ), mx_floorfrac( p.z, Z ) ).toVar(); + const sqdist = vec3( 1e6, 1e6, 1e6 ).toVar(); + + Loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => { + + Loop( { start: - 1, end: int( 1 ), name: 'z', condition: '<=' }, ( { z } ) => { + + const dist = float( mx_worley_distance( localpos, x, y, z, X, Y, Z, jitter, metric ) ).toVar(); + + If( dist.lessThan( sqdist.x ), () => { + + sqdist.z.assign( sqdist.y ); + sqdist.y.assign( sqdist.x ); + sqdist.x.assign( dist ); + + } ).ElseIf( dist.lessThan( sqdist.y ), () => { + + sqdist.z.assign( sqdist.y ); + sqdist.y.assign( dist ); + + } ).ElseIf( dist.lessThan( sqdist.z ), () => { + + sqdist.z.assign( dist ); + + } ); + + } ); + + } ); + + } ); + + If( metric.equal( int( 0 ) ), () => { + + sqdist.assign( sqrt( sqdist ) ); + + } ); + + return sqdist; + +} ).setLayout( { + name: 'mx_worley_noise_vec3_1', + type: 'vec3', + inputs: [ + { name: 'p', type: 'vec3' }, + { name: 'jitter', type: 'float' }, + { name: 'metric', type: 'int' } + ] +} ); + +const mx_worley_noise_vec3$1 = /*@__PURE__*/ overloadingFn( [ mx_worley_noise_vec3_0, mx_worley_noise_vec3_1 ] ); + +// Three.js Transpiler +// https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/genglsl/lib/mx_hsv.glsl + + +const mx_hsvtorgb = /*@__PURE__*/ Fn( ( [ hsv ] ) => { + + const s = hsv.y; + const v = hsv.z; + + const result = vec3().toVar(); + + If( s.lessThan( 0.0001 ), () => { + + result.assign( vec3( v, v, v ) ); + + } ).Else( () => { + + let h = hsv.x; + h = h.sub( floor( h ) ).mul( 6.0 ).toVar(); // TODO: check what .toVar() is needed in node system cache + const hi = int( trunc( h ) ); + const f = h.sub( float( hi ) ); + const p = v.mul( s.oneMinus() ); + const q = v.mul( s.mul( f ).oneMinus() ); + const t = v.mul( s.mul( f.oneMinus() ).oneMinus() ); + + If( hi.equal( int( 0 ) ), () => { + + result.assign( vec3( v, t, p ) ); + + } ).ElseIf( hi.equal( int( 1 ) ), () => { + + result.assign( vec3( q, v, p ) ); + + } ).ElseIf( hi.equal( int( 2 ) ), () => { + + result.assign( vec3( p, v, t ) ); + + } ).ElseIf( hi.equal( int( 3 ) ), () => { + + result.assign( vec3( p, q, v ) ); + + } ).ElseIf( hi.equal( int( 4 ) ), () => { + + result.assign( vec3( t, p, v ) ); + + } ).Else( () => { + + result.assign( vec3( v, p, q ) ); + + } ); + + } ); + + return result; + +} ).setLayout( { + name: 'mx_hsvtorgb', + type: 'vec3', + inputs: [ + { name: 'hsv', type: 'vec3' } + ] +} ); + +const mx_rgbtohsv = /*@__PURE__*/ Fn( ( [ c_immutable ] ) => { + + const c = vec3( c_immutable ).toVar(); + const r = float( c.x ).toVar(); + const g = float( c.y ).toVar(); + const b = float( c.z ).toVar(); + const mincomp = float( min$1( r, min$1( g, b ) ) ).toVar(); + const maxcomp = float( max$1( r, max$1( g, b ) ) ).toVar(); + const delta = float( maxcomp.sub( mincomp ) ).toVar(); + const h = float().toVar(), s = float().toVar(), v = float().toVar(); + v.assign( maxcomp ); + + If( maxcomp.greaterThan( 0.0 ), () => { + + s.assign( delta.div( maxcomp ) ); + + } ).Else( () => { + + s.assign( 0.0 ); + + } ); + + If( s.lessThanEqual( 0.0 ), () => { + + h.assign( 0.0 ); + + } ).Else( () => { + + If( r.greaterThanEqual( maxcomp ), () => { + + h.assign( g.sub( b ).div( delta ) ); + + } ).ElseIf( g.greaterThanEqual( maxcomp ), () => { + + h.assign( add( 2.0, b.sub( r ).div( delta ) ) ); + + } ).Else( () => { + + h.assign( add( 4.0, r.sub( g ).div( delta ) ) ); + + } ); + + h.mulAssign( 1.0 / 6.0 ); + + If( h.lessThan( 0.0 ), () => { + + h.addAssign( 1.0 ); + + } ); + + } ); + + return vec3( h, s, v ); + +} ).setLayout( { + name: 'mx_rgbtohsv', + type: 'vec3', + inputs: [ + { name: 'c', type: 'vec3' } + ] +} ); + +// Three.js Transpiler +// https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/genglsl/lib/mx_transform_color.glsl + + +const mx_srgb_texture_to_lin_rec709 = /*@__PURE__*/ Fn( ( [ color_immutable ] ) => { + + const color = vec3( color_immutable ).toVar(); + const isAbove = bvec3( greaterThan( color, vec3( 0.04045 ) ) ).toVar(); + const linSeg = vec3( color.div( 12.92 ) ).toVar(); + const powSeg = vec3( pow( max$1( color.add( vec3( 0.055 ) ), vec3( 0.0 ) ).div( 1.055 ), vec3( 2.4 ) ) ).toVar(); + + return mix( linSeg, powSeg, isAbove ); + +} ).setLayout( { + name: 'mx_srgb_texture_to_lin_rec709', + type: 'vec3', + inputs: [ + { name: 'color', type: 'vec3' } + ] +} ); + +const mx_aastep = ( threshold, value ) => { + + threshold = float( threshold ); + value = float( value ); + + const afwidth = vec2( value.dFdx(), value.dFdy() ).length().mul( 0.70710678118654757 ); + + return smoothstep( threshold.sub( afwidth ), threshold.add( afwidth ), value ); + +}; + +const _ramp = ( a, b, uv, p ) => mix( a, b, uv[ p ].clamp() ); +const mx_ramplr = ( valuel, valuer, texcoord = uv() ) => _ramp( valuel, valuer, texcoord, 'x' ); +const mx_ramptb = ( valuet, valueb, texcoord = uv() ) => _ramp( valuet, valueb, texcoord, 'y' ); + +const _split = ( a, b, center, uv, p ) => mix( a, b, mx_aastep( center, uv[ p ] ) ); +const mx_splitlr = ( valuel, valuer, center, texcoord = uv() ) => _split( valuel, valuer, center, texcoord, 'x' ); +const mx_splittb = ( valuet, valueb, center, texcoord = uv() ) => _split( valuet, valueb, center, texcoord, 'y' ); + +const mx_transform_uv = ( uv_scale = 1, uv_offset = 0, uv_geo = uv() ) => uv_geo.mul( uv_scale ).add( uv_offset ); + +const mx_safepower = ( in1, in2 = 1 ) => { + + in1 = float( in1 ); + + return in1.abs().pow( in2 ).mul( in1.sign() ); + +}; + +const mx_contrast = ( input, amount = 1, pivot = .5 ) => float( input ).sub( pivot ).mul( amount ).add( pivot ); + +const mx_noise_float = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => mx_perlin_noise_float( texcoord.convert( 'vec2|vec3' ) ).mul( amplitude ).add( pivot ); +//export const mx_noise_vec2 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => mx_perlin_noise_vec3( texcoord.convert( 'vec2|vec3' ) ).mul( amplitude ).add( pivot ); +const mx_noise_vec3 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => mx_perlin_noise_vec3( texcoord.convert( 'vec2|vec3' ) ).mul( amplitude ).add( pivot ); +const mx_noise_vec4 = ( texcoord = uv(), amplitude = 1, pivot = 0 ) => { + + texcoord = texcoord.convert( 'vec2|vec3' ); // overloading type + + const noise_vec4 = vec4( mx_perlin_noise_vec3( texcoord ), mx_perlin_noise_float( texcoord.add( vec2( 19, 73 ) ) ) ); + + return noise_vec4.mul( amplitude ).add( pivot ); + +}; + +const mx_worley_noise_float = ( texcoord = uv(), jitter = 1 ) => mx_worley_noise_float$1( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) ); +const mx_worley_noise_vec2 = ( texcoord = uv(), jitter = 1 ) => mx_worley_noise_vec2$1( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) ); +const mx_worley_noise_vec3 = ( texcoord = uv(), jitter = 1 ) => mx_worley_noise_vec3$1( texcoord.convert( 'vec2|vec3' ), jitter, int( 1 ) ); + +const mx_cell_noise_float = ( texcoord = uv() ) => mx_cell_noise_float$1( texcoord.convert( 'vec2|vec3' ) ); + +const mx_fractal_noise_float = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => mx_fractal_noise_float$1( position, int( octaves ), lacunarity, diminish ).mul( amplitude ); +const mx_fractal_noise_vec2 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => mx_fractal_noise_vec2$1( position, int( octaves ), lacunarity, diminish ).mul( amplitude ); +const mx_fractal_noise_vec3 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => mx_fractal_noise_vec3$1( position, int( octaves ), lacunarity, diminish ).mul( amplitude ); +const mx_fractal_noise_vec4 = ( position = uv(), octaves = 3, lacunarity = 2, diminish = .5, amplitude = 1 ) => mx_fractal_noise_vec4$1( position, int( octaves ), lacunarity, diminish ).mul( amplitude ); + +// https://devlog-martinsh.blogspot.com/2011/09/box-projected-cube-environment-mapping.html + +const getParallaxCorrectNormal = /*@__PURE__*/ Fn( ( [ normal, cubeSize, cubePos ] ) => { + + const nDir = normalize( normal ).toVar( 'nDir' ); + const rbmax = sub( float( 0.5 ).mul( cubeSize.sub( cubePos ) ), positionWorld ).div( nDir ).toVar( 'rbmax' ); + const rbmin = sub( float( - 0.5 ).mul( cubeSize.sub( cubePos ) ), positionWorld ).div( nDir ).toVar( 'rbmin' ); + const rbminmax = vec3().toVar( 'rbminmax' ); + rbminmax.x = nDir.x.greaterThan( float( 0 ) ).select( rbmax.x, rbmin.x ); + rbminmax.y = nDir.y.greaterThan( float( 0 ) ).select( rbmax.y, rbmin.y ); + rbminmax.z = nDir.z.greaterThan( float( 0 ) ).select( rbmax.z, rbmin.z ); + + const correction = min$1( min$1( rbminmax.x, rbminmax.y ), rbminmax.z ).toVar( 'correction' ); + const boxIntersection = positionWorld.add( nDir.mul( correction ) ).toVar( 'boxIntersection' ); + return boxIntersection.sub( cubePos ); + +} ); + +const getShIrradianceAt = /*@__PURE__*/ Fn( ( [ normal, shCoefficients ] ) => { + + // normal is assumed to have unit length + + const x = normal.x, y = normal.y, z = normal.z; + + // band 0 + let result = shCoefficients.element( 0 ).mul( 0.886227 ); + + // band 1 + result = result.add( shCoefficients.element( 1 ).mul( 2.0 * 0.511664 ).mul( y ) ); + result = result.add( shCoefficients.element( 2 ).mul( 2.0 * 0.511664 ).mul( z ) ); + result = result.add( shCoefficients.element( 3 ).mul( 2.0 * 0.511664 ).mul( x ) ); + + // band 2 + result = result.add( shCoefficients.element( 4 ).mul( 2.0 * 0.429043 ).mul( x ).mul( y ) ); + result = result.add( shCoefficients.element( 5 ).mul( 2.0 * 0.429043 ).mul( y ).mul( z ) ); + result = result.add( shCoefficients.element( 6 ).mul( z.mul( z ).mul( 0.743125 ).sub( 0.247708 ) ) ); + result = result.add( shCoefficients.element( 7 ).mul( 2.0 * 0.429043 ).mul( x ).mul( z ) ); + result = result.add( shCoefficients.element( 8 ).mul( 0.429043 ).mul( mul( x, x ).sub( mul( y, y ) ) ) ); + + return result; + +} ); + +// constants + +var TSL = /*#__PURE__*/Object.freeze({ + __proto__: null, + BRDF_GGX: BRDF_GGX, + BRDF_Lambert: BRDF_Lambert, + BasicShadowFilter: BasicShadowFilter, + Break: Break, + Continue: Continue, + DFGApprox: DFGApprox, + D_GGX: D_GGX, + Discard: Discard, + EPSILON: EPSILON, + F_Schlick: F_Schlick, + Fn: Fn, + INFINITY: INFINITY, + If: If, + Loop: Loop, + NodeAccess: NodeAccess, + NodeShaderStage: NodeShaderStage, + NodeType: NodeType, + NodeUpdateType: NodeUpdateType, + PCFShadowFilter: PCFShadowFilter, + PCFSoftShadowFilter: PCFSoftShadowFilter, + PI: PI, + PI2: PI2, + Return: Return, + Schlick_to_F0: Schlick_to_F0, + ScriptableNodeResources: ScriptableNodeResources, + ShaderNode: ShaderNode, + TBNViewMatrix: TBNViewMatrix, + VSMShadowFilter: VSMShadowFilter, + V_GGX_SmithCorrelated: V_GGX_SmithCorrelated, + abs: abs, + acesFilmicToneMapping: acesFilmicToneMapping, + acos: acos, + add: add, + addMethodChaining: addMethodChaining, + addNodeElement: addNodeElement, + agxToneMapping: agxToneMapping, + all: all, + alphaT: alphaT, + and: and, + anisotropy: anisotropy, + anisotropyB: anisotropyB, + anisotropyT: anisotropyT, + any: any, + append: append, + arrayBuffer: arrayBuffer, + asin: asin, + assign: assign, + atan: atan, + atan2: atan2, + atomicAdd: atomicAdd, + atomicAnd: atomicAnd, + atomicFunc: atomicFunc, + atomicMax: atomicMax, + atomicMin: atomicMin, + atomicOr: atomicOr, + atomicStore: atomicStore, + atomicSub: atomicSub, + atomicXor: atomicXor, + attenuationColor: attenuationColor, + attenuationDistance: attenuationDistance, + attribute: attribute, + attributeArray: attributeArray, + backgroundBlurriness: backgroundBlurriness, + backgroundIntensity: backgroundIntensity, + backgroundRotation: backgroundRotation, + batch: batch, + billboarding: billboarding, + bitAnd: bitAnd, + bitNot: bitNot, + bitOr: bitOr, + bitXor: bitXor, + bitangentGeometry: bitangentGeometry, + bitangentLocal: bitangentLocal, + bitangentView: bitangentView, + bitangentWorld: bitangentWorld, + bitcast: bitcast, + blendBurn: blendBurn, + blendColor: blendColor, + blendDodge: blendDodge, + blendOverlay: blendOverlay, + blendScreen: blendScreen, + blur: blur, + bool: bool, + buffer: buffer, + bufferAttribute: bufferAttribute, + bumpMap: bumpMap, + burn: burn, + bvec2: bvec2, + bvec3: bvec3, + bvec4: bvec4, + bypass: bypass, + cache: cache, + call: call, + cameraFar: cameraFar, + cameraNear: cameraNear, + cameraNormalMatrix: cameraNormalMatrix, + cameraPosition: cameraPosition, + cameraProjectionMatrix: cameraProjectionMatrix, + cameraProjectionMatrixInverse: cameraProjectionMatrixInverse, + cameraViewMatrix: cameraViewMatrix, + cameraWorldMatrix: cameraWorldMatrix, + cbrt: cbrt, + cdl: cdl, + ceil: ceil, + checker: checker, + cineonToneMapping: cineonToneMapping, + clamp: clamp, + clearcoat: clearcoat, + clearcoatRoughness: clearcoatRoughness, + code: code, + color: color, + colorSpaceToWorking: colorSpaceToWorking, + colorToDirection: colorToDirection, + compute: compute, + cond: cond, + context: context, + convert: convert, + convertColorSpace: convertColorSpace, + convertToTexture: convertToTexture, + cos: cos, + cross: cross, + cubeTexture: cubeTexture, + dFdx: dFdx, + dFdy: dFdy, + dashSize: dashSize, + defaultBuildStages: defaultBuildStages, + defaultShaderStages: defaultShaderStages, + defined: defined, + degrees: degrees, + deltaTime: deltaTime, + densityFog: densityFog, + depth: depth, + depthPass: depthPass, + difference: difference, + diffuseColor: diffuseColor, + directPointLight: directPointLight, + directionToColor: directionToColor, + dispersion: dispersion, + distance: distance, + div: div, + dodge: dodge, + dot: dot, + drawIndex: drawIndex, + dynamicBufferAttribute: dynamicBufferAttribute, + element: element, + emissive: emissive, + equal: equal, + equals: equals, + equirectUV: equirectUV, + exp: exp, + exp2: exp2, + expression: expression, + faceDirection: faceDirection, + faceForward: faceForward, + float: float, + floor: floor, + fog: fog, + fract: fract, + frameGroup: frameGroup, + frameId: frameId, + frontFacing: frontFacing, + fwidth: fwidth, + gain: gain, + gapSize: gapSize, + getConstNodeType: getConstNodeType, + getCurrentStack: getCurrentStack, + getDirection: getDirection, + getDistanceAttenuation: getDistanceAttenuation, + getGeometryRoughness: getGeometryRoughness, + getNormalFromDepth: getNormalFromDepth, + getParallaxCorrectNormal: getParallaxCorrectNormal, + getRoughness: getRoughness, + getScreenPosition: getScreenPosition, + getShIrradianceAt: getShIrradianceAt, + getTextureIndex: getTextureIndex, + getViewPosition: getViewPosition, + glsl: glsl, + glslFn: glslFn, + grayscale: grayscale, + greaterThan: greaterThan, + greaterThanEqual: greaterThanEqual, + hash: hash, + highPrecisionModelNormalViewMatrix: highPrecisionModelNormalViewMatrix, + highPrecisionModelViewMatrix: highPrecisionModelViewMatrix, + hue: hue, + instance: instance, + instanceIndex: instanceIndex, + instancedArray: instancedArray, + instancedBufferAttribute: instancedBufferAttribute, + instancedDynamicBufferAttribute: instancedDynamicBufferAttribute, + instancedMesh: instancedMesh, + int: int, + inverseSqrt: inverseSqrt, + invocationLocalIndex: invocationLocalIndex, + invocationSubgroupIndex: invocationSubgroupIndex, + ior: ior, + iridescence: iridescence, + iridescenceIOR: iridescenceIOR, + iridescenceThickness: iridescenceThickness, + ivec2: ivec2, + ivec3: ivec3, + ivec4: ivec4, + js: js, + label: label, + length: length, + lengthSq: lengthSq, + lessThan: lessThan, + lessThanEqual: lessThanEqual, + lightPosition: lightPosition, + lightProjectionUV: lightProjectionUV, + lightShadowMatrix: lightShadowMatrix, + lightTargetDirection: lightTargetDirection, + lightTargetPosition: lightTargetPosition, + lightViewPosition: lightViewPosition, + lightingContext: lightingContext, + lights: lights, + linearDepth: linearDepth, + linearToneMapping: linearToneMapping, + localId: localId, + log: log, + log2: log2, + logarithmicDepthToViewZ: logarithmicDepthToViewZ, + loop: loop, + luminance: luminance, + mat2: mat2, + mat3: mat3, + mat4: mat4, + matcapUV: matcapUV, + materialAOMap: materialAOMap, + materialAlphaTest: materialAlphaTest, + materialAnisotropy: materialAnisotropy, + materialAnisotropyVector: materialAnisotropyVector, + materialAttenuationColor: materialAttenuationColor, + materialAttenuationDistance: materialAttenuationDistance, + materialClearcoat: materialClearcoat, + materialClearcoatNormal: materialClearcoatNormal, + materialClearcoatRoughness: materialClearcoatRoughness, + materialColor: materialColor, + materialDispersion: materialDispersion, + materialEmissive: materialEmissive, + materialIOR: materialIOR, + materialIridescence: materialIridescence, + materialIridescenceIOR: materialIridescenceIOR, + materialIridescenceThickness: materialIridescenceThickness, + materialLightMap: materialLightMap, + materialLineDashOffset: materialLineDashOffset, + materialLineDashSize: materialLineDashSize, + materialLineGapSize: materialLineGapSize, + materialLineScale: materialLineScale, + materialLineWidth: materialLineWidth, + materialMetalness: materialMetalness, + materialNormal: materialNormal, + materialOpacity: materialOpacity, + materialPointWidth: materialPointWidth, + materialReference: materialReference, + materialReflectivity: materialReflectivity, + materialRefractionRatio: materialRefractionRatio, + materialRotation: materialRotation, + materialRoughness: materialRoughness, + materialSheen: materialSheen, + materialSheenRoughness: materialSheenRoughness, + materialShininess: materialShininess, + materialSpecular: materialSpecular, + materialSpecularColor: materialSpecularColor, + materialSpecularIntensity: materialSpecularIntensity, + materialSpecularStrength: materialSpecularStrength, + materialThickness: materialThickness, + materialTransmission: materialTransmission, + max: max$1, + maxMipLevel: maxMipLevel, + metalness: metalness, + min: min$1, + mix: mix, + mixElement: mixElement, + mod: mod, + modInt: modInt, + modelDirection: modelDirection, + modelNormalMatrix: modelNormalMatrix, + modelPosition: modelPosition, + modelScale: modelScale, + modelViewMatrix: modelViewMatrix, + modelViewPosition: modelViewPosition, + modelViewProjection: modelViewProjection, + modelWorldMatrix: modelWorldMatrix, + modelWorldMatrixInverse: modelWorldMatrixInverse, + morphReference: morphReference, + mrt: mrt, + mul: mul, + mx_aastep: mx_aastep, + mx_cell_noise_float: mx_cell_noise_float, + mx_contrast: mx_contrast, + mx_fractal_noise_float: mx_fractal_noise_float, + mx_fractal_noise_vec2: mx_fractal_noise_vec2, + mx_fractal_noise_vec3: mx_fractal_noise_vec3, + mx_fractal_noise_vec4: mx_fractal_noise_vec4, + mx_hsvtorgb: mx_hsvtorgb, + mx_noise_float: mx_noise_float, + mx_noise_vec3: mx_noise_vec3, + mx_noise_vec4: mx_noise_vec4, + mx_ramplr: mx_ramplr, + mx_ramptb: mx_ramptb, + mx_rgbtohsv: mx_rgbtohsv, + mx_safepower: mx_safepower, + mx_splitlr: mx_splitlr, + mx_splittb: mx_splittb, + mx_srgb_texture_to_lin_rec709: mx_srgb_texture_to_lin_rec709, + mx_transform_uv: mx_transform_uv, + mx_worley_noise_float: mx_worley_noise_float, + mx_worley_noise_vec2: mx_worley_noise_vec2, + mx_worley_noise_vec3: mx_worley_noise_vec3, + negate: negate, + neutralToneMapping: neutralToneMapping, + nodeArray: nodeArray, + nodeImmutable: nodeImmutable, + nodeObject: nodeObject, + nodeObjects: nodeObjects, + nodeProxy: nodeProxy, + normalFlat: normalFlat, + normalGeometry: normalGeometry, + normalLocal: normalLocal, + normalMap: normalMap, + normalView: normalView, + normalWorld: normalWorld, + normalize: normalize, + not: not, + notEqual: notEqual, + numWorkgroups: numWorkgroups, + objectDirection: objectDirection, + objectGroup: objectGroup, + objectPosition: objectPosition, + objectScale: objectScale, + objectViewPosition: objectViewPosition, + objectWorldMatrix: objectWorldMatrix, + oneMinus: oneMinus, + or: or, + orthographicDepthToViewZ: orthographicDepthToViewZ, + oscSawtooth: oscSawtooth, + oscSine: oscSine, + oscSquare: oscSquare, + oscTriangle: oscTriangle, + output: output, + outputStruct: outputStruct, + overlay: overlay, + overloadingFn: overloadingFn, + parabola: parabola, + parallaxDirection: parallaxDirection, + parallaxUV: parallaxUV, + parameter: parameter, + pass: pass, + passTexture: passTexture, + pcurve: pcurve, + perspectiveDepthToViewZ: perspectiveDepthToViewZ, + pmremTexture: pmremTexture, + pointUV: pointUV, + pointWidth: pointWidth, + positionGeometry: positionGeometry, + positionLocal: positionLocal, + positionPrevious: positionPrevious, + positionView: positionView, + positionViewDirection: positionViewDirection, + positionWorld: positionWorld, + positionWorldDirection: positionWorldDirection, + posterize: posterize, + pow: pow, + pow2: pow2, + pow3: pow3, + pow4: pow4, + property: property, + radians: radians, + rand: rand, + range: range, + rangeFog: rangeFog, + reciprocal: reciprocal, + reference: reference, + referenceBuffer: referenceBuffer, + reflect: reflect, + reflectVector: reflectVector, + reflectView: reflectView, + reflector: reflector, + refract: refract, + refractVector: refractVector, + refractView: refractView, + reinhardToneMapping: reinhardToneMapping, + remainder: remainder, + remap: remap, + remapClamp: remapClamp, + renderGroup: renderGroup, + renderOutput: renderOutput, + rendererReference: rendererReference, + rotate: rotate, + rotateUV: rotateUV, + roughness: roughness, + round: round, + rtt: rtt, + sRGBTransferEOTF: sRGBTransferEOTF, + sRGBTransferOETF: sRGBTransferOETF, + sampler: sampler, + saturate: saturate, + saturation: saturation, + screen: screen, + screenCoordinate: screenCoordinate, + screenSize: screenSize, + screenUV: screenUV, + scriptable: scriptable, + scriptableValue: scriptableValue, + select: select, + setCurrentStack: setCurrentStack, + shaderStages: shaderStages, + shadow: shadow, + sharedUniformGroup: sharedUniformGroup, + sheen: sheen, + sheenRoughness: sheenRoughness, + shiftLeft: shiftLeft, + shiftRight: shiftRight, + shininess: shininess, + sign: sign, + sin: sin, + sinc: sinc, + skinning: skinning, + skinningReference: skinningReference, + smoothstep: smoothstep, + smoothstepElement: smoothstepElement, + specularColor: specularColor, + specularF90: specularF90, + spherizeUV: spherizeUV, + split: split, + spritesheetUV: spritesheetUV, + sqrt: sqrt, + stack: stack, + step: step, + storage: storage, + storageBarrier: storageBarrier, + storageObject: storageObject, + storageTexture: storageTexture, + string: string, + sub: sub, + subgroupIndex: subgroupIndex, + subgroupSize: subgroupSize, + tan: tan, + tangentGeometry: tangentGeometry, + tangentLocal: tangentLocal, + tangentView: tangentView, + tangentWorld: tangentWorld, + temp: temp, + texture: texture, + texture3D: texture3D, + textureBarrier: textureBarrier, + textureBicubic: textureBicubic, + textureCubeUV: textureCubeUV, + textureLoad: textureLoad, + textureSize: textureSize, + textureStore: textureStore, + thickness: thickness, + threshold: threshold, + time: time, + timerDelta: timerDelta, + timerGlobal: timerGlobal, + timerLocal: timerLocal, + toOutputColorSpace: toOutputColorSpace, + toWorkingColorSpace: toWorkingColorSpace, + toneMapping: toneMapping, + toneMappingExposure: toneMappingExposure, + toonOutlinePass: toonOutlinePass, + transformDirection: transformDirection, + transformNormal: transformNormal, + transformNormalToView: transformNormalToView, + transformedBentNormalView: transformedBentNormalView, + transformedBitangentView: transformedBitangentView, + transformedBitangentWorld: transformedBitangentWorld, + transformedClearcoatNormalView: transformedClearcoatNormalView, + transformedNormalView: transformedNormalView, + transformedNormalWorld: transformedNormalWorld, + transformedTangentView: transformedTangentView, + transformedTangentWorld: transformedTangentWorld, + transmission: transmission, + transpose: transpose, + tri: tri, + tri3: tri3, + triNoise3D: triNoise3D, + triplanarTexture: triplanarTexture, + triplanarTextures: triplanarTextures, + trunc: trunc, + tslFn: tslFn, + uint: uint, + uniform: uniform, + uniformArray: uniformArray, + uniformGroup: uniformGroup, + uniforms: uniforms, + userData: userData, + uv: uv, + uvec2: uvec2, + uvec3: uvec3, + uvec4: uvec4, + varying: varying, + varyingProperty: varyingProperty, + vec2: vec2, + vec3: vec3, + vec4: vec4, + vectorComponents: vectorComponents, + velocity: velocity, + vertexColor: vertexColor, + vertexIndex: vertexIndex, + vibrance: vibrance, + viewZToLogarithmicDepth: viewZToLogarithmicDepth, + viewZToOrthographicDepth: viewZToOrthographicDepth, + viewZToPerspectiveDepth: viewZToPerspectiveDepth, + viewport: viewport, + viewportBottomLeft: viewportBottomLeft, + viewportCoordinate: viewportCoordinate, + viewportDepthTexture: viewportDepthTexture, + viewportLinearDepth: viewportLinearDepth, + viewportMipTexture: viewportMipTexture, + viewportResolution: viewportResolution, + viewportSafeUV: viewportSafeUV, + viewportSharedTexture: viewportSharedTexture, + viewportSize: viewportSize, + viewportTexture: viewportTexture, + viewportTopLeft: viewportTopLeft, + viewportUV: viewportUV, + wgsl: wgsl, + wgslFn: wgslFn, + workgroupArray: workgroupArray, + workgroupBarrier: workgroupBarrier, + workgroupId: workgroupId, + workingToColorSpace: workingToColorSpace, + xor: xor +}); + +const _clearColor$1 = /*@__PURE__*/ new Color4(); + +class Background extends DataMap { + + constructor( renderer, nodes ) { + + super(); + + this.renderer = renderer; + this.nodes = nodes; + + } + + update( scene, renderList, renderContext ) { + + const renderer = this.renderer; + const background = this.nodes.getBackgroundNode( scene ) || scene.background; + + let forceClear = false; + + if ( background === null ) { + + // no background settings, use clear color configuration from the renderer + + renderer._clearColor.getRGB( _clearColor$1, LinearSRGBColorSpace ); + _clearColor$1.a = renderer._clearColor.a; + + } else if ( background.isColor === true ) { + + // background is an opaque color + + background.getRGB( _clearColor$1, LinearSRGBColorSpace ); + _clearColor$1.a = 1; + + forceClear = true; + + } else if ( background.isNode === true ) { + + const sceneData = this.get( scene ); + const backgroundNode = background; + + _clearColor$1.copy( renderer._clearColor ); + + let backgroundMesh = sceneData.backgroundMesh; + + if ( backgroundMesh === undefined ) { + + const backgroundMeshNode = context( vec4( backgroundNode ).mul( backgroundIntensity ), { + // @TODO: Add Texture2D support using node context + getUV: () => backgroundRotation.mul( normalWorld ), + getTextureLevel: () => backgroundBlurriness + } ); + + let viewProj = modelViewProjection(); + viewProj = viewProj.setZ( viewProj.w ); + + const nodeMaterial = new NodeMaterial(); + nodeMaterial.name = 'Background.material'; + nodeMaterial.side = BackSide; + nodeMaterial.depthTest = false; + nodeMaterial.depthWrite = false; + nodeMaterial.fog = false; + nodeMaterial.lights = false; + nodeMaterial.vertexNode = viewProj; + nodeMaterial.colorNode = backgroundMeshNode; + + sceneData.backgroundMeshNode = backgroundMeshNode; + sceneData.backgroundMesh = backgroundMesh = new Mesh( new SphereGeometry( 1, 32, 32 ), nodeMaterial ); + backgroundMesh.frustumCulled = false; + backgroundMesh.name = 'Background.mesh'; + + backgroundMesh.onBeforeRender = function ( renderer, scene, camera ) { + + this.matrixWorld.copyPosition( camera.matrixWorld ); + + }; + + } + + const backgroundCacheKey = backgroundNode.getCacheKey(); + + if ( sceneData.backgroundCacheKey !== backgroundCacheKey ) { + + sceneData.backgroundMeshNode.node = vec4( backgroundNode ).mul( backgroundIntensity ); + sceneData.backgroundMeshNode.needsUpdate = true; + + backgroundMesh.material.needsUpdate = true; + + sceneData.backgroundCacheKey = backgroundCacheKey; + + } + + renderList.unshift( backgroundMesh, backgroundMesh.geometry, backgroundMesh.material, 0, 0, null, null ); + + } else { + + console.error( 'THREE.Renderer: Unsupported background configuration.', background ); + + } + + // + + if ( renderer.autoClear === true || forceClear === true ) { + + const clearColorValue = renderContext.clearColorValue; + + clearColorValue.r = _clearColor$1.r; + clearColorValue.g = _clearColor$1.g; + clearColorValue.b = _clearColor$1.b; + clearColorValue.a = _clearColor$1.a; + + // premultiply alpha + + if ( renderer.backend.isWebGLBackend === true || renderer.alpha === true ) { + + clearColorValue.r *= clearColorValue.a; + clearColorValue.g *= clearColorValue.a; + clearColorValue.b *= clearColorValue.a; + + } + + // + + renderContext.depthClearValue = renderer._clearDepth; + renderContext.stencilClearValue = renderer._clearStencil; + + renderContext.clearColor = renderer.autoClearColor === true; + renderContext.clearDepth = renderer.autoClearDepth === true; + renderContext.clearStencil = renderer.autoClearStencil === true; + + } else { + + renderContext.clearColor = false; + renderContext.clearDepth = false; + renderContext.clearStencil = false; + + } + + } + +} + +let _id$5 = 0; + +class BindGroup { + + constructor( name = '', bindings = [], index = 0, bindingsReference = [] ) { + + this.name = name; + this.bindings = bindings; + this.index = index; + this.bindingsReference = bindingsReference; + + this.id = _id$5 ++; + + } + +} + +class NodeBuilderState { + + constructor( vertexShader, fragmentShader, computeShader, nodeAttributes, bindings, updateNodes, updateBeforeNodes, updateAfterNodes, monitor, transforms = [] ) { + + this.vertexShader = vertexShader; + this.fragmentShader = fragmentShader; + this.computeShader = computeShader; + this.transforms = transforms; + + this.nodeAttributes = nodeAttributes; + this.bindings = bindings; + + this.updateNodes = updateNodes; + this.updateBeforeNodes = updateBeforeNodes; + this.updateAfterNodes = updateAfterNodes; + + this.monitor = monitor; + + this.usedTimes = 0; + + } + + createBindings() { + + const bindings = []; + + for ( const instanceGroup of this.bindings ) { + + const shared = instanceGroup.bindings[ 0 ].groupNode.shared; + + if ( shared !== true ) { + + const bindingsGroup = new BindGroup( instanceGroup.name, [], instanceGroup.index, instanceGroup ); + bindings.push( bindingsGroup ); + + for ( const instanceBinding of instanceGroup.bindings ) { + + bindingsGroup.bindings.push( instanceBinding.clone() ); + + } + + } else { + + bindings.push( instanceGroup ); + + } + + } + + return bindings; + + } + +} + +class NodeAttribute { + + constructor( name, type, node = null ) { + + this.isNodeAttribute = true; + + this.name = name; + this.type = type; + this.node = node; + + } + +} + +class NodeUniform { + + constructor( name, type, node ) { + + this.isNodeUniform = true; + + this.name = name; + this.type = type; + this.node = node.getSelf(); + + } + + get value() { + + return this.node.value; + + } + + set value( val ) { + + this.node.value = val; + + } + + get id() { + + return this.node.id; + + } + + get groupNode() { + + return this.node.groupNode; + + } + +} + +class NodeVar { + + constructor( name, type ) { + + this.isNodeVar = true; + + this.name = name; + this.type = type; + + } + +} + +class NodeVarying extends NodeVar { + + constructor( name, type ) { + + super( name, type ); + + this.needsInterpolation = false; + + this.isNodeVarying = true; + + } + +} + +class NodeCode { + + constructor( name, type, code = '' ) { + + this.name = name; + this.type = type; + this.code = code; + + Object.defineProperty( this, 'isNodeCode', { value: true } ); + + } + +} + +let id = 0; + +class NodeCache { + + constructor( parent = null ) { + + this.id = id ++; + this.nodesData = new WeakMap(); + + this.parent = parent; + + } + + getData( node ) { + + let data = this.nodesData.get( node ); + + if ( data === undefined && this.parent !== null ) { + + data = this.parent.getData( node ); + + } + + return data; + + } + + setData( node, data ) { + + this.nodesData.set( node, data ); + + } + +} + +class Uniform { + + constructor( name, value ) { + + this.name = name; + this.value = value; + + this.boundary = 0; // used to build the uniform buffer according to the STD140 layout + this.itemSize = 0; + + this.offset = 0; // this property is set by WebGPUUniformsGroup and marks the start position in the uniform buffer + + } + + setValue( value ) { + + this.value = value; + + } + + getValue() { + + return this.value; + + } + +} + +class NumberUniform extends Uniform { + + constructor( name, value = 0 ) { + + super( name, value ); + + this.isNumberUniform = true; + + this.boundary = 4; + this.itemSize = 1; + + } + +} + +class Vector2Uniform extends Uniform { + + constructor( name, value = new Vector2() ) { + + super( name, value ); + + this.isVector2Uniform = true; + + this.boundary = 8; + this.itemSize = 2; + + } + +} + +class Vector3Uniform extends Uniform { + + constructor( name, value = new Vector3() ) { + + super( name, value ); + + this.isVector3Uniform = true; + + this.boundary = 16; + this.itemSize = 3; + + } + +} + +class Vector4Uniform extends Uniform { + + constructor( name, value = new Vector4() ) { + + super( name, value ); + + this.isVector4Uniform = true; + + this.boundary = 16; + this.itemSize = 4; + + } + +} + +class ColorUniform extends Uniform { + + constructor( name, value = new Color() ) { + + super( name, value ); + + this.isColorUniform = true; + + this.boundary = 16; + this.itemSize = 3; + + } + +} + +class Matrix3Uniform extends Uniform { + + constructor( name, value = new Matrix3() ) { + + super( name, value ); + + this.isMatrix3Uniform = true; + + this.boundary = 48; + this.itemSize = 12; + + } + +} + +class Matrix4Uniform extends Uniform { + + constructor( name, value = new Matrix4() ) { + + super( name, value ); + + this.isMatrix4Uniform = true; + + this.boundary = 64; + this.itemSize = 16; + + } + +} + +class NumberNodeUniform extends NumberUniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +class Vector2NodeUniform extends Vector2Uniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +class Vector3NodeUniform extends Vector3Uniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +class Vector4NodeUniform extends Vector4Uniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +class ColorNodeUniform extends ColorUniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +class Matrix3NodeUniform extends Matrix3Uniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +class Matrix4NodeUniform extends Matrix4Uniform { + + constructor( nodeUniform ) { + + super( nodeUniform.name, nodeUniform.value ); + + this.nodeUniform = nodeUniform; + + } + + getValue() { + + return this.nodeUniform.value; + + } + + getType() { + + return this.nodeUniform.type; + + } + +} + +const LOD_MIN = 4; + +// The standard deviations (radians) associated with the extra mips. These are +// chosen to approximate a Trowbridge-Reitz distribution function times the +// geometric shadowing function. These sigma values squared must match the +// variance #defines in cube_uv_reflection_fragment.glsl.js. +const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ]; + +// The maximum length of the blur for loop. Smaller sigmas will use fewer +// samples and exit early, but not recompile the shader. +const MAX_SAMPLES = 20; + +const _flatCamera = /*@__PURE__*/ new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); +const _cubeCamera = /*@__PURE__*/ new PerspectiveCamera( 90, 1 ); +const _clearColor = /*@__PURE__*/ new Color(); +let _oldTarget = null; +let _oldActiveCubeFace = 0; +let _oldActiveMipmapLevel = 0; + +// Golden Ratio +const PHI = ( 1 + Math.sqrt( 5 ) ) / 2; +const INV_PHI = 1 / PHI; + +// Vertices of a dodecahedron (except the opposites, which represent the +// same axis), used as axis directions evenly spread on a sphere. +const _axisDirections = [ + /*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ), + /*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ), + /*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ), + /*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ), + /*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ), + /*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ), + /*@__PURE__*/ new Vector3( - 1, 1, - 1 ), + /*@__PURE__*/ new Vector3( 1, 1, - 1 ), + /*@__PURE__*/ new Vector3( - 1, 1, 1 ), + /*@__PURE__*/ new Vector3( 1, 1, 1 ) +]; + +// + +// WebGPU Face indices +const _faceLib = [ + 3, 1, 5, + 0, 4, 2 +]; + +const direction = getDirection( uv(), attribute( 'faceIndex' ) ).normalize(); +const outputDirection = vec3( direction.x, direction.y.negate(), direction.z ); + +/** + * This class generates a Prefiltered, Mipmapped Radiance Environment Map + * (PMREM) from a cubeMap environment texture. This allows different levels of + * blur to be quickly accessed based on material roughness. It is packed into a + * special CubeUV format that allows us to perform custom interpolation so that + * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap + * chain, it only goes down to the LOD_MIN level (above), and then creates extra + * even more filtered 'mips' at the same LOD_MIN resolution, associated with + * higher roughness levels. In this way we maintain resolution to smoothly + * interpolate diffuse lighting while limiting sampling computation. + * + * Paper: Fast, Accurate Image-Based Lighting + * https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view +*/ + +class PMREMGenerator { + + constructor( renderer ) { + + this._renderer = renderer; + this._pingPongRenderTarget = null; + + this._lodMax = 0; + this._cubeSize = 0; + this._lodPlanes = []; + this._sizeLods = []; + this._sigmas = []; + this._lodMeshes = []; + + this._blurMaterial = null; + this._cubemapMaterial = null; + this._equirectMaterial = null; + this._backgroundBox = null; + + } + + get _hasInitialized() { + + return this._renderer.hasInitialized(); + + } + + /** + * Generates a PMREM from a supplied Scene, which can be faster than using an + * image if networking bandwidth is low. Optional sigma specifies a blur radius + * in radians to be applied to the scene before PMREM generation. Optional near + * and far planes ensure the scene is rendered in its entirety (the cubeCamera + * is placed at the origin). + */ + fromScene( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) { + + this._setSize( 256 ); + + if ( this._hasInitialized === false ) { + + console.warn( 'THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.' ); + + const cubeUVRenderTarget = renderTarget || this._allocateTargets(); + + this.fromSceneAsync( scene, sigma, near, far, cubeUVRenderTarget ); + + return cubeUVRenderTarget; + + } + + _oldTarget = this._renderer.getRenderTarget(); + _oldActiveCubeFace = this._renderer.getActiveCubeFace(); + _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); + + const cubeUVRenderTarget = renderTarget || this._allocateTargets(); + cubeUVRenderTarget.depthBuffer = true; + + this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget ); + + if ( sigma > 0 ) { + + this._blur( cubeUVRenderTarget, 0, 0, sigma ); + + } + + this._applyPMREM( cubeUVRenderTarget ); + + this._cleanup( cubeUVRenderTarget ); + + return cubeUVRenderTarget; + + } + + async fromSceneAsync( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) { + + if ( this._hasInitialized === false ) await this._renderer.init(); + + return this.fromScene( scene, sigma, near, far, renderTarget ); + + } + + /** + * Generates a PMREM from an equirectangular texture, which can be either LDR + * or HDR. The ideal input image size is 1k (1024 x 512), + * as this matches best with the 256 x 256 cubemap output. + */ + fromEquirectangular( equirectangular, renderTarget = null ) { + + if ( this._hasInitialized === false ) { + + console.warn( 'THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead.' ); + + this._setSizeFromTexture( equirectangular ); + + const cubeUVRenderTarget = renderTarget || this._allocateTargets(); + + this.fromEquirectangularAsync( equirectangular, cubeUVRenderTarget ); + + return cubeUVRenderTarget; + + } + + return this._fromTexture( equirectangular, renderTarget ); + + } + + async fromEquirectangularAsync( equirectangular, renderTarget = null ) { + + if ( this._hasInitialized === false ) await this._renderer.init(); + + return this._fromTexture( equirectangular, renderTarget ); + + } + + /** + * Generates a PMREM from an cubemap texture, which can be either LDR + * or HDR. The ideal input cube size is 256 x 256, + * as this matches best with the 256 x 256 cubemap output. + */ + fromCubemap( cubemap, renderTarget = null ) { + + if ( this._hasInitialized === false ) { + + console.warn( 'THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead.' ); + + this._setSizeFromTexture( cubemap ); + + const cubeUVRenderTarget = renderTarget || this._allocateTargets(); + + this.fromCubemapAsync( cubemap, renderTarget ); + + return cubeUVRenderTarget; + + } + + return this._fromTexture( cubemap, renderTarget ); + + } + + async fromCubemapAsync( cubemap, renderTarget = null ) { + + if ( this._hasInitialized === false ) await this._renderer.init(); + + return this._fromTexture( cubemap, renderTarget ); + + } + + /** + * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during + * your texture's network fetch for increased concurrency. + */ + async compileCubemapShader() { + + if ( this._cubemapMaterial === null ) { + + this._cubemapMaterial = _getCubemapMaterial(); + await this._compileMaterial( this._cubemapMaterial ); + + } + + } + + /** + * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during + * your texture's network fetch for increased concurrency. + */ + async compileEquirectangularShader() { + + if ( this._equirectMaterial === null ) { + + this._equirectMaterial = _getEquirectMaterial(); + await this._compileMaterial( this._equirectMaterial ); + + } + + } + + /** + * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class, + * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on + * one of them will cause any others to also become unusable. + */ + dispose() { + + this._dispose(); + + if ( this._cubemapMaterial !== null ) this._cubemapMaterial.dispose(); + if ( this._equirectMaterial !== null ) this._equirectMaterial.dispose(); + if ( this._backgroundBox !== null ) { + + this._backgroundBox.geometry.dispose(); + this._backgroundBox.material.dispose(); + + } + + } + + // private interface + + _setSizeFromTexture( texture ) { + + if ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ) { + + this._setSize( texture.image.length === 0 ? 16 : ( texture.image[ 0 ].width || texture.image[ 0 ].image.width ) ); + + } else { // Equirectangular + + this._setSize( texture.image.width / 4 ); + + } + + } + + _setSize( cubeSize ) { + + this._lodMax = Math.floor( Math.log2( cubeSize ) ); + this._cubeSize = Math.pow( 2, this._lodMax ); + + } + + _dispose() { + + if ( this._blurMaterial !== null ) this._blurMaterial.dispose(); + + if ( this._pingPongRenderTarget !== null ) this._pingPongRenderTarget.dispose(); + + for ( let i = 0; i < this._lodPlanes.length; i ++ ) { + + this._lodPlanes[ i ].dispose(); + + } + + } + + _cleanup( outputTarget ) { + + this._renderer.setRenderTarget( _oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel ); + outputTarget.scissorTest = false; + _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height ); + + } + + _fromTexture( texture, renderTarget ) { + + this._setSizeFromTexture( texture ); + + _oldTarget = this._renderer.getRenderTarget(); + _oldActiveCubeFace = this._renderer.getActiveCubeFace(); + _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); + + const cubeUVRenderTarget = renderTarget || this._allocateTargets(); + this._textureToCubeUV( texture, cubeUVRenderTarget ); + this._applyPMREM( cubeUVRenderTarget ); + this._cleanup( cubeUVRenderTarget ); + + return cubeUVRenderTarget; + + } + + _allocateTargets() { + + const width = 3 * Math.max( this._cubeSize, 16 * 7 ); + const height = 4 * this._cubeSize; + + const params = { + magFilter: LinearFilter, + minFilter: LinearFilter, + generateMipmaps: false, + type: HalfFloatType, + format: RGBAFormat, + colorSpace: LinearSRGBColorSpace, + //depthBuffer: false + }; + + const cubeUVRenderTarget = _createRenderTarget( width, height, params ); + + if ( this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height ) { + + if ( this._pingPongRenderTarget !== null ) { + + this._dispose(); + + } + + this._pingPongRenderTarget = _createRenderTarget( width, height, params ); + + const { _lodMax } = this; + ( { sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas, lodMeshes: this._lodMeshes } = _createPlanes( _lodMax ) ); + + this._blurMaterial = _getBlurShader( _lodMax, width, height ); + + } + + return cubeUVRenderTarget; + + } + + async _compileMaterial( material ) { + + const tmpMesh = new Mesh( this._lodPlanes[ 0 ], material ); + await this._renderer.compile( tmpMesh, _flatCamera ); + + } + + _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) { + + const cubeCamera = _cubeCamera; + cubeCamera.near = near; + cubeCamera.far = far; + + // px, py, pz, nx, ny, nz + const upSign = [ - 1, 1, - 1, - 1, - 1, - 1 ]; + const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ]; + + const renderer = this._renderer; + + const originalAutoClear = renderer.autoClear; + + renderer.getClearColor( _clearColor ); + + renderer.autoClear = false; + + let backgroundBox = this._backgroundBox; + + if ( backgroundBox === null ) { + + const backgroundMaterial = new MeshBasicMaterial( { + name: 'PMREM.Background', + side: BackSide, + depthWrite: false, + depthTest: false + } ); + + backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial ); + + } + + let useSolidColor = false; + const background = scene.background; + + if ( background ) { + + if ( background.isColor ) { + + backgroundBox.material.color.copy( background ); + scene.background = null; + useSolidColor = true; + + } + + } else { + + backgroundBox.material.color.copy( _clearColor ); + useSolidColor = true; + + } + + renderer.setRenderTarget( cubeUVRenderTarget ); + + renderer.clear(); + + if ( useSolidColor ) { + + renderer.render( backgroundBox, cubeCamera ); + + } + + for ( let i = 0; i < 6; i ++ ) { + + const col = i % 3; + + if ( col === 0 ) { + + cubeCamera.up.set( 0, upSign[ i ], 0 ); + cubeCamera.lookAt( forwardSign[ i ], 0, 0 ); + + } else if ( col === 1 ) { + + cubeCamera.up.set( 0, 0, upSign[ i ] ); + cubeCamera.lookAt( 0, forwardSign[ i ], 0 ); + + } else { + + cubeCamera.up.set( 0, upSign[ i ], 0 ); + cubeCamera.lookAt( 0, 0, forwardSign[ i ] ); + + } + + const size = this._cubeSize; + + _setViewport( cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size ); + + renderer.render( scene, cubeCamera ); + + } + + renderer.autoClear = originalAutoClear; + scene.background = background; + + } + + _textureToCubeUV( texture, cubeUVRenderTarget ) { + + const renderer = this._renderer; + + const isCubeTexture = ( texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping ); + + if ( isCubeTexture ) { + + if ( this._cubemapMaterial === null ) { + + this._cubemapMaterial = _getCubemapMaterial( texture ); + + } + + } else { + + if ( this._equirectMaterial === null ) { + + this._equirectMaterial = _getEquirectMaterial( texture ); + + } + + } + + const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial; + material.fragmentNode.value = texture; + + const mesh = this._lodMeshes[ 0 ]; + mesh.material = material; + + const size = this._cubeSize; + + _setViewport( cubeUVRenderTarget, 0, 0, 3 * size, 2 * size ); + + renderer.setRenderTarget( cubeUVRenderTarget ); + renderer.render( mesh, _flatCamera ); + + } + + _applyPMREM( cubeUVRenderTarget ) { + + const renderer = this._renderer; + const autoClear = renderer.autoClear; + renderer.autoClear = false; + const n = this._lodPlanes.length; + + for ( let i = 1; i < n; i ++ ) { + + const sigma = Math.sqrt( this._sigmas[ i ] * this._sigmas[ i ] - this._sigmas[ i - 1 ] * this._sigmas[ i - 1 ] ); + + const poleAxis = _axisDirections[ ( n - i - 1 ) % _axisDirections.length ]; + + this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis ); + + } + + renderer.autoClear = autoClear; + + } + + /** + * This is a two-pass Gaussian blur for a cubemap. Normally this is done + * vertically and horizontally, but this breaks down on a cube. Here we apply + * the blur latitudinally (around the poles), and then longitudinally (towards + * the poles) to approximate the orthogonally-separable blur. It is least + * accurate at the poles, but still does a decent job. + */ + _blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) { + + const pingPongRenderTarget = this._pingPongRenderTarget; + + this._halfBlur( + cubeUVRenderTarget, + pingPongRenderTarget, + lodIn, + lodOut, + sigma, + 'latitudinal', + poleAxis ); + + this._halfBlur( + pingPongRenderTarget, + cubeUVRenderTarget, + lodOut, + lodOut, + sigma, + 'longitudinal', + poleAxis ); + + } + + _halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) { + + const renderer = this._renderer; + const blurMaterial = this._blurMaterial; + + if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) { + + console.error( 'blur direction must be either latitudinal or longitudinal!' ); + + } + + // Number of standard deviations at which to cut off the discrete approximation. + const STANDARD_DEVIATIONS = 3; + + const blurMesh = this._lodMeshes[ lodOut ]; + blurMesh.material = blurMaterial; + + const blurUniforms = blurMaterial.uniforms; + + const pixels = this._sizeLods[ lodIn ] - 1; + const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 ); + const sigmaPixels = sigmaRadians / radiansPerPixel; + const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES; + + if ( samples > MAX_SAMPLES ) { + + console.warn( `sigmaRadians, ${ + sigmaRadians}, is too large and will clip, as it requested ${ + samples} samples when the maximum is set to ${MAX_SAMPLES}` ); + + } + + const weights = []; + let sum = 0; + + for ( let i = 0; i < MAX_SAMPLES; ++ i ) { + + const x = i / sigmaPixels; + const weight = Math.exp( - x * x / 2 ); + weights.push( weight ); + + if ( i === 0 ) { + + sum += weight; + + } else if ( i < samples ) { + + sum += 2 * weight; + + } + + } + + for ( let i = 0; i < weights.length; i ++ ) { + + weights[ i ] = weights[ i ] / sum; + + } + + targetIn.texture.frame = ( targetIn.texture.frame || 0 ) + 1; + + blurUniforms.envMap.value = targetIn.texture; + blurUniforms.samples.value = samples; + blurUniforms.weights.array = weights; + blurUniforms.latitudinal.value = direction === 'latitudinal' ? 1 : 0; + + if ( poleAxis ) { + + blurUniforms.poleAxis.value = poleAxis; + + } + + const { _lodMax } = this; + blurUniforms.dTheta.value = radiansPerPixel; + blurUniforms.mipInt.value = _lodMax - lodIn; + + const outputSize = this._sizeLods[ lodOut ]; + const x = 3 * outputSize * ( lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0 ); + const y = 4 * ( this._cubeSize - outputSize ); + + _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize ); + renderer.setRenderTarget( targetOut ); + renderer.render( blurMesh, _flatCamera ); + + } + +} + +function _createPlanes( lodMax ) { + + const lodPlanes = []; + const sizeLods = []; + const sigmas = []; + const lodMeshes = []; + + let lod = lodMax; + + const totalLods = lodMax - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length; + + for ( let i = 0; i < totalLods; i ++ ) { + + const sizeLod = Math.pow( 2, lod ); + sizeLods.push( sizeLod ); + let sigma = 1.0 / sizeLod; + + if ( i > lodMax - LOD_MIN ) { + + sigma = EXTRA_LOD_SIGMA[ i - lodMax + LOD_MIN - 1 ]; + + } else if ( i === 0 ) { + + sigma = 0; + + } + + sigmas.push( sigma ); + + const texelSize = 1.0 / ( sizeLod - 2 ); + const min = - texelSize; + const max = 1 + texelSize; + const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ]; + + const cubeFaces = 6; + const vertices = 6; + const positionSize = 3; + const uvSize = 2; + const faceIndexSize = 1; + + const position = new Float32Array( positionSize * vertices * cubeFaces ); + const uv = new Float32Array( uvSize * vertices * cubeFaces ); + const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces ); + + for ( let face = 0; face < cubeFaces; face ++ ) { + + const x = ( face % 3 ) * 2 / 3 - 1; + const y = face > 2 ? 0 : - 1; + const coordinates = [ + x, y, 0, + x + 2 / 3, y, 0, + x + 2 / 3, y + 1, 0, + x, y, 0, + x + 2 / 3, y + 1, 0, + x, y + 1, 0 + ]; + + const faceIdx = _faceLib[ face ]; + position.set( coordinates, positionSize * vertices * faceIdx ); + uv.set( uv1, uvSize * vertices * faceIdx ); + const fill = [ faceIdx, faceIdx, faceIdx, faceIdx, faceIdx, faceIdx ]; + faceIndex.set( fill, faceIndexSize * vertices * faceIdx ); + + } + + const planes = new BufferGeometry(); + planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) ); + planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) ); + planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) ); + lodPlanes.push( planes ); + lodMeshes.push( new Mesh( planes, null ) ); + + if ( lod > LOD_MIN ) { + + lod --; + + } + + } + + return { lodPlanes, sizeLods, sigmas, lodMeshes }; + +} + +function _createRenderTarget( width, height, params ) { + + const cubeUVRenderTarget = new RenderTarget( width, height, params ); + cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping; + cubeUVRenderTarget.texture.name = 'PMREM.cubeUv'; + cubeUVRenderTarget.texture.isPMREMTexture = true; + cubeUVRenderTarget.scissorTest = true; + return cubeUVRenderTarget; + +} + +function _setViewport( target, x, y, width, height ) { + + target.viewport.set( x, y, width, height ); + target.scissor.set( x, y, width, height ); + +} + +function _getMaterial( type ) { + + const material = new NodeMaterial(); + material.depthTest = false; + material.depthWrite = false; + material.blending = NoBlending; + material.name = `PMREM_${ type }`; + + return material; + +} + +function _getBlurShader( lodMax, width, height ) { + + const weights = uniformArray( new Array( MAX_SAMPLES ).fill( 0 ) ); + const poleAxis = uniform( new Vector3( 0, 1, 0 ) ); + const dTheta = uniform( 0 ); + const n = float( MAX_SAMPLES ); + const latitudinal = uniform( 0 ); // false, bool + const samples = uniform( 1 ); // int + const envMap = texture( null ); + const mipInt = uniform( 0 ); // int + const CUBEUV_TEXEL_WIDTH = float( 1 / width ); + const CUBEUV_TEXEL_HEIGHT = float( 1 / height ); + const CUBEUV_MAX_MIP = float( lodMax ); + + const materialUniforms = { + n, + latitudinal, + weights, + poleAxis, + outputDirection, + dTheta, + samples, + envMap, + mipInt, + CUBEUV_TEXEL_WIDTH, + CUBEUV_TEXEL_HEIGHT, + CUBEUV_MAX_MIP + }; + + const material = _getMaterial( 'blur' ); + material.uniforms = materialUniforms; // TODO: Move to outside of the material + material.fragmentNode = blur( { ...materialUniforms, latitudinal: latitudinal.equal( 1 ) } ); + + return material; + +} + +function _getCubemapMaterial( envTexture ) { + + const material = _getMaterial( 'cubemap' ); + material.fragmentNode = cubeTexture( envTexture, outputDirection ); + + return material; + +} + +function _getEquirectMaterial( envTexture ) { + + const material = _getMaterial( 'equirect' ); + material.fragmentNode = texture( envTexture, equirectUV( outputDirection ), 0 ); + + return material; + +} + +const rendererCache = new WeakMap(); + +const typeFromArray = new Map( [ + [ Int8Array, 'int' ], + [ Int16Array, 'int' ], + [ Int32Array, 'int' ], + [ Uint8Array, 'uint' ], + [ Uint16Array, 'uint' ], + [ Uint32Array, 'uint' ], + [ Float32Array, 'float' ] +] ); + +const toFloat = ( value ) => { + + if ( /e/g.test( value ) ) { + + return String( value ).replace( /\+/g, '' ); + + } else { + + value = Number( value ); + + return value + ( value % 1 ? '' : '.0' ); + + } + +}; + +class NodeBuilder { + + constructor( object, renderer, parser ) { + + this.object = object; + this.material = ( object && object.material ) || null; + this.geometry = ( object && object.geometry ) || null; + this.renderer = renderer; + this.parser = parser; + this.scene = null; + this.camera = null; + + this.nodes = []; + this.sequentialNodes = []; + this.updateNodes = []; + this.updateBeforeNodes = []; + this.updateAfterNodes = []; + this.hashNodes = {}; + + this.monitor = null; + + this.lightsNode = null; + this.environmentNode = null; + this.fogNode = null; + + this.clippingContext = null; + + this.vertexShader = null; + this.fragmentShader = null; + this.computeShader = null; + + this.flowNodes = { vertex: [], fragment: [], compute: [] }; + this.flowCode = { vertex: '', fragment: '', compute: '' }; + this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 }; + this.structs = { vertex: [], fragment: [], compute: [], index: 0 }; + this.bindings = { vertex: {}, fragment: {}, compute: {} }; + this.bindingsIndexes = {}; + this.bindGroups = null; + this.attributes = []; + this.bufferAttributes = []; + this.varyings = []; + this.codes = {}; + this.vars = {}; + this.flow = { code: '' }; + this.chaining = []; + this.stack = stack(); + this.stacks = []; + this.tab = '\t'; + + this.currentFunctionNode = null; + + this.context = { + material: this.material + }; + + this.cache = new NodeCache(); + this.globalCache = this.cache; + + this.flowsData = new WeakMap(); + + this.shaderStage = null; + this.buildStage = null; + + this.useComparisonMethod = false; + + } + + getBindGroupsCache() { + + let bindGroupsCache = rendererCache.get( this.renderer ); + + if ( bindGroupsCache === undefined ) { + + bindGroupsCache = new ChainMap(); + + rendererCache.set( this.renderer, bindGroupsCache ); + + } + + return bindGroupsCache; + + } + + createRenderTarget( width, height, options ) { + + return new RenderTarget( width, height, options ); + + } + + createCubeRenderTarget( size, options ) { + + return new CubeRenderTarget( size, options ); + + } + + createPMREMGenerator() { + + // TODO: Move Materials.js to outside of the Nodes.js in order to remove this function and improve tree-shaking support + + return new PMREMGenerator( this.renderer ); + + } + + includes( node ) { + + return this.nodes.includes( node ); + + } + + _getBindGroup( groupName, bindings ) { + + const bindGroupsCache = this.getBindGroupsCache(); + + // + + const bindingsArray = []; + + let sharedGroup = true; + + for ( const binding of bindings ) { + + bindingsArray.push( binding ); + + sharedGroup = sharedGroup && binding.groupNode.shared !== true; + + } + + // + + let bindGroup; + + if ( sharedGroup ) { + + bindGroup = bindGroupsCache.get( bindingsArray ); + + if ( bindGroup === undefined ) { + + bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray ); + + bindGroupsCache.set( bindingsArray, bindGroup ); + + } + + } else { + + bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray ); + + } + + return bindGroup; + + } + + getBindGroupArray( groupName, shaderStage ) { + + const bindings = this.bindings[ shaderStage ]; + + let bindGroup = bindings[ groupName ]; + + if ( bindGroup === undefined ) { + + if ( this.bindingsIndexes[ groupName ] === undefined ) { + + this.bindingsIndexes[ groupName ] = { binding: 0, group: Object.keys( this.bindingsIndexes ).length }; + + } + + bindings[ groupName ] = bindGroup = []; + + } + + return bindGroup; + + } + + getBindings() { + + let bindingsGroups = this.bindGroups; + + if ( bindingsGroups === null ) { + + const groups = {}; + const bindings = this.bindings; + + for ( const shaderStage of shaderStages ) { + + for ( const groupName in bindings[ shaderStage ] ) { + + const uniforms = bindings[ shaderStage ][ groupName ]; + + const groupUniforms = groups[ groupName ] || ( groups[ groupName ] = [] ); + groupUniforms.push( ...uniforms ); + + } + + } + + bindingsGroups = []; + + for ( const groupName in groups ) { + + const group = groups[ groupName ]; + + const bindingsGroup = this._getBindGroup( groupName, group ); + + bindingsGroups.push( bindingsGroup ); + + } + + this.bindGroups = bindingsGroups; + + } + + return bindingsGroups; + + } + + sortBindingGroups() { + + const bindingsGroups = this.getBindings(); + + bindingsGroups.sort( ( a, b ) => ( a.bindings[ 0 ].groupNode.order - b.bindings[ 0 ].groupNode.order ) ); + + for ( let i = 0; i < bindingsGroups.length; i ++ ) { + + const bindingGroup = bindingsGroups[ i ]; + this.bindingsIndexes[ bindingGroup.name ].group = i; + + bindingGroup.index = i; + + } + + } + + setHashNode( node, hash ) { + + this.hashNodes[ hash ] = node; + + } + + addNode( node ) { + + if ( this.nodes.includes( node ) === false ) { + + this.nodes.push( node ); + + this.setHashNode( node, node.getHash( this ) ); + + } + + } + + addSequentialNode( node ) { + + if ( this.sequentialNodes.includes( node ) === false ) { + + this.sequentialNodes.push( node ); + + } + + } + + buildUpdateNodes() { + + for ( const node of this.nodes ) { + + const updateType = node.getUpdateType(); + + if ( updateType !== NodeUpdateType.NONE ) { + + this.updateNodes.push( node.getSelf() ); + + } + + } + + for ( const node of this.sequentialNodes ) { + + const updateBeforeType = node.getUpdateBeforeType(); + const updateAfterType = node.getUpdateAfterType(); + + if ( updateBeforeType !== NodeUpdateType.NONE ) { + + this.updateBeforeNodes.push( node.getSelf() ); + + } + + if ( updateAfterType !== NodeUpdateType.NONE ) { + + this.updateAfterNodes.push( node.getSelf() ); + + } + + } + + } + + get currentNode() { + + return this.chaining[ this.chaining.length - 1 ]; + + } + + isFilteredTexture( texture ) { + + return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter || + texture.minFilter === LinearFilter || texture.minFilter === LinearMipmapNearestFilter || texture.minFilter === NearestMipmapLinearFilter || texture.minFilter === LinearMipmapLinearFilter ); + + } + + addChain( node ) { + + /* + if ( this.chaining.indexOf( node ) !== - 1 ) { + + console.warn( 'Recursive node: ', node ); + + } + */ + + this.chaining.push( node ); + + } + + removeChain( node ) { + + const lastChain = this.chaining.pop(); + + if ( lastChain !== node ) { + + throw new Error( 'NodeBuilder: Invalid node chaining!' ); + + } + + } + + getMethod( method ) { + + return method; + + } + + getNodeFromHash( hash ) { + + return this.hashNodes[ hash ]; + + } + + addFlow( shaderStage, node ) { + + this.flowNodes[ shaderStage ].push( node ); + + return node; + + } + + setContext( context ) { + + this.context = context; + + } + + getContext() { + + return this.context; + + } + + getSharedContext() { + + ({ ...this.context }); + + return this.context; + + } + + setCache( cache ) { + + this.cache = cache; + + } + + getCache() { + + return this.cache; + + } + + getCacheFromNode( node, parent = true ) { + + const data = this.getDataFromNode( node ); + if ( data.cache === undefined ) data.cache = new NodeCache( parent ? this.getCache() : null ); + + return data.cache; + + } + + isAvailable( /*name*/ ) { + + return false; + + } + + getVertexIndex() { + + console.warn( 'Abstract function.' ); + + } + + getInstanceIndex() { + + console.warn( 'Abstract function.' ); + + } + + getDrawIndex() { + + console.warn( 'Abstract function.' ); + + } + + getFrontFacing() { + + console.warn( 'Abstract function.' ); + + } + + getFragCoord() { + + console.warn( 'Abstract function.' ); + + } + + isFlipY() { + + return false; + + } + + increaseUsage( node ) { + + const nodeData = this.getDataFromNode( node ); + nodeData.usageCount = nodeData.usageCount === undefined ? 1 : nodeData.usageCount + 1; + + return nodeData.usageCount; + + } + + generateTexture( /* texture, textureProperty, uvSnippet */ ) { + + console.warn( 'Abstract function.' ); + + } + + generateTextureLod( /* texture, textureProperty, uvSnippet, levelSnippet */ ) { + + console.warn( 'Abstract function.' ); + + } + + generateConst( type, value = null ) { + + if ( value === null ) { + + if ( type === 'float' || type === 'int' || type === 'uint' ) value = 0; + else if ( type === 'bool' ) value = false; + else if ( type === 'color' ) value = new Color(); + else if ( type === 'vec2' ) value = new Vector2(); + else if ( type === 'vec3' ) value = new Vector3(); + else if ( type === 'vec4' ) value = new Vector4(); + + } + + if ( type === 'float' ) return toFloat( value ); + if ( type === 'int' ) return `${ Math.round( value ) }`; + if ( type === 'uint' ) return value >= 0 ? `${ Math.round( value ) }u` : '0u'; + if ( type === 'bool' ) return value ? 'true' : 'false'; + if ( type === 'color' ) return `${ this.getType( 'vec3' ) }( ${ toFloat( value.r ) }, ${ toFloat( value.g ) }, ${ toFloat( value.b ) } )`; + + const typeLength = this.getTypeLength( type ); + + const componentType = this.getComponentType( type ); + + const generateConst = value => this.generateConst( componentType, value ); + + if ( typeLength === 2 ) { + + return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) } )`; + + } else if ( typeLength === 3 ) { + + return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) } )`; + + } else if ( typeLength === 4 ) { + + return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) }, ${ generateConst( value.w ) } )`; + + } else if ( typeLength > 4 && value && ( value.isMatrix3 || value.isMatrix4 ) ) { + + return `${ this.getType( type ) }( ${ value.elements.map( generateConst ).join( ', ' ) } )`; + + } else if ( typeLength > 4 ) { + + return `${ this.getType( type ) }()`; + + } + + throw new Error( `NodeBuilder: Type '${type}' not found in generate constant attempt.` ); + + } + + getType( type ) { + + if ( type === 'color' ) return 'vec3'; + + return type; + + } + + hasGeometryAttribute( name ) { + + return this.geometry && this.geometry.getAttribute( name ) !== undefined; + + } + + getAttribute( name, type ) { + + const attributes = this.attributes; + + // find attribute + + for ( const attribute of attributes ) { + + if ( attribute.name === name ) { + + return attribute; + + } + + } + + // create a new if no exist + + const attribute = new NodeAttribute( name, type ); + + attributes.push( attribute ); + + return attribute; + + } + + getPropertyName( node/*, shaderStage*/ ) { + + return node.name; + + } + + isVector( type ) { + + return /vec\d/.test( type ); + + } + + isMatrix( type ) { + + return /mat\d/.test( type ); + + } + + isReference( type ) { + + return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D'; + + } + + needsToWorkingColorSpace( /*texture*/ ) { + + return false; + + } + + getComponentTypeFromTexture( texture ) { + + const type = texture.type; + + if ( texture.isDataTexture ) { + + if ( type === IntType ) return 'int'; + if ( type === UnsignedIntType ) return 'uint'; + + } + + return 'float'; + + } + + getElementType( type ) { + + if ( type === 'mat2' ) return 'vec2'; + if ( type === 'mat3' ) return 'vec3'; + if ( type === 'mat4' ) return 'vec4'; + + return this.getComponentType( type ); + + } + + getComponentType( type ) { + + type = this.getVectorType( type ); + + if ( type === 'float' || type === 'bool' || type === 'int' || type === 'uint' ) return type; + + const componentType = /(b|i|u|)(vec|mat)([2-4])/.exec( type ); + + if ( componentType === null ) return null; + + if ( componentType[ 1 ] === 'b' ) return 'bool'; + if ( componentType[ 1 ] === 'i' ) return 'int'; + if ( componentType[ 1 ] === 'u' ) return 'uint'; + + return 'float'; + + } + + getVectorType( type ) { + + if ( type === 'color' ) return 'vec3'; + if ( type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'texture3D' ) return 'vec4'; + + return type; + + } + + getTypeFromLength( length, componentType = 'float' ) { + + if ( length === 1 ) return componentType; + + const baseType = getTypeFromLength( length ); + const prefix = componentType === 'float' ? '' : componentType[ 0 ]; + + return prefix + baseType; + + } + + getTypeFromArray( array ) { + + return typeFromArray.get( array.constructor ); + + } + + getTypeFromAttribute( attribute ) { + + let dataAttribute = attribute; + + if ( attribute.isInterleavedBufferAttribute ) dataAttribute = attribute.data; + + const array = dataAttribute.array; + const itemSize = attribute.itemSize; + const normalized = attribute.normalized; + + let arrayType; + + if ( ! ( attribute instanceof Float16BufferAttribute ) && normalized !== true ) { + + arrayType = this.getTypeFromArray( array ); + + } + + return this.getTypeFromLength( itemSize, arrayType ); + + } + + getTypeLength( type ) { + + const vecType = this.getVectorType( type ); + const vecNum = /vec([2-4])/.exec( vecType ); + + if ( vecNum !== null ) return Number( vecNum[ 1 ] ); + if ( vecType === 'float' || vecType === 'bool' || vecType === 'int' || vecType === 'uint' ) return 1; + if ( /mat2/.test( type ) === true ) return 4; + if ( /mat3/.test( type ) === true ) return 9; + if ( /mat4/.test( type ) === true ) return 16; + + return 0; + + } + + getVectorFromMatrix( type ) { + + return type.replace( 'mat', 'vec' ); + + } + + changeComponentType( type, newComponentType ) { + + return this.getTypeFromLength( this.getTypeLength( type ), newComponentType ); + + } + + getIntegerType( type ) { + + const componentType = this.getComponentType( type ); + + if ( componentType === 'int' || componentType === 'uint' ) return type; + + return this.changeComponentType( type, 'int' ); + + } + + addStack() { + + this.stack = stack( this.stack ); + + this.stacks.push( getCurrentStack() || this.stack ); + setCurrentStack( this.stack ); + + return this.stack; + + } + + removeStack() { + + const lastStack = this.stack; + this.stack = lastStack.parent; + + setCurrentStack( this.stacks.pop() ); + + return lastStack; + + } + + getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) { + + cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache; + + let nodeData = cache.getData( node ); + + if ( nodeData === undefined ) { + + nodeData = {}; + + cache.setData( node, nodeData ); + + } + + if ( nodeData[ shaderStage ] === undefined ) nodeData[ shaderStage ] = {}; + + return nodeData[ shaderStage ]; + + } + + getNodeProperties( node, shaderStage = 'any' ) { + + const nodeData = this.getDataFromNode( node, shaderStage ); + + return nodeData.properties || ( nodeData.properties = { outputNode: null } ); + + } + + getBufferAttributeFromNode( node, type ) { + + const nodeData = this.getDataFromNode( node ); + + let bufferAttribute = nodeData.bufferAttribute; + + if ( bufferAttribute === undefined ) { + + const index = this.uniforms.index ++; + + bufferAttribute = new NodeAttribute( 'nodeAttribute' + index, type, node ); + + this.bufferAttributes.push( bufferAttribute ); + + nodeData.bufferAttribute = bufferAttribute; + + } + + return bufferAttribute; + + } + + getStructTypeFromNode( node, shaderStage = this.shaderStage ) { + + const nodeData = this.getDataFromNode( node, shaderStage ); + + if ( nodeData.structType === undefined ) { + + const index = this.structs.index ++; + + node.name = `StructType${ index }`; + this.structs[ shaderStage ].push( node ); + + nodeData.structType = node; + + } + + return node; + + } + + getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) { + + const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache ); + + let nodeUniform = nodeData.uniform; + + if ( nodeUniform === undefined ) { + + const index = this.uniforms.index ++; + + nodeUniform = new NodeUniform( name || ( 'nodeUniform' + index ), type, node ); + + this.uniforms[ shaderStage ].push( nodeUniform ); + + nodeData.uniform = nodeUniform; + + } + + return nodeUniform; + + } + + getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage ) { + + const nodeData = this.getDataFromNode( node, shaderStage ); + + let nodeVar = nodeData.variable; + + if ( nodeVar === undefined ) { + + const vars = this.vars[ shaderStage ] || ( this.vars[ shaderStage ] = [] ); + + if ( name === null ) name = 'nodeVar' + vars.length; + + nodeVar = new NodeVar( name, type ); + + vars.push( nodeVar ); + + nodeData.variable = nodeVar; + + } + + return nodeVar; + + } + + getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) { + + const nodeData = this.getDataFromNode( node, 'any' ); + + let nodeVarying = nodeData.varying; + + if ( nodeVarying === undefined ) { + + const varyings = this.varyings; + const index = varyings.length; + + if ( name === null ) name = 'nodeVarying' + index; + + nodeVarying = new NodeVarying( name, type ); + + varyings.push( nodeVarying ); + + nodeData.varying = nodeVarying; + + } + + return nodeVarying; + + } + + getCodeFromNode( node, type, shaderStage = this.shaderStage ) { + + const nodeData = this.getDataFromNode( node ); + + let nodeCode = nodeData.code; + + if ( nodeCode === undefined ) { + + const codes = this.codes[ shaderStage ] || ( this.codes[ shaderStage ] = [] ); + const index = codes.length; + + nodeCode = new NodeCode( 'nodeCode' + index, type ); + + codes.push( nodeCode ); + + nodeData.code = nodeCode; + + } + + return nodeCode; + + } + + addFlowCodeHierarchy( node, nodeBlock ) { + + const { flowCodes, flowCodeBlock } = this.getDataFromNode( node ); + + let needsFlowCode = true; + let nodeBlockHierarchy = nodeBlock; + + while ( nodeBlockHierarchy ) { + + if ( flowCodeBlock.get( nodeBlockHierarchy ) === true ) { + + needsFlowCode = false; + break; + + } + + nodeBlockHierarchy = this.getDataFromNode( nodeBlockHierarchy ).parentNodeBlock; + + } + + if ( needsFlowCode ) { + + for ( const flowCode of flowCodes ) { + + this.addLineFlowCode( flowCode ); + + } + + } + + } + + addLineFlowCodeBlock( node, code, nodeBlock ) { + + const nodeData = this.getDataFromNode( node ); + const flowCodes = nodeData.flowCodes || ( nodeData.flowCodes = [] ); + const codeBlock = nodeData.flowCodeBlock || ( nodeData.flowCodeBlock = new WeakMap() ); + + flowCodes.push( code ); + codeBlock.set( nodeBlock, true ); + + } + + addLineFlowCode( code, node = null ) { + + if ( code === '' ) return this; + + if ( node !== null && this.context.nodeBlock ) { + + this.addLineFlowCodeBlock( node, code, this.context.nodeBlock ); + + } + + code = this.tab + code; + + if ( ! /;\s*$/.test( code ) ) { + + code = code + ';\n'; + + } + + this.flow.code += code; + + return this; + + } + + addFlowCode( code ) { + + this.flow.code += code; + + return this; + + } + + addFlowTab() { + + this.tab += '\t'; + + return this; + + } + + removeFlowTab() { + + this.tab = this.tab.slice( 0, - 1 ); + + return this; + + } + + getFlowData( node/*, shaderStage*/ ) { + + return this.flowsData.get( node ); + + } + + flowNode( node ) { + + const output = node.getNodeType( this ); + + const flowData = this.flowChildNode( node, output ); + + this.flowsData.set( node, flowData ); + + return flowData; + + } + + buildFunctionNode( shaderNode ) { + + const fn = new FunctionNode(); + + const previous = this.currentFunctionNode; + + this.currentFunctionNode = fn; + + fn.code = this.buildFunctionCode( shaderNode ); + + this.currentFunctionNode = previous; + + return fn; + + } + + flowShaderNode( shaderNode ) { + + const layout = shaderNode.layout; + + const inputs = { + [ Symbol.iterator ]() { + + let index = 0; + const values = Object.values( this ); + return { + next: () => ( { + value: values[ index ], + done: index ++ >= values.length + } ) + }; + + } + }; + + for ( const input of layout.inputs ) { + + inputs[ input.name ] = new ParameterNode( input.type, input.name ); + + } + + // + + shaderNode.layout = null; + + const callNode = shaderNode.call( inputs ); + const flowData = this.flowStagesNode( callNode, layout.type ); + + shaderNode.layout = layout; + + return flowData; + + } + + flowStagesNode( node, output = null ) { + + const previousFlow = this.flow; + const previousVars = this.vars; + const previousCache = this.cache; + const previousBuildStage = this.buildStage; + const previousStack = this.stack; + + const flow = { + code: '' + }; + + this.flow = flow; + this.vars = {}; + this.cache = new NodeCache(); + this.stack = stack(); + + for ( const buildStage of defaultBuildStages ) { + + this.setBuildStage( buildStage ); + + flow.result = node.build( this, output ); + + } + + flow.vars = this.getVars( this.shaderStage ); + + this.flow = previousFlow; + this.vars = previousVars; + this.cache = previousCache; + this.stack = previousStack; + + this.setBuildStage( previousBuildStage ); + + return flow; + + } + + getFunctionOperator() { + + return null; + + } + + flowChildNode( node, output = null ) { + + const previousFlow = this.flow; + + const flow = { + code: '' + }; + + this.flow = flow; + + flow.result = node.build( this, output ); + + this.flow = previousFlow; + + return flow; + + } + + flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) { + + const previousShaderStage = this.shaderStage; + + this.setShaderStage( shaderStage ); + + const flowData = this.flowChildNode( node, output ); + + if ( propertyName !== null ) { + + flowData.code += `${ this.tab + propertyName } = ${ flowData.result };\n`; + + } + + this.flowCode[ shaderStage ] = this.flowCode[ shaderStage ] + flowData.code; + + this.setShaderStage( previousShaderStage ); + + return flowData; + + } + + getAttributesArray() { + + return this.attributes.concat( this.bufferAttributes ); + + } + + getAttributes( /*shaderStage*/ ) { + + console.warn( 'Abstract function.' ); + + } + + getVaryings( /*shaderStage*/ ) { + + console.warn( 'Abstract function.' ); + + } + + getVar( type, name ) { + + return `${ this.getType( type ) } ${ name }`; + + } + + getVars( shaderStage ) { + + let snippet = ''; + + const vars = this.vars[ shaderStage ]; + + if ( vars !== undefined ) { + + for ( const variable of vars ) { + + snippet += `${ this.getVar( variable.type, variable.name ) }; `; + + } + + } + + return snippet; + + } + + getUniforms( /*shaderStage*/ ) { + + console.warn( 'Abstract function.' ); + + } + + getCodes( shaderStage ) { + + const codes = this.codes[ shaderStage ]; + + let code = ''; + + if ( codes !== undefined ) { + + for ( const nodeCode of codes ) { + + code += nodeCode.code + '\n'; + + } + + } + + return code; + + } + + getHash() { + + return this.vertexShader + this.fragmentShader + this.computeShader; + + } + + setShaderStage( shaderStage ) { + + this.shaderStage = shaderStage; + + } + + getShaderStage() { + + return this.shaderStage; + + } + + setBuildStage( buildStage ) { + + this.buildStage = buildStage; + + } + + getBuildStage() { + + return this.buildStage; + + } + + buildCode() { + + console.warn( 'Abstract function.' ); + + } + + build() { + + const { object, material, renderer } = this; + + if ( material !== null ) { + + let nodeMaterial = renderer.library.fromMaterial( material ); + + if ( nodeMaterial === null ) { + + console.error( `NodeMaterial: Material "${ material.type }" is not compatible.` ); + + nodeMaterial = new NodeMaterial(); + + } + + nodeMaterial.build( this ); + + } else { + + this.addFlow( 'compute', object ); + + } + + // setup() -> stage 1: create possible new nodes and returns an output reference node + // analyze() -> stage 2: analyze nodes to possible optimization and validation + // generate() -> stage 3: generate shader + + for ( const buildStage of defaultBuildStages ) { + + this.setBuildStage( buildStage ); + + if ( this.context.vertex && this.context.vertex.isNode ) { + + this.flowNodeFromShaderStage( 'vertex', this.context.vertex ); + + } + + for ( const shaderStage of shaderStages ) { + + this.setShaderStage( shaderStage ); + + const flowNodes = this.flowNodes[ shaderStage ]; + + for ( const node of flowNodes ) { + + if ( buildStage === 'generate' ) { + + this.flowNode( node ); + + } else { + + node.build( this ); + + } + + } + + } + + } + + this.setBuildStage( null ); + this.setShaderStage( null ); + + // stage 4: build code for a specific output + + this.buildCode(); + this.buildUpdateNodes(); + + return this; + + } + + getNodeUniform( uniformNode, type ) { + + if ( type === 'float' || type === 'int' || type === 'uint' ) return new NumberNodeUniform( uniformNode ); + if ( type === 'vec2' || type === 'ivec2' || type === 'uvec2' ) return new Vector2NodeUniform( uniformNode ); + if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) return new Vector3NodeUniform( uniformNode ); + if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) return new Vector4NodeUniform( uniformNode ); + if ( type === 'color' ) return new ColorNodeUniform( uniformNode ); + if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode ); + if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode ); + + throw new Error( `Uniform "${type}" not declared.` ); + + } + + createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168 + + throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` ); + + } + + format( snippet, fromType, toType ) { + + fromType = this.getVectorType( fromType ); + toType = this.getVectorType( toType ); + + if ( fromType === toType || toType === null || this.isReference( toType ) ) { + + return snippet; + + } + + const fromTypeLength = this.getTypeLength( fromType ); + const toTypeLength = this.getTypeLength( toType ); + + if ( fromTypeLength === 16 && toTypeLength === 9 ) { + + return `${ this.getType( toType ) }(${ snippet }[0].xyz, ${ snippet }[1].xyz, ${ snippet }[2].xyz)`; + + } + + if ( fromTypeLength === 9 && toTypeLength === 4 ) { + + return `${ this.getType( toType ) }(${ snippet }[0].xy, ${ snippet }[1].xy)`; + + } + + + if ( fromTypeLength > 4 ) { // fromType is matrix-like + + // @TODO: ignore for now + + return snippet; + + } + + if ( toTypeLength > 4 || toTypeLength === 0 ) { // toType is matrix-like or unknown + + // @TODO: ignore for now + + return snippet; + + } + + if ( fromTypeLength === toTypeLength ) { + + return `${ this.getType( toType ) }( ${ snippet } )`; + + } + + if ( fromTypeLength > toTypeLength ) { + + return this.format( `${ snippet }.${ 'xyz'.slice( 0, toTypeLength ) }`, this.getTypeFromLength( toTypeLength, this.getComponentType( fromType ) ), toType ); + + } + + if ( toTypeLength === 4 && fromTypeLength > 1 ) { // toType is vec4-like + + return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec3' ) }, 1.0 )`; + + } + + if ( fromTypeLength === 2 ) { // fromType is vec2-like and toType is vec3-like + + return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec2' ) }, 0.0 )`; + + } + + if ( fromTypeLength === 1 && toTypeLength > 1 && fromType !== this.getComponentType( toType ) ) { // fromType is float-like + + // convert a number value to vector type, e.g: + // vec3( 1u ) -> vec3( float( 1u ) ) + + snippet = `${ this.getType( this.getComponentType( toType ) ) }( ${ snippet } )`; + + } + + return `${ this.getType( toType ) }( ${ snippet } )`; // fromType is float-like + + } + + getSignature() { + + return `// Three.js r${ REVISION } - Node System\n`; + + } + +} + +class NodeFrame { + + constructor() { + + this.time = 0; + this.deltaTime = 0; + + this.frameId = 0; + this.renderId = 0; + + this.startTime = null; + + this.updateMap = new WeakMap(); + this.updateBeforeMap = new WeakMap(); + this.updateAfterMap = new WeakMap(); + + this.renderer = null; + this.material = null; + this.camera = null; + this.object = null; + this.scene = null; + + } + + _getMaps( referenceMap, nodeRef ) { + + let maps = referenceMap.get( nodeRef ); + + if ( maps === undefined ) { + + maps = { + renderMap: new WeakMap(), + frameMap: new WeakMap() + }; + + referenceMap.set( nodeRef, maps ); + + } + + return maps; + + } + + updateBeforeNode( node ) { + + const updateType = node.getUpdateBeforeType(); + const reference = node.updateReference( this ); + + if ( updateType === NodeUpdateType.FRAME ) { + + const { frameMap } = this._getMaps( this.updateBeforeMap, reference ); + + if ( frameMap.get( reference ) !== this.frameId ) { + + if ( node.updateBefore( this ) !== false ) { + + frameMap.set( reference, this.frameId ); + + } + + } + + } else if ( updateType === NodeUpdateType.RENDER ) { + + const { renderMap } = this._getMaps( this.updateBeforeMap, reference ); + + if ( renderMap.get( reference ) !== this.renderId ) { + + if ( node.updateBefore( this ) !== false ) { + + renderMap.set( reference, this.renderId ); + + } + + } + + } else if ( updateType === NodeUpdateType.OBJECT ) { + + node.updateBefore( this ); + + } + + } + + updateAfterNode( node ) { + + const updateType = node.getUpdateAfterType(); + const reference = node.updateReference( this ); + + if ( updateType === NodeUpdateType.FRAME ) { + + const { frameMap } = this._getMaps( this.updateAfterMap, reference ); + + if ( frameMap.get( reference ) !== this.frameId ) { + + if ( node.updateAfter( this ) !== false ) { + + frameMap.set( reference, this.frameId ); + + } + + } + + } else if ( updateType === NodeUpdateType.RENDER ) { + + const { renderMap } = this._getMaps( this.updateAfterMap, reference ); + + if ( renderMap.get( reference ) !== this.renderId ) { + + if ( node.updateAfter( this ) !== false ) { + + renderMap.set( reference, this.renderId ); + + } + + } + + } else if ( updateType === NodeUpdateType.OBJECT ) { + + node.updateAfter( this ); + + } + + } + + updateNode( node ) { + + const updateType = node.getUpdateType(); + const reference = node.updateReference( this ); + + if ( updateType === NodeUpdateType.FRAME ) { + + const { frameMap } = this._getMaps( this.updateMap, reference ); + + if ( frameMap.get( reference ) !== this.frameId ) { + + if ( node.update( this ) !== false ) { + + frameMap.set( reference, this.frameId ); + + } + + } + + } else if ( updateType === NodeUpdateType.RENDER ) { + + const { renderMap } = this._getMaps( this.updateMap, reference ); + + if ( renderMap.get( reference ) !== this.renderId ) { + + if ( node.update( this ) !== false ) { + + renderMap.set( reference, this.renderId ); + + } + + } + + } else if ( updateType === NodeUpdateType.OBJECT ) { + + node.update( this ); + + } + + } + + update() { + + this.frameId ++; + + if ( this.lastTime === undefined ) this.lastTime = performance.now(); + + this.deltaTime = ( performance.now() - this.lastTime ) / 1000; + + this.lastTime = performance.now(); + + this.time += this.deltaTime; + + } + +} + +class NodeFunctionInput { + + constructor( type, name, count = null, qualifier = '', isConst = false ) { + + this.type = type; + this.name = name; + this.count = count; + this.qualifier = qualifier; + this.isConst = isConst; + + } + +} + +NodeFunctionInput.isNodeFunctionInput = true; + +class DirectionalLightNode extends AnalyticLightNode { + + static get type() { + + return 'DirectionalLightNode'; + + } + + constructor( light = null ) { + + super( light ); + + } + + setup( builder ) { + + super.setup( builder ); + + const lightingModel = builder.context.lightingModel; + + const lightColor = this.colorNode; + const lightDirection = lightTargetDirection( this.light ); + const reflectedLight = builder.context.reflectedLight; + + lightingModel.direct( { + lightDirection, + lightColor, + reflectedLight + }, builder.stack, builder ); + + } + +} + +const _matrix41 = /*@__PURE__*/ new Matrix4(); +const _matrix42 = /*@__PURE__*/ new Matrix4(); + +let ltcLib = null; + +class RectAreaLightNode extends AnalyticLightNode { + + static get type() { + + return 'RectAreaLightNode'; + + } + + constructor( light = null ) { + + super( light ); + + this.halfHeight = uniform( new Vector3() ).setGroup( renderGroup ); + this.halfWidth = uniform( new Vector3() ).setGroup( renderGroup ); + + this.updateType = NodeUpdateType.RENDER; + + } + + update( frame ) { + + super.update( frame ); + + const { light } = this; + + const viewMatrix = frame.camera.matrixWorldInverse; + + _matrix42.identity(); + _matrix41.copy( light.matrixWorld ); + _matrix41.premultiply( viewMatrix ); + _matrix42.extractRotation( _matrix41 ); + + this.halfWidth.value.set( light.width * 0.5, 0.0, 0.0 ); + this.halfHeight.value.set( 0.0, light.height * 0.5, 0.0 ); + + this.halfWidth.value.applyMatrix4( _matrix42 ); + this.halfHeight.value.applyMatrix4( _matrix42 ); + + } + + setup( builder ) { + + super.setup( builder ); + + let ltc_1, ltc_2; + + if ( builder.isAvailable( 'float32Filterable' ) ) { + + ltc_1 = texture( ltcLib.LTC_FLOAT_1 ); + ltc_2 = texture( ltcLib.LTC_FLOAT_2 ); + + } else { + + ltc_1 = texture( ltcLib.LTC_HALF_1 ); + ltc_2 = texture( ltcLib.LTC_HALF_2 ); + + } + + const { colorNode, light } = this; + const lightingModel = builder.context.lightingModel; + + const lightPosition = lightViewPosition( light ); + const reflectedLight = builder.context.reflectedLight; + + lightingModel.directRectArea( { + lightColor: colorNode, + lightPosition, + halfWidth: this.halfWidth, + halfHeight: this.halfHeight, + reflectedLight, + ltc_1, + ltc_2 + }, builder.stack, builder ); + + } + + static setLTC( ltc ) { + + ltcLib = ltc; + + } + +} + +class SpotLightNode extends AnalyticLightNode { + + static get type() { + + return 'SpotLightNode'; + + } + + constructor( light = null ) { + + super( light ); + + this.coneCosNode = uniform( 0 ).setGroup( renderGroup ); + this.penumbraCosNode = uniform( 0 ).setGroup( renderGroup ); + + this.cutoffDistanceNode = uniform( 0 ).setGroup( renderGroup ); + this.decayExponentNode = uniform( 0 ).setGroup( renderGroup ); + + } + + update( frame ) { + + super.update( frame ); + + const { light } = this; + + this.coneCosNode.value = Math.cos( light.angle ); + this.penumbraCosNode.value = Math.cos( light.angle * ( 1 - light.penumbra ) ); + + this.cutoffDistanceNode.value = light.distance; + this.decayExponentNode.value = light.decay; + + } + + getSpotAttenuation( angleCosine ) { + + const { coneCosNode, penumbraCosNode } = this; + + return smoothstep( coneCosNode, penumbraCosNode, angleCosine ); + + } + + setup( builder ) { + + super.setup( builder ); + + const lightingModel = builder.context.lightingModel; + + const { colorNode, cutoffDistanceNode, decayExponentNode, light } = this; + + const lVector = lightViewPosition( light ).sub( positionView ); // @TODO: Add it into LightNode + + const lightDirection = lVector.normalize(); + const angleCos = lightDirection.dot( lightTargetDirection( light ) ); + const spotAttenuation = this.getSpotAttenuation( angleCos ); + + const lightDistance = lVector.length(); + + const lightAttenuation = getDistanceAttenuation( { + lightDistance, + cutoffDistance: cutoffDistanceNode, + decayExponent: decayExponentNode + } ); + + let lightColor = colorNode.mul( spotAttenuation ).mul( lightAttenuation ); + + if ( light.map ) { + + const spotLightCoord = lightProjectionUV( light ); + const projectedTexture = texture( light.map, spotLightCoord.xy ).onRenderUpdate( () => light.map ); + + const inSpotLightMap = spotLightCoord.mul( 2. ).sub( 1. ).abs().lessThan( 1. ).all(); + + lightColor = inSpotLightMap.select( lightColor.mul( projectedTexture ), lightColor ); + + } + + const reflectedLight = builder.context.reflectedLight; + + lightingModel.direct( { + lightDirection, + lightColor, + reflectedLight + }, builder.stack, builder ); + + } + +} + +class IESSpotLightNode extends SpotLightNode { + + static get type() { + + return 'IESSpotLightNode'; + + } + + getSpotAttenuation( angleCosine ) { + + const iesMap = this.light.iesMap; + + let spotAttenuation = null; + + if ( iesMap && iesMap.isTexture === true ) { + + const angle = angleCosine.acos().mul( 1.0 / Math.PI ); + + spotAttenuation = texture( iesMap, vec2( angle, 0 ), 0 ).r; + + } else { + + spotAttenuation = super.getSpotAttenuation( angleCosine ); + + } + + return spotAttenuation; + + } + +} + +class AmbientLightNode extends AnalyticLightNode { + + static get type() { + + return 'AmbientLightNode'; + + } + + constructor( light = null ) { + + super( light ); + + } + + setup( { context } ) { + + context.irradiance.addAssign( this.colorNode ); + + } + +} + +class HemisphereLightNode extends AnalyticLightNode { + + static get type() { + + return 'HemisphereLightNode'; + + } + + constructor( light = null ) { + + super( light ); + + this.lightPositionNode = lightPosition( light ); + this.lightDirectionNode = this.lightPositionNode.normalize(); + + this.groundColorNode = uniform( new Color() ).setGroup( renderGroup ); + + } + + update( frame ) { + + const { light } = this; + + super.update( frame ); + + this.lightPositionNode.object3d = light; + + this.groundColorNode.value.copy( light.groundColor ).multiplyScalar( light.intensity ); + + } + + setup( builder ) { + + const { colorNode, groundColorNode, lightDirectionNode } = this; + + const dotNL = normalView.dot( lightDirectionNode ); + const hemiDiffuseWeight = dotNL.mul( 0.5 ).add( 0.5 ); + + const irradiance = mix( groundColorNode, colorNode, hemiDiffuseWeight ); + + builder.context.irradiance.addAssign( irradiance ); + + } + +} + +class LightProbeNode extends AnalyticLightNode { + + static get type() { + + return 'LightProbeNode'; + + } + + constructor( light = null ) { + + super( light ); + + const array = []; + + for ( let i = 0; i < 9; i ++ ) array.push( new Vector3() ); + + this.lightProbe = uniformArray( array ); + + } + + update( frame ) { + + const { light } = this; + + super.update( frame ); + + // + + for ( let i = 0; i < 9; i ++ ) { + + this.lightProbe.array[ i ].copy( light.sh.coefficients[ i ] ).multiplyScalar( light.intensity ); + + } + + } + + setup( builder ) { + + const irradiance = getShIrradianceAt( normalWorld, this.lightProbe ); + + builder.context.irradiance.addAssign( irradiance ); + + } + +} + +class NodeParser { + + parseFunction( /*source*/ ) { + + console.warn( 'Abstract function.' ); + + } + +} + +class NodeFunction { + + constructor( type, inputs, name = '', precision = '' ) { + + this.type = type; + this.inputs = inputs; + this.name = name; + this.precision = precision; + + } + + getCode( /*name = this.name*/ ) { + + console.warn( 'Abstract function.' ); + + } + +} + +NodeFunction.isNodeFunction = true; + +const declarationRegexp$1 = /^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i; +const propertiesRegexp$1 = /[a-z_0-9]+/ig; + +const pragmaMain = '#pragma main'; + +const parse$1 = ( source ) => { + + source = source.trim(); + + const pragmaMainIndex = source.indexOf( pragmaMain ); + + const mainCode = pragmaMainIndex !== - 1 ? source.slice( pragmaMainIndex + pragmaMain.length ) : source; + + const declaration = mainCode.match( declarationRegexp$1 ); + + if ( declaration !== null && declaration.length === 5 ) { + + // tokenizer + + const inputsCode = declaration[ 4 ]; + const propsMatches = []; + + let nameMatch = null; + + while ( ( nameMatch = propertiesRegexp$1.exec( inputsCode ) ) !== null ) { + + propsMatches.push( nameMatch ); + + } + + // parser + + const inputs = []; + + let i = 0; + + while ( i < propsMatches.length ) { + + const isConst = propsMatches[ i ][ 0 ] === 'const'; + + if ( isConst === true ) { + + i ++; + + } + + let qualifier = propsMatches[ i ][ 0 ]; + + if ( qualifier === 'in' || qualifier === 'out' || qualifier === 'inout' ) { + + i ++; + + } else { + + qualifier = ''; + + } + + const type = propsMatches[ i ++ ][ 0 ]; + + let count = Number.parseInt( propsMatches[ i ][ 0 ] ); + + if ( Number.isNaN( count ) === false ) i ++; + else count = null; + + const name = propsMatches[ i ++ ][ 0 ]; + + inputs.push( new NodeFunctionInput( type, name, count, qualifier, isConst ) ); + + } + + // + + const blockCode = mainCode.substring( declaration[ 0 ].length ); + + const name = declaration[ 3 ] !== undefined ? declaration[ 3 ] : ''; + const type = declaration[ 2 ]; + + const precision = declaration[ 1 ] !== undefined ? declaration[ 1 ] : ''; + + const headerCode = pragmaMainIndex !== - 1 ? source.slice( 0, pragmaMainIndex ) : ''; + + return { + type, + inputs, + name, + precision, + inputsCode, + blockCode, + headerCode + }; + + } else { + + throw new Error( 'FunctionNode: Function is not a GLSL code.' ); + + } + +}; + +class GLSLNodeFunction extends NodeFunction { + + constructor( source ) { + + const { type, inputs, name, precision, inputsCode, blockCode, headerCode } = parse$1( source ); + + super( type, inputs, name, precision ); + + this.inputsCode = inputsCode; + this.blockCode = blockCode; + this.headerCode = headerCode; + + } + + getCode( name = this.name ) { + + let code; + + const blockCode = this.blockCode; + + if ( blockCode !== '' ) { + + const { type, inputsCode, headerCode, precision } = this; + + let declarationCode = `${ type } ${ name } ( ${ inputsCode.trim() } )`; + + if ( precision !== '' ) { + + declarationCode = `${ precision } ${ declarationCode }`; + + } + + code = headerCode + declarationCode + blockCode; + + } else { + + // interface function + + code = ''; + + } + + return code; + + } + +} + +class GLSLNodeParser extends NodeParser { + + parseFunction( source ) { + + return new GLSLNodeFunction( source ); + + } + +} + +const outputNodeMap = new WeakMap(); + +class Nodes extends DataMap { + + constructor( renderer, backend ) { + + super(); + + this.renderer = renderer; + this.backend = backend; + this.nodeFrame = new NodeFrame(); + this.nodeBuilderCache = new Map(); + this.callHashCache = new ChainMap(); + this.groupsData = new ChainMap(); + + } + + updateGroup( nodeUniformsGroup ) { + + const groupNode = nodeUniformsGroup.groupNode; + const name = groupNode.name; + + // objectGroup is every updated + + if ( name === objectGroup.name ) return true; + + // renderGroup is updated once per render/compute call + + if ( name === renderGroup.name ) { + + const uniformsGroupData = this.get( nodeUniformsGroup ); + const renderId = this.nodeFrame.renderId; + + if ( uniformsGroupData.renderId !== renderId ) { + + uniformsGroupData.renderId = renderId; + + return true; + + } + + return false; + + } + + // frameGroup is updated once per frame + + if ( name === frameGroup.name ) { + + const uniformsGroupData = this.get( nodeUniformsGroup ); + const frameId = this.nodeFrame.frameId; + + if ( uniformsGroupData.frameId !== frameId ) { + + uniformsGroupData.frameId = frameId; + + return true; + + } + + return false; + + } + + // other groups are updated just when groupNode.needsUpdate is true + + const groupChain = [ groupNode, nodeUniformsGroup ]; + + let groupData = this.groupsData.get( groupChain ); + if ( groupData === undefined ) this.groupsData.set( groupChain, groupData = {} ); + + if ( groupData.version !== groupNode.version ) { + + groupData.version = groupNode.version; + + return true; + + } + + return false; + + } + + getForRenderCacheKey( renderObject ) { + + return renderObject.initialCacheKey; + + } + + getForRender( renderObject ) { + + const renderObjectData = this.get( renderObject ); + + let nodeBuilderState = renderObjectData.nodeBuilderState; + + if ( nodeBuilderState === undefined ) { + + const { nodeBuilderCache } = this; + + const cacheKey = this.getForRenderCacheKey( renderObject ); + + nodeBuilderState = nodeBuilderCache.get( cacheKey ); + + if ( nodeBuilderState === undefined ) { + + const nodeBuilder = this.backend.createNodeBuilder( renderObject.object, this.renderer ); + nodeBuilder.scene = renderObject.scene; + nodeBuilder.material = renderObject.material; + nodeBuilder.camera = renderObject.camera; + nodeBuilder.context.material = renderObject.material; + nodeBuilder.lightsNode = renderObject.lightsNode; + nodeBuilder.environmentNode = this.getEnvironmentNode( renderObject.scene ); + nodeBuilder.fogNode = this.getFogNode( renderObject.scene ); + nodeBuilder.clippingContext = renderObject.clippingContext; + nodeBuilder.build(); + + nodeBuilderState = this._createNodeBuilderState( nodeBuilder ); + + nodeBuilderCache.set( cacheKey, nodeBuilderState ); + + } + + nodeBuilderState.usedTimes ++; + + renderObjectData.nodeBuilderState = nodeBuilderState; + + } + + return nodeBuilderState; + + } + + delete( object ) { + + if ( object.isRenderObject ) { + + const nodeBuilderState = this.get( object ).nodeBuilderState; + nodeBuilderState.usedTimes --; + + if ( nodeBuilderState.usedTimes === 0 ) { + + this.nodeBuilderCache.delete( this.getForRenderCacheKey( object ) ); + + } + + } + + return super.delete( object ); + + } + + getForCompute( computeNode ) { + + const computeData = this.get( computeNode ); + + let nodeBuilderState = computeData.nodeBuilderState; + + if ( nodeBuilderState === undefined ) { + + const nodeBuilder = this.backend.createNodeBuilder( computeNode, this.renderer ); + nodeBuilder.build(); + + nodeBuilderState = this._createNodeBuilderState( nodeBuilder ); + + computeData.nodeBuilderState = nodeBuilderState; + + } + + return nodeBuilderState; + + } + + _createNodeBuilderState( nodeBuilder ) { + + return new NodeBuilderState( + nodeBuilder.vertexShader, + nodeBuilder.fragmentShader, + nodeBuilder.computeShader, + nodeBuilder.getAttributesArray(), + nodeBuilder.getBindings(), + nodeBuilder.updateNodes, + nodeBuilder.updateBeforeNodes, + nodeBuilder.updateAfterNodes, + nodeBuilder.monitor, + nodeBuilder.transforms + ); + + } + + getEnvironmentNode( scene ) { + + return scene.environmentNode || this.get( scene ).environmentNode || null; + + } + + getBackgroundNode( scene ) { + + return scene.backgroundNode || this.get( scene ).backgroundNode || null; + + } + + getFogNode( scene ) { + + return scene.fogNode || this.get( scene ).fogNode || null; + + } + + getCacheKey( scene, lightsNode ) { + + const chain = [ scene, lightsNode ]; + const callId = this.renderer.info.calls; + + let cacheKeyData = this.callHashCache.get( chain ); + + if ( cacheKeyData === undefined || cacheKeyData.callId !== callId ) { + + const environmentNode = this.getEnvironmentNode( scene ); + const fogNode = this.getFogNode( scene ); + + const values = []; + + if ( lightsNode ) values.push( lightsNode.getCacheKey( true ) ); + if ( environmentNode ) values.push( environmentNode.getCacheKey() ); + if ( fogNode ) values.push( fogNode.getCacheKey() ); + + values.push( this.renderer.shadowMap.enabled ? 1 : 0 ); + + cacheKeyData = { + callId, + cacheKey: hashArray( values ) + }; + + this.callHashCache.set( chain, cacheKeyData ); + + } + + return cacheKeyData.cacheKey; + + } + + updateScene( scene ) { + + this.updateEnvironment( scene ); + this.updateFog( scene ); + this.updateBackground( scene ); + + } + + get isToneMappingState() { + + return this.renderer.getRenderTarget() ? false : true; + + } + + updateBackground( scene ) { + + const sceneData = this.get( scene ); + const background = scene.background; + + if ( background ) { + + const forceUpdate = ( scene.backgroundBlurriness === 0 && sceneData.backgroundBlurriness > 0 ) || ( scene.backgroundBlurriness > 0 && sceneData.backgroundBlurriness === 0 ); + + if ( sceneData.background !== background || forceUpdate ) { + + let backgroundNode = null; + + if ( background.isCubeTexture === true || ( background.mapping === EquirectangularReflectionMapping || background.mapping === EquirectangularRefractionMapping || background.mapping === CubeUVReflectionMapping ) ) { + + if ( scene.backgroundBlurriness > 0 || background.mapping === CubeUVReflectionMapping ) { + + backgroundNode = pmremTexture( background ); + + } else { + + let envMap; + + if ( background.isCubeTexture === true ) { + + envMap = cubeTexture( background ); + + } else { + + envMap = texture( background ); + + } + + backgroundNode = cubeMapNode( envMap ); + + } + + } else if ( background.isTexture === true ) { + + backgroundNode = texture( background, screenUV.flipY() ).setUpdateMatrix( true ); + + } else if ( background.isColor !== true ) { + + console.error( 'WebGPUNodes: Unsupported background configuration.', background ); + + } + + sceneData.backgroundNode = backgroundNode; + sceneData.background = background; + sceneData.backgroundBlurriness = scene.backgroundBlurriness; + + } + + } else if ( sceneData.backgroundNode ) { + + delete sceneData.backgroundNode; + delete sceneData.background; + + } + + } + + updateFog( scene ) { + + const sceneData = this.get( scene ); + const fog = scene.fog; + + if ( fog ) { + + if ( sceneData.fog !== fog ) { + + let fogNode = null; + + if ( fog.isFogExp2 ) { + + const color = reference( 'color', 'color', fog ).setGroup( renderGroup ); + const density = reference( 'density', 'float', fog ).setGroup( renderGroup ); + + fogNode = densityFog( color, density ); + + } else if ( fog.isFog ) { + + const color = reference( 'color', 'color', fog ).setGroup( renderGroup ); + const near = reference( 'near', 'float', fog ).setGroup( renderGroup ); + const far = reference( 'far', 'float', fog ).setGroup( renderGroup ); + + fogNode = rangeFog( color, near, far ); + + } else { + + console.error( 'WebGPUNodes: Unsupported fog configuration.', fog ); + + } + + sceneData.fogNode = fogNode; + sceneData.fog = fog; + + } + + } else { + + delete sceneData.fogNode; + delete sceneData.fog; + + } + + } + + updateEnvironment( scene ) { + + const sceneData = this.get( scene ); + const environment = scene.environment; + + if ( environment ) { + + if ( sceneData.environment !== environment ) { + + let environmentNode = null; + + if ( environment.isCubeTexture === true ) { + + environmentNode = cubeTexture( environment ); + + } else if ( environment.isTexture === true ) { + + environmentNode = texture( environment ); + + } else { + + console.error( 'Nodes: Unsupported environment configuration.', environment ); + + } + + sceneData.environmentNode = environmentNode; + sceneData.environment = environment; + + } + + } else if ( sceneData.environmentNode ) { + + delete sceneData.environmentNode; + delete sceneData.environment; + + } + + } + + getNodeFrame( renderer = this.renderer, scene = null, object = null, camera = null, material = null ) { + + const nodeFrame = this.nodeFrame; + nodeFrame.renderer = renderer; + nodeFrame.scene = scene; + nodeFrame.object = object; + nodeFrame.camera = camera; + nodeFrame.material = material; + + return nodeFrame; + + } + + getNodeFrameForRender( renderObject ) { + + return this.getNodeFrame( renderObject.renderer, renderObject.scene, renderObject.object, renderObject.camera, renderObject.material ); + + } + + getOutputCacheKey() { + + const renderer = this.renderer; + + return renderer.toneMapping + ',' + renderer.currentColorSpace; + + } + + hasOutputChange( outputTarget ) { + + const cacheKey = outputNodeMap.get( outputTarget ); + + return cacheKey !== this.getOutputCacheKey(); + + } + + getOutputNode( outputTexture ) { + + const renderer = this.renderer; + const cacheKey = this.getOutputCacheKey(); + + const output = texture( outputTexture, screenUV ).renderOutput( renderer.toneMapping, renderer.currentColorSpace ); + + outputNodeMap.set( outputTexture, cacheKey ); + + return output; + + } + + updateBefore( renderObject ) { + + const nodeBuilder = renderObject.getNodeBuilderState(); + + for ( const node of nodeBuilder.updateBeforeNodes ) { + + // update frame state for each node + + this.getNodeFrameForRender( renderObject ).updateBeforeNode( node ); + + } + + } + + updateAfter( renderObject ) { + + const nodeBuilder = renderObject.getNodeBuilderState(); + + for ( const node of nodeBuilder.updateAfterNodes ) { + + // update frame state for each node + + this.getNodeFrameForRender( renderObject ).updateAfterNode( node ); + + } + + } + + updateForCompute( computeNode ) { + + const nodeFrame = this.getNodeFrame(); + const nodeBuilder = this.getForCompute( computeNode ); + + for ( const node of nodeBuilder.updateNodes ) { + + nodeFrame.updateNode( node ); + + } + + } + + updateForRender( renderObject ) { + + const nodeFrame = this.getNodeFrameForRender( renderObject ); + const nodeBuilder = renderObject.getNodeBuilderState(); + + for ( const node of nodeBuilder.updateNodes ) { + + nodeFrame.updateNode( node ); + + } + + } + + needsRefresh( renderObject ) { + + const nodeFrame = this.getNodeFrameForRender( renderObject ); + const monitor = renderObject.getMonitor(); + + return monitor.needsRefresh( renderObject, nodeFrame ); + + } + + dispose() { + + super.dispose(); + + this.nodeFrame = new NodeFrame(); + this.nodeBuilderCache = new Map(); + + } + +} + +const _plane = /*@__PURE__*/ new Plane(); + +class ClippingContext { + + constructor( parentContext = null ) { + + this.version = 0; + + this.clipIntersection = null; + this.cacheKey = ''; + + + if ( parentContext === null ) { + + this.intersectionPlanes = []; + this.unionPlanes = []; + + this.viewNormalMatrix = new Matrix3(); + this.clippingGroupContexts = new WeakMap(); + + this.shadowPass = false; + + } else { + + this.viewNormalMatrix = parentContext.viewNormalMatrix; + this.clippingGroupContexts = parentContext.clippingGroupContexts; + + this.shadowPass = parentContext.shadowPass; + + this.viewMatrix = parentContext.viewMatrix; + + } + + this.parentVersion = null; + + } + + projectPlanes( source, destination, offset ) { + + const l = source.length; + + for ( let i = 0; i < l; i ++ ) { + + _plane.copy( source[ i ] ).applyMatrix4( this.viewMatrix, this.viewNormalMatrix ); + + const v = destination[ offset + i ]; + const normal = _plane.normal; + + v.x = - normal.x; + v.y = - normal.y; + v.z = - normal.z; + v.w = _plane.constant; + + } + + } + + updateGlobal( scene, camera ) { + + this.shadowPass = ( scene.overrideMaterial !== null && scene.overrideMaterial.isShadowNodeMaterial ); + this.viewMatrix = camera.matrixWorldInverse; + + this.viewNormalMatrix.getNormalMatrix( this.viewMatrix ); + + } + + update( parentContext, clippingGroup ) { + + let update = false; + + if ( parentContext.version !== this.parentVersion ) { + + this.intersectionPlanes = Array.from( parentContext.intersectionPlanes ); + this.unionPlanes = Array.from( parentContext.unionPlanes ); + this.parentVersion = parentContext.version; + + } + + if ( this.clipIntersection !== clippingGroup.clipIntersection ) { + + this.clipIntersection = clippingGroup.clipIntersection; + + if ( this.clipIntersection ) { + + this.unionPlanes.length = parentContext.unionPlanes.length; + + } else { + + this.intersectionPlanes.length = parentContext.intersectionPlanes.length; + + } + + } + + const srcClippingPlanes = clippingGroup.clippingPlanes; + const l = srcClippingPlanes.length; + + let dstClippingPlanes; + let offset; + + if ( this.clipIntersection ) { + + dstClippingPlanes = this.intersectionPlanes; + offset = parentContext.intersectionPlanes.length; + + } else { + + dstClippingPlanes = this.unionPlanes; + offset = parentContext.unionPlanes.length; + + } + + if ( dstClippingPlanes.length !== offset + l ) { + + dstClippingPlanes.length = offset + l; + + for ( let i = 0; i < l; i ++ ) { + + dstClippingPlanes[ offset + i ] = new Vector4(); + + } + + update = true; + + } + + this.projectPlanes( srcClippingPlanes, dstClippingPlanes, offset ); + + if ( update ) { + + this.version ++; + this.cacheKey = `${ this.intersectionPlanes.length }:${ this.unionPlanes.length }`; + + } + + } + + getGroupContext( clippingGroup ) { + + if ( this.shadowPass && ! clippingGroup.clipShadows ) return this; + + let context = this.clippingGroupContexts.get( clippingGroup ); + + if ( context === undefined ) { + + context = new ClippingContext( this ); + this.clippingGroupContexts.set( clippingGroup, context ); + + } + + context.update( this, clippingGroup ); + + return context; + + } + + get unionClippingCount() { + + return this.unionPlanes.length; + + } + +} + +class RenderBundle { + + constructor( scene, camera ) { + + this.scene = scene; + this.camera = camera; + + } + + clone() { + + return Object.assign( new this.constructor(), this ); + + } + +} + +class RenderBundles { + + constructor() { + + this.lists = new ChainMap(); + + } + + get( scene, camera ) { + + const lists = this.lists; + const keys = [ scene, camera ]; + + let list = lists.get( keys ); + + if ( list === undefined ) { + + list = new RenderBundle( scene, camera ); + lists.set( keys, list ); + + } + + return list; + + } + + dispose() { + + this.lists = new ChainMap(); + + } + +} + +class NodeLibrary { + + constructor() { + + this.lightNodes = new WeakMap(); + this.materialNodes = new Map(); + this.toneMappingNodes = new Map(); + + } + + fromMaterial( material ) { + + if ( material.isNodeMaterial ) return material; + + let nodeMaterial = null; + + const nodeMaterialClass = this.getMaterialNodeClass( material.type ); + + if ( nodeMaterialClass !== null ) { + + nodeMaterial = new nodeMaterialClass(); + + for ( const key in material ) { + + nodeMaterial[ key ] = material[ key ]; + + } + + } + + return nodeMaterial; + + } + + addToneMapping( toneMappingNode, toneMapping ) { + + this.addType( toneMappingNode, toneMapping, this.toneMappingNodes ); + + } + + getToneMappingFunction( toneMapping ) { + + return this.toneMappingNodes.get( toneMapping ) || null; + + } + + getMaterialNodeClass( materialType ) { + + return this.materialNodes.get( materialType ) || null; + + } + + addMaterial( materialNodeClass, materialClassType ) { + + this.addType( materialNodeClass, materialClassType, this.materialNodes ); + + } + + getLightNodeClass( light ) { + + return this.lightNodes.get( light ) || null; + + } + + addLight( lightNodeClass, lightClass ) { + + this.addClass( lightNodeClass, lightClass, this.lightNodes ); + + } + + addType( nodeClass, type, library ) { + + if ( library.has( type ) ) { + + console.warn( `Redefinition of node ${ type }` ); + return; + + } + + if ( typeof nodeClass !== 'function' ) throw new Error( `Node class ${ nodeClass.name } is not a class.` ); + if ( typeof type === 'function' || typeof type === 'object' ) throw new Error( `Base class ${ type } is not a class.` ); + + library.set( type, nodeClass ); + + } + + addClass( nodeClass, baseClass, library ) { + + if ( library.has( baseClass ) ) { + + console.warn( `Redefinition of node ${ baseClass.name }` ); + return; + + } + + if ( typeof nodeClass !== 'function' ) throw new Error( `Node class ${ nodeClass.name } is not a class.` ); + if ( typeof baseClass !== 'function' ) throw new Error( `Base class ${ baseClass.name } is not a class.` ); + + library.set( baseClass, nodeClass ); + + } + +} + +const _defaultLights = /*@__PURE__*/ new LightsNode(); + +class Lighting extends ChainMap { + + constructor() { + + super(); + + } + + createNode( lights = [] ) { + + return new LightsNode().setLights( lights ); + + } + + getNode( scene, camera ) { + + // ignore post-processing + + if ( scene.isQuadMesh ) return _defaultLights; + + // tiled lighting + + const keys = [ scene, camera ]; + + let node = this.get( keys ); + + if ( node === undefined ) { + + node = this.createNode(); + this.set( keys, node ); + + } + + return node; + + } + +} + +const _scene = /*@__PURE__*/ new Scene(); +const _drawingBufferSize = /*@__PURE__*/ new Vector2(); +const _screen = /*@__PURE__*/ new Vector4(); +const _frustum = /*@__PURE__*/ new Frustum(); +const _projScreenMatrix = /*@__PURE__*/ new Matrix4(); +const _vector4 = /*@__PURE__*/ new Vector4(); + +class Renderer { + + constructor( backend, parameters = {} ) { + + this.isRenderer = true; + + // + + const { + logarithmicDepthBuffer = false, + alpha = true, + depth = true, + stencil = false, + antialias = false, + samples = 0, + getFallback = null + } = parameters; + + // public + this.domElement = backend.getDomElement(); + + this.backend = backend; + + this.samples = samples || ( antialias === true ) ? 4 : 0; + + this.autoClear = true; + this.autoClearColor = true; + this.autoClearDepth = true; + this.autoClearStencil = true; + + this.alpha = alpha; + + this.logarithmicDepthBuffer = logarithmicDepthBuffer; + + this.outputColorSpace = SRGBColorSpace; + + this.toneMapping = NoToneMapping; + this.toneMappingExposure = 1.0; + + this.sortObjects = true; + + this.depth = depth; + this.stencil = stencil; + + this.info = new Info(); + + this.nodes = { + modelViewMatrix: null, + modelNormalViewMatrix: null + }; + + this.library = new NodeLibrary(); + this.lighting = new Lighting(); + + // internals + + this._getFallback = getFallback; + + this._pixelRatio = 1; + this._width = this.domElement.width; + this._height = this.domElement.height; + + this._viewport = new Vector4( 0, 0, this._width, this._height ); + this._scissor = new Vector4( 0, 0, this._width, this._height ); + this._scissorTest = false; + + this._attributes = null; + this._geometries = null; + this._nodes = null; + this._animation = null; + this._bindings = null; + this._objects = null; + this._pipelines = null; + this._bundles = null; + this._renderLists = null; + this._renderContexts = null; + this._textures = null; + this._background = null; + + this._quad = new QuadMesh( new NodeMaterial() ); + this._quad.material.type = 'Renderer_output'; + + this._currentRenderContext = null; + + this._opaqueSort = null; + this._transparentSort = null; + + this._frameBufferTarget = null; + + const alphaClear = this.alpha === true ? 0 : 1; + + this._clearColor = new Color4( 0, 0, 0, alphaClear ); + this._clearDepth = 1; + this._clearStencil = 0; + + this._renderTarget = null; + this._activeCubeFace = 0; + this._activeMipmapLevel = 0; + + this._mrt = null; + + this._renderObjectFunction = null; + this._currentRenderObjectFunction = null; + this._currentRenderBundle = null; + + this._handleObjectFunction = this._renderObjectDirect; + + this._isDeviceLost = false; + this.onDeviceLost = this._onDeviceLost; + + this._initialized = false; + this._initPromise = null; + + this._compilationPromises = null; + + this.transparent = true; + this.opaque = true; + + this.shadowMap = { + enabled: false, + type: PCFShadowMap + }; + + this.xr = { + enabled: false + }; + + this.debug = { + checkShaderErrors: true, + onShaderError: null, + getShaderAsync: async ( scene, camera, object ) => { + + await this.compileAsync( scene, camera ); + + const renderList = this._renderLists.get( scene, camera ); + const renderContext = this._renderContexts.get( scene, camera, this._renderTarget ); + + const material = scene.overrideMaterial || object.material; + + const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext, renderContext.clippingContext ); + + const { fragmentShader, vertexShader } = renderObject.getNodeBuilderState(); + + return { fragmentShader, vertexShader }; + + } + }; + + } + + async init() { + + if ( this._initialized ) { + + throw new Error( 'Renderer: Backend has already been initialized.' ); + + } + + if ( this._initPromise !== null ) { + + return this._initPromise; + + } + + this._initPromise = new Promise( async ( resolve, reject ) => { + + let backend = this.backend; + + try { + + await backend.init( this ); + + } catch ( error ) { + + if ( this._getFallback !== null ) { + + // try the fallback + + try { + + this.backend = backend = this._getFallback( error ); + await backend.init( this ); + + } catch ( error ) { + + reject( error ); + return; + + } + + } else { + + reject( error ); + return; + + } + + } + + this._nodes = new Nodes( this, backend ); + this._animation = new Animation( this._nodes, this.info ); + this._attributes = new Attributes( backend ); + this._background = new Background( this, this._nodes ); + this._geometries = new Geometries( this._attributes, this.info ); + this._textures = new Textures( this, backend, this.info ); + this._pipelines = new Pipelines( backend, this._nodes ); + this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info ); + this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info ); + this._renderLists = new RenderLists( this.lighting ); + this._bundles = new RenderBundles(); + this._renderContexts = new RenderContexts(); + + // + + this._animation.start(); + this._initialized = true; + + resolve(); + + } ); + + return this._initPromise; + + } + + get coordinateSystem() { + + return this.backend.coordinateSystem; + + } + + async compileAsync( scene, camera, targetScene = null ) { + + if ( this._isDeviceLost === true ) return; + + if ( this._initialized === false ) await this.init(); + + // preserve render tree + + const nodeFrame = this._nodes.nodeFrame; + + const previousRenderId = nodeFrame.renderId; + const previousRenderContext = this._currentRenderContext; + const previousRenderObjectFunction = this._currentRenderObjectFunction; + const previousCompilationPromises = this._compilationPromises; + + // + + const sceneRef = ( scene.isScene === true ) ? scene : _scene; + + if ( targetScene === null ) targetScene = scene; + + const renderTarget = this._renderTarget; + const renderContext = this._renderContexts.get( targetScene, camera, renderTarget ); + const activeMipmapLevel = this._activeMipmapLevel; + + const compilationPromises = []; + + this._currentRenderContext = renderContext; + this._currentRenderObjectFunction = this.renderObject; + + this._handleObjectFunction = this._createObjectPipeline; + + this._compilationPromises = compilationPromises; + + nodeFrame.renderId ++; + + // + + nodeFrame.update(); + + // + + renderContext.depth = this.depth; + renderContext.stencil = this.stencil; + + if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext(); + renderContext.clippingContext.updateGlobal( sceneRef, camera ); + + // + + sceneRef.onBeforeRender( this, scene, camera, renderTarget ); + + // + + const renderList = this._renderLists.get( scene, camera ); + renderList.begin(); + + this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext ); + + // include lights from target scene + if ( targetScene !== scene ) { + + targetScene.traverseVisible( function ( object ) { + + if ( object.isLight && object.layers.test( camera.layers ) ) { + + renderList.pushLight( object ); + + } + + } ); + + } + + renderList.finish(); + + // + + if ( renderTarget !== null ) { + + this._textures.updateRenderTarget( renderTarget, activeMipmapLevel ); + + const renderTargetData = this._textures.get( renderTarget ); + + renderContext.textures = renderTargetData.textures; + renderContext.depthTexture = renderTargetData.depthTexture; + + } else { + + renderContext.textures = null; + renderContext.depthTexture = null; + + } + + // + + this._nodes.updateScene( sceneRef ); + + // + + this._background.update( sceneRef, renderList, renderContext ); + + // process render lists + + const opaqueObjects = renderList.opaque; + const transparentObjects = renderList.transparent; + const transparentDoublePassObjects = renderList.transparentDoublePass; + const lightsNode = renderList.lightsNode; + + if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode ); + if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode ); + + // restore render tree + + nodeFrame.renderId = previousRenderId; + + this._currentRenderContext = previousRenderContext; + this._currentRenderObjectFunction = previousRenderObjectFunction; + this._compilationPromises = previousCompilationPromises; + + this._handleObjectFunction = this._renderObjectDirect; + + // wait for all promises setup by backends awaiting compilation/linking/pipeline creation to complete + + await Promise.all( compilationPromises ); + + } + + async renderAsync( scene, camera ) { + + if ( this._initialized === false ) await this.init(); + + const renderContext = this._renderScene( scene, camera ); + + await this.backend.resolveTimestampAsync( renderContext, 'render' ); + + } + + async waitForGPU() { + + await this.backend.waitForGPU(); + + } + + setMRT( mrt ) { + + this._mrt = mrt; + + return this; + + } + + getMRT() { + + return this._mrt; + + } + + _onDeviceLost( info ) { + + let errorMessage = `THREE.WebGPURenderer: ${info.api} Device Lost:\n\nMessage: ${info.message}`; + + if ( info.reason ) { + + errorMessage += `\nReason: ${info.reason}`; + + } + + console.error( errorMessage ); + + this._isDeviceLost = true; + + } + + + _renderBundle( bundle, sceneRef, lightsNode ) { + + const { bundleGroup, camera, renderList } = bundle; + + const renderContext = this._currentRenderContext; + + // + + const renderBundle = this._bundles.get( bundleGroup, camera ); + const renderBundleData = this.backend.get( renderBundle ); + + if ( renderBundleData.renderContexts === undefined ) renderBundleData.renderContexts = new Set(); + + // + + const needsUpdate = bundleGroup.version !== renderBundleData.version; + const renderBundleNeedsUpdate = renderBundleData.renderContexts.has( renderContext ) === false || needsUpdate; + + renderBundleData.renderContexts.add( renderContext ); + + if ( renderBundleNeedsUpdate ) { + + this.backend.beginBundle( renderContext ); + + if ( renderBundleData.renderObjects === undefined || needsUpdate ) { + + renderBundleData.renderObjects = []; + + } + + this._currentRenderBundle = renderBundle; + + const opaqueObjects = renderList.opaque; + + if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode ); + + this._currentRenderBundle = null; + + // + + this.backend.finishBundle( renderContext, renderBundle ); + + renderBundleData.version = bundleGroup.version; + + } else { + + const { renderObjects } = renderBundleData; + + for ( let i = 0, l = renderObjects.length; i < l; i ++ ) { + + const renderObject = renderObjects[ i ]; + + if ( this._nodes.needsRefresh( renderObject ) ) { + + this._nodes.updateBefore( renderObject ); + + this._nodes.updateForRender( renderObject ); + this._bindings.updateForRender( renderObject ); + + this._nodes.updateAfter( renderObject ); + + } + + } + + } + + this.backend.addBundle( renderContext, renderBundle ); + + } + + render( scene, camera ) { + + if ( this._initialized === false ) { + + console.warn( 'THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead.' ); + + return this.renderAsync( scene, camera ); + + } + + this._renderScene( scene, camera ); + + } + + _getFrameBufferTarget() { + + const { currentToneMapping, currentColorSpace } = this; + + const useToneMapping = currentToneMapping !== NoToneMapping; + const useColorSpace = currentColorSpace !== LinearSRGBColorSpace; + + if ( useToneMapping === false && useColorSpace === false ) return null; + + const { width, height } = this.getDrawingBufferSize( _drawingBufferSize ); + const { depth, stencil } = this; + + let frameBufferTarget = this._frameBufferTarget; + + if ( frameBufferTarget === null ) { + + frameBufferTarget = new RenderTarget( width, height, { + depthBuffer: depth, + stencilBuffer: stencil, + type: HalfFloatType, // FloatType + format: RGBAFormat, + colorSpace: LinearSRGBColorSpace, + generateMipmaps: false, + minFilter: LinearFilter, + magFilter: LinearFilter, + samples: this.samples + } ); + + frameBufferTarget.isPostProcessingRenderTarget = true; + + this._frameBufferTarget = frameBufferTarget; + + } + + frameBufferTarget.depthBuffer = depth; + frameBufferTarget.stencilBuffer = stencil; + frameBufferTarget.setSize( width, height ); + frameBufferTarget.viewport.copy( this._viewport ); + frameBufferTarget.scissor.copy( this._scissor ); + frameBufferTarget.viewport.multiplyScalar( this._pixelRatio ); + frameBufferTarget.scissor.multiplyScalar( this._pixelRatio ); + frameBufferTarget.scissorTest = this._scissorTest; + + return frameBufferTarget; + + } + + _renderScene( scene, camera, useFrameBufferTarget = true ) { + + if ( this._isDeviceLost === true ) return; + + const frameBufferTarget = useFrameBufferTarget ? this._getFrameBufferTarget() : null; + + // preserve render tree + + const nodeFrame = this._nodes.nodeFrame; + + const previousRenderId = nodeFrame.renderId; + const previousRenderContext = this._currentRenderContext; + const previousRenderObjectFunction = this._currentRenderObjectFunction; + + // + + const sceneRef = ( scene.isScene === true ) ? scene : _scene; + + const outputRenderTarget = this._renderTarget; + + const activeCubeFace = this._activeCubeFace; + const activeMipmapLevel = this._activeMipmapLevel; + + // + + let renderTarget; + + if ( frameBufferTarget !== null ) { + + renderTarget = frameBufferTarget; + + this.setRenderTarget( renderTarget ); + + } else { + + renderTarget = outputRenderTarget; + + } + + // + + const renderContext = this._renderContexts.get( scene, camera, renderTarget ); + + this._currentRenderContext = renderContext; + this._currentRenderObjectFunction = this._renderObjectFunction || this.renderObject; + + // + + this.info.calls ++; + this.info.render.calls ++; + this.info.render.frameCalls ++; + + nodeFrame.renderId = this.info.calls; + + // + + const coordinateSystem = this.coordinateSystem; + + if ( camera.coordinateSystem !== coordinateSystem ) { + + camera.coordinateSystem = coordinateSystem; + + camera.updateProjectionMatrix(); + + } + + // + + if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld(); + + if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld(); + + // + + let viewport = this._viewport; + let scissor = this._scissor; + let pixelRatio = this._pixelRatio; + + if ( renderTarget !== null ) { + + viewport = renderTarget.viewport; + scissor = renderTarget.scissor; + pixelRatio = 1; + + } + + this.getDrawingBufferSize( _drawingBufferSize ); + + _screen.set( 0, 0, _drawingBufferSize.width, _drawingBufferSize.height ); + + const minDepth = ( viewport.minDepth === undefined ) ? 0 : viewport.minDepth; + const maxDepth = ( viewport.maxDepth === undefined ) ? 1 : viewport.maxDepth; + + renderContext.viewportValue.copy( viewport ).multiplyScalar( pixelRatio ).floor(); + renderContext.viewportValue.width >>= activeMipmapLevel; + renderContext.viewportValue.height >>= activeMipmapLevel; + renderContext.viewportValue.minDepth = minDepth; + renderContext.viewportValue.maxDepth = maxDepth; + renderContext.viewport = renderContext.viewportValue.equals( _screen ) === false; + + renderContext.scissorValue.copy( scissor ).multiplyScalar( pixelRatio ).floor(); + renderContext.scissor = this._scissorTest && renderContext.scissorValue.equals( _screen ) === false; + renderContext.scissorValue.width >>= activeMipmapLevel; + renderContext.scissorValue.height >>= activeMipmapLevel; + + if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext(); + renderContext.clippingContext.updateGlobal( sceneRef, camera ); + + // + + sceneRef.onBeforeRender( this, scene, camera, renderTarget ); + + // + + _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); + _frustum.setFromProjectionMatrix( _projScreenMatrix, coordinateSystem ); + + const renderList = this._renderLists.get( scene, camera ); + renderList.begin(); + + this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext ); + + renderList.finish(); + + if ( this.sortObjects === true ) { + + renderList.sort( this._opaqueSort, this._transparentSort ); + + } + + // + + if ( renderTarget !== null ) { + + this._textures.updateRenderTarget( renderTarget, activeMipmapLevel ); + + const renderTargetData = this._textures.get( renderTarget ); + + renderContext.textures = renderTargetData.textures; + renderContext.depthTexture = renderTargetData.depthTexture; + renderContext.width = renderTargetData.width; + renderContext.height = renderTargetData.height; + renderContext.renderTarget = renderTarget; + renderContext.depth = renderTarget.depthBuffer; + renderContext.stencil = renderTarget.stencilBuffer; + + } else { + + renderContext.textures = null; + renderContext.depthTexture = null; + renderContext.width = this.domElement.width; + renderContext.height = this.domElement.height; + renderContext.depth = this.depth; + renderContext.stencil = this.stencil; + + } + + renderContext.width >>= activeMipmapLevel; + renderContext.height >>= activeMipmapLevel; + renderContext.activeCubeFace = activeCubeFace; + renderContext.activeMipmapLevel = activeMipmapLevel; + renderContext.occlusionQueryCount = renderList.occlusionQueryCount; + + // + + this._nodes.updateScene( sceneRef ); + + // + + this._background.update( sceneRef, renderList, renderContext ); + + // + + this.backend.beginRender( renderContext ); + + // process render lists + + const { + bundles, + lightsNode, + transparentDoublePass: transparentDoublePassObjects, + transparent: transparentObjects, + opaque: opaqueObjects + } = renderList; + + if ( bundles.length > 0 ) this._renderBundles( bundles, sceneRef, lightsNode ); + if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode ); + if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode ); + + // finish render pass + + this.backend.finishRender( renderContext ); + + // restore render tree + + nodeFrame.renderId = previousRenderId; + + this._currentRenderContext = previousRenderContext; + this._currentRenderObjectFunction = previousRenderObjectFunction; + + // + + if ( frameBufferTarget !== null ) { + + this.setRenderTarget( outputRenderTarget, activeCubeFace, activeMipmapLevel ); + + const quad = this._quad; + + if ( this._nodes.hasOutputChange( renderTarget.texture ) ) { + + quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture ); + quad.material.needsUpdate = true; + + } + + this._renderScene( quad, quad.camera, false ); + + } + + // + + sceneRef.onAfterRender( this, scene, camera, renderTarget ); + + // + + return renderContext; + + } + + getMaxAnisotropy() { + + return this.backend.getMaxAnisotropy(); + + } + + getActiveCubeFace() { + + return this._activeCubeFace; + + } + + getActiveMipmapLevel() { + + return this._activeMipmapLevel; + + } + + async setAnimationLoop( callback ) { + + if ( this._initialized === false ) await this.init(); + + this._animation.setAnimationLoop( callback ); + + } + + async getArrayBufferAsync( attribute ) { + + return await this.backend.getArrayBufferAsync( attribute ); + + } + + getContext() { + + return this.backend.getContext(); + + } + + getPixelRatio() { + + return this._pixelRatio; + + } + + getDrawingBufferSize( target ) { + + return target.set( this._width * this._pixelRatio, this._height * this._pixelRatio ).floor(); + + } + + getSize( target ) { + + return target.set( this._width, this._height ); + + } + + setPixelRatio( value = 1 ) { + + if ( this._pixelRatio === value ) return; + + this._pixelRatio = value; + + this.setSize( this._width, this._height, false ); + + } + + setDrawingBufferSize( width, height, pixelRatio ) { + + this._width = width; + this._height = height; + + this._pixelRatio = pixelRatio; + + this.domElement.width = Math.floor( width * pixelRatio ); + this.domElement.height = Math.floor( height * pixelRatio ); + + this.setViewport( 0, 0, width, height ); + + if ( this._initialized ) this.backend.updateSize(); + + } + + setSize( width, height, updateStyle = true ) { + + this._width = width; + this._height = height; + + this.domElement.width = Math.floor( width * this._pixelRatio ); + this.domElement.height = Math.floor( height * this._pixelRatio ); + + if ( updateStyle === true ) { + + this.domElement.style.width = width + 'px'; + this.domElement.style.height = height + 'px'; + + } + + this.setViewport( 0, 0, width, height ); + + if ( this._initialized ) this.backend.updateSize(); + + } + + setOpaqueSort( method ) { + + this._opaqueSort = method; + + } + + setTransparentSort( method ) { + + this._transparentSort = method; + + } + + getScissor( target ) { + + const scissor = this._scissor; + + target.x = scissor.x; + target.y = scissor.y; + target.width = scissor.width; + target.height = scissor.height; + + return target; + + } + + setScissor( x, y, width, height ) { + + const scissor = this._scissor; + + if ( x.isVector4 ) { + + scissor.copy( x ); + + } else { + + scissor.set( x, y, width, height ); + + } + + } + + getScissorTest() { + + return this._scissorTest; + + } + + setScissorTest( boolean ) { + + this._scissorTest = boolean; + + this.backend.setScissorTest( boolean ); + + } + + getViewport( target ) { + + return target.copy( this._viewport ); + + } + + setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) { + + const viewport = this._viewport; + + if ( x.isVector4 ) { + + viewport.copy( x ); + + } else { + + viewport.set( x, y, width, height ); + + } + + viewport.minDepth = minDepth; + viewport.maxDepth = maxDepth; + + } + + getClearColor( target ) { + + return target.copy( this._clearColor ); + + } + + setClearColor( color, alpha = 1 ) { + + this._clearColor.set( color ); + this._clearColor.a = alpha; + + } + + getClearAlpha() { + + return this._clearColor.a; + + } + + setClearAlpha( alpha ) { + + this._clearColor.a = alpha; + + } + + getClearDepth() { + + return this._clearDepth; + + } + + setClearDepth( depth ) { + + this._clearDepth = depth; + + } + + getClearStencil() { + + return this._clearStencil; + + } + + setClearStencil( stencil ) { + + this._clearStencil = stencil; + + } + + isOccluded( object ) { + + const renderContext = this._currentRenderContext; + + return renderContext && this.backend.isOccluded( renderContext, object ); + + } + + clear( color = true, depth = true, stencil = true ) { + + if ( this._initialized === false ) { + + console.warn( 'THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead.' ); + + return this.clearAsync( color, depth, stencil ); + + } + + const renderTarget = this._renderTarget || this._getFrameBufferTarget(); + + let renderTargetData = null; + + if ( renderTarget !== null ) { + + this._textures.updateRenderTarget( renderTarget ); + + renderTargetData = this._textures.get( renderTarget ); + + } + + this.backend.clear( color, depth, stencil, renderTargetData ); + + if ( renderTarget !== null && this._renderTarget === null ) { + + // If a color space transform or tone mapping is required, + // the clear operation clears the intermediate renderTarget texture, but does not update the screen canvas. + + const quad = this._quad; + + if ( this._nodes.hasOutputChange( renderTarget.texture ) ) { + + quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture ); + quad.material.needsUpdate = true; + + } + + this._renderScene( quad, quad.camera, false ); + + } + + } + + clearColor() { + + return this.clear( true, false, false ); + + } + + clearDepth() { + + return this.clear( false, true, false ); + + } + + clearStencil() { + + return this.clear( false, false, true ); + + } + + async clearAsync( color = true, depth = true, stencil = true ) { + + if ( this._initialized === false ) await this.init(); + + this.clear( color, depth, stencil ); + + } + + clearColorAsync() { + + return this.clearAsync( true, false, false ); + + } + + clearDepthAsync() { + + return this.clearAsync( false, true, false ); + + } + + clearStencilAsync() { + + return this.clearAsync( false, false, true ); + + } + + get currentToneMapping() { + + return this._renderTarget !== null ? NoToneMapping : this.toneMapping; + + } + + get currentColorSpace() { + + return this._renderTarget !== null ? LinearSRGBColorSpace : this.outputColorSpace; + + } + + dispose() { + + this.info.dispose(); + this.backend.dispose(); + + this._animation.dispose(); + this._objects.dispose(); + this._pipelines.dispose(); + this._nodes.dispose(); + this._bindings.dispose(); + this._renderLists.dispose(); + this._renderContexts.dispose(); + this._textures.dispose(); + + this.setRenderTarget( null ); + this.setAnimationLoop( null ); + + } + + setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) { + + this._renderTarget = renderTarget; + this._activeCubeFace = activeCubeFace; + this._activeMipmapLevel = activeMipmapLevel; + + } + + getRenderTarget() { + + return this._renderTarget; + + } + + setRenderObjectFunction( renderObjectFunction ) { + + this._renderObjectFunction = renderObjectFunction; + + } + + getRenderObjectFunction() { + + return this._renderObjectFunction; + + } + + compute( computeNodes ) { + + if ( this.isDeviceLost === true ) return; + + if ( this._initialized === false ) { + + console.warn( 'THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead.' ); + + return this.computeAsync( computeNodes ); + + } + + // + + const nodeFrame = this._nodes.nodeFrame; + + const previousRenderId = nodeFrame.renderId; + + // + + this.info.calls ++; + this.info.compute.calls ++; + this.info.compute.frameCalls ++; + + nodeFrame.renderId = this.info.calls; + + // + + const backend = this.backend; + const pipelines = this._pipelines; + const bindings = this._bindings; + const nodes = this._nodes; + + const computeList = Array.isArray( computeNodes ) ? computeNodes : [ computeNodes ]; + + if ( computeList[ 0 ] === undefined || computeList[ 0 ].isComputeNode !== true ) { + + throw new Error( 'THREE.Renderer: .compute() expects a ComputeNode.' ); + + } + + backend.beginCompute( computeNodes ); + + for ( const computeNode of computeList ) { + + // onInit + + if ( pipelines.has( computeNode ) === false ) { + + const dispose = () => { + + computeNode.removeEventListener( 'dispose', dispose ); + + pipelines.delete( computeNode ); + bindings.delete( computeNode ); + nodes.delete( computeNode ); + + }; + + computeNode.addEventListener( 'dispose', dispose ); + + // + + const onInitFn = computeNode.onInitFunction; + + if ( onInitFn !== null ) { + + onInitFn.call( computeNode, { renderer: this } ); + + } + + } + + nodes.updateForCompute( computeNode ); + bindings.updateForCompute( computeNode ); + + const computeBindings = bindings.getForCompute( computeNode ); + const computePipeline = pipelines.getForCompute( computeNode, computeBindings ); + + backend.compute( computeNodes, computeNode, computeBindings, computePipeline ); + + } + + backend.finishCompute( computeNodes ); + + // + + nodeFrame.renderId = previousRenderId; + + } + + async computeAsync( computeNodes ) { + + if ( this._initialized === false ) await this.init(); + + this.compute( computeNodes ); + + await this.backend.resolveTimestampAsync( computeNodes, 'compute' ); + + } + + async hasFeatureAsync( name ) { + + if ( this._initialized === false ) await this.init(); + + return this.backend.hasFeature( name ); + + } + + hasFeature( name ) { + + if ( this._initialized === false ) { + + console.warn( 'THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead.' ); + + return false; + + } + + return this.backend.hasFeature( name ); + + } + + hasInitialized() { + + return this._initialized; + + } + + async initTextureAsync( texture ) { + + if ( this._initialized === false ) await this.init(); + + this._textures.updateTexture( texture ); + + } + + initTexture( texture ) { + + if ( this._initialized === false ) { + + console.warn( 'THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead.' ); + + return false; + + } + + this._textures.updateTexture( texture ); + + } + + copyFramebufferToTexture( framebufferTexture, rectangle = null ) { + + if ( rectangle !== null ) { + + if ( rectangle.isVector2 ) { + + rectangle = _vector4.set( rectangle.x, rectangle.y, framebufferTexture.image.width, framebufferTexture.image.height ).floor(); + + } else if ( rectangle.isVector4 ) { + + rectangle = _vector4.copy( rectangle ).floor(); + + } else { + + console.error( 'THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.' ); + + return; + + } + + } else { + + rectangle = _vector4.set( 0, 0, framebufferTexture.image.width, framebufferTexture.image.height ); + + } + + // + + let renderContext = this._currentRenderContext; + let renderTarget; + + if ( renderContext !== null ) { + + renderTarget = renderContext.renderTarget; + + } else { + + renderTarget = this._renderTarget || this._getFrameBufferTarget(); + + if ( renderTarget !== null ) { + + this._textures.updateRenderTarget( renderTarget ); + + renderContext = this._textures.get( renderTarget ); + + } + + } + + // + + this._textures.updateTexture( framebufferTexture, { renderTarget } ); + + this.backend.copyFramebufferToTexture( framebufferTexture, renderContext, rectangle ); + + } + + copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { + + this._textures.updateTexture( srcTexture ); + this._textures.updateTexture( dstTexture ); + + this.backend.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level ); + + } + + readRenderTargetPixelsAsync( renderTarget, x, y, width, height, index = 0, faceIndex = 0 ) { + + return this.backend.copyTextureToBuffer( renderTarget.textures[ index ], x, y, width, height, faceIndex ); + + } + + _projectObject( object, camera, groupOrder, renderList, clippingContext ) { + + if ( object.visible === false ) return; + + const visible = object.layers.test( camera.layers ); + + if ( visible ) { + + if ( object.isGroup ) { + + groupOrder = object.renderOrder; + + if ( object.isClippingGroup && object.enabled ) clippingContext = clippingContext.getGroupContext( object ); + + } else if ( object.isLOD ) { + + if ( object.autoUpdate === true ) object.update( camera ); + + } else if ( object.isLight ) { + + renderList.pushLight( object ); + + } else if ( object.isSprite ) { + + if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) { + + if ( this.sortObjects === true ) { + + _vector4.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix ); + + } + + const { geometry, material } = object; + + if ( material.visible ) { + + renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext ); + + } + + } + + } else if ( object.isLineLoop ) { + + console.error( 'THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.' ); + + } else if ( object.isMesh || object.isLine || object.isPoints ) { + + if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) { + + const { geometry, material } = object; + + if ( this.sortObjects === true ) { + + if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere(); + + _vector4 + .copy( geometry.boundingSphere.center ) + .applyMatrix4( object.matrixWorld ) + .applyMatrix4( _projScreenMatrix ); + + } + + if ( Array.isArray( material ) ) { + + const groups = geometry.groups; + + for ( let i = 0, l = groups.length; i < l; i ++ ) { + + const group = groups[ i ]; + const groupMaterial = material[ group.materialIndex ]; + + if ( groupMaterial && groupMaterial.visible ) { + + renderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group, clippingContext ); + + } + + } + + } else if ( material.visible ) { + + renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext ); + + } + + } + + } + + } + + if ( object.isBundleGroup === true && this.backend.beginBundle !== undefined ) { + + const baseRenderList = renderList; + + // replace render list + renderList = this._renderLists.get( object, camera ); + + renderList.begin(); + + baseRenderList.pushBundle( { + bundleGroup: object, + camera, + renderList, + } ); + + renderList.finish(); + + } + + const children = object.children; + + for ( let i = 0, l = children.length; i < l; i ++ ) { + + this._projectObject( children[ i ], camera, groupOrder, renderList, clippingContext ); + + } + + } + + _renderBundles( bundles, sceneRef, lightsNode ) { + + for ( const bundle of bundles ) { + + this._renderBundle( bundle, sceneRef, lightsNode ); + + } + + } + + _renderTransparents( renderList, doublePassList, camera, scene, lightsNode ) { + + if ( doublePassList.length > 0 ) { + + // render back side + + for ( const { material } of doublePassList ) { + + material.side = BackSide; + + } + + this._renderObjects( doublePassList, camera, scene, lightsNode, 'backSide' ); + + // render front side + + for ( const { material } of doublePassList ) { + + material.side = FrontSide; + + } + + this._renderObjects( renderList, camera, scene, lightsNode ); + + // restore + + for ( const { material } of doublePassList ) { + + material.side = DoubleSide; + + } + + } else { + + this._renderObjects( renderList, camera, scene, lightsNode ); + + } + + } + + _renderObjects( renderList, camera, scene, lightsNode, passId = null ) { + + // process renderable objects + + for ( let i = 0, il = renderList.length; i < il; i ++ ) { + + const renderItem = renderList[ i ]; + + // @TODO: Add support for multiple materials per object. This will require to extract + // the material from the renderItem object and pass it with its group data to renderObject(). + + const { object, geometry, material, group, clippingContext } = renderItem; + + if ( camera.isArrayCamera ) { + + const cameras = camera.cameras; + + for ( let j = 0, jl = cameras.length; j < jl; j ++ ) { + + const camera2 = cameras[ j ]; + + if ( object.layers.test( camera2.layers ) ) { + + const vp = camera2.viewport; + const minDepth = ( vp.minDepth === undefined ) ? 0 : vp.minDepth; + const maxDepth = ( vp.maxDepth === undefined ) ? 1 : vp.maxDepth; + + const viewportValue = this._currentRenderContext.viewportValue; + viewportValue.copy( vp ).multiplyScalar( this._pixelRatio ).floor(); + viewportValue.minDepth = minDepth; + viewportValue.maxDepth = maxDepth; + + this.backend.updateViewport( this._currentRenderContext ); + + this._currentRenderObjectFunction( object, scene, camera2, geometry, material, group, lightsNode, clippingContext, passId ); + + } + + } + + } else { + + this._currentRenderObjectFunction( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId ); + + } + + } + + } + + renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext = null, passId = null ) { + + let overridePositionNode; + let overrideColorNode; + let overrideDepthNode; + + // + + object.onBeforeRender( this, scene, camera, geometry, material, group ); + + // + + if ( scene.overrideMaterial !== null ) { + + const overrideMaterial = scene.overrideMaterial; + + if ( material.positionNode && material.positionNode.isNode ) { + + overridePositionNode = overrideMaterial.positionNode; + overrideMaterial.positionNode = material.positionNode; + + } + + overrideMaterial.alphaTest = material.alphaTest; + overrideMaterial.alphaMap = material.alphaMap; + + if ( overrideMaterial.isShadowNodeMaterial ) { + + overrideMaterial.side = material.shadowSide === null ? material.side : material.shadowSide; + + if ( material.depthNode && material.depthNode.isNode ) { + + overrideDepthNode = overrideMaterial.depthNode; + overrideMaterial.depthNode = material.depthNode; + + } + + if ( material.castShadowNode && material.castShadowNode.isNode ) { + + overrideColorNode = overrideMaterial.colorNode; + overrideMaterial.colorNode = material.castShadowNode; + + } + + } + + material = overrideMaterial; + + } + + // + + if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) { + + material.side = BackSide; + this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, 'backSide' ); // create backSide pass id + + material.side = FrontSide; + this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId ); // use default pass id + + material.side = DoubleSide; + + } else { + + this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId ); + + } + + // + + if ( overridePositionNode !== undefined ) { + + scene.overrideMaterial.positionNode = overridePositionNode; + + } + + if ( overrideDepthNode !== undefined ) { + + scene.overrideMaterial.depthNode = overrideDepthNode; + + } + + if ( overrideColorNode !== undefined ) { + + scene.overrideMaterial.colorNode = overrideColorNode; + + } + + // + + object.onAfterRender( this, scene, camera, geometry, material, group ); + + } + + _renderObjectDirect( object, material, scene, camera, lightsNode, group, clippingContext, passId ) { + + const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId ); + renderObject.drawRange = object.geometry.drawRange; + renderObject.group = group; + + // + + const needsRefresh = this._nodes.needsRefresh( renderObject ); + + if ( needsRefresh ) { + + this._nodes.updateBefore( renderObject ); + + this._geometries.updateForRender( renderObject ); + + this._nodes.updateForRender( renderObject ); + this._bindings.updateForRender( renderObject ); + + } + + this._pipelines.updateForRender( renderObject ); + + // + + if ( this._currentRenderBundle !== null ) { + + const renderBundleData = this.backend.get( this._currentRenderBundle ); + + renderBundleData.renderObjects.push( renderObject ); + + renderObject.bundle = this._currentRenderBundle.scene; + + } + + this.backend.draw( renderObject, this.info ); + + if ( needsRefresh ) this._nodes.updateAfter( renderObject ); + + } + + _createObjectPipeline( object, material, scene, camera, lightsNode, clippingContext, passId ) { + + const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId ); + + // + + this._nodes.updateBefore( renderObject ); + + this._geometries.updateForRender( renderObject ); + + this._nodes.updateForRender( renderObject ); + this._bindings.updateForRender( renderObject ); + + this._pipelines.getForRender( renderObject, this._compilationPromises ); + + this._nodes.updateAfter( renderObject ); + + } + + get compile() { + + return this.compileAsync; + + } + +} + +class Binding { + + constructor( name = '' ) { + + this.name = name; + + this.visibility = 0; + + } + + setVisibility( visibility ) { + + this.visibility |= visibility; + + } + + clone() { + + return Object.assign( new this.constructor(), this ); + + } + +} + +function getFloatLength( floatLength ) { + + // ensure chunk size alignment (STD140 layout) + + return floatLength + ( ( GPU_CHUNK_BYTES - ( floatLength % GPU_CHUNK_BYTES ) ) % GPU_CHUNK_BYTES ); + +} + +class Buffer extends Binding { + + constructor( name, buffer = null ) { + + super( name ); + + this.isBuffer = true; + + this.bytesPerElement = Float32Array.BYTES_PER_ELEMENT; + + this._buffer = buffer; + + } + + get byteLength() { + + return getFloatLength( this._buffer.byteLength ); + + } + + get buffer() { + + return this._buffer; + + } + + update() { + + return true; + + } + +} + +class UniformBuffer extends Buffer { + + constructor( name, buffer = null ) { + + super( name, buffer ); + + this.isUniformBuffer = true; + + } + +} + +let _id$4 = 0; + +class NodeUniformBuffer extends UniformBuffer { + + constructor( nodeUniform, groupNode ) { + + super( 'UniformBuffer_' + _id$4 ++, nodeUniform ? nodeUniform.value : null ); + + this.nodeUniform = nodeUniform; + this.groupNode = groupNode; + + } + + get buffer() { + + return this.nodeUniform.value; + + } + +} + +class UniformsGroup extends UniformBuffer { + + constructor( name ) { + + super( name ); + + this.isUniformsGroup = true; + + this._values = null; + + // the order of uniforms in this array must match the order of uniforms in the shader + + this.uniforms = []; + + } + + addUniform( uniform ) { + + this.uniforms.push( uniform ); + + return this; + + } + + removeUniform( uniform ) { + + const index = this.uniforms.indexOf( uniform ); + + if ( index !== - 1 ) { + + this.uniforms.splice( index, 1 ); + + } + + return this; + + } + + get values() { + + if ( this._values === null ) { + + this._values = Array.from( this.buffer ); + + } + + return this._values; + + } + + get buffer() { + + let buffer = this._buffer; + + if ( buffer === null ) { + + const byteLength = this.byteLength; + + buffer = new Float32Array( new ArrayBuffer( byteLength ) ); + + this._buffer = buffer; + + } + + return buffer; + + } + + get byteLength() { + + let offset = 0; // global buffer offset in bytes + + for ( let i = 0, l = this.uniforms.length; i < l; i ++ ) { + + const uniform = this.uniforms[ i ]; + + const { boundary, itemSize } = uniform; + + // offset within a single chunk in bytes + + const chunkOffset = offset % GPU_CHUNK_BYTES; + const remainingSizeInChunk = GPU_CHUNK_BYTES - chunkOffset; + + // conformance tests + + if ( chunkOffset !== 0 && ( remainingSizeInChunk - boundary ) < 0 ) { + + // check for chunk overflow + + offset += ( GPU_CHUNK_BYTES - chunkOffset ); + + } else if ( chunkOffset % boundary !== 0 ) { + + // check for correct alignment + + offset += ( chunkOffset % boundary ); + + } + + uniform.offset = ( offset / this.bytesPerElement ); + + offset += ( itemSize * this.bytesPerElement ); + + } + + return Math.ceil( offset / GPU_CHUNK_BYTES ) * GPU_CHUNK_BYTES; + + } + + update() { + + let updated = false; + + for ( const uniform of this.uniforms ) { + + if ( this.updateByType( uniform ) === true ) { + + updated = true; + + } + + } + + return updated; + + } + + updateByType( uniform ) { + + if ( uniform.isNumberUniform ) return this.updateNumber( uniform ); + if ( uniform.isVector2Uniform ) return this.updateVector2( uniform ); + if ( uniform.isVector3Uniform ) return this.updateVector3( uniform ); + if ( uniform.isVector4Uniform ) return this.updateVector4( uniform ); + if ( uniform.isColorUniform ) return this.updateColor( uniform ); + if ( uniform.isMatrix3Uniform ) return this.updateMatrix3( uniform ); + if ( uniform.isMatrix4Uniform ) return this.updateMatrix4( uniform ); + + console.error( 'THREE.WebGPUUniformsGroup: Unsupported uniform type.', uniform ); + + } + + updateNumber( uniform ) { + + let updated = false; + + const a = this.values; + const v = uniform.getValue(); + const offset = uniform.offset; + const type = uniform.getType(); + + if ( a[ offset ] !== v ) { + + const b = this._getBufferForType( type ); + + b[ offset ] = a[ offset ] = v; + updated = true; + + } + + return updated; + + } + + updateVector2( uniform ) { + + let updated = false; + + const a = this.values; + const v = uniform.getValue(); + const offset = uniform.offset; + const type = uniform.getType(); + + if ( a[ offset + 0 ] !== v.x || a[ offset + 1 ] !== v.y ) { + + const b = this._getBufferForType( type ); + + b[ offset + 0 ] = a[ offset + 0 ] = v.x; + b[ offset + 1 ] = a[ offset + 1 ] = v.y; + + updated = true; + + } + + return updated; + + } + + updateVector3( uniform ) { + + let updated = false; + + const a = this.values; + const v = uniform.getValue(); + const offset = uniform.offset; + const type = uniform.getType(); + + if ( a[ offset + 0 ] !== v.x || a[ offset + 1 ] !== v.y || a[ offset + 2 ] !== v.z ) { + + const b = this._getBufferForType( type ); + + b[ offset + 0 ] = a[ offset + 0 ] = v.x; + b[ offset + 1 ] = a[ offset + 1 ] = v.y; + b[ offset + 2 ] = a[ offset + 2 ] = v.z; + + updated = true; + + } + + return updated; + + } + + updateVector4( uniform ) { + + let updated = false; + + const a = this.values; + const v = uniform.getValue(); + const offset = uniform.offset; + const type = uniform.getType(); + + if ( a[ offset + 0 ] !== v.x || a[ offset + 1 ] !== v.y || a[ offset + 2 ] !== v.z || a[ offset + 4 ] !== v.w ) { + + const b = this._getBufferForType( type ); + + b[ offset + 0 ] = a[ offset + 0 ] = v.x; + b[ offset + 1 ] = a[ offset + 1 ] = v.y; + b[ offset + 2 ] = a[ offset + 2 ] = v.z; + b[ offset + 3 ] = a[ offset + 3 ] = v.w; + + updated = true; + + } + + return updated; + + } + + updateColor( uniform ) { + + let updated = false; + + const a = this.values; + const c = uniform.getValue(); + const offset = uniform.offset; + + if ( a[ offset + 0 ] !== c.r || a[ offset + 1 ] !== c.g || a[ offset + 2 ] !== c.b ) { + + const b = this.buffer; + + b[ offset + 0 ] = a[ offset + 0 ] = c.r; + b[ offset + 1 ] = a[ offset + 1 ] = c.g; + b[ offset + 2 ] = a[ offset + 2 ] = c.b; + + updated = true; + + } + + return updated; + + } + + updateMatrix3( uniform ) { + + let updated = false; + + const a = this.values; + const e = uniform.getValue().elements; + const offset = uniform.offset; + + if ( a[ offset + 0 ] !== e[ 0 ] || a[ offset + 1 ] !== e[ 1 ] || a[ offset + 2 ] !== e[ 2 ] || + a[ offset + 4 ] !== e[ 3 ] || a[ offset + 5 ] !== e[ 4 ] || a[ offset + 6 ] !== e[ 5 ] || + a[ offset + 8 ] !== e[ 6 ] || a[ offset + 9 ] !== e[ 7 ] || a[ offset + 10 ] !== e[ 8 ] ) { + + const b = this.buffer; + + b[ offset + 0 ] = a[ offset + 0 ] = e[ 0 ]; + b[ offset + 1 ] = a[ offset + 1 ] = e[ 1 ]; + b[ offset + 2 ] = a[ offset + 2 ] = e[ 2 ]; + b[ offset + 4 ] = a[ offset + 4 ] = e[ 3 ]; + b[ offset + 5 ] = a[ offset + 5 ] = e[ 4 ]; + b[ offset + 6 ] = a[ offset + 6 ] = e[ 5 ]; + b[ offset + 8 ] = a[ offset + 8 ] = e[ 6 ]; + b[ offset + 9 ] = a[ offset + 9 ] = e[ 7 ]; + b[ offset + 10 ] = a[ offset + 10 ] = e[ 8 ]; + + updated = true; + + } + + return updated; + + } + + updateMatrix4( uniform ) { + + let updated = false; + + const a = this.values; + const e = uniform.getValue().elements; + const offset = uniform.offset; + + if ( arraysEqual( a, e, offset ) === false ) { + + const b = this.buffer; + b.set( e, offset ); + setArray( a, e, offset ); + updated = true; + + } + + return updated; + + } + + _getBufferForType( type ) { + + if ( type === 'int' || type === 'ivec2' || type === 'ivec3' || type === 'ivec4' ) return new Int32Array( this.buffer.buffer ); + if ( type === 'uint' || type === 'uvec2' || type === 'uvec3' || type === 'uvec4' ) return new Uint32Array( this.buffer.buffer ); + return this.buffer; + + } + +} + +function setArray( a, b, offset ) { + + for ( let i = 0, l = b.length; i < l; i ++ ) { + + a[ offset + i ] = b[ i ]; + + } + +} + +function arraysEqual( a, b, offset ) { + + for ( let i = 0, l = b.length; i < l; i ++ ) { + + if ( a[ offset + i ] !== b[ i ] ) return false; + + } + + return true; + +} + +let _id$3 = 0; + +class NodeUniformsGroup extends UniformsGroup { + + constructor( name, groupNode ) { + + super( name ); + + this.id = _id$3 ++; + this.groupNode = groupNode; + + this.isNodeUniformsGroup = true; + + } + + getNodes() { + + const nodes = []; + + for ( const uniform of this.uniforms ) { + + const node = uniform.nodeUniform.node; + + if ( ! node ) throw new Error( 'NodeUniformsGroup: Uniform has no node.' ); + + nodes.push( node ); + + } + + return nodes; + + } + +} + +let _id$2 = 0; + +class SampledTexture extends Binding { + + constructor( name, texture ) { + + super( name ); + + this.id = _id$2 ++; + + this.texture = texture; + this.version = texture ? texture.version : 0; + this.store = false; + this.generation = null; + + this.isSampledTexture = true; + + } + + needsBindingsUpdate( generation ) { + + const { texture } = this; + + if ( generation !== this.generation ) { + + this.generation = generation; + + return true; + + } + + return texture.isVideoTexture; + + } + + update() { + + const { texture, version } = this; + + if ( version !== texture.version ) { + + this.version = texture.version; + + return true; + + } + + return false; + + } + +} + +class NodeSampledTexture extends SampledTexture { + + constructor( name, textureNode, groupNode, access = null ) { + + super( name, textureNode ? textureNode.value : null ); + + this.textureNode = textureNode; + this.groupNode = groupNode; + + this.access = access; + + } + + needsBindingsUpdate( generation ) { + + return this.textureNode.value !== this.texture || super.needsBindingsUpdate( generation ); + + } + + update() { + + const { textureNode } = this; + + if ( this.texture !== textureNode.value ) { + + this.texture = textureNode.value; + + return true; + + } + + return super.update(); + + } + +} + +class NodeSampledCubeTexture extends NodeSampledTexture { + + constructor( name, textureNode, groupNode, access ) { + + super( name, textureNode, groupNode, access ); + + this.isSampledCubeTexture = true; + + } + +} + +class NodeSampledTexture3D extends NodeSampledTexture { + + constructor( name, textureNode, groupNode, access ) { + + super( name, textureNode, groupNode, access ); + + this.isSampledTexture3D = true; + + } + +} + +const glslMethods = { + atan2: 'atan', + textureDimensions: 'textureSize', + equals: 'equal' +}; + +const precisionLib = { + low: 'lowp', + medium: 'mediump', + high: 'highp' +}; + +const supports$1 = { + swizzleAssign: true, + storageBuffer: false +}; + +const defaultPrecisions = ` +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler3D; +precision highp samplerCube; +precision highp sampler2DArray; + +precision highp usampler2D; +precision highp usampler3D; +precision highp usamplerCube; +precision highp usampler2DArray; + +precision highp isampler2D; +precision highp isampler3D; +precision highp isamplerCube; +precision highp isampler2DArray; + +precision lowp sampler2DShadow; +`; + +class GLSLNodeBuilder extends NodeBuilder { + + constructor( object, renderer ) { + + super( object, renderer, new GLSLNodeParser() ); + + this.uniformGroups = {}; + this.transforms = []; + this.extensions = {}; + this.builtins = { vertex: [], fragment: [], compute: [] }; + + this.useComparisonMethod = true; + + } + + needsToWorkingColorSpace( texture ) { + + return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace; + + } + + getMethod( method ) { + + return glslMethods[ method ] || method; + + } + + getOutputStructName() { + + return ''; + + } + + buildFunctionCode( shaderNode ) { + + const layout = shaderNode.layout; + const flowData = this.flowShaderNode( shaderNode ); + + const parameters = []; + + for ( const input of layout.inputs ) { + + parameters.push( this.getType( input.type ) + ' ' + input.name ); + + } + + // + + const code = `${ this.getType( layout.type ) } ${ layout.name }( ${ parameters.join( ', ' ) } ) { + + ${ flowData.vars } + +${ flowData.code } + return ${ flowData.result }; + +}`; + + // + + return code; + + } + + setupPBO( storageBufferNode ) { + + const attribute = storageBufferNode.value; + + if ( attribute.pbo === undefined ) { + + const originalArray = attribute.array; + const numElements = attribute.count * attribute.itemSize; + + const { itemSize } = attribute; + + const isInteger = attribute.array.constructor.name.toLowerCase().includes( 'int' ); + + let format = isInteger ? RedIntegerFormat : RedFormat; + + if ( itemSize === 2 ) { + + format = isInteger ? RGIntegerFormat : RGFormat; + + } else if ( itemSize === 3 ) { + + format = isInteger ? RGBIntegerFormat : RGBFormat; + + } else if ( itemSize === 4 ) { + + format = isInteger ? RGBAIntegerFormat : RGBAFormat; + + } + + const typeMap = { + Float32Array: FloatType, + Uint8Array: UnsignedByteType, + Uint16Array: UnsignedShortType, + Uint32Array: UnsignedIntType, + Int8Array: ByteType, + Int16Array: ShortType, + Int32Array: IntType, + Uint8ClampedArray: UnsignedByteType, + }; + + const width = Math.pow( 2, Math.ceil( Math.log2( Math.sqrt( numElements / itemSize ) ) ) ); + let height = Math.ceil( ( numElements / itemSize ) / width ); + if ( width * height * itemSize < numElements ) height ++; // Ensure enough space + + const newSize = width * height * itemSize; + + const newArray = new originalArray.constructor( newSize ); + + newArray.set( originalArray, 0 ); + + attribute.array = newArray; + + const pboTexture = new DataTexture( attribute.array, width, height, format, typeMap[ attribute.array.constructor.name ] || FloatType ); + pboTexture.needsUpdate = true; + pboTexture.isPBOTexture = true; + + const pbo = new TextureNode( pboTexture, null, null ); + pbo.setPrecision( 'high' ); + + attribute.pboNode = pbo; + attribute.pbo = pbo.value; + + this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label ); + + } + + } + + getPropertyName( node, shaderStage = this.shaderStage ) { + + if ( node.isNodeUniform && node.node.isTextureNode !== true && node.node.isBufferNode !== true ) { + + return shaderStage.charAt( 0 ) + '_' + node.name; + + } + + return super.getPropertyName( node, shaderStage ); + + } + + generatePBO( storageArrayElementNode ) { + + const { node, indexNode } = storageArrayElementNode; + const attribute = node.value; + + if ( this.renderer.backend.has( attribute ) ) { + + const attributeData = this.renderer.backend.get( attribute ); + attributeData.pbo = attribute.pbo; + + } + + const nodeUniform = this.getUniformFromNode( attribute.pboNode, 'texture', this.shaderStage, this.context.label ); + const textureName = this.getPropertyName( nodeUniform ); + + this.increaseUsage( indexNode ); // force cache generate to be used as index in x,y + const indexSnippet = indexNode.build( this, 'uint' ); + + const elementNodeData = this.getDataFromNode( storageArrayElementNode ); + + let propertyName = elementNodeData.propertyName; + + if ( propertyName === undefined ) { + + // property element + + const nodeVar = this.getVarFromNode( storageArrayElementNode ); + + propertyName = this.getPropertyName( nodeVar ); + + // property size + + const bufferNodeData = this.getDataFromNode( node ); + + let propertySizeName = bufferNodeData.propertySizeName; + + if ( propertySizeName === undefined ) { + + propertySizeName = propertyName + 'Size'; + + this.getVarFromNode( node, propertySizeName, 'uint' ); + + this.addLineFlowCode( `${ propertySizeName } = uint( textureSize( ${ textureName }, 0 ).x )`, storageArrayElementNode ); + + bufferNodeData.propertySizeName = propertySizeName; + + } + + // + + const { itemSize } = attribute; + + const channel = '.' + vectorComponents.join( '' ).slice( 0, itemSize ); + const uvSnippet = `ivec2(${indexSnippet} % ${ propertySizeName }, ${indexSnippet} / ${ propertySizeName })`; + + const snippet = this.generateTextureLoad( null, textureName, uvSnippet, null, '0' ); + + // + + + let prefix = 'vec4'; + + if ( attribute.pbo.type === UnsignedIntType ) { + + prefix = 'uvec4'; + + } else if ( attribute.pbo.type === IntType ) { + + prefix = 'ivec4'; + + } + + this.addLineFlowCode( `${ propertyName } = ${prefix}(${ snippet })${channel}`, storageArrayElementNode ); + + elementNodeData.propertyName = propertyName; + + } + + return propertyName; + + } + + generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0' ) { + + if ( depthSnippet ) { + + return `texelFetch( ${ textureProperty }, ivec3( ${ uvIndexSnippet }, ${ depthSnippet } ), ${ levelSnippet } )`; + + } else { + + return `texelFetch( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet } )`; + + } + + } + + generateTexture( texture, textureProperty, uvSnippet, depthSnippet ) { + + if ( texture.isDepthTexture ) { + + return `texture( ${ textureProperty }, ${ uvSnippet } ).x`; + + } else { + + if ( depthSnippet ) uvSnippet = `vec3( ${ uvSnippet }, ${ depthSnippet } )`; + + return `texture( ${ textureProperty }, ${ uvSnippet } )`; + + } + + } + + generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet ) { + + return `textureLod( ${ textureProperty }, ${ uvSnippet }, ${ levelSnippet } )`; + + } + + generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) { + + return `texture( ${ textureProperty }, ${ uvSnippet }, ${ biasSnippet } )`; + + } + + generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet ) { + + return `textureGrad( ${ textureProperty }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`; + + } + + generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + return `texture( ${ textureProperty }, vec3( ${ uvSnippet }, ${ compareSnippet } ) )`; + + } else { + + console.error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` ); + + } + + } + + getVars( shaderStage ) { + + const snippets = []; + + const vars = this.vars[ shaderStage ]; + + if ( vars !== undefined ) { + + for ( const variable of vars ) { + + snippets.push( `${ this.getVar( variable.type, variable.name ) };` ); + + } + + } + + return snippets.join( '\n\t' ); + + } + + getUniforms( shaderStage ) { + + const uniforms = this.uniforms[ shaderStage ]; + + const bindingSnippets = []; + const uniformGroups = {}; + + for ( const uniform of uniforms ) { + + let snippet = null; + let group = false; + + if ( uniform.type === 'texture' ) { + + const texture = uniform.node.value; + + let typePrefix = ''; + + if ( texture.isDataTexture === true ) { + + + if ( texture.type === UnsignedIntType ) { + + typePrefix = 'u'; + + } else if ( texture.type === IntType ) { + + typePrefix = 'i'; + + } + + } + + if ( texture.compareFunction ) { + + snippet = `sampler2DShadow ${ uniform.name };`; + + } else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) { + + snippet = `${typePrefix}sampler2DArray ${ uniform.name };`; + + } else { + + snippet = `${typePrefix}sampler2D ${ uniform.name };`; + + } + + } else if ( uniform.type === 'cubeTexture' ) { + + snippet = `samplerCube ${ uniform.name };`; + + } else if ( uniform.type === 'texture3D' ) { + + snippet = `sampler3D ${ uniform.name };`; + + } else if ( uniform.type === 'buffer' ) { + + const bufferNode = uniform.node; + const bufferType = this.getType( bufferNode.bufferType ); + const bufferCount = bufferNode.bufferCount; + + const bufferCountSnippet = bufferCount > 0 ? bufferCount : ''; + snippet = `${bufferNode.name} {\n\t${ bufferType } ${ uniform.name }[${ bufferCountSnippet }];\n};\n`; + + } else { + + const vectorType = this.getVectorType( uniform.type ); + + snippet = `${ vectorType } ${ this.getPropertyName( uniform, shaderStage ) };`; + + group = true; + + } + + const precision = uniform.node.precision; + + if ( precision !== null ) { + + snippet = precisionLib[ precision ] + ' ' + snippet; + + } + + if ( group ) { + + snippet = '\t' + snippet; + + const groupName = uniform.groupNode.name; + const groupSnippets = uniformGroups[ groupName ] || ( uniformGroups[ groupName ] = [] ); + + groupSnippets.push( snippet ); + + } else { + + snippet = 'uniform ' + snippet; + + bindingSnippets.push( snippet ); + + } + + } + + let output = ''; + + for ( const name in uniformGroups ) { + + const groupSnippets = uniformGroups[ name ]; + + output += this._getGLSLUniformStruct( shaderStage + '_' + name, groupSnippets.join( '\n' ) ) + '\n'; + + } + + output += bindingSnippets.join( '\n' ); + + return output; + + } + + getTypeFromAttribute( attribute ) { + + let nodeType = super.getTypeFromAttribute( attribute ); + + if ( /^[iu]/.test( nodeType ) && attribute.gpuType !== IntType ) { + + let dataAttribute = attribute; + + if ( attribute.isInterleavedBufferAttribute ) dataAttribute = attribute.data; + + const array = dataAttribute.array; + + if ( ( array instanceof Uint32Array || array instanceof Int32Array ) === false ) { + + nodeType = nodeType.slice( 1 ); + + } + + } + + return nodeType; + + } + + getAttributes( shaderStage ) { + + let snippet = ''; + + if ( shaderStage === 'vertex' || shaderStage === 'compute' ) { + + const attributes = this.getAttributesArray(); + + let location = 0; + + for ( const attribute of attributes ) { + + snippet += `layout( location = ${ location ++ } ) in ${ attribute.type } ${ attribute.name };\n`; + + } + + } + + return snippet; + + } + + getStructMembers( struct ) { + + const snippets = []; + const members = struct.getMemberTypes(); + + for ( let i = 0; i < members.length; i ++ ) { + + const member = members[ i ]; + snippets.push( `layout( location = ${i} ) out ${ member} m${i};` ); + + } + + return snippets.join( '\n' ); + + } + + getStructs( shaderStage ) { + + const snippets = []; + const structs = this.structs[ shaderStage ]; + + if ( structs.length === 0 ) { + + return 'layout( location = 0 ) out vec4 fragColor;\n'; + + } + + for ( let index = 0, length = structs.length; index < length; index ++ ) { + + const struct = structs[ index ]; + + let snippet = '\n'; + snippet += this.getStructMembers( struct ); + snippet += '\n'; + + snippets.push( snippet ); + + } + + return snippets.join( '\n\n' ); + + } + + getVaryings( shaderStage ) { + + let snippet = ''; + + const varyings = this.varyings; + + if ( shaderStage === 'vertex' || shaderStage === 'compute' ) { + + for ( const varying of varyings ) { + + if ( shaderStage === 'compute' ) varying.needsInterpolation = true; + const type = this.getType( varying.type ); + const flat = type.includes( 'int' ) || type.includes( 'uv' ) || type.includes( 'iv' ) ? 'flat ' : ''; + + snippet += `${flat}${varying.needsInterpolation ? 'out' : '/*out*/'} ${type} ${varying.name};\n`; + + } + + } else if ( shaderStage === 'fragment' ) { + + for ( const varying of varyings ) { + + if ( varying.needsInterpolation ) { + + const type = this.getType( varying.type ); + const flat = type.includes( 'int' ) || type.includes( 'uv' ) || type.includes( 'iv' ) ? 'flat ' : ''; + + snippet += `${flat}in ${type} ${varying.name};\n`; + + } + + } + + } + + for ( const builtin of this.builtins[ shaderStage ] ) { + + snippet += `${builtin};\n`; + + } + + return snippet; + + } + + getVertexIndex() { + + return 'uint( gl_VertexID )'; + + } + + getInstanceIndex() { + + return 'uint( gl_InstanceID )'; + + } + + getInvocationLocalIndex() { + + const workgroupSize = this.object.workgroupSize; + + const size = workgroupSize.reduce( ( acc, curr ) => acc * curr, 1 ); + + return `uint( gl_InstanceID ) % ${size}u`; + + } + + getDrawIndex() { + + const extensions = this.renderer.backend.extensions; + + if ( extensions.has( 'WEBGL_multi_draw' ) ) { + + return 'uint( gl_DrawID )'; + + } + + return null; + + } + + getFrontFacing() { + + return 'gl_FrontFacing'; + + } + + getFragCoord() { + + return 'gl_FragCoord.xy'; + + } + + getFragDepth() { + + return 'gl_FragDepth'; + + } + + enableExtension( name, behavior, shaderStage = this.shaderStage ) { + + const map = this.extensions[ shaderStage ] || ( this.extensions[ shaderStage ] = new Map() ); + + if ( map.has( name ) === false ) { + + map.set( name, { + name, + behavior + } ); + + } + + } + + getExtensions( shaderStage ) { + + const snippets = []; + + if ( shaderStage === 'vertex' ) { + + const ext = this.renderer.backend.extensions; + const isBatchedMesh = this.object.isBatchedMesh; + + if ( isBatchedMesh && ext.has( 'WEBGL_multi_draw' ) ) { + + this.enableExtension( 'GL_ANGLE_multi_draw', 'require', shaderStage ); + + } + + } + + const extensions = this.extensions[ shaderStage ]; + + if ( extensions !== undefined ) { + + for ( const { name, behavior } of extensions.values() ) { + + snippets.push( `#extension ${name} : ${behavior}` ); + + } + + } + + return snippets.join( '\n' ); + + } + + getClipDistance() { + + return 'gl_ClipDistance'; + + } + + isAvailable( name ) { + + let result = supports$1[ name ]; + + if ( result === undefined ) { + + let extensionName; + + result = false; + + switch ( name ) { + + case 'float32Filterable': + extensionName = 'OES_texture_float_linear'; + break; + + case 'clipDistance': + extensionName = 'WEBGL_clip_cull_distance'; + break; + + } + + if ( extensionName !== undefined ) { + + const extensions = this.renderer.backend.extensions; + + if ( extensions.has( extensionName ) ) { + + extensions.get( extensionName ); + result = true; + + } + + } + + supports$1[ name ] = result; + + } + + return result; + + } + + isFlipY() { + + return true; + + } + + enableHardwareClipping( planeCount ) { + + this.enableExtension( 'GL_ANGLE_clip_cull_distance', 'require' ); + + this.builtins[ 'vertex' ].push( `out float gl_ClipDistance[ ${ planeCount } ]` ); + + } + + registerTransform( varyingName, attributeNode ) { + + this.transforms.push( { varyingName, attributeNode } ); + + } + + getTransforms( /* shaderStage */ ) { + + const transforms = this.transforms; + + let snippet = ''; + + for ( let i = 0; i < transforms.length; i ++ ) { + + const transform = transforms[ i ]; + + const attributeName = this.getPropertyName( transform.attributeNode ); + + snippet += `${ transform.varyingName } = ${ attributeName };\n\t`; + + } + + return snippet; + + } + + _getGLSLUniformStruct( name, vars ) { + + return ` +layout( std140 ) uniform ${name} { +${vars} +};`; + + } + + _getGLSLVertexCode( shaderData ) { + + return `#version 300 es + +${ this.getSignature() } + +// extensions +${shaderData.extensions} + +// precision +${ defaultPrecisions } + +// uniforms +${shaderData.uniforms} + +// varyings +${shaderData.varyings} + +// attributes +${shaderData.attributes} + +// codes +${shaderData.codes} + +void main() { + + // vars + ${shaderData.vars} + + // transforms + ${shaderData.transforms} + + // flow + ${shaderData.flow} + + gl_PointSize = 1.0; + +} +`; + + } + + _getGLSLFragmentCode( shaderData ) { + + return `#version 300 es + +${ this.getSignature() } + +// precision +${ defaultPrecisions } + +// uniforms +${shaderData.uniforms} + +// varyings +${shaderData.varyings} + +// codes +${shaderData.codes} + +${shaderData.structs} + +void main() { + + // vars + ${shaderData.vars} + + // flow + ${shaderData.flow} + +} +`; + + } + + buildCode() { + + const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} }; + + this.sortBindingGroups(); + + for ( const shaderStage in shadersData ) { + + let flow = '// code\n\n'; + flow += this.flowCode[ shaderStage ]; + + const flowNodes = this.flowNodes[ shaderStage ]; + const mainNode = flowNodes[ flowNodes.length - 1 ]; + + for ( const node of flowNodes ) { + + const flowSlotData = this.getFlowData( node/*, shaderStage*/ ); + const slotName = node.name; + + if ( slotName ) { + + if ( flow.length > 0 ) flow += '\n'; + + flow += `\t// flow -> ${ slotName }\n\t`; + + } + + flow += `${ flowSlotData.code }\n\t`; + + if ( node === mainNode && shaderStage !== 'compute' ) { + + flow += '// result\n\t'; + + if ( shaderStage === 'vertex' ) { + + flow += 'gl_Position = '; + flow += `${ flowSlotData.result };`; + + } else if ( shaderStage === 'fragment' ) { + + if ( ! node.outputNode.isOutputStructNode ) { + + flow += 'fragColor = '; + flow += `${ flowSlotData.result };`; + + } + + } + + } + + } + + const stageData = shadersData[ shaderStage ]; + + stageData.extensions = this.getExtensions( shaderStage ); + stageData.uniforms = this.getUniforms( shaderStage ); + stageData.attributes = this.getAttributes( shaderStage ); + stageData.varyings = this.getVaryings( shaderStage ); + stageData.vars = this.getVars( shaderStage ); + stageData.structs = this.getStructs( shaderStage ); + stageData.codes = this.getCodes( shaderStage ); + stageData.transforms = this.getTransforms( shaderStage ); + stageData.flow = flow; + + } + + if ( this.material !== null ) { + + this.vertexShader = this._getGLSLVertexCode( shadersData.vertex ); + this.fragmentShader = this._getGLSLFragmentCode( shadersData.fragment ); + + } else { + + this.computeShader = this._getGLSLVertexCode( shadersData.compute ); + + } + + } + + getUniformFromNode( node, type, shaderStage, name = null ) { + + const uniformNode = super.getUniformFromNode( node, type, shaderStage, name ); + const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache ); + + let uniformGPU = nodeData.uniformGPU; + + if ( uniformGPU === undefined ) { + + const group = node.groupNode; + const groupName = group.name; + + const bindings = this.getBindGroupArray( groupName, shaderStage ); + + if ( type === 'texture' ) { + + uniformGPU = new NodeSampledTexture( uniformNode.name, uniformNode.node, group ); + bindings.push( uniformGPU ); + + } else if ( type === 'cubeTexture' ) { + + uniformGPU = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group ); + bindings.push( uniformGPU ); + + } else if ( type === 'texture3D' ) { + + uniformGPU = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group ); + bindings.push( uniformGPU ); + + } else if ( type === 'buffer' ) { + + node.name = `NodeBuffer_${ node.id }`; + uniformNode.name = `buffer${ node.id }`; + + const buffer = new NodeUniformBuffer( node, group ); + buffer.name = node.name; + + bindings.push( buffer ); + + uniformGPU = buffer; + + } else { + + const uniformsStage = this.uniformGroups[ shaderStage ] || ( this.uniformGroups[ shaderStage ] = {} ); + + let uniformsGroup = uniformsStage[ groupName ]; + + if ( uniformsGroup === undefined ) { + + uniformsGroup = new NodeUniformsGroup( shaderStage + '_' + groupName, group ); + //uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] ); + + uniformsStage[ groupName ] = uniformsGroup; + + bindings.push( uniformsGroup ); + + } + + uniformGPU = this.getNodeUniform( uniformNode, type ); + + uniformsGroup.addUniform( uniformGPU ); + + } + + nodeData.uniformGPU = uniformGPU; + + } + + return uniformNode; + + } + +} + +let vector2 = null; +let vector4 = null; +let color4 = null; + +class Backend { + + constructor( parameters = {} ) { + + this.parameters = Object.assign( {}, parameters ); + this.data = new WeakMap(); + this.renderer = null; + this.domElement = null; + + } + + async init( renderer ) { + + this.renderer = renderer; + + } + + // render context + + begin( /*renderContext*/ ) { } + + finish( /*renderContext*/ ) { } + + // render object + + draw( /*renderObject, info*/ ) { } + + // program + + createProgram( /*program*/ ) { } + + destroyProgram( /*program*/ ) { } + + // bindings + + createBindings( /*bingGroup, bindings*/ ) { } + + updateBindings( /*bingGroup, bindings*/ ) { } + + // pipeline + + createRenderPipeline( /*renderObject*/ ) { } + + createComputePipeline( /*computeNode, pipeline*/ ) { } + + destroyPipeline( /*pipeline*/ ) { } + + // cache key + + needsRenderUpdate( /*renderObject*/ ) { } // return Boolean ( fast test ) + + getRenderCacheKey( /*renderObject*/ ) { } // return String + + // node builder + + createNodeBuilder( /*renderObject*/ ) { } // return NodeBuilder (ADD IT) + + // textures + + createSampler( /*texture*/ ) { } + + createDefaultTexture( /*texture*/ ) { } + + createTexture( /*texture*/ ) { } + + copyTextureToBuffer( /*texture, x, y, width, height*/ ) {} + + // attributes + + createAttribute( /*attribute*/ ) { } + + createIndexAttribute( /*attribute*/ ) { } + + updateAttribute( /*attribute*/ ) { } + + destroyAttribute( /*attribute*/ ) { } + + // canvas + + getContext() { } + + updateSize() { } + + // utils + + resolveTimestampAsync( /*renderContext, type*/ ) { } + + hasFeatureAsync( /*name*/ ) { } // return Boolean + + hasFeature( /*name*/ ) { } // return Boolean + + getInstanceCount( renderObject ) { + + const { object, geometry } = renderObject; + + return geometry.isInstancedBufferGeometry ? geometry.instanceCount : ( object.count > 1 ? object.count : 1 ); + + } + + getDrawingBufferSize() { + + vector2 = vector2 || new Vector2(); + + return this.renderer.getDrawingBufferSize( vector2 ); + + } + + getScissor() { + + vector4 = vector4 || new Vector4(); + + return this.renderer.getScissor( vector4 ); + + } + + setScissorTest( /*boolean*/ ) { } + + getClearColor() { + + const renderer = this.renderer; + + color4 = color4 || new Color4(); + + renderer.getClearColor( color4 ); + + color4.getRGB( color4, this.renderer.currentColorSpace ); + + return color4; + + } + + getDomElement() { + + let domElement = this.domElement; + + if ( domElement === null ) { + + domElement = ( this.parameters.canvas !== undefined ) ? this.parameters.canvas : createCanvasElement(); + + // OffscreenCanvas does not have setAttribute, see #22811 + if ( 'setAttribute' in domElement ) domElement.setAttribute( 'data-engine', `three.js r${REVISION} webgpu` ); + + this.domElement = domElement; + + } + + return domElement; + + } + + // resource properties + + set( object, value ) { + + this.data.set( object, value ); + + } + + get( object ) { + + let map = this.data.get( object ); + + if ( map === undefined ) { + + map = {}; + this.data.set( object, map ); + + } + + return map; + + } + + has( object ) { + + return this.data.has( object ); + + } + + delete( object ) { + + this.data.delete( object ); + + } + + dispose() { } + +} + +let _id$1 = 0; + +class DualAttributeData { + + constructor( attributeData, dualBuffer ) { + + this.buffers = [ attributeData.bufferGPU, dualBuffer ]; + this.type = attributeData.type; + this.bufferType = attributeData.bufferType; + this.pbo = attributeData.pbo; + this.byteLength = attributeData.byteLength; + this.bytesPerElement = attributeData.BYTES_PER_ELEMENT; + this.version = attributeData.version; + this.isInteger = attributeData.isInteger; + this.activeBufferIndex = 0; + this.baseId = attributeData.id; + + } + + + get id() { + + return `${ this.baseId }|${ this.activeBufferIndex }`; + + } + + get bufferGPU() { + + return this.buffers[ this.activeBufferIndex ]; + + } + + get transformBuffer() { + + return this.buffers[ this.activeBufferIndex ^ 1 ]; + + } + + switchBuffers() { + + this.activeBufferIndex ^= 1; + + } + +} + +class WebGLAttributeUtils { + + constructor( backend ) { + + this.backend = backend; + + } + + createAttribute( attribute, bufferType ) { + + const backend = this.backend; + const { gl } = backend; + + const array = attribute.array; + const usage = attribute.usage || gl.STATIC_DRAW; + + const bufferAttribute = attribute.isInterleavedBufferAttribute ? attribute.data : attribute; + const bufferData = backend.get( bufferAttribute ); + + let bufferGPU = bufferData.bufferGPU; + + if ( bufferGPU === undefined ) { + + bufferGPU = this._createBuffer( gl, bufferType, array, usage ); + + bufferData.bufferGPU = bufferGPU; + bufferData.bufferType = bufferType; + bufferData.version = bufferAttribute.version; + + } + + //attribute.onUploadCallback(); + + let type; + + if ( array instanceof Float32Array ) { + + type = gl.FLOAT; + + } else if ( array instanceof Uint16Array ) { + + if ( attribute.isFloat16BufferAttribute ) { + + type = gl.HALF_FLOAT; + + } else { + + type = gl.UNSIGNED_SHORT; + + } + + } else if ( array instanceof Int16Array ) { + + type = gl.SHORT; + + } else if ( array instanceof Uint32Array ) { + + type = gl.UNSIGNED_INT; + + } else if ( array instanceof Int32Array ) { + + type = gl.INT; + + } else if ( array instanceof Int8Array ) { + + type = gl.BYTE; + + } else if ( array instanceof Uint8Array ) { + + type = gl.UNSIGNED_BYTE; + + } else if ( array instanceof Uint8ClampedArray ) { + + type = gl.UNSIGNED_BYTE; + + } else { + + throw new Error( 'THREE.WebGLBackend: Unsupported buffer data format: ' + array ); + + } + + let attributeData = { + bufferGPU, + bufferType, + type, + byteLength: array.byteLength, + bytesPerElement: array.BYTES_PER_ELEMENT, + version: attribute.version, + pbo: attribute.pbo, + isInteger: type === gl.INT || type === gl.UNSIGNED_INT || attribute.gpuType === IntType, + id: _id$1 ++ + }; + + if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) { + + // create buffer for tranform feedback use + const bufferGPUDual = this._createBuffer( gl, bufferType, array, usage ); + attributeData = new DualAttributeData( attributeData, bufferGPUDual ); + + } + + backend.set( attribute, attributeData ); + + } + + updateAttribute( attribute ) { + + const backend = this.backend; + const { gl } = backend; + + const array = attribute.array; + const bufferAttribute = attribute.isInterleavedBufferAttribute ? attribute.data : attribute; + const bufferData = backend.get( bufferAttribute ); + const bufferType = bufferData.bufferType; + const updateRanges = attribute.isInterleavedBufferAttribute ? attribute.data.updateRanges : attribute.updateRanges; + + gl.bindBuffer( bufferType, bufferData.bufferGPU ); + + if ( updateRanges.length === 0 ) { + + // Not using update ranges + + gl.bufferSubData( bufferType, 0, array ); + + } else { + + for ( let i = 0, l = updateRanges.length; i < l; i ++ ) { + + const range = updateRanges[ i ]; + gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT, + array, range.start, range.count ); + + } + + bufferAttribute.clearUpdateRanges(); + + } + + gl.bindBuffer( bufferType, null ); + + bufferData.version = bufferAttribute.version; + + } + + destroyAttribute( attribute ) { + + const backend = this.backend; + const { gl } = backend; + + if ( attribute.isInterleavedBufferAttribute ) { + + backend.delete( attribute.data ); + + } + + const attributeData = backend.get( attribute ); + + gl.deleteBuffer( attributeData.bufferGPU ); + + backend.delete( attribute ); + + } + + async getArrayBufferAsync( attribute ) { + + const backend = this.backend; + const { gl } = backend; + + const bufferAttribute = attribute.isInterleavedBufferAttribute ? attribute.data : attribute; + const { bufferGPU } = backend.get( bufferAttribute ); + + const array = attribute.array; + const byteLength = array.byteLength; + + gl.bindBuffer( gl.COPY_READ_BUFFER, bufferGPU ); + + const writeBuffer = gl.createBuffer(); + + gl.bindBuffer( gl.COPY_WRITE_BUFFER, writeBuffer ); + gl.bufferData( gl.COPY_WRITE_BUFFER, byteLength, gl.STREAM_READ ); + + gl.copyBufferSubData( gl.COPY_READ_BUFFER, gl.COPY_WRITE_BUFFER, 0, 0, byteLength ); + + await backend.utils._clientWaitAsync(); + + const dstBuffer = new attribute.array.constructor( array.length ); + + // Ensure the buffer is bound before reading + gl.bindBuffer( gl.COPY_WRITE_BUFFER, writeBuffer ); + + gl.getBufferSubData( gl.COPY_WRITE_BUFFER, 0, dstBuffer ); + + gl.deleteBuffer( writeBuffer ); + + gl.bindBuffer( gl.COPY_READ_BUFFER, null ); + gl.bindBuffer( gl.COPY_WRITE_BUFFER, null ); + + return dstBuffer.buffer; + + } + + _createBuffer( gl, bufferType, array, usage ) { + + const bufferGPU = gl.createBuffer(); + + gl.bindBuffer( bufferType, bufferGPU ); + gl.bufferData( bufferType, array, usage ); + gl.bindBuffer( bufferType, null ); + + return bufferGPU; + + } + +} + +let initialized$1 = false, equationToGL, factorToGL; + +class WebGLState { + + constructor( backend ) { + + this.backend = backend; + + this.gl = this.backend.gl; + + this.enabled = {}; + this.currentFlipSided = null; + this.currentCullFace = null; + this.currentProgram = null; + this.currentBlendingEnabled = false; + this.currentBlending = null; + this.currentBlendSrc = null; + this.currentBlendDst = null; + this.currentBlendSrcAlpha = null; + this.currentBlendDstAlpha = null; + this.currentPremultipledAlpha = null; + this.currentPolygonOffsetFactor = null; + this.currentPolygonOffsetUnits = null; + this.currentColorMask = null; + this.currentDepthFunc = null; + this.currentDepthMask = null; + this.currentStencilFunc = null; + this.currentStencilRef = null; + this.currentStencilFuncMask = null; + this.currentStencilFail = null; + this.currentStencilZFail = null; + this.currentStencilZPass = null; + this.currentStencilMask = null; + this.currentLineWidth = null; + this.currentClippingPlanes = 0; + + this.currentBoundFramebuffers = {}; + this.currentDrawbuffers = new WeakMap(); + + this.maxTextures = this.gl.getParameter( this.gl.MAX_TEXTURE_IMAGE_UNITS ); + this.currentTextureSlot = null; + this.currentBoundTextures = {}; + this.currentBoundBufferBases = {}; + + if ( initialized$1 === false ) { + + this._init( this.gl ); + + initialized$1 = true; + + } + + } + + _init( gl ) { + + // Store only WebGL constants here. + + equationToGL = { + [ AddEquation ]: gl.FUNC_ADD, + [ SubtractEquation ]: gl.FUNC_SUBTRACT, + [ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT + }; + + factorToGL = { + [ ZeroFactor ]: gl.ZERO, + [ OneFactor ]: gl.ONE, + [ SrcColorFactor ]: gl.SRC_COLOR, + [ SrcAlphaFactor ]: gl.SRC_ALPHA, + [ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE, + [ DstColorFactor ]: gl.DST_COLOR, + [ DstAlphaFactor ]: gl.DST_ALPHA, + [ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR, + [ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA, + [ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR, + [ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA + }; + + } + + enable( id ) { + + const { enabled } = this; + + if ( enabled[ id ] !== true ) { + + this.gl.enable( id ); + enabled[ id ] = true; + + } + + } + + disable( id ) { + + const { enabled } = this; + + if ( enabled[ id ] !== false ) { + + this.gl.disable( id ); + enabled[ id ] = false; + + } + + } + + setFlipSided( flipSided ) { + + if ( this.currentFlipSided !== flipSided ) { + + const { gl } = this; + + if ( flipSided ) { + + gl.frontFace( gl.CW ); + + } else { + + gl.frontFace( gl.CCW ); + + } + + this.currentFlipSided = flipSided; + + } + + } + + setCullFace( cullFace ) { + + const { gl } = this; + + if ( cullFace !== CullFaceNone ) { + + this.enable( gl.CULL_FACE ); + + if ( cullFace !== this.currentCullFace ) { + + if ( cullFace === CullFaceBack ) { + + gl.cullFace( gl.BACK ); + + } else if ( cullFace === CullFaceFront ) { + + gl.cullFace( gl.FRONT ); + + } else { + + gl.cullFace( gl.FRONT_AND_BACK ); + + } + + } + + } else { + + this.disable( gl.CULL_FACE ); + + } + + this.currentCullFace = cullFace; + + } + + setLineWidth( width ) { + + const { currentLineWidth, gl } = this; + + if ( width !== currentLineWidth ) { + + gl.lineWidth( width ); + + this.currentLineWidth = width; + + } + + } + + + setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) { + + const { gl } = this; + + if ( blending === NoBlending ) { + + if ( this.currentBlendingEnabled === true ) { + + this.disable( gl.BLEND ); + this.currentBlendingEnabled = false; + + } + + return; + + } + + if ( this.currentBlendingEnabled === false ) { + + this.enable( gl.BLEND ); + this.currentBlendingEnabled = true; + + } + + if ( blending !== CustomBlending ) { + + if ( blending !== this.currentBlending || premultipliedAlpha !== this.currentPremultipledAlpha ) { + + if ( this.currentBlendEquation !== AddEquation || this.currentBlendEquationAlpha !== AddEquation ) { + + gl.blendEquation( gl.FUNC_ADD ); + + this.currentBlendEquation = AddEquation; + this.currentBlendEquationAlpha = AddEquation; + + } + + if ( premultipliedAlpha ) { + + switch ( blending ) { + + case NormalBlending: + gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); + break; + + case AdditiveBlending: + gl.blendFunc( gl.ONE, gl.ONE ); + break; + + case SubtractiveBlending: + gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE ); + break; + + case MultiplyBlending: + gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA ); + break; + + default: + console.error( 'THREE.WebGLState: Invalid blending: ', blending ); + break; + + } + + } else { + + switch ( blending ) { + + case NormalBlending: + gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); + break; + + case AdditiveBlending: + gl.blendFunc( gl.SRC_ALPHA, gl.ONE ); + break; + + case SubtractiveBlending: + gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE ); + break; + + case MultiplyBlending: + gl.blendFunc( gl.ZERO, gl.SRC_COLOR ); + break; + + default: + console.error( 'THREE.WebGLState: Invalid blending: ', blending ); + break; + + } + + } + + this.currentBlendSrc = null; + this.currentBlendDst = null; + this.currentBlendSrcAlpha = null; + this.currentBlendDstAlpha = null; + + this.currentBlending = blending; + this.currentPremultipledAlpha = premultipliedAlpha; + + } + + return; + + } + + // custom blending + + blendEquationAlpha = blendEquationAlpha || blendEquation; + blendSrcAlpha = blendSrcAlpha || blendSrc; + blendDstAlpha = blendDstAlpha || blendDst; + + if ( blendEquation !== this.currentBlendEquation || blendEquationAlpha !== this.currentBlendEquationAlpha ) { + + gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] ); + + this.currentBlendEquation = blendEquation; + this.currentBlendEquationAlpha = blendEquationAlpha; + + } + + if ( blendSrc !== this.currentBlendSrc || blendDst !== this.currentBlendDst || blendSrcAlpha !== this.currentBlendSrcAlpha || blendDstAlpha !== this.currentBlendDstAlpha ) { + + gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] ); + + this.currentBlendSrc = blendSrc; + this.currentBlendDst = blendDst; + this.currentBlendSrcAlpha = blendSrcAlpha; + this.currentBlendDstAlpha = blendDstAlpha; + + } + + this.currentBlending = blending; + this.currentPremultipledAlpha = false; + + } + + setColorMask( colorMask ) { + + if ( this.currentColorMask !== colorMask ) { + + this.gl.colorMask( colorMask, colorMask, colorMask, colorMask ); + this.currentColorMask = colorMask; + + } + + } + + setDepthTest( depthTest ) { + + const { gl } = this; + + if ( depthTest ) { + + this.enable( gl.DEPTH_TEST ); + + } else { + + this.disable( gl.DEPTH_TEST ); + + } + + } + + setDepthMask( depthMask ) { + + if ( this.currentDepthMask !== depthMask ) { + + this.gl.depthMask( depthMask ); + this.currentDepthMask = depthMask; + + } + + } + + setDepthFunc( depthFunc ) { + + if ( this.currentDepthFunc !== depthFunc ) { + + const { gl } = this; + + switch ( depthFunc ) { + + case NeverDepth: + + gl.depthFunc( gl.NEVER ); + break; + + case AlwaysDepth: + + gl.depthFunc( gl.ALWAYS ); + break; + + case LessDepth: + + gl.depthFunc( gl.LESS ); + break; + + case LessEqualDepth: + + gl.depthFunc( gl.LEQUAL ); + break; + + case EqualDepth: + + gl.depthFunc( gl.EQUAL ); + break; + + case GreaterEqualDepth: + + gl.depthFunc( gl.GEQUAL ); + break; + + case GreaterDepth: + + gl.depthFunc( gl.GREATER ); + break; + + case NotEqualDepth: + + gl.depthFunc( gl.NOTEQUAL ); + break; + + default: + + gl.depthFunc( gl.LEQUAL ); + + } + + this.currentDepthFunc = depthFunc; + + } + + } + + setStencilTest( stencilTest ) { + + const { gl } = this; + + if ( stencilTest ) { + + this.enable( gl.STENCIL_TEST ); + + } else { + + this.disable( gl.STENCIL_TEST ); + + } + + } + + setStencilMask( stencilMask ) { + + if ( this.currentStencilMask !== stencilMask ) { + + this.gl.stencilMask( stencilMask ); + this.currentStencilMask = stencilMask; + + } + + } + + setStencilFunc( stencilFunc, stencilRef, stencilMask ) { + + if ( this.currentStencilFunc !== stencilFunc || + this.currentStencilRef !== stencilRef || + this.currentStencilFuncMask !== stencilMask ) { + + this.gl.stencilFunc( stencilFunc, stencilRef, stencilMask ); + + this.currentStencilFunc = stencilFunc; + this.currentStencilRef = stencilRef; + this.currentStencilFuncMask = stencilMask; + + } + + } + + setStencilOp( stencilFail, stencilZFail, stencilZPass ) { + + if ( this.currentStencilFail !== stencilFail || + this.currentStencilZFail !== stencilZFail || + this.currentStencilZPass !== stencilZPass ) { + + this.gl.stencilOp( stencilFail, stencilZFail, stencilZPass ); + + this.currentStencilFail = stencilFail; + this.currentStencilZFail = stencilZFail; + this.currentStencilZPass = stencilZPass; + + } + + } + + setMaterial( material, frontFaceCW, hardwareClippingPlanes ) { + + const { gl } = this; + + material.side === DoubleSide + ? this.disable( gl.CULL_FACE ) + : this.enable( gl.CULL_FACE ); + + let flipSided = ( material.side === BackSide ); + if ( frontFaceCW ) flipSided = ! flipSided; + + this.setFlipSided( flipSided ); + + ( material.blending === NormalBlending && material.transparent === false ) + ? this.setBlending( NoBlending ) + : this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha ); + + this.setDepthFunc( material.depthFunc ); + this.setDepthTest( material.depthTest ); + this.setDepthMask( material.depthWrite ); + this.setColorMask( material.colorWrite ); + + const stencilWrite = material.stencilWrite; + this.setStencilTest( stencilWrite ); + if ( stencilWrite ) { + + this.setStencilMask( material.stencilWriteMask ); + this.setStencilFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask ); + this.setStencilOp( material.stencilFail, material.stencilZFail, material.stencilZPass ); + + } + + this.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits ); + + material.alphaToCoverage === true && this.backend.renderer.samples > 1 + ? this.enable( gl.SAMPLE_ALPHA_TO_COVERAGE ) + : this.disable( gl.SAMPLE_ALPHA_TO_COVERAGE ); + + if ( hardwareClippingPlanes > 0 ) { + + if ( this.currentClippingPlanes !== hardwareClippingPlanes ) { + + const CLIP_DISTANCE0_WEBGL = 0x3000; + + for ( let i = 0; i < 8; i ++ ) { + + if ( i < hardwareClippingPlanes ) { + + this.enable( CLIP_DISTANCE0_WEBGL + i ); + + } else { + + this.disable( CLIP_DISTANCE0_WEBGL + i ); + + } + + } + + } + + } + + } + + setPolygonOffset( polygonOffset, factor, units ) { + + const { gl } = this; + + if ( polygonOffset ) { + + this.enable( gl.POLYGON_OFFSET_FILL ); + + if ( this.currentPolygonOffsetFactor !== factor || this.currentPolygonOffsetUnits !== units ) { + + gl.polygonOffset( factor, units ); + + this.currentPolygonOffsetFactor = factor; + this.currentPolygonOffsetUnits = units; + + } + + } else { + + this.disable( gl.POLYGON_OFFSET_FILL ); + + } + + } + + useProgram( program ) { + + if ( this.currentProgram !== program ) { + + this.gl.useProgram( program ); + + this.currentProgram = program; + + return true; + + } + + return false; + + } + + // framebuffer + + + bindFramebuffer( target, framebuffer ) { + + const { gl, currentBoundFramebuffers } = this; + + if ( currentBoundFramebuffers[ target ] !== framebuffer ) { + + gl.bindFramebuffer( target, framebuffer ); + + currentBoundFramebuffers[ target ] = framebuffer; + + // gl.DRAW_FRAMEBUFFER is equivalent to gl.FRAMEBUFFER + + if ( target === gl.DRAW_FRAMEBUFFER ) { + + currentBoundFramebuffers[ gl.FRAMEBUFFER ] = framebuffer; + + } + + if ( target === gl.FRAMEBUFFER ) { + + currentBoundFramebuffers[ gl.DRAW_FRAMEBUFFER ] = framebuffer; + + } + + return true; + + } + + return false; + + } + + drawBuffers( renderContext, framebuffer ) { + + const { gl } = this; + + let drawBuffers = []; + + let needsUpdate = false; + + if ( renderContext.textures !== null ) { + + drawBuffers = this.currentDrawbuffers.get( framebuffer ); + + if ( drawBuffers === undefined ) { + + drawBuffers = []; + this.currentDrawbuffers.set( framebuffer, drawBuffers ); + + } + + + const textures = renderContext.textures; + + if ( drawBuffers.length !== textures.length || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) { + + for ( let i = 0, il = textures.length; i < il; i ++ ) { + + drawBuffers[ i ] = gl.COLOR_ATTACHMENT0 + i; + + } + + drawBuffers.length = textures.length; + + needsUpdate = true; + + } + + + } else { + + if ( drawBuffers[ 0 ] !== gl.BACK ) { + + drawBuffers[ 0 ] = gl.BACK; + + needsUpdate = true; + + } + + } + + if ( needsUpdate ) { + + gl.drawBuffers( drawBuffers ); + + } + + } + + + // texture + + activeTexture( webglSlot ) { + + const { gl, currentTextureSlot, maxTextures } = this; + + if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1; + + if ( currentTextureSlot !== webglSlot ) { + + gl.activeTexture( webglSlot ); + this.currentTextureSlot = webglSlot; + + } + + } + + bindTexture( webglType, webglTexture, webglSlot ) { + + const { gl, currentTextureSlot, currentBoundTextures, maxTextures } = this; + + if ( webglSlot === undefined ) { + + if ( currentTextureSlot === null ) { + + webglSlot = gl.TEXTURE0 + maxTextures - 1; + + } else { + + webglSlot = currentTextureSlot; + + } + + } + + let boundTexture = currentBoundTextures[ webglSlot ]; + + if ( boundTexture === undefined ) { + + boundTexture = { type: undefined, texture: undefined }; + currentBoundTextures[ webglSlot ] = boundTexture; + + } + + if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) { + + if ( currentTextureSlot !== webglSlot ) { + + gl.activeTexture( webglSlot ); + this.currentTextureSlot = webglSlot; + + } + + gl.bindTexture( webglType, webglTexture ); + + boundTexture.type = webglType; + boundTexture.texture = webglTexture; + + } + + } + + bindBufferBase( target, index, buffer ) { + + const { gl } = this; + + const key = `${target}-${index}`; + + if ( this.currentBoundBufferBases[ key ] !== buffer ) { + + gl.bindBufferBase( target, index, buffer ); + this.currentBoundBufferBases[ key ] = buffer; + + return true; + + } + + return false; + + } + + + unbindTexture() { + + const { gl, currentTextureSlot, currentBoundTextures } = this; + + const boundTexture = currentBoundTextures[ currentTextureSlot ]; + + if ( boundTexture !== undefined && boundTexture.type !== undefined ) { + + gl.bindTexture( boundTexture.type, null ); + + boundTexture.type = undefined; + boundTexture.texture = undefined; + + } + + } + +} + +class WebGLUtils { + + constructor( backend ) { + + this.backend = backend; + + this.gl = this.backend.gl; + this.extensions = backend.extensions; + + } + + convert( p, colorSpace = NoColorSpace ) { + + const { gl, extensions } = this; + + let extension; + + if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE; + if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4; + if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1; + if ( p === UnsignedInt5999Type ) return gl.UNSIGNED_INT_5_9_9_9_REV; + + if ( p === ByteType ) return gl.BYTE; + if ( p === ShortType ) return gl.SHORT; + if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT; + if ( p === IntType ) return gl.INT; + if ( p === UnsignedIntType ) return gl.UNSIGNED_INT; + if ( p === FloatType ) return gl.FLOAT; + + if ( p === HalfFloatType ) { + + return gl.HALF_FLOAT; + + } + + if ( p === AlphaFormat ) return gl.ALPHA; + if ( p === RGBFormat ) return gl.RGB; + if ( p === RGBAFormat ) return gl.RGBA; + if ( p === LuminanceFormat ) return gl.LUMINANCE; + if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA; + if ( p === DepthFormat ) return gl.DEPTH_COMPONENT; + if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL; + + // WebGL2 formats. + + if ( p === RedFormat ) return gl.RED; + if ( p === RedIntegerFormat ) return gl.RED_INTEGER; + if ( p === RGFormat ) return gl.RG; + if ( p === RGIntegerFormat ) return gl.RG_INTEGER; + if ( p === RGBAIntegerFormat ) return gl.RGBA_INTEGER; + + // S3TC + + if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) { + + if ( colorSpace === SRGBColorSpace ) { + + extension = extensions.get( 'WEBGL_compressed_texture_s3tc_srgb' ); + + if ( extension !== null ) { + + if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; + if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; + + } else { + + return null; + + } + + } else { + + extension = extensions.get( 'WEBGL_compressed_texture_s3tc' ); + + if ( extension !== null ) { + + if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; + if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; + if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; + + } else { + + return null; + + } + + } + + } + + // PVRTC + + if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' ); + + if ( extension !== null ) { + + if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; + if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; + if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + + } else { + + return null; + + } + + } + + // ETC + + if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_etc' ); + + if ( extension !== null ) { + + if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2; + if ( p === RGBA_ETC2_EAC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC; + + } else { + + return null; + + } + + } + + // ASTC + + if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || + p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || + p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || + p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || + p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_astc' ); + + if ( extension !== null ) { + + if ( p === RGBA_ASTC_4x4_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR; + if ( p === RGBA_ASTC_5x4_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR; + if ( p === RGBA_ASTC_5x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR; + if ( p === RGBA_ASTC_6x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR; + if ( p === RGBA_ASTC_6x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR; + if ( p === RGBA_ASTC_8x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR; + if ( p === RGBA_ASTC_8x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR; + if ( p === RGBA_ASTC_8x8_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR; + if ( p === RGBA_ASTC_10x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR; + if ( p === RGBA_ASTC_10x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR; + if ( p === RGBA_ASTC_10x8_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR; + if ( p === RGBA_ASTC_10x10_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR; + if ( p === RGBA_ASTC_12x10_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR; + if ( p === RGBA_ASTC_12x12_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR; + + } else { + + return null; + + } + + } + + // BPTC + + if ( p === RGBA_BPTC_Format ) { + + extension = extensions.get( 'EXT_texture_compression_bptc' ); + + if ( extension !== null ) { + + if ( p === RGBA_BPTC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT; + + } else { + + return null; + + } + + } + + // RGTC + + if ( p === RED_RGTC1_Format || p === SIGNED_RED_RGTC1_Format || p === RED_GREEN_RGTC2_Format || p === SIGNED_RED_GREEN_RGTC2_Format ) { + + extension = extensions.get( 'EXT_texture_compression_rgtc' ); + + if ( extension !== null ) { + + if ( p === RGBA_BPTC_Format ) return extension.COMPRESSED_RED_RGTC1_EXT; + if ( p === SIGNED_RED_RGTC1_Format ) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT; + if ( p === RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT; + if ( p === SIGNED_RED_GREEN_RGTC2_Format ) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT; + + } else { + + return null; + + } + + } + + // + + if ( p === UnsignedInt248Type ) { + + return gl.UNSIGNED_INT_24_8; + + } + + // if "p" can't be resolved, assume the user defines a WebGL constant as a string (fallback/workaround for packed RGB formats) + + return ( gl[ p ] !== undefined ) ? gl[ p ] : null; + + } + + _clientWaitAsync() { + + const { gl } = this; + + const sync = gl.fenceSync( gl.SYNC_GPU_COMMANDS_COMPLETE, 0 ); + + gl.flush(); + + return new Promise( ( resolve, reject ) => { + + function test() { + + const res = gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ); + + if ( res === gl.WAIT_FAILED ) { + + gl.deleteSync( sync ); + + reject(); + return; + + } + + if ( res === gl.TIMEOUT_EXPIRED ) { + + requestAnimationFrame( test ); + return; + + } + + gl.deleteSync( sync ); + + resolve(); + + } + + test(); + + } ); + + } + +} + +let initialized = false, wrappingToGL, filterToGL, compareToGL; + +class WebGLTextureUtils { + + constructor( backend ) { + + this.backend = backend; + + this.gl = backend.gl; + this.extensions = backend.extensions; + this.defaultTextures = {}; + + if ( initialized === false ) { + + this._init( this.gl ); + + initialized = true; + + } + + } + + _init( gl ) { + + // Store only WebGL constants here. + + wrappingToGL = { + [ RepeatWrapping ]: gl.REPEAT, + [ ClampToEdgeWrapping ]: gl.CLAMP_TO_EDGE, + [ MirroredRepeatWrapping ]: gl.MIRRORED_REPEAT + }; + + filterToGL = { + [ NearestFilter ]: gl.NEAREST, + [ NearestMipmapNearestFilter ]: gl.NEAREST_MIPMAP_NEAREST, + [ NearestMipmapLinearFilter ]: gl.NEAREST_MIPMAP_LINEAR, + + [ LinearFilter ]: gl.LINEAR, + [ LinearMipmapNearestFilter ]: gl.LINEAR_MIPMAP_NEAREST, + [ LinearMipmapLinearFilter ]: gl.LINEAR_MIPMAP_LINEAR + }; + + compareToGL = { + [ NeverCompare ]: gl.NEVER, + [ AlwaysCompare ]: gl.ALWAYS, + [ LessCompare ]: gl.LESS, + [ LessEqualCompare ]: gl.LEQUAL, + [ EqualCompare ]: gl.EQUAL, + [ GreaterEqualCompare ]: gl.GEQUAL, + [ GreaterCompare ]: gl.GREATER, + [ NotEqualCompare ]: gl.NOTEQUAL + }; + + } + + filterFallback( f ) { + + const { gl } = this; + + if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) { + + return gl.NEAREST; + + } + + return gl.LINEAR; + + } + + getGLTextureType( texture ) { + + const { gl } = this; + + let glTextureType; + + if ( texture.isCubeTexture === true ) { + + glTextureType = gl.TEXTURE_CUBE_MAP; + + } else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) { + + glTextureType = gl.TEXTURE_2D_ARRAY; + + } else if ( texture.isData3DTexture === true ) { // TODO: isCompressed3DTexture, wait for #26642 + + glTextureType = gl.TEXTURE_3D; + + } else { + + glTextureType = gl.TEXTURE_2D; + + + } + + return glTextureType; + + } + + getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) { + + const { gl, extensions } = this; + + if ( internalFormatName !== null ) { + + if ( gl[ internalFormatName ] !== undefined ) return gl[ internalFormatName ]; + + console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' ); + + } + + let internalFormat = glFormat; + + if ( glFormat === gl.RED ) { + + if ( glType === gl.FLOAT ) internalFormat = gl.R32F; + if ( glType === gl.HALF_FLOAT ) internalFormat = gl.R16F; + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.R16; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.R32UI; + if ( glType === gl.BYTE ) internalFormat = gl.R8I; + if ( glType === gl.SHORT ) internalFormat = gl.R16I; + if ( glType === gl.INT ) internalFormat = gl.R32I; + + } + + if ( glFormat === gl.RED_INTEGER ) { + + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8UI; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.R16UI; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.R32UI; + if ( glType === gl.BYTE ) internalFormat = gl.R8I; + if ( glType === gl.SHORT ) internalFormat = gl.R16I; + if ( glType === gl.INT ) internalFormat = gl.R32I; + + } + + if ( glFormat === gl.RG ) { + + if ( glType === gl.FLOAT ) internalFormat = gl.RG32F; + if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RG16F; + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RG8; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RG16; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RG32UI; + if ( glType === gl.BYTE ) internalFormat = gl.RG8I; + if ( glType === gl.SHORT ) internalFormat = gl.RG16I; + if ( glType === gl.INT ) internalFormat = gl.RG32I; + + } + + if ( glFormat === gl.RG_INTEGER ) { + + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RG8UI; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RG16UI; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RG32UI; + if ( glType === gl.BYTE ) internalFormat = gl.RG8I; + if ( glType === gl.SHORT ) internalFormat = gl.RG16I; + if ( glType === gl.INT ) internalFormat = gl.RG32I; + + } + + if ( glFormat === gl.RGB ) { + + if ( glType === gl.FLOAT ) internalFormat = gl.RGB32F; + if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGB16F; + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RGB8; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RGB16; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RGB32UI; + if ( glType === gl.BYTE ) internalFormat = gl.RGB8I; + if ( glType === gl.SHORT ) internalFormat = gl.RGB16I; + if ( glType === gl.INT ) internalFormat = gl.RGB32I; + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( colorSpace === SRGBColorSpace && forceLinearTransfer === false ) ? gl.SRGB8 : gl.RGB8; + if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565; + if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1; + if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4; + if ( glType === gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = gl.RGB9_E5; + + } + + if ( glFormat === gl.RGB_INTEGER ) { + + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RGB8UI; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RGB16UI; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RGB32UI; + if ( glType === gl.BYTE ) internalFormat = gl.RGB8I; + if ( glType === gl.SHORT ) internalFormat = gl.RGB16I; + if ( glType === gl.INT ) internalFormat = gl.RGB32I; + + } + + if ( glFormat === gl.RGBA ) { + + if ( glType === gl.FLOAT ) internalFormat = gl.RGBA32F; + if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGBA16F; + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RGBA8; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RGBA16; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RGBA32UI; + if ( glType === gl.BYTE ) internalFormat = gl.RGBA8I; + if ( glType === gl.SHORT ) internalFormat = gl.RGBA16I; + if ( glType === gl.INT ) internalFormat = gl.RGBA32I; + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( colorSpace === SRGBColorSpace && forceLinearTransfer === false ) ? gl.SRGB8_ALPHA8 : gl.RGBA8; + if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGBA4; + if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1; + + } + + if ( glFormat === gl.RGBA_INTEGER ) { + + if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RGBA8UI; + if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.RGBA16UI; + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.RGBA32UI; + if ( glType === gl.BYTE ) internalFormat = gl.RGBA8I; + if ( glType === gl.SHORT ) internalFormat = gl.RGBA16I; + if ( glType === gl.INT ) internalFormat = gl.RGBA32I; + + } + + if ( glFormat === gl.DEPTH_COMPONENT ) { + + if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.DEPTH24_STENCIL8; + if ( glType === gl.FLOAT ) internalFormat = gl.DEPTH_COMPONENT32F; + + } + + if ( glFormat === gl.DEPTH_STENCIL ) { + + if ( glType === gl.UNSIGNED_INT_24_8 ) internalFormat = gl.DEPTH24_STENCIL8; + + } + + if ( internalFormat === gl.R16F || internalFormat === gl.R32F || + internalFormat === gl.RG16F || internalFormat === gl.RG32F || + internalFormat === gl.RGBA16F || internalFormat === gl.RGBA32F ) { + + extensions.get( 'EXT_color_buffer_float' ); + + } + + return internalFormat; + + } + + setTextureParameters( textureType, texture ) { + + const { gl, extensions, backend } = this; + + + gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, texture.flipY ); + gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha ); + gl.pixelStorei( gl.UNPACK_ALIGNMENT, texture.unpackAlignment ); + gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE ); + + gl.texParameteri( textureType, gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] ); + gl.texParameteri( textureType, gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] ); + + if ( textureType === gl.TEXTURE_3D || textureType === gl.TEXTURE_2D_ARRAY ) { + + gl.texParameteri( textureType, gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] ); + + } + + gl.texParameteri( textureType, gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] ); + + + const hasMipmaps = texture.mipmaps !== undefined && texture.mipmaps.length > 0; + + // follow WebGPU backend mapping for texture filtering + const minFilter = texture.minFilter === LinearFilter && hasMipmaps ? LinearMipmapLinearFilter : texture.minFilter; + + gl.texParameteri( textureType, gl.TEXTURE_MIN_FILTER, filterToGL[ minFilter ] ); + + if ( texture.compareFunction ) { + + gl.texParameteri( textureType, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE ); + gl.texParameteri( textureType, gl.TEXTURE_COMPARE_FUNC, compareToGL[ texture.compareFunction ] ); + + } + + if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) { + + if ( texture.magFilter === NearestFilter ) return; + if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return; + if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2 + + if ( texture.anisotropy > 1 ) { + + const extension = extensions.get( 'EXT_texture_filter_anisotropic' ); + gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, backend.getMaxAnisotropy() ) ); + + } + + } + + } + + createDefaultTexture( texture ) { + + const { gl, backend, defaultTextures } = this; + + + const glTextureType = this.getGLTextureType( texture ); + + let textureGPU = defaultTextures[ glTextureType ]; + + if ( textureGPU === undefined ) { + + textureGPU = gl.createTexture(); + + backend.state.bindTexture( glTextureType, textureGPU ); + gl.texParameteri( glTextureType, gl.TEXTURE_MIN_FILTER, gl.NEAREST ); + gl.texParameteri( glTextureType, gl.TEXTURE_MAG_FILTER, gl.NEAREST ); + + // gl.texImage2D( glTextureType, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data ); + + defaultTextures[ glTextureType ] = textureGPU; + + } + + backend.set( texture, { + textureGPU, + glTextureType, + isDefault: true + } ); + + } + + createTexture( texture, options ) { + + const { gl, backend } = this; + const { levels, width, height, depth } = options; + + const glFormat = backend.utils.convert( texture.format, texture.colorSpace ); + const glType = backend.utils.convert( texture.type ); + const glInternalFormat = this.getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture ); + + const textureGPU = gl.createTexture(); + const glTextureType = this.getGLTextureType( texture ); + + backend.state.bindTexture( glTextureType, textureGPU ); + + this.setTextureParameters( glTextureType, texture ); + + if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) { + + gl.texStorage3D( gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, width, height, depth ); + + } else if ( texture.isData3DTexture ) { + + gl.texStorage3D( gl.TEXTURE_3D, levels, glInternalFormat, width, height, depth ); + + } else if ( ! texture.isVideoTexture ) { + + gl.texStorage2D( glTextureType, levels, glInternalFormat, width, height ); + + } + + backend.set( texture, { + textureGPU, + glTextureType, + glFormat, + glType, + glInternalFormat + } ); + + } + + copyBufferToTexture( buffer, texture ) { + + const { gl, backend } = this; + + const { textureGPU, glTextureType, glFormat, glType } = backend.get( texture ); + + const { width, height } = texture.source.data; + + gl.bindBuffer( gl.PIXEL_UNPACK_BUFFER, buffer ); + + backend.state.bindTexture( glTextureType, textureGPU ); + + gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false ); + gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false ); + gl.texSubImage2D( glTextureType, 0, 0, 0, width, height, glFormat, glType, 0 ); + + gl.bindBuffer( gl.PIXEL_UNPACK_BUFFER, null ); + + backend.state.unbindTexture(); + // debug + // const framebuffer = gl.createFramebuffer(); + // gl.bindFramebuffer( gl.FRAMEBUFFER, framebuffer ); + // gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, glTextureType, textureGPU, 0 ); + + // const readout = new Float32Array( width * height * 4 ); + + // const altFormat = gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_FORMAT ); + // const altType = gl.getParameter( gl.IMPLEMENTATION_COLOR_READ_TYPE ); + + // gl.readPixels( 0, 0, width, height, altFormat, altType, readout ); + // gl.bindFramebuffer( gl.FRAMEBUFFER, null ); + // console.log( readout ); + + } + + updateTexture( texture, options ) { + + const { gl } = this; + const { width, height } = options; + const { textureGPU, glTextureType, glFormat, glType, glInternalFormat } = this.backend.get( texture ); + + if ( texture.isRenderTargetTexture || ( textureGPU === undefined /* unsupported texture format */ ) ) + return; + + const getImage = ( source ) => { + + if ( source.isDataTexture ) { + + return source.image.data; + + } else if ( ( typeof HTMLImageElement !== 'undefined' && source instanceof HTMLImageElement ) || + ( typeof HTMLCanvasElement !== 'undefined' && source instanceof HTMLCanvasElement ) || + ( typeof ImageBitmap !== 'undefined' && source instanceof ImageBitmap ) || + source instanceof OffscreenCanvas ) { + + return source; + + } + + return source.data; + + }; + + this.backend.state.bindTexture( glTextureType, textureGPU ); + + this.setTextureParameters( glTextureType, texture ); + + if ( texture.isCompressedTexture ) { + + const mipmaps = texture.mipmaps; + const image = options.image; + + for ( let i = 0; i < mipmaps.length; i ++ ) { + + const mipmap = mipmaps[ i ]; + + if ( texture.isCompressedArrayTexture ) { + + + if ( texture.format !== gl.RGBA ) { + + if ( glFormat !== null ) { + + gl.compressedTexSubImage3D( gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data ); + + } else { + + console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' ); + + } + + } else { + + gl.texSubImage3D( gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data ); + + } + + } else { + + if ( glFormat !== null ) { + + gl.compressedTexSubImage2D( gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data ); + + } else { + + console.warn( 'Unsupported compressed texture format' ); + + } + + } + + } + + + } else if ( texture.isCubeTexture ) { + + const images = options.images; + + for ( let i = 0; i < 6; i ++ ) { + + const image = getImage( images[ i ] ); + + gl.texSubImage2D( gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, width, height, glFormat, glType, image ); + + } + + } else if ( texture.isDataArrayTexture ) { + + const image = options.image; + + gl.texSubImage3D( gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data ); + + } else if ( texture.isData3DTexture ) { + + const image = options.image; + + gl.texSubImage3D( gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data ); + + } else if ( texture.isVideoTexture ) { + + texture.update(); + + gl.texImage2D( glTextureType, 0, glInternalFormat, glFormat, glType, options.image ); + + + } else { + + const image = getImage( options.image ); + + gl.texSubImage2D( glTextureType, 0, 0, 0, width, height, glFormat, glType, image ); + + } + + } + + generateMipmaps( texture ) { + + const { gl, backend } = this; + const { textureGPU, glTextureType } = backend.get( texture ); + + backend.state.bindTexture( glTextureType, textureGPU ); + gl.generateMipmap( glTextureType ); + + } + + deallocateRenderBuffers( renderTarget ) { + + const { gl, backend } = this; + + // remove framebuffer reference + if ( renderTarget ) { + + const renderContextData = backend.get( renderTarget ); + + renderContextData.renderBufferStorageSetup = undefined; + + if ( renderContextData.framebuffers ) { + + for ( const cacheKey in renderContextData.framebuffers ) { + + gl.deleteFramebuffer( renderContextData.framebuffers[ cacheKey ] ); + + } + + delete renderContextData.framebuffers; + + } + + if ( renderContextData.depthRenderbuffer ) { + + gl.deleteRenderbuffer( renderContextData.depthRenderbuffer ); + delete renderContextData.depthRenderbuffer; + + } + + if ( renderContextData.stencilRenderbuffer ) { + + gl.deleteRenderbuffer( renderContextData.stencilRenderbuffer ); + delete renderContextData.stencilRenderbuffer; + + } + + if ( renderContextData.msaaFrameBuffer ) { + + gl.deleteFramebuffer( renderContextData.msaaFrameBuffer ); + delete renderContextData.msaaFrameBuffer; + + } + + if ( renderContextData.msaaRenderbuffers ) { + + for ( let i = 0; i < renderContextData.msaaRenderbuffers.length; i ++ ) { + + gl.deleteRenderbuffer( renderContextData.msaaRenderbuffers[ i ] ); + + } + + delete renderContextData.msaaRenderbuffers; + + } + + } + + } + + destroyTexture( texture ) { + + const { gl, backend } = this; + const { textureGPU, renderTarget } = backend.get( texture ); + + this.deallocateRenderBuffers( renderTarget ); + gl.deleteTexture( textureGPU ); + + backend.delete( texture ); + + } + + copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { + + const { gl, backend } = this; + const { state } = this.backend; + + const { textureGPU: dstTextureGPU, glTextureType, glType, glFormat } = backend.get( dstTexture ); + + let width, height, minX, minY; + let dstX, dstY; + + if ( srcRegion !== null ) { + + width = srcRegion.max.x - srcRegion.min.x; + height = srcRegion.max.y - srcRegion.min.y; + minX = srcRegion.min.x; + minY = srcRegion.min.y; + + } else { + + width = srcTexture.image.width; + height = srcTexture.image.height; + minX = 0; + minY = 0; + + } + + if ( dstPosition !== null ) { + + dstX = dstPosition.x; + dstY = dstPosition.y; + + } else { + + dstX = 0; + dstY = 0; + + } + + state.bindTexture( glTextureType, dstTextureGPU ); + + // As another texture upload may have changed pixelStorei + // parameters, make sure they are correct for the dstTexture + gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); + gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY ); + gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha ); + gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment ); + + const currentUnpackRowLen = gl.getParameter( gl.UNPACK_ROW_LENGTH ); + const currentUnpackImageHeight = gl.getParameter( gl.UNPACK_IMAGE_HEIGHT ); + const currentUnpackSkipPixels = gl.getParameter( gl.UNPACK_SKIP_PIXELS ); + const currentUnpackSkipRows = gl.getParameter( gl.UNPACK_SKIP_ROWS ); + const currentUnpackSkipImages = gl.getParameter( gl.UNPACK_SKIP_IMAGES ); + + const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image; + + gl.pixelStorei( gl.UNPACK_ROW_LENGTH, image.width ); + gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, image.height ); + gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, minX ); + gl.pixelStorei( gl.UNPACK_SKIP_ROWS, minY ); + + if ( srcTexture.isRenderTargetTexture || srcTexture.isDepthTexture ) { + + const srcTextureData = backend.get( srcTexture ); + const dstTextureData = backend.get( dstTexture ); + + const srcRenderContextData = backend.get( srcTextureData.renderTarget ); + const dstRenderContextData = backend.get( dstTextureData.renderTarget ); + + const srcFramebuffer = srcRenderContextData.framebuffers[ srcTextureData.cacheKey ]; + const dstFramebuffer = dstRenderContextData.framebuffers[ dstTextureData.cacheKey ]; + + state.bindFramebuffer( gl.READ_FRAMEBUFFER, srcFramebuffer ); + state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, dstFramebuffer ); + + let mask = gl.COLOR_BUFFER_BIT; + + if ( srcTexture.isDepthTexture ) mask = gl.DEPTH_BUFFER_BIT; + + gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, mask, gl.NEAREST ); + + state.bindFramebuffer( gl.READ_FRAMEBUFFER, null ); + state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, null ); + + } else { + + if ( srcTexture.isDataTexture ) { + + gl.texSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data ); + + } else { + + if ( srcTexture.isCompressedTexture ) { + + gl.compressedTexSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data ); + + } else { + + gl.texSubImage2D( gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image ); + + } + + } + + } + + gl.pixelStorei( gl.UNPACK_ROW_LENGTH, currentUnpackRowLen ); + gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight ); + gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels ); + gl.pixelStorei( gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows ); + gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages ); + + // Generate mipmaps only when copying level 0 + if ( level === 0 && dstTexture.generateMipmaps ) gl.generateMipmap( gl.TEXTURE_2D ); + + state.unbindTexture(); + + } + + copyFramebufferToTexture( texture, renderContext, rectangle ) { + + const { gl } = this; + const { state } = this.backend; + + const { textureGPU } = this.backend.get( texture ); + + const { x, y, z: width, w: height } = rectangle; + + const requireDrawFrameBuffer = texture.isDepthTexture === true || ( renderContext.renderTarget && renderContext.renderTarget.samples > 0 ); + + const srcHeight = renderContext.renderTarget ? renderContext.renderTarget.height : this.backend.gerDrawingBufferSize().y; + + if ( requireDrawFrameBuffer ) { + + const partial = ( x !== 0 || y !== 0 ); + let mask; + let attachment; + + if ( texture.isDepthTexture === true ) { + + mask = gl.DEPTH_BUFFER_BIT; + attachment = gl.DEPTH_ATTACHMENT; + + if ( renderContext.stencil ) { + + mask |= gl.STENCIL_BUFFER_BIT; + + } + + } else { + + mask = gl.COLOR_BUFFER_BIT; + attachment = gl.COLOR_ATTACHMENT0; + + } + + if ( partial ) { + + const renderTargetContextData = this.backend.get( renderContext.renderTarget ); + + const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ]; + const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer; + + state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb ); + state.bindFramebuffer( gl.READ_FRAMEBUFFER, msaaFrameBuffer ); + + const flippedY = srcHeight - y - height; + + gl.blitFramebuffer( x, flippedY, x + width, flippedY + height, x, flippedY, x + width, flippedY + height, mask, gl.NEAREST ); + + state.bindFramebuffer( gl.READ_FRAMEBUFFER, fb ); + + state.bindTexture( gl.TEXTURE_2D, textureGPU ); + + gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, x, flippedY, width, height ); + + state.unbindTexture(); + + } else { + + const fb = gl.createFramebuffer(); + + state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb ); + + gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 ); + gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST ); + + gl.deleteFramebuffer( fb ); + + } + + } else { + + state.bindTexture( gl.TEXTURE_2D, textureGPU ); + gl.copyTexSubImage2D( gl.TEXTURE_2D, 0, 0, 0, x, srcHeight - height - y, width, height ); + + state.unbindTexture(); + + } + + if ( texture.generateMipmaps ) this.generateMipmaps( texture ); + + this.backend._setFramebuffer( renderContext ); + + } + + // Setup storage for internal depth/stencil buffers and bind to correct framebuffer + setupRenderBufferStorage( renderbuffer, renderContext ) { + + const { gl } = this; + const renderTarget = renderContext.renderTarget; + + const { samples, depthTexture, depthBuffer, stencilBuffer, width, height } = renderTarget; + + gl.bindRenderbuffer( gl.RENDERBUFFER, renderbuffer ); + + if ( depthBuffer && ! stencilBuffer ) { + + let glInternalFormat = gl.DEPTH_COMPONENT24; + + if ( samples > 0 ) { + + if ( depthTexture && depthTexture.isDepthTexture ) { + + if ( depthTexture.type === gl.FLOAT ) { + + glInternalFormat = gl.DEPTH_COMPONENT32F; + + } + + } + + gl.renderbufferStorageMultisample( gl.RENDERBUFFER, samples, glInternalFormat, width, height ); + + } else { + + gl.renderbufferStorage( gl.RENDERBUFFER, glInternalFormat, width, height ); + + } + + gl.framebufferRenderbuffer( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer ); + + } else if ( depthBuffer && stencilBuffer ) { + + if ( samples > 0 ) { + + gl.renderbufferStorageMultisample( gl.RENDERBUFFER, samples, gl.DEPTH24_STENCIL8, width, height ); + + } else { + + gl.renderbufferStorage( gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height ); + + } + + + gl.framebufferRenderbuffer( gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, renderbuffer ); + + } + + } + + async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { + + const { backend, gl } = this; + + const { textureGPU, glFormat, glType } = this.backend.get( texture ); + + const fb = gl.createFramebuffer(); + + gl.bindFramebuffer( gl.READ_FRAMEBUFFER, fb ); + + const target = texture.isCubeTexture ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D; + + gl.framebufferTexture2D( gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, target, textureGPU, 0 ); + + const typedArrayType = this._getTypedArrayType( glType ); + const bytesPerTexel = this._getBytesPerTexel( glType, glFormat ); + + const elementCount = width * height; + const byteLength = elementCount * bytesPerTexel; + + const buffer = gl.createBuffer(); + + gl.bindBuffer( gl.PIXEL_PACK_BUFFER, buffer ); + gl.bufferData( gl.PIXEL_PACK_BUFFER, byteLength, gl.STREAM_READ ); + gl.readPixels( x, y, width, height, glFormat, glType, 0 ); + gl.bindBuffer( gl.PIXEL_PACK_BUFFER, null ); + + await backend.utils._clientWaitAsync(); + + const dstBuffer = new typedArrayType( byteLength / typedArrayType.BYTES_PER_ELEMENT ); + + gl.bindBuffer( gl.PIXEL_PACK_BUFFER, buffer ); + gl.getBufferSubData( gl.PIXEL_PACK_BUFFER, 0, dstBuffer ); + gl.bindBuffer( gl.PIXEL_PACK_BUFFER, null ); + + gl.deleteFramebuffer( fb ); + + return dstBuffer; + + } + + _getTypedArrayType( glType ) { + + const { gl } = this; + + if ( glType === gl.UNSIGNED_BYTE ) return Uint8Array; + + if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) return Uint16Array; + if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) return Uint16Array; + if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) return Uint16Array; + if ( glType === gl.UNSIGNED_SHORT ) return Uint16Array; + if ( glType === gl.UNSIGNED_INT ) return Uint32Array; + + if ( glType === gl.HALF_FLOAT ) return Uint16Array; + if ( glType === gl.FLOAT ) return Float32Array; + + throw new Error( `Unsupported WebGL type: ${glType}` ); + + } + + _getBytesPerTexel( glType, glFormat ) { + + const { gl } = this; + + let bytesPerComponent = 0; + + if ( glType === gl.UNSIGNED_BYTE ) bytesPerComponent = 1; + + if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 || + glType === gl.UNSIGNED_SHORT_5_5_5_1 || + glType === gl.UNSIGNED_SHORT_5_6_5 || + glType === gl.UNSIGNED_SHORT || + glType === gl.HALF_FLOAT ) bytesPerComponent = 2; + + if ( glType === gl.UNSIGNED_INT || + glType === gl.FLOAT ) bytesPerComponent = 4; + + if ( glFormat === gl.RGBA ) return bytesPerComponent * 4; + if ( glFormat === gl.RGB ) return bytesPerComponent * 3; + if ( glFormat === gl.ALPHA ) return bytesPerComponent; + + } + +} + +class WebGLExtensions { + + constructor( backend ) { + + this.backend = backend; + + this.gl = this.backend.gl; + this.availableExtensions = this.gl.getSupportedExtensions(); + + this.extensions = {}; + + } + + get( name ) { + + let extension = this.extensions[ name ]; + + if ( extension === undefined ) { + + extension = this.gl.getExtension( name ); + + this.extensions[ name ] = extension; + + } + + return extension; + + } + + has( name ) { + + return this.availableExtensions.includes( name ); + + } + +} + +class WebGLCapabilities { + + constructor( backend ) { + + this.backend = backend; + + this.maxAnisotropy = null; + + } + + getMaxAnisotropy() { + + if ( this.maxAnisotropy !== null ) return this.maxAnisotropy; + + const gl = this.backend.gl; + const extensions = this.backend.extensions; + + if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) { + + const extension = extensions.get( 'EXT_texture_filter_anisotropic' ); + + this.maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT ); + + } else { + + this.maxAnisotropy = 0; + + } + + return this.maxAnisotropy; + + } + +} + +const GLFeatureName = { + + 'WEBGL_multi_draw': 'WEBGL_multi_draw', + 'WEBGL_compressed_texture_astc': 'texture-compression-astc', + 'WEBGL_compressed_texture_etc': 'texture-compression-etc2', + 'WEBGL_compressed_texture_etc1': 'texture-compression-etc1', + 'WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc', + 'WEBKIT_WEBGL_compressed_texture_pvrtc': 'texture-compression-pvrtc', + 'WEBGL_compressed_texture_s3tc': 'texture-compression-bc', + 'EXT_texture_compression_bptc': 'texture-compression-bptc', + 'EXT_disjoint_timer_query_webgl2': 'timestamp-query', + +}; + +class WebGLBufferRenderer { + + constructor( backend ) { + + this.gl = backend.gl; + this.extensions = backend.extensions; + this.info = backend.renderer.info; + this.mode = null; + this.index = 0; + this.type = null; + this.object = null; + + } + + render( start, count ) { + + const { gl, mode, object, type, info, index } = this; + + if ( index !== 0 ) { + + gl.drawElements( mode, count, type, start ); + + } else { + + gl.drawArrays( mode, start, count ); + + } + + info.update( object, count, mode, 1 ); + + } + + renderInstances( start, count, primcount ) { + + const { gl, mode, type, index, object, info } = this; + + if ( primcount === 0 ) return; + + if ( index !== 0 ) { + + gl.drawElementsInstanced( mode, count, type, start, primcount ); + + } else { + + gl.drawArraysInstanced( mode, start, count, primcount ); + + } + + info.update( object, count, mode, primcount ); + + } + + renderMultiDraw( starts, counts, drawCount ) { + + const { extensions, mode, object, info } = this; + + if ( drawCount === 0 ) return; + + const extension = extensions.get( 'WEBGL_multi_draw' ); + + if ( extension === null ) { + + for ( let i = 0; i < drawCount; i ++ ) { + + this.render( starts[ i ], counts[ i ] ); + + } + + } else { + + if ( this.index !== 0 ) { + + extension.multiDrawElementsWEBGL( mode, counts, 0, this.type, starts, 0, drawCount ); + + } else { + + extension.multiDrawArraysWEBGL( mode, starts, 0, counts, 0, drawCount ); + + } + + let elementCount = 0; + for ( let i = 0; i < drawCount; i ++ ) { + + elementCount += counts[ i ]; + + } + + info.update( object, elementCount, mode, 1 ); + + } + + } + + renderMultiDrawInstances( starts, counts, drawCount, primcount ) { + + const { extensions, mode, object, info } = this; + + if ( drawCount === 0 ) return; + + const extension = extensions.get( 'WEBGL_multi_draw' ); + + if ( extension === null ) { + + for ( let i = 0; i < drawCount; i ++ ) { + + this.renderInstances( starts[ i ], counts[ i ], primcount[ i ] ); + + } + + } else { + + if ( this.index !== 0 ) { + + extension.multiDrawElementsInstancedWEBGL( mode, counts, 0, this.type, starts, 0, primcount, 0, drawCount ); + + } else { + + extension.multiDrawArraysInstancedWEBGL( mode, starts, 0, counts, 0, primcount, 0, drawCount ); + + } + + let elementCount = 0; + for ( let i = 0; i < drawCount; i ++ ) { + + elementCount += counts[ i ] * primcount[ i ]; + + } + + info.update( object, elementCount, mode, 1 ); + + } + + } + + // + +} + +// + +class WebGLBackend extends Backend { + + constructor( parameters = {} ) { + + super( parameters ); + + this.isWebGLBackend = true; + + } + + init( renderer ) { + + super.init( renderer ); + + // + + const parameters = this.parameters; + + const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2' ); + + function onContextLost( event ) { + + event.preventDefault(); + + const contextLossInfo = { + api: 'WebGL', + message: event.statusMessage || 'Unknown reason', + reason: null, + originalEvent: event + }; + + renderer.onDeviceLost( contextLossInfo ); + + } + + this._onContextLost = onContextLost; + + renderer.domElement.addEventListener( 'webglcontextlost', onContextLost, false ); + + this.gl = glContext; + + this.extensions = new WebGLExtensions( this ); + this.capabilities = new WebGLCapabilities( this ); + this.attributeUtils = new WebGLAttributeUtils( this ); + this.textureUtils = new WebGLTextureUtils( this ); + this.bufferRenderer = new WebGLBufferRenderer( this ); + + this.state = new WebGLState( this ); + this.utils = new WebGLUtils( this ); + + this.vaoCache = {}; + this.transformFeedbackCache = {}; + this.discard = false; + this.trackTimestamp = ( parameters.trackTimestamp === true ); + + this.extensions.get( 'EXT_color_buffer_float' ); + this.extensions.get( 'WEBGL_clip_cull_distance' ); + this.extensions.get( 'OES_texture_float_linear' ); + this.extensions.get( 'EXT_color_buffer_half_float' ); + this.extensions.get( 'WEBGL_multisampled_render_to_texture' ); + this.extensions.get( 'WEBGL_render_shared_exponent' ); + this.extensions.get( 'WEBGL_multi_draw' ); + + this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' ); + this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' ); + + this._knownBindings = new WeakSet(); + + this._currentContext = null; + + } + + get coordinateSystem() { + + return WebGLCoordinateSystem; + + } + + async getArrayBufferAsync( attribute ) { + + return await this.attributeUtils.getArrayBufferAsync( attribute ); + + } + + async waitForGPU() { + + await this.utils._clientWaitAsync(); + + } + + initTimestampQuery( renderContext ) { + + if ( ! this.disjoint || ! this.trackTimestamp ) return; + + const renderContextData = this.get( renderContext ); + + if ( this.queryRunning ) { + + if ( ! renderContextData.queryQueue ) renderContextData.queryQueue = []; + renderContextData.queryQueue.push( renderContext ); + return; + + } + + if ( renderContextData.activeQuery ) { + + this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT ); + renderContextData.activeQuery = null; + + } + + renderContextData.activeQuery = this.gl.createQuery(); + + if ( renderContextData.activeQuery !== null ) { + + this.gl.beginQuery( this.disjoint.TIME_ELAPSED_EXT, renderContextData.activeQuery ); + this.queryRunning = true; + + } + + } + + // timestamp utils + + prepareTimestampBuffer( renderContext ) { + + if ( ! this.disjoint || ! this.trackTimestamp ) return; + + const renderContextData = this.get( renderContext ); + + if ( renderContextData.activeQuery ) { + + this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT ); + + if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = []; + renderContextData.gpuQueries.push( { query: renderContextData.activeQuery } ); + renderContextData.activeQuery = null; + this.queryRunning = false; + + if ( renderContextData.queryQueue && renderContextData.queryQueue.length > 0 ) { + + const nextRenderContext = renderContextData.queryQueue.shift(); + this.initTimestampQuery( nextRenderContext ); + + } + + } + + } + + async resolveTimestampAsync( renderContext, type = 'render' ) { + + if ( ! this.disjoint || ! this.trackTimestamp ) return; + + const renderContextData = this.get( renderContext ); + + if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = []; + + for ( let i = 0; i < renderContextData.gpuQueries.length; i ++ ) { + + const queryInfo = renderContextData.gpuQueries[ i ]; + const available = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT_AVAILABLE ); + const disjoint = this.gl.getParameter( this.disjoint.GPU_DISJOINT_EXT ); + + if ( available && ! disjoint ) { + + const elapsed = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT ); + const duration = Number( elapsed ) / 1000000; // Convert nanoseconds to milliseconds + this.gl.deleteQuery( queryInfo.query ); + renderContextData.gpuQueries.splice( i, 1 ); // Remove the processed query + i --; + this.renderer.info.updateTimestamp( type, duration ); + + } + + } + + } + + getContext() { + + return this.gl; + + } + + beginRender( renderContext ) { + + const { gl } = this; + const renderContextData = this.get( renderContext ); + + // + + // + + this.initTimestampQuery( renderContext ); + + renderContextData.previousContext = this._currentContext; + this._currentContext = renderContext; + + this._setFramebuffer( renderContext ); + + this.clear( renderContext.clearColor, renderContext.clearDepth, renderContext.clearStencil, renderContext, false ); + + // + if ( renderContext.viewport ) { + + this.updateViewport( renderContext ); + + } else { + + gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight ); + + } + + if ( renderContext.scissor ) { + + const { x, y, width, height } = renderContext.scissorValue; + + gl.scissor( x, renderContext.height - height - y, width, height ); + + } + + const occlusionQueryCount = renderContext.occlusionQueryCount; + + if ( occlusionQueryCount > 0 ) { + + // Get a reference to the array of objects with queries. The renderContextData property + // can be changed by another render pass before the async reading of all previous queries complete + renderContextData.currentOcclusionQueries = renderContextData.occlusionQueries; + renderContextData.currentOcclusionQueryObjects = renderContextData.occlusionQueryObjects; + + renderContextData.lastOcclusionObject = null; + renderContextData.occlusionQueries = new Array( occlusionQueryCount ); + renderContextData.occlusionQueryObjects = new Array( occlusionQueryCount ); + renderContextData.occlusionQueryIndex = 0; + + } + + } + + finishRender( renderContext ) { + + const { gl, state } = this; + const renderContextData = this.get( renderContext ); + const previousContext = renderContextData.previousContext; + + const occlusionQueryCount = renderContext.occlusionQueryCount; + + if ( occlusionQueryCount > 0 ) { + + if ( occlusionQueryCount > renderContextData.occlusionQueryIndex ) { + + gl.endQuery( gl.ANY_SAMPLES_PASSED ); + + } + + this.resolveOccludedAsync( renderContext ); + + } + + const textures = renderContext.textures; + + if ( textures !== null ) { + + for ( let i = 0; i < textures.length; i ++ ) { + + const texture = textures[ i ]; + + if ( texture.generateMipmaps ) { + + this.generateMipmaps( texture ); + + } + + } + + } + + this._currentContext = previousContext; + + if ( renderContext.textures !== null && renderContext.renderTarget ) { + + const renderTargetContextData = this.get( renderContext.renderTarget ); + + const { samples } = renderContext.renderTarget; + + if ( samples > 0 ) { + + const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ]; + + const mask = gl.COLOR_BUFFER_BIT; + + const msaaFrameBuffer = renderTargetContextData.msaaFrameBuffer; + + const textures = renderContext.textures; + + state.bindFramebuffer( gl.READ_FRAMEBUFFER, msaaFrameBuffer ); + state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb ); + + for ( let i = 0; i < textures.length; i ++ ) { + + // TODO Add support for MRT + + if ( renderContext.scissor ) { + + const { x, y, width, height } = renderContext.scissorValue; + + const viewY = renderContext.height - height - y; + + gl.blitFramebuffer( x, viewY, x + width, viewY + height, x, viewY, x + width, viewY + height, mask, gl.NEAREST ); + gl.invalidateSubFramebuffer( gl.READ_FRAMEBUFFER, renderTargetContextData.invalidationArray, x, viewY, width, height ); + + } else { + + gl.blitFramebuffer( 0, 0, renderContext.width, renderContext.height, 0, 0, renderContext.width, renderContext.height, mask, gl.NEAREST ); + gl.invalidateFramebuffer( gl.READ_FRAMEBUFFER, renderTargetContextData.invalidationArray ); + + } + + } + + } + + + } + + if ( previousContext !== null ) { + + this._setFramebuffer( previousContext ); + + if ( previousContext.viewport ) { + + this.updateViewport( previousContext ); + + } else { + + gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight ); + + } + + } + + this.prepareTimestampBuffer( renderContext ); + + } + + resolveOccludedAsync( renderContext ) { + + const renderContextData = this.get( renderContext ); + + // handle occlusion query results + + const { currentOcclusionQueries, currentOcclusionQueryObjects } = renderContextData; + + if ( currentOcclusionQueries && currentOcclusionQueryObjects ) { + + const occluded = new WeakSet(); + const { gl } = this; + + renderContextData.currentOcclusionQueryObjects = null; + renderContextData.currentOcclusionQueries = null; + + const check = () => { + + let completed = 0; + + // check all queries and requeue as appropriate + for ( let i = 0; i < currentOcclusionQueries.length; i ++ ) { + + const query = currentOcclusionQueries[ i ]; + + if ( query === null ) continue; + + if ( gl.getQueryParameter( query, gl.QUERY_RESULT_AVAILABLE ) ) { + + if ( gl.getQueryParameter( query, gl.QUERY_RESULT ) > 0 ) occluded.add( currentOcclusionQueryObjects[ i ] ); + + currentOcclusionQueries[ i ] = null; + gl.deleteQuery( query ); + + completed ++; + + } + + } + + if ( completed < currentOcclusionQueries.length ) { + + requestAnimationFrame( check ); + + } else { + + renderContextData.occluded = occluded; + + } + + }; + + check(); + + } + + } + + isOccluded( renderContext, object ) { + + const renderContextData = this.get( renderContext ); + + return renderContextData.occluded && renderContextData.occluded.has( object ); + + } + + updateViewport( renderContext ) { + + const gl = this.gl; + const { x, y, width, height } = renderContext.viewportValue; + + gl.viewport( x, renderContext.height - height - y, width, height ); + + } + + setScissorTest( boolean ) { + + const gl = this.gl; + + if ( boolean ) { + + gl.enable( gl.SCISSOR_TEST ); + + } else { + + gl.disable( gl.SCISSOR_TEST ); + + } + + } + + clear( color, depth, stencil, descriptor = null, setFrameBuffer = true ) { + + const { gl } = this; + + if ( descriptor === null ) { + + const clearColor = this.getClearColor(); + + // premultiply alpha + + clearColor.r *= clearColor.a; + clearColor.g *= clearColor.a; + clearColor.b *= clearColor.a; + + descriptor = { + textures: null, + clearColorValue: clearColor + }; + + } + + // + + let clear = 0; + + if ( color ) clear |= gl.COLOR_BUFFER_BIT; + if ( depth ) clear |= gl.DEPTH_BUFFER_BIT; + if ( stencil ) clear |= gl.STENCIL_BUFFER_BIT; + + if ( clear !== 0 ) { + + let clearColor; + + if ( descriptor.clearColorValue ) { + + clearColor = descriptor.clearColorValue; + + } else { + + clearColor = this.getClearColor(); + + // premultiply alpha + + clearColor.r *= clearColor.a; + clearColor.g *= clearColor.a; + clearColor.b *= clearColor.a; + + } + + if ( depth ) this.state.setDepthMask( true ); + + if ( descriptor.textures === null ) { + + gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a ); + gl.clear( clear ); + + } else { + + if ( setFrameBuffer ) this._setFramebuffer( descriptor ); + + if ( color ) { + + for ( let i = 0; i < descriptor.textures.length; i ++ ) { + + gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] ); + + } + + } + + if ( depth && stencil ) { + + gl.clearBufferfi( gl.DEPTH_STENCIL, 0, 1, 0 ); + + } else if ( depth ) { + + gl.clearBufferfv( gl.DEPTH, 0, [ 1.0 ] ); + + } else if ( stencil ) { + + gl.clearBufferiv( gl.STENCIL, 0, [ 0 ] ); + + } + + } + + } + + } + + beginCompute( computeGroup ) { + + const { state, gl } = this; + + state.bindFramebuffer( gl.FRAMEBUFFER, null ); + this.initTimestampQuery( computeGroup ); + + } + + compute( computeGroup, computeNode, bindings, pipeline ) { + + const { state, gl } = this; + + if ( ! this.discard ) { + + // required here to handle async behaviour of render.compute() + gl.enable( gl.RASTERIZER_DISCARD ); + this.discard = true; + + } + + const { programGPU, transformBuffers, attributes } = this.get( pipeline ); + + const vaoKey = this._getVaoKey( null, attributes ); + + const vaoGPU = this.vaoCache[ vaoKey ]; + + if ( vaoGPU === undefined ) { + + this._createVao( null, attributes ); + + } else { + + gl.bindVertexArray( vaoGPU ); + + } + + state.useProgram( programGPU ); + + this._bindUniforms( bindings ); + + const transformFeedbackGPU = this._getTransformFeedback( transformBuffers ); + + gl.bindTransformFeedback( gl.TRANSFORM_FEEDBACK, transformFeedbackGPU ); + gl.beginTransformFeedback( gl.POINTS ); + + if ( attributes[ 0 ].isStorageInstancedBufferAttribute ) { + + gl.drawArraysInstanced( gl.POINTS, 0, 1, computeNode.count ); + + } else { + + gl.drawArrays( gl.POINTS, 0, computeNode.count ); + + } + + gl.endTransformFeedback(); + gl.bindTransformFeedback( gl.TRANSFORM_FEEDBACK, null ); + + // switch active buffers + + for ( let i = 0; i < transformBuffers.length; i ++ ) { + + const dualAttributeData = transformBuffers[ i ]; + + if ( dualAttributeData.pbo ) { + + this.textureUtils.copyBufferToTexture( dualAttributeData.transformBuffer, dualAttributeData.pbo ); + + } + + dualAttributeData.switchBuffers(); + + + } + + } + + finishCompute( computeGroup ) { + + const gl = this.gl; + + this.discard = false; + + gl.disable( gl.RASTERIZER_DISCARD ); + + this.prepareTimestampBuffer( computeGroup ); + + if ( this._currentContext ) { + + this._setFramebuffer( this._currentContext ); + + } + + } + + draw( renderObject/*, info*/ ) { + + const { object, pipeline, material, context, hardwareClippingPlanes } = renderObject; + const { programGPU } = this.get( pipeline ); + + const { gl, state } = this; + + const contextData = this.get( context ); + + const drawParams = renderObject.getDrawParameters(); + + if ( drawParams === null ) return; + + // + + this._bindUniforms( renderObject.getBindings() ); + + const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 ); + + state.setMaterial( material, frontFaceCW, hardwareClippingPlanes ); + + state.useProgram( programGPU ); + + // + + const renderObjectData = this.get( renderObject ); + + let vaoGPU = renderObjectData.staticVao; + + if ( vaoGPU === undefined || renderObjectData.geometryId !== renderObject.geometry.id ) { + + const vaoKey = this._getVaoKey( renderObject.getIndex(), renderObject.getAttributes() ); + + vaoGPU = this.vaoCache[ vaoKey ]; + + if ( vaoGPU === undefined ) { + + let staticVao; + + ( { vaoGPU, staticVao } = this._createVao( renderObject.getIndex(), renderObject.getAttributes() ) ); + + if ( staticVao ) { + + renderObjectData.staticVao = vaoGPU; + renderObjectData.geometryId = renderObject.geometry.id; + + } + + } + + } + + gl.bindVertexArray( vaoGPU ); + + // + + const index = renderObject.getIndex(); + + // + + const lastObject = contextData.lastOcclusionObject; + + if ( lastObject !== object && lastObject !== undefined ) { + + if ( lastObject !== null && lastObject.occlusionTest === true ) { + + gl.endQuery( gl.ANY_SAMPLES_PASSED ); + + contextData.occlusionQueryIndex ++; + + } + + if ( object.occlusionTest === true ) { + + const query = gl.createQuery(); + + gl.beginQuery( gl.ANY_SAMPLES_PASSED, query ); + + contextData.occlusionQueries[ contextData.occlusionQueryIndex ] = query; + contextData.occlusionQueryObjects[ contextData.occlusionQueryIndex ] = object; + + } + + contextData.lastOcclusionObject = object; + + } + + // + const renderer = this.bufferRenderer; + + if ( object.isPoints ) renderer.mode = gl.POINTS; + else if ( object.isLineSegments ) renderer.mode = gl.LINES; + else if ( object.isLine ) renderer.mode = gl.LINE_STRIP; + else if ( object.isLineLoop ) renderer.mode = gl.LINE_LOOP; + else { + + if ( material.wireframe === true ) { + + state.setLineWidth( material.wireframeLinewidth * this.renderer.getPixelRatio() ); + renderer.mode = gl.LINES; + + } else { + + renderer.mode = gl.TRIANGLES; + + } + + } + + // + + const { vertexCount, instanceCount } = drawParams; + let { firstVertex } = drawParams; + + renderer.object = object; + + if ( index !== null ) { + + firstVertex *= index.array.BYTES_PER_ELEMENT; + + const indexData = this.get( index ); + + renderer.index = index.count; + renderer.type = indexData.type; + + } else { + + renderer.index = 0; + + } + + if ( object.isBatchedMesh ) { + + if ( object._multiDrawInstances !== null ) { + + renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances ); + + } else if ( ! this.hasFeature( 'WEBGL_multi_draw' ) ) { + + warnOnce( 'THREE.WebGLRenderer: WEBGL_multi_draw not supported.' ); + + } else { + + renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount ); + + } + + } else if ( instanceCount > 1 ) { + + renderer.renderInstances( firstVertex, vertexCount, instanceCount ); + + } else { + + renderer.render( firstVertex, vertexCount ); + + } + // + + gl.bindVertexArray( null ); + + } + + needsRenderUpdate( /*renderObject*/ ) { + + return false; + + } + + getRenderCacheKey( /*renderObject*/ ) { + + return ''; + + } + + // textures + + createDefaultTexture( texture ) { + + this.textureUtils.createDefaultTexture( texture ); + + } + + createTexture( texture, options ) { + + this.textureUtils.createTexture( texture, options ); + + } + + updateTexture( texture, options ) { + + this.textureUtils.updateTexture( texture, options ); + + } + + generateMipmaps( texture ) { + + this.textureUtils.generateMipmaps( texture ); + + } + + + destroyTexture( texture ) { + + this.textureUtils.destroyTexture( texture ); + + } + + copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { + + return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex ); + + } + + createSampler( /*texture*/ ) { + + //console.warn( 'Abstract class.' ); + + } + + destroySampler() {} + + // node builder + + createNodeBuilder( object, renderer ) { + + return new GLSLNodeBuilder( object, renderer ); + + } + + // program + + createProgram( program ) { + + const gl = this.gl; + const { stage, code } = program; + + const shader = stage === 'fragment' ? gl.createShader( gl.FRAGMENT_SHADER ) : gl.createShader( gl.VERTEX_SHADER ); + + gl.shaderSource( shader, code ); + gl.compileShader( shader ); + + this.set( program, { + shaderGPU: shader + } ); + + } + + destroyProgram( /*program*/ ) { + + console.warn( 'Abstract class.' ); + + } + + createRenderPipeline( renderObject, promises ) { + + const gl = this.gl; + const pipeline = renderObject.pipeline; + + // Program + + const { fragmentProgram, vertexProgram } = pipeline; + + const programGPU = gl.createProgram(); + + const fragmentShader = this.get( fragmentProgram ).shaderGPU; + const vertexShader = this.get( vertexProgram ).shaderGPU; + + gl.attachShader( programGPU, fragmentShader ); + gl.attachShader( programGPU, vertexShader ); + gl.linkProgram( programGPU ); + + this.set( pipeline, { + programGPU, + fragmentShader, + vertexShader + } ); + + if ( promises !== null && this.parallel ) { + + const p = new Promise( ( resolve /*, reject*/ ) => { + + const parallel = this.parallel; + const checkStatus = () => { + + if ( gl.getProgramParameter( programGPU, parallel.COMPLETION_STATUS_KHR ) ) { + + this._completeCompile( renderObject, pipeline ); + resolve(); + + } else { + + requestAnimationFrame( checkStatus ); + + } + + }; + + checkStatus(); + + } ); + + promises.push( p ); + + return; + + } + + this._completeCompile( renderObject, pipeline ); + + } + + _handleSource( string, errorLine ) { + + const lines = string.split( '\n' ); + const lines2 = []; + + const from = Math.max( errorLine - 6, 0 ); + const to = Math.min( errorLine + 6, lines.length ); + + for ( let i = from; i < to; i ++ ) { + + const line = i + 1; + lines2.push( `${line === errorLine ? '>' : ' '} ${line}: ${lines[ i ]}` ); + + } + + return lines2.join( '\n' ); + + } + + _getShaderErrors( gl, shader, type ) { + + const status = gl.getShaderParameter( shader, gl.COMPILE_STATUS ); + const errors = gl.getShaderInfoLog( shader ).trim(); + + if ( status && errors === '' ) return ''; + + const errorMatches = /ERROR: 0:(\d+)/.exec( errors ); + if ( errorMatches ) { + + const errorLine = parseInt( errorMatches[ 1 ] ); + return type.toUpperCase() + '\n\n' + errors + '\n\n' + this._handleSource( gl.getShaderSource( shader ), errorLine ); + + } else { + + return errors; + + } + + } + + _logProgramError( programGPU, glFragmentShader, glVertexShader ) { + + if ( this.renderer.debug.checkShaderErrors ) { + + const gl = this.gl; + + const programLog = gl.getProgramInfoLog( programGPU ).trim(); + + if ( gl.getProgramParameter( programGPU, gl.LINK_STATUS ) === false ) { + + + if ( typeof this.renderer.debug.onShaderError === 'function' ) { + + this.renderer.debug.onShaderError( gl, programGPU, glVertexShader, glFragmentShader ); + + } else { + + // default error reporting + + const vertexErrors = this._getShaderErrors( gl, glVertexShader, 'vertex' ); + const fragmentErrors = this._getShaderErrors( gl, glFragmentShader, 'fragment' ); + + console.error( + 'THREE.WebGLProgram: Shader Error ' + gl.getError() + ' - ' + + 'VALIDATE_STATUS ' + gl.getProgramParameter( programGPU, gl.VALIDATE_STATUS ) + '\n\n' + + 'Program Info Log: ' + programLog + '\n' + + vertexErrors + '\n' + + fragmentErrors + ); + + } + + } else if ( programLog !== '' ) { + + console.warn( 'THREE.WebGLProgram: Program Info Log:', programLog ); + + } + + } + + } + + _completeCompile( renderObject, pipeline ) { + + const { state, gl } = this; + const pipelineData = this.get( pipeline ); + const { programGPU, fragmentShader, vertexShader } = pipelineData; + + if ( gl.getProgramParameter( programGPU, gl.LINK_STATUS ) === false ) { + + this._logProgramError( programGPU, fragmentShader, vertexShader ); + + } + + state.useProgram( programGPU ); + + // Bindings + + const bindings = renderObject.getBindings(); + + this._setupBindings( bindings, programGPU ); + + // + + this.set( pipeline, { + programGPU + } ); + + } + + createComputePipeline( computePipeline, bindings ) { + + const { state, gl } = this; + + // Program + + const fragmentProgram = { + stage: 'fragment', + code: '#version 300 es\nprecision highp float;\nvoid main() {}' + }; + + this.createProgram( fragmentProgram ); + + const { computeProgram } = computePipeline; + + const programGPU = gl.createProgram(); + + const fragmentShader = this.get( fragmentProgram ).shaderGPU; + const vertexShader = this.get( computeProgram ).shaderGPU; + + const transforms = computeProgram.transforms; + + const transformVaryingNames = []; + const transformAttributeNodes = []; + + for ( let i = 0; i < transforms.length; i ++ ) { + + const transform = transforms[ i ]; + + transformVaryingNames.push( transform.varyingName ); + transformAttributeNodes.push( transform.attributeNode ); + + } + + gl.attachShader( programGPU, fragmentShader ); + gl.attachShader( programGPU, vertexShader ); + + gl.transformFeedbackVaryings( + programGPU, + transformVaryingNames, + gl.SEPARATE_ATTRIBS + ); + + gl.linkProgram( programGPU ); + + if ( gl.getProgramParameter( programGPU, gl.LINK_STATUS ) === false ) { + + this._logProgramError( programGPU, fragmentShader, vertexShader ); + + + } + + state.useProgram( programGPU ); + + // Bindings + + this._setupBindings( bindings, programGPU ); + + const attributeNodes = computeProgram.attributes; + const attributes = []; + const transformBuffers = []; + + for ( let i = 0; i < attributeNodes.length; i ++ ) { + + const attribute = attributeNodes[ i ].node.attribute; + + attributes.push( attribute ); + + if ( ! this.has( attribute ) ) this.attributeUtils.createAttribute( attribute, gl.ARRAY_BUFFER ); + + } + + for ( let i = 0; i < transformAttributeNodes.length; i ++ ) { + + const attribute = transformAttributeNodes[ i ].attribute; + + if ( ! this.has( attribute ) ) this.attributeUtils.createAttribute( attribute, gl.ARRAY_BUFFER ); + + const attributeData = this.get( attribute ); + + transformBuffers.push( attributeData ); + + } + + // + + this.set( computePipeline, { + programGPU, + transformBuffers, + attributes + } ); + + } + + createBindings( bindGroup, bindings ) { + + if ( this._knownBindings.has( bindings ) === false ) { + + this._knownBindings.add( bindings ); + + let uniformBuffers = 0; + let textures = 0; + + for ( const bindGroup of bindings ) { + + this.set( bindGroup, { + textures: textures, + uniformBuffers: uniformBuffers + } ); + + for ( const binding of bindGroup.bindings ) { + + if ( binding.isUniformBuffer ) uniformBuffers ++; + if ( binding.isSampledTexture ) textures ++; + + } + + } + + } + + this.updateBindings( bindGroup, bindings ); + + } + + updateBindings( bindGroup /*, bindings*/ ) { + + const { gl } = this; + + const bindGroupData = this.get( bindGroup ); + + let i = bindGroupData.uniformBuffers; + let t = bindGroupData.textures; + + for ( const binding of bindGroup.bindings ) { + + if ( binding.isUniformsGroup || binding.isUniformBuffer ) { + + const data = binding.buffer; + const bufferGPU = gl.createBuffer(); + + gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU ); + gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW ); + + this.set( binding, { + index: i ++, + bufferGPU + } ); + + } else if ( binding.isSampledTexture ) { + + const { textureGPU, glTextureType } = this.get( binding.texture ); + + this.set( binding, { + index: t ++, + textureGPU, + glTextureType + } ); + + } + + } + + } + + updateBinding( binding ) { + + const gl = this.gl; + + if ( binding.isUniformsGroup || binding.isUniformBuffer ) { + + const bindingData = this.get( binding ); + const bufferGPU = bindingData.bufferGPU; + const data = binding.buffer; + + gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU ); + gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW ); + + } + + } + + // attributes + + createIndexAttribute( attribute ) { + + const gl = this.gl; + + this.attributeUtils.createAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER ); + + } + + createAttribute( attribute ) { + + if ( this.has( attribute ) ) return; + + const gl = this.gl; + + this.attributeUtils.createAttribute( attribute, gl.ARRAY_BUFFER ); + + } + + createStorageAttribute( attribute ) { + + if ( this.has( attribute ) ) return; + + const gl = this.gl; + + this.attributeUtils.createAttribute( attribute, gl.ARRAY_BUFFER ); + + } + + updateAttribute( attribute ) { + + this.attributeUtils.updateAttribute( attribute ); + + } + + destroyAttribute( attribute ) { + + this.attributeUtils.destroyAttribute( attribute ); + + } + + updateSize() { + + //console.warn( 'Abstract class.' ); + + } + + hasFeature( name ) { + + const keysMatching = Object.keys( GLFeatureName ).filter( key => GLFeatureName[ key ] === name ); + + const extensions = this.extensions; + + for ( let i = 0; i < keysMatching.length; i ++ ) { + + if ( extensions.has( keysMatching[ i ] ) ) return true; + + } + + return false; + + } + + getMaxAnisotropy() { + + return this.capabilities.getMaxAnisotropy(); + + } + + copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level ) { + + this.textureUtils.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level ); + + } + + copyFramebufferToTexture( texture, renderContext, rectangle ) { + + this.textureUtils.copyFramebufferToTexture( texture, renderContext, rectangle ); + + } + + _setFramebuffer( descriptor ) { + + const { gl, state } = this; + + let currentFrameBuffer = null; + + if ( descriptor.textures !== null ) { + + const renderTarget = descriptor.renderTarget; + const renderTargetContextData = this.get( renderTarget ); + const { samples, depthBuffer, stencilBuffer } = renderTarget; + + const isCube = renderTarget.isWebGLCubeRenderTarget === true; + + let msaaFb = renderTargetContextData.msaaFrameBuffer; + let depthRenderbuffer = renderTargetContextData.depthRenderbuffer; + + const cacheKey = getCacheKey( descriptor ); + + let fb; + + if ( isCube ) { + + renderTargetContextData.cubeFramebuffers || ( renderTargetContextData.cubeFramebuffers = {} ); + + fb = renderTargetContextData.cubeFramebuffers[ cacheKey ]; + + } else { + + renderTargetContextData.framebuffers || ( renderTargetContextData.framebuffers = {} ); + + fb = renderTargetContextData.framebuffers[ cacheKey ]; + + } + + if ( fb === undefined ) { + + fb = gl.createFramebuffer(); + + state.bindFramebuffer( gl.FRAMEBUFFER, fb ); + + const textures = descriptor.textures; + + if ( isCube ) { + + renderTargetContextData.cubeFramebuffers[ cacheKey ] = fb; + + const { textureGPU } = this.get( textures[ 0 ] ); + + const cubeFace = this.renderer._activeCubeFace; + + gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + cubeFace, textureGPU, 0 ); + + } else { + + renderTargetContextData.framebuffers[ cacheKey ] = fb; + + for ( let i = 0; i < textures.length; i ++ ) { + + const texture = textures[ i ]; + const textureData = this.get( texture ); + textureData.renderTarget = descriptor.renderTarget; + textureData.cacheKey = cacheKey; // required for copyTextureToTexture() + + const attachment = gl.COLOR_ATTACHMENT0 + i; + + gl.framebufferTexture2D( gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureData.textureGPU, 0 ); + + } + + state.drawBuffers( descriptor, fb ); + + } + + if ( descriptor.depthTexture !== null ) { + + const textureData = this.get( descriptor.depthTexture ); + const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT; + textureData.renderTarget = descriptor.renderTarget; + textureData.cacheKey = cacheKey; // required for copyTextureToTexture() + + gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 ); + + } + + } + + if ( samples > 0 ) { + + if ( msaaFb === undefined ) { + + const invalidationArray = []; + + msaaFb = gl.createFramebuffer(); + + state.bindFramebuffer( gl.FRAMEBUFFER, msaaFb ); + + const msaaRenderbuffers = []; + + const textures = descriptor.textures; + + for ( let i = 0; i < textures.length; i ++ ) { + + msaaRenderbuffers[ i ] = gl.createRenderbuffer(); + + gl.bindRenderbuffer( gl.RENDERBUFFER, msaaRenderbuffers[ i ] ); + + invalidationArray.push( gl.COLOR_ATTACHMENT0 + i ); + + if ( depthBuffer ) { + + const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT; + invalidationArray.push( depthStyle ); + + } + + const texture = descriptor.textures[ i ]; + const textureData = this.get( texture ); + + gl.renderbufferStorageMultisample( gl.RENDERBUFFER, samples, textureData.glInternalFormat, descriptor.width, descriptor.height ); + gl.framebufferRenderbuffer( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, msaaRenderbuffers[ i ] ); + + + } + + renderTargetContextData.msaaFrameBuffer = msaaFb; + renderTargetContextData.msaaRenderbuffers = msaaRenderbuffers; + + if ( depthRenderbuffer === undefined ) { + + depthRenderbuffer = gl.createRenderbuffer(); + this.textureUtils.setupRenderBufferStorage( depthRenderbuffer, descriptor ); + + renderTargetContextData.depthRenderbuffer = depthRenderbuffer; + + const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT; + invalidationArray.push( depthStyle ); + + } + + renderTargetContextData.invalidationArray = invalidationArray; + + } + + currentFrameBuffer = renderTargetContextData.msaaFrameBuffer; + + } else { + + currentFrameBuffer = fb; + + } + + } + + state.bindFramebuffer( gl.FRAMEBUFFER, currentFrameBuffer ); + + } + + + _getVaoKey( index, attributes ) { + + let key = []; + + if ( index !== null ) { + + const indexData = this.get( index ); + + key += ':' + indexData.id; + + } + + for ( let i = 0; i < attributes.length; i ++ ) { + + const attributeData = this.get( attributes[ i ] ); + + key += ':' + attributeData.id; + + } + + return key; + + } + + _createVao( index, attributes ) { + + const { gl } = this; + + const vaoGPU = gl.createVertexArray(); + let key = ''; + + let staticVao = true; + + gl.bindVertexArray( vaoGPU ); + + if ( index !== null ) { + + const indexData = this.get( index ); + + gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, indexData.bufferGPU ); + + key += ':' + indexData.id; + + } + + for ( let i = 0; i < attributes.length; i ++ ) { + + const attribute = attributes[ i ]; + const attributeData = this.get( attribute ); + + key += ':' + attributeData.id; + + gl.bindBuffer( gl.ARRAY_BUFFER, attributeData.bufferGPU ); + gl.enableVertexAttribArray( i ); + + if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) staticVao = false; + + let stride, offset; + + if ( attribute.isInterleavedBufferAttribute === true ) { + + stride = attribute.data.stride * attributeData.bytesPerElement; + offset = attribute.offset * attributeData.bytesPerElement; + + } else { + + stride = 0; + offset = 0; + + } + + if ( attributeData.isInteger ) { + + gl.vertexAttribIPointer( i, attribute.itemSize, attributeData.type, stride, offset ); + + } else { + + gl.vertexAttribPointer( i, attribute.itemSize, attributeData.type, attribute.normalized, stride, offset ); + + } + + if ( attribute.isInstancedBufferAttribute && ! attribute.isInterleavedBufferAttribute ) { + + gl.vertexAttribDivisor( i, attribute.meshPerAttribute ); + + } else if ( attribute.isInterleavedBufferAttribute && attribute.data.isInstancedInterleavedBuffer ) { + + gl.vertexAttribDivisor( i, attribute.data.meshPerAttribute ); + + } + + } + + gl.bindBuffer( gl.ARRAY_BUFFER, null ); + + this.vaoCache[ key ] = vaoGPU; + + return { vaoGPU, staticVao }; + + } + + _getTransformFeedback( transformBuffers ) { + + let key = ''; + + for ( let i = 0; i < transformBuffers.length; i ++ ) { + + key += ':' + transformBuffers[ i ].id; + + } + + let transformFeedbackGPU = this.transformFeedbackCache[ key ]; + + if ( transformFeedbackGPU !== undefined ) { + + return transformFeedbackGPU; + + } + + const { gl } = this; + + transformFeedbackGPU = gl.createTransformFeedback(); + + gl.bindTransformFeedback( gl.TRANSFORM_FEEDBACK, transformFeedbackGPU ); + + for ( let i = 0; i < transformBuffers.length; i ++ ) { + + const attributeData = transformBuffers[ i ]; + + gl.bindBufferBase( gl.TRANSFORM_FEEDBACK_BUFFER, i, attributeData.transformBuffer ); + + } + + gl.bindTransformFeedback( gl.TRANSFORM_FEEDBACK, null ); + + this.transformFeedbackCache[ key ] = transformFeedbackGPU; + + return transformFeedbackGPU; + + } + + + _setupBindings( bindings, programGPU ) { + + const gl = this.gl; + + for ( const bindGroup of bindings ) { + + for ( const binding of bindGroup.bindings ) { + + const bindingData = this.get( binding ); + const index = bindingData.index; + + if ( binding.isUniformsGroup || binding.isUniformBuffer ) { + + const location = gl.getUniformBlockIndex( programGPU, binding.name ); + gl.uniformBlockBinding( programGPU, location, index ); + + } else if ( binding.isSampledTexture ) { + + const location = gl.getUniformLocation( programGPU, binding.name ); + gl.uniform1i( location, index ); + + } + + } + + } + + } + + _bindUniforms( bindings ) { + + const { gl, state } = this; + + for ( const bindGroup of bindings ) { + + for ( const binding of bindGroup.bindings ) { + + const bindingData = this.get( binding ); + const index = bindingData.index; + + if ( binding.isUniformsGroup || binding.isUniformBuffer ) { + + // TODO USE bindBufferRange to group multiple uniform buffers + state.bindBufferBase( gl.UNIFORM_BUFFER, index, bindingData.bufferGPU ); + + } else if ( binding.isSampledTexture ) { + + state.bindTexture( bindingData.glTextureType, bindingData.textureGPU, gl.TEXTURE0 + index ); + + } + + } + + } + + } + + dispose() { + + this.renderer.domElement.removeEventListener( 'webglcontextlost', this._onContextLost ); + + } + +} + +const GPUPrimitiveTopology = { + PointList: 'point-list', + LineList: 'line-list', + LineStrip: 'line-strip', + TriangleList: 'triangle-list', + TriangleStrip: 'triangle-strip', +}; + +const GPUCompareFunction = { + Never: 'never', + Less: 'less', + Equal: 'equal', + LessEqual: 'less-equal', + Greater: 'greater', + NotEqual: 'not-equal', + GreaterEqual: 'greater-equal', + Always: 'always' +}; + +const GPUStoreOp = { + Store: 'store', + Discard: 'discard' +}; + +const GPULoadOp = { + Load: 'load', + Clear: 'clear' +}; + +const GPUFrontFace = { + CCW: 'ccw', + CW: 'cw' +}; + +const GPUCullMode = { + None: 'none', + Front: 'front', + Back: 'back' +}; + +const GPUIndexFormat = { + Uint16: 'uint16', + Uint32: 'uint32' +}; + +const GPUTextureFormat = { + + // 8-bit formats + + R8Unorm: 'r8unorm', + R8Snorm: 'r8snorm', + R8Uint: 'r8uint', + R8Sint: 'r8sint', + + // 16-bit formats + + R16Uint: 'r16uint', + R16Sint: 'r16sint', + R16Float: 'r16float', + RG8Unorm: 'rg8unorm', + RG8Snorm: 'rg8snorm', + RG8Uint: 'rg8uint', + RG8Sint: 'rg8sint', + + // 32-bit formats + + R32Uint: 'r32uint', + R32Sint: 'r32sint', + R32Float: 'r32float', + RG16Uint: 'rg16uint', + RG16Sint: 'rg16sint', + RG16Float: 'rg16float', + RGBA8Unorm: 'rgba8unorm', + RGBA8UnormSRGB: 'rgba8unorm-srgb', + RGBA8Snorm: 'rgba8snorm', + RGBA8Uint: 'rgba8uint', + RGBA8Sint: 'rgba8sint', + BGRA8Unorm: 'bgra8unorm', + BGRA8UnormSRGB: 'bgra8unorm-srgb', + // Packed 32-bit formats + RGB9E5UFloat: 'rgb9e5ufloat', + RGB10A2Unorm: 'rgb10a2unorm', + RG11B10uFloat: 'rgb10a2unorm', + + // 64-bit formats + + RG32Uint: 'rg32uint', + RG32Sint: 'rg32sint', + RG32Float: 'rg32float', + RGBA16Uint: 'rgba16uint', + RGBA16Sint: 'rgba16sint', + RGBA16Float: 'rgba16float', + + // 128-bit formats + + RGBA32Uint: 'rgba32uint', + RGBA32Sint: 'rgba32sint', + RGBA32Float: 'rgba32float', + + // Depth and stencil formats + + Stencil8: 'stencil8', + Depth16Unorm: 'depth16unorm', + Depth24Plus: 'depth24plus', + Depth24PlusStencil8: 'depth24plus-stencil8', + Depth32Float: 'depth32float', + + // 'depth32float-stencil8' extension + + Depth32FloatStencil8: 'depth32float-stencil8', + + // BC compressed formats usable if 'texture-compression-bc' is both + // supported by the device/user agent and enabled in requestDevice. + + BC1RGBAUnorm: 'bc1-rgba-unorm', + BC1RGBAUnormSRGB: 'bc1-rgba-unorm-srgb', + BC2RGBAUnorm: 'bc2-rgba-unorm', + BC2RGBAUnormSRGB: 'bc2-rgba-unorm-srgb', + BC3RGBAUnorm: 'bc3-rgba-unorm', + BC3RGBAUnormSRGB: 'bc3-rgba-unorm-srgb', + BC4RUnorm: 'bc4-r-unorm', + BC4RSnorm: 'bc4-r-snorm', + BC5RGUnorm: 'bc5-rg-unorm', + BC5RGSnorm: 'bc5-rg-snorm', + BC6HRGBUFloat: 'bc6h-rgb-ufloat', + BC6HRGBFloat: 'bc6h-rgb-float', + BC7RGBAUnorm: 'bc7-rgba-unorm', + BC7RGBAUnormSRGB: 'bc7-rgba-srgb', + + // ETC2 compressed formats usable if 'texture-compression-etc2' is both + // supported by the device/user agent and enabled in requestDevice. + + ETC2RGB8Unorm: 'etc2-rgb8unorm', + ETC2RGB8UnormSRGB: 'etc2-rgb8unorm-srgb', + ETC2RGB8A1Unorm: 'etc2-rgb8a1unorm', + ETC2RGB8A1UnormSRGB: 'etc2-rgb8a1unorm-srgb', + ETC2RGBA8Unorm: 'etc2-rgba8unorm', + ETC2RGBA8UnormSRGB: 'etc2-rgba8unorm-srgb', + EACR11Unorm: 'eac-r11unorm', + EACR11Snorm: 'eac-r11snorm', + EACRG11Unorm: 'eac-rg11unorm', + EACRG11Snorm: 'eac-rg11snorm', + + // ASTC compressed formats usable if 'texture-compression-astc' is both + // supported by the device/user agent and enabled in requestDevice. + + ASTC4x4Unorm: 'astc-4x4-unorm', + ASTC4x4UnormSRGB: 'astc-4x4-unorm-srgb', + ASTC5x4Unorm: 'astc-5x4-unorm', + ASTC5x4UnormSRGB: 'astc-5x4-unorm-srgb', + ASTC5x5Unorm: 'astc-5x5-unorm', + ASTC5x5UnormSRGB: 'astc-5x5-unorm-srgb', + ASTC6x5Unorm: 'astc-6x5-unorm', + ASTC6x5UnormSRGB: 'astc-6x5-unorm-srgb', + ASTC6x6Unorm: 'astc-6x6-unorm', + ASTC6x6UnormSRGB: 'astc-6x6-unorm-srgb', + ASTC8x5Unorm: 'astc-8x5-unorm', + ASTC8x5UnormSRGB: 'astc-8x5-unorm-srgb', + ASTC8x6Unorm: 'astc-8x6-unorm', + ASTC8x6UnormSRGB: 'astc-8x6-unorm-srgb', + ASTC8x8Unorm: 'astc-8x8-unorm', + ASTC8x8UnormSRGB: 'astc-8x8-unorm-srgb', + ASTC10x5Unorm: 'astc-10x5-unorm', + ASTC10x5UnormSRGB: 'astc-10x5-unorm-srgb', + ASTC10x6Unorm: 'astc-10x6-unorm', + ASTC10x6UnormSRGB: 'astc-10x6-unorm-srgb', + ASTC10x8Unorm: 'astc-10x8-unorm', + ASTC10x8UnormSRGB: 'astc-10x8-unorm-srgb', + ASTC10x10Unorm: 'astc-10x10-unorm', + ASTC10x10UnormSRGB: 'astc-10x10-unorm-srgb', + ASTC12x10Unorm: 'astc-12x10-unorm', + ASTC12x10UnormSRGB: 'astc-12x10-unorm-srgb', + ASTC12x12Unorm: 'astc-12x12-unorm', + ASTC12x12UnormSRGB: 'astc-12x12-unorm-srgb', + +}; + +const GPUAddressMode = { + ClampToEdge: 'clamp-to-edge', + Repeat: 'repeat', + MirrorRepeat: 'mirror-repeat' +}; + +const GPUFilterMode = { + Linear: 'linear', + Nearest: 'nearest' +}; + +const GPUBlendFactor = { + Zero: 'zero', + One: 'one', + Src: 'src', + OneMinusSrc: 'one-minus-src', + SrcAlpha: 'src-alpha', + OneMinusSrcAlpha: 'one-minus-src-alpha', + Dst: 'dst', + OneMinusDstColor: 'one-minus-dst', + DstAlpha: 'dst-alpha', + OneMinusDstAlpha: 'one-minus-dst-alpha', + SrcAlphaSaturated: 'src-alpha-saturated', + Constant: 'constant', + OneMinusConstant: 'one-minus-constant' +}; + +const GPUBlendOperation = { + Add: 'add', + Subtract: 'subtract', + ReverseSubtract: 'reverse-subtract', + Min: 'min', + Max: 'max' +}; + +const GPUColorWriteFlags = { + None: 0, + Red: 0x1, + Green: 0x2, + Blue: 0x4, + Alpha: 0x8, + All: 0xF +}; + +const GPUStencilOperation = { + Keep: 'keep', + Zero: 'zero', + Replace: 'replace', + Invert: 'invert', + IncrementClamp: 'increment-clamp', + DecrementClamp: 'decrement-clamp', + IncrementWrap: 'increment-wrap', + DecrementWrap: 'decrement-wrap' +}; + +const GPUBufferBindingType = { + Uniform: 'uniform', + Storage: 'storage', + ReadOnlyStorage: 'read-only-storage' +}; + +const GPUStorageTextureAccess = { + WriteOnly: 'write-only', + ReadOnly: 'read-only', + ReadWrite: 'read-write', +}; + +const GPUTextureSampleType = { + Float: 'float', + UnfilterableFloat: 'unfilterable-float', + Depth: 'depth', + SInt: 'sint', + UInt: 'uint' +}; + +const GPUTextureDimension = { + OneD: '1d', + TwoD: '2d', + ThreeD: '3d' +}; + +const GPUTextureViewDimension = { + OneD: '1d', + TwoD: '2d', + TwoDArray: '2d-array', + Cube: 'cube', + CubeArray: 'cube-array', + ThreeD: '3d' +}; + +const GPUTextureAspect = { + All: 'all', + StencilOnly: 'stencil-only', + DepthOnly: 'depth-only' +}; + +const GPUInputStepMode = { + Vertex: 'vertex', + Instance: 'instance' +}; + +const GPUFeatureName = { + DepthClipControl: 'depth-clip-control', + Depth32FloatStencil8: 'depth32float-stencil8', + TextureCompressionBC: 'texture-compression-bc', + TextureCompressionETC2: 'texture-compression-etc2', + TextureCompressionASTC: 'texture-compression-astc', + TimestampQuery: 'timestamp-query', + IndirectFirstInstance: 'indirect-first-instance', + ShaderF16: 'shader-f16', + RG11B10UFloat: 'rg11b10ufloat-renderable', + BGRA8UNormStorage: 'bgra8unorm-storage', + Float32Filterable: 'float32-filterable', + ClipDistances: 'clip-distances', + DualSourceBlending: 'dual-source-blending', + Subgroups: 'subgroups' +}; + +class Sampler extends Binding { + + constructor( name, texture ) { + + super( name ); + + this.texture = texture; + this.version = texture ? texture.version : 0; + + this.isSampler = true; + + } + +} + +class NodeSampler extends Sampler { + + constructor( name, textureNode, groupNode ) { + + super( name, textureNode ? textureNode.value : null ); + + this.textureNode = textureNode; + this.groupNode = groupNode; + + } + + update() { + + this.texture = this.textureNode.value; + + } + +} + +class StorageBuffer extends Buffer { + + constructor( name, attribute ) { + + super( name, attribute ? attribute.array : null ); + + this.attribute = attribute; + + this.isStorageBuffer = true; + + } + +} + +let _id = 0; + +class NodeStorageBuffer extends StorageBuffer { + + constructor( nodeUniform, groupNode ) { + + super( 'StorageBuffer_' + _id ++, nodeUniform ? nodeUniform.value : null ); + + this.nodeUniform = nodeUniform; + this.access = nodeUniform ? nodeUniform.access : NodeAccess.READ_WRITE; + this.groupNode = groupNode; + + } + + get buffer() { + + return this.nodeUniform.value; + + } + +} + +class WebGPUTexturePassUtils extends DataMap { + + constructor( device ) { + + super(); + + this.device = device; + + const mipmapVertexSource = ` +struct VarysStruct { + @builtin( position ) Position: vec4, + @location( 0 ) vTex : vec2 +}; + +@vertex +fn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct { + + var Varys : VarysStruct; + + var pos = array< vec2, 4 >( + vec2( -1.0, 1.0 ), + vec2( 1.0, 1.0 ), + vec2( -1.0, -1.0 ), + vec2( 1.0, -1.0 ) + ); + + var tex = array< vec2, 4 >( + vec2( 0.0, 0.0 ), + vec2( 1.0, 0.0 ), + vec2( 0.0, 1.0 ), + vec2( 1.0, 1.0 ) + ); + + Varys.vTex = tex[ vertexIndex ]; + Varys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 ); + + return Varys; + +} +`; + + const mipmapFragmentSource = ` +@group( 0 ) @binding( 0 ) +var imgSampler : sampler; + +@group( 0 ) @binding( 1 ) +var img : texture_2d; + +@fragment +fn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 { + + return textureSample( img, imgSampler, vTex ); + +} +`; + + const flipYFragmentSource = ` +@group( 0 ) @binding( 0 ) +var imgSampler : sampler; + +@group( 0 ) @binding( 1 ) +var img : texture_2d; + +@fragment +fn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 { + + return textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) ); + +} +`; + this.mipmapSampler = device.createSampler( { minFilter: GPUFilterMode.Linear } ); + this.flipYSampler = device.createSampler( { minFilter: GPUFilterMode.Nearest } ); //@TODO?: Consider using textureLoad() + + // We'll need a new pipeline for every texture format used. + this.transferPipelines = {}; + this.flipYPipelines = {}; + + this.mipmapVertexShaderModule = device.createShaderModule( { + label: 'mipmapVertex', + code: mipmapVertexSource + } ); + + this.mipmapFragmentShaderModule = device.createShaderModule( { + label: 'mipmapFragment', + code: mipmapFragmentSource + } ); + + this.flipYFragmentShaderModule = device.createShaderModule( { + label: 'flipYFragment', + code: flipYFragmentSource + } ); + + } + + getTransferPipeline( format ) { + + let pipeline = this.transferPipelines[ format ]; + + if ( pipeline === undefined ) { + + pipeline = this.device.createRenderPipeline( { + label: `mipmap-${ format }`, + vertex: { + module: this.mipmapVertexShaderModule, + entryPoint: 'main' + }, + fragment: { + module: this.mipmapFragmentShaderModule, + entryPoint: 'main', + targets: [ { format } ] + }, + primitive: { + topology: GPUPrimitiveTopology.TriangleStrip, + stripIndexFormat: GPUIndexFormat.Uint32 + }, + layout: 'auto' + } ); + + this.transferPipelines[ format ] = pipeline; + + } + + return pipeline; + + } + + getFlipYPipeline( format ) { + + let pipeline = this.flipYPipelines[ format ]; + + if ( pipeline === undefined ) { + + pipeline = this.device.createRenderPipeline( { + label: `flipY-${ format }`, + vertex: { + module: this.mipmapVertexShaderModule, + entryPoint: 'main' + }, + fragment: { + module: this.flipYFragmentShaderModule, + entryPoint: 'main', + targets: [ { format } ] + }, + primitive: { + topology: GPUPrimitiveTopology.TriangleStrip, + stripIndexFormat: GPUIndexFormat.Uint32 + }, + layout: 'auto' + } ); + + this.flipYPipelines[ format ] = pipeline; + + } + + return pipeline; + + } + + flipY( textureGPU, textureGPUDescriptor, baseArrayLayer = 0 ) { + + const format = textureGPUDescriptor.format; + const { width, height } = textureGPUDescriptor.size; + + const transferPipeline = this.getTransferPipeline( format ); + const flipYPipeline = this.getFlipYPipeline( format ); + + const tempTexture = this.device.createTexture( { + size: { width, height, depthOrArrayLayers: 1 }, + format, + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING + } ); + + const srcView = textureGPU.createView( { + baseMipLevel: 0, + mipLevelCount: 1, + dimension: GPUTextureViewDimension.TwoD, + baseArrayLayer + } ); + + const dstView = tempTexture.createView( { + baseMipLevel: 0, + mipLevelCount: 1, + dimension: GPUTextureViewDimension.TwoD, + baseArrayLayer: 0 + } ); + + const commandEncoder = this.device.createCommandEncoder( {} ); + + const pass = ( pipeline, sourceView, destinationView ) => { + + const bindGroupLayout = pipeline.getBindGroupLayout( 0 ); // @TODO: Consider making this static. + + const bindGroup = this.device.createBindGroup( { + layout: bindGroupLayout, + entries: [ { + binding: 0, + resource: this.flipYSampler + }, { + binding: 1, + resource: sourceView + } ] + } ); + + const passEncoder = commandEncoder.beginRenderPass( { + colorAttachments: [ { + view: destinationView, + loadOp: GPULoadOp.Clear, + storeOp: GPUStoreOp.Store, + clearValue: [ 0, 0, 0, 0 ] + } ] + } ); + + passEncoder.setPipeline( pipeline ); + passEncoder.setBindGroup( 0, bindGroup ); + passEncoder.draw( 4, 1, 0, 0 ); + passEncoder.end(); + + }; + + pass( transferPipeline, srcView, dstView ); + pass( flipYPipeline, dstView, srcView ); + + this.device.queue.submit( [ commandEncoder.finish() ] ); + + tempTexture.destroy(); + + } + + generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer = 0 ) { + + const textureData = this.get( textureGPU ); + + if ( textureData.useCount === undefined ) { + + textureData.useCount = 0; + textureData.layers = []; + + } + + const passes = textureData.layers[ baseArrayLayer ] || this._mipmapCreateBundles( textureGPU, textureGPUDescriptor, baseArrayLayer ); + + const commandEncoder = this.device.createCommandEncoder( {} ); + + this._mipmapRunBundles( commandEncoder, passes ); + + this.device.queue.submit( [ commandEncoder.finish() ] ); + + if ( textureData.useCount !== 0 ) textureData.layers[ baseArrayLayer ] = passes; + + textureData.useCount ++; + + } + + _mipmapCreateBundles( textureGPU, textureGPUDescriptor, baseArrayLayer ) { + + const pipeline = this.getTransferPipeline( textureGPUDescriptor.format ); + + const bindGroupLayout = pipeline.getBindGroupLayout( 0 ); // @TODO: Consider making this static. + + let srcView = textureGPU.createView( { + baseMipLevel: 0, + mipLevelCount: 1, + dimension: GPUTextureViewDimension.TwoD, + baseArrayLayer + } ); + + const passes = []; + + for ( let i = 1; i < textureGPUDescriptor.mipLevelCount; i ++ ) { + + const bindGroup = this.device.createBindGroup( { + layout: bindGroupLayout, + entries: [ { + binding: 0, + resource: this.mipmapSampler + }, { + binding: 1, + resource: srcView + } ] + } ); + + const dstView = textureGPU.createView( { + baseMipLevel: i, + mipLevelCount: 1, + dimension: GPUTextureViewDimension.TwoD, + baseArrayLayer + } ); + + const passDescriptor = { + colorAttachments: [ { + view: dstView, + loadOp: GPULoadOp.Clear, + storeOp: GPUStoreOp.Store, + clearValue: [ 0, 0, 0, 0 ] + } ] + }; + + const passEncoder = this.device.createRenderBundleEncoder( { + colorFormats: [ textureGPUDescriptor.format ] + } ); + + passEncoder.setPipeline( pipeline ); + passEncoder.setBindGroup( 0, bindGroup ); + passEncoder.draw( 4, 1, 0, 0 ); + + passes.push( { + renderBundles: [ passEncoder.finish() ], + passDescriptor + } ); + + srcView = dstView; + + } + + return passes; + + } + + _mipmapRunBundles( commandEncoder, passes ) { + + const levels = passes.length; + + for ( let i = 0; i < levels; i ++ ) { + + const pass = passes[ i ]; + + const passEncoder = commandEncoder.beginRenderPass( pass.passDescriptor ); + + passEncoder.executeBundles( pass.renderBundles ); + + passEncoder.end(); + + } + + } + +} + +const _compareToWebGPU = { + [ NeverCompare ]: 'never', + [ LessCompare ]: 'less', + [ EqualCompare ]: 'equal', + [ LessEqualCompare ]: 'less-equal', + [ GreaterCompare ]: 'greater', + [ GreaterEqualCompare ]: 'greater-equal', + [ AlwaysCompare ]: 'always', + [ NotEqualCompare ]: 'not-equal' +}; + +const _flipMap = [ 0, 1, 3, 2, 4, 5 ]; + +class WebGPUTextureUtils { + + constructor( backend ) { + + this.backend = backend; + + this._passUtils = null; + + this.defaultTexture = {}; + this.defaultCubeTexture = {}; + this.defaultVideoFrame = null; + + this.colorBuffer = null; + + this.depthTexture = new DepthTexture(); + this.depthTexture.name = 'depthBuffer'; + + } + + createSampler( texture ) { + + const backend = this.backend; + const device = backend.device; + + const textureGPU = backend.get( texture ); + + const samplerDescriptorGPU = { + addressModeU: this._convertAddressMode( texture.wrapS ), + addressModeV: this._convertAddressMode( texture.wrapT ), + addressModeW: this._convertAddressMode( texture.wrapR ), + magFilter: this._convertFilterMode( texture.magFilter ), + minFilter: this._convertFilterMode( texture.minFilter ), + mipmapFilter: this._convertFilterMode( texture.minFilter ), + maxAnisotropy: 1 + }; + + // anisotropy can only be used when all filter modes are set to linear. + + if ( samplerDescriptorGPU.magFilter === GPUFilterMode.Linear && samplerDescriptorGPU.minFilter === GPUFilterMode.Linear && samplerDescriptorGPU.mipmapFilter === GPUFilterMode.Linear ) { + + samplerDescriptorGPU.maxAnisotropy = texture.anisotropy; + + } + + if ( texture.isDepthTexture && texture.compareFunction !== null ) { + + samplerDescriptorGPU.compare = _compareToWebGPU[ texture.compareFunction ]; + + } + + textureGPU.sampler = device.createSampler( samplerDescriptorGPU ); + + } + + createDefaultTexture( texture ) { + + let textureGPU; + + const format = getFormat( texture ); + + if ( texture.isCubeTexture ) { + + textureGPU = this._getDefaultCubeTextureGPU( format ); + + } else if ( texture.isVideoTexture ) { + + this.backend.get( texture ).externalTexture = this._getDefaultVideoFrame(); + + } else { + + textureGPU = this._getDefaultTextureGPU( format ); + + } + + this.backend.get( texture ).texture = textureGPU; + + } + + createTexture( texture, options = {} ) { + + const backend = this.backend; + const textureData = backend.get( texture ); + + if ( textureData.initialized ) { + + throw new Error( 'WebGPUTextureUtils: Texture already initialized.' ); + + } + + if ( options.needsMipmaps === undefined ) options.needsMipmaps = false; + if ( options.levels === undefined ) options.levels = 1; + if ( options.depth === undefined ) options.depth = 1; + + const { width, height, depth, levels } = options; + + if ( texture.isFramebufferTexture ) { + + if ( options.renderTarget ) { + + options.format = this.backend.utils.getCurrentColorFormat( options.renderTarget ); + + } else { + + options.format = this.backend.utils.getPreferredCanvasFormat(); + + } + + } + + const dimension = this._getDimension( texture ); + const format = texture.internalFormat || options.format || getFormat( texture, backend.device ); + + textureData.format = format; + + let sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1; + + sampleCount = backend.utils.getSampleCount( sampleCount ); + + const primarySampleCount = texture.isRenderTargetTexture && ! texture.isMultisampleRenderTargetTexture ? 1 : sampleCount; + + let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC; + + if ( texture.isStorageTexture === true ) { + + usage |= GPUTextureUsage.STORAGE_BINDING; + + } + + if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true ) { + + usage |= GPUTextureUsage.RENDER_ATTACHMENT; + + } + + const textureDescriptorGPU = { + label: texture.name, + size: { + width: width, + height: height, + depthOrArrayLayers: depth, + }, + mipLevelCount: levels, + sampleCount: primarySampleCount, + dimension: dimension, + format: format, + usage: usage + }; + + // texture creation + + if ( texture.isVideoTexture ) { + + const video = texture.source.data; + const videoFrame = new VideoFrame( video ); + + textureDescriptorGPU.size.width = videoFrame.displayWidth; + textureDescriptorGPU.size.height = videoFrame.displayHeight; + + videoFrame.close(); + + textureData.externalTexture = video; + + } else { + + if ( format === undefined ) { + + console.warn( 'WebGPURenderer: Texture format not supported.' ); + + return this.createDefaultTexture( texture ); + + } + + textureData.texture = backend.device.createTexture( textureDescriptorGPU ); + + } + + if ( texture.isRenderTargetTexture && sampleCount > 1 && ! texture.isMultisampleRenderTargetTexture ) { + + const msaaTextureDescriptorGPU = Object.assign( {}, textureDescriptorGPU ); + + msaaTextureDescriptorGPU.label = msaaTextureDescriptorGPU.label + '-msaa'; + msaaTextureDescriptorGPU.sampleCount = sampleCount; + + textureData.msaaTexture = backend.device.createTexture( msaaTextureDescriptorGPU ); + + } + + textureData.initialized = true; + + textureData.textureDescriptorGPU = textureDescriptorGPU; + + } + + destroyTexture( texture ) { + + const backend = this.backend; + const textureData = backend.get( texture ); + + if ( textureData.texture !== undefined ) textureData.texture.destroy(); + + if ( textureData.msaaTexture !== undefined ) textureData.msaaTexture.destroy(); + + backend.delete( texture ); + + } + + destroySampler( texture ) { + + const backend = this.backend; + const textureData = backend.get( texture ); + + delete textureData.sampler; + + } + + generateMipmaps( texture ) { + + const textureData = this.backend.get( texture ); + + if ( texture.isCubeTexture ) { + + for ( let i = 0; i < 6; i ++ ) { + + this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i ); + + } + + } else { + + const depth = texture.image.depth || 1; + + for ( let i = 0; i < depth; i ++ ) { + + this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i ); + + } + + } + + } + + getColorBuffer() { + + if ( this.colorBuffer ) this.colorBuffer.destroy(); + + const backend = this.backend; + const { width, height } = backend.getDrawingBufferSize(); + + this.colorBuffer = backend.device.createTexture( { + label: 'colorBuffer', + size: { + width: width, + height: height, + depthOrArrayLayers: 1 + }, + sampleCount: backend.utils.getSampleCount( backend.renderer.samples ), + format: backend.utils.getPreferredCanvasFormat(), + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC + } ); + + return this.colorBuffer; + + } + + getDepthBuffer( depth = true, stencil = false ) { + + const backend = this.backend; + const { width, height } = backend.getDrawingBufferSize(); + + const depthTexture = this.depthTexture; + const depthTextureGPU = backend.get( depthTexture ).texture; + + let format, type; + + if ( stencil ) { + + format = DepthStencilFormat; + type = UnsignedInt248Type; + + } else if ( depth ) { + + format = DepthFormat; + type = UnsignedIntType; + + } + + if ( depthTextureGPU !== undefined ) { + + if ( depthTexture.image.width === width && depthTexture.image.height === height && depthTexture.format === format && depthTexture.type === type ) { + + return depthTextureGPU; + + } + + this.destroyTexture( depthTexture ); + + } + + depthTexture.name = 'depthBuffer'; + depthTexture.format = format; + depthTexture.type = type; + depthTexture.image.width = width; + depthTexture.image.height = height; + + this.createTexture( depthTexture, { sampleCount: backend.utils.getSampleCount( backend.renderer.samples ), width, height } ); + + return backend.get( depthTexture ).texture; + + } + + updateTexture( texture, options ) { + + const textureData = this.backend.get( texture ); + + const { textureDescriptorGPU } = textureData; + + if ( texture.isRenderTargetTexture || ( textureDescriptorGPU === undefined /* unsupported texture format */ ) ) + return; + + // transfer texture data + + if ( texture.isDataTexture ) { + + this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY ); + + } else if ( texture.isDataArrayTexture || texture.isData3DTexture ) { + + for ( let i = 0; i < options.image.depth; i ++ ) { + + this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, i, texture.flipY, i ); + + } + + } else if ( texture.isCompressedTexture || texture.isCompressedArrayTexture ) { + + this._copyCompressedBufferToTexture( texture.mipmaps, textureData.texture, textureDescriptorGPU ); + + } else if ( texture.isCubeTexture ) { + + this._copyCubeMapToTexture( options.images, textureData.texture, textureDescriptorGPU, texture.flipY ); + + } else if ( texture.isVideoTexture ) { + + const video = texture.source.data; + + textureData.externalTexture = video; + + } else { + + this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY ); + + } + + // + + textureData.version = texture.version; + + if ( texture.onUpdate ) texture.onUpdate( texture ); + + } + + async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { + + const device = this.backend.device; + + const textureData = this.backend.get( texture ); + const textureGPU = textureData.texture; + const format = textureData.textureDescriptorGPU.format; + const bytesPerTexel = this._getBytesPerTexel( format ); + + let bytesPerRow = width * bytesPerTexel; + bytesPerRow = Math.ceil( bytesPerRow / 256 ) * 256; // Align to 256 bytes + + const readBuffer = device.createBuffer( + { + size: width * height * bytesPerTexel, + usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ + } + ); + + const encoder = device.createCommandEncoder(); + + encoder.copyTextureToBuffer( + { + texture: textureGPU, + origin: { x, y, z: faceIndex }, + }, + { + buffer: readBuffer, + bytesPerRow: bytesPerRow + }, + { + width: width, + height: height + } + + ); + + const typedArrayType = this._getTypedArrayType( format ); + + device.queue.submit( [ encoder.finish() ] ); + + await readBuffer.mapAsync( GPUMapMode.READ ); + + const buffer = readBuffer.getMappedRange(); + + return new typedArrayType( buffer ); + + } + + _isEnvironmentTexture( texture ) { + + const mapping = texture.mapping; + + return ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) || ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping ); + + } + + _getDefaultTextureGPU( format ) { + + let defaultTexture = this.defaultTexture[ format ]; + + if ( defaultTexture === undefined ) { + + const texture = new Texture(); + texture.minFilter = NearestFilter; + texture.magFilter = NearestFilter; + + this.createTexture( texture, { width: 1, height: 1, format } ); + + this.defaultTexture[ format ] = defaultTexture = texture; + + } + + return this.backend.get( defaultTexture ).texture; + + } + + _getDefaultCubeTextureGPU( format ) { + + let defaultCubeTexture = this.defaultTexture[ format ]; + + if ( defaultCubeTexture === undefined ) { + + const texture = new CubeTexture(); + texture.minFilter = NearestFilter; + texture.magFilter = NearestFilter; + + this.createTexture( texture, { width: 1, height: 1, depth: 6 } ); + + this.defaultCubeTexture[ format ] = defaultCubeTexture = texture; + + } + + return this.backend.get( defaultCubeTexture ).texture; + + } + + _getDefaultVideoFrame() { + + let defaultVideoFrame = this.defaultVideoFrame; + + if ( defaultVideoFrame === null ) { + + const init = { + timestamp: 0, + codedWidth: 1, + codedHeight: 1, + format: 'RGBA', + }; + + this.defaultVideoFrame = defaultVideoFrame = new VideoFrame( new Uint8Array( [ 0, 0, 0, 0xff ] ), init ); + + } + + return defaultVideoFrame; + + } + + _copyCubeMapToTexture( images, textureGPU, textureDescriptorGPU, flipY ) { + + for ( let i = 0; i < 6; i ++ ) { + + const image = images[ i ]; + + const flipIndex = flipY === true ? _flipMap[ i ] : i; + + if ( image.isDataTexture ) { + + this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, flipY ); + + } else { + + this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, flipY ); + + } + + } + + } + + _copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY ) { + + const device = this.backend.device; + + device.queue.copyExternalImageToTexture( + { + source: image + }, { + texture: textureGPU, + mipLevel: 0, + origin: { x: 0, y: 0, z: originDepth } + }, { + width: image.width, + height: image.height, + depthOrArrayLayers: 1 + } + ); + + if ( flipY === true ) { + + this._flipY( textureGPU, textureDescriptorGPU, originDepth ); + + } + + } + + _getPassUtils() { + + let passUtils = this._passUtils; + + if ( passUtils === null ) { + + this._passUtils = passUtils = new WebGPUTexturePassUtils( this.backend.device ); + + } + + return passUtils; + + } + + _generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) { + + this._getPassUtils().generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer ); + + } + + _flipY( textureGPU, textureDescriptorGPU, originDepth = 0 ) { + + this._getPassUtils().flipY( textureGPU, textureDescriptorGPU, originDepth ); + + } + + _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0 ) { + + // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture() + // @TODO: Consider to support valid buffer layouts with other formats like RGB + + const device = this.backend.device; + + const data = image.data; + + const bytesPerTexel = this._getBytesPerTexel( textureDescriptorGPU.format ); + const bytesPerRow = image.width * bytesPerTexel; + + device.queue.writeTexture( + { + texture: textureGPU, + mipLevel: 0, + origin: { x: 0, y: 0, z: originDepth } + }, + data, + { + offset: image.width * image.height * bytesPerTexel * depth, + bytesPerRow + }, + { + width: image.width, + height: image.height, + depthOrArrayLayers: 1 + } ); + + if ( flipY === true ) { + + this._flipY( textureGPU, textureDescriptorGPU, originDepth ); + + } + + } + + _copyCompressedBufferToTexture( mipmaps, textureGPU, textureDescriptorGPU ) { + + // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture() + + const device = this.backend.device; + + const blockData = this._getBlockData( textureDescriptorGPU.format ); + const isTextureArray = textureDescriptorGPU.size.depthOrArrayLayers > 1; + + for ( let i = 0; i < mipmaps.length; i ++ ) { + + const mipmap = mipmaps[ i ]; + + const width = mipmap.width; + const height = mipmap.height; + const depth = isTextureArray ? textureDescriptorGPU.size.depthOrArrayLayers : 1; + + const bytesPerRow = Math.ceil( width / blockData.width ) * blockData.byteLength; + const bytesPerImage = bytesPerRow * Math.ceil( height / blockData.height ); + + for ( let j = 0; j < depth; j ++ ) { + + device.queue.writeTexture( + { + texture: textureGPU, + mipLevel: i, + origin: { x: 0, y: 0, z: j } + }, + mipmap.data, + { + offset: j * bytesPerImage, + bytesPerRow, + rowsPerImage: Math.ceil( height / blockData.height ) + }, + { + width: Math.ceil( width / blockData.width ) * blockData.width, + height: Math.ceil( height / blockData.height ) * blockData.height, + depthOrArrayLayers: 1 + } + ); + + } + + } + + } + + _getBlockData( format ) { + + // this method is only relevant for compressed texture formats + + if ( format === GPUTextureFormat.BC1RGBAUnorm || format === GPUTextureFormat.BC1RGBAUnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; // DXT1 + if ( format === GPUTextureFormat.BC2RGBAUnorm || format === GPUTextureFormat.BC2RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // DXT3 + if ( format === GPUTextureFormat.BC3RGBAUnorm || format === GPUTextureFormat.BC3RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // DXT5 + if ( format === GPUTextureFormat.BC4RUnorm || format === GPUTextureFormat.BC4RSNorm ) return { byteLength: 8, width: 4, height: 4 }; // RGTC1 + if ( format === GPUTextureFormat.BC5RGUnorm || format === GPUTextureFormat.BC5RGSnorm ) return { byteLength: 16, width: 4, height: 4 }; // RGTC2 + if ( format === GPUTextureFormat.BC6HRGBUFloat || format === GPUTextureFormat.BC6HRGBFloat ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (float) + if ( format === GPUTextureFormat.BC7RGBAUnorm || format === GPUTextureFormat.BC7RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (unorm) + + if ( format === GPUTextureFormat.ETC2RGB8Unorm || format === GPUTextureFormat.ETC2RGB8UnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; + if ( format === GPUTextureFormat.ETC2RGB8A1Unorm || format === GPUTextureFormat.ETC2RGB8A1UnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; + if ( format === GPUTextureFormat.ETC2RGBA8Unorm || format === GPUTextureFormat.ETC2RGBA8UnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; + if ( format === GPUTextureFormat.EACR11Unorm ) return { byteLength: 8, width: 4, height: 4 }; + if ( format === GPUTextureFormat.EACR11Snorm ) return { byteLength: 8, width: 4, height: 4 }; + if ( format === GPUTextureFormat.EACRG11Unorm ) return { byteLength: 16, width: 4, height: 4 }; + if ( format === GPUTextureFormat.EACRG11Snorm ) return { byteLength: 16, width: 4, height: 4 }; + + if ( format === GPUTextureFormat.ASTC4x4Unorm || format === GPUTextureFormat.ASTC4x4UnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; + if ( format === GPUTextureFormat.ASTC5x4Unorm || format === GPUTextureFormat.ASTC5x4UnormSRGB ) return { byteLength: 16, width: 5, height: 4 }; + if ( format === GPUTextureFormat.ASTC5x5Unorm || format === GPUTextureFormat.ASTC5x5UnormSRGB ) return { byteLength: 16, width: 5, height: 5 }; + if ( format === GPUTextureFormat.ASTC6x5Unorm || format === GPUTextureFormat.ASTC6x5UnormSRGB ) return { byteLength: 16, width: 6, height: 5 }; + if ( format === GPUTextureFormat.ASTC6x6Unorm || format === GPUTextureFormat.ASTC6x6UnormSRGB ) return { byteLength: 16, width: 6, height: 6 }; + if ( format === GPUTextureFormat.ASTC8x5Unorm || format === GPUTextureFormat.ASTC8x5UnormSRGB ) return { byteLength: 16, width: 8, height: 5 }; + if ( format === GPUTextureFormat.ASTC8x6Unorm || format === GPUTextureFormat.ASTC8x6UnormSRGB ) return { byteLength: 16, width: 8, height: 6 }; + if ( format === GPUTextureFormat.ASTC8x8Unorm || format === GPUTextureFormat.ASTC8x8UnormSRGB ) return { byteLength: 16, width: 8, height: 8 }; + if ( format === GPUTextureFormat.ASTC10x5Unorm || format === GPUTextureFormat.ASTC10x5UnormSRGB ) return { byteLength: 16, width: 10, height: 5 }; + if ( format === GPUTextureFormat.ASTC10x6Unorm || format === GPUTextureFormat.ASTC10x6UnormSRGB ) return { byteLength: 16, width: 10, height: 6 }; + if ( format === GPUTextureFormat.ASTC10x8Unorm || format === GPUTextureFormat.ASTC10x8UnormSRGB ) return { byteLength: 16, width: 10, height: 8 }; + if ( format === GPUTextureFormat.ASTC10x10Unorm || format === GPUTextureFormat.ASTC10x10UnormSRGB ) return { byteLength: 16, width: 10, height: 10 }; + if ( format === GPUTextureFormat.ASTC12x10Unorm || format === GPUTextureFormat.ASTC12x10UnormSRGB ) return { byteLength: 16, width: 12, height: 10 }; + if ( format === GPUTextureFormat.ASTC12x12Unorm || format === GPUTextureFormat.ASTC12x12UnormSRGB ) return { byteLength: 16, width: 12, height: 12 }; + + } + + _convertAddressMode( value ) { + + let addressMode = GPUAddressMode.ClampToEdge; + + if ( value === RepeatWrapping ) { + + addressMode = GPUAddressMode.Repeat; + + } else if ( value === MirroredRepeatWrapping ) { + + addressMode = GPUAddressMode.MirrorRepeat; + + } + + return addressMode; + + } + + _convertFilterMode( value ) { + + let filterMode = GPUFilterMode.Linear; + + if ( value === NearestFilter || value === NearestMipmapNearestFilter || value === NearestMipmapLinearFilter ) { + + filterMode = GPUFilterMode.Nearest; + + } + + return filterMode; + + } + + _getBytesPerTexel( format ) { + + // 8-bit formats + if ( format === GPUTextureFormat.R8Unorm || + format === GPUTextureFormat.R8Snorm || + format === GPUTextureFormat.R8Uint || + format === GPUTextureFormat.R8Sint ) return 1; + + // 16-bit formats + if ( format === GPUTextureFormat.R16Uint || + format === GPUTextureFormat.R16Sint || + format === GPUTextureFormat.R16Float || + format === GPUTextureFormat.RG8Unorm || + format === GPUTextureFormat.RG8Snorm || + format === GPUTextureFormat.RG8Uint || + format === GPUTextureFormat.RG8Sint ) return 2; + + // 32-bit formats + if ( format === GPUTextureFormat.R32Uint || + format === GPUTextureFormat.R32Sint || + format === GPUTextureFormat.R32Float || + format === GPUTextureFormat.RG16Uint || + format === GPUTextureFormat.RG16Sint || + format === GPUTextureFormat.RG16Float || + format === GPUTextureFormat.RGBA8Unorm || + format === GPUTextureFormat.RGBA8UnormSRGB || + format === GPUTextureFormat.RGBA8Snorm || + format === GPUTextureFormat.RGBA8Uint || + format === GPUTextureFormat.RGBA8Sint || + format === GPUTextureFormat.BGRA8Unorm || + format === GPUTextureFormat.BGRA8UnormSRGB || + // Packed 32-bit formats + format === GPUTextureFormat.RGB9E5UFloat || + format === GPUTextureFormat.RGB10A2Unorm || + format === GPUTextureFormat.RG11B10UFloat || + format === GPUTextureFormat.Depth32Float || + format === GPUTextureFormat.Depth24Plus || + format === GPUTextureFormat.Depth24PlusStencil8 || + format === GPUTextureFormat.Depth32FloatStencil8 ) return 4; + + // 64-bit formats + if ( format === GPUTextureFormat.RG32Uint || + format === GPUTextureFormat.RG32Sint || + format === GPUTextureFormat.RG32Float || + format === GPUTextureFormat.RGBA16Uint || + format === GPUTextureFormat.RGBA16Sint || + format === GPUTextureFormat.RGBA16Float ) return 8; + + // 128-bit formats + if ( format === GPUTextureFormat.RGBA32Uint || + format === GPUTextureFormat.RGBA32Sint || + format === GPUTextureFormat.RGBA32Float ) return 16; + + + } + + _getTypedArrayType( format ) { + + if ( format === GPUTextureFormat.R8Uint ) return Uint8Array; + if ( format === GPUTextureFormat.R8Sint ) return Int8Array; + if ( format === GPUTextureFormat.R8Unorm ) return Uint8Array; + if ( format === GPUTextureFormat.R8Snorm ) return Int8Array; + if ( format === GPUTextureFormat.RG8Uint ) return Uint8Array; + if ( format === GPUTextureFormat.RG8Sint ) return Int8Array; + if ( format === GPUTextureFormat.RG8Unorm ) return Uint8Array; + if ( format === GPUTextureFormat.RG8Snorm ) return Int8Array; + if ( format === GPUTextureFormat.RGBA8Uint ) return Uint8Array; + if ( format === GPUTextureFormat.RGBA8Sint ) return Int8Array; + if ( format === GPUTextureFormat.RGBA8Unorm ) return Uint8Array; + if ( format === GPUTextureFormat.RGBA8Snorm ) return Int8Array; + + + if ( format === GPUTextureFormat.R16Uint ) return Uint16Array; + if ( format === GPUTextureFormat.R16Sint ) return Int16Array; + if ( format === GPUTextureFormat.RG16Uint ) return Uint16Array; + if ( format === GPUTextureFormat.RG16Sint ) return Int16Array; + if ( format === GPUTextureFormat.RGBA16Uint ) return Uint16Array; + if ( format === GPUTextureFormat.RGBA16Sint ) return Int16Array; + if ( format === GPUTextureFormat.R16Float ) return Uint16Array; + if ( format === GPUTextureFormat.RG16Float ) return Uint16Array; + if ( format === GPUTextureFormat.RGBA16Float ) return Uint16Array; + + + if ( format === GPUTextureFormat.R32Uint ) return Uint32Array; + if ( format === GPUTextureFormat.R32Sint ) return Int32Array; + if ( format === GPUTextureFormat.R32Float ) return Float32Array; + if ( format === GPUTextureFormat.RG32Uint ) return Uint32Array; + if ( format === GPUTextureFormat.RG32Sint ) return Int32Array; + if ( format === GPUTextureFormat.RG32Float ) return Float32Array; + if ( format === GPUTextureFormat.RGBA32Uint ) return Uint32Array; + if ( format === GPUTextureFormat.RGBA32Sint ) return Int32Array; + if ( format === GPUTextureFormat.RGBA32Float ) return Float32Array; + + if ( format === GPUTextureFormat.BGRA8Unorm ) return Uint8Array; + if ( format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array; + if ( format === GPUTextureFormat.RGB10A2Unorm ) return Uint32Array; + if ( format === GPUTextureFormat.RGB9E5UFloat ) return Uint32Array; + if ( format === GPUTextureFormat.RG11B10UFloat ) return Uint32Array; + + if ( format === GPUTextureFormat.Depth32Float ) return Float32Array; + if ( format === GPUTextureFormat.Depth24Plus ) return Uint32Array; + if ( format === GPUTextureFormat.Depth24PlusStencil8 ) return Uint32Array; + if ( format === GPUTextureFormat.Depth32FloatStencil8 ) return Float32Array; + + } + + _getDimension( texture ) { + + let dimension; + + if ( texture.isData3DTexture ) { + + dimension = GPUTextureDimension.ThreeD; + + } else { + + dimension = GPUTextureDimension.TwoD; + + } + + return dimension; + + } + +} + +function getFormat( texture, device = null ) { + + const format = texture.format; + const type = texture.type; + const colorSpace = texture.colorSpace; + + let formatGPU; + + if ( texture.isCompressedTexture === true || texture.isCompressedArrayTexture === true ) { + + switch ( format ) { + + case RGBA_S3TC_DXT1_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm; + break; + + case RGBA_S3TC_DXT3_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm; + break; + + case RGBA_S3TC_DXT5_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm; + break; + + case RGB_ETC2_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm; + break; + + case RGBA_ETC2_EAC_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGBA8UnormSRGB : GPUTextureFormat.ETC2RGBA8Unorm; + break; + + case RGBA_ASTC_4x4_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC4x4UnormSRGB : GPUTextureFormat.ASTC4x4Unorm; + break; + + case RGBA_ASTC_5x4_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x4UnormSRGB : GPUTextureFormat.ASTC5x4Unorm; + break; + + case RGBA_ASTC_5x5_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x5UnormSRGB : GPUTextureFormat.ASTC5x5Unorm; + break; + + case RGBA_ASTC_6x5_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x5UnormSRGB : GPUTextureFormat.ASTC6x5Unorm; + break; + + case RGBA_ASTC_6x6_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x6UnormSRGB : GPUTextureFormat.ASTC6x6Unorm; + break; + + case RGBA_ASTC_8x5_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x5UnormSRGB : GPUTextureFormat.ASTC8x5Unorm; + break; + + case RGBA_ASTC_8x6_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x6UnormSRGB : GPUTextureFormat.ASTC8x6Unorm; + break; + + case RGBA_ASTC_8x8_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x8UnormSRGB : GPUTextureFormat.ASTC8x8Unorm; + break; + + case RGBA_ASTC_10x5_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x5UnormSRGB : GPUTextureFormat.ASTC10x5Unorm; + break; + + case RGBA_ASTC_10x6_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x6UnormSRGB : GPUTextureFormat.ASTC10x6Unorm; + break; + + case RGBA_ASTC_10x8_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x8UnormSRGB : GPUTextureFormat.ASTC10x8Unorm; + break; + + case RGBA_ASTC_10x10_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x10UnormSRGB : GPUTextureFormat.ASTC10x10Unorm; + break; + + case RGBA_ASTC_12x10_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x10UnormSRGB : GPUTextureFormat.ASTC12x10Unorm; + break; + + case RGBA_ASTC_12x12_Format: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x12UnormSRGB : GPUTextureFormat.ASTC12x12Unorm; + break; + + case RGBAFormat: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture format.', format ); + + } + + } else { + + switch ( format ) { + + case RGBAFormat: + + switch ( type ) { + + case ByteType: + formatGPU = GPUTextureFormat.RGBA8Snorm; + break; + + case ShortType: + formatGPU = GPUTextureFormat.RGBA16Sint; + break; + + case UnsignedShortType: + formatGPU = GPUTextureFormat.RGBA16Uint; + break; + case UnsignedIntType: + formatGPU = GPUTextureFormat.RGBA32Uint; + break; + + case IntType: + formatGPU = GPUTextureFormat.RGBA32Sint; + break; + + case UnsignedByteType: + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm; + break; + + case HalfFloatType: + formatGPU = GPUTextureFormat.RGBA16Float; + break; + + case FloatType: + formatGPU = GPUTextureFormat.RGBA32Float; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type ); + + } + + break; + + case RGBFormat: + + switch ( type ) { + + case UnsignedInt5999Type: + formatGPU = GPUTextureFormat.RGB9E5UFloat; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RGBFormat.', type ); + + } + + break; + + case RedFormat: + + switch ( type ) { + + case ByteType: + formatGPU = GPUTextureFormat.R8Snorm; + break; + + case ShortType: + formatGPU = GPUTextureFormat.R16Sint; + break; + + case UnsignedShortType: + formatGPU = GPUTextureFormat.R16Uint; + break; + + case UnsignedIntType: + formatGPU = GPUTextureFormat.R32Uint; + break; + + case IntType: + formatGPU = GPUTextureFormat.R32Sint; + break; + + case UnsignedByteType: + formatGPU = GPUTextureFormat.R8Unorm; + break; + + case HalfFloatType: + formatGPU = GPUTextureFormat.R16Float; + break; + + case FloatType: + formatGPU = GPUTextureFormat.R32Float; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type ); + + } + + break; + + case RGFormat: + + switch ( type ) { + + case ByteType: + formatGPU = GPUTextureFormat.RG8Snorm; + break; + + case ShortType: + formatGPU = GPUTextureFormat.RG16Sint; + break; + + case UnsignedShortType: + formatGPU = GPUTextureFormat.RG16Uint; + break; + + case UnsignedIntType: + formatGPU = GPUTextureFormat.RG32Uint; + break; + + case IntType: + formatGPU = GPUTextureFormat.RG32Sint; + break; + + case UnsignedByteType: + formatGPU = GPUTextureFormat.RG8Unorm; + break; + + case HalfFloatType: + formatGPU = GPUTextureFormat.RG16Float; + break; + + case FloatType: + formatGPU = GPUTextureFormat.RG32Float; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type ); + + } + + break; + + case DepthFormat: + + switch ( type ) { + + case UnsignedShortType: + formatGPU = GPUTextureFormat.Depth16Unorm; + break; + + case UnsignedIntType: + formatGPU = GPUTextureFormat.Depth24Plus; + break; + + case FloatType: + formatGPU = GPUTextureFormat.Depth32Float; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with DepthFormat.', type ); + + } + + break; + + case DepthStencilFormat: + + switch ( type ) { + + case UnsignedInt248Type: + formatGPU = GPUTextureFormat.Depth24PlusStencil8; + break; + + case FloatType: + + if ( device && device.features.has( GPUFeatureName.Depth32FloatStencil8 ) === false ) { + + console.error( 'WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.' ); + + } + + formatGPU = GPUTextureFormat.Depth32FloatStencil8; + + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with DepthStencilFormat.', type ); + + } + + break; + + case RedIntegerFormat: + + switch ( type ) { + + case IntType: + formatGPU = GPUTextureFormat.R32Sint; + break; + + case UnsignedIntType: + formatGPU = GPUTextureFormat.R32Uint; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RedIntegerFormat.', type ); + + } + + break; + + case RGIntegerFormat: + + switch ( type ) { + + case IntType: + formatGPU = GPUTextureFormat.RG32Sint; + break; + + case UnsignedIntType: + formatGPU = GPUTextureFormat.RG32Uint; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RGIntegerFormat.', type ); + + } + + break; + + case RGBAIntegerFormat: + + switch ( type ) { + + case IntType: + formatGPU = GPUTextureFormat.RGBA32Sint; + break; + + case UnsignedIntType: + formatGPU = GPUTextureFormat.RGBA32Uint; + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.', type ); + + } + + break; + + default: + console.error( 'WebGPURenderer: Unsupported texture format.', format ); + + } + + } + + return formatGPU; + +} + +const declarationRegexp = /^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i; +const propertiesRegexp = /([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig; + +const wgslTypeLib$1 = { + 'f32': 'float', + 'i32': 'int', + 'u32': 'uint', + 'bool': 'bool', + + 'vec2': 'vec2', + 'vec2': 'ivec2', + 'vec2': 'uvec2', + 'vec2': 'bvec2', + + 'vec2f': 'vec2', + 'vec2i': 'ivec2', + 'vec2u': 'uvec2', + 'vec2b': 'bvec2', + + 'vec3': 'vec3', + 'vec3': 'ivec3', + 'vec3': 'uvec3', + 'vec3': 'bvec3', + + 'vec3f': 'vec3', + 'vec3i': 'ivec3', + 'vec3u': 'uvec3', + 'vec3b': 'bvec3', + + 'vec4': 'vec4', + 'vec4': 'ivec4', + 'vec4': 'uvec4', + 'vec4': 'bvec4', + + 'vec4f': 'vec4', + 'vec4i': 'ivec4', + 'vec4u': 'uvec4', + 'vec4b': 'bvec4', + + 'mat2x2': 'mat2', + 'mat2x2f': 'mat2', + + 'mat3x3': 'mat3', + 'mat3x3f': 'mat3', + + 'mat4x4': 'mat4', + 'mat4x4f': 'mat4', + + 'sampler': 'sampler', + + 'texture_1d': 'texture', + + 'texture_2d': 'texture', + 'texture_2d_array': 'texture', + 'texture_multisampled_2d': 'cubeTexture', + + 'texture_depth_2d': 'depthTexture', + + 'texture_3d': 'texture3D', + + 'texture_cube': 'cubeTexture', + 'texture_cube_array': 'cubeTexture', + + 'texture_storage_1d': 'storageTexture', + 'texture_storage_2d': 'storageTexture', + 'texture_storage_2d_array': 'storageTexture', + 'texture_storage_3d': 'storageTexture' + +}; + +const parse = ( source ) => { + + source = source.trim(); + + const declaration = source.match( declarationRegexp ); + + if ( declaration !== null && declaration.length === 4 ) { + + const inputsCode = declaration[ 2 ]; + const propsMatches = []; + let match = null; + + while ( ( match = propertiesRegexp.exec( inputsCode ) ) !== null ) { + + propsMatches.push( { name: match[ 1 ], type: match[ 2 ] } ); + + } + + // Process matches to correctly pair names and types + const inputs = []; + for ( let i = 0; i < propsMatches.length; i ++ ) { + + const { name, type } = propsMatches[ i ]; + + let resolvedType = type; + + if ( resolvedType.startsWith( 'ptr' ) ) { + + resolvedType = 'pointer'; + + } else { + + if ( resolvedType.startsWith( 'texture' ) ) { + + resolvedType = type.split( '<' )[ 0 ]; + + } + + resolvedType = wgslTypeLib$1[ resolvedType ]; + + } + + inputs.push( new NodeFunctionInput( resolvedType, name ) ); + + } + + const blockCode = source.substring( declaration[ 0 ].length ); + const outputType = declaration[ 3 ] || 'void'; + + const name = declaration[ 1 ] !== undefined ? declaration[ 1 ] : ''; + const type = wgslTypeLib$1[ outputType ] || outputType; + + return { + type, + inputs, + name, + inputsCode, + blockCode, + outputType + }; + + } else { + + throw new Error( 'FunctionNode: Function is not a WGSL code.' ); + + } + +}; + +class WGSLNodeFunction extends NodeFunction { + + constructor( source ) { + + const { type, inputs, name, inputsCode, blockCode, outputType } = parse( source ); + + super( type, inputs, name ); + + this.inputsCode = inputsCode; + this.blockCode = blockCode; + this.outputType = outputType; + + } + + getCode( name = this.name ) { + + const outputType = this.outputType !== 'void' ? '-> ' + this.outputType : ''; + + return `fn ${ name } ( ${ this.inputsCode.trim() } ) ${ outputType }` + this.blockCode; + + } + +} + +class WGSLNodeParser extends NodeParser { + + parseFunction( source ) { + + return new WGSLNodeFunction( source ); + + } + +} + +// GPUShaderStage is not defined in browsers not supporting WebGPU +const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 }; + +const accessNames = { + [ NodeAccess.READ_ONLY ]: 'read', + [ NodeAccess.WRITE_ONLY ]: 'write', + [ NodeAccess.READ_WRITE ]: 'read_write' +}; + +const wrapNames = { + [ RepeatWrapping ]: 'repeat', + [ ClampToEdgeWrapping ]: 'clamp', + [ MirroredRepeatWrapping ]: 'mirror' +}; + +const gpuShaderStageLib = { + 'vertex': GPUShaderStage ? GPUShaderStage.VERTEX : 1, + 'fragment': GPUShaderStage ? GPUShaderStage.FRAGMENT : 2, + 'compute': GPUShaderStage ? GPUShaderStage.COMPUTE : 4 +}; + +const supports = { + instance: true, + swizzleAssign: false, + storageBuffer: true +}; + +const wgslFnOpLib = { + '^^': 'tsl_xor' +}; + +const wgslTypeLib = { + float: 'f32', + int: 'i32', + uint: 'u32', + bool: 'bool', + color: 'vec3', + + vec2: 'vec2', + ivec2: 'vec2', + uvec2: 'vec2', + bvec2: 'vec2', + + vec3: 'vec3', + ivec3: 'vec3', + uvec3: 'vec3', + bvec3: 'vec3', + + vec4: 'vec4', + ivec4: 'vec4', + uvec4: 'vec4', + bvec4: 'vec4', + + mat2: 'mat2x2', + mat3: 'mat3x3', + mat4: 'mat4x4' +}; + +const wgslCodeCache = {}; + +const wgslPolyfill = { + tsl_xor: new CodeNode( 'fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }' ), + mod_float: new CodeNode( 'fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ), + mod_vec2: new CodeNode( 'fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ), + mod_vec3: new CodeNode( 'fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ), + mod_vec4: new CodeNode( 'fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ), + equals_bool: new CodeNode( 'fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ), + equals_bvec2: new CodeNode( 'fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }' ), + equals_bvec3: new CodeNode( 'fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }' ), + equals_bvec4: new CodeNode( 'fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }' ), + repeatWrapping_float: new CodeNode( 'fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }' ), + mirrorWrapping_float: new CodeNode( 'fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }' ), + clampWrapping_float: new CodeNode( 'fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }' ), + biquadraticTexture: new CodeNode( /* wgsl */` +fn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f { + + let res = vec2f( iRes ); + + let uvScaled = coord * res; + let uvWrapping = ( ( uvScaled % res ) + res ) % res; + + // https://www.shadertoy.com/view/WtyXRy + + let uv = uvWrapping - 0.5; + let iuv = floor( uv ); + let f = fract( uv ); + + let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level ); + let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level ); + let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level ); + let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level ); + + return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y ); + +} +` ) +}; + +const wgslMethods = { + dFdx: 'dpdx', + dFdy: '- dpdy', + mod_float: 'tsl_mod_float', + mod_vec2: 'tsl_mod_vec2', + mod_vec3: 'tsl_mod_vec3', + mod_vec4: 'tsl_mod_vec4', + equals_bool: 'tsl_equals_bool', + equals_bvec2: 'tsl_equals_bvec2', + equals_bvec3: 'tsl_equals_bvec3', + equals_bvec4: 'tsl_equals_bvec4', + inversesqrt: 'inverseSqrt', + bitcast: 'bitcast' +}; + +// WebGPU issue: does not support pow() with negative base on Windows + +if ( typeof navigator !== 'undefined' && /Windows/g.test( navigator.userAgent ) ) { + + wgslPolyfill.pow_float = new CodeNode( 'fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }' ); + wgslPolyfill.pow_vec2 = new CodeNode( 'fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }', [ wgslPolyfill.pow_float ] ); + wgslPolyfill.pow_vec3 = new CodeNode( 'fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }', [ wgslPolyfill.pow_float ] ); + wgslPolyfill.pow_vec4 = new CodeNode( 'fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }', [ wgslPolyfill.pow_float ] ); + + wgslMethods.pow_float = 'tsl_pow_float'; + wgslMethods.pow_vec2 = 'tsl_pow_vec2'; + wgslMethods.pow_vec3 = 'tsl_pow_vec3'; + wgslMethods.pow_vec4 = 'tsl_pow_vec4'; + +} + +// + +let diagnostics = ''; + +if ( ( typeof navigator !== 'undefined' && /Firefox|Deno/g.test( navigator.userAgent ) ) !== true ) { + + diagnostics += 'diagnostic( off, derivative_uniformity );\n'; + +} + +// + +class WGSLNodeBuilder extends NodeBuilder { + + constructor( object, renderer ) { + + super( object, renderer, new WGSLNodeParser() ); + + this.uniformGroups = {}; + + this.builtins = {}; + + this.directives = {}; + + this.scopedArrays = new Map(); + + } + + needsToWorkingColorSpace( texture ) { + + return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace; + + } + + _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + if ( depthSnippet ) { + + return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`; + + } else { + + return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`; + + } + + } else if ( this.isFilteredTexture( texture ) ) { + + return this.generateFilteredTexture( texture, textureProperty, uvSnippet ); + + } else { + + return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0' ); + + } + + } + + _generateVideoSample( textureProperty, uvSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + return `textureSampleBaseClampToEdge( ${ textureProperty }, ${ textureProperty }_sampler, vec2( ${ uvSnippet }.x, 1.0 - ${ uvSnippet }.y ) )`; + + } else { + + console.error( `WebGPURenderer: THREE.VideoTexture does not support ${ shaderStage } shader.` ); + + } + + } + + _generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false ) { + + return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`; + + } else if ( this.isFilteredTexture( texture ) ) { + + return this.generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet ); + + } else { + + return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet ); + + } + + } + + generateWrapFunction( texture ) { + + const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }T`; + + let nodeCode = wgslCodeCache[ functionName ]; + + if ( nodeCode === undefined ) { + + const includes = []; + + let code = `fn ${ functionName }( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`; + + const addWrapSnippet = ( wrap, axis ) => { + + if ( wrap === RepeatWrapping ) { + + includes.push( wgslPolyfill.repeatWrapping_float ); + + code += `\t\ttsl_repeatWrapping_float( coord.${ axis } )`; + + } else if ( wrap === ClampToEdgeWrapping ) { + + includes.push( wgslPolyfill.clampWrapping_float ); + + code += `\t\ttsl_clampWrapping_float( coord.${ axis } )`; + + } else if ( wrap === MirroredRepeatWrapping ) { + + includes.push( wgslPolyfill.mirrorWrapping_float ); + + code += `\t\ttsl_mirrorWrapping_float( coord.${ axis } )`; + + } else { + + code += `\t\tcoord.${ axis }`; + + console.warn( `WebGPURenderer: Unsupported texture wrap type "${ wrap }" for vertex shader.` ); + + } + + }; + + addWrapSnippet( texture.wrapS, 'x' ); + + code += ',\n'; + + addWrapSnippet( texture.wrapT, 'y' ); + + code += '\n\t);\n\n}\n'; + + wgslCodeCache[ functionName ] = nodeCode = new CodeNode( code, includes ); + + } + + nodeCode.build( this ); + + return functionName; + + } + + generateTextureDimension( texture, textureProperty, levelSnippet ) { + + const textureData = this.getDataFromNode( texture, this.shaderStage, this.globalCache ); + + if ( textureData.dimensionsSnippet === undefined ) textureData.dimensionsSnippet = {}; + + let textureDimensionNode = textureData.dimensionsSnippet[ levelSnippet ]; + + if ( textureData.dimensionsSnippet[ levelSnippet ] === undefined ) { + + let textureDimensionsParams; + + if ( texture.isMultisampleRenderTargetTexture === true ) { + + textureDimensionsParams = textureProperty; + + } else { + + textureDimensionsParams = `${ textureProperty }, u32( ${ levelSnippet } )`; + + } + + textureDimensionNode = new VarNode( new ExpressionNode( `textureDimensions( ${ textureDimensionsParams } )`, 'uvec2' ) ); + + textureData.dimensionsSnippet[ levelSnippet ] = textureDimensionNode; + + } + + return textureDimensionNode.build( this ); + + } + + generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet = '0u' ) { + + this._include( 'biquadraticTexture' ); + + const wrapFunction = this.generateWrapFunction( texture ); + const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet ); + + return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`; + + } + + generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet = '0u' ) { + + const wrapFunction = this.generateWrapFunction( texture ); + const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet ); + + const coordSnippet = `vec2u( ${ wrapFunction }( ${ uvSnippet } ) * vec2f( ${ textureDimension } ) )`; + + return this.generateTextureLoad( texture, textureProperty, coordSnippet, depthSnippet, levelSnippet ); + + } + + generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0u' ) { + + if ( texture.isVideoTexture === true || texture.isStorageTexture === true ) { + + return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`; + + } else if ( depthSnippet ) { + + return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`; + + } else { + + return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`; + + } + + } + + generateTextureStore( texture, textureProperty, uvIndexSnippet, valueSnippet ) { + + return `textureStore( ${ textureProperty }, ${ uvIndexSnippet }, ${ valueSnippet } )`; + + } + + isSampleCompare( texture ) { + + return texture.isDepthTexture === true && texture.compareFunction !== null; + + } + + isUnfilterable( texture ) { + + return this.getComponentTypeFromTexture( texture ) !== 'float' || + ( ! this.isAvailable( 'float32Filterable' ) && texture.isDataTexture === true && texture.type === FloatType ) || + ( this.isSampleCompare( texture ) === false && texture.minFilter === NearestFilter && texture.magFilter === NearestFilter ) || + texture.isMultisampleRenderTargetTexture === true; + + } + + generateTexture( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + let snippet = null; + + if ( texture.isVideoTexture === true ) { + + snippet = this._generateVideoSample( textureProperty, uvSnippet, shaderStage ); + + } else if ( this.isUnfilterable( texture ) ) { + + snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0', shaderStage ); + + } else { + + snippet = this._generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage ); + + } + + return snippet; + + } + + generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + // TODO handle i32 or u32 --> uvSnippet, array_index: A, ddx, ddy + return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`; + + } else { + + console.error( `WebGPURenderer: THREE.TextureNode.gradient() does not support ${ shaderStage } shader.` ); + + } + + } + + generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`; + + } else { + + console.error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` ); + + } + + } + + generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + let snippet = null; + + if ( texture.isVideoTexture === true ) { + + snippet = this._generateVideoSample( textureProperty, uvSnippet, shaderStage ); + + } else { + + snippet = this._generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage ); + + } + + return snippet; + + } + + generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, shaderStage = this.shaderStage ) { + + if ( shaderStage === 'fragment' ) { + + return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`; + + } else { + + console.error( `WebGPURenderer: THREE.TextureNode.biasNode does not support ${ shaderStage } shader.` ); + + } + + } + + getPropertyName( node, shaderStage = this.shaderStage ) { + + if ( node.isNodeVarying === true && node.needsInterpolation === true ) { + + if ( shaderStage === 'vertex' ) { + + return `varyings.${ node.name }`; + + } + + } else if ( node.isNodeUniform === true ) { + + const name = node.name; + const type = node.type; + + if ( type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'texture3D' ) { + + return name; + + } else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) { + + return `NodeBuffer_${ node.id }.${name}`; + + } else { + + return node.groupNode.name + '.' + name; + + } + + } + + return super.getPropertyName( node ); + + } + + getOutputStructName() { + + return 'output'; + + } + + _getUniformGroupCount( shaderStage ) { + + return Object.keys( this.uniforms[ shaderStage ] ).length; + + } + + getFunctionOperator( op ) { + + const fnOp = wgslFnOpLib[ op ]; + + if ( fnOp !== undefined ) { + + this._include( fnOp ); + + return fnOp; + + } + + return null; + + } + + getNodeAccess( node, shaderStage ) { + + if ( shaderStage !== 'compute' ) + return NodeAccess.READ_ONLY; + + return node.access; + + } + + getStorageAccess( node, shaderStage ) { + + return accessNames[ this.getNodeAccess( node, shaderStage ) ]; + + } + + getUniformFromNode( node, type, shaderStage, name = null ) { + + const uniformNode = super.getUniformFromNode( node, type, shaderStage, name ); + const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache ); + + if ( nodeData.uniformGPU === undefined ) { + + let uniformGPU; + + const group = node.groupNode; + const groupName = group.name; + + const bindings = this.getBindGroupArray( groupName, shaderStage ); + + if ( type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'texture3D' ) { + + let texture = null; + + const access = this.getNodeAccess( node, shaderStage ); + + if ( type === 'texture' || type === 'storageTexture' ) { + + texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group, access ); + + } else if ( type === 'cubeTexture' ) { + + texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, access ); + + } else if ( type === 'texture3D' ) { + + texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, access ); + + } + + texture.store = node.isStorageTextureNode === true; + texture.setVisibility( gpuShaderStageLib[ shaderStage ] ); + + if ( shaderStage === 'fragment' && this.isUnfilterable( node.value ) === false && texture.store === false ) { + + const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node, group ); + sampler.setVisibility( gpuShaderStageLib[ shaderStage ] ); + + bindings.push( sampler, texture ); + + uniformGPU = [ sampler, texture ]; + + } else { + + bindings.push( texture ); + + uniformGPU = [ texture ]; + + } + + } else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) { + + const bufferClass = type === 'buffer' ? NodeUniformBuffer : NodeStorageBuffer; + + const buffer = new bufferClass( node, group ); + buffer.setVisibility( gpuShaderStageLib[ shaderStage ] ); + + bindings.push( buffer ); + + uniformGPU = buffer; + + } else { + + const uniformsStage = this.uniformGroups[ shaderStage ] || ( this.uniformGroups[ shaderStage ] = {} ); + + let uniformsGroup = uniformsStage[ groupName ]; + + if ( uniformsGroup === undefined ) { + + uniformsGroup = new NodeUniformsGroup( groupName, group ); + uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] ); + + uniformsStage[ groupName ] = uniformsGroup; + + bindings.push( uniformsGroup ); + + } + + uniformGPU = this.getNodeUniform( uniformNode, type ); + + uniformsGroup.addUniform( uniformGPU ); + + } + + nodeData.uniformGPU = uniformGPU; + + } + + return uniformNode; + + } + + getBuiltin( name, property, type, shaderStage = this.shaderStage ) { + + const map = this.builtins[ shaderStage ] || ( this.builtins[ shaderStage ] = new Map() ); + + if ( map.has( name ) === false ) { + + map.set( name, { + name, + property, + type + } ); + + } + + return property; + + } + + hasBuiltin( name, shaderStage = this.shaderStage ) { + + return ( this.builtins[ shaderStage ] !== undefined && this.builtins[ shaderStage ].has( name ) ); + + } + + getVertexIndex() { + + if ( this.shaderStage === 'vertex' ) { + + return this.getBuiltin( 'vertex_index', 'vertexIndex', 'u32', 'attribute' ); + + } + + return 'vertexIndex'; + + } + + buildFunctionCode( shaderNode ) { + + const layout = shaderNode.layout; + const flowData = this.flowShaderNode( shaderNode ); + + const parameters = []; + + for ( const input of layout.inputs ) { + + parameters.push( input.name + ' : ' + this.getType( input.type ) ); + + } + + // + + let code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } { +${ flowData.vars } +${ flowData.code } +`; + + if ( flowData.result ) { + + code += `\treturn ${ flowData.result };\n`; + + } + + code += '\n}\n'; + + // + + return code; + + } + + getInstanceIndex() { + + if ( this.shaderStage === 'vertex' ) { + + return this.getBuiltin( 'instance_index', 'instanceIndex', 'u32', 'attribute' ); + + } + + return 'instanceIndex'; + + } + + getInvocationLocalIndex() { + + return this.getBuiltin( 'local_invocation_index', 'invocationLocalIndex', 'u32', 'attribute' ); + + } + + getSubgroupSize() { + + this.enableSubGroups(); + + return this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' ); + + } + + getInvocationSubgroupIndex() { + + this.enableSubGroups(); + + return this.getBuiltin( 'subgroup_invocation_id', 'invocationSubgroupIndex', 'u32', 'attribute' ); + + } + + getSubgroupIndex() { + + this.enableSubGroups(); + + return this.getBuiltin( 'subgroup_id', 'subgroupIndex', 'u32', 'attribute' ); + + } + + getDrawIndex() { + + return null; + + } + + getFrontFacing() { + + return this.getBuiltin( 'front_facing', 'isFront', 'bool' ); + + } + + getFragCoord() { + + return this.getBuiltin( 'position', 'fragCoord', 'vec4' ) + '.xy'; + + } + + getFragDepth() { + + return 'output.' + this.getBuiltin( 'frag_depth', 'depth', 'f32', 'output' ); + + } + + getClipDistance() { + + return 'varyings.hw_clip_distances'; + + } + + isFlipY() { + + return false; + + } + + enableDirective( name, shaderStage = this.shaderStage ) { + + const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = new Set() ); + stage.add( name ); + + } + + getDirectives( shaderStage ) { + + const snippets = []; + const directives = this.directives[ shaderStage ]; + + if ( directives !== undefined ) { + + for ( const directive of directives ) { + + snippets.push( `enable ${directive};` ); + + } + + } + + return snippets.join( '\n' ); + + } + + enableSubGroups() { + + this.enableDirective( 'subgroups' ); + + } + + enableSubgroupsF16() { + + this.enableDirective( 'subgroups-f16' ); + + } + + enableClipDistances() { + + this.enableDirective( 'clip_distances' ); + + } + + enableShaderF16() { + + this.enableDirective( 'f16' ); + + } + + enableDualSourceBlending() { + + this.enableDirective( 'dual_source_blending' ); + + } + + enableHardwareClipping( planeCount ) { + + this.enableClipDistances(); + this.getBuiltin( 'clip_distances', 'hw_clip_distances', `array`, 'vertex' ); + + } + + getBuiltins( shaderStage ) { + + const snippets = []; + const builtins = this.builtins[ shaderStage ]; + + if ( builtins !== undefined ) { + + for ( const { name, property, type } of builtins.values() ) { + + snippets.push( `@builtin( ${name} ) ${property} : ${type}` ); + + } + + } + + return snippets.join( ',\n\t' ); + + } + + getScopedArray( name, scope, bufferType, bufferCount ) { + + if ( this.scopedArrays.has( name ) === false ) { + + this.scopedArrays.set( name, { + name, + scope, + bufferType, + bufferCount + } ); + + } + + return name; + + } + + getScopedArrays( shaderStage ) { + + if ( shaderStage !== 'compute' ) { + + return; + + } + + const snippets = []; + + for ( const { name, scope, bufferType, bufferCount } of this.scopedArrays.values() ) { + + const type = this.getType( bufferType ); + + snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` ); + + } + + return snippets.join( '\n' ); + + } + + getAttributes( shaderStage ) { + + const snippets = []; + + if ( shaderStage === 'compute' ) { + + this.getBuiltin( 'global_invocation_id', 'id', 'vec3', 'attribute' ); + this.getBuiltin( 'workgroup_id', 'workgroupId', 'vec3', 'attribute' ); + this.getBuiltin( 'local_invocation_id', 'localId', 'vec3', 'attribute' ); + this.getBuiltin( 'num_workgroups', 'numWorkgroups', 'vec3', 'attribute' ); + + if ( this.renderer.hasFeature( 'subgroups' ) ) { + + this.enableDirective( 'subgroups', shaderStage ); + this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' ); + + } + + } + + if ( shaderStage === 'vertex' || shaderStage === 'compute' ) { + + const builtins = this.getBuiltins( 'attribute' ); + + if ( builtins ) snippets.push( builtins ); + + const attributes = this.getAttributesArray(); + + for ( let index = 0, length = attributes.length; index < length; index ++ ) { + + const attribute = attributes[ index ]; + const name = attribute.name; + const type = this.getType( attribute.type ); + + snippets.push( `@location( ${index} ) ${ name } : ${ type }` ); + + } + + } + + return snippets.join( ',\n\t' ); + + } + + getStructMembers( struct ) { + + const snippets = []; + const members = struct.getMemberTypes(); + + for ( let i = 0; i < members.length; i ++ ) { + + const member = members[ i ]; + snippets.push( `\t@location( ${i} ) m${i} : ${ member }` ); + + } + + const builtins = this.getBuiltins( 'output' ); + + if ( builtins ) snippets.push( '\t' + builtins ); + + return snippets.join( ',\n' ); + + } + + getStructs( shaderStage ) { + + const snippets = []; + const structs = this.structs[ shaderStage ]; + + for ( let index = 0, length = structs.length; index < length; index ++ ) { + + const struct = structs[ index ]; + const name = struct.name; + + let snippet = `\struct ${ name } {\n`; + snippet += this.getStructMembers( struct ); + snippet += '\n}'; + + + snippets.push( snippet ); + + snippets.push( `\nvar output : ${ name };\n\n` ); + + } + + return snippets.join( '\n\n' ); + + } + + getVar( type, name ) { + + return `var ${ name } : ${ this.getType( type ) }`; + + } + + getVars( shaderStage ) { + + const snippets = []; + const vars = this.vars[ shaderStage ]; + + if ( vars !== undefined ) { + + for ( const variable of vars ) { + + snippets.push( `\t${ this.getVar( variable.type, variable.name ) };` ); + + } + + } + + return `\n${ snippets.join( '\n' ) }\n`; + + } + + getVaryings( shaderStage ) { + + const snippets = []; + + if ( shaderStage === 'vertex' ) { + + this.getBuiltin( 'position', 'Vertex', 'vec4', 'vertex' ); + + } + + if ( shaderStage === 'vertex' || shaderStage === 'fragment' ) { + + const varyings = this.varyings; + const vars = this.vars[ shaderStage ]; + + for ( let index = 0; index < varyings.length; index ++ ) { + + const varying = varyings[ index ]; + + if ( varying.needsInterpolation ) { + + let attributesSnippet = `@location( ${index} )`; + + if ( /^(int|uint|ivec|uvec)/.test( varying.type ) ) { + + attributesSnippet += ' @interpolate( flat )'; + + + } + + snippets.push( `${ attributesSnippet } ${ varying.name } : ${ this.getType( varying.type ) }` ); + + } else if ( shaderStage === 'vertex' && vars.includes( varying ) === false ) { + + vars.push( varying ); + + } + + } + + } + + const builtins = this.getBuiltins( shaderStage ); + + if ( builtins ) snippets.push( builtins ); + + const code = snippets.join( ',\n\t' ); + + return shaderStage === 'vertex' ? this._getWGSLStruct( 'VaryingsStruct', '\t' + code ) : code; + + } + + getUniforms( shaderStage ) { + + const uniforms = this.uniforms[ shaderStage ]; + + const bindingSnippets = []; + const bufferSnippets = []; + const structSnippets = []; + const uniformGroups = {}; + + for ( const uniform of uniforms ) { + + const groupName = uniform.groupNode.name; + const uniformIndexes = this.bindingsIndexes[ groupName ]; + + if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) { + + const texture = uniform.node.value; + + if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) { + + if ( this.isSampleCompare( texture ) ) { + + bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` ); + + } else { + + bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler;` ); + + } + + } + + let textureType; + + let multisampled = ''; + + if ( texture.isMultisampleRenderTargetTexture === true ) { + + multisampled = '_multisampled'; + + } + + if ( texture.isCubeTexture === true ) { + + textureType = 'texture_cube'; + + } else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) { + + textureType = 'texture_2d_array'; + + } else if ( texture.isDepthTexture === true ) { + + textureType = `texture_depth${multisampled}_2d`; + + } else if ( texture.isVideoTexture === true ) { + + textureType = 'texture_external'; + + } else if ( texture.isData3DTexture === true ) { + + textureType = 'texture_3d'; + + } else if ( uniform.node.isStorageTextureNode === true ) { + + const format = getFormat( texture ); + const access = this.getStorageAccess( uniform.node, shaderStage ); + + textureType = `texture_storage_2d<${ format }, ${ access }>`; + + } else { + + const componentPrefix = this.getComponentTypeFromTexture( texture ).charAt( 0 ); + + textureType = `texture${multisampled}_2d<${ componentPrefix }32>`; + + } + + bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name } : ${ textureType };` ); + + } else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' || uniform.type === 'indirectStorageBuffer' ) { + + const bufferNode = uniform.node; + const bufferType = this.getType( bufferNode.bufferType ); + const bufferCount = bufferNode.bufferCount; + + const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; + const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; + const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode, shaderStage ) }` : 'uniform'; + + bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + + } else { + + const vectorType = this.getType( this.getVectorType( uniform.type ) ); + const groupName = uniform.groupNode.name; + + const group = uniformGroups[ groupName ] || ( uniformGroups[ groupName ] = { + index: uniformIndexes.binding ++, + id: uniformIndexes.group, + snippets: [] + } ); + + group.snippets.push( `\t${ uniform.name } : ${ vectorType }` ); + + } + + } + + for ( const name in uniformGroups ) { + + const group = uniformGroups[ name ]; + + structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + + } + + let code = bindingSnippets.join( '\n' ); + code += bufferSnippets.join( '\n' ); + code += structSnippets.join( '\n' ); + + return code; + + } + + buildCode() { + + const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} }; + + this.sortBindingGroups(); + + for ( const shaderStage in shadersData ) { + + const stageData = shadersData[ shaderStage ]; + stageData.uniforms = this.getUniforms( shaderStage ); + stageData.attributes = this.getAttributes( shaderStage ); + stageData.varyings = this.getVaryings( shaderStage ); + stageData.structs = this.getStructs( shaderStage ); + stageData.vars = this.getVars( shaderStage ); + stageData.codes = this.getCodes( shaderStage ); + stageData.directives = this.getDirectives( shaderStage ); + stageData.scopedArrays = this.getScopedArrays( shaderStage ); + + // + + let flow = '// code\n\n'; + flow += this.flowCode[ shaderStage ]; + + const flowNodes = this.flowNodes[ shaderStage ]; + const mainNode = flowNodes[ flowNodes.length - 1 ]; + + const outputNode = mainNode.outputNode; + const isOutputStruct = ( outputNode !== undefined && outputNode.isOutputStructNode === true ); + + for ( const node of flowNodes ) { + + const flowSlotData = this.getFlowData( node/*, shaderStage*/ ); + const slotName = node.name; + + if ( slotName ) { + + if ( flow.length > 0 ) flow += '\n'; + + flow += `\t// flow -> ${ slotName }\n\t`; + + } + + flow += `${ flowSlotData.code }\n\t`; + + if ( node === mainNode && shaderStage !== 'compute' ) { + + flow += '// result\n\n\t'; + + if ( shaderStage === 'vertex' ) { + + flow += `varyings.Vertex = ${ flowSlotData.result };`; + + } else if ( shaderStage === 'fragment' ) { + + if ( isOutputStruct ) { + + stageData.returnType = outputNode.nodeType; + + flow += `return ${ flowSlotData.result };`; + + } else { + + let structSnippet = '\t@location(0) color: vec4'; + + const builtins = this.getBuiltins( 'output' ); + + if ( builtins ) structSnippet += ',\n\t' + builtins; + + stageData.returnType = 'OutputStruct'; + stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet ); + stageData.structs += '\nvar output : OutputStruct;\n\n'; + + flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`; + + } + + } + + } + + } + + stageData.flow = flow; + + + } + + if ( this.material !== null ) { + + this.vertexShader = this._getWGSLVertexCode( shadersData.vertex ); + this.fragmentShader = this._getWGSLFragmentCode( shadersData.fragment ); + + } else { + + this.computeShader = this._getWGSLComputeCode( shadersData.compute, ( this.object.workgroupSize || [ 64 ] ).join( ', ' ) ); + + } + + } + + getMethod( method, output = null ) { + + let wgslMethod; + + if ( output !== null ) { + + wgslMethod = this._getWGSLMethod( method + '_' + output ); + + } + + if ( wgslMethod === undefined ) { + + wgslMethod = this._getWGSLMethod( method ); + + } + + return wgslMethod || method; + + } + + getType( type ) { + + return wgslTypeLib[ type ] || type; + + } + + isAvailable( name ) { + + let result = supports[ name ]; + + if ( result === undefined ) { + + if ( name === 'float32Filterable' ) { + + result = this.renderer.hasFeature( 'float32-filterable' ); + + } else if ( name === 'clipDistance' ) { + + result = this.renderer.hasFeature( 'clip-distances' ); + + } + + supports[ name ] = result; + + } + + return result; + + } + + _getWGSLMethod( method ) { + + if ( wgslPolyfill[ method ] !== undefined ) { + + this._include( method ); + + } + + return wgslMethods[ method ]; + + } + + _include( name ) { + + const codeNode = wgslPolyfill[ name ]; + codeNode.build( this ); + + if ( this.currentFunctionNode !== null ) { + + this.currentFunctionNode.includes.push( codeNode ); + + } + + return codeNode; + + } + + _getWGSLVertexCode( shaderData ) { + + return `${ this.getSignature() } +// directives +${shaderData.directives} + +// uniforms +${shaderData.uniforms} + +// varyings +${shaderData.varyings} +var varyings : VaryingsStruct; + +// codes +${shaderData.codes} + +@vertex +fn main( ${shaderData.attributes} ) -> VaryingsStruct { + + // vars + ${shaderData.vars} + + // flow + ${shaderData.flow} + + return varyings; + +} +`; + + } + + _getWGSLFragmentCode( shaderData ) { + + return `${ this.getSignature() } +// global +${ diagnostics } + +// uniforms +${shaderData.uniforms} + +// structs +${shaderData.structs} + +// codes +${shaderData.codes} + +@fragment +fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} { + + // vars + ${shaderData.vars} + + // flow + ${shaderData.flow} + +} +`; + + } + + _getWGSLComputeCode( shaderData, workgroupSize ) { + + return `${ this.getSignature() } +// directives +${shaderData.directives} + +// system +var instanceIndex : u32; + +// locals +${shaderData.scopedArrays} + +// uniforms +${shaderData.uniforms} + +// codes +${shaderData.codes} + +@compute @workgroup_size( ${workgroupSize} ) +fn main( ${shaderData.attributes} ) { + + // system + instanceIndex = id.x + id.y * numWorkgroups.x * u32(${workgroupSize}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${workgroupSize}); + + // vars + ${shaderData.vars} + + // flow + ${shaderData.flow} + +} +`; + + } + + _getWGSLStruct( name, vars ) { + + return ` +struct ${name} { +${vars} +};`; + + } + + _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) { + + const structName = name + 'Struct'; + const structSnippet = this._getWGSLStruct( structName, vars ); + + return `${structSnippet} +@binding( ${binding} ) @group( ${group} ) +var<${access}> ${name} : ${structName};`; + + } + +} + +class WebGPUUtils { + + constructor( backend ) { + + this.backend = backend; + + } + + getCurrentDepthStencilFormat( renderContext ) { + + let format; + + if ( renderContext.depthTexture !== null ) { + + format = this.getTextureFormatGPU( renderContext.depthTexture ); + + } else if ( renderContext.depth && renderContext.stencil ) { + + format = GPUTextureFormat.Depth24PlusStencil8; + + } else if ( renderContext.depth ) { + + format = GPUTextureFormat.Depth24Plus; + + } + + return format; + + } + + getTextureFormatGPU( texture ) { + + return this.backend.get( texture ).format; + + } + + getCurrentColorFormat( renderContext ) { + + let format; + + if ( renderContext.textures !== null ) { + + format = this.getTextureFormatGPU( renderContext.textures[ 0 ] ); + + } else { + + format = this.getPreferredCanvasFormat(); // default context format + + } + + return format; + + } + + getCurrentColorSpace( renderContext ) { + + if ( renderContext.textures !== null ) { + + return renderContext.textures[ 0 ].colorSpace; + + } + + return this.backend.renderer.outputColorSpace; + + } + + getPrimitiveTopology( object, material ) { + + if ( object.isPoints ) return GPUPrimitiveTopology.PointList; + else if ( object.isLineSegments || ( object.isMesh && material.wireframe === true ) ) return GPUPrimitiveTopology.LineList; + else if ( object.isLine ) return GPUPrimitiveTopology.LineStrip; + else if ( object.isMesh ) return GPUPrimitiveTopology.TriangleList; + + } + + getSampleCount( sampleCount ) { + + let count = 1; + + if ( sampleCount > 1 ) { + + // WebGPU only supports power-of-two sample counts and 2 is not a valid value + count = Math.pow( 2, Math.floor( Math.log2( sampleCount ) ) ); + + if ( count === 2 ) { + + count = 4; + + } + + } + + return count; + + } + + getSampleCountRenderContext( renderContext ) { + + if ( renderContext.textures !== null ) { + + return this.getSampleCount( renderContext.sampleCount ); + + } + + return this.getSampleCount( this.backend.renderer.samples ); + + } + + getPreferredCanvasFormat() { + + // TODO: Remove this check when Quest 34.5 is out + // https://github.com/mrdoob/three.js/pull/29221/files#r1731833949 + + if ( navigator.userAgent.includes( 'Quest' ) ) { + + return GPUTextureFormat.BGRA8Unorm; + + } else { + + return navigator.gpu.getPreferredCanvasFormat(); + + } + + } + +} + +const typedArraysToVertexFormatPrefix = new Map( [ + [ Int8Array, [ 'sint8', 'snorm8' ]], + [ Uint8Array, [ 'uint8', 'unorm8' ]], + [ Int16Array, [ 'sint16', 'snorm16' ]], + [ Uint16Array, [ 'uint16', 'unorm16' ]], + [ Int32Array, [ 'sint32', 'snorm32' ]], + [ Uint32Array, [ 'uint32', 'unorm32' ]], + [ Float32Array, [ 'float32', ]], +] ); + +const typedAttributeToVertexFormatPrefix = new Map( [ + [ Float16BufferAttribute, [ 'float16', ]], +] ); + +const typeArraysToVertexFormatPrefixForItemSize1 = new Map( [ + [ Int32Array, 'sint32' ], + [ Int16Array, 'sint32' ], // patch for INT16 + [ Uint32Array, 'uint32' ], + [ Uint16Array, 'uint32' ], // patch for UINT16 + [ Float32Array, 'float32' ] +] ); + +class WebGPUAttributeUtils { + + constructor( backend ) { + + this.backend = backend; + + } + + createAttribute( attribute, usage ) { + + const bufferAttribute = this._getBufferAttribute( attribute ); + + const backend = this.backend; + const bufferData = backend.get( bufferAttribute ); + + let buffer = bufferData.buffer; + + if ( buffer === undefined ) { + + const device = backend.device; + + let array = bufferAttribute.array; + + // patch for INT16 and UINT16 + if ( attribute.normalized === false && ( array.constructor === Int16Array || array.constructor === Uint16Array ) ) { + + const tempArray = new Uint32Array( array.length ); + for ( let i = 0; i < array.length; i ++ ) { + + tempArray[ i ] = array[ i ]; + + } + + array = tempArray; + + } + + bufferAttribute.array = array; + + if ( ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) && bufferAttribute.itemSize === 3 ) { + + array = new array.constructor( bufferAttribute.count * 4 ); + + for ( let i = 0; i < bufferAttribute.count; i ++ ) { + + array.set( bufferAttribute.array.subarray( i * 3, i * 3 + 3 ), i * 4 ); + + } + + // Update BufferAttribute + bufferAttribute.itemSize = 4; + bufferAttribute.array = array; + + } + + const size = array.byteLength + ( ( 4 - ( array.byteLength % 4 ) ) % 4 ); // ensure 4 byte alignment, see #20441 + + buffer = device.createBuffer( { + label: bufferAttribute.name, + size: size, + usage: usage, + mappedAtCreation: true + } ); + + new array.constructor( buffer.getMappedRange() ).set( array ); + + buffer.unmap(); + + bufferData.buffer = buffer; + + } + + } + + updateAttribute( attribute ) { + + const bufferAttribute = this._getBufferAttribute( attribute ); + + const backend = this.backend; + const device = backend.device; + + const buffer = backend.get( bufferAttribute ).buffer; + + const array = bufferAttribute.array; + const isTypedArray = this._isTypedArray( array ); + const updateRanges = bufferAttribute.updateRanges; + + if ( updateRanges.length === 0 ) { + + // Not using update ranges + + device.queue.writeBuffer( + buffer, + 0, + array, + 0 + ); + + } else { + + const byteOffsetFactor = isTypedArray ? 1 : array.BYTES_PER_ELEMENT; + + for ( let i = 0, l = updateRanges.length; i < l; i ++ ) { + + const range = updateRanges[ i ]; + + const dataOffset = range.start * byteOffsetFactor; + const size = range.count * byteOffsetFactor; + + device.queue.writeBuffer( + buffer, + 0, + array, + dataOffset, + size + ); + + } + + bufferAttribute.clearUpdateRanges(); + + } + + } + + createShaderVertexBuffers( renderObject ) { + + const attributes = renderObject.getAttributes(); + const vertexBuffers = new Map(); + + for ( let slot = 0; slot < attributes.length; slot ++ ) { + + const geometryAttribute = attributes[ slot ]; + const bytesPerElement = geometryAttribute.array.BYTES_PER_ELEMENT; + const bufferAttribute = this._getBufferAttribute( geometryAttribute ); + + let vertexBufferLayout = vertexBuffers.get( bufferAttribute ); + + if ( vertexBufferLayout === undefined ) { + + let arrayStride, stepMode; + + if ( geometryAttribute.isInterleavedBufferAttribute === true ) { + + arrayStride = geometryAttribute.data.stride * bytesPerElement; + stepMode = geometryAttribute.data.isInstancedInterleavedBuffer ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex; + + } else { + + arrayStride = geometryAttribute.itemSize * bytesPerElement; + stepMode = geometryAttribute.isInstancedBufferAttribute ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex; + + } + + // patch for INT16 and UINT16 + if ( geometryAttribute.normalized === false && ( geometryAttribute.array.constructor === Int16Array || geometryAttribute.array.constructor === Uint16Array ) ) { + + arrayStride = 4; + + } + + vertexBufferLayout = { + arrayStride, + attributes: [], + stepMode + }; + + vertexBuffers.set( bufferAttribute, vertexBufferLayout ); + + } + + const format = this._getVertexFormat( geometryAttribute ); + const offset = ( geometryAttribute.isInterleavedBufferAttribute === true ) ? geometryAttribute.offset * bytesPerElement : 0; + + vertexBufferLayout.attributes.push( { + shaderLocation: slot, + offset, + format + } ); + + } + + return Array.from( vertexBuffers.values() ); + + } + + destroyAttribute( attribute ) { + + const backend = this.backend; + const data = backend.get( this._getBufferAttribute( attribute ) ); + + data.buffer.destroy(); + + backend.delete( attribute ); + + } + + async getArrayBufferAsync( attribute ) { + + const backend = this.backend; + const device = backend.device; + + const data = backend.get( this._getBufferAttribute( attribute ) ); + + const bufferGPU = data.buffer; + const size = bufferGPU.size; + + const readBufferGPU = device.createBuffer( { + label: attribute.name, + size, + usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ + } ); + + + const cmdEncoder = device.createCommandEncoder( {} ); + + cmdEncoder.copyBufferToBuffer( + bufferGPU, + 0, + readBufferGPU, + 0, + size + ); + + readBufferGPU.unmap(); + + const gpuCommands = cmdEncoder.finish(); + device.queue.submit( [ gpuCommands ] ); + + await readBufferGPU.mapAsync( GPUMapMode.READ ); + + const arrayBuffer = readBufferGPU.getMappedRange(); + + return arrayBuffer; + + } + + _getVertexFormat( geometryAttribute ) { + + const { itemSize, normalized } = geometryAttribute; + const ArrayType = geometryAttribute.array.constructor; + const AttributeType = geometryAttribute.constructor; + + let format; + + if ( itemSize == 1 ) { + + format = typeArraysToVertexFormatPrefixForItemSize1.get( ArrayType ); + + } else { + + const prefixOptions = typedAttributeToVertexFormatPrefix.get( AttributeType ) || typedArraysToVertexFormatPrefix.get( ArrayType ); + const prefix = prefixOptions[ normalized ? 1 : 0 ]; + + if ( prefix ) { + + const bytesPerUnit = ArrayType.BYTES_PER_ELEMENT * itemSize; + const paddedBytesPerUnit = Math.floor( ( bytesPerUnit + 3 ) / 4 ) * 4; + const paddedItemSize = paddedBytesPerUnit / ArrayType.BYTES_PER_ELEMENT; + + if ( paddedItemSize % 1 ) { + + throw new Error( 'THREE.WebGPUAttributeUtils: Bad vertex format item size.' ); + + } + + format = `${prefix}x${paddedItemSize}`; + + } + + } + + if ( ! format ) { + + console.error( 'THREE.WebGPUAttributeUtils: Vertex format not supported yet.' ); + + } + + return format; + + } + + _isTypedArray( array ) { + + return ArrayBuffer.isView( array ) && ! ( array instanceof DataView ); + + } + + _getBufferAttribute( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data; + + return attribute; + + } + +} + +class WebGPUBindingUtils { + + constructor( backend ) { + + this.backend = backend; + this.bindGroupLayoutCache = new WeakMap(); + + } + + createBindingsLayout( bindGroup ) { + + const backend = this.backend; + const device = backend.device; + + const entries = []; + + let index = 0; + + for ( const binding of bindGroup.bindings ) { + + const bindingGPU = { + binding: index ++, + visibility: binding.visibility + }; + + if ( binding.isUniformBuffer || binding.isStorageBuffer ) { + + const buffer = {}; // GPUBufferBindingLayout + + if ( binding.isStorageBuffer ) { + + if ( binding.visibility & 4 ) { + + // compute + + if ( binding.access === NodeAccess.READ_WRITE || binding.access === NodeAccess.WRITE_ONLY ) { + + buffer.type = GPUBufferBindingType.Storage; + + } else { + + buffer.type = GPUBufferBindingType.ReadOnlyStorage; + + } + + } else { + + buffer.type = GPUBufferBindingType.ReadOnlyStorage; + + } + + } + + bindingGPU.buffer = buffer; + + } else if ( binding.isSampler ) { + + const sampler = {}; // GPUSamplerBindingLayout + + if ( binding.texture.isDepthTexture ) { + + if ( binding.texture.compareFunction !== null ) { + + sampler.type = 'comparison'; + + } + + } + + bindingGPU.sampler = sampler; + + } else if ( binding.isSampledTexture && binding.texture.isVideoTexture ) { + + bindingGPU.externalTexture = {}; // GPUExternalTextureBindingLayout + + } else if ( binding.isSampledTexture && binding.store ) { + + const storageTexture = {}; // GPUStorageTextureBindingLayout + storageTexture.format = this.backend.get( binding.texture ).texture.format; + + const access = binding.access; + + if ( access === NodeAccess.READ_WRITE ) { + + storageTexture.access = GPUStorageTextureAccess.ReadWrite; + + } else if ( access === NodeAccess.WRITE_ONLY ) { + + storageTexture.access = GPUStorageTextureAccess.WriteOnly; + + } else { + + storageTexture.access = GPUStorageTextureAccess.ReadOnly; + + } + + bindingGPU.storageTexture = storageTexture; + + } else if ( binding.isSampledTexture ) { + + const texture = {}; // GPUTextureBindingLayout + + if ( binding.texture.isMultisampleRenderTargetTexture === true ) { + + texture.multisampled = true; + + } + + if ( binding.texture.isDepthTexture ) { + + texture.sampleType = GPUTextureSampleType.Depth; + + } else if ( binding.texture.isDataTexture || binding.texture.isDataArrayTexture || binding.texture.isData3DTexture ) { + + const type = binding.texture.type; + + if ( type === IntType ) { + + texture.sampleType = GPUTextureSampleType.SInt; + + } else if ( type === UnsignedIntType ) { + + texture.sampleType = GPUTextureSampleType.UInt; + + } else if ( type === FloatType ) { + + if ( this.backend.hasFeature( 'float32-filterable' ) ) { + + texture.sampleType = GPUTextureSampleType.Float; + + } else { + + texture.sampleType = GPUTextureSampleType.UnfilterableFloat; + + } + + } + + } + + if ( binding.isSampledCubeTexture ) { + + texture.viewDimension = GPUTextureViewDimension.Cube; + + } else if ( binding.texture.isDataArrayTexture || binding.texture.isCompressedArrayTexture ) { + + texture.viewDimension = GPUTextureViewDimension.TwoDArray; + + } else if ( binding.isSampledTexture3D ) { + + texture.viewDimension = GPUTextureViewDimension.ThreeD; + + } + + bindingGPU.texture = texture; + + } else { + + console.error( `WebGPUBindingUtils: Unsupported binding "${ binding }".` ); + + } + + entries.push( bindingGPU ); + + } + + return device.createBindGroupLayout( { entries } ); + + } + + createBindings( bindGroup, bindings, cacheIndex, version = 0 ) { + + const { backend, bindGroupLayoutCache } = this; + const bindingsData = backend.get( bindGroup ); + + // setup (static) binding layout and (dynamic) binding group + + let bindLayoutGPU = bindGroupLayoutCache.get( bindGroup.bindingsReference ); + + if ( bindLayoutGPU === undefined ) { + + bindLayoutGPU = this.createBindingsLayout( bindGroup ); + bindGroupLayoutCache.set( bindGroup.bindingsReference, bindLayoutGPU ); + + } + + let bindGroupGPU; + + if ( cacheIndex > 0 ) { + + if ( bindingsData.groups === undefined ) { + + bindingsData.groups = []; + bindingsData.versions = []; + + } + + if ( bindingsData.versions[ cacheIndex ] === version ) { + + bindGroupGPU = bindingsData.groups[ cacheIndex ]; + + } + + } + + if ( bindGroupGPU === undefined ) { + + bindGroupGPU = this.createBindGroup( bindGroup, bindLayoutGPU ); + + if ( cacheIndex > 0 ) { + + bindingsData.groups[ cacheIndex ] = bindGroupGPU; + bindingsData.versions[ cacheIndex ] = version; + + } + + } + + bindingsData.group = bindGroupGPU; + bindingsData.layout = bindLayoutGPU; + + } + + updateBinding( binding ) { + + const backend = this.backend; + const device = backend.device; + + const buffer = binding.buffer; + const bufferGPU = backend.get( binding ).buffer; + + device.queue.writeBuffer( bufferGPU, 0, buffer, 0 ); + + } + + createBindGroup( bindGroup, layoutGPU ) { + + const backend = this.backend; + const device = backend.device; + + let bindingPoint = 0; + const entriesGPU = []; + + for ( const binding of bindGroup.bindings ) { + + if ( binding.isUniformBuffer ) { + + const bindingData = backend.get( binding ); + + if ( bindingData.buffer === undefined ) { + + const byteLength = binding.byteLength; + + const usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST; + + const bufferGPU = device.createBuffer( { + label: 'bindingBuffer_' + binding.name, + size: byteLength, + usage: usage + } ); + + bindingData.buffer = bufferGPU; + + } + + entriesGPU.push( { binding: bindingPoint, resource: { buffer: bindingData.buffer } } ); + + } else if ( binding.isStorageBuffer ) { + + const bindingData = backend.get( binding ); + + if ( bindingData.buffer === undefined ) { + + const attribute = binding.attribute; + //const usage = GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | /*GPUBufferUsage.COPY_SRC |*/ GPUBufferUsage.COPY_DST; + + //backend.attributeUtils.createAttribute( attribute, usage ); // @TODO: Move it to universal renderer + + bindingData.buffer = backend.get( attribute ).buffer; + + } + + entriesGPU.push( { binding: bindingPoint, resource: { buffer: bindingData.buffer } } ); + + } else if ( binding.isSampler ) { + + const textureGPU = backend.get( binding.texture ); + + entriesGPU.push( { binding: bindingPoint, resource: textureGPU.sampler } ); + + } else if ( binding.isSampledTexture ) { + + const textureData = backend.get( binding.texture ); + + let resourceGPU; + + if ( textureData.externalTexture !== undefined ) { + + resourceGPU = device.importExternalTexture( { source: textureData.externalTexture } ); + + } else { + + const mipLevelCount = binding.store ? 1 : textureData.texture.mipLevelCount; + const propertyName = `view-${ textureData.texture.width }-${ textureData.texture.height }-${ mipLevelCount }`; + + resourceGPU = textureData[ propertyName ]; + + if ( resourceGPU === undefined ) { + + const aspectGPU = GPUTextureAspect.All; + + let dimensionViewGPU; + + if ( binding.isSampledCubeTexture ) { + + dimensionViewGPU = GPUTextureViewDimension.Cube; + + } else if ( binding.isSampledTexture3D ) { + + dimensionViewGPU = GPUTextureViewDimension.ThreeD; + + } else if ( binding.texture.isDataArrayTexture || binding.texture.isCompressedArrayTexture ) { + + dimensionViewGPU = GPUTextureViewDimension.TwoDArray; + + } else { + + dimensionViewGPU = GPUTextureViewDimension.TwoD; + + } + + resourceGPU = textureData[ propertyName ] = textureData.texture.createView( { aspect: aspectGPU, dimension: dimensionViewGPU, mipLevelCount } ); + + } + + } + + entriesGPU.push( { binding: bindingPoint, resource: resourceGPU } ); + + } + + bindingPoint ++; + + } + + return device.createBindGroup( { + label: 'bindGroup_' + bindGroup.name, + layout: layoutGPU, + entries: entriesGPU + } ); + + } + +} + +class WebGPUPipelineUtils { + + constructor( backend ) { + + this.backend = backend; + + } + + _getSampleCount( renderObjectContext ) { + + return this.backend.utils.getSampleCountRenderContext( renderObjectContext ); + + } + + createRenderPipeline( renderObject, promises ) { + + const { object, material, geometry, pipeline } = renderObject; + const { vertexProgram, fragmentProgram } = pipeline; + + const backend = this.backend; + const device = backend.device; + const utils = backend.utils; + + const pipelineData = backend.get( pipeline ); + + // bind group layouts + + const bindGroupLayouts = []; + + for ( const bindGroup of renderObject.getBindings() ) { + + const bindingsData = backend.get( bindGroup ); + + bindGroupLayouts.push( bindingsData.layout ); + + } + + // vertex buffers + + const vertexBuffers = backend.attributeUtils.createShaderVertexBuffers( renderObject ); + + // blending + + let blending; + + if ( material.transparent === true && material.blending !== NoBlending ) { + + blending = this._getBlending( material ); + + } + + // stencil + + let stencilFront = {}; + + if ( material.stencilWrite === true ) { + + stencilFront = { + compare: this._getStencilCompare( material ), + failOp: this._getStencilOperation( material.stencilFail ), + depthFailOp: this._getStencilOperation( material.stencilZFail ), + passOp: this._getStencilOperation( material.stencilZPass ) + }; + + } + + const colorWriteMask = this._getColorWriteMask( material ); + + const targets = []; + + if ( renderObject.context.textures !== null ) { + + const textures = renderObject.context.textures; + + for ( let i = 0; i < textures.length; i ++ ) { + + const colorFormat = utils.getTextureFormatGPU( textures[ i ] ); + + targets.push( { + format: colorFormat, + blend: blending, + writeMask: colorWriteMask + } ); + + } + + } else { + + const colorFormat = utils.getCurrentColorFormat( renderObject.context ); + + targets.push( { + format: colorFormat, + blend: blending, + writeMask: colorWriteMask + } ); + + } + + const vertexModule = backend.get( vertexProgram ).module; + const fragmentModule = backend.get( fragmentProgram ).module; + + const primitiveState = this._getPrimitiveState( object, geometry, material ); + const depthCompare = this._getDepthCompare( material ); + const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderObject.context ); + + const sampleCount = this._getSampleCount( renderObject.context ); + + const pipelineDescriptor = { + label: `renderPipeline_${ material.name || material.type }_${ material.id }`, + vertex: Object.assign( {}, vertexModule, { buffers: vertexBuffers } ), + fragment: Object.assign( {}, fragmentModule, { targets } ), + primitive: primitiveState, + multisample: { + count: sampleCount, + alphaToCoverageEnabled: material.alphaToCoverage && sampleCount > 1 + }, + layout: device.createPipelineLayout( { + bindGroupLayouts + } ) + }; + + + const depthStencil = {}; + const renderDepth = renderObject.context.depth; + const renderStencil = renderObject.context.stencil; + + if ( renderDepth === true || renderStencil === true ) { + + if ( renderDepth === true ) { + + depthStencil.format = depthStencilFormat; + depthStencil.depthWriteEnabled = material.depthWrite; + depthStencil.depthCompare = depthCompare; + + } + + if ( renderStencil === true ) { + + depthStencil.stencilFront = stencilFront; + depthStencil.stencilBack = {}; // three.js does not provide an API to configure the back function (gl.stencilFuncSeparate() was never used) + depthStencil.stencilReadMask = material.stencilFuncMask; + depthStencil.stencilWriteMask = material.stencilWriteMask; + + } + + pipelineDescriptor.depthStencil = depthStencil; + + } + + + if ( promises === null ) { + + pipelineData.pipeline = device.createRenderPipeline( pipelineDescriptor ); + + } else { + + const p = new Promise( ( resolve /*, reject*/ ) => { + + device.createRenderPipelineAsync( pipelineDescriptor ).then( pipeline => { + + pipelineData.pipeline = pipeline; + resolve(); + + } ); + + } ); + + promises.push( p ); + + } + + } + + createBundleEncoder( renderContext ) { + + const backend = this.backend; + const { utils, device } = backend; + + const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderContext ); + const colorFormat = utils.getCurrentColorFormat( renderContext ); + const sampleCount = this._getSampleCount( renderContext ); + + const descriptor = { + label: 'renderBundleEncoder', + colorFormats: [ colorFormat ], + depthStencilFormat, + sampleCount + }; + + return device.createRenderBundleEncoder( descriptor ); + + } + + createComputePipeline( pipeline, bindings ) { + + const backend = this.backend; + const device = backend.device; + + const computeProgram = backend.get( pipeline.computeProgram ).module; + + const pipelineGPU = backend.get( pipeline ); + + // bind group layouts + + const bindGroupLayouts = []; + + for ( const bindingsGroup of bindings ) { + + const bindingsData = backend.get( bindingsGroup ); + + bindGroupLayouts.push( bindingsData.layout ); + + } + + pipelineGPU.pipeline = device.createComputePipeline( { + compute: computeProgram, + layout: device.createPipelineLayout( { + bindGroupLayouts + } ) + } ); + + } + + _getBlending( material ) { + + let color, alpha; + + const blending = material.blending; + const blendSrc = material.blendSrc; + const blendDst = material.blendDst; + const blendEquation = material.blendEquation; + + + if ( blending === CustomBlending ) { + + const blendSrcAlpha = material.blendSrcAlpha !== null ? material.blendSrcAlpha : blendSrc; + const blendDstAlpha = material.blendDstAlpha !== null ? material.blendDstAlpha : blendDst; + const blendEquationAlpha = material.blendEquationAlpha !== null ? material.blendEquationAlpha : blendEquation; + + color = { + srcFactor: this._getBlendFactor( blendSrc ), + dstFactor: this._getBlendFactor( blendDst ), + operation: this._getBlendOperation( blendEquation ) + }; + + alpha = { + srcFactor: this._getBlendFactor( blendSrcAlpha ), + dstFactor: this._getBlendFactor( blendDstAlpha ), + operation: this._getBlendOperation( blendEquationAlpha ) + }; + + } else { + + const premultipliedAlpha = material.premultipliedAlpha; + + const setBlend = ( srcRGB, dstRGB, srcAlpha, dstAlpha ) => { + + color = { + srcFactor: srcRGB, + dstFactor: dstRGB, + operation: GPUBlendOperation.Add + }; + + alpha = { + srcFactor: srcAlpha, + dstFactor: dstAlpha, + operation: GPUBlendOperation.Add + }; + + }; + + if ( premultipliedAlpha ) { + + switch ( blending ) { + + case NormalBlending: + setBlend( GPUBlendFactor.One, GPUBlendFactor.OneMinusSrcAlpha, GPUBlendFactor.One, GPUBlendFactor.OneMinusSrcAlpha ); + break; + + case AdditiveBlending: + setBlend( GPUBlendFactor.One, GPUBlendFactor.One, GPUBlendFactor.One, GPUBlendFactor.One ); + break; + + case SubtractiveBlending: + setBlend( GPUBlendFactor.Zero, GPUBlendFactor.OneMinusSrc, GPUBlendFactor.Zero, GPUBlendFactor.One ); + break; + + case MultiplyBlending: + setBlend( GPUBlendFactor.Zero, GPUBlendFactor.Src, GPUBlendFactor.Zero, GPUBlendFactor.SrcAlpha ); + break; + + } + + } else { + + switch ( blending ) { + + case NormalBlending: + setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.OneMinusSrcAlpha, GPUBlendFactor.One, GPUBlendFactor.OneMinusSrcAlpha ); + break; + + case AdditiveBlending: + setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.One, GPUBlendFactor.SrcAlpha, GPUBlendFactor.One ); + break; + + case SubtractiveBlending: + setBlend( GPUBlendFactor.Zero, GPUBlendFactor.OneMinusSrc, GPUBlendFactor.Zero, GPUBlendFactor.One ); + break; + + case MultiplyBlending: + setBlend( GPUBlendFactor.Zero, GPUBlendFactor.Src, GPUBlendFactor.Zero, GPUBlendFactor.Src ); + break; + + } + + } + + } + + if ( color !== undefined && alpha !== undefined ) { + + return { color, alpha }; + + } else { + + console.error( 'THREE.WebGPURenderer: Invalid blending: ', blending ); + + } + + } + + _getBlendFactor( blend ) { + + let blendFactor; + + switch ( blend ) { + + case ZeroFactor: + blendFactor = GPUBlendFactor.Zero; + break; + + case OneFactor: + blendFactor = GPUBlendFactor.One; + break; + + case SrcColorFactor: + blendFactor = GPUBlendFactor.Src; + break; + + case OneMinusSrcColorFactor: + blendFactor = GPUBlendFactor.OneMinusSrc; + break; + + case SrcAlphaFactor: + blendFactor = GPUBlendFactor.SrcAlpha; + break; + + case OneMinusSrcAlphaFactor: + blendFactor = GPUBlendFactor.OneMinusSrcAlpha; + break; + + case DstColorFactor: + blendFactor = GPUBlendFactor.Dst; + break; + + case OneMinusDstColorFactor: + blendFactor = GPUBlendFactor.OneMinusDstColor; + break; + + case DstAlphaFactor: + blendFactor = GPUBlendFactor.DstAlpha; + break; + + case OneMinusDstAlphaFactor: + blendFactor = GPUBlendFactor.OneMinusDstAlpha; + break; + + case SrcAlphaSaturateFactor: + blendFactor = GPUBlendFactor.SrcAlphaSaturated; + break; + + case BlendColorFactor: + blendFactor = GPUBlendFactor.Constant; + break; + + case OneMinusBlendColorFactor: + blendFactor = GPUBlendFactor.OneMinusConstant; + break; + + default: + console.error( 'THREE.WebGPURenderer: Blend factor not supported.', blend ); + + } + + return blendFactor; + + } + + _getStencilCompare( material ) { + + let stencilCompare; + + const stencilFunc = material.stencilFunc; + + switch ( stencilFunc ) { + + case NeverStencilFunc: + stencilCompare = GPUCompareFunction.Never; + break; + + case AlwaysStencilFunc: + stencilCompare = GPUCompareFunction.Always; + break; + + case LessStencilFunc: + stencilCompare = GPUCompareFunction.Less; + break; + + case LessEqualStencilFunc: + stencilCompare = GPUCompareFunction.LessEqual; + break; + + case EqualStencilFunc: + stencilCompare = GPUCompareFunction.Equal; + break; + + case GreaterEqualStencilFunc: + stencilCompare = GPUCompareFunction.GreaterEqual; + break; + + case GreaterStencilFunc: + stencilCompare = GPUCompareFunction.Greater; + break; + + case NotEqualStencilFunc: + stencilCompare = GPUCompareFunction.NotEqual; + break; + + default: + console.error( 'THREE.WebGPURenderer: Invalid stencil function.', stencilFunc ); + + } + + return stencilCompare; + + } + + _getStencilOperation( op ) { + + let stencilOperation; + + switch ( op ) { + + case KeepStencilOp: + stencilOperation = GPUStencilOperation.Keep; + break; + + case ZeroStencilOp: + stencilOperation = GPUStencilOperation.Zero; + break; + + case ReplaceStencilOp: + stencilOperation = GPUStencilOperation.Replace; + break; + + case InvertStencilOp: + stencilOperation = GPUStencilOperation.Invert; + break; + + case IncrementStencilOp: + stencilOperation = GPUStencilOperation.IncrementClamp; + break; + + case DecrementStencilOp: + stencilOperation = GPUStencilOperation.DecrementClamp; + break; + + case IncrementWrapStencilOp: + stencilOperation = GPUStencilOperation.IncrementWrap; + break; + + case DecrementWrapStencilOp: + stencilOperation = GPUStencilOperation.DecrementWrap; + break; + + default: + console.error( 'THREE.WebGPURenderer: Invalid stencil operation.', stencilOperation ); + + } + + return stencilOperation; + + } + + _getBlendOperation( blendEquation ) { + + let blendOperation; + + switch ( blendEquation ) { + + case AddEquation: + blendOperation = GPUBlendOperation.Add; + break; + + case SubtractEquation: + blendOperation = GPUBlendOperation.Subtract; + break; + + case ReverseSubtractEquation: + blendOperation = GPUBlendOperation.ReverseSubtract; + break; + + case MinEquation: + blendOperation = GPUBlendOperation.Min; + break; + + case MaxEquation: + blendOperation = GPUBlendOperation.Max; + break; + + default: + console.error( 'THREE.WebGPUPipelineUtils: Blend equation not supported.', blendEquation ); + + } + + return blendOperation; + + } + + _getPrimitiveState( object, geometry, material ) { + + const descriptor = {}; + const utils = this.backend.utils; + + descriptor.topology = utils.getPrimitiveTopology( object, material ); + + if ( geometry.index !== null && object.isLine === true && object.isLineSegments !== true ) { + + descriptor.stripIndexFormat = ( geometry.index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32; + + } + + switch ( material.side ) { + + case FrontSide: + descriptor.frontFace = GPUFrontFace.CCW; + descriptor.cullMode = GPUCullMode.Back; + break; + + case BackSide: + descriptor.frontFace = GPUFrontFace.CCW; + descriptor.cullMode = GPUCullMode.Front; + break; + + case DoubleSide: + descriptor.frontFace = GPUFrontFace.CCW; + descriptor.cullMode = GPUCullMode.None; + break; + + default: + console.error( 'THREE.WebGPUPipelineUtils: Unknown material.side value.', material.side ); + break; + + } + + return descriptor; + + } + + _getColorWriteMask( material ) { + + return ( material.colorWrite === true ) ? GPUColorWriteFlags.All : GPUColorWriteFlags.None; + + } + + _getDepthCompare( material ) { + + let depthCompare; + + if ( material.depthTest === false ) { + + depthCompare = GPUCompareFunction.Always; + + } else { + + const depthFunc = material.depthFunc; + + switch ( depthFunc ) { + + case NeverDepth: + depthCompare = GPUCompareFunction.Never; + break; + + case AlwaysDepth: + depthCompare = GPUCompareFunction.Always; + break; + + case LessDepth: + depthCompare = GPUCompareFunction.Less; + break; + + case LessEqualDepth: + depthCompare = GPUCompareFunction.LessEqual; + break; + + case EqualDepth: + depthCompare = GPUCompareFunction.Equal; + break; + + case GreaterEqualDepth: + depthCompare = GPUCompareFunction.GreaterEqual; + break; + + case GreaterDepth: + depthCompare = GPUCompareFunction.Greater; + break; + + case NotEqualDepth: + depthCompare = GPUCompareFunction.NotEqual; + break; + + default: + console.error( 'THREE.WebGPUPipelineUtils: Invalid depth function.', depthFunc ); + + } + + } + + return depthCompare; + + } + +} + +/*// debugger tools +import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js'; +//*/ + + +// + +class WebGPUBackend extends Backend { + + constructor( parameters = {} ) { + + super( parameters ); + + this.isWebGPUBackend = true; + + // some parameters require default values other than "undefined" + this.parameters.alpha = ( parameters.alpha === undefined ) ? true : parameters.alpha; + + this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits; + + this.trackTimestamp = ( parameters.trackTimestamp === true ); + + this.device = null; + this.context = null; + this.colorBuffer = null; + this.defaultRenderPassdescriptor = null; + + this.utils = new WebGPUUtils( this ); + this.attributeUtils = new WebGPUAttributeUtils( this ); + this.bindingUtils = new WebGPUBindingUtils( this ); + this.pipelineUtils = new WebGPUPipelineUtils( this ); + this.textureUtils = new WebGPUTextureUtils( this ); + this.occludedResolveCache = new Map(); + + } + + async init( renderer ) { + + await super.init( renderer ); + + // + + const parameters = this.parameters; + + // create the device if it is not passed with parameters + + let device; + + if ( parameters.device === undefined ) { + + const adapterOptions = { + powerPreference: parameters.powerPreference + }; + + const adapter = ( typeof navigator !== 'undefined' ) ? await navigator.gpu.requestAdapter( adapterOptions ) : null; + + if ( adapter === null ) { + + throw new Error( 'WebGPUBackend: Unable to create WebGPU adapter.' ); + + } + + // feature support + + const features = Object.values( GPUFeatureName ); + + const supportedFeatures = []; + + for ( const name of features ) { + + if ( adapter.features.has( name ) ) { + + supportedFeatures.push( name ); + + } + + } + + const deviceDescriptor = { + requiredFeatures: supportedFeatures, + requiredLimits: parameters.requiredLimits + }; + + device = await adapter.requestDevice( deviceDescriptor ); + + } else { + + device = parameters.device; + + } + + device.lost.then( ( info ) => { + + const deviceLossInfo = { + api: 'WebGPU', + message: info.message || 'Unknown reason', + reason: info.reason || null, + originalEvent: info + }; + + renderer.onDeviceLost( deviceLossInfo ); + + } ); + + const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' ); + + this.device = device; + this.context = context; + + const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque'; + + this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery ); + + this.context.configure( { + device: this.device, + format: this.utils.getPreferredCanvasFormat(), + usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC, + alphaMode: alphaMode + } ); + + this.updateSize(); + + } + + get coordinateSystem() { + + return WebGPUCoordinateSystem; + + } + + async getArrayBufferAsync( attribute ) { + + return await this.attributeUtils.getArrayBufferAsync( attribute ); + + } + + getContext() { + + return this.context; + + } + + _getDefaultRenderPassDescriptor() { + + let descriptor = this.defaultRenderPassdescriptor; + + if ( descriptor === null ) { + + const renderer = this.renderer; + + descriptor = { + colorAttachments: [ { + view: null + } ], + }; + + if ( this.renderer.depth === true || this.renderer.stencil === true ) { + + descriptor.depthStencilAttachment = { + view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView() + }; + + } + + const colorAttachment = descriptor.colorAttachments[ 0 ]; + + if ( this.renderer.samples > 0 ) { + + colorAttachment.view = this.colorBuffer.createView(); + + } else { + + colorAttachment.resolveTarget = undefined; + + } + + this.defaultRenderPassdescriptor = descriptor; + + } + + const colorAttachment = descriptor.colorAttachments[ 0 ]; + + if ( this.renderer.samples > 0 ) { + + colorAttachment.resolveTarget = this.context.getCurrentTexture().createView(); + + } else { + + colorAttachment.view = this.context.getCurrentTexture().createView(); + + } + + return descriptor; + + } + + _getRenderPassDescriptor( renderContext ) { + + const renderTarget = renderContext.renderTarget; + const renderTargetData = this.get( renderTarget ); + + let descriptors = renderTargetData.descriptors; + + if ( descriptors === undefined || + renderTargetData.width !== renderTarget.width || + renderTargetData.height !== renderTarget.height || + renderTargetData.activeMipmapLevel !== renderTarget.activeMipmapLevel || + renderTargetData.samples !== renderTarget.samples + ) { + + descriptors = {}; + + renderTargetData.descriptors = descriptors; + + // dispose + + const onDispose = () => { + + renderTarget.removeEventListener( 'dispose', onDispose ); + + this.delete( renderTarget ); + + }; + + renderTarget.addEventListener( 'dispose', onDispose ); + + } + + const cacheKey = renderContext.getCacheKey(); + + let descriptor = descriptors[ cacheKey ]; + + if ( descriptor === undefined ) { + + const textures = renderContext.textures; + const colorAttachments = []; + + for ( let i = 0; i < textures.length; i ++ ) { + + const textureData = this.get( textures[ i ] ); + + const textureView = textureData.texture.createView( { + baseMipLevel: renderContext.activeMipmapLevel, + mipLevelCount: 1, + baseArrayLayer: renderContext.activeCubeFace, + dimension: GPUTextureViewDimension.TwoD + } ); + + let view, resolveTarget; + + if ( textureData.msaaTexture !== undefined ) { + + view = textureData.msaaTexture.createView(); + resolveTarget = textureView; + + } else { + + view = textureView; + resolveTarget = undefined; + + } + + colorAttachments.push( { + view, + resolveTarget, + loadOp: GPULoadOp.Load, + storeOp: GPUStoreOp.Store + } ); + + } + + + descriptor = { + colorAttachments, + }; + + if ( renderContext.depth ) { + + const depthTextureData = this.get( renderContext.depthTexture ); + + const depthStencilAttachment = { + view: depthTextureData.texture.createView() + }; + descriptor.depthStencilAttachment = depthStencilAttachment; + + } + + descriptors[ cacheKey ] = descriptor; + + renderTargetData.width = renderTarget.width; + renderTargetData.height = renderTarget.height; + renderTargetData.samples = renderTarget.samples; + renderTargetData.activeMipmapLevel = renderTarget.activeMipmapLevel; + + } + + return descriptor; + + } + + beginRender( renderContext ) { + + const renderContextData = this.get( renderContext ); + + const device = this.device; + const occlusionQueryCount = renderContext.occlusionQueryCount; + + let occlusionQuerySet; + + if ( occlusionQueryCount > 0 ) { + + if ( renderContextData.currentOcclusionQuerySet ) renderContextData.currentOcclusionQuerySet.destroy(); + if ( renderContextData.currentOcclusionQueryBuffer ) renderContextData.currentOcclusionQueryBuffer.destroy(); + + // Get a reference to the array of objects with queries. The renderContextData property + // can be changed by another render pass before the buffer.mapAsyc() completes. + renderContextData.currentOcclusionQuerySet = renderContextData.occlusionQuerySet; + renderContextData.currentOcclusionQueryBuffer = renderContextData.occlusionQueryBuffer; + renderContextData.currentOcclusionQueryObjects = renderContextData.occlusionQueryObjects; + + // + + occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount, label: `occlusionQuerySet_${ renderContext.id }` } ); + + renderContextData.occlusionQuerySet = occlusionQuerySet; + renderContextData.occlusionQueryIndex = 0; + renderContextData.occlusionQueryObjects = new Array( occlusionQueryCount ); + + renderContextData.lastOcclusionObject = null; + + } + + let descriptor; + + if ( renderContext.textures === null ) { + + descriptor = this._getDefaultRenderPassDescriptor(); + + } else { + + descriptor = this._getRenderPassDescriptor( renderContext ); + + } + + this.initTimestampQuery( renderContext, descriptor ); + + descriptor.occlusionQuerySet = occlusionQuerySet; + + const depthStencilAttachment = descriptor.depthStencilAttachment; + + if ( renderContext.textures !== null ) { + + const colorAttachments = descriptor.colorAttachments; + + for ( let i = 0; i < colorAttachments.length; i ++ ) { + + const colorAttachment = colorAttachments[ i ]; + + if ( renderContext.clearColor ) { + + colorAttachment.clearValue = i === 0 ? renderContext.clearColorValue : { r: 0, g: 0, b: 0, a: 1 }; + colorAttachment.loadOp = GPULoadOp.Clear; + colorAttachment.storeOp = GPUStoreOp.Store; + + } else { + + colorAttachment.loadOp = GPULoadOp.Load; + colorAttachment.storeOp = GPUStoreOp.Store; + + } + + } + + } else { + + const colorAttachment = descriptor.colorAttachments[ 0 ]; + + if ( renderContext.clearColor ) { + + colorAttachment.clearValue = renderContext.clearColorValue; + colorAttachment.loadOp = GPULoadOp.Clear; + colorAttachment.storeOp = GPUStoreOp.Store; + + } else { + + colorAttachment.loadOp = GPULoadOp.Load; + colorAttachment.storeOp = GPUStoreOp.Store; + + } + + } + + // + + if ( renderContext.depth ) { + + if ( renderContext.clearDepth ) { + + depthStencilAttachment.depthClearValue = renderContext.clearDepthValue; + depthStencilAttachment.depthLoadOp = GPULoadOp.Clear; + depthStencilAttachment.depthStoreOp = GPUStoreOp.Store; + + } else { + + depthStencilAttachment.depthLoadOp = GPULoadOp.Load; + depthStencilAttachment.depthStoreOp = GPUStoreOp.Store; + + } + + } + + if ( renderContext.stencil ) { + + if ( renderContext.clearStencil ) { + + depthStencilAttachment.stencilClearValue = renderContext.clearStencilValue; + depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear; + depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store; + + } else { + + depthStencilAttachment.stencilLoadOp = GPULoadOp.Load; + depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store; + + } + + } + + // + + const encoder = device.createCommandEncoder( { label: 'renderContext_' + renderContext.id } ); + const currentPass = encoder.beginRenderPass( descriptor ); + + // + + renderContextData.descriptor = descriptor; + renderContextData.encoder = encoder; + renderContextData.currentPass = currentPass; + renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null }; + renderContextData.renderBundles = []; + + // + + if ( renderContext.viewport ) { + + this.updateViewport( renderContext ); + + } + + if ( renderContext.scissor ) { + + const { x, y, width, height } = renderContext.scissorValue; + + currentPass.setScissorRect( x, y, width, height ); + + } + + } + + finishRender( renderContext ) { + + const renderContextData = this.get( renderContext ); + const occlusionQueryCount = renderContext.occlusionQueryCount; + + if ( renderContextData.renderBundles.length > 0 ) { + + renderContextData.currentPass.executeBundles( renderContextData.renderBundles ); + + } + + if ( occlusionQueryCount > renderContextData.occlusionQueryIndex ) { + + renderContextData.currentPass.endOcclusionQuery(); + + } + + renderContextData.currentPass.end(); + + if ( occlusionQueryCount > 0 ) { + + const bufferSize = occlusionQueryCount * 8; // 8 byte entries for query results + + // + + let queryResolveBuffer = this.occludedResolveCache.get( bufferSize ); + + if ( queryResolveBuffer === undefined ) { + + queryResolveBuffer = this.device.createBuffer( + { + size: bufferSize, + usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC + } + ); + + this.occludedResolveCache.set( bufferSize, queryResolveBuffer ); + + } + + // + + const readBuffer = this.device.createBuffer( + { + size: bufferSize, + usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ + } + ); + + // two buffers required here - WebGPU doesn't allow usage of QUERY_RESOLVE & MAP_READ to be combined + renderContextData.encoder.resolveQuerySet( renderContextData.occlusionQuerySet, 0, occlusionQueryCount, queryResolveBuffer, 0 ); + renderContextData.encoder.copyBufferToBuffer( queryResolveBuffer, 0, readBuffer, 0, bufferSize ); + + renderContextData.occlusionQueryBuffer = readBuffer; + + // + + this.resolveOccludedAsync( renderContext ); + + } + + this.prepareTimestampBuffer( renderContext, renderContextData.encoder ); + + this.device.queue.submit( [ renderContextData.encoder.finish() ] ); + + + // + + if ( renderContext.textures !== null ) { + + const textures = renderContext.textures; + + for ( let i = 0; i < textures.length; i ++ ) { + + const texture = textures[ i ]; + + if ( texture.generateMipmaps === true ) { + + this.textureUtils.generateMipmaps( texture ); + + } + + } + + } + + } + + isOccluded( renderContext, object ) { + + const renderContextData = this.get( renderContext ); + + return renderContextData.occluded && renderContextData.occluded.has( object ); + + } + + async resolveOccludedAsync( renderContext ) { + + const renderContextData = this.get( renderContext ); + + // handle occlusion query results + + const { currentOcclusionQueryBuffer, currentOcclusionQueryObjects } = renderContextData; + + if ( currentOcclusionQueryBuffer && currentOcclusionQueryObjects ) { + + const occluded = new WeakSet(); + + renderContextData.currentOcclusionQueryObjects = null; + renderContextData.currentOcclusionQueryBuffer = null; + + await currentOcclusionQueryBuffer.mapAsync( GPUMapMode.READ ); + + const buffer = currentOcclusionQueryBuffer.getMappedRange(); + const results = new BigUint64Array( buffer ); + + for ( let i = 0; i < currentOcclusionQueryObjects.length; i ++ ) { + + if ( results[ i ] !== BigInt( 0 ) ) { + + occluded.add( currentOcclusionQueryObjects[ i ] ); + + } + + } + + currentOcclusionQueryBuffer.destroy(); + + renderContextData.occluded = occluded; + + } + + } + + updateViewport( renderContext ) { + + const { currentPass } = this.get( renderContext ); + const { x, y, width, height, minDepth, maxDepth } = renderContext.viewportValue; + + currentPass.setViewport( x, y, width, height, minDepth, maxDepth ); + + } + + clear( color, depth, stencil, renderTargetData = null ) { + + const device = this.device; + const renderer = this.renderer; + + let colorAttachments = []; + + let depthStencilAttachment; + let clearValue; + + let supportsDepth; + let supportsStencil; + + if ( color ) { + + const clearColor = this.getClearColor(); + + if ( this.renderer.alpha === true ) { + + // premultiply alpha + + const a = clearColor.a; + + clearValue = { r: clearColor.r * a, g: clearColor.g * a, b: clearColor.b * a, a: a }; + + } else { + + clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a }; + + } + + } + + if ( renderTargetData === null ) { + + supportsDepth = renderer.depth; + supportsStencil = renderer.stencil; + + const descriptor = this._getDefaultRenderPassDescriptor(); + + if ( color ) { + + colorAttachments = descriptor.colorAttachments; + + const colorAttachment = colorAttachments[ 0 ]; + + colorAttachment.clearValue = clearValue; + colorAttachment.loadOp = GPULoadOp.Clear; + colorAttachment.storeOp = GPUStoreOp.Store; + + } + + if ( supportsDepth || supportsStencil ) { + + depthStencilAttachment = descriptor.depthStencilAttachment; + + } + + } else { + + supportsDepth = renderTargetData.depth; + supportsStencil = renderTargetData.stencil; + + if ( color ) { + + for ( const texture of renderTargetData.textures ) { + + const textureData = this.get( texture ); + const textureView = textureData.texture.createView(); + + let view, resolveTarget; + + if ( textureData.msaaTexture !== undefined ) { + + view = textureData.msaaTexture.createView(); + resolveTarget = textureView; + + } else { + + view = textureView; + resolveTarget = undefined; + + } + + colorAttachments.push( { + view, + resolveTarget, + clearValue, + loadOp: GPULoadOp.Clear, + storeOp: GPUStoreOp.Store + } ); + + } + + } + + if ( supportsDepth || supportsStencil ) { + + const depthTextureData = this.get( renderTargetData.depthTexture ); + + depthStencilAttachment = { + view: depthTextureData.texture.createView() + }; + + } + + } + + // + + if ( supportsDepth ) { + + if ( depth ) { + + depthStencilAttachment.depthLoadOp = GPULoadOp.Clear; + depthStencilAttachment.depthClearValue = renderer.getClearDepth(); + depthStencilAttachment.depthStoreOp = GPUStoreOp.Store; + + } else { + + depthStencilAttachment.depthLoadOp = GPULoadOp.Load; + depthStencilAttachment.depthStoreOp = GPUStoreOp.Store; + + } + + } + + // + + if ( supportsStencil ) { + + if ( stencil ) { + + depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear; + depthStencilAttachment.stencilClearValue = renderer.getClearStencil(); + depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store; + + } else { + + depthStencilAttachment.stencilLoadOp = GPULoadOp.Load; + depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store; + + } + + } + + // + + const encoder = device.createCommandEncoder( {} ); + const currentPass = encoder.beginRenderPass( { + colorAttachments, + depthStencilAttachment + } ); + + currentPass.end(); + + device.queue.submit( [ encoder.finish() ] ); + + } + + // compute + + beginCompute( computeGroup ) { + + const groupGPU = this.get( computeGroup ); + + + const descriptor = {}; + + this.initTimestampQuery( computeGroup, descriptor ); + + groupGPU.cmdEncoderGPU = this.device.createCommandEncoder(); + + groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass( descriptor ); + + } + + compute( computeGroup, computeNode, bindings, pipeline ) { + + const { passEncoderGPU } = this.get( computeGroup ); + + // pipeline + + const pipelineGPU = this.get( pipeline ).pipeline; + passEncoderGPU.setPipeline( pipelineGPU ); + + // bind groups + + for ( let i = 0, l = bindings.length; i < l; i ++ ) { + + const bindGroup = bindings[ i ]; + const bindingsData = this.get( bindGroup ); + + passEncoderGPU.setBindGroup( i, bindingsData.group ); + + } + + const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension; + + const computeNodeData = this.get( computeNode ); + + if ( computeNodeData.dispatchSize === undefined ) computeNodeData.dispatchSize = { x: 0, y: 1, z: 1 }; + + const { dispatchSize } = computeNodeData; + + if ( computeNode.dispatchCount > maxComputeWorkgroupsPerDimension ) { + + dispatchSize.x = Math.min( computeNode.dispatchCount, maxComputeWorkgroupsPerDimension ); + dispatchSize.y = Math.ceil( computeNode.dispatchCount / maxComputeWorkgroupsPerDimension ); + + } else { + + dispatchSize.x = computeNode.dispatchCount; + + } + + passEncoderGPU.dispatchWorkgroups( + dispatchSize.x, + dispatchSize.y, + dispatchSize.z + ); + + } + + finishCompute( computeGroup ) { + + const groupData = this.get( computeGroup ); + + groupData.passEncoderGPU.end(); + + this.prepareTimestampBuffer( computeGroup, groupData.cmdEncoderGPU ); + + this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] ); + + } + + async waitForGPU() { + + await this.device.queue.onSubmittedWorkDone(); + + } + + // render object + + draw( renderObject, info ) { + + const { object, context, pipeline } = renderObject; + const bindings = renderObject.getBindings(); + const renderContextData = this.get( context ); + const pipelineGPU = this.get( pipeline ).pipeline; + const currentSets = renderContextData.currentSets; + const passEncoderGPU = renderContextData.currentPass; + + const drawParams = renderObject.getDrawParameters(); + + if ( drawParams === null ) return; + + // pipeline + + if ( currentSets.pipeline !== pipelineGPU ) { + + passEncoderGPU.setPipeline( pipelineGPU ); + + currentSets.pipeline = pipelineGPU; + + } + + // bind groups + + const currentBindingGroups = currentSets.bindingGroups; + + for ( let i = 0, l = bindings.length; i < l; i ++ ) { + + const bindGroup = bindings[ i ]; + const bindingsData = this.get( bindGroup ); + + if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) { + + passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group ); + currentBindingGroups[ bindGroup.index ] = bindGroup.id; + + } + + } + + // attributes + + const index = renderObject.getIndex(); + + const hasIndex = ( index !== null ); + + // index + + if ( hasIndex === true ) { + + if ( currentSets.index !== index ) { + + const buffer = this.get( index ).buffer; + const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32; + + passEncoderGPU.setIndexBuffer( buffer, indexFormat ); + + currentSets.index = index; + + } + + } + + // vertex buffers + + const vertexBuffers = renderObject.getVertexBuffers(); + + for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) { + + const vertexBuffer = vertexBuffers[ i ]; + + if ( currentSets.attributes[ i ] !== vertexBuffer ) { + + const buffer = this.get( vertexBuffer ).buffer; + passEncoderGPU.setVertexBuffer( i, buffer ); + + currentSets.attributes[ i ] = vertexBuffer; + + } + + } + + // occlusion queries - handle multiple consecutive draw calls for an object + + if ( renderContextData.occlusionQuerySet !== undefined ) { + + const lastObject = renderContextData.lastOcclusionObject; + + if ( lastObject !== object ) { + + if ( lastObject !== null && lastObject.occlusionTest === true ) { + + passEncoderGPU.endOcclusionQuery(); + renderContextData.occlusionQueryIndex ++; + + } + + if ( object.occlusionTest === true ) { + + passEncoderGPU.beginOcclusionQuery( renderContextData.occlusionQueryIndex ); + renderContextData.occlusionQueryObjects[ renderContextData.occlusionQueryIndex ] = object; + + } + + renderContextData.lastOcclusionObject = object; + + } + + } + + // draw + + if ( object.isBatchedMesh === true ) { + + const starts = object._multiDrawStarts; + const counts = object._multiDrawCounts; + const drawCount = object._multiDrawCount; + const drawInstances = object._multiDrawInstances; + + const bytesPerElement = hasIndex ? index.array.BYTES_PER_ELEMENT : 1; + + for ( let i = 0; i < drawCount; i ++ ) { + + const count = drawInstances ? drawInstances[ i ] : 1; + const firstInstance = count > 1 ? 0 : i; + + passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance ); + + } + + } else if ( hasIndex === true ) { + + const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams; + + const indirect = renderObject.getIndirect(); + + if ( indirect !== null ) { + + const buffer = this.get( indirect ).buffer; + + passEncoderGPU.drawIndexedIndirect( buffer, 0 ); + + } else { + + passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 ); + + } + + info.update( object, indexCount, instanceCount ); + + } else { + + const { vertexCount, instanceCount, firstVertex } = drawParams; + + const indirect = renderObject.getIndirect(); + + if ( indirect !== null ) { + + const buffer = this.get( indirect ).buffer; + + passEncoderGPU.drawIndirect( buffer, 0 ); + + } else { + + passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 ); + + } + + info.update( object, vertexCount, instanceCount ); + + } + + } + + // cache key + + needsRenderUpdate( renderObject ) { + + const data = this.get( renderObject ); + + const { object, material } = renderObject; + + const utils = this.utils; + + const sampleCount = utils.getSampleCountRenderContext( renderObject.context ); + const colorSpace = utils.getCurrentColorSpace( renderObject.context ); + const colorFormat = utils.getCurrentColorFormat( renderObject.context ); + const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderObject.context ); + const primitiveTopology = utils.getPrimitiveTopology( object, material ); + + let needsUpdate = false; + + if ( data.material !== material || data.materialVersion !== material.version || + data.transparent !== material.transparent || data.blending !== material.blending || data.premultipliedAlpha !== material.premultipliedAlpha || + data.blendSrc !== material.blendSrc || data.blendDst !== material.blendDst || data.blendEquation !== material.blendEquation || + data.blendSrcAlpha !== material.blendSrcAlpha || data.blendDstAlpha !== material.blendDstAlpha || data.blendEquationAlpha !== material.blendEquationAlpha || + data.colorWrite !== material.colorWrite || data.depthWrite !== material.depthWrite || data.depthTest !== material.depthTest || data.depthFunc !== material.depthFunc || + data.stencilWrite !== material.stencilWrite || data.stencilFunc !== material.stencilFunc || + data.stencilFail !== material.stencilFail || data.stencilZFail !== material.stencilZFail || data.stencilZPass !== material.stencilZPass || + data.stencilFuncMask !== material.stencilFuncMask || data.stencilWriteMask !== material.stencilWriteMask || + data.side !== material.side || data.alphaToCoverage !== material.alphaToCoverage || + data.sampleCount !== sampleCount || data.colorSpace !== colorSpace || + data.colorFormat !== colorFormat || data.depthStencilFormat !== depthStencilFormat || + data.primitiveTopology !== primitiveTopology || + data.clippingContextCacheKey !== renderObject.clippingContextCacheKey + ) { + + data.material = material; data.materialVersion = material.version; + data.transparent = material.transparent; data.blending = material.blending; data.premultipliedAlpha = material.premultipliedAlpha; + data.blendSrc = material.blendSrc; data.blendDst = material.blendDst; data.blendEquation = material.blendEquation; + data.blendSrcAlpha = material.blendSrcAlpha; data.blendDstAlpha = material.blendDstAlpha; data.blendEquationAlpha = material.blendEquationAlpha; + data.colorWrite = material.colorWrite; + data.depthWrite = material.depthWrite; data.depthTest = material.depthTest; data.depthFunc = material.depthFunc; + data.stencilWrite = material.stencilWrite; data.stencilFunc = material.stencilFunc; + data.stencilFail = material.stencilFail; data.stencilZFail = material.stencilZFail; data.stencilZPass = material.stencilZPass; + data.stencilFuncMask = material.stencilFuncMask; data.stencilWriteMask = material.stencilWriteMask; + data.side = material.side; data.alphaToCoverage = material.alphaToCoverage; + data.sampleCount = sampleCount; + data.colorSpace = colorSpace; + data.colorFormat = colorFormat; + data.depthStencilFormat = depthStencilFormat; + data.primitiveTopology = primitiveTopology; + data.clippingContextCacheKey = renderObject.clippingContextCacheKey; + + needsUpdate = true; + + } + + return needsUpdate; + + } + + getRenderCacheKey( renderObject ) { + + const { object, material } = renderObject; + + const utils = this.utils; + const renderContext = renderObject.context; + + return [ + material.transparent, material.blending, material.premultipliedAlpha, + material.blendSrc, material.blendDst, material.blendEquation, + material.blendSrcAlpha, material.blendDstAlpha, material.blendEquationAlpha, + material.colorWrite, + material.depthWrite, material.depthTest, material.depthFunc, + material.stencilWrite, material.stencilFunc, + material.stencilFail, material.stencilZFail, material.stencilZPass, + material.stencilFuncMask, material.stencilWriteMask, + material.side, + utils.getSampleCountRenderContext( renderContext ), + utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ), + utils.getPrimitiveTopology( object, material ), + renderObject.getGeometryCacheKey(), + renderObject.clippingContextCacheKey + ].join(); + + } + + // textures + + createSampler( texture ) { + + this.textureUtils.createSampler( texture ); + + } + + destroySampler( texture ) { + + this.textureUtils.destroySampler( texture ); + + } + + createDefaultTexture( texture ) { + + this.textureUtils.createDefaultTexture( texture ); + + } + + createTexture( texture, options ) { + + this.textureUtils.createTexture( texture, options ); + + } + + updateTexture( texture, options ) { + + this.textureUtils.updateTexture( texture, options ); + + } + + generateMipmaps( texture ) { + + this.textureUtils.generateMipmaps( texture ); + + } + + destroyTexture( texture ) { + + this.textureUtils.destroyTexture( texture ); + + } + + copyTextureToBuffer( texture, x, y, width, height, faceIndex ) { + + return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex ); + + } + + + initTimestampQuery( renderContext, descriptor ) { + + if ( ! this.trackTimestamp ) return; + + const renderContextData = this.get( renderContext ); + + if ( ! renderContextData.timeStampQuerySet ) { + + + const type = renderContext.isComputeNode ? 'compute' : 'render'; + const timeStampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2, label: `timestamp_${type}_${renderContext.id}` } ); + + const timestampWrites = { + querySet: timeStampQuerySet, + beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins. + endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends. + }; + + Object.assign( descriptor, { timestampWrites } ); + + renderContextData.timeStampQuerySet = timeStampQuerySet; + + } + + } + + // timestamp utils + + prepareTimestampBuffer( renderContext, encoder ) { + + if ( ! this.trackTimestamp ) return; + + const renderContextData = this.get( renderContext ); + + + const size = 2 * BigInt64Array.BYTES_PER_ELEMENT; + + if ( renderContextData.currentTimestampQueryBuffers === undefined ) { + + renderContextData.currentTimestampQueryBuffers = { + resolveBuffer: this.device.createBuffer( { + label: 'timestamp resolve buffer', + size: size, + usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC, + } ), + resultBuffer: this.device.createBuffer( { + label: 'timestamp result buffer', + size: size, + usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ, + } ) + }; + + } + + const { resolveBuffer, resultBuffer } = renderContextData.currentTimestampQueryBuffers; + + + encoder.resolveQuerySet( renderContextData.timeStampQuerySet, 0, 2, resolveBuffer, 0 ); + + if ( resultBuffer.mapState === 'unmapped' ) { + + encoder.copyBufferToBuffer( resolveBuffer, 0, resultBuffer, 0, size ); + + } + + } + + async resolveTimestampAsync( renderContext, type = 'render' ) { + + if ( ! this.trackTimestamp ) return; + + const renderContextData = this.get( renderContext ); + + if ( renderContextData.currentTimestampQueryBuffers === undefined ) return; + + const { resultBuffer } = renderContextData.currentTimestampQueryBuffers; + + await this.device.queue.onSubmittedWorkDone(); + + if ( resultBuffer.mapState === 'unmapped' ) { + + resultBuffer.mapAsync( GPUMapMode.READ ).then( () => { + + const times = new BigUint64Array( resultBuffer.getMappedRange() ); + const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000; + + + this.renderer.info.updateTimestamp( type, duration ); + + resultBuffer.unmap(); + + + } ); + + } + + } + + // node builder + + createNodeBuilder( object, renderer ) { + + return new WGSLNodeBuilder( object, renderer ); + + } + + // program + + createProgram( program ) { + + const programGPU = this.get( program ); + + programGPU.module = { + module: this.device.createShaderModule( { code: program.code, label: program.stage } ), + entryPoint: 'main' + }; + + } + + destroyProgram( program ) { + + this.delete( program ); + + } + + // pipelines + + createRenderPipeline( renderObject, promises ) { + + this.pipelineUtils.createRenderPipeline( renderObject, promises ); + + } + + createComputePipeline( computePipeline, bindings ) { + + this.pipelineUtils.createComputePipeline( computePipeline, bindings ); + + } + + beginBundle( renderContext ) { + + const renderContextData = this.get( renderContext ); + + renderContextData._currentPass = renderContextData.currentPass; + renderContextData._currentSets = renderContextData.currentSets; + + renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null }; + renderContextData.currentPass = this.pipelineUtils.createBundleEncoder( renderContext ); + + } + + finishBundle( renderContext, bundle ) { + + const renderContextData = this.get( renderContext ); + + const bundleEncoder = renderContextData.currentPass; + const bundleGPU = bundleEncoder.finish(); + + this.get( bundle ).bundleGPU = bundleGPU; + + // restore render pass state + + renderContextData.currentSets = renderContextData._currentSets; + renderContextData.currentPass = renderContextData._currentPass; + + } + + addBundle( renderContext, bundle ) { + + const renderContextData = this.get( renderContext ); + + renderContextData.renderBundles.push( this.get( bundle ).bundleGPU ); + + } + + // bindings + + createBindings( bindGroup, bindings, cacheIndex, version ) { + + this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version ); + + } + + updateBindings( bindGroup, bindings, cacheIndex, version ) { + + this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version ); + + } + + updateBinding( binding ) { + + this.bindingUtils.updateBinding( binding ); + + } + + // attributes + + createIndexAttribute( attribute ) { + + this.attributeUtils.createAttribute( attribute, GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST ); + + } + + createAttribute( attribute ) { + + this.attributeUtils.createAttribute( attribute, GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST ); + + } + + createStorageAttribute( attribute ) { + + this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST ); + + } + + createIndirectStorageAttribute( attribute ) { + + this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST ); + + } + + updateAttribute( attribute ) { + + this.attributeUtils.updateAttribute( attribute ); + + } + + destroyAttribute( attribute ) { + + this.attributeUtils.destroyAttribute( attribute ); + + } + + // canvas + + updateSize() { + + this.colorBuffer = this.textureUtils.getColorBuffer(); + this.defaultRenderPassdescriptor = null; + + } + + // utils public + + getMaxAnisotropy() { + + return 16; + + } + + hasFeature( name ) { + + return this.device.features.has( name ); + + } + + copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) { + + let dstX = 0; + let dstY = 0; + let dstLayer = 0; + + let srcX = 0; + let srcY = 0; + let srcLayer = 0; + + let srcWidth = srcTexture.image.width; + let srcHeight = srcTexture.image.height; + + if ( srcRegion !== null ) { + + srcX = srcRegion.x; + srcY = srcRegion.y; + srcLayer = srcRegion.z || 0; + srcWidth = srcRegion.width; + srcHeight = srcRegion.height; + + } + + if ( dstPosition !== null ) { + + dstX = dstPosition.x; + dstY = dstPosition.y; + dstLayer = dstPosition.z || 0; + + } + + const encoder = this.device.createCommandEncoder( { label: 'copyTextureToTexture_' + srcTexture.id + '_' + dstTexture.id } ); + + const sourceGPU = this.get( srcTexture ).texture; + const destinationGPU = this.get( dstTexture ).texture; + + encoder.copyTextureToTexture( + { + texture: sourceGPU, + mipLevel: level, + origin: { x: srcX, y: srcY, z: srcLayer } + }, + { + texture: destinationGPU, + mipLevel: level, + origin: { x: dstX, y: dstY, z: dstLayer } + }, + [ + srcWidth, + srcHeight, + 1 + ] + ); + + this.device.queue.submit( [ encoder.finish() ] ); + + } + + copyFramebufferToTexture( texture, renderContext, rectangle ) { + + const renderContextData = this.get( renderContext ); + + let sourceGPU = null; + + if ( renderContext.renderTarget ) { + + if ( texture.isDepthTexture ) { + + sourceGPU = this.get( renderContext.depthTexture ).texture; + + } else { + + sourceGPU = this.get( renderContext.textures[ 0 ] ).texture; + + } + + } else { + + if ( texture.isDepthTexture ) { + + sourceGPU = this.textureUtils.getDepthBuffer( renderContext.depth, renderContext.stencil ); + + } else { + + sourceGPU = this.context.getCurrentTexture(); + + } + + } + + const destinationGPU = this.get( texture ).texture; + + if ( sourceGPU.format !== destinationGPU.format ) { + + console.error( 'WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.', sourceGPU.format, destinationGPU.format ); + + return; + + } + + let encoder; + + if ( renderContextData.currentPass ) { + + renderContextData.currentPass.end(); + + encoder = renderContextData.encoder; + + } else { + + encoder = this.device.createCommandEncoder( { label: 'copyFramebufferToTexture_' + texture.id } ); + + } + + encoder.copyTextureToTexture( + { + texture: sourceGPU, + origin: [ rectangle.x, rectangle.y, 0 ], + }, + { + texture: destinationGPU + }, + [ + rectangle.z, + rectangle.w + ] + ); + + if ( texture.generateMipmaps ) this.textureUtils.generateMipmaps( texture ); + + if ( renderContextData.currentPass ) { + + const { descriptor } = renderContextData; + + for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) { + + descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load; + + } + + if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load; + if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load; + + renderContextData.currentPass = encoder.beginRenderPass( descriptor ); + renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null }; + + if ( renderContext.viewport ) { + + this.updateViewport( renderContext ); + + } + + if ( renderContext.scissor ) { + + const { x, y, width, height } = renderContext.scissorValue; + + renderContextData.currentPass.setScissorRect( x, y, width, height ); + + } + + } else { + + this.device.queue.submit( [ encoder.finish() ] ); + + } + + } + +} + +class IESSpotLight extends SpotLight { + + constructor( color, intensity, distance, angle, penumbra, decay ) { + + super( color, intensity, distance, angle, penumbra, decay ); + + this.iesMap = null; + + } + + copy( source, recursive ) { + + super.copy( source, recursive ); + + this.iesMap = source.iesMap; + + return this; + + } + +} + +class StandardNodeLibrary extends NodeLibrary { + + constructor() { + + super(); + + this.addMaterial( MeshPhongNodeMaterial, 'MeshPhongMaterial' ); + this.addMaterial( MeshStandardNodeMaterial, 'MeshStandardMaterial' ); + this.addMaterial( MeshPhysicalNodeMaterial, 'MeshPhysicalMaterial' ); + this.addMaterial( MeshToonNodeMaterial, 'MeshToonMaterial' ); + this.addMaterial( MeshBasicNodeMaterial, 'MeshBasicMaterial' ); + this.addMaterial( MeshLambertNodeMaterial, 'MeshLambertMaterial' ); + this.addMaterial( MeshNormalNodeMaterial, 'MeshNormalMaterial' ); + this.addMaterial( MeshMatcapNodeMaterial, 'MeshMatcapMaterial' ); + this.addMaterial( LineBasicNodeMaterial, 'LineBasicMaterial' ); + this.addMaterial( LineDashedNodeMaterial, 'LineDashedMaterial' ); + this.addMaterial( PointsNodeMaterial, 'PointsMaterial' ); + this.addMaterial( SpriteNodeMaterial, 'SpriteMaterial' ); + this.addMaterial( ShadowNodeMaterial, 'ShadowMaterial' ); + + this.addLight( PointLightNode, PointLight ); + this.addLight( DirectionalLightNode, DirectionalLight ); + this.addLight( RectAreaLightNode, RectAreaLight ); + this.addLight( SpotLightNode, SpotLight ); + this.addLight( AmbientLightNode, AmbientLight ); + this.addLight( HemisphereLightNode, HemisphereLight ); + this.addLight( LightProbeNode, LightProbe ); + this.addLight( IESSpotLightNode, IESSpotLight ); + + this.addToneMapping( linearToneMapping, LinearToneMapping ); + this.addToneMapping( reinhardToneMapping, ReinhardToneMapping ); + this.addToneMapping( cineonToneMapping, CineonToneMapping ); + this.addToneMapping( acesFilmicToneMapping, ACESFilmicToneMapping ); + this.addToneMapping( agxToneMapping, AgXToneMapping ); + this.addToneMapping( neutralToneMapping, NeutralToneMapping ); + + } + +} + +/* +const debugHandler = { + + get: function ( target, name ) { + + // Add |update + if ( /^(create|destroy)/.test( name ) ) console.log( 'WebGPUBackend.' + name ); + + return target[ name ]; + + } + +}; +*/ +class WebGPURenderer extends Renderer { + + constructor( parameters = {} ) { + + let BackendClass; + + if ( parameters.forceWebGL ) { + + BackendClass = WebGLBackend; + + } else { + + BackendClass = WebGPUBackend; + + parameters.getFallback = () => { + + console.warn( 'THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' ); + + return new WebGLBackend( parameters ); + + }; + + } + + const backend = new BackendClass( parameters ); + + //super( new Proxy( backend, debugHandler ) ); + super( backend, parameters ); + + this.library = new StandardNodeLibrary(); + + this.isWebGPURenderer = true; + + } + +} + +class BundleGroup extends Group { + + constructor() { + + super(); + + this.isBundleGroup = true; + + this.type = 'BundleGroup'; + + this.static = true; + this.version = 0; + + } + + set needsUpdate( value ) { + + if ( value === true ) this.version ++; + + } + +} + +const _material = /*@__PURE__*/ new NodeMaterial(); +const _quadMesh = /*@__PURE__*/ new QuadMesh( _material ); + +class PostProcessing { + + constructor( renderer, outputNode = vec4( 0, 0, 1, 1 ) ) { + + this.renderer = renderer; + this.outputNode = outputNode; + + this.outputColorTransform = true; + + this.needsUpdate = true; + + _material.name = 'PostProcessing'; + + } + + render() { + + this.update(); + + const renderer = this.renderer; + + const toneMapping = renderer.toneMapping; + const outputColorSpace = renderer.outputColorSpace; + + renderer.toneMapping = NoToneMapping; + renderer.outputColorSpace = LinearSRGBColorSpace; + + // + + _quadMesh.render( renderer ); + + // + + renderer.toneMapping = toneMapping; + renderer.outputColorSpace = outputColorSpace; + + } + + update() { + + if ( this.needsUpdate === true ) { + + const renderer = this.renderer; + + const toneMapping = renderer.toneMapping; + const outputColorSpace = renderer.outputColorSpace; + + _quadMesh.material.fragmentNode = this.outputColorTransform === true ? renderOutput( this.outputNode, toneMapping, outputColorSpace ) : this.outputNode.context( { toneMapping, outputColorSpace } ); + _quadMesh.material.needsUpdate = true; + + this.needsUpdate = false; + + } + + } + + async renderAsync() { + + this.update(); + + const renderer = this.renderer; + + const toneMapping = renderer.toneMapping; + const outputColorSpace = renderer.outputColorSpace; + + renderer.toneMapping = NoToneMapping; + renderer.outputColorSpace = LinearSRGBColorSpace; + + // + + await _quadMesh.renderAsync( renderer ); + + // + + renderer.toneMapping = toneMapping; + renderer.outputColorSpace = outputColorSpace; + + } + +} + +// renderer state + +function saveRendererState( renderer, state = {} ) { + + state.toneMapping = renderer.toneMapping; + state.toneMappingExposure = renderer.toneMappingExposure; + state.outputColorSpace = renderer.outputColorSpace; + state.renderTarget = renderer.getRenderTarget(); + state.activeCubeFace = renderer.getActiveCubeFace(); + state.activeMipmapLevel = renderer.getActiveMipmapLevel(); + state.renderObjectFunction = renderer.getRenderObjectFunction(); + state.pixelRatio = renderer.getPixelRatio(); + state.mrt = renderer.getMRT(); + state.clearColor = renderer.getClearColor( state.clearColor || new Color() ); + state.clearAlpha = renderer.getClearAlpha(); + state.autoClear = renderer.autoClear; + state.scissorTest = renderer.getScissorTest(); + + return state; + +} + +function resetRendererState( renderer, state ) { + + state = saveRendererState( renderer, state ); + + renderer.setMRT( null ); + renderer.setRenderObjectFunction( null ); + renderer.setClearColor( 0x000000, 1 ); + renderer.autoClear = true; + + return state; + +} + +function restoreRendererState( renderer, state ) { + + renderer.toneMapping = state.toneMapping; + renderer.toneMappingExposure = state.toneMappingExposure; + renderer.outputColorSpace = state.outputColorSpace; + renderer.setRenderTarget( state.renderTarget, state.activeCubeFace, state.activeMipmapLevel ); + renderer.setRenderObjectFunction( state.renderObjectFunction ); + renderer.setPixelRatio( state.pixelRatio ); + renderer.setMRT( state.mrt ); + renderer.setClearColor( state.clearColor, state.clearAlpha ); + renderer.autoClear = state.autoClear; + renderer.setScissorTest( state.scissorTest ); + +} + +// renderer and scene state + +function saveRendererAndSceneState( renderer, scene, state = {} ) { + + state = saveRendererState( renderer, state ); + state.background = scene.background; + state.backgroundNode = scene.backgroundNode; + state.overrideMaterial = scene.overrideMaterial; + + return state; + +} + +function resetRendererAndSceneState( renderer, scene, state ) { + + state = saveRendererAndSceneState( renderer, scene, state ); + + scene.background = null; + scene.backgroundNode = null; + scene.overrideMaterial = null; + + return state; + +} + +function restoreRendererAndSceneState( renderer, scene, state ) { + + restoreRendererState( renderer, state ); + + scene.background = state.background; + scene.backgroundNode = state.backgroundNode; + scene.overrideMaterial = state.overrideMaterial; + +} + +var PostProcessingUtils = /*#__PURE__*/Object.freeze({ + __proto__: null, + resetRendererAndSceneState: resetRendererAndSceneState, + resetRendererState: resetRendererState, + restoreRendererAndSceneState: restoreRendererAndSceneState, + restoreRendererState: restoreRendererState, + saveRendererAndSceneState: saveRendererAndSceneState, + saveRendererState: saveRendererState +}); + +class StorageTexture extends Texture { + + constructor( width = 1, height = 1 ) { + + super(); + + this.image = { width, height }; + + this.magFilter = LinearFilter; + this.minFilter = LinearFilter; + + this.isStorageTexture = true; + + } + +} + +class IndirectStorageBufferAttribute extends StorageBufferAttribute { + + constructor( array, itemSize ) { + + super( array, itemSize, Uint32Array ); + + this.isIndirectStorageBufferAttribute = true; + + } + +} + +class NodeLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.textures = {}; + this.nodes = {}; + + } + + load( url, onLoad, onProgress, onError ) { + + const loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + loader.load( url, ( text ) => { + + try { + + onLoad( this.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + this.manager.itemError( url ); + + } + + }, onProgress, onError ); + + } + + parseNodes( json ) { + + const nodes = {}; + + if ( json !== undefined ) { + + for ( const nodeJSON of json ) { + + const { uuid, type } = nodeJSON; + + nodes[ uuid ] = this.createNodeFromType( type ); + nodes[ uuid ].uuid = uuid; + + } + + const meta = { nodes, textures: this.textures }; + + for ( const nodeJSON of json ) { + + nodeJSON.meta = meta; + + const node = nodes[ nodeJSON.uuid ]; + node.deserialize( nodeJSON ); + + delete nodeJSON.meta; + + } + + } + + return nodes; + + } + + parse( json ) { + + const node = this.createNodeFromType( json.type ); + node.uuid = json.uuid; + + const nodes = this.parseNodes( json.nodes ); + const meta = { nodes, textures: this.textures }; + + json.meta = meta; + + node.deserialize( json ); + + delete json.meta; + + return node; + + } + + setTextures( value ) { + + this.textures = value; + return this; + + } + + setNodes( value ) { + + this.nodes = value; + return this; + + } + + createNodeFromType( type ) { + + if ( this.nodes[ type ] === undefined ) { + + console.error( 'THREE.NodeLoader: Node type not found:', type ); + return float(); + + } + + return nodeObject( new this.nodes[ type ]() ); + + } + +} + +class NodeMaterialLoader extends MaterialLoader { + + constructor( manager ) { + + super( manager ); + + this.nodes = {}; + this.nodeMaterials = {}; + + } + + parse( json ) { + + const material = super.parse( json ); + + const nodes = this.nodes; + const inputNodes = json.inputNodes; + + for ( const property in inputNodes ) { + + const uuid = inputNodes[ property ]; + + material[ property ] = nodes[ uuid ]; + + } + + return material; + + } + + setNodes( value ) { + + this.nodes = value; + return this; + + } + + setNodeMaterials( value ) { + + this.nodeMaterials = value; + return this; + + } + + createMaterialFromType( type ) { + + const materialClass = this.nodeMaterials[ type ]; + + if ( materialClass !== undefined ) { + + return new materialClass(); + + } + + return super.createMaterialFromType( type ); + + } + +} + +class NodeObjectLoader extends ObjectLoader { + + constructor( manager ) { + + super( manager ); + + this.nodes = {}; + this.nodeMaterials = {}; + + this._nodesJSON = null; + + } + + setNodes( value ) { + + this.nodes = value; + return this; + + } + + setNodeMaterials( value ) { + + this.nodeMaterials = value; + return this; + + } + + parse( json, onLoad ) { + + this._nodesJSON = json.nodes; + + const data = super.parse( json, onLoad ); + + this._nodesJSON = null; // dispose + + return data; + + } + + parseNodes( json, textures ) { + + if ( json !== undefined ) { + + const loader = new NodeLoader(); + loader.setNodes( this.nodes ); + loader.setTextures( textures ); + + return loader.parseNodes( json ); + + } + + return {}; + + } + + parseMaterials( json, textures ) { + + const materials = {}; + + if ( json !== undefined ) { + + const nodes = this.parseNodes( this._nodesJSON, textures ); + + const loader = new NodeMaterialLoader(); + loader.setTextures( textures ); + loader.setNodes( nodes ); + loader.setNodeMaterials( this.nodeMaterials ); + + for ( let i = 0, l = json.length; i < l; i ++ ) { + + const data = json[ i ]; + + materials[ data.uuid ] = loader.parse( data ); + + } + + } + + return materials; + + } + +} + +class ClippingGroup extends Group { + + constructor() { + + super(); + + this.isClippingGroup = true; + this.clippingPlanes = []; + this.enabled = true; + this.clipIntersection = false; + this.clipShadows = false; + + } + +} + +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BackSide, BasicEnvironmentNode, BasicShadowMap, BatchNode, BoxGeometry, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedMeshNode, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, JoinNode, KeepStencilOp, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, LightProbe, LightProbeNode, Lighting, LightingContextNode, LightingModel, LightingNode, LightsNode, Line2NodeMaterial, LineBasicMaterial, LineBasicNodeMaterial, LineDashedMaterial, LineDashedNodeMaterial, LinearFilter, LinearMipMapLinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, Loader, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAccess, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGBIntegerFormat, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, ScreenNode, ScriptableNode, ScriptableValueNode, SetNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TSL, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, createCanvasElement, defaultBuildStages, defaultShaderStages, shaderStages, vectorComponents }; diff --git a/libs/three.js/r171/build/three.webgpu.min.js b/libs/three.js/r171/build/three.webgpu.min.js new file mode 100644 index 000000000..4e02be30e --- /dev/null +++ b/libs/three.js/r171/build/three.webgpu.min.js @@ -0,0 +1,6 @@ +/** + * @license + * Copyright 2010-2024 Three.js Authors + * SPDX-License-Identifier: MIT + */ +import{Color as e,Vector2 as t,Vector3 as r,Vector4 as s,Matrix3 as i,Matrix4 as n,EventDispatcher as o,MathUtils as a,ColorManagement as u,SRGBTransfer as l,NoToneMapping as d,StaticDrawUsage as c,InterleavedBuffer as h,DynamicDrawUsage as p,InterleavedBufferAttribute as g,NoColorSpace as m,UnsignedIntType as f,IntType as y,WebGLCoordinateSystem as b,BackSide as x,CubeReflectionMapping as T,CubeRefractionMapping as _,WebGPUCoordinateSystem as v,TangentSpaceNormalMap as N,ObjectSpaceNormalMap as S,InstancedInterleavedBuffer as A,InstancedBufferAttribute as R,DataArrayTexture as C,FloatType as E,FramebufferTexture as w,LinearMipmapLinearFilter as M,DepthTexture as B,Material as U,NormalBlending as F,PointsMaterial as P,LineBasicMaterial as I,LineDashedMaterial as L,NoBlending as D,MeshNormalMaterial as V,WebGLCubeRenderTarget as O,BoxGeometry as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as W,CubeTexture as H,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as K,MixOperation as X,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as re,MeshToonMaterial as se,MeshMatcapMaterial as ie,SpriteMaterial as ne,ShadowMaterial as oe,Uint32BufferAttribute as ae,Uint16BufferAttribute as ue,DoubleSide as le,DepthStencilFormat as de,DepthFormat as ce,UnsignedInt248Type as he,UnsignedByteType as pe,RenderTarget as ge,Plane as me,Object3D as fe,HalfFloatType as ye,LinearMipMapLinearFilter as be,OrthographicCamera as xe,BufferGeometry as Te,Float32BufferAttribute as _e,BufferAttribute as ve,UVMapping as Ne,Euler as Se,LinearSRGBColorSpace as Ae,LessCompare as Re,VSMShadowMap as Ce,RGFormat as Ee,BasicShadowMap as we,SphereGeometry as Me,CubeUVReflectionMapping as Be,PerspectiveCamera as Ue,RGBAFormat as Fe,LinearMipmapNearestFilter as Pe,NearestMipmapLinearFilter as Ie,Float16BufferAttribute as Le,REVISION as De,SRGBColorSpace as Ve,PCFShadowMap as Oe,FrontSide as Ge,Frustum as ke,DataTexture as ze,RedIntegerFormat as $e,RedFormat as We,RGIntegerFormat as He,RGBIntegerFormat as je,RGBFormat as qe,RGBAIntegerFormat as Ke,UnsignedShortType as Xe,ByteType as Ye,ShortType as Qe,createCanvasElement as Ze,AddEquation as Je,SubtractEquation as et,ReverseSubtractEquation as tt,ZeroFactor as rt,OneFactor as st,SrcColorFactor as it,SrcAlphaFactor as nt,SrcAlphaSaturateFactor as ot,DstColorFactor as at,DstAlphaFactor as ut,OneMinusSrcColorFactor as lt,OneMinusSrcAlphaFactor as dt,OneMinusDstColorFactor as ct,OneMinusDstAlphaFactor as ht,CullFaceNone as pt,CullFaceBack as gt,CullFaceFront as mt,CustomBlending as ft,MultiplyBlending as yt,SubtractiveBlending as bt,AdditiveBlending as xt,NotEqualDepth as Tt,GreaterDepth as _t,GreaterEqualDepth as vt,EqualDepth as Nt,LessEqualDepth as St,LessDepth as At,AlwaysDepth as Rt,NeverDepth as Ct,UnsignedShort4444Type as Et,UnsignedShort5551Type as wt,UnsignedInt5999Type as Mt,AlphaFormat as Bt,LuminanceFormat as Ut,LuminanceAlphaFormat as Ft,RGB_S3TC_DXT1_Format as Pt,RGBA_S3TC_DXT1_Format as It,RGBA_S3TC_DXT3_Format as Lt,RGBA_S3TC_DXT5_Format as Dt,RGB_PVRTC_4BPPV1_Format as Vt,RGB_PVRTC_2BPPV1_Format as Ot,RGBA_PVRTC_4BPPV1_Format as Gt,RGBA_PVRTC_2BPPV1_Format as kt,RGB_ETC1_Format as zt,RGB_ETC2_Format as $t,RGBA_ETC2_EAC_Format as Wt,RGBA_ASTC_4x4_Format as Ht,RGBA_ASTC_5x4_Format as jt,RGBA_ASTC_5x5_Format as qt,RGBA_ASTC_6x5_Format as Kt,RGBA_ASTC_6x6_Format as Xt,RGBA_ASTC_8x5_Format as Yt,RGBA_ASTC_8x6_Format as Qt,RGBA_ASTC_8x8_Format as Zt,RGBA_ASTC_10x5_Format as Jt,RGBA_ASTC_10x6_Format as er,RGBA_ASTC_10x8_Format as tr,RGBA_ASTC_10x10_Format as rr,RGBA_ASTC_12x10_Format as sr,RGBA_ASTC_12x12_Format as ir,RGBA_BPTC_Format as nr,RED_RGTC1_Format as or,SIGNED_RED_RGTC1_Format as ar,RED_GREEN_RGTC2_Format as ur,SIGNED_RED_GREEN_RGTC2_Format as lr,RepeatWrapping as dr,ClampToEdgeWrapping as cr,MirroredRepeatWrapping as hr,NearestFilter as pr,NearestMipmapNearestFilter as gr,NeverCompare as mr,AlwaysCompare as fr,LessEqualCompare as yr,EqualCompare as br,GreaterEqualCompare as xr,GreaterCompare as Tr,NotEqualCompare as _r,warnOnce as vr,NotEqualStencilFunc as Nr,GreaterStencilFunc as Sr,GreaterEqualStencilFunc as Ar,EqualStencilFunc as Rr,LessEqualStencilFunc as Cr,LessStencilFunc as Er,AlwaysStencilFunc as wr,NeverStencilFunc as Mr,DecrementWrapStencilOp as Br,IncrementWrapStencilOp as Ur,DecrementStencilOp as Fr,IncrementStencilOp as Pr,InvertStencilOp as Ir,ReplaceStencilOp as Lr,ZeroStencilOp as Dr,KeepStencilOp as Vr,MaxEquation as Or,MinEquation as Gr,SpotLight as kr,PointLight as zr,DirectionalLight as $r,RectAreaLight as Wr,AmbientLight as Hr,HemisphereLight as jr,LightProbe as qr,LinearToneMapping as Kr,ReinhardToneMapping as Xr,CineonToneMapping as Yr,ACESFilmicToneMapping as Qr,AgXToneMapping as Zr,NeutralToneMapping as Jr,Group as es,Loader as ts,FileLoader as rs,MaterialLoader as ss,ObjectLoader as is}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrayCamera,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Matrix2,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const ns=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class os{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=ns,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:r,material:s,object:i}=e;if(t={material:this.getMaterialData(s),geometry:{attributes:this.getAttributesData(r.attributes),indexVersion:r.index?r.index.version:null,drawRange:{start:r.drawRange.start,count:r.drawRange.count}},worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:r,height:s}=e.context;t.bufferWidth=r,t.bufferHeight=s}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const r in e){const s=e[r];t[r]={version:s.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const r of this.refreshUniforms){const s=e[r];null!=s&&("object"==typeof s&&void 0!==s.clone?!0===s.isTexture?t[r]={id:s.id,version:s.version}:t[r]=s.clone():t[r]=s)}return t}equals(e){const{object:t,material:r,geometry:s}=e,i=this.getRenderObjectData(e);if(!0!==i.worldMatrix.equals(t.matrixWorld))return i.worldMatrix.copy(t.matrixWorld),!1;const n=i.material;for(const e in n){const t=n[e],s=r[e];if(void 0!==t.equals){if(!1===t.equals(s))return t.copy(s),!1}else if(!0===s.isTexture){if(t.id!==s.id||t.version!==s.version)return t.id=s.id,t.version=s.version,!1}else if(t!==s)return n[e]=s,!1}if(n.transmission>0){const{width:t,height:r}=e.context;if(i.bufferWidth!==t||i.bufferHeight!==r)return i.bufferWidth=t,i.bufferHeight=r,!1}const o=i.geometry,a=s.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return i.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],r=a[e];if(void 0===r)return delete u[e],!1;if(t.version!==r.version)return t.version=r.version,!1}const c=s.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==s.drawRange.start||o.drawRange.count!==s.drawRange.count)return o.drawRange.start=s.drawRange.start,o.drawRange.count=s.drawRange.count,!1;if(i.morphTargetInfluences){let e=!1;for(let r=0;r>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),s=Math.imul(s^s>>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),4294967296*(2097151&s)+(r>>>0)}const us=e=>as(e),ls=e=>as(e),ds=(...e)=>as(e);function cs(e,t=!1){const r=[];!0===e.isNode&&(r.push(e.id),e=e.getSelf());for(const{property:s,childNode:i}of hs(e))r.push(r,as(s.slice(0,-4)),i.getCacheKey(t));return as(r)}function*hs(e,t=!1){for(const r in e){if(!0===r.startsWith("_"))continue;const s=e[r];if(!0===Array.isArray(s))for(let e=0;ee.charCodeAt(0))).buffer}var Ts=Object.freeze({__proto__:null,arrayBufferToBase64:bs,base64ToArrayBuffer:xs,getCacheKey:cs,getLengthFromType:ms,getNodeChildren:hs,getTypeFromLength:gs,getValueFromType:ys,getValueType:fs,hash:ds,hashArray:ls,hashString:us});const _s={VERTEX:"vertex",FRAGMENT:"fragment"},vs={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Ns={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Ss={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},As=["fragment","vertex"],Rs=["setup","analyze","generate"],Cs=[...As,"compute"],Es=["x","y","z","w"];let ws=0;class Ms extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=vs.NONE,this.updateBeforeType=vs.NONE,this.updateAfterType=vs.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:ws++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,vs.FRAME)}onRenderUpdate(e){return this.onUpdate(e,vs.RENDER)}onObjectUpdate(e){return this.onUpdate(e,vs.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of hs(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=cs(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let r=0;for(const e of this.getChildren())t["node"+r++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const r of Object.values(t))r&&!0===r.isNode&&r.build(e)}}generate(e,t){const{outputNode:r}=e.getNodeProperties(this);if(r&&!0===r.isNode)return r.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const r=this.getShared(e);if(this!==r)return r.build(e,t);e.addNode(this),e.addChain(this);let s=null;const i=e.getBuildStage();if("setup"===i){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const r of Object.values(t))r&&!0===r.isNode&&r.build(e)}}else if("analyze"===i)this.analyze(e);else if("generate"===i){if(1===this.generate.length){const r=this.getNodeType(e),i=e.getDataFromNode(this);s=i.snippet,void 0===s?(s=this.generate(e)||"",i.snippet=s):void 0!==i.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),s=e.format(s,r,t)}else s=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),s}getSerializeChildren(){return hs(this)}serialize(e){const t=this.getSerializeChildren(),r={};for(const{property:s,index:i,childNode:n}of t)void 0!==i?(void 0===r[s]&&(r[s]=Number.isInteger(i)?[]:{}),r[s][i]=n.toJSON(e.meta).uuid):r[s]=n.toJSON(e.meta).uuid;Object.keys(r).length>0&&(e.inputNodes=r)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const r in e.inputNodes)if(Array.isArray(e.inputNodes[r])){const s=[];for(const i of e.inputNodes[r])s.push(t[i]);this[r]=s}else if("object"==typeof e.inputNodes[r]){const s={};for(const i in e.inputNodes[r]){const n=e.inputNodes[r][i];s[i]=t[n]}this[r]=s}else{const s=e.inputNodes[r];this[r]=t[s]}}}toJSON(e){const{uuid:t,type:r}=this,s=void 0===e||"string"==typeof e;s&&(e={textures:{},images:{},nodes:{}});let i=e.nodes[t];function n(e){const t=[];for(const r in e){const s=e[r];delete s.metadata,t.push(s)}return t}if(void 0===i&&(i={uuid:t,type:r,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==s&&(e.nodes[i.uuid]=i),this.serialize(i),delete i.meta),s){const t=n(e.textures),r=n(e.images),s=n(e.nodes);t.length>0&&(i.textures=t),r.length>0&&(i.images=r),s.length>0&&(i.nodes=s)}return i}}class Bs extends Ms{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Us extends Ms{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let r=null;for(const s of this.convertTo.split("|"))null!==r&&e.getTypeLength(t)!==e.getTypeLength(s)||(r=s);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const r=this.node,s=this.getNodeType(e),i=r.build(e,s);return e.format(i,s,t)}}class Fs extends Ms{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const r=e.getVectorType(this.getNodeType(e,t)),s=e.getDataFromNode(this);if(void 0!==s.propertyName)return e.format(s.propertyName,r,t);if("void"!==r&&"void"!==t&&this.hasDependencies(e)){const i=super.build(e,r),n=e.getVarFromNode(this,null,r),o=e.getPropertyName(n);return e.addLineFlowCode(`${o} = ${i}`,this),s.snippet=i,s.propertyName=o,e.format(s.propertyName,r,t)}}return super.build(e,t)}}class Ps extends Fs{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,r)=>t+e.getTypeLength(r.getNodeType(e))),0))}generate(e,t){const r=this.getNodeType(e),s=this.nodes,i=e.getComponentType(r),n=[];for(const t of s){let r=t.build(e);const s=e.getComponentType(t.getNodeType(e));s!==i&&(r=e.format(r,s,i)),n.push(r)}const o=`${e.getType(r)}( ${n.join(", ")} )`;return e.format(o,r,t)}}const Is=Es.join("");class Ls extends Ms{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(Es.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const r=this.node,s=e.getTypeLength(r.getNodeType(e));let i=null;if(s>1){let n=null;this.getVectorLength()>=s&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=r.build(e,n);i=this.components.length===s&&this.components===Is.slice(0,this.components.length)?e.format(o,n,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else i=r.build(e,t);return i}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ds extends Fs{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:r,targetNode:s}=this,i=this.getNodeType(e),n=e.getTypeFromLength(r.length,s.getNodeType(e)),o=s.build(e,n),a=t.build(e,i),u=e.getTypeLength(i),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Hs=e=>Ws(e).split("").sort().join(""),js={setup(e,t){const r=t.shift();return e(yi(r),...t)},get(e,t,r){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(ks.assign(r,...e),r);if(zs.has(t)){const s=zs.get(t);return e.isStackNode?(...e)=>r.add(s(...e)):(...e)=>s(r,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&zs.has(t.slice(0,t.length-6))){const s=zs.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>r.assign(e[0],s(...e)):(...e)=>r.assign(s(r,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Ws(t),fi(new Ls(r,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Hs(t.slice(3).toLowerCase()),r=>fi(new Ds(e,t,r));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Hs(t.slice(4).toLowerCase()),()=>fi(new Vs(fi(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),fi(new Ls(e,t));if(!0===/^\d+$/.test(t))return fi(new Bs(r,new Gs(Number(t),"uint")))}return Reflect.get(e,t,r)},set:(e,t,r,s)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,r,s):(s[t].assign(r),!0)},qs=new WeakMap,Ks=new WeakMap,Xs=function(e,t=null){for(const r in e)e[r]=fi(e[r],t);return e},Ys=function(e,t=null){const r=e.length;for(let s=0;sfi(null!==s?Object.assign(e,s):e);return null===t?(...t)=>i(new e(...bi(t))):null!==r?(r=fi(r),(...s)=>i(new e(t,...bi(s),r))):(...r)=>i(new e(t,...bi(r)))},Zs=function(e,...t){return fi(new e(...bi(t)))};class Js extends Ms{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:r}=this,s=e.getNodeProperties(t);if(s.onceOutput)return s.onceOutput;let i=null;if(t.layout){let s=Ks.get(e.constructor);void 0===s&&(s=new WeakMap,Ks.set(e.constructor,s));let n=s.get(t);void 0===n&&(n=fi(e.buildFunctionNode(t)),s.set(t,n)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(n),i=fi(n.call(r))}else{const s=t.jsFunc,n=null!==r?s(r,e):s(e);i=fi(n)}return t.once&&(s.onceOutput=i),i}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class ei extends Ms{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return yi(e),fi(new Js(this,e))}setup(){return this.call()}}const ti=[!1,!0],ri=[0,1,2,3],si=[-1,-2],ii=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],ni=new Map;for(const e of ti)ni.set(e,new Gs(e));const oi=new Map;for(const e of ri)oi.set(e,new Gs(e,"uint"));const ai=new Map([...oi].map((e=>new Gs(e.value,"int"))));for(const e of si)ai.set(e,new Gs(e,"int"));const ui=new Map([...ai].map((e=>new Gs(e.value))));for(const e of ii)ui.set(e,new Gs(e));for(const e of ii)ui.set(-e,new Gs(-e));const li={bool:ni,uint:oi,ints:ai,float:ui},di=new Map([...ni,...ui]),ci=(e,t)=>di.has(e)?di.get(e):!0===e.isNode?e:new Gs(e,t),hi=function(e,t=null){return(...r)=>{if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every((e=>"object"!=typeof e)))&&(r=[ys(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return fi(t.get(r[0]));if(1===r.length){const t=ci(r[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?fi(t):fi(new Us(t,e))}const s=r.map((e=>ci(e)));return fi(new Ps(s,e))}},pi=e=>"object"==typeof e&&null!==e?e.value:e,gi=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function mi(e,t){return new Proxy(new ei(e,t),js)}const fi=(e,t=null)=>function(e,t=null){const r=fs(e);if("node"===r){let t=qs.get(e);return void 0===t&&(t=new Proxy(e,js),qs.set(e,t),qs.set(t,t)),t}return null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r?fi(ci(e,t)):"shader"===r?_i(e):e}(e,t),yi=(e,t=null)=>new Xs(e,t),bi=(e,t=null)=>new Ys(e,t),xi=(...e)=>new Qs(...e),Ti=(...e)=>new Zs(...e),_i=(e,t)=>{const r=new mi(e,t),s=(...e)=>{let t;return yi(e),t=e[0]&&e[0].isNode?[...e]:e[0],r.call(t)};return s.shaderNode=r,s.setLayout=e=>(r.setLayout(e),s),s.once=()=>(r.once=!0,s),s};$s("toGlobal",(e=>(e.global=!0,e)));const vi=e=>{ks=e},Ni=()=>ks,Si=(...e)=>ks.If(...e);function Ai(e){return ks&&ks.add(e),e}$s("append",Ai);const Ri=new hi("color"),Ci=new hi("float",li.float),Ei=new hi("int",li.ints),wi=new hi("uint",li.uint),Mi=new hi("bool",li.bool),Bi=new hi("vec2"),Ui=new hi("ivec2"),Fi=new hi("uvec2"),Pi=new hi("bvec2"),Ii=new hi("vec3"),Li=new hi("ivec3"),Di=new hi("uvec3"),Vi=new hi("bvec3"),Oi=new hi("vec4"),Gi=new hi("ivec4"),ki=new hi("uvec4"),zi=new hi("bvec4"),$i=new hi("mat2"),Wi=new hi("mat3"),Hi=new hi("mat4");$s("toColor",Ri),$s("toFloat",Ci),$s("toInt",Ei),$s("toUint",wi),$s("toBool",Mi),$s("toVec2",Bi),$s("toIVec2",Ui),$s("toUVec2",Fi),$s("toBVec2",Pi),$s("toVec3",Ii),$s("toIVec3",Li),$s("toUVec3",Di),$s("toBVec3",Vi),$s("toVec4",Oi),$s("toIVec4",Gi),$s("toUVec4",ki),$s("toBVec4",zi),$s("toMat2",$i),$s("toMat3",Wi),$s("toMat4",Hi);const ji=xi(Bs),qi=(e,t)=>fi(new Us(fi(e),t));$s("element",ji),$s("convert",qi);class Ki extends Ms{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=r,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xi=e=>new Ki(e),Yi=(e,t=0)=>new Ki(e,!0,t),Qi=Yi("frame"),Zi=Yi("render"),Ji=Xi("object");class en extends Os{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Ji}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const r=this.getSelf();return e=e.bind(r),super.onUpdate((t=>{const s=e(t,r);void 0!==s&&(this.value=s)}),t)}generate(e,t){const r=this.getNodeType(e),s=this.getUniformHash(e);let i=e.getNodeFromHash(s);void 0===i&&(e.setHashNode(this,s),i=this);const n=i.getInputType(e),o=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,r,t)}}const tn=(e,t)=>{const r=gi(t||e),s=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return fi(new en(s,r))};class rn extends Ms{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1){super(e),this.name=t,this.varying=r,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const sn=(e,t)=>fi(new rn(e,t)),nn=(e,t)=>fi(new rn(e,t,!0)),on=Ti(rn,"vec4","DiffuseColor"),an=Ti(rn,"vec3","EmissiveColor"),un=Ti(rn,"float","Roughness"),ln=Ti(rn,"float","Metalness"),dn=Ti(rn,"float","Clearcoat"),cn=Ti(rn,"float","ClearcoatRoughness"),hn=Ti(rn,"vec3","Sheen"),pn=Ti(rn,"float","SheenRoughness"),gn=Ti(rn,"float","Iridescence"),mn=Ti(rn,"float","IridescenceIOR"),fn=Ti(rn,"float","IridescenceThickness"),yn=Ti(rn,"float","AlphaT"),bn=Ti(rn,"float","Anisotropy"),xn=Ti(rn,"vec3","AnisotropyT"),Tn=Ti(rn,"vec3","AnisotropyB"),_n=Ti(rn,"color","SpecularColor"),vn=Ti(rn,"float","SpecularF90"),Nn=Ti(rn,"float","Shininess"),Sn=Ti(rn,"vec4","Output"),An=Ti(rn,"float","dashSize"),Rn=Ti(rn,"float","gapSize"),Cn=Ti(rn,"float","pointWidth"),En=Ti(rn,"float","IOR"),wn=Ti(rn,"float","Transmission"),Mn=Ti(rn,"float","Thickness"),Bn=Ti(rn,"float","AttenuationDistance"),Un=Ti(rn,"color","AttenuationColor"),Fn=Ti(rn,"float","Dispersion");class Pn extends Fs{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const r=e.getTypeLength(t.node.getNodeType(e));return Es.join("").slice(0,r)!==t.components}return!1}generate(e,t){const{targetNode:r,sourceNode:s}=this,i=this.needsSplitAssign(e),n=r.getNodeType(e),o=r.context({assign:!0}).build(e),a=s.build(e,n),u=s.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(i){const s=e.getVarFromNode(this,null,n),i=e.getPropertyName(s);e.addLineFlowCode(`${i} = ${a}`,this);const u=r.node.context({assign:!0}).build(e);for(let t=0;t{const s=r.type;let i;return i="pointer"===s?"&"+t.build(e):t.build(e,s),i};if(Array.isArray(i))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?bi(t):yi(t[0]),fi(new Ln(fi(e),t)));$s("call",Dn);class Vn extends Fs{static get type(){return"OperatorNode"}constructor(e,t,r,...s){if(super(),s.length>0){let i=new Vn(e,t,r);for(let t=0;t>"===r||"<<"===r)return e.getIntegerType(n);if("!"===r||"=="===r||"&&"===r||"||"===r||"^^"===r)return"bool";if("<"===r||">"===r||"<="===r||">="===r){const r=t?e.getTypeLength(t):Math.max(e.getTypeLength(n),e.getTypeLength(o));return r>1?`bvec${r}`:"bool"}return"float"===n&&e.isMatrix(o)?o:e.isMatrix(n)&&e.isVector(o)?e.getVectorFromMatrix(n):e.isVector(n)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(n)?o:n}generate(e,t){const r=this.op,s=this.aNode,i=this.bNode,n=this.getNodeType(e,t);let o=null,a=null;"void"!==n?(o=s.getNodeType(e),a=void 0!==i?i.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===r||"<<"===r?(o=n,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=n):o=a=n;const u=s.build(e,o),l=void 0!==i?i.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(r);return"void"!==t?"<"===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} < ${l} )`,n,t):"<="===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} <= ${l} )`,n,t):">"===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} > ${l} )`,n,t):">="===r&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} >= ${l} )`,n,t):"!"===r||"~"===r?e.format(`(${r}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`( ${u} ${r} ${l} )`,n,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`${u} ${r} ${l}`,n,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const On=xi(Vn,"+"),Gn=xi(Vn,"-"),kn=xi(Vn,"*"),zn=xi(Vn,"/"),$n=xi(Vn,"%"),Wn=xi(Vn,"=="),Hn=xi(Vn,"!="),jn=xi(Vn,"<"),qn=xi(Vn,">"),Kn=xi(Vn,"<="),Xn=xi(Vn,">="),Yn=xi(Vn,"&&"),Qn=xi(Vn,"||"),Zn=xi(Vn,"!"),Jn=xi(Vn,"^^"),eo=xi(Vn,"&"),to=xi(Vn,"~"),ro=xi(Vn,"|"),so=xi(Vn,"^"),io=xi(Vn,"<<"),no=xi(Vn,">>");$s("add",On),$s("sub",Gn),$s("mul",kn),$s("div",zn),$s("modInt",$n),$s("equal",Wn),$s("notEqual",Hn),$s("lessThan",jn),$s("greaterThan",qn),$s("lessThanEqual",Kn),$s("greaterThanEqual",Xn),$s("and",Yn),$s("or",Qn),$s("not",Zn),$s("xor",Jn),$s("bitAnd",eo),$s("bitNot",to),$s("bitOr",ro),$s("bitXor",so),$s("shiftLeft",io),$s("shiftRight",no);const oo=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),$n(...e));$s("remainder",oo);class ao extends Fs{static get type(){return"MathNode"}constructor(e,t,r=null,s=null){super(),this.method=e,this.aNode=t,this.bNode=r,this.cNode=s}getInputType(e){const t=this.aNode.getNodeType(e),r=this.bNode?this.bNode.getNodeType(e):null,s=this.cNode?this.cNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(r)?0:e.getTypeLength(r),o=e.isMatrix(s)?0:e.getTypeLength(s);return i>n&&i>o?t:n>o?r:o>i?s:t}getNodeType(e){const t=this.method;return t===ao.LENGTH||t===ao.DISTANCE||t===ao.DOT?"float":t===ao.CROSS?"vec3":t===ao.ALL?"bool":t===ao.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===ao.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const r=this.method,s=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(r===ao.TRANSFORM_DIRECTION){let r=n,s=o;e.isMatrix(r.getNodeType(e))?s=Oi(Ii(s),0):r=Oi(Ii(r),0);const i=kn(r,s).xyz;return Ro(i).build(e,t)}if(r===ao.NEGATE)return e.format("( - "+n.build(e,i)+" )",s,t);if(r===ao.ONE_MINUS)return Gn(1,n).build(e,t);if(r===ao.RECIPROCAL)return zn(1,n).build(e,t);if(r===ao.DIFFERENCE)return Po(Gn(n,o)).build(e,t);{const l=[];return r===ao.CROSS||r===ao.MOD?l.push(n.build(e,s),o.build(e,s)):u&&r===ao.STEP?l.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),o.build(e,i)):u&&(r===ao.MIN||r===ao.MAX)||r===ao.MOD?l.push(n.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):r===ao.REFRACT?l.push(n.build(e,i),o.build(e,i),a.build(e,"float")):r===ao.MIX?l.push(n.build(e,i),o.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)):(l.push(n.build(e,i)),null!==o&&l.push(o.build(e,i)),null!==a&&l.push(a.build(e,i))),e.format(`${e.getMethod(r,s)}( ${l.join(", ")} )`,s,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}ao.ALL="all",ao.ANY="any",ao.EQUALS="equals",ao.RADIANS="radians",ao.DEGREES="degrees",ao.EXP="exp",ao.EXP2="exp2",ao.LOG="log",ao.LOG2="log2",ao.SQRT="sqrt",ao.INVERSE_SQRT="inversesqrt",ao.FLOOR="floor",ao.CEIL="ceil",ao.NORMALIZE="normalize",ao.FRACT="fract",ao.SIN="sin",ao.COS="cos",ao.TAN="tan",ao.ASIN="asin",ao.ACOS="acos",ao.ATAN="atan",ao.ABS="abs",ao.SIGN="sign",ao.LENGTH="length",ao.NEGATE="negate",ao.ONE_MINUS="oneMinus",ao.DFDX="dFdx",ao.DFDY="dFdy",ao.ROUND="round",ao.RECIPROCAL="reciprocal",ao.TRUNC="trunc",ao.FWIDTH="fwidth",ao.BITCAST="bitcast",ao.TRANSPOSE="transpose",ao.ATAN2="atan2",ao.MIN="min",ao.MAX="max",ao.MOD="mod",ao.STEP="step",ao.REFLECT="reflect",ao.DISTANCE="distance",ao.DIFFERENCE="difference",ao.DOT="dot",ao.CROSS="cross",ao.POW="pow",ao.TRANSFORM_DIRECTION="transformDirection",ao.MIX="mix",ao.CLAMP="clamp",ao.REFRACT="refract",ao.SMOOTHSTEP="smoothstep",ao.FACEFORWARD="faceforward";const uo=Ci(1e-6),lo=Ci(1e6),co=Ci(Math.PI),ho=Ci(2*Math.PI),po=xi(ao,ao.ALL),go=xi(ao,ao.ANY),mo=xi(ao,ao.EQUALS),fo=xi(ao,ao.RADIANS),yo=xi(ao,ao.DEGREES),bo=xi(ao,ao.EXP),xo=xi(ao,ao.EXP2),To=xi(ao,ao.LOG),_o=xi(ao,ao.LOG2),vo=xi(ao,ao.SQRT),No=xi(ao,ao.INVERSE_SQRT),So=xi(ao,ao.FLOOR),Ao=xi(ao,ao.CEIL),Ro=xi(ao,ao.NORMALIZE),Co=xi(ao,ao.FRACT),Eo=xi(ao,ao.SIN),wo=xi(ao,ao.COS),Mo=xi(ao,ao.TAN),Bo=xi(ao,ao.ASIN),Uo=xi(ao,ao.ACOS),Fo=xi(ao,ao.ATAN),Po=xi(ao,ao.ABS),Io=xi(ao,ao.SIGN),Lo=xi(ao,ao.LENGTH),Do=xi(ao,ao.NEGATE),Vo=xi(ao,ao.ONE_MINUS),Oo=xi(ao,ao.DFDX),Go=xi(ao,ao.DFDY),ko=xi(ao,ao.ROUND),zo=xi(ao,ao.RECIPROCAL),$o=xi(ao,ao.TRUNC),Wo=xi(ao,ao.FWIDTH),Ho=xi(ao,ao.BITCAST),jo=xi(ao,ao.TRANSPOSE),qo=xi(ao,ao.ATAN2),Ko=xi(ao,ao.MIN),Xo=xi(ao,ao.MAX),Yo=xi(ao,ao.MOD),Qo=xi(ao,ao.STEP),Zo=xi(ao,ao.REFLECT),Jo=xi(ao,ao.DISTANCE),ea=xi(ao,ao.DIFFERENCE),ta=xi(ao,ao.DOT),ra=xi(ao,ao.CROSS),sa=xi(ao,ao.POW),ia=xi(ao,ao.POW,2),na=xi(ao,ao.POW,3),oa=xi(ao,ao.POW,4),aa=xi(ao,ao.TRANSFORM_DIRECTION),ua=e=>kn(Io(e),sa(Po(e),1/3)),la=e=>ta(e,e),da=xi(ao,ao.MIX),ca=(e,t=0,r=1)=>fi(new ao(ao.CLAMP,fi(e),fi(t),fi(r))),ha=e=>ca(e),pa=xi(ao,ao.REFRACT),ga=xi(ao,ao.SMOOTHSTEP),ma=xi(ao,ao.FACEFORWARD),fa=_i((([e])=>{const t=ta(e.xy,Bi(12.9898,78.233)),r=Yo(t,co);return Co(Eo(r).mul(43758.5453))})),ya=(e,t,r)=>da(t,r,e),ba=(e,t,r)=>ga(t,r,e);$s("all",po),$s("any",go),$s("equals",mo),$s("radians",fo),$s("degrees",yo),$s("exp",bo),$s("exp2",xo),$s("log",To),$s("log2",_o),$s("sqrt",vo),$s("inverseSqrt",No),$s("floor",So),$s("ceil",Ao),$s("normalize",Ro),$s("fract",Co),$s("sin",Eo),$s("cos",wo),$s("tan",Mo),$s("asin",Bo),$s("acos",Uo),$s("atan",Fo),$s("abs",Po),$s("sign",Io),$s("length",Lo),$s("lengthSq",la),$s("negate",Do),$s("oneMinus",Vo),$s("dFdx",Oo),$s("dFdy",Go),$s("round",ko),$s("reciprocal",zo),$s("trunc",$o),$s("fwidth",Wo),$s("atan2",qo),$s("min",Ko),$s("max",Xo),$s("mod",Yo),$s("step",Qo),$s("reflect",Zo),$s("distance",Jo),$s("dot",ta),$s("cross",ra),$s("pow",sa),$s("pow2",ia),$s("pow3",na),$s("pow4",oa),$s("transformDirection",aa),$s("mix",ya),$s("clamp",ca),$s("refract",pa),$s("smoothstep",ba),$s("faceForward",ma),$s("difference",ea),$s("saturate",ha),$s("cbrt",ua),$s("transpose",jo),$s("rand",fa);class xa extends Ms{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const r=this.elseNode.getNodeType(e);if(e.getTypeLength(r)>e.getTypeLength(t))return r}return t}setup(e){const t=this.condNode.cache(),r=this.ifNode.cache(),s=this.elseNode?this.elseNode.cache():null,i=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=i,null!==s&&(e.getDataFromNode(s).parentNodeBlock=i);const n=e.getNodeProperties(this);n.condNode=t,n.ifNode=r.context({nodeBlock:r}),n.elseNode=s?s.context({nodeBlock:s}):null}generate(e,t){const r=this.getNodeType(e),s=e.getDataFromNode(this);if(void 0!==s.nodeProperty)return s.nodeProperty;const{condNode:i,ifNode:n,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?sn(r).build(e):"";s.nodeProperty=u;const l=i.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=n.build(e,r);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,r);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,r,t)}}const Ta=xi(xa);$s("select",Ta);const _a=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),Ta(...e));$s("cond",_a);class va extends Ms{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e);return e.setContext(t),r}generate(e,t){const r=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e,t);return e.setContext(r),s}}const Na=xi(va),Sa=(e,t)=>Na(e,{label:t});$s("context",Na),$s("label",Sa);class Aa extends Ms{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:r}=this,s=e.getVarFromNode(this,r,e.getVectorType(this.getNodeType(e))),i=e.getPropertyName(s),n=t.build(e,s.type);return e.addLineFlowCode(`${i} = ${n}`,this),i}}const Ra=xi(Aa);$s("toVar",((...e)=>Ra(...e).append()));const Ca=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Ra(e));$s("temp",Ca);class Ea extends Ms{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let r=t.varying;if(void 0===r){const s=this.name,i=this.getNodeType(e);t.varying=r=e.getVaryingFromNode(this,s,i),t.node=this.node}return r.needsInterpolation||(r.needsInterpolation="fragment"===e.shaderStage),r}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),r=this.setupVarying(e);if(void 0===t.propertyName){const s=this.getNodeType(e),i=e.getPropertyName(r,_s.VERTEX);e.flowNodeFromShaderStage(_s.VERTEX,this.node,s,i),t.propertyName=i}return e.getPropertyName(r)}}const wa=xi(Ea);$s("varying",wa);const Ma=_i((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),r=e.mul(.0773993808),s=e.lessThanEqual(.04045);return da(t,r,s)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba=_i((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),r=e.mul(12.92),s=e.lessThanEqual(.0031308);return da(t,r,s)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ua="WorkingColorSpace",Fa="OutputColorSpace";class Pa extends Fs{static get type(){return"ColorSpaceNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.source=t,this.target=r}resolveColorSpace(e,t){return t===Ua?u.workingColorSpace:t===Fa?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,r=this.resolveColorSpace(e,this.source),s=this.resolveColorSpace(e,this.target);let n=t;return!1!==u.enabled&&r!==s&&r&&s?(u.getTransfer(r)===l&&(n=Oi(Ma(n.rgb),n.a)),u.getPrimaries(r)!==u.getPrimaries(s)&&(n=Oi(Wi(u._getMatrix(new i,r,s)).mul(n.rgb),n.a)),u.getTransfer(s)===l&&(n=Oi(Ba(n.rgb),n.a)),n):n}}const Ia=e=>fi(new Pa(fi(e),Ua,Fa)),La=e=>fi(new Pa(fi(e),Fa,Ua)),Da=(e,t)=>fi(new Pa(fi(e),Ua,t)),Va=(e,t)=>fi(new Pa(fi(e),t,Ua));$s("toOutputColorSpace",Ia),$s("toWorkingColorSpace",La),$s("workingToColorSpace",Da),$s("colorSpaceToWorking",Va);let Oa=class extends Bs{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),r=this.referenceNode.getNodeType(),s=this.getNodeType();return e.format(t,r,s)}};class Ga extends Ms{static get type(){return"ReferenceBaseNode"}constructor(e,t,r=null,s=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=s,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.updateType=vs.OBJECT}setGroup(e){return this.group=e,this}element(e){return fi(new Oa(this,fi(e)))}setNodeType(e){const t=tn(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let r=e[t[0]];for(let e=1;efi(new ka(e,t,r));class $a extends Fs{static get type(){return"ToneMappingNode"}constructor(e,t=Ha,r=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=r}getCacheKey(){return ds(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,r=this.toneMapping;if(r===d)return t;let s=null;const i=e.renderer.library.getToneMappingFunction(r);return null!==i?s=Oi(i(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",r),s=t),s}}const Wa=(e,t,r)=>fi(new $a(e,fi(t),fi(r))),Ha=za("toneMappingExposure","float");$s("toneMapping",((e,t,r)=>Wa(t,r,e)));class ja extends Os{static get type(){return"BufferAttributeNode"}constructor(e,t=null,r=0,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=r,this.bufferOffset=s,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),r=this.value,s=e.getTypeLength(t),i=this.bufferStride||s,n=this.bufferOffset,o=!0===r.isInterleavedBuffer?r:new h(r,i),a=new g(o,s,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),r=e.getBufferAttributeFromNode(this,t),s=e.getPropertyName(r);let i=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=s,i=s;else{i=wa(this).build(e,t)}return i}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,r,s)=>fi(new ja(e,t,r,s)),Ka=(e,t,r,s)=>qa(e,t,r,s).setUsage(p),Xa=(e,t,r,s)=>qa(e,t,r,s).setInstanced(!0),Ya=(e,t,r,s)=>Ka(e,t,r,s).setInstanced(!0);$s("toAttribute",(e=>qa(e.value)));class Qa extends Ms{static get type(){return"ComputeNode"}constructor(e,t,r=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=r,this.dispatchCount=0,this.version=1,this.updateBeforeType=vs.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let r=t[0];for(let e=1;efi(new Qa(fi(e),t,r));$s("compute",Za);class Ja extends Ms{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const r=e.getCache(),s=e.getCacheFromNode(this,this.parent);e.setCache(s);const i=this.node.build(e,...t);return e.setCache(r),i}}const eu=(e,...t)=>fi(new Ja(fi(e),...t));$s("cache",eu);class tu extends Ms{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const ru=xi(tu);$s("bypass",ru);class su extends Ms{static get type(){return"RemapNode"}constructor(e,t,r,s=Ci(0),i=Ci(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=r,this.outLowNode=s,this.outHighNode=i,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:r,outLowNode:s,outHighNode:i,doClamp:n}=this;let o=e.sub(t).div(r.sub(t));return!0===n&&(o=o.clamp()),o.mul(i.sub(s)).add(s)}}const iu=xi(su,null,null,{doClamp:!1}),nu=xi(su);$s("remap",iu),$s("remapClamp",nu);class ou extends Ms{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const r=this.getNodeType(e),s=this.snippet;if("void"!==r)return e.format(`( ${s} )`,r,t);e.addLineFlowCode(s,this)}}const au=xi(ou),uu=e=>(e?Ta(e,au("discard")):au("discard")).append();$s("discard",uu);class lu extends Fs{static get type(){return"RenderOutputNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=r,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const r=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,s=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return r!==d&&(t=t.toneMapping(r)),s!==m&&s!==u.workingColorSpace&&(t=t.workingToColorSpace(s)),t}}const du=(e,t=null,r=null)=>fi(new lu(fi(e),t,r));$s("renderOutput",du);class cu extends Ms{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const r=this.getAttributeName(e);if(e.hasGeometryAttribute(r)){const s=e.geometry.getAttribute(r);t=e.getTypeFromAttribute(s)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),r=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const s=e.geometry.getAttribute(t),i=e.getTypeFromAttribute(s),n=e.getAttribute(t,i);if("vertex"===e.shaderStage)return e.format(n.name,i,r);return wa(this).build(e,r)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(r)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const hu=(e,t)=>fi(new cu(e,t)),pu=e=>hu("uv"+(e>0?e:""),"vec2");class gu extends Ms{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const r=this.textureNode.build(e,"property"),s=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${r}, ${s} )`,this.getNodeType(e),t)}}const mu=xi(gu);class fu extends en{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=vs.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,r=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(r&&void 0!==r.width){const{width:e,height:t}=r;this.value=Math.log2(Math.max(e,t))}}}const yu=xi(fu);class bu extends en{static get type(){return"TextureNode"}constructor(e,t=null,r=null,s=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=r,this.biasNode=s,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=vs.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return pu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=tn(this.value.matrix)),this._matrixUniform.mul(Ii(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?vs.FRAME:vs.NONE,this}setupUV(e,t){const r=this.value;return e.isFlipY()&&(r.image instanceof ImageBitmap&&!0===r.flipY||!0===r.isRenderTargetTexture||!0===r.isFramebufferTexture||!0===r.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(Ei(mu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let r=this.uvNode;null!==r&&!0!==e.context.forceUVContext||!e.context.getUV||(r=e.context.getUV(this)),r||(r=this.getDefaultUV()),!0===this.updateMatrix&&(r=this.getTransformedUV(r)),r=this.setupUV(e,r);let s=this.levelNode;null===s&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this)),t.uvNode=r,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,r,s,i,n,o,a){const u=this.value;let l;return l=s?e.generateTextureLevel(u,t,r,s,n):i?e.generateTextureBias(u,t,r,i,n):a?e.generateTextureGrad(u,t,r,a,n):o?e.generateTextureCompare(u,t,r,o,n):!1===this.sampler?e.generateTextureLoad(u,t,r,n):e.generateTexture(u,t,r,n),l}generate(e,t){const r=e.getNodeProperties(this),s=this.value;if(!s||!0!==s.isTexture)throw new Error("TextureNode: Need a three.js texture.");const i=super.generate(e,"property");if("sampler"===t)return i+"_sampler";if(e.isReference(t))return i;{const n=e.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:t,levelNode:s,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=r,c=this.generateUV(e,t),h=s?s.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,i,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),n.snippet=b,n.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(s)&&(a=Va(au(a,u),s.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=fi(e),t.referenceNode=this.getSelf(),fi(t)}blur(e){const t=this.clone();return t.biasNode=fi(e).mul(yu(t)),t.referenceNode=this.getSelf(),fi(t)}level(e){const t=this.clone();return t.levelNode=fi(e),t.referenceNode=this.getSelf(),fi(t)}size(e){return mu(this,e)}bias(e){const t=this.clone();return t.biasNode=fi(e),t.referenceNode=this.getSelf(),fi(t)}compare(e){const t=this.clone();return t.compareNode=fi(e),t.referenceNode=this.getSelf(),fi(t)}grad(e,t){const r=this.clone();return r.gradNode=[fi(e),fi(t)],r.referenceNode=this.getSelf(),fi(r)}depth(e){const t=this.clone();return t.depthNode=fi(e),t.referenceNode=this.getSelf(),fi(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const xu=xi(bu),Tu=(...e)=>xu(...e).setSampler(!1),_u=tn("float").label("cameraNear").setGroup(Zi).onRenderUpdate((({camera:e})=>e.near)),vu=tn("float").label("cameraFar").setGroup(Zi).onRenderUpdate((({camera:e})=>e.far)),Nu=tn("mat4").label("cameraProjectionMatrix").setGroup(Zi).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Su=tn("mat4").label("cameraProjectionMatrixInverse").setGroup(Zi).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Au=tn("mat4").label("cameraViewMatrix").setGroup(Zi).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),Ru=tn("mat4").label("cameraWorldMatrix").setGroup(Zi).onRenderUpdate((({camera:e})=>e.matrixWorld)),Cu=tn("mat3").label("cameraNormalMatrix").setGroup(Zi).onRenderUpdate((({camera:e})=>e.normalMatrix)),Eu=tn(new r).label("cameraPosition").setGroup(Zi).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class wu extends Ms{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=vs.OBJECT,this._uniformNode=new en(null)}getNodeType(){const e=this.scope;return e===wu.WORLD_MATRIX?"mat4":e===wu.POSITION||e===wu.VIEW_POSITION||e===wu.DIRECTION||e===wu.SCALE?"vec3":void 0}update(e){const t=this.object3d,s=this._uniformNode,i=this.scope;if(i===wu.WORLD_MATRIX)s.value=t.matrixWorld;else if(i===wu.POSITION)s.value=s.value||new r,s.value.setFromMatrixPosition(t.matrixWorld);else if(i===wu.SCALE)s.value=s.value||new r,s.value.setFromMatrixScale(t.matrixWorld);else if(i===wu.DIRECTION)s.value=s.value||new r,t.getWorldDirection(s.value);else if(i===wu.VIEW_POSITION){const i=e.camera;s.value=s.value||new r,s.value.setFromMatrixPosition(t.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(e){const t=this.scope;return t===wu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==wu.POSITION&&t!==wu.VIEW_POSITION&&t!==wu.DIRECTION&&t!==wu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}wu.WORLD_MATRIX="worldMatrix",wu.POSITION="position",wu.SCALE="scale",wu.VIEW_POSITION="viewPosition",wu.DIRECTION="direction";const Mu=xi(wu,wu.DIRECTION),Bu=xi(wu,wu.WORLD_MATRIX),Uu=xi(wu,wu.POSITION),Fu=xi(wu,wu.SCALE),Pu=xi(wu,wu.VIEW_POSITION);class Iu extends wu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Lu=Ti(Iu,Iu.DIRECTION),Du=Ti(Iu,Iu.WORLD_MATRIX),Vu=Ti(Iu,Iu.POSITION),Ou=Ti(Iu,Iu.SCALE),Gu=Ti(Iu,Iu.VIEW_POSITION),ku=tn(new i).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),zu=tn(new n).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),$u=Au.mul(Du).toVar("modelViewMatrix"),Wu=_i((e=>(e.context.isHighPrecisionModelViewMatrix=!0,tn("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Hu=_i((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return tn("mat3").onObjectUpdate((({object:e,camera:r})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),ju=hu("position","vec3"),qu=ju.varying("positionLocal"),Ku=ju.varying("positionPrevious"),Xu=Du.mul(qu).xyz.varying("v_positionWorld"),Yu=qu.transformDirection(Du).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),Qu=$u.mul(qu).xyz.varying("v_positionView"),Zu=Qu.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class Ju extends Ms{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:r}=e;return t.coordinateSystem===b&&r.side===x?"false":e.getFrontFacing()}}const el=Ti(Ju),tl=Ci(el).mul(2).sub(1),rl=hu("normal","vec3"),sl=_i((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Ii(0,1,0)):rl),"vec3").once()().toVar("normalLocal"),il=Qu.dFdx().cross(Qu.dFdy()).normalize().toVar("normalFlat"),nl=_i((e=>{let t;return t=!0===e.material.flatShading?il:wa(cl(sl),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ol=wa(nl.transformDirection(Au),"v_normalWorld").normalize().toVar("normalWorld"),al=_i((e=>e.context.setupNormal()),"vec3").once()().mul(tl).toVar("transformedNormalView"),ul=al.transformDirection(Au).toVar("transformedNormalWorld"),ll=_i((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(tl).toVar("transformedClearcoatNormalView"),dl=_i((([e,t=Du])=>{const r=Wi(t),s=e.div(Ii(r[0].dot(r[0]),r[1].dot(r[1]),r[2].dot(r[2])));return r.mul(s).xyz})),cl=_i((([e],t)=>{const r=t.renderer.nodes.modelNormalViewMatrix;if(null!==r)return r.transformDirection(e);const s=ku.mul(e);return Au.transformDirection(s)})),hl=tn(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),pl=Zu.negate().reflect(al),gl=Zu.negate().refract(al,hl),ml=pl.transformDirection(Au).toVar("reflectVector"),fl=gl.transformDirection(Au).toVar("reflectVector");class yl extends bu{static get type(){return"CubeTextureNode"}constructor(e,t=null,r=null,s=null){super(e,t,r,s),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?ml:e.mapping===_?fl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Ii(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const r=this.value;return e.renderer.coordinateSystem!==v&&r.isRenderTargetTexture?t:Ii(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const bl=xi(yl);class xl extends en{static get type(){return"BufferNode"}constructor(e,t,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=r}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const Tl=(e,t,r)=>fi(new xl(e,t,r));class _l extends Bs{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),r=this.getNodeType();return e.format(t,"vec4",r)}}class vl extends xl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=vs.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,r=this.getElementLength(),s=this.getElementType();if(1===r)for(let r=0;rfi(new vl(e,t));class Sl extends Bs{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),r=this.referenceNode.getNodeType(),s=this.getNodeType();return e.format(t,r,s)}}class Al extends Ms{static get type(){return"ReferenceNode"}constructor(e,t,r=null,s=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=s,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.name=null,this.updateType=vs.OBJECT}element(e){return fi(new Sl(this,fi(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?Tl(null,e,this.count):Array.isArray(this.getValueFromReference())?Nl(null,e):"texture"===e?xu(null):"cubeTexture"===e?bl(null):tn(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let r=e[t[0]];for(let e=1;efi(new Al(e,t,r)),Cl=(e,t,r,s)=>fi(new Al(e,t,s,r));class El extends Al{static get type(){return"MaterialReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.material=r,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const wl=(e,t,r)=>fi(new El(e,t,r)),Ml=_i((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),hu("tangent","vec4"))))(),Bl=Ml.xyz.toVar("tangentLocal"),Ul=$u.mul(Oi(Bl,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Fl=Ul.transformDirection(Au).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Pl=Ul.toVar("transformedTangentView"),Il=Pl.transformDirection(Au).normalize().toVar("transformedTangentWorld"),Ll=e=>e.mul(Ml.w).xyz,Dl=wa(Ll(rl.cross(Ml)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),Vl=wa(Ll(sl.cross(Bl)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),Ol=wa(Ll(nl.cross(Ul)),"v_bitangentView").normalize().toVar("bitangentView"),Gl=wa(Ll(ol.cross(Fl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),kl=Ll(al.cross(Pl)).normalize().toVar("transformedBitangentView"),zl=kl.transformDirection(Au).normalize().toVar("transformedBitangentWorld"),$l=Wi(Ul,Ol,nl),Wl=Zu.mul($l),Hl=(()=>{let e=Tn.cross(Zu);return e=e.cross(Tn).normalize(),e=da(e,al,bn.mul(un.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),jl=_i((e=>{const{eye_pos:t,surf_norm:r,mapN:s,uv:i}=e,n=t.dFdx(),o=t.dFdy(),a=i.dFdx(),u=i.dFdy(),l=r,d=o.cross(l),c=l.cross(n),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=tl.mul(g.inverseSqrt());return On(h.mul(s.x,m),p.mul(s.y,m),l.mul(s.z)).normalize()}));class ql extends Fs{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=N}setup(e){const{normalMapType:t,scaleNode:r}=this;let s=this.node.mul(2).sub(1);null!==r&&(s=Ii(s.xy.mul(r),s.z));let i=null;if(t===S)i=cl(s);else if(t===N){i=!0===e.hasGeometryAttribute("tangent")?$l.mul(s).normalize():jl({eye_pos:Qu,surf_norm:nl,mapN:s,uv:pu()})}return i}}const Kl=xi(ql),Xl=_i((({textureNode:e,bumpScale:t})=>{const r=t=>e.cache().context({getUV:e=>t(e.uvNode||pu()),forceUVContext:!0}),s=Ci(r((e=>e)));return Bi(Ci(r((e=>e.add(e.dFdx())))).sub(s),Ci(r((e=>e.add(e.dFdy())))).sub(s)).mul(t)})),Yl=_i((e=>{const{surf_pos:t,surf_norm:r,dHdxy:s}=e,i=t.dFdx().normalize(),n=r,o=t.dFdy().normalize().cross(n),a=n.cross(i),u=i.dot(o).mul(tl),l=u.sign().mul(s.x.mul(o).add(s.y.mul(a)));return u.abs().mul(r).sub(l).normalize()}));class Ql extends Fs{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=Xl({textureNode:this.textureNode,bumpScale:e});return Yl({surf_pos:Qu,surf_norm:nl,dHdxy:t})}}const Zl=xi(Ql),Jl=new Map;class ed extends Ms{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let r=Jl.get(e);return void 0===r&&(r=wl(e,t),Jl.set(e,r)),r}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,r=this.scope;let s=null;if(r===ed.COLOR){const e=void 0!==t.color?this.getColor(r):Ii();s=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(r===ed.OPACITY){const e=this.getFloat(r);s=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(r===ed.SPECULAR_STRENGTH)s=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Ci(1);else if(r===ed.SPECULAR_INTENSITY){const e=this.getFloat(r);s=t.specularMap?e.mul(this.getTexture(r).a):e}else if(r===ed.SPECULAR_COLOR){const e=this.getColor(r);s=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(r).rgb):e}else if(r===ed.ROUGHNESS){const e=this.getFloat(r);s=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(r).g):e}else if(r===ed.METALNESS){const e=this.getFloat(r);s=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(r).b):e}else if(r===ed.EMISSIVE){const e=this.getFloat("emissiveIntensity"),i=this.getColor(r).mul(e);s=t.emissiveMap&&!0===t.emissiveMap.isTexture?i.mul(this.getTexture(r)):i}else if(r===ed.NORMAL)t.normalMap?(s=Kl(this.getTexture("normal"),this.getCache("normalScale","vec2")),s.normalMapType=t.normalMapType):s=t.bumpMap?Zl(this.getTexture("bump").r,this.getFloat("bumpScale")):nl;else if(r===ed.CLEARCOAT){const e=this.getFloat(r);s=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===ed.CLEARCOAT_ROUGHNESS){const e=this.getFloat(r);s=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===ed.CLEARCOAT_NORMAL)s=t.clearcoatNormalMap?Kl(this.getTexture(r),this.getCache(r+"Scale","vec2")):nl;else if(r===ed.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));s=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(r===ed.SHEEN_ROUGHNESS){const e=this.getFloat(r);s=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(r).a):e,s=s.clamp(.07,1)}else if(r===ed.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(r);s=$i(Vd.x,Vd.y,Vd.y.negate(),Vd.x).mul(e.rg.mul(2).sub(Bi(1)).normalize().mul(e.b))}else s=Vd;else if(r===ed.IRIDESCENCE_THICKNESS){const e=Rl("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const i=Rl("0","float",t.iridescenceThicknessRange);s=e.sub(i).mul(this.getTexture(r).g).add(i)}else s=e}else if(r===ed.TRANSMISSION){const e=this.getFloat(r);s=t.transmissionMap?e.mul(this.getTexture(r).r):e}else if(r===ed.THICKNESS){const e=this.getFloat(r);s=t.thicknessMap?e.mul(this.getTexture(r).g):e}else if(r===ed.IOR)s=this.getFloat(r);else if(r===ed.LIGHT_MAP)s=this.getTexture(r).rgb.mul(this.getFloat("lightMapIntensity"));else if(r===ed.AO_MAP)s=this.getTexture(r).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);s=this.getCache(r,t)}return s}}ed.ALPHA_TEST="alphaTest",ed.COLOR="color",ed.OPACITY="opacity",ed.SHININESS="shininess",ed.SPECULAR="specular",ed.SPECULAR_STRENGTH="specularStrength",ed.SPECULAR_INTENSITY="specularIntensity",ed.SPECULAR_COLOR="specularColor",ed.REFLECTIVITY="reflectivity",ed.ROUGHNESS="roughness",ed.METALNESS="metalness",ed.NORMAL="normal",ed.CLEARCOAT="clearcoat",ed.CLEARCOAT_ROUGHNESS="clearcoatRoughness",ed.CLEARCOAT_NORMAL="clearcoatNormal",ed.EMISSIVE="emissive",ed.ROTATION="rotation",ed.SHEEN="sheen",ed.SHEEN_ROUGHNESS="sheenRoughness",ed.ANISOTROPY="anisotropy",ed.IRIDESCENCE="iridescence",ed.IRIDESCENCE_IOR="iridescenceIOR",ed.IRIDESCENCE_THICKNESS="iridescenceThickness",ed.IOR="ior",ed.TRANSMISSION="transmission",ed.THICKNESS="thickness",ed.ATTENUATION_DISTANCE="attenuationDistance",ed.ATTENUATION_COLOR="attenuationColor",ed.LINE_SCALE="scale",ed.LINE_DASH_SIZE="dashSize",ed.LINE_GAP_SIZE="gapSize",ed.LINE_WIDTH="linewidth",ed.LINE_DASH_OFFSET="dashOffset",ed.POINT_WIDTH="pointWidth",ed.DISPERSION="dispersion",ed.LIGHT_MAP="light",ed.AO_MAP="ao";const td=Ti(ed,ed.ALPHA_TEST),rd=Ti(ed,ed.COLOR),sd=Ti(ed,ed.SHININESS),id=Ti(ed,ed.EMISSIVE),nd=Ti(ed,ed.OPACITY),od=Ti(ed,ed.SPECULAR),ad=Ti(ed,ed.SPECULAR_INTENSITY),ud=Ti(ed,ed.SPECULAR_COLOR),ld=Ti(ed,ed.SPECULAR_STRENGTH),dd=Ti(ed,ed.REFLECTIVITY),cd=Ti(ed,ed.ROUGHNESS),hd=Ti(ed,ed.METALNESS),pd=Ti(ed,ed.NORMAL).context({getUV:null}),gd=Ti(ed,ed.CLEARCOAT),md=Ti(ed,ed.CLEARCOAT_ROUGHNESS),fd=Ti(ed,ed.CLEARCOAT_NORMAL).context({getUV:null}),yd=Ti(ed,ed.ROTATION),bd=Ti(ed,ed.SHEEN),xd=Ti(ed,ed.SHEEN_ROUGHNESS),Td=Ti(ed,ed.ANISOTROPY),_d=Ti(ed,ed.IRIDESCENCE),vd=Ti(ed,ed.IRIDESCENCE_IOR),Nd=Ti(ed,ed.IRIDESCENCE_THICKNESS),Sd=Ti(ed,ed.TRANSMISSION),Ad=Ti(ed,ed.THICKNESS),Rd=Ti(ed,ed.IOR),Cd=Ti(ed,ed.ATTENUATION_DISTANCE),Ed=Ti(ed,ed.ATTENUATION_COLOR),wd=Ti(ed,ed.LINE_SCALE),Md=Ti(ed,ed.LINE_DASH_SIZE),Bd=Ti(ed,ed.LINE_GAP_SIZE),Ud=Ti(ed,ed.LINE_WIDTH),Fd=Ti(ed,ed.LINE_DASH_OFFSET),Pd=Ti(ed,ed.POINT_WIDTH),Id=Ti(ed,ed.DISPERSION),Ld=Ti(ed,ed.LIGHT_MAP),Dd=Ti(ed,ed.AO_MAP),Vd=tn(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Od extends Fs{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return wa(e.context.mvp);const t=this.positionNode||qu,r=e.renderer.nodes.modelViewMatrix||$u;return Nu.mul(r).mul(t)}}const Gd=xi(Od);class kd extends Ms{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),r=this.scope;let s,i;if(r===kd.VERTEX)s=e.getVertexIndex();else if(r===kd.INSTANCE)s=e.getInstanceIndex();else if(r===kd.DRAW)s=e.getDrawIndex();else if(r===kd.INVOCATION_LOCAL)s=e.getInvocationLocalIndex();else if(r===kd.INVOCATION_SUBGROUP)s=e.getInvocationSubgroupIndex();else{if(r!==kd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+r);s=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)i=s;else{i=wa(this).build(e,t)}return i}}kd.VERTEX="vertex",kd.INSTANCE="instance",kd.SUBGROUP="subgroup",kd.INVOCATION_LOCAL="invocationLocal",kd.INVOCATION_SUBGROUP="invocationSubgroup",kd.DRAW="draw";const zd=Ti(kd,kd.VERTEX),$d=Ti(kd,kd.INSTANCE),Wd=Ti(kd,kd.SUBGROUP),Hd=Ti(kd,kd.INVOCATION_SUBGROUP),jd=Ti(kd,kd.INVOCATION_LOCAL),qd=Ti(kd,kd.DRAW);class Kd extends Ms{static get type(){return"InstanceNode"}constructor(e,t,r){super("void"),this.count=e,this.instanceMatrix=t,this.instanceColor=r,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=vs.FRAME,this.buffer=null,this.bufferColor=null}setup(e){const{count:t,instanceMatrix:r,instanceColor:s}=this;let{instanceMatrixNode:i,instanceColorNode:n}=this;if(null===i){if(t<=1e3)i=Tl(r.array,"mat4",Math.max(t,1)).element($d);else{const e=new A(r.array,16,1);this.buffer=e;const t=r.usage===p?Ya:Xa,s=[t(e,"vec4",16,0),t(e,"vec4",16,4),t(e,"vec4",16,8),t(e,"vec4",16,12)];i=Hi(...s)}this.instanceMatrixNode=i}if(s&&null===n){const e=new R(s.array,3),t=s.usage===p?Ya:Xa;this.bufferColor=e,n=Ii(t(e,"vec3",3,0)),this.instanceColorNode=n}const o=i.mul(qu).xyz;if(qu.assign(o),e.hasGeometryAttribute("normal")){const e=dl(sl,i);sl.assign(e)}null!==this.instanceColorNode&&nn("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMatrix.version),this.instanceColor&&this.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceColor.version)}}const Xd=xi(Kd);class Yd extends Kd{static get type(){return"InstancedMeshNode"}constructor(e){const{count:t,instanceMatrix:r,instanceColor:s}=e;super(t,r,s),this.instanceMesh=e}}const Qd=xi(Yd);class Zd extends Ms{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=$d:this.batchingIdNode=qd);const t=_i((([e])=>{const t=mu(Tu(this.batchMesh._indirectTexture),0),r=Ei(e).modInt(Ei(t)),s=Ei(e).div(Ei(t));return Tu(this.batchMesh._indirectTexture,Ui(r,s)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),r=t(Ei(this.batchingIdNode)),s=this.batchMesh._matricesTexture,i=mu(Tu(s),0),n=Ci(r).mul(4).toInt().toVar(),o=n.modInt(i),a=n.div(Ei(i)),u=Hi(Tu(s,Ui(o,a)),Tu(s,Ui(o.add(1),a)),Tu(s,Ui(o.add(2),a)),Tu(s,Ui(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=_i((([e])=>{const t=mu(Tu(l),0).x,r=e,s=r.modInt(t),i=r.div(t);return Tu(l,Ui(s,i)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(r);nn("vec3","vBatchColor").assign(t)}const d=Wi(u);qu.assign(u.mul(qu));const c=sl.div(Ii(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;sl.assign(h),e.hasGeometryAttribute("tangent")&&Bl.mulAssign(d)}}const Jd=xi(Zd),ec=new WeakMap;class tc extends Ms{static get type(){return"SkinningNode"}constructor(e,t=!1){let r,s,i;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=vs.OBJECT,this.skinIndexNode=hu("skinIndex","uvec4"),this.skinWeightNode=hu("skinWeight","vec4"),t?(r=Rl("bindMatrix","mat4"),s=Rl("bindMatrixInverse","mat4"),i=Cl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(r=tn(e.bindMatrix,"mat4"),s=tn(e.bindMatrixInverse,"mat4"),i=Tl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=r,this.bindMatrixInverseNode=s,this.boneMatricesNode=i,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=qu){const{skinIndexNode:r,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(r.x),a=e.element(r.y),u=e.element(r.z),l=e.element(r.w),d=i.mul(t),c=On(o.mul(s.x).mul(d),a.mul(s.y).mul(d),u.mul(s.z).mul(d),l.mul(s.w).mul(d));return n.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=sl){const{skinIndexNode:r,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(r.x),a=e.element(r.y),u=e.element(r.z),l=e.element(r.w);let d=On(s.x.mul(o),s.y.mul(a),s.z.mul(u),s.w.mul(l));return d=n.mul(d).mul(i),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Cl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Ku)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Ku.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(qu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();sl.assign(t),e.hasGeometryAttribute("tangent")&&Bl.assign(t)}}generate(e,t){if("void"!==t)return qu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;ec.get(t)!==e.frameId&&(ec.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const rc=e=>fi(new tc(e,!0));class sc extends Ms{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const r={};for(let e=0,t=this.params.length-1;eNumber(n)?">=":"<"));const d={start:i,end:n,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const i=s.build(e,"void"),n=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+i);for(let t=0,r=this.params.length-1;tfi(new sc(bi(e,"int"))).append(),nc=()=>au("break").append(),oc=new WeakMap,ac=new s,uc=_i((({bufferMap:e,influence:t,stride:r,width:s,depth:i,offset:n})=>{const o=Ei(zd).mul(r).add(n),a=o.div(s),u=o.sub(a.mul(s));return Tu(e,Ui(u,a)).depth(i).mul(t)}));class lc extends Ms{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=tn(1),this.updateType=vs.OBJECT}setup(e){const{geometry:r}=e,s=void 0!==r.morphAttributes.position,i=r.hasAttribute("normal")&&void 0!==r.morphAttributes.normal,n=r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color,o=void 0!==n?n.length:0,{texture:a,stride:u,size:l}=function(e){const r=void 0!==e.morphAttributes.position,s=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,n=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==n?n.length:0;let a=oc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===r&&(c=1),!0===s&&(c=2),!0===i&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Ci(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Tu(this.mesh.morphTexture,Ui(Ei(e).add(1),Ei($d))).r):t.assign(Rl("morphTargetInfluences","float").element(e).toVar()),!0===s&&qu.addAssign(uc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Ei(0)})),!0===i&&sl.addAssign(uc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Ei(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const dc=xi(lc);class cc extends Ms{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class hc extends cc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class pc extends va{static get type(){return"LightingContextNode"}constructor(e,t=null,r=null,s=null){super(e),this.lightingModel=t,this.backdropNode=r,this.backdropAlphaNode=s,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,r={directDiffuse:Ii().toVar("directDiffuse"),directSpecular:Ii().toVar("directSpecular"),indirectDiffuse:Ii().toVar("indirectDiffuse"),indirectSpecular:Ii().toVar("indirectSpecular")};return{radiance:Ii().toVar("radiance"),irradiance:Ii().toVar("irradiance"),iblIrradiance:Ii().toVar("iblIrradiance"),ambientOcclusion:Ci(1).toVar("ambientOcclusion"),reflectedLight:r,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const gc=xi(pc);class mc extends cc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let fc,yc;class bc extends Ms{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===bc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=vs.NONE;return this.scope!==bc.SIZE&&this.scope!==bc.VIEWPORT||(e=vs.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===bc.VIEWPORT?null!==t?yc.copy(t.viewport):(e.getViewport(yc),yc.multiplyScalar(e.getPixelRatio())):null!==t?(fc.width=t.width,fc.height=t.height):e.getDrawingBufferSize(fc)}setup(){const e=this.scope;let r=null;return r=e===bc.SIZE?tn(fc||(fc=new t)):e===bc.VIEWPORT?tn(yc||(yc=new s)):Bi(_c.div(Tc)),r}generate(e){if(this.scope===bc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const r=e.getNodeProperties(Tc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${r}.y - ${t}.y )`}return t}return super.generate(e)}}bc.COORDINATE="coordinate",bc.VIEWPORT="viewport",bc.SIZE="size",bc.UV="uv";const xc=Ti(bc,bc.UV),Tc=Ti(bc,bc.SIZE),_c=Ti(bc,bc.COORDINATE),vc=Ti(bc,bc.VIEWPORT),Nc=vc.zw,Sc=_c.sub(vc.xy),Ac=Sc.div(Nc),Rc=_i((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Tc)),"vec2").once()(),Cc=_i((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),xc)),"vec2").once()(),Ec=_i((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),xc.flipY())),"vec2").once()(),wc=new t;class Mc extends bu{static get type(){return"ViewportTextureNode"}constructor(e=xc,t=null,r=null){null===r&&((r=new w).minFilter=M),super(r,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=vs.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(wc);const r=this.value;r.image.width===wc.width&&r.image.height===wc.height||(r.image.width=wc.width,r.image.height=wc.height,r.needsUpdate=!0);const s=r.generateMipmaps;r.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(r),r.generateMipmaps=s}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Bc=xi(Mc),Uc=xi(Mc,null,null,{generateMipmaps:!0});let Fc=null;class Pc extends Mc{static get type(){return"ViewportDepthTextureNode"}constructor(e=xc,t=null){null===Fc&&(Fc=new B),super(e,t,Fc)}}const Ic=xi(Pc);class Lc extends Ms{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===Lc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,r=this.valueNode;let s=null;if(t===Lc.DEPTH_BASE)null!==r&&(s=kc().assign(r));else if(t===Lc.DEPTH)s=e.isPerspectiveCamera?Vc(Qu.z,_u,vu):Dc(Qu.z,_u,vu);else if(t===Lc.LINEAR_DEPTH)if(null!==r)if(e.isPerspectiveCamera){const e=Oc(r,_u,vu);s=Dc(e,_u,vu)}else s=r;else s=Dc(Qu.z,_u,vu);return s}}Lc.DEPTH_BASE="depthBase",Lc.DEPTH="depth",Lc.LINEAR_DEPTH="linearDepth";const Dc=(e,t,r)=>e.add(t).div(t.sub(r)),Vc=(e,t,r)=>t.add(e).mul(r).div(r.sub(t).mul(e)),Oc=(e,t,r)=>t.mul(r).div(r.sub(t).mul(e).sub(r)),Gc=(e,t,r)=>{t=t.max(1e-6).toVar();const s=_o(e.negate().div(t)),i=_o(r.div(t));return s.div(i)},kc=xi(Lc,Lc.DEPTH_BASE),zc=Ti(Lc,Lc.DEPTH),$c=xi(Lc,Lc.LINEAR_DEPTH),Wc=$c(Ic());zc.assign=e=>kc(e);const Hc=xi(class extends Ms{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class jc extends Ms{static get type(){return"ClippingNode"}constructor(e=jc.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:r,unionPlanes:s}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===jc.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(r,s):this.scope===jc.HARDWARE?this.setupHardwareClipping(s,e):this.setupDefault(r,s)}setupAlphaToCoverage(e,t){return _i((()=>{const r=Ci().toVar("distanceToPlane"),s=Ci().toVar("distanceToGradient"),i=Ci(1).toVar("clipOpacity"),n=t.length;if(!this.hardwareClipping&&n>0){const e=Nl(t);ic(n,(({i:t})=>{const n=e.element(t);r.assign(Qu.dot(n.xyz).negate().add(n.w)),s.assign(r.fwidth().div(2)),i.mulAssign(ga(s.negate(),s,r))}))}const o=e.length;if(o>0){const t=Nl(e),n=Ci(1).toVar("intersectionClipOpacity");ic(o,(({i:e})=>{const i=t.element(e);r.assign(Qu.dot(i.xyz).negate().add(i.w)),s.assign(r.fwidth().div(2)),n.mulAssign(ga(s.negate(),s,r).oneMinus())})),i.mulAssign(n.oneMinus())}on.a.mulAssign(i),on.a.equal(0).discard()}))()}setupDefault(e,t){return _i((()=>{const r=t.length;if(!this.hardwareClipping&&r>0){const e=Nl(t);ic(r,(({i:t})=>{const r=e.element(t);Qu.dot(r.xyz).greaterThan(r.w).discard()}))}const s=e.length;if(s>0){const t=Nl(e),r=Mi(!0).toVar("clipped");ic(s,(({i:e})=>{const s=t.element(e);r.assign(Qu.dot(s.xyz).greaterThan(s.w).and(r))})),r.discard()}}))()}setupHardwareClipping(e,t){const r=e.length;return t.enableHardwareClipping(r),_i((()=>{const s=Nl(e),i=Hc(t.getClipDistance());ic(r,(({i:e})=>{const t=s.element(e),r=Qu.dot(t.xyz).sub(t.w).negate();i.element(e).assign(r)}))}))()}}jc.ALPHA_TO_COVERAGE="alphaToCoverage",jc.DEFAULT="default",jc.HARDWARE="hardware";const qc=_i((([e])=>Co(kn(1e4,Eo(kn(17,e.x).add(kn(.1,e.y)))).mul(On(.1,Po(Eo(kn(13,e.y).add(e.x)))))))),Kc=_i((([e])=>qc(Bi(qc(e.xy),e.z)))),Xc=_i((([e])=>{const t=Xo(Lo(Oo(e.xyz)),Lo(Go(e.xyz))),r=Ci(1).div(Ci(.05).mul(t)).toVar("pixScale"),s=Bi(xo(So(_o(r))),xo(Ao(_o(r)))),i=Bi(Kc(So(s.x.mul(e.xyz))),Kc(So(s.y.mul(e.xyz)))),n=Co(_o(r)),o=On(kn(n.oneMinus(),i.x),kn(n,i.y)),a=Ko(n,n.oneMinus()),u=Ii(o.mul(o).div(kn(2,a).mul(Gn(1,a))),o.sub(kn(.5,a)).div(Gn(1,a)),Gn(1,Gn(1,o).mul(Gn(1,o)).div(kn(2,a).mul(Gn(1,a))))),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return ca(l,1e-6,1)})).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class Yc extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+cs(this)}build(e){this.setup(e)}setupObserver(e){return new os(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,r=t.getRenderTarget();let s;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const i=this.setupClipping(e);if(!0===this.depthWrite&&(null!==r?!0===r.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const n=this.setupLighting(e);null!==i&&e.stack.add(i);const o=Oi(n,on.a).max(0);if(s=this.setupOutput(e,o),Sn.assign(s),null!==this.outputNode&&(s=this.outputNode),null!==r){const e=t.getMRT(),r=this.mrtNode;null!==e?(s=e,null!==r&&(s=e.merge(r))):null!==r&&(s=r)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Oi(t)),s=this.setupOutput(e,t)}e.stack.outputNode=s,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:r}=e.clippingContext;let s=null;if(t.length>0||r.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?s=fi(new jc(jc.ALPHA_TO_COVERAGE)):e.stack.add(fi(new jc))}return s}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(fi(new jc(jc.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:r}=e;let s=this.depthNode;if(null===s){const e=t.getMRT();e&&e.has("depth")?s=e.get("depth"):!0===t.logarithmicDepthBuffer&&(s=r.isPerspectiveCamera?Gc(Qu.z,_u,vu):Dc(Qu.z,_u,vu))}null!==s&&zc.assign(s).append()}setupPosition(e){const{object:t}=e,r=t.geometry;if(e.addStack(),(r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color)&&dc(t).append(),!0===t.isSkinnedMesh&&rc(t).append(),this.displacementMap){const e=wl("displacementMap","texture"),t=wl("displacementScale","float"),r=wl("displacementBias","float");qu.addAssign(sl.normalize().mul(e.x.mul(t).add(r)))}t.isBatchedMesh&&Jd(t).append(),t.isInstancedMesh&&t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&Qd(t).append(),null!==this.positionNode&&qu.assign(this.positionNode),this.setupHardwareClipping(e);const s=Gd();return e.context.vertex=e.removeStack(),e.context.mvp=s,s}setupDiffuseColor({object:e,geometry:t}){let r=this.colorNode?Oi(this.colorNode):rd;if(!0===this.vertexColors&&t.hasAttribute("color")&&(r=Oi(r.xyz.mul(hu("color","vec3")),r.a)),e.instanceColor){r=nn("vec3","vInstanceColor").mul(r)}if(e.isBatchedMesh&&e._colorsTexture){r=nn("vec3","vBatchColor").mul(r)}on.assign(r);const s=this.opacityNode?Ci(this.opacityNode):nd;if(on.a.assign(on.a.mul(s)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Ci(this.alphaTestNode):td;on.a.lessThanEqual(e).discard()}!0===this.alphaHash&&on.a.lessThan(Xc(qu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&on.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Ii(0):on.rgb}setupNormal(){return this.normalNode?Ii(this.normalNode):pd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?wl("envMap","cubeTexture"):wl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new mc(Ld)),t}setupLights(e){const t=[],r=this.setupEnvironment(e);r&&r.isLightingNode&&t.push(r);const s=this.setupLightMap(e);if(s&&s.isLightingNode&&t.push(s),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:Dd;t.push(new hc(e))}let i=this.lightsNode||e.lightsNode;return t.length>0&&(i=e.renderer.lighting.createNode([...i.getLights(),...t])),i}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:r,backdropAlphaNode:s,emissiveNode:i}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(n&&n.getScope().hasLights){const t=this.setupLightingModel(e);o=gc(n,t,r,s)}else null!==r&&(o=Ii(null!==s?da(o,r,s):r));return(i&&!0===i.isNode||t.emissive&&!0===t.emissive.isColor)&&(an.assign(Ii(i||id)),o=o.add(an)),o}setupOutput(e,t){if(!0===this.fog){const r=e.fogNode;r&&(t=Oi(r.mix(t.rgb,r.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const r=e[t];void 0===this[t]&&(this[t]=r,r&&r.clone&&(this[t]=r.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const r=U.prototype.toJSON.call(this,e),s=hs(this);r.inputNodes={};for(const{property:t,childNode:i}of s)r.inputNodes[t]=i.toJSON(e).uuid;function i(e){const t=[];for(const r in e){const s=e[r];delete s.metadata,t.push(s)}return t}if(t){const t=i(e.textures),s=i(e.images),n=i(e.nodes);t.length>0&&(r.textures=t),s.length>0&&(r.images=s),n.length>0&&(r.nodes=n)}return r}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const Qc=new P;class Zc extends Yc{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(Qc),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,r=this.useColor;this.vertexNode=_i((()=>{const e=hu("instancePosition").xyz,t=Oi($u.mul(Oi(e,1))),r=vc.z.div(vc.w),s=Nu.mul(t),i=ju.xy.toVar();return i.mulAssign(this.pointWidthNode?this.pointWidthNode:Pd),i.assign(i.div(vc.z)),i.y.assign(i.y.mul(r)),i.assign(i.mul(s.w)),s.addAssign(Oi(i,0,0)),s}))(),this.fragmentNode=_i((()=>{const s=Ci(1).toVar(),i=la(pu().mul(2).sub(1));if(t&&e.samples>1){const e=Ci(i.fwidth()).toVar();s.assign(ga(e.oneMinus(),e.add(1),i).oneMinus())}else i.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(r){n=hu("instanceColor").mul(rd)}else n=rd;return s.mulAssign(nd),Oi(n,s)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const Jc=new I;class eh extends Yc{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(Jc),this.setValues(e)}}const th=new L;class rh extends Yc{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(th),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Ci(this.offsetNodeNode):Fd,t=this.dashScaleNode?Ci(this.dashScaleNode):wd,r=this.dashSizeNode?Ci(this.dashSizeNode):Md,s=this.dashSizeNode?Ci(this.dashGapNode):Bd;An.assign(r),Rn.assign(s);const i=wa(hu("lineDistance").mul(t));(e?i.add(e):i).mod(An.add(Rn)).greaterThan(An).discard()}}let sh=null;class ih extends Mc{static get type(){return"ViewportSharedTextureNode"}constructor(e=xc,t=null){null===sh&&(sh=new w),super(e,t,sh)}updateReference(){return this}}const nh=xi(ih),oh=new L;class ah extends Yc{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(oh),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.blending=D,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,r=this.useColor,s=this.dashed,i=this.worldUnits,n=_i((({start:e,end:t})=>{const r=Nu.element(2).element(2),s=Nu.element(3).element(2).mul(-.5).div(r).sub(e.z).div(t.z.sub(e.z));return Oi(da(e.xyz,t.xyz,s),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=_i((()=>{const e=hu("instanceStart"),t=hu("instanceEnd"),r=Oi($u.mul(Oi(e,1))).toVar("start"),o=Oi($u.mul(Oi(t,1))).toVar("end");if(s){const e=this.dashScaleNode?Ci(this.dashScaleNode):wd,t=this.offsetNode?Ci(this.offsetNodeNode):Fd,r=hu("instanceDistanceStart"),s=hu("instanceDistanceEnd");let i=ju.y.lessThan(.5).select(e.mul(r),e.mul(s));i=i.add(t),nn("float","lineDistance").assign(i)}i&&(nn("vec3","worldStart").assign(r.xyz),nn("vec3","worldEnd").assign(o.xyz));const a=vc.z.div(vc.w),u=Nu.element(2).element(3).equal(-1);Si(u,(()=>{Si(r.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(n({start:r,end:o}))})).ElseIf(o.z.lessThan(0).and(r.z.greaterThanEqual(0)),(()=>{r.assign(n({start:o,end:r}))}))}));const l=Nu.mul(r),d=Nu.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Oi().toVar();if(i){const e=o.xyz.sub(r.xyz).normalize(),t=da(r.xyz,o.xyz,.5).normalize(),i=e.cross(t).normalize(),n=e.cross(i),a=nn("vec4","worldPos");a.assign(ju.y.lessThan(.5).select(r,o));const u=Ud.mul(.5);a.addAssign(Oi(ju.x.lessThan(0).select(i.mul(u),i.mul(u).negate()),0)),s||(a.addAssign(Oi(ju.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Oi(n.mul(u),0)),Si(ju.y.greaterThan(1).or(ju.y.lessThan(0)),(()=>{a.subAssign(Oi(n.mul(2).mul(u),0))}))),g.assign(Nu.mul(a));const l=Ii().toVar();l.assign(ju.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=Bi(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(ju.x.lessThan(0).select(e.negate(),e)),Si(ju.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(ju.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Ud)),e.assign(e.div(vc.w)),g.assign(ju.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Oi(e,0,0)))}return g}))();const o=_i((({p1:e,p2:t,p3:r,p4:s})=>{const i=e.sub(r),n=s.sub(r),o=t.sub(e),a=i.dot(n),u=n.dot(o),l=i.dot(o),d=n.dot(n),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return Bi(h,p)}));if(this.colorNode=_i((()=>{const n=pu();if(s){const e=this.dashSizeNode?Ci(this.dashSizeNode):Md,t=this.dashSizeNode?Ci(this.dashGapNode):Bd;An.assign(e),Rn.assign(t);const r=nn("float","lineDistance");n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),r.mod(An.add(Rn)).greaterThan(An).discard()}const a=Ci(1).toVar("alpha");if(i){const r=nn("vec3","worldStart"),i=nn("vec3","worldEnd"),n=nn("vec4","worldPos").xyz.normalize().mul(1e5),u=i.sub(r),l=o({p1:r,p2:i,p3:Ii(0,0,0),p4:n}),d=r.add(u.mul(l.x)),c=n.mul(l.y),h=d.sub(c).length().div(Ud);if(!s)if(t&&e.samples>1){const e=h.fwidth();a.assign(ga(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),r=e.mul(e).add(t.mul(t)),s=Ci(r.fwidth()).toVar("dlen");Si(n.y.abs().greaterThan(1),(()=>{a.assign(ga(s.oneMinus(),s.add(1),r).oneMinus())}))}else Si(n.y.abs().greaterThan(1),(()=>{const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(r){const e=hu("instanceColorStart"),t=hu("instanceColorEnd");u=ju.y.lessThan(.5).select(e,t).mul(rd)}else u=rd;return Oi(u,a)}))(),this.transparent){const e=this.opacityNode?Ci(this.opacityNode):nd;this.outputNode=Oi(this.colorNode.rgb.mul(e).add(nh().rgb.mul(e.oneMinus())),this.colorNode.a)}}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const uh=e=>fi(e).mul(.5).add(.5),lh=new V;class dh extends Yc{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(lh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Ci(this.opacityNode):nd;on.assign(Oi(uh(al),e))}}class ch extends Fs{static get type(){return"EquirectUVNode"}constructor(e=Yu){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),r=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Bi(t,r)}}const hh=xi(ch);class ph extends O{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const r=t.minFilter,s=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i=new G(5,5,5),n=hh(Yu),o=new Yc;o.colorNode=xu(t,n,0),o.side=x,o.blending=D;const a=new k(i,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new W(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=r,t.currentGenerateMipmaps=s,a.geometry.dispose(),a.material.dispose(),this}}const gh=new WeakMap;class mh extends Fs{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=bl();const t=new H;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=vs.RENDER}updateBefore(e){const{renderer:t,material:r}=e,s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:r[s.property];if(e&&e.isTexture){const r=e.mapping;if(r===j||r===q){if(gh.has(e)){const t=gh.get(e);yh(t,e.mapping),this._cubeTexture=t}else{const r=e.image;if(function(e){return null!=e&&e.height>0}(r)){const s=new ph(r.height);s.fromEquirectangularTexture(t,e),yh(s.texture,e.mapping),this._cubeTexture=s.texture,gh.set(e,s.texture),e.addEventListener("dispose",fh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function fh(e){const t=e.target;t.removeEventListener("dispose",fh);const r=gh.get(t);void 0!==r&&(gh.delete(t),r.dispose())}function yh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const bh=xi(mh);class xh extends cc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=bh(this.envNode)}}class Th extends cc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Ci(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class _h{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class vh extends _h{constructor(){super()}indirect(e,t,r){const s=e.ambientOcclusion,i=e.reflectedLight,n=r.context.irradianceLightMap;i.indirectDiffuse.assign(Oi(0)),n?i.indirectDiffuse.addAssign(n):i.indirectDiffuse.addAssign(Oi(1,1,1,0)),i.indirectDiffuse.mulAssign(s),i.indirectDiffuse.mulAssign(on.rgb)}finish(e,t,r){const s=r.material,i=e.outgoingLight,n=r.context.environment;if(n)switch(s.combine){case Y:i.rgb.assign(da(i.rgb,i.rgb.mul(n.rgb),ld.mul(dd)));break;case X:i.rgb.assign(da(i.rgb,n.rgb,ld.mul(dd)));break;case K:i.rgb.addAssign(n.rgb.mul(ld.mul(dd)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",s.combine)}}}const Nh=new Q;class Sh extends Yc{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Nh),this.setValues(e)}setupNormal(){return nl}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new xh(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Th(Ld)),t}setupOutgoingLight(){return on.rgb}setupLightingModel(){return new vh}}const Ah=_i((({f0:e,f90:t,dotVH:r})=>{const s=r.mul(-5.55473).sub(6.98316).mul(r).exp2();return e.mul(s.oneMinus()).add(t.mul(s))})),Rh=_i((e=>e.diffuseColor.mul(1/Math.PI))),Ch=_i((({dotNH:e})=>Nn.mul(Ci(.5)).add(1).mul(Ci(1/Math.PI)).mul(e.pow(Nn)))),Eh=_i((({lightDirection:e})=>{const t=e.add(Zu).normalize(),r=al.dot(t).clamp(),s=Zu.dot(t).clamp(),i=Ah({f0:_n,f90:1,dotVH:s}),n=Ci(.25),o=Ch({dotNH:r});return i.mul(n).mul(o)}));class wh extends vh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:r}){const s=al.dot(e).clamp().mul(t);r.directDiffuse.addAssign(s.mul(Rh({diffuseColor:on.rgb}))),!0===this.specular&&r.directSpecular.addAssign(s.mul(Eh({lightDirection:e})).mul(ld))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:r}){r.indirectDiffuse.addAssign(t.mul(Rh({diffuseColor:on}))),r.indirectDiffuse.mulAssign(e)}}const Mh=new Z;class Bh extends Yc{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Mh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new xh(t):null}setupLightingModel(){return new wh(!1)}}const Uh=new J;class Fh extends Yc{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Uh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new xh(t):null}setupLightingModel(){return new wh}setupVariants(){const e=(this.shininessNode?Ci(this.shininessNode):sd).max(1e-4);Nn.assign(e);const t=this.specularNode||od;_n.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Ph=_i((e=>{if(!1===e.geometry.hasAttribute("normal"))return Ci(0);const t=nl.dFdx().abs().max(nl.dFdy().abs());return t.x.max(t.y).max(t.z)})),Ih=_i((e=>{const{roughness:t}=e,r=Ph();let s=t.max(.0525);return s=s.add(r),s=s.min(1),s})),Lh=_i((({alpha:e,dotNL:t,dotNV:r})=>{const s=e.pow2(),i=t.mul(s.add(s.oneMinus().mul(r.pow2())).sqrt()),n=r.mul(s.add(s.oneMinus().mul(t.pow2())).sqrt());return zn(.5,i.add(n).max(uo))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),Dh=_i((({alphaT:e,alphaB:t,dotTV:r,dotBV:s,dotTL:i,dotBL:n,dotNV:o,dotNL:a})=>{const u=a.mul(Ii(e.mul(r),t.mul(s),o).length()),l=o.mul(Ii(e.mul(i),t.mul(n),a).length());return zn(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Vh=_i((({alpha:e,dotNH:t})=>{const r=e.pow2(),s=t.pow2().mul(r.oneMinus()).oneMinus();return r.div(s.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Oh=Ci(1/Math.PI),Gh=_i((({alphaT:e,alphaB:t,dotNH:r,dotTH:s,dotBH:i})=>{const n=e.mul(t),o=Ii(t.mul(s),e.mul(i),n.mul(r)),a=o.dot(o),u=n.div(a);return Oh.mul(n.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),kh=_i((e=>{const{lightDirection:t,f0:r,f90:s,roughness:i,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||al,l=i.pow2(),d=t.add(Zu).normalize(),c=u.dot(t).clamp(),h=u.dot(Zu).clamp(),p=u.dot(d).clamp(),g=Zu.dot(d).clamp();let m,f,y=Ah({f0:r,f90:s,dotVH:g});if(pi(o)&&(y=gn.mix(y,n)),pi(a)){const e=xn.dot(t),r=xn.dot(Zu),s=xn.dot(d),i=Tn.dot(t),n=Tn.dot(Zu),o=Tn.dot(d);m=Dh({alphaT:yn,alphaB:l,dotTV:r,dotBV:n,dotTL:e,dotBL:i,dotNV:h,dotNL:c}),f=Gh({alphaT:yn,alphaB:l,dotNH:p,dotTH:s,dotBH:o})}else m=Lh({alpha:l,dotNL:c,dotNV:h}),f=Vh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),zh=_i((({roughness:e,dotNV:t})=>{const r=Oi(-1,-.0275,-.572,.022),s=Oi(1,.0425,1.04,-.04),i=e.mul(r).add(s),n=i.x.mul(i.x).min(t.mul(-9.28).exp2()).mul(i.x).add(i.y);return Bi(-1.04,1.04).mul(n).add(i.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),$h=_i((e=>{const{dotNV:t,specularColor:r,specularF90:s,roughness:i}=e,n=zh({dotNV:t,roughness:i});return r.mul(n.x).add(s.mul(n.y))})),Wh=_i((({f:e,f90:t,dotVH:r})=>{const s=r.oneMinus().saturate(),i=s.mul(s),n=s.mul(i,i).clamp(0,.9999);return e.sub(Ii(t).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Hh=_i((({roughness:e,dotNH:t})=>{const r=e.pow2(),s=Ci(1).div(r),i=t.pow2().oneMinus().max(.0078125);return Ci(2).add(s).mul(i.pow(s.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),jh=_i((({dotNV:e,dotNL:t})=>Ci(1).div(Ci(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),qh=_i((({lightDirection:e})=>{const t=e.add(Zu).normalize(),r=al.dot(e).clamp(),s=al.dot(Zu).clamp(),i=al.dot(t).clamp(),n=Hh({roughness:pn,dotNH:i}),o=jh({dotNV:s,dotNL:r});return hn.mul(n).mul(o)})),Kh=_i((({N:e,V:t,roughness:r})=>{const s=e.dot(t).saturate(),i=Bi(r,s.oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),Xh=_i((({f:e})=>{const t=e.length();return Xo(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),Yh=_i((({v1:e,v2:t})=>{const r=e.dot(t),s=r.abs().toVar(),i=s.mul(.0145206).add(.4965155).mul(s).add(.8543985).toVar(),n=s.add(4.1616724).mul(s).add(3.417594).toVar(),o=i.div(n),a=r.greaterThan(0).select(o,Xo(r.mul(r).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),Qh=_i((({N:e,V:t,P:r,mInv:s,p0:i,p1:n,p2:o,p3:a})=>{const u=n.sub(i).toVar(),l=a.sub(i).toVar(),d=u.cross(l),c=Ii().toVar();return Si(d.dot(r.sub(i)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=s.mul(Wi(u,l,e).transpose()).toVar(),h=d.mul(i.sub(r)).normalize().toVar(),p=d.mul(n.sub(r)).normalize().toVar(),g=d.mul(o.sub(r)).normalize().toVar(),m=d.mul(a.sub(r)).normalize().toVar(),f=Ii(0).toVar();f.addAssign(Yh({v1:h,v2:p})),f.addAssign(Yh({v1:p,v2:g})),f.addAssign(Yh({v1:g,v2:m})),f.addAssign(Yh({v1:m,v2:h})),c.assign(Ii(Xh({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),Zh=1/6,Jh=e=>kn(Zh,kn(e,kn(e,e.negate().add(3)).sub(3)).add(1)),ep=e=>kn(Zh,kn(e,kn(e,kn(3,e).sub(6))).add(4)),tp=e=>kn(Zh,kn(e,kn(e,kn(-3,e).add(3)).add(3)).add(1)),rp=e=>kn(Zh,sa(e,3)),sp=e=>Jh(e).add(ep(e)),ip=e=>tp(e).add(rp(e)),np=e=>On(-1,ep(e).div(Jh(e).add(ep(e)))),op=e=>On(1,rp(e).div(tp(e).add(rp(e)))),ap=(e,t,r)=>{const s=e.uvNode,i=kn(s,t.zw).add(.5),n=So(i),o=Co(i),a=sp(o.x),u=ip(o.x),l=np(o.x),d=op(o.x),c=np(o.y),h=op(o.y),p=Bi(n.x.add(l),n.y.add(c)).sub(.5).mul(t.xy),g=Bi(n.x.add(d),n.y.add(c)).sub(.5).mul(t.xy),m=Bi(n.x.add(l),n.y.add(h)).sub(.5).mul(t.xy),f=Bi(n.x.add(d),n.y.add(h)).sub(.5).mul(t.xy),y=sp(o.y).mul(On(a.mul(e.uv(p).level(r)),u.mul(e.uv(g).level(r)))),b=ip(o.y).mul(On(a.mul(e.uv(m).level(r)),u.mul(e.uv(f).level(r))));return y.add(b)},up=_i((([e,t=Ci(3)])=>{const r=Bi(e.size(Ei(t))),s=Bi(e.size(Ei(t.add(1)))),i=zn(1,r),n=zn(1,s),o=ap(e,Oi(i,r),So(t)),a=ap(e,Oi(n,s),Ao(t));return Co(t).mix(o,a)})),lp=_i((([e,t,r,s,i])=>{const n=Ii(pa(t.negate(),Ro(e),zn(1,s))),o=Ii(Lo(i[0].xyz),Lo(i[1].xyz),Lo(i[2].xyz));return Ro(n).mul(r.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),dp=_i((([e,t])=>e.mul(ca(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),cp=Uc(),hp=Uc(),pp=_i((([e,t,r],{material:s})=>{const i=(s.side==x?cp:hp).uv(e),n=_o(Tc.x).mul(dp(t,r));return up(i,n)})),gp=_i((([e,t,r])=>(Si(r.notEqual(0),(()=>{const s=To(t).negate().div(r);return bo(s.negate().mul(e))})),Ii(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),mp=_i((([e,t,r,s,i,n,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Oi().toVar(),f=Ii().toVar();const i=d.sub(1).mul(g.mul(.025)),n=Ii(d.sub(i),d,d.add(i));ic({start:0,end:3},(({i:i})=>{const d=n.element(i),g=lp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Oi(y,1))),x=Bi(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(Bi(x.x,x.y.oneMinus()));const T=pp(x,r,d);m.element(i).assign(T.element(i)),m.a.addAssign(T.a),f.element(i).assign(s.element(i).mul(gp(Lo(g),h,p).element(i)))})),m.a.divAssign(3)}else{const i=lp(e,t,c,d,a),n=o.add(i),g=l.mul(u.mul(Oi(n,1))),y=Bi(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(Bi(y.x,y.y.oneMinus())),m=pp(y,r,d),f=s.mul(gp(Lo(i),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Ii($h({dotNV:b,specularColor:i,specularF90:n,roughness:r})),T=f.r.add(f.g,f.b).div(3);return Oi(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),fp=Wi(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),yp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),bp=_i((({outsideIOR:e,eta2:t,cosTheta1:r,thinFilmThickness:s,baseF0:i})=>{const n=da(e,t,ga(0,.03,s)),o=e.div(n).pow2().mul(r.pow2().oneMinus()).oneMinus();Si(o.lessThan(0),(()=>Ii(1)));const a=o.sqrt(),u=yp(n,e),l=Ah({f0:u,f90:1,dotVH:r}),d=l.oneMinus(),c=n.lessThan(e).select(Math.PI,0),h=Ci(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Ii(1).add(t).div(Ii(1).sub(t))})(i.clamp(0,.9999)),g=yp(p,n.toVec3()),m=Ah({f0:g,f90:1,dotVH:a}),f=Ii(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(s,a,2),b=Ii(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Ii(1).sub(x)),v=l.add(_).toVar(),N=_.sub(d).toVar();return ic({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{N.mulAssign(T);const t=((e,t)=>{const r=e.mul(2*Math.PI*1e-9),s=Ii(54856e-17,44201e-17,52481e-17),i=Ii(1681e3,1795300,2208400),n=Ii(43278e5,93046e5,66121e5),o=Ci(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(r.mul(2239900).add(t.x).cos()).mul(r.pow2().mul(-45282e5).exp());let a=s.mul(n.mul(2*Math.PI).sqrt()).mul(i.mul(r).add(t).cos()).mul(r.pow2().negate().mul(n).exp());return a=Ii(a.x.add(o),a.y,a.z).div(1.0685e-7),fp.mul(a)})(Ci(e).mul(y),Ci(e).mul(b)).mul(2);v.addAssign(N.mul(t))})),v.max(Ii(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),xp=_i((({normal:e,viewDir:t,roughness:r})=>{const s=e.dot(t).saturate(),i=r.pow2(),n=Ta(r.lessThan(.25),Ci(-339.2).mul(i).add(Ci(161.4).mul(r)).sub(25.9),Ci(-8.48).mul(i).add(Ci(14.3).mul(r)).sub(9.95)),o=Ta(r.lessThan(.25),Ci(44).mul(i).sub(Ci(23.7).mul(r)).add(3.26),Ci(1.97).mul(i).sub(Ci(3.27).mul(r)).add(.72));return Ta(r.lessThan(.25),0,Ci(.1).mul(r).sub(.025)).add(n.mul(s).add(o).exp()).mul(1/Math.PI).saturate()})),Tp=Ii(.04),_p=Ci(1);class vp extends _h{constructor(e=!1,t=!1,r=!1,s=!1,i=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=r,this.anisotropy=s,this.transmission=i,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Ii().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Ii().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Ii().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Ii().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Ii().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=al.dot(Zu).clamp();this.iridescenceFresnel=bp({outsideIOR:Ci(1),eta2:mn,cosTheta1:e,thinFilmThickness:fn,baseF0:_n}),this.iridescenceF0=Wh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Xu,r=Eu.sub(Xu).normalize(),s=ul;e.backdrop=mp(s,r,un,on,_n,vn,t,Du,Au,Nu,En,Mn,Un,Bn,this.dispersion?Fn:null),e.backdropAlpha=wn,on.a.mulAssign(da(1,e.backdrop.a,wn))}}computeMultiscattering(e,t,r){const s=al.dot(Zu).clamp(),i=zh({roughness:un,dotNV:s}),n=(this.iridescenceF0?gn.mix(_n,this.iridescenceF0):_n).mul(i.x).add(r.mul(i.y)),o=i.x.add(i.y).oneMinus(),a=_n.add(_n.oneMinus().mul(.047619)),u=n.mul(a).div(o.mul(a).oneMinus());e.addAssign(n),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:r}){const s=al.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(s.mul(qh({lightDirection:e}))),!0===this.clearcoat){const r=ll.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(r.mul(kh({lightDirection:e,f0:Tp,f90:_p,roughness:cn,normalView:ll})))}r.directDiffuse.addAssign(s.mul(Rh({diffuseColor:on.rgb}))),r.directSpecular.addAssign(s.mul(kh({lightDirection:e,f0:_n,f90:1,roughness:un,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:s,reflectedLight:i,ltc_1:n,ltc_2:o}){const a=t.add(r).sub(s),u=t.sub(r).sub(s),l=t.sub(r).add(s),d=t.add(r).add(s),c=al,h=Zu,p=Qu.toVar(),g=Kh({N:c,V:h,roughness:un}),m=n.uv(g).toVar(),f=o.uv(g).toVar(),y=Wi(Ii(m.x,0,m.y),Ii(0,1,0),Ii(m.z,0,m.w)).toVar(),b=_n.mul(f.x).add(_n.oneMinus().mul(f.y)).toVar();i.directSpecular.addAssign(e.mul(b).mul(Qh({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),i.directDiffuse.addAssign(e.mul(on).mul(Qh({N:c,V:h,P:p,mInv:Wi(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,r){this.indirectDiffuse(e,t,r),this.indirectSpecular(e,t,r),this.ambientOcclusion(e,t,r)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Rh({diffuseColor:on})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:r}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(hn,xp({normal:al,viewDir:Zu,roughness:pn}))),!0===this.clearcoat){const e=ll.dot(Zu).clamp(),t=$h({dotNV:e,specularColor:Tp,specularF90:_p,roughness:cn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const s=Ii().toVar("singleScattering"),i=Ii().toVar("multiScattering"),n=t.mul(1/Math.PI);this.computeMultiscattering(s,i,vn);const o=s.add(i),a=on.mul(o.r.max(o.g).max(o.b).oneMinus());r.indirectSpecular.addAssign(e.mul(s)),r.indirectSpecular.addAssign(i.mul(n)),r.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const r=al.dot(Zu).clamp().add(e),s=un.mul(-16).oneMinus().negate().exp2(),i=e.sub(r.pow(s).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(i)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=ll.dot(Zu).clamp(),r=Ah({dotVH:e,f0:Tp,f90:_p}),s=t.mul(dn.mul(r).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(dn));t.assign(s)}if(!0===this.sheen){const e=hn.r.max(hn.g).max(hn.b).mul(.157).oneMinus(),r=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(r)}}}const Np=Ci(1),Sp=Ci(-2),Ap=Ci(.8),Rp=Ci(-1),Cp=Ci(.4),Ep=Ci(2),wp=Ci(.305),Mp=Ci(3),Bp=Ci(.21),Up=Ci(4),Fp=Ci(4),Pp=Ci(16),Ip=_i((([e])=>{const t=Ii(Po(e)).toVar(),r=Ci(-1).toVar();return Si(t.x.greaterThan(t.z),(()=>{Si(t.x.greaterThan(t.y),(()=>{r.assign(Ta(e.x.greaterThan(0),0,3))})).Else((()=>{r.assign(Ta(e.y.greaterThan(0),1,4))}))})).Else((()=>{Si(t.z.greaterThan(t.y),(()=>{r.assign(Ta(e.z.greaterThan(0),2,5))})).Else((()=>{r.assign(Ta(e.y.greaterThan(0),1,4))}))})),r})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),Lp=_i((([e,t])=>{const r=Bi().toVar();return Si(t.equal(0),(()=>{r.assign(Bi(e.z,e.y).div(Po(e.x)))})).ElseIf(t.equal(1),(()=>{r.assign(Bi(e.x.negate(),e.z.negate()).div(Po(e.y)))})).ElseIf(t.equal(2),(()=>{r.assign(Bi(e.x.negate(),e.y).div(Po(e.z)))})).ElseIf(t.equal(3),(()=>{r.assign(Bi(e.z.negate(),e.y).div(Po(e.x)))})).ElseIf(t.equal(4),(()=>{r.assign(Bi(e.x.negate(),e.z).div(Po(e.y)))})).Else((()=>{r.assign(Bi(e.x,e.y).div(Po(e.z)))})),kn(.5,r.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),Dp=_i((([e])=>{const t=Ci(0).toVar();return Si(e.greaterThanEqual(Ap),(()=>{t.assign(Np.sub(e).mul(Rp.sub(Sp)).div(Np.sub(Ap)).add(Sp))})).ElseIf(e.greaterThanEqual(Cp),(()=>{t.assign(Ap.sub(e).mul(Ep.sub(Rp)).div(Ap.sub(Cp)).add(Rp))})).ElseIf(e.greaterThanEqual(wp),(()=>{t.assign(Cp.sub(e).mul(Mp.sub(Ep)).div(Cp.sub(wp)).add(Ep))})).ElseIf(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).Else((()=>{t.assign(Ci(-2).mul(_o(kn(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Vp=_i((([e,t])=>{const r=e.toVar();r.assign(kn(2,r).sub(1));const s=Ii(r,1).toVar();return Si(t.equal(0),(()=>{s.assign(s.zyx)})).ElseIf(t.equal(1),(()=>{s.assign(s.xzy),s.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{s.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{s.assign(s.zyx),s.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{s.assign(s.xzy),s.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{s.z.mulAssign(-1)})),s})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Op=_i((([e,t,r,s,i,n])=>{const o=Ci(r),a=Ii(t),u=ca(Dp(o),Sp,n),l=Co(u),d=So(u),c=Ii(Gp(e,a,d,s,i,n)).toVar();return Si(l.notEqual(0),(()=>{const t=Ii(Gp(e,a,d.add(1),s,i,n)).toVar();c.assign(da(c,t,l))})),c})),Gp=_i((([e,t,r,s,i,n])=>{const o=Ci(r).toVar(),a=Ii(t),u=Ci(Ip(a)).toVar(),l=Ci(Xo(Fp.sub(o),0)).toVar();o.assign(Xo(o,Fp));const d=Ci(xo(o)).toVar(),c=Bi(Lp(a,u).mul(d.sub(2)).add(1)).toVar();return Si(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(kn(3,Pp))),c.y.addAssign(kn(4,xo(n).sub(d))),c.x.mulAssign(s),c.y.mulAssign(i),e.uv(c).grad(Bi(),Bi())})),kp=_i((({envMap:e,mipInt:t,outputDirection:r,theta:s,axis:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=wo(s),l=r.mul(u).add(i.cross(r).mul(Eo(s))).add(i.mul(i.dot(r).mul(u.oneMinus())));return Gp(e,l,t,n,o,a)})),zp=_i((({n:e,latitudinal:t,poleAxis:r,outputDirection:s,weights:i,samples:n,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Ii(Ta(t,r,ra(r,s))).toVar();Si(po(h.equals(Ii(0))),(()=>{h.assign(Ii(s.z,0,s.x.negate()))})),h.assign(Ro(h));const p=Ii().toVar();return p.addAssign(i.element(Ei(0)).mul(kp({theta:0,axis:h,outputDirection:s,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),ic({start:Ei(1),end:e},(({i:e})=>{Si(e.greaterThanEqual(n),(()=>{nc()}));const t=Ci(o.mul(Ci(e))).toVar();p.addAssign(i.element(e).mul(kp({theta:t.mul(-1),axis:h,outputDirection:s,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(i.element(e).mul(kp({theta:t,axis:h,outputDirection:s,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Oi(p,1)}));let $p=null;const Wp=new WeakMap;function Hp(e){let t=Wp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const r=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const r=6;for(let s=0;s0}(r))return null;t=$p.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Wp.set(e,t)}return t.texture}class jp extends Fs{static get type(){return"PMREMNode"}constructor(e,t=null,r=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=r,this._generator=null;const s=new ee;s.isRenderTargetTexture=!0,this._texture=xu(s),this._width=tn(0),this._height=tn(0),this._maxMip=tn(0),this.updateBeforeType=vs.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,r=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:r,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,r=this._value;t!==r.pmremVersion&&(e=!0===r.isPMREMTexture?r:Hp(r),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===$p&&($p=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const r=this.value;e.renderer.coordinateSystem===b&&!0!==r.isPMREMTexture&&!0===r.isRenderTargetTexture&&(t=Ii(t.x.negate(),t.yz));let s=this.levelNode;return null===s&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this)),Op(this._texture,t,s,this._width,this._height,this._maxMip)}}const qp=xi(jp),Kp=new WeakMap;class Xp extends cc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:t[r.property];let s=Kp.get(e);void 0===s&&(s=qp(e),Kp.set(e,s)),r=s}const s=t.envMap?Rl("envMapIntensity","float",e.material):Rl("environmentIntensity","float",e.scene),i=!0===t.useAnisotropy||t.anisotropy>0?Hl:al,n=r.context(Yp(un,i)).mul(s),o=r.context(Qp(ul)).mul(Math.PI).mul(s),a=eu(n),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=r.context(Yp(cn,ll)).mul(s),t=eu(e);l.addAssign(t)}}}const Yp=(e,t)=>{let r=null;return{getUV:()=>(null===r&&(r=Zu.negate().reflect(t),r=e.mul(e).mix(r,t).normalize(),r=r.transformDirection(Au)),r),getTextureLevel:()=>e}},Qp=e=>({getUV:()=>e,getTextureLevel:()=>Ci(1)}),Zp=new te;class Jp extends Yc{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(Zp),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new Xp(t):null}setupLightingModel(){return new vp}setupSpecular(){const e=da(Ii(.04),on.rgb,ln);_n.assign(e),vn.assign(1)}setupVariants(){const e=this.metalnessNode?Ci(this.metalnessNode):hd;ln.assign(e);let t=this.roughnessNode?Ci(this.roughnessNode):cd;t=Ih({roughness:t}),un.assign(t),this.setupSpecular(),on.assign(Oi(on.rgb.mul(e.oneMinus()),on.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const eg=new re;class tg extends Jp{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(eg),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Ci(this.iorNode):Rd;En.assign(e),_n.assign(da(Ko(ia(En.sub(1).div(En.add(1))).mul(ud),Ii(1)).mul(ad),on.rgb,ln)),vn.assign(da(ad,1,ln))}setupLightingModel(){return new vp(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Ci(this.clearcoatNode):gd,t=this.clearcoatRoughnessNode?Ci(this.clearcoatRoughnessNode):md;dn.assign(e),cn.assign(Ih({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Ii(this.sheenNode):bd,t=this.sheenRoughnessNode?Ci(this.sheenRoughnessNode):xd;hn.assign(e),pn.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Ci(this.iridescenceNode):_d,t=this.iridescenceIORNode?Ci(this.iridescenceIORNode):vd,r=this.iridescenceThicknessNode?Ci(this.iridescenceThicknessNode):Nd;gn.assign(e),mn.assign(t),fn.assign(r)}if(this.useAnisotropy){const e=(this.anisotropyNode?Bi(this.anisotropyNode):Td).toVar();bn.assign(e.length()),Si(bn.equal(0),(()=>{e.assign(Bi(1,0))})).Else((()=>{e.divAssign(Bi(bn)),bn.assign(bn.saturate())})),yn.assign(bn.pow2().mix(un.pow2(),1)),xn.assign($l[0].mul(e.x).add($l[1].mul(e.y))),Tn.assign($l[1].mul(e.x).sub($l[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Ci(this.transmissionNode):Sd,t=this.thicknessNode?Ci(this.thicknessNode):Ad,r=this.attenuationDistanceNode?Ci(this.attenuationDistanceNode):Cd,s=this.attenuationColorNode?Ii(this.attenuationColorNode):Ed;if(wn.assign(e),Mn.assign(t),Bn.assign(r),Un.assign(s),this.useDispersion){const e=this.dispersionNode?Ci(this.dispersionNode):Id;Fn.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Ii(this.clearcoatNormalNode):fd}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class rg extends vp{constructor(e,t,r,s){super(e,t,r),this.useSSS=s}direct({lightDirection:e,lightColor:t,reflectedLight:r},s,i){if(!0===this.useSSS){const s=i.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=s,c=e.add(al.mul(o)).normalize(),h=Ci(Zu.dot(c.negate()).saturate().pow(l).mul(d)),p=Ii(h.add(a).mul(n));r.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:r},s,i)}}class sg extends tg{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Ci(.1),this.thicknessAmbientNode=Ci(0),this.thicknessAttenuationNode=Ci(.1),this.thicknessPowerNode=Ci(2),this.thicknessScaleNode=Ci(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new rg(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const ig=_i((({normal:e,lightDirection:t,builder:r})=>{const s=e.dot(t),i=Bi(s.mul(.5).add(.5),0);if(r.material.gradientMap){const e=wl("gradientMap","texture").context({getUV:()=>i});return Ii(e.r)}{const e=i.fwidth().mul(.5);return da(Ii(.7),Ii(1),ga(Ci(.7).sub(e.x),Ci(.7).add(e.x),i.x))}}));class ng extends _h{direct({lightDirection:e,lightColor:t,reflectedLight:r},s,i){const n=ig({normal:rl,lightDirection:e,builder:i}).mul(t);r.directDiffuse.addAssign(n.mul(Rh({diffuseColor:on.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:r}){r.indirectDiffuse.addAssign(t.mul(Rh({diffuseColor:on}))),r.indirectDiffuse.mulAssign(e)}}const og=new se;class ag extends Yc{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(og),this.setValues(e)}setupLightingModel(){return new ng}}class ug extends Fs{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Ii(Zu.z,0,Zu.x.negate()).normalize(),t=Zu.cross(e);return Bi(e.dot(al),t.dot(al)).mul(.495).add(.5)}}const lg=Ti(ug),dg=new ie;class cg extends Yc{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(dg),this.setValues(e)}setupVariants(e){const t=lg;let r;r=e.material.matcap?wl("matcap","texture").context({getUV:()=>t}):Ii(da(.2,.8,t.y)),on.rgb.mulAssign(r.rgb)}}const hg=new P;class pg extends Yc{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(hg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class gg extends Fs{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:r}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),s=t.sin();return $i(e,s,s.negate(),e).mul(r)}{const e=t,s=Hi(Oi(1,0,0,0),Oi(0,wo(e.x),Eo(e.x).negate(),0),Oi(0,Eo(e.x),wo(e.x),0),Oi(0,0,0,1)),i=Hi(Oi(wo(e.y),0,Eo(e.y),0),Oi(0,1,0,0),Oi(Eo(e.y).negate(),0,wo(e.y),0),Oi(0,0,0,1)),n=Hi(Oi(wo(e.z),Eo(e.z).negate(),0,0),Oi(Eo(e.z),wo(e.z),0,0),Oi(0,0,1,0),Oi(0,0,0,1));return s.mul(i).mul(n).mul(Oi(r,1)).xyz}}}const mg=xi(gg),fg=new ne;class yg extends Yc{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(fg),this.setValues(e)}setupPosition({object:e,camera:t,context:r}){const s=this.sizeAttenuation,{positionNode:i,rotationNode:n,scaleNode:o}=this,a=qu;let u=$u.mul(Ii(i||0)),l=Bi(Du[0].xyz.length(),Du[1].xyz.length());if(null!==o&&(l=l.mul(o)),!s)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Ci(2).div(Nu.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,r)=>fi(new Ga(e,t,r)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Ci(n||yd),h=mg(d,c);u=Oi(u.xy.add(h),u.zw);const p=Nu.mul(u);return r.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class bg extends _h{constructor(){super(),this.shadowNode=Ci(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){on.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(on.rgb)}}const xg=new oe;class Tg extends Yc{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(xg),this.setValues(e)}setupLightingModel(){return new bg}}const _g=_i((({texture:e,uv:t})=>{const r=1e-4,s=Ii().toVar();return Si(t.x.lessThan(r),(()=>{s.assign(Ii(1,0,0))})).ElseIf(t.y.lessThan(r),(()=>{s.assign(Ii(0,1,0))})).ElseIf(t.z.lessThan(r),(()=>{s.assign(Ii(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{s.assign(Ii(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{s.assign(Ii(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{s.assign(Ii(0,0,-1))})).Else((()=>{const r=.01,i=e.uv(t.add(Ii(-.01,0,0))).r.sub(e.uv(t.add(Ii(r,0,0))).r),n=e.uv(t.add(Ii(0,-.01,0))).r.sub(e.uv(t.add(Ii(0,r,0))).r),o=e.uv(t.add(Ii(0,0,-.01))).r.sub(e.uv(t.add(Ii(0,0,r))).r);s.assign(Ii(i,n,o))})),s.normalize()}));class vg extends bu{static get type(){return"Texture3DNode"}constructor(e,t=null,r=null){super(e,t,r),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Ii(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return _g({texture:this,uv:e})}}const Ng=xi(vg);class Sg extends Yc{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=Ng(this.map,null,0),r=_i((({orig:e,dir:t})=>{const r=Ii(-.5),s=Ii(.5),i=t.reciprocal(),n=r.sub(e).mul(i),o=s.sub(e).mul(i),a=Ko(n,o),u=Xo(n,o),l=Xo(a.x,Xo(a.y,a.z)),d=Ko(u.x,Ko(u.y,u.z));return Bi(l,d)}));this.fragmentNode=_i((()=>{const e=wa(Ii(zu.mul(Oi(Eu,1)))),s=wa(ju.sub(e)).normalize(),i=Bi(r({orig:e,dir:s})).toVar();i.x.greaterThan(i.y).discard(),i.assign(Bi(Xo(i.x,0),i.y));const n=Ii(e.add(i.x.mul(s))).toVar(),o=Ii(s.abs().reciprocal()).toVar(),a=Ci(Ko(o.x,Ko(o.y,o.z))).toVar("delta");a.divAssign(wl("steps","float"));const u=Oi(wl("base","color"),0).toVar();return ic({type:"float",start:i.x,end:i.y,update:"+= delta"},(()=>{const e=sn("float","d").assign(t.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:n,finalColor:u}).append():(u.a.assign(1),nc()),n.addAssign(s.mul(a))})),u.a.equal(0).discard(),Oi(u)}))(),super.setup(e)}}class Ag{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,r)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,r)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Rg{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let r=0;r{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,r=[],s=new Set;for(const i of e){const e=i.node&&i.node.attribute?i.node.attribute:t.getAttribute(i.name);if(void 0===e)continue;r.push(e);const n=e.isInterleavedBufferAttribute?e.data:e;s.add(n)}return this.attributes=r,this.vertexBuffers=Array.from(s.values()),r}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:r,group:s,drawRange:i}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=r.isInstancedBufferGeometry?r.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(n.instanceCount=u,!0===e.isBatchedMesh)return n;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=i.start*l,c=(i.start+i.count)*l;null!==s&&(d=Math.max(d,s.start*l),c=Math.min(c,(s.start+s.count)*l));const h=r.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(n.vertexCount=g,n.firstVertex=d,n)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const r of Object.keys(e.attributes).sort()){const s=e.attributes[r];t+=r+",",s.data&&(t+=s.data.stride+","),s.offset&&(t+=s.offset+","),s.itemSize&&(t+=s.itemSize+","),s.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let r=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let r=Object.getPrototypeOf(e);for(;r;){const e=Object.getOwnPropertyDescriptors(r);for(const r in e)if(void 0!==e[r]){const s=e[r];s&&"function"==typeof s.get&&t.push(r)}r=Object.getPrototypeOf(r)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const s=t[e];let i;if(null!==s){const e=typeof s;"number"===e?i=0!==s?"1":"0":"object"===e?(i="{",s.isTexture&&(i+=s.mapping),i+="}"):i=String(s)}else i=String(s);r+=i+","}return r+=this.clippingContextCacheKey+",",e.geometry&&(r+=this.getGeometryCacheKey()),e.skeleton&&(r+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(r+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(r+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(r+=e._colorsTexture.uuid+",")),e.count>1&&(r+=e.uuid+","),r+=e.receiveShadow+",",us(r)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const wg=[];class Mg{constructor(e,t,r,s,i,n){this.renderer=e,this.nodes=t,this.geometries=r,this.pipelines=s,this.bindings=i,this.info=n,this.chainMaps={}}get(e,t,r,s,i,n,o,a){const u=this.getChainMap(a);wg[0]=e,wg[1]=t,wg[2]=n,wg[3]=i;let l=u.get(wg);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,r,s,i,n,o,a),u.set(wg,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,r,s,i,n,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Rg)}dispose(){this.chainMaps={}}createRenderObject(e,t,r,s,i,n,o,a,u,l,d){const c=this.getChainMap(d),h=new Eg(e,t,r,s,i,n,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Bg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Ug=1,Fg=2,Pg=3,Ig=4,Lg=16;class Dg extends Bg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const r=this.get(e);if(void 0===r.version)t===Ug?this.backend.createAttribute(e):t===Fg?this.backend.createIndexAttribute(e):t===Pg?this.backend.createStorageAttribute(e):t===Ig&&this.backend.createIndirectStorageAttribute(e),r.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(r.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return i.version=Vg(e),i}class Gg extends Bg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const r=()=>{this.info.memory.geometries--;const s=t.index,i=e.getAttributes();null!==s&&this.attributes.delete(s);for(const e of i)this.attributes.delete(e);const n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",r)};t.addEventListener("dispose",r)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Pg):this.updateAttribute(e,Ug);const r=this.getIndex(e);null!==r&&this.updateAttribute(r,Fg);const s=e.geometry.indirect;null!==s&&this.updateAttribute(s,Ig)}updateAttribute(e,t){const r=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,r)):this.attributeCall.get(e.data)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e.data,r),this.attributeCall.set(e,r)):this.attributeCall.get(e)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e,r))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:r}=e;let s=t.index;if(!0===r.wireframe){const e=this.wireframes;let r=e.get(t);void 0===r?(r=Og(t),e.set(t,r)):r.version!==Vg(t)&&(this.attributes.delete(r),r=Og(t),e.set(t,r)),s=r}return s}}class kg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,r){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=r*(t/3):e.isPoints?this.render.points+=r*t:e.isLineSegments?this.render.lines+=r*(t/2):e.isLine?this.render.lines+=r*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class zg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class $g extends zg{constructor(e,t,r){super(e),this.vertexProgram=t,this.fragmentProgram=r}}class Wg extends zg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Hg=0;class jg{constructor(e,t,r=null,s=null){this.id=Hg++,this.code=e,this.stage=t,this.transforms=r,this.attributes=s,this.usedTimes=0}}class qg extends Bg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:r}=this,s=this.get(e);if(this._needsComputeUpdate(e)){const i=s.pipeline;i&&(i.usedTimes--,i.computeProgram.usedTimes--);const n=this.nodes.getForCompute(e);let o=this.programs.compute.get(n.computeShader);void 0===o&&(i&&0===i.computeProgram.usedTimes&&this._releaseProgram(i.computeProgram),o=new jg(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),r.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(i&&0===i.usedTimes&&this._releasePipeline(i),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,s.version=e.version,s.pipeline=u}return s.pipeline}getForRender(e,t=null){const{backend:r}=this,s=this.get(e);if(this._needsRenderUpdate(e)){const i=s.pipeline;i&&(i.usedTimes--,i.vertexProgram.usedTimes--,i.fragmentProgram.usedTimes--);const n=e.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(i&&0===i.vertexProgram.usedTimes&&this._releaseProgram(i.vertexProgram),o=new jg(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),r.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(i&&0===i.fragmentProgram.usedTimes&&this._releaseProgram(i.fragmentProgram),a=new jg(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),r.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(i&&0===i.usedTimes&&this._releasePipeline(i),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,s.pipeline=l}return s.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,r,s){r=r||this._getComputeCacheKey(e,t);let i=this.caches.get(r);return void 0===i&&(i=new Wg(r,t),this.caches.set(r,i),this.backend.createComputePipeline(i,s)),i}_getRenderPipeline(e,t,r,s,i){s=s||this._getRenderCacheKey(e,t,r);let n=this.caches.get(s);return void 0===n&&(n=new $g(s,t,r),this.caches.set(s,n),e.pipeline=n,this.backend.createRenderPipeline(e,i)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,r){return t.id+","+r.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,r=e.stage;this.programs[r].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class Kg extends Bg{constructor(e,t,r,s,i,n){super(),this.backend=e,this.textures=r,this.pipelines=i,this.attributes=s,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const r=this.get(e);void 0===r.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),r.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const r=this.get(e);void 0===r.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),r.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,r=e.isIndirectStorageBufferAttribute?Ig:Pg;this.attributes.update(e,r)}}_update(e,t){const{backend:r}=this;let s=!1,i=!0,n=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&r.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(s=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=r.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?i=!1:(n=10*n+u.id,o+=u.version),!0===r.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,s),this.textures.updateTexture(u),s=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===s&&this.backend.updateBindings(e,t,i?n:0,o)}}function Xg(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function Yg(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function Qg(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class Zg{constructor(e,t,r){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,r),this.lightsArray=[],this.scene=t,this.camera=r,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,r,s,i,n,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:r,groupOrder:s,renderOrder:e.renderOrder,z:i,group:n,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=r,a.groupOrder=s,a.renderOrder=e.renderOrder,a.z=i,a.group=n,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,r,s,i,n,o){const a=this.getNextRenderItem(e,t,r,s,i,n,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===r.transparent||r.transmission>0?(Qg(r)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,r,s,i,n,o){const a=this.getNextRenderItem(e,t,r,s,i,n,o);!0===r.transparent||r.transmission>0?(Qg(r)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||Xg),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||Yg),this.transparent.length>1&&this.transparent.sort(t||Yg)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||i[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,i[t]=l),r.width===o.width&&o.height===r.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),r.width=o.width,r.height=o.height,r.textures=n,r.depthTexture=l||null,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,r.renderTarget=e,r.sampleCount!==s&&(c=!0,l&&(l.needsUpdate=!0),r.sampleCount=s);const h={sampleCount:s};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const s=e.image;if(void 0===s)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===s.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const r=[];for(const t of e.images)r.push(t);t.images=r}else t.image=s;void 0!==r.isDefaultTexture&&!0!==r.isDefaultTexture||(i.createTexture(e,t),r.isDefaultTexture=!1,r.generation=e.version),!0===e.source.dataReady&&i.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&i.generateMipmaps(e)}}else i.createDefaultTexture(e),r.isDefaultTexture=!0,r.generation=e.version}if(!0!==r.initialized){r.initialized=!0,r.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}r.version=e.version}getSize(e,t=im){let r=e.images?e.images[0]:e.image;return r?(void 0!==r.image&&(r=r.image),t.width=r.width||1,t.height=r.height||1,t.depth=e.isCubeTexture?6:r.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,r){let s;return s=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,r)))+1,s}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class om extends e{constructor(e,t,r,s=1){super(e,t,r),this.a=s}set(e,t,r,s=1){return this.a=s,super.set(e,t,r)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class am extends rn{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}class um extends Ms{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const r=new mi(t);return this._currentCond=Ta(e,r),this.add(this._currentCond)}ElseIf(e,t){const r=new mi(t),s=Ta(e,r);return this._currentCond.elseNode=s,this._currentCond=s,this}Else(e){return this._currentCond.elseNode=new mi(e),this}build(e,...t){const r=Ni();vi(this);for(const t of this.nodes)t.build(e,"void");return vi(r),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const lm=xi(um);class dm extends Ms{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class cm extends Ms{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,r=[];for(let s=0;s{const t=e.toUint().mul(747796405).add(2891336453),r=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return r.shiftRight(22).bitXor(r).toFloat().mul(1/2**32)})),ym=(e,t)=>sa(kn(4,e.mul(Gn(1,e))),t),bm=_i((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),xm=_i((([e])=>Ii(bm(e.z.add(bm(e.y.mul(1)))),bm(e.z.add(bm(e.x.mul(1)))),bm(e.y.add(bm(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Tm=_i((([e,t,r])=>{const s=Ii(e).toVar(),i=Ci(1.4).toVar(),n=Ci(0).toVar(),o=Ii(s).toVar();return ic({start:Ci(0),end:Ci(3),type:"float",condition:"<="},(()=>{const e=Ii(xm(o.mul(2))).toVar();s.addAssign(e.add(r.mul(Ci(.1).mul(t)))),o.mulAssign(1.8),i.mulAssign(1.5),s.mulAssign(1.2);const a=Ci(bm(s.z.add(bm(s.x.add(bm(s.y)))))).toVar();n.addAssign(a.div(i)),o.addAssign(.14)})),n})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class _m extends Ms{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let r=this._candidateFnCall;if(null===r){let s=null,i=-1;for(const r of this.functionNodes){const n=r.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(t.length===o.length){let n=0;for(let r=0;ri&&(s=r,i=n)}}this._candidateFnCall=r=s(...t)}return r}}const vm=xi(_m),Nm=e=>(...t)=>vm(e,...t),Sm=tn(0).setGroup(Zi).onRenderUpdate((e=>e.time)),Am=tn(0).setGroup(Zi).onRenderUpdate((e=>e.deltaTime)),Rm=tn(0,"uint").setGroup(Zi).onRenderUpdate((e=>e.frameId)),Cm=_i((([e,t,r=Bi(.5)])=>mg(e.sub(r),t).add(r))),Em=_i((([e,t,r=Bi(.5)])=>{const s=e.sub(r),i=s.dot(s),n=i.mul(i).mul(t);return e.add(s.mul(n))})),wm=_i((({position:e=null,horizontal:t=!0,vertical:r=!1})=>{let s;null!==e?(s=Du.toVar(),s[3][0]=e.x,s[3][1]=e.y,s[3][2]=e.z):s=Du;const i=Au.mul(s);return pi(t)&&(i[0][0]=Du[0].length(),i[0][1]=0,i[0][2]=0),pi(r)&&(i[1][0]=0,i[1][1]=Du[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,Nu.mul(i).mul(qu)})),Mm=_i((([e=null])=>{const t=$c();return $c(Ic(e)).sub(t).lessThan(0).select(xc,e)}));class Bm extends Ms{static get type(){return"SpriteSheetUVNode"}constructor(e,t=pu(),r=Ci(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=r}setup(){const{frameNode:e,uvNode:t,countNode:r}=this,{width:s,height:i}=r,n=e.mod(s.mul(i)).floor(),o=n.mod(s),a=i.sub(n.add(1).div(s).ceil()),u=r.reciprocal(),l=Bi(o,a);return t.add(l).mul(u)}}const Um=xi(Bm);class Fm extends Ms{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,r=null,s=Ci(1),i=qu,n=sl){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=r,this.scaleNode=s,this.positionNode=i,this.normalNode=n}setup(){const{textureXNode:e,textureYNode:t,textureZNode:r,scaleNode:s,positionNode:i,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(Ii(1)));const a=i.yz.mul(s),u=i.zx.mul(s),l=i.xy.mul(s),d=e.value,c=null!==t?t.value:d,h=null!==r?r.value:d,p=xu(d,a).mul(o.x),g=xu(c,u).mul(o.y),m=xu(h,l).mul(o.z);return On(p,g,m)}}const Pm=xi(Fm),Im=new me,Lm=new r,Dm=new r,Vm=new r,Om=new n,Gm=new r(0,0,-1),km=new s,zm=new r,$m=new r,Wm=new s,Hm=new t,jm=new ge,qm=xc.flipX();jm.depthTexture=new B(1,1);let Km=!1;class Xm extends bu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||jm.texture,qm),this._reflectorBaseNode=e.reflector||new Ym(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=fi(new Xm({defaultTexture:jm.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class Ym extends Ms{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:r=new fe,resolution:s=1,generateMipmaps:i=!1,bounces:n=!0,depth:o=!1}=t;this.textureNode=e,this.target=r,this.resolution=s,this.generateMipmaps=i,this.bounces=n,this.depth=o,this.updateBeforeType=n?vs.RENDER:vs.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const r=this.resolution;t.getDrawingBufferSize(Hm),e.setSize(Math.round(Hm.width*r),Math.round(Hm.height*r))}setup(e){return this._updateResolution(jm,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&Km)return;Km=!0;const{scene:t,camera:r,renderer:s,material:i}=e,{target:n}=this,o=this.getVirtualCamera(r),a=this.getRenderTarget(o);if(s.getDrawingBufferSize(Hm),this._updateResolution(a,s),Dm.setFromMatrixPosition(n.matrixWorld),Vm.setFromMatrixPosition(r.matrixWorld),Om.extractRotation(n.matrixWorld),Lm.set(0,0,1),Lm.applyMatrix4(Om),zm.subVectors(Dm,Vm),zm.dot(Lm)>0)return;zm.reflect(Lm).negate(),zm.add(Dm),Om.extractRotation(r.matrixWorld),Gm.set(0,0,-1),Gm.applyMatrix4(Om),Gm.add(Vm),$m.subVectors(Dm,Gm),$m.reflect(Lm).negate(),$m.add(Dm),o.coordinateSystem=r.coordinateSystem,o.position.copy(zm),o.up.set(0,1,0),o.up.applyMatrix4(Om),o.up.reflect(Lm),o.lookAt($m),o.near=r.near,o.far=r.far,o.updateMatrixWorld(),o.projectionMatrix.copy(r.projectionMatrix),Im.setFromNormalAndCoplanarPoint(Lm,Dm),Im.applyMatrix4(o.matrixWorldInverse),km.set(Im.normal.x,Im.normal.y,Im.normal.z,Im.constant);const u=o.projectionMatrix;Wm.x=(Math.sign(km.x)+u.elements[8])/u.elements[0],Wm.y=(Math.sign(km.y)+u.elements[9])/u.elements[5],Wm.z=-1,Wm.w=(1+u.elements[10])/u.elements[14],km.multiplyScalar(1/km.dot(Wm));u.elements[2]=km.x,u.elements[6]=km.y,u.elements[10]=s.coordinateSystem===v?km.z-0:km.z+1-0,u.elements[14]=km.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),i.visible=!1;const l=s.getRenderTarget(),d=s.getMRT();s.setMRT(null),s.setRenderTarget(a),s.render(t,o),s.setMRT(d),s.setRenderTarget(l),i.visible=!0,Km=!1}}const Qm=new xe(-1,1,1,-1,0,1);class Zm extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const Jm=new Zm;class ef extends k{constructor(e=null){super(Jm,e),this.camera=Qm,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,Qm)}render(e){e.render(this,Qm)}}const tf=new t;class rf extends bu{static get type(){return"RTTNode"}constructor(e,t=null,r=null,s={type:ye}){const i=new ge(t,r,s);super(i.texture,pu()),this.node=e,this.width=t,this.height=r,this.renderTarget=i,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new ef(new Yc),this.updateBeforeType=vs.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const r=e*this.pixelRatio,s=t*this.pixelRatio;this.renderTarget.setSize(r,s),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(tf);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new bu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const sf=(e,...t)=>fi(new rf(fi(e),...t)),nf=_i((([e,t,r],s)=>{let i;s.renderer.coordinateSystem===v?(e=Bi(e.x,e.y.oneMinus()).mul(2).sub(1),i=Oi(Ii(e,t),1)):i=Oi(Ii(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const n=Oi(r.mul(i));return n.xyz.div(n.w)})),of=_i((([e,t])=>{const r=t.mul(Oi(e,1)),s=r.xy.div(r.w).mul(.5).add(.5).toVar();return Bi(s.x,s.y.oneMinus())})),af=_i((([e,t,r])=>{const s=mu(Tu(t)),i=Ui(e.mul(s)).toVar(),n=Tu(t,i).toVar(),o=Tu(t,i.sub(Ui(2,0))).toVar(),a=Tu(t,i.sub(Ui(1,0))).toVar(),u=Tu(t,i.add(Ui(1,0))).toVar(),l=Tu(t,i.add(Ui(2,0))).toVar(),d=Tu(t,i.add(Ui(0,2))).toVar(),c=Tu(t,i.add(Ui(0,1))).toVar(),h=Tu(t,i.sub(Ui(0,1))).toVar(),p=Tu(t,i.sub(Ui(0,2))).toVar(),g=Po(Gn(Ci(2).mul(a).sub(o),n)).toVar(),m=Po(Gn(Ci(2).mul(u).sub(l),n)).toVar(),f=Po(Gn(Ci(2).mul(c).sub(d),n)).toVar(),y=Po(Gn(Ci(2).mul(h).sub(p),n)).toVar(),b=nf(e,n,r).toVar(),x=g.lessThan(m).select(b.sub(nf(e.sub(Bi(Ci(1).div(s.x),0)),a,r)),b.negate().add(nf(e.add(Bi(Ci(1).div(s.x),0)),u,r))),T=f.lessThan(y).select(b.sub(nf(e.add(Bi(0,Ci(1).div(s.y))),c,r)),b.negate().add(nf(e.sub(Bi(0,Ci(1).div(s.y))),h,r)));return Ro(ra(x,T))}));class uf extends R{constructor(e,t,r=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new r(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class lf extends ve{constructor(e,t,r=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new r(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class df extends Bs{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.isPBO&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let r;const s=e.context.assign;if(r=!1===e.isAvailable("storageBuffer")?!0!==this.node.isPBO||!0===s||!this.node.value.isInstancedBufferAttribute&&"compute"===e.shaderStage?this.node.build(e):e.generatePBO(this):super.generate(e),!0!==s){const s=this.getNodeType(e);r=e.format(r,s,t)}return r}}const cf=xi(df);class hf extends xl{static get type(){return"StorageBufferNode"}constructor(e,t=null,r=0){null===t&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t=gs(e.itemSize),r=e.count),super(e,t,r),this.isStorageBufferNode=!0,this.access=Ss.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this.bufferCount=r,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return cf(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Ss.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=wa(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:r}=this.getAttributeData(),s=r.build(e);return e.registerTransform(s,t),s}}const pf=(e,t,r)=>fi(new hf(e,t,r));class gf extends cu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let r;return r=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new s(1,1,1,1)),r}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}class mf extends Ms{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const ff=Ti(mf),yf=new Se,bf=new n;class xf extends Ms{static get type(){return"SceneNode"}constructor(e=xf.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,r=null!==this.scene?this.scene:e.scene;let s;return t===xf.BACKGROUND_BLURRINESS?s=Rl("backgroundBlurriness","float",r):t===xf.BACKGROUND_INTENSITY?s=Rl("backgroundIntensity","float",r):t===xf.BACKGROUND_ROTATION?s=tn("mat4").label("backgroundRotation").setGroup(Zi).onRenderUpdate((()=>{const e=r.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(yf.copy(r.backgroundRotation),yf.x*=-1,yf.y*=-1,yf.z*=-1,bf.makeRotationFromEuler(yf)):bf.identity(),bf})):console.error("THREE.SceneNode: Unknown scope:",t),s}}xf.BACKGROUND_BLURRINESS="backgroundBlurriness",xf.BACKGROUND_INTENSITY="backgroundIntensity",xf.BACKGROUND_ROTATION="backgroundRotation";const Tf=Ti(xf,xf.BACKGROUND_BLURRINESS),_f=Ti(xf,xf.BACKGROUND_INTENSITY),vf=Ti(xf,xf.BACKGROUND_ROTATION);class Nf extends bu{static get type(){return"StorageTextureNode"}constructor(e,t,r=null){super(e,t),this.storeNode=r,this.isStorageTextureNode=!0,this.access=Ss.WRITE_ONLY}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let r;return r=null!==this.storeNode?this.generateStore(e):super.generate(e,t),r}toReadWrite(){return this.setAccess(Ss.READ_WRITE)}toReadOnly(){return this.setAccess(Ss.READ_ONLY)}toWriteOnly(){return this.setAccess(Ss.WRITE_ONLY)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:r,storeNode:s}=t,i=super.generate(e,"property"),n=r.build(e,"uvec2"),o=s.build(e,"vec4"),a=e.generateTextureStore(e,i,n,o);e.addLineFlowCode(a,this)}}const Sf=xi(Nf);class Af extends Al{static get type(){return"UserDataNode"}constructor(e,t,r=null){super(e,t,r),this.userData=r}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const Rf=new WeakMap;class Cf extends Fs{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=vs.OBJECT,this.updateAfterType=vs.OBJECT,this.previousModelWorldMatrix=tn(new n),this.previousProjectionMatrix=tn(new n).setGroup(Zi),this.previousCameraViewMatrix=tn(new n)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:r}){const s=wf(r);this.previousModelWorldMatrix.value.copy(s);const i=Ef(t);i.frameId!==e&&(i.frameId=e,void 0===i.previousProjectionMatrix?(i.previousProjectionMatrix=new n,i.previousCameraViewMatrix=new n,i.currentProjectionMatrix=new n,i.currentCameraViewMatrix=new n,i.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(i.previousProjectionMatrix.copy(i.currentProjectionMatrix),i.previousCameraViewMatrix.copy(i.currentCameraViewMatrix)),i.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(i.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(i.previousCameraViewMatrix))}updateAfter({object:e}){wf(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Nu:tn(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),r=e.mul($u).mul(qu),s=this.previousProjectionMatrix.mul(t).mul(Ku),i=r.xy.div(r.w),n=s.xy.div(s.w);return Gn(i,n)}}function Ef(e){let t=Rf.get(e);return void 0===t&&(t={},Rf.set(e,t)),t}function wf(e,t=0){const r=Ef(e);let s=r[t];return void 0===s&&(r[t]=s=new n),s}const Mf=Ti(Cf),Bf=_i((([e,t])=>Ko(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"blendBurn",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Uf=_i((([e,t])=>Ko(e.div(t.oneMinus()),1))).setLayout({name:"blendDodge",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Ff=_i((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"blendScreen",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Pf=_i((([e,t])=>da(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Qo(.5,e)))).setLayout({name:"blendOverlay",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),If=_i((([e,t])=>{const r=t.a.add(e.a.mul(t.a.oneMinus()));return Oi(t.rgb.mul(t.a).add(e.rgb.mul(e.a).mul(t.a.oneMinus())).div(r),r)})).setLayout({name:"blendColor",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Lf=_i((([e])=>Gf(e.rgb))),Df=_i((([e,t=Ci(1)])=>t.mix(Gf(e.rgb),e.rgb))),Vf=_i((([e,t=Ci(1)])=>{const r=On(e.r,e.g,e.b).div(3),s=e.r.max(e.g.max(e.b)),i=s.sub(r).mul(t).mul(-3);return da(e.rgb,s,i)})),Of=_i((([e,t=Ci(1)])=>{const r=Ii(.57735,.57735,.57735),s=t.cos();return Ii(e.rgb.mul(s).add(r.cross(e.rgb).mul(t.sin()).add(r.mul(ta(r,e.rgb).mul(s.oneMinus())))))})),Gf=(e,t=Ii(u.getLuminanceCoefficients(new r)))=>ta(e,t),kf=_i((([e,t=Ii(1),s=Ii(0),i=Ii(1),n=Ci(1),o=Ii(u.getLuminanceCoefficients(new r,Ae))])=>{const a=e.rgb.dot(Ii(o)),l=Xo(e.rgb.mul(t).add(s),0).toVar(),d=l.pow(i).toVar();return Si(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),Si(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),Si(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(n))),Oi(l.rgb,e.a)}));class zf extends Fs{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const $f=xi(zf),Wf=new t;class Hf extends bu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class jf extends Hf{static get type(){return"PassMultipleTextureNode"}constructor(e,t,r=!1){super(e,null),this.textureName=t,this.previousTexture=r}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class qf extends Fs{static get type(){return"PassNode"}constructor(e,t,r,s={}){super("vec4"),this.scope=e,this.scene=t,this.camera=r,this.options=s,this._pixelRatio=1,this._width=1,this._height=1;const i=new B;i.isRenderTargetTexture=!0,i.name="depth";const n=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...s});n.texture.name="output",n.depthTexture=i,this.renderTarget=n,this.updateBeforeType=vs.FRAME,this._textures={output:n.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=tn(0),this._cameraFar=tn(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const r=this._textures[e],s=this.renderTarget.textures.indexOf(r);this.renderTarget.textures[s]=t,this._textures[e]=t,this._previousTextures[e]=r,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=fi(new jf(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=fi(new jf(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const r=this._cameraNear,s=this._cameraFar;this._viewZNodes[e]=t=Oc(this.getTextureNode(e),r,s)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const r=this._cameraNear,s=this._cameraFar,i=this.getViewZNode(e);this._linearDepthNodes[e]=t=Dc(i,r,s)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===qf.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:r,camera:s}=this;this._pixelRatio=t.getPixelRatio();const i=t.getSize(Wf);this.setSize(i.width,i.height);const n=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=s.near,this._cameraFar.value=s.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(r,s),t.setRenderTarget(n),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const r=this._width*this._pixelRatio,s=this._height*this._pixelRatio;this.renderTarget.setSize(r,s)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}qf.COLOR="color",qf.DEPTH="depth";class Kf extends qf{static get type(){return"ToonOutlinePassNode"}constructor(e,t,r,s,i){super(qf.COLOR,e,t),this.colorNode=r,this.thicknessNode=s,this.alphaNode=i,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,r=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,r,s,i,n,o,a,u)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const l=this._getOutlineMaterial(n);t.renderObject(e,r,s,i,l,o,a,u)}t.renderObject(e,r,s,i,n,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(r)}_createMaterial(){const e=new Yc;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=sl.negate(),r=Nu.mul($u),s=Ci(1),i=r.mul(Oi(qu,1)),n=r.mul(Oi(qu.add(t),1)),o=Ro(i.sub(n));return e.vertexNode=i.add(o.mul(this.thicknessNode).mul(i.w).mul(s)),e.colorNode=Oi(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const Xf=_i((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Yf=_i((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qf=_i((([e,t])=>{const r=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),s=e.mul(e.mul(6.2).add(1.7)).add(.06);return r.div(s).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Zf=_i((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),r=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(r)})),Jf=_i((([e,t])=>{const r=Wi(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),s=Wi(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=r.mul(e),e=Zf(e),(e=s.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),ey=Wi(Ii(1.6605,-.1246,-.0182),Ii(-.5876,1.1329,-.1006),Ii(-.0728,-.0083,1.1187)),ty=Wi(Ii(.6274,.0691,.0164),Ii(.3293,.9195,.088),Ii(.0433,.0113,.8956)),ry=_i((([e])=>{const t=Ii(e).toVar(),r=Ii(t.mul(t)).toVar(),s=Ii(r.mul(r)).toVar();return Ci(15.5).mul(s.mul(r)).sub(kn(40.14,s.mul(t))).add(kn(31.96,s).sub(kn(6.868,r.mul(t))).add(kn(.4298,r).add(kn(.1191,t).sub(.00232))))})),sy=_i((([e,t])=>{const r=Ii(e).toVar(),s=Wi(Ii(.856627153315983,.137318972929847,.11189821299995),Ii(.0951212405381588,.761241990602591,.0767994186031903),Ii(.0482516061458583,.101439036467562,.811302368396859)),i=Wi(Ii(1.1271005818144368,-.1413297634984383,-.14132976349843826),Ii(-.11060664309660323,1.157823702216272,-.11060664309660294),Ii(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=Ci(-12.47393),o=Ci(4.026069);return r.mulAssign(t),r.assign(ty.mul(r)),r.assign(s.mul(r)),r.assign(Xo(r,1e-10)),r.assign(_o(r)),r.assign(r.sub(n).div(o.sub(n))),r.assign(ca(r,0,1)),r.assign(ry(r)),r.assign(i.mul(r)),r.assign(sa(Xo(Ii(0),r),Ii(2.2))),r.assign(ey.mul(r)),r.assign(ca(r,0,1)),r})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),iy=_i((([e,t])=>{const r=Ci(.76),s=Ci(.15);e=e.mul(t);const i=Ko(e.r,Ko(e.g,e.b)),n=Ta(i.lessThan(.08),i.sub(kn(6.25,i.mul(i))),.04);e.subAssign(n);const o=Xo(e.r,Xo(e.g,e.b));Si(o.lessThan(r),(()=>e));const a=Gn(1,r),u=Gn(1,a.mul(a).div(o.add(a.sub(r))));e.mulAssign(u.div(o));const l=Gn(1,zn(1,s.mul(o.sub(u)).add(1)));return da(e,Ii(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class ny extends Ms{static get type(){return"CodeNode"}constructor(e="",t=[],r=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=r,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const r of t)r.build(e);const r=e.getCodeFromNode(this,this.getNodeType(e));return r.code=this.code,r.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const oy=xi(ny);class ay extends ny{static get type(){return"FunctionNode"}constructor(e="",t=[],r=""){super(e,t,r)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let r=t.nodeFunction;return void 0===r&&(r=e.parser.parseFunction(this.code),t.nodeFunction=r),r}generate(e,t){super.generate(e);const r=this.getNodeFunction(e),s=r.name,i=r.type,n=e.getCodeFromNode(this,i);""!==s&&(n.name=s);const o=e.getPropertyName(n),a=this.getNodeFunction(e).getCode(o);return n.code=a+"\n","property"===t?o:e.format(`${o}()`,i,t)}}const uy=(e,t=[],r="")=>{for(let e=0;es.call(...e);return i.functionNode=s,i};class ly extends Ms{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Ci()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=bs(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?xs(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const dy=xi(ly);class cy extends Map{get(e,t=null,...r){if(this.has(e))return super.get(e);if(null!==t){const s=t(...r);return this.set(e,s),s}}}class hy{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const py=new cy;class gy extends Ms{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new cy,this._output=dy(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const r=this._outputs;return void 0===r[e]?r[e]=dy(t):r[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const r=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),r[e]=t,r[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),r[e]=t,r[e].events.addEventListener("refresh",this.onRefresh)):void 0===r[e]?(r[e]=dy(t),r[e].events.addEventListener("refresh",this.onRefresh)):r[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const r=this.getObject()[e];if("function"==typeof r)return r(...t)}async callAsync(e,...t){const r=this.getObject()[e];if("function"==typeof r)return"AsyncFunction"===r.constructor.name?await r(...t):r(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new hy(this),t=py.get("THREE"),r=py.get("TSL"),s=this.getMethod(this.codeNode),i=[e,this._local,py,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,r];this._object=s(...i);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const e of n.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Ci()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",r="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],r),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[us(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const r in this.parameters)t.push(this.parameters[r].getCacheKey(e));return ls(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const my=xi(gy);class fy extends Ms{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const r=e.context.getViewZ;return void 0!==r&&(t=r(this)),(t||Qu.z).negate()}setup(){return this.factorNode}}const yy=xi(fy);class by extends fy{static get type(){return"FogRangeNode"}constructor(e,t,r){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=r}setup(e){const t=this.getViewZNode(e);return ga(this.nearNode,this.farNode,t)}}const xy=xi(by);class Ty extends fy{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),r=this.densityNode;return r.mul(r,t,t).negate().exp().oneMinus()}}const _y=xi(Ty);let vy=null,Ny=null;class Sy extends Ms{static get type(){return"RangeNode"}constructor(e=Ci(),t=Ci()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(fs(this.minNode.value)),r=e.getTypeLength(fs(this.maxNode.value));return t>r?t:r}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let r=null;if(t.count>1){const i=this.minNode.value,n=this.maxNode.value,o=e.getTypeLength(fs(i)),u=e.getTypeLength(fs(n));vy=vy||new s,Ny=Ny||new s,vy.setScalar(0),Ny.setScalar(0),1===o?vy.setScalar(i):i.isColor?vy.set(i.r,i.g,i.b):vy.set(i.x,i.y,i.z||0,i.w||0),1===u?Ny.setScalar(n):n.isColor?Ny.set(n.r,n.g,n.b):Ny.set(n.x,n.y,n.z||0,n.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;efi(new Ry(e,t)),Ey=Cy("numWorkgroups","uvec3"),wy=Cy("workgroupId","uvec3"),My=Cy("localId","uvec3"),By=Cy("subgroupSize","uint");const Uy=xi(class extends Ms{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:r}=e;!0===r.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}});class Fy extends Bs{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let r;const s=e.context.assign;if(r=super.generate(e),!0!==s){const s=this.getNodeType(e);r=e.format(r,s,t)}return r}}class Py extends Ms{constructor(e,t,r=0){super(t),this.bufferType=t,this.bufferCount=r,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return fi(new Fy(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}class Iy extends Fs{static get type(){return"AtomicFunctionNode"}constructor(e,t,r,s=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=r,this.storeNode=s}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,r=this.getNodeType(e),s=this.getInputType(e),i=this.pointerNode,n=this.valueNode,o=[];o.push(`&${i.build(e,s)}`),o.push(n.build(e,s));const a=`${e.getMethod(t,r)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,s);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}Iy.ATOMIC_LOAD="atomicLoad",Iy.ATOMIC_STORE="atomicStore",Iy.ATOMIC_ADD="atomicAdd",Iy.ATOMIC_SUB="atomicSub",Iy.ATOMIC_MAX="atomicMax",Iy.ATOMIC_MIN="atomicMin",Iy.ATOMIC_AND="atomicAnd",Iy.ATOMIC_OR="atomicOr",Iy.ATOMIC_XOR="atomicXor";const Ly=xi(Iy),Dy=(e,t,r,s)=>{const i=Ly(e,t,r,s);return i.append(),i};let Vy;function Oy(e){Vy=Vy||new WeakMap;let t=Vy.get(e);return void 0===t&&Vy.set(e,t={}),t}function Gy(e){const t=Oy(e);return t.shadowMatrix||(t.shadowMatrix=tn("mat4").setGroup(Zi).onRenderUpdate((()=>(e.shadow.updateMatrices(e),e.shadow.matrix))))}function ky(e){const t=Oy(e);if(void 0===t.projectionUV){const r=Gy(e).mul(Xu);t.projectionUV=r.xyz.div(r.w)}return t.projectionUV}function zy(e){const t=Oy(e);return t.position||(t.position=tn(new r).setGroup(Zi).onRenderUpdate(((t,r)=>r.value.setFromMatrixPosition(e.matrixWorld))))}function $y(e){const t=Oy(e);return t.targetPosition||(t.targetPosition=tn(new r).setGroup(Zi).onRenderUpdate(((t,r)=>r.value.setFromMatrixPosition(e.target.matrixWorld))))}function Wy(e){const t=Oy(e);return t.viewPosition||(t.viewPosition=tn(new r).setGroup(Zi).onRenderUpdate((({camera:t},s)=>{s.value=s.value||new r,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(t.matrixWorldInverse)})))}const Hy=e=>Au.transformDirection(zy(e).sub($y(e))),jy=(e,t)=>{for(const r of t)if(r.isAnalyticLightNode&&r.light.id===e)return r;return null},qy=new WeakMap;class Ky extends Ms{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Ii().toVar("totalDiffuse"),this.totalSpecularNode=Ii().toVar("totalSpecular"),this.outgoingLightNode=Ii().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const r of t.nodes)r.build(e)}setupLightsNode(e){const t=[],r=this._lightNodes,s=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),i=e.renderer.library;for(const e of s)if(e.isNode)t.push(fi(e));else{let s=null;if(null!==r&&(s=jy(e.id,r)),null===s){const r=i.getLightNodeClass(e.constructor);if(null===r){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let s=null;qy.has(e)?s=qy.get(e):(s=fi(new r(e)),qy.set(e,s)),t.push(s)}}this._lightNodes=t}setupLights(e,t){for(const r of t)r.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,r=t.lightingModel;let s=this.outgoingLightNode;if(r){const{_lightNodes:i,totalDiffuseNode:n,totalSpecularNode:o}=this;t.outgoingLight=s;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,r.start(t,a,e),this.setupLights(e,i),r.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Ii(null!==l?l.mix(g,u):u),t.material.transparent=!0),n.assign(g),o.assign(c.add(p)),s.assign(n.add(o)),r.finish(t,a,e),s=s.bypass(e.removeStack())}return s}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const Xy=new WeakMap,Yy=Ii().toVar("shadowWorldPosition"),Qy=_i((([e,t,r])=>{let s=Xu.sub(e).length();return s=s.sub(t).div(r.sub(t)),s=s.saturate(),s})),Zy=e=>{let t=Xy.get(e);if(void 0===t){const r=e.isPointLight?(e=>{const t=e.shadow.camera,r=Rl("near","float",t).setGroup(Zi),s=Rl("far","float",t).setGroup(Zi),i=Uu(e);return Qy(i,r,s)})(e):null;t=new Yc,t.colorNode=Oi(0,0,0,1),t.depthNode=r,t.isShadowNodeMaterial=!0,t.blending=D,t.name="ShadowMaterial",Xy.set(e,t)}return t},Jy=_i((({depthTexture:e,shadowCoord:t})=>xu(e,t.xy).compare(t.z))),eb=_i((({depthTexture:e,shadowCoord:t,shadow:r})=>{const s=(t,r)=>xu(e,t).compare(r),i=Rl("mapSize","vec2",r).setGroup(Zi),n=Rl("radius","float",r).setGroup(Zi),o=Bi(1).div(i),a=o.x.negate().mul(n),u=o.y.negate().mul(n),l=o.x.mul(n),d=o.y.mul(n),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return On(s(t.xy.add(Bi(a,u)),t.z),s(t.xy.add(Bi(0,u)),t.z),s(t.xy.add(Bi(l,u)),t.z),s(t.xy.add(Bi(c,h)),t.z),s(t.xy.add(Bi(0,h)),t.z),s(t.xy.add(Bi(p,h)),t.z),s(t.xy.add(Bi(a,0)),t.z),s(t.xy.add(Bi(c,0)),t.z),s(t.xy,t.z),s(t.xy.add(Bi(p,0)),t.z),s(t.xy.add(Bi(l,0)),t.z),s(t.xy.add(Bi(c,g)),t.z),s(t.xy.add(Bi(0,g)),t.z),s(t.xy.add(Bi(p,g)),t.z),s(t.xy.add(Bi(a,d)),t.z),s(t.xy.add(Bi(0,d)),t.z),s(t.xy.add(Bi(l,d)),t.z)).mul(1/17)})),tb=_i((({depthTexture:e,shadowCoord:t,shadow:r})=>{const s=(t,r)=>xu(e,t).compare(r),i=Rl("mapSize","vec2",r).setGroup(Zi),n=Bi(1).div(i),o=n.x,a=n.y,u=t.xy,l=Co(u.mul(i).add(.5));return u.subAssign(l.mul(n)),On(s(u,t.z),s(u.add(Bi(o,0)),t.z),s(u.add(Bi(0,a)),t.z),s(u.add(n),t.z),da(s(u.add(Bi(o.negate(),0)),t.z),s(u.add(Bi(o.mul(2),0)),t.z),l.x),da(s(u.add(Bi(o.negate(),a)),t.z),s(u.add(Bi(o.mul(2),a)),t.z),l.x),da(s(u.add(Bi(0,a.negate())),t.z),s(u.add(Bi(0,a.mul(2))),t.z),l.y),da(s(u.add(Bi(o,a.negate())),t.z),s(u.add(Bi(o,a.mul(2))),t.z),l.y),da(da(s(u.add(Bi(o.negate(),a.negate())),t.z),s(u.add(Bi(o.mul(2),a.negate())),t.z),l.x),da(s(u.add(Bi(o.negate(),a.mul(2))),t.z),s(u.add(Bi(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),rb=_i((({depthTexture:e,shadowCoord:t})=>{const r=Ci(1).toVar(),s=xu(e).uv(t.xy).rg,i=Qo(t.z,s.x);return Si(i.notEqual(Ci(1)),(()=>{const e=t.z.sub(s.x),n=Xo(0,s.y.mul(s.y));let o=n.div(n.add(e.mul(e)));o=ca(Gn(o,.3).div(.95-.3)),r.assign(ca(Xo(i,o)))})),r})),sb=_i((({samples:e,radius:t,size:r,shadowPass:s})=>{const i=Ci(0).toVar(),n=Ci(0).toVar(),o=e.lessThanEqual(Ci(1)).select(Ci(0),Ci(2).div(e.sub(1))),a=e.lessThanEqual(Ci(1)).select(Ci(0),Ci(-1));ic({start:Ei(0),end:Ei(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Ci(e).mul(o)),l=s.uv(On(_c.xy,Bi(0,u).mul(t)).div(r)).x;i.addAssign(l),n.addAssign(l.mul(l))})),i.divAssign(e),n.divAssign(e);const u=vo(n.sub(i.mul(i)));return Bi(i,u)})),ib=_i((({samples:e,radius:t,size:r,shadowPass:s})=>{const i=Ci(0).toVar(),n=Ci(0).toVar(),o=e.lessThanEqual(Ci(1)).select(Ci(0),Ci(2).div(e.sub(1))),a=e.lessThanEqual(Ci(1)).select(Ci(0),Ci(-1));ic({start:Ei(0),end:Ei(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Ci(e).mul(o)),l=s.uv(On(_c.xy,Bi(u,0).mul(t)).div(r));i.addAssign(l.x),n.addAssign(On(l.y.mul(l.y),l.x.mul(l.x)))})),i.divAssign(e),n.divAssign(e);const u=vo(n.sub(i.mul(i)));return Bi(i,u)})),nb=[Jy,eb,tb,rb],ob=new ef;class ab extends Ms{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=vs.RENDER,this._node=null,this.isShadowNode=!0}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:s,shadow:i}){const n=s.x.greaterThanEqual(0).and(s.x.lessThanEqual(1)).and(s.y.greaterThanEqual(0)).and(s.y.lessThanEqual(1)).and(s.z.lessThanEqual(1)),o=t({depthTexture:r,shadowCoord:s,shadow:i});return n.select(o,Ci(1))}setupShadowCoord(e,t){const{shadow:r}=this,{renderer:s}=e,i=Rl("bias","float",r).setGroup(Zi);let n,o=t;if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)o=o.xyz.div(o.w),n=o.z,s.coordinateSystem===v&&(n=n.mul(2).sub(1));else{const e=o.w;o=o.xy.div(e);const t=Rl("near","float",r.camera).setGroup(Zi),s=Rl("far","float",r.camera).setGroup(Zi);n=Gc(e.negate(),t,s)}return o=Ii(o.x,o.y.oneMinus(),n.add(i)),o}getShadowFilterFn(e){return nb[e]}setupShadow(e){const{renderer:t}=e,{light:r,shadow:s}=this,i=t.shadowMap.type,n=new B(s.mapSize.width,s.mapSize.height);n.compareFunction=Re;const o=e.createRenderTarget(s.mapSize.width,s.mapSize.height);if(o.depthTexture=n,s.camera.updateProjectionMatrix(),i===Ce){n.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:Ee,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(s.mapSize.width,s.mapSize.height,{format:Ee,type:ye});const t=xu(n),r=xu(this.vsmShadowMapVertical.texture),i=Rl("blurSamples","float",s).setGroup(Zi),o=Rl("radius","float",s).setGroup(Zi),a=Rl("mapSize","vec2",s).setGroup(Zi);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new Yc);u.fragmentNode=sb({samples:i,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new Yc),u.fragmentNode=ib({samples:i,radius:o,size:a,shadowPass:r}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Rl("intensity","float",s).setGroup(Zi),u=Rl("normalBias","float",s).setGroup(Zi),l=Gy(r).mul(Yy.add(ul.mul(u))),d=this.setupShadowCoord(e,l),c=s.filterNode||this.getShadowFilterFn(t.shadowMap.type)||null;if(null===c)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const h=i===Ce?this.vsmShadowMapHorizontal.texture:n,p=this.setupShadowFilter(e,{filterFn:c,shadowTexture:o.texture,depthTexture:h,shadowCoord:d,shadow:s}),g=xu(o.texture,d),m=da(1,p.rgb.mix(g,1),a.mul(g.a)).toVar();return this.shadowMap=o,this.shadow.map=o,m}setup(e){if(!1!==e.renderer.shadowMap.enabled)return _i((({material:t})=>{Yy.assign(t.shadowPositionNode||Xu);let r=this._node;return null===r&&(this._node=r=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(r=e.material.receivedShadowNode(r)),r}))()}renderShadow(e){const{shadow:t,shadowMap:r}=this,{renderer:s,scene:i}=e;r.setSize(t.mapSize.width,t.mapSize.height),s.render(i,t.camera)}updateShadow(e){const{shadowMap:t,light:r,shadow:s}=this,{renderer:i,scene:n,camera:o}=e,a=i.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=n.overrideMaterial;n.overrideMaterial=Zy(r),s.camera.layers.mask=o.layers.mask;const d=i.getRenderTarget(),c=i.getRenderObjectFunction(),h=i.getMRT();i.setMRT(null),i.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Ce)&&i.renderObject(e,...t)})),i.setRenderTarget(t),this.renderShadow(e),i.setRenderObjectFunction(c),!0!==r.isPointLight&&a===Ce&&this.vsmPass(i),i.setRenderTarget(d),i.setMRT(h),n.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),ob.material=this.vsmMaterialVertical,ob.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),ob.material=this.vsmMaterialHorizontal,ob.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=vs.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const ub=(e,t)=>fi(new ab(e,t));class lb extends cc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.light=t,this.color=new e,this.colorNode=t&&t.colorNode||tn(this.color).setGroup(Zi),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=vs.FRAME}getCacheKey(){return ds(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadowNode(){return ub(this.light)}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let r=this.shadowColorNode;if(null===r){const t=this.light.shadow.shadowNode;let s;s=void 0!==t?fi(t):this.setupShadowNode(e),this.shadowNode=s,this.shadowColorNode=r=this.colorNode.mul(s),this.baseColorNode=this.colorNode}this.colorNode=r}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null)}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const db=_i((e=>{const{lightDistance:t,cutoffDistance:r,decayExponent:s}=e,i=t.pow(s).max(.01).reciprocal();return r.greaterThan(0).select(i.mul(t.div(r).pow4().oneMinus().clamp().pow2()),i)})),cb=new e,hb=_i((([e,t])=>{const r=e.toVar(),s=Po(r),i=zn(1,Xo(s.x,Xo(s.y,s.z)));s.mulAssign(i),r.mulAssign(i.mul(t.mul(2).oneMinus()));const n=Bi(r.xy).toVar(),o=t.mul(1.5).oneMinus();return Si(s.z.greaterThanEqual(o),(()=>{Si(r.z.greaterThan(0),(()=>{n.x.assign(Gn(4,r.x))}))})).ElseIf(s.x.greaterThanEqual(o),(()=>{const e=Io(r.x);n.x.assign(r.z.mul(e).add(e.mul(2)))})).ElseIf(s.y.greaterThanEqual(o),(()=>{const e=Io(r.y);n.x.assign(r.x.add(e.mul(2)).add(2)),n.y.assign(r.z.mul(e).sub(2))})),Bi(.125,.25).mul(n).add(Bi(.375,.75)).flipY()})).setLayout({name:"cubeToUV",type:"vec2",inputs:[{name:"pos",type:"vec3"},{name:"texelSizeY",type:"float"}]}),pb=_i((({depthTexture:e,bd3D:t,dp:r,texelSize:s})=>xu(e,hb(t,s.y)).compare(r))),gb=_i((({depthTexture:e,bd3D:t,dp:r,texelSize:s,shadow:i})=>{const n=Rl("radius","float",i).setGroup(Zi),o=Bi(-1,1).mul(n).mul(s.y);return xu(e,hb(t.add(o.xyy),s.y)).compare(r).add(xu(e,hb(t.add(o.yyy),s.y)).compare(r)).add(xu(e,hb(t.add(o.xyx),s.y)).compare(r)).add(xu(e,hb(t.add(o.yyx),s.y)).compare(r)).add(xu(e,hb(t,s.y)).compare(r)).add(xu(e,hb(t.add(o.xxy),s.y)).compare(r)).add(xu(e,hb(t.add(o.yxy),s.y)).compare(r)).add(xu(e,hb(t.add(o.xxx),s.y)).compare(r)).add(xu(e,hb(t.add(o.yxx),s.y)).compare(r)).mul(1/9)})),mb=_i((({filterFn:e,depthTexture:t,shadowCoord:r,shadow:s})=>{const i=r.xyz.toVar(),n=i.length(),o=tn("float").setGroup(Zi).onRenderUpdate((()=>s.camera.near)),a=tn("float").setGroup(Zi).onRenderUpdate((()=>s.camera.far)),u=Rl("bias","float",s).setGroup(Zi),l=tn(s.mapSize).setGroup(Zi),d=Ci(1).toVar();return Si(n.sub(a).lessThanEqual(0).and(n.sub(o).greaterThanEqual(0)),(()=>{const r=n.sub(o).div(a.sub(o)).toVar();r.addAssign(u);const c=i.normalize(),h=Bi(1).div(l.mul(Bi(4,2)));d.assign(e({depthTexture:t,bd3D:c,dp:r,texelSize:h,shadow:s}))})),d})),fb=new s,yb=new t,bb=new t;class xb extends ab{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===we?pb:gb}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,shadowTexture:r,depthTexture:s,shadowCoord:i,shadow:n}){return mb({filterFn:t,shadowTexture:r,depthTexture:s,shadowCoord:i,shadow:n})}renderShadow(e){const{shadow:t,shadowMap:r,light:s}=this,{renderer:i,scene:n}=e,o=t.getFrameExtents();bb.copy(t.mapSize),bb.multiply(o),r.setSize(bb.width,bb.height),yb.copy(t.mapSize);const a=i.autoClear,u=i.getClearColor(cb),l=i.getClearAlpha();i.autoClear=!1,i.setClearColor(t.clearColor,t.clearAlpha),i.clear();const d=t.getViewportCount();for(let e=0;e{const n=i.context.lightingModel,o=t.sub(Qu),a=o.normalize(),u=o.length(),l=db({lightDistance:u,cutoffDistance:r,decayExponent:s}),d=e.mul(l),c=i.context.reflectedLight;n.direct({lightDirection:a,lightColor:d,reflectedLight:c},i.stack,i)}));class _b extends lb{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=tn(0).setGroup(Zi),this.decayExponentNode=tn(0).setGroup(Zi)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){return((e,t)=>fi(new xb(e,t)))(this.light)}setup(e){super.setup(e),Tb({color:this.colorNode,lightViewPosition:Wy(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const vb=_i((([e=t()])=>{const t=e.mul(2),r=t.x.floor(),s=t.y.floor();return r.add(s).mod(2).sign()})),Nb=_i((([e,t,r])=>{const s=Ci(r).toVar(),i=Ci(t).toVar(),n=Mi(e).toVar();return Ta(n,i,s)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),Sb=_i((([e,t])=>{const r=Mi(t).toVar(),s=Ci(e).toVar();return Ta(r,s.negate(),s)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),Ab=_i((([e])=>{const t=Ci(e).toVar();return Ei(So(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),Rb=_i((([e,t])=>{const r=Ci(e).toVar();return t.assign(Ab(r)),r.sub(Ci(t))})),Cb=Nm([_i((([e,t,r,s,i,n])=>{const o=Ci(n).toVar(),a=Ci(i).toVar(),u=Ci(s).toVar(),l=Ci(r).toVar(),d=Ci(t).toVar(),c=Ci(e).toVar(),h=Ci(Gn(1,a)).toVar();return Gn(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),_i((([e,t,r,s,i,n])=>{const o=Ci(n).toVar(),a=Ci(i).toVar(),u=Ii(s).toVar(),l=Ii(r).toVar(),d=Ii(t).toVar(),c=Ii(e).toVar(),h=Ci(Gn(1,a)).toVar();return Gn(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),Eb=Nm([_i((([e,t,r,s,i,n,o,a,u,l,d])=>{const c=Ci(d).toVar(),h=Ci(l).toVar(),p=Ci(u).toVar(),g=Ci(a).toVar(),m=Ci(o).toVar(),f=Ci(n).toVar(),y=Ci(i).toVar(),b=Ci(s).toVar(),x=Ci(r).toVar(),T=Ci(t).toVar(),_=Ci(e).toVar(),v=Ci(Gn(1,p)).toVar(),N=Ci(Gn(1,h)).toVar();return Ci(Gn(1,c)).toVar().mul(N.mul(_.mul(v).add(T.mul(p))).add(h.mul(x.mul(v).add(b.mul(p))))).add(c.mul(N.mul(y.mul(v).add(f.mul(p))).add(h.mul(m.mul(v).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),_i((([e,t,r,s,i,n,o,a,u,l,d])=>{const c=Ci(d).toVar(),h=Ci(l).toVar(),p=Ci(u).toVar(),g=Ii(a).toVar(),m=Ii(o).toVar(),f=Ii(n).toVar(),y=Ii(i).toVar(),b=Ii(s).toVar(),x=Ii(r).toVar(),T=Ii(t).toVar(),_=Ii(e).toVar(),v=Ci(Gn(1,p)).toVar(),N=Ci(Gn(1,h)).toVar();return Ci(Gn(1,c)).toVar().mul(N.mul(_.mul(v).add(T.mul(p))).add(h.mul(x.mul(v).add(b.mul(p))))).add(c.mul(N.mul(y.mul(v).add(f.mul(p))).add(h.mul(m.mul(v).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),wb=_i((([e,t,r])=>{const s=Ci(r).toVar(),i=Ci(t).toVar(),n=wi(e).toVar(),o=wi(n.bitAnd(wi(7))).toVar(),a=Ci(Nb(o.lessThan(wi(4)),i,s)).toVar(),u=Ci(kn(2,Nb(o.lessThan(wi(4)),s,i))).toVar();return Sb(a,Mi(o.bitAnd(wi(1)))).add(Sb(u,Mi(o.bitAnd(wi(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),Mb=_i((([e,t,r,s])=>{const i=Ci(s).toVar(),n=Ci(r).toVar(),o=Ci(t).toVar(),a=wi(e).toVar(),u=wi(a.bitAnd(wi(15))).toVar(),l=Ci(Nb(u.lessThan(wi(8)),o,n)).toVar(),d=Ci(Nb(u.lessThan(wi(4)),n,Nb(u.equal(wi(12)).or(u.equal(wi(14))),o,i))).toVar();return Sb(l,Mi(u.bitAnd(wi(1)))).add(Sb(d,Mi(u.bitAnd(wi(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),Bb=Nm([wb,Mb]),Ub=_i((([e,t,r])=>{const s=Ci(r).toVar(),i=Ci(t).toVar(),n=Di(e).toVar();return Ii(Bb(n.x,i,s),Bb(n.y,i,s),Bb(n.z,i,s))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),Fb=_i((([e,t,r,s])=>{const i=Ci(s).toVar(),n=Ci(r).toVar(),o=Ci(t).toVar(),a=Di(e).toVar();return Ii(Bb(a.x,o,n,i),Bb(a.y,o,n,i),Bb(a.z,o,n,i))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),Pb=Nm([Ub,Fb]),Ib=_i((([e])=>{const t=Ci(e).toVar();return kn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),Lb=_i((([e])=>{const t=Ci(e).toVar();return kn(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),Db=Nm([Ib,_i((([e])=>{const t=Ii(e).toVar();return kn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),Vb=Nm([Lb,_i((([e])=>{const t=Ii(e).toVar();return kn(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),Ob=_i((([e,t])=>{const r=Ei(t).toVar(),s=wi(e).toVar();return s.shiftLeft(r).bitOr(s.shiftRight(Ei(32).sub(r)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),Gb=_i((([e,t,r])=>{e.subAssign(r),e.bitXorAssign(Ob(r,Ei(4))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(Ob(e,Ei(6))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(Ob(t,Ei(8))),t.addAssign(e),e.subAssign(r),e.bitXorAssign(Ob(r,Ei(16))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(Ob(e,Ei(19))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(Ob(t,Ei(4))),t.addAssign(e)})),kb=_i((([e,t,r])=>{const s=wi(r).toVar(),i=wi(t).toVar(),n=wi(e).toVar();return s.bitXorAssign(i),s.subAssign(Ob(i,Ei(14))),n.bitXorAssign(s),n.subAssign(Ob(s,Ei(11))),i.bitXorAssign(n),i.subAssign(Ob(n,Ei(25))),s.bitXorAssign(i),s.subAssign(Ob(i,Ei(16))),n.bitXorAssign(s),n.subAssign(Ob(s,Ei(4))),i.bitXorAssign(n),i.subAssign(Ob(n,Ei(14))),s.bitXorAssign(i),s.subAssign(Ob(i,Ei(24))),s})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),zb=_i((([e])=>{const t=wi(e).toVar();return Ci(t).div(Ci(wi(Ei(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),$b=_i((([e])=>{const t=Ci(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),Wb=Nm([_i((([e])=>{const t=Ei(e).toVar(),r=wi(wi(1)).toVar(),s=wi(wi(Ei(3735928559)).add(r.shiftLeft(wi(2))).add(wi(13))).toVar();return kb(s.add(wi(t)),s,s)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),_i((([e,t])=>{const r=Ei(t).toVar(),s=Ei(e).toVar(),i=wi(wi(2)).toVar(),n=wi().toVar(),o=wi().toVar(),a=wi().toVar();return n.assign(o.assign(a.assign(wi(Ei(3735928559)).add(i.shiftLeft(wi(2))).add(wi(13))))),n.addAssign(wi(s)),o.addAssign(wi(r)),kb(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ei(t).toVar(),n=Ei(e).toVar(),o=wi(wi(3)).toVar(),a=wi().toVar(),u=wi().toVar(),l=wi().toVar();return a.assign(u.assign(l.assign(wi(Ei(3735928559)).add(o.shiftLeft(wi(2))).add(wi(13))))),a.addAssign(wi(n)),u.addAssign(wi(i)),l.addAssign(wi(s)),kb(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),_i((([e,t,r,s])=>{const i=Ei(s).toVar(),n=Ei(r).toVar(),o=Ei(t).toVar(),a=Ei(e).toVar(),u=wi(wi(4)).toVar(),l=wi().toVar(),d=wi().toVar(),c=wi().toVar();return l.assign(d.assign(c.assign(wi(Ei(3735928559)).add(u.shiftLeft(wi(2))).add(wi(13))))),l.addAssign(wi(a)),d.addAssign(wi(o)),c.addAssign(wi(n)),Gb(l,d,c),l.addAssign(wi(i)),kb(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),_i((([e,t,r,s,i])=>{const n=Ei(i).toVar(),o=Ei(s).toVar(),a=Ei(r).toVar(),u=Ei(t).toVar(),l=Ei(e).toVar(),d=wi(wi(5)).toVar(),c=wi().toVar(),h=wi().toVar(),p=wi().toVar();return c.assign(h.assign(p.assign(wi(Ei(3735928559)).add(d.shiftLeft(wi(2))).add(wi(13))))),c.addAssign(wi(l)),h.addAssign(wi(u)),p.addAssign(wi(a)),Gb(c,h,p),c.addAssign(wi(o)),h.addAssign(wi(n)),kb(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),Hb=Nm([_i((([e,t])=>{const r=Ei(t).toVar(),s=Ei(e).toVar(),i=wi(Wb(s,r)).toVar(),n=Di().toVar();return n.x.assign(i.bitAnd(Ei(255))),n.y.assign(i.shiftRight(Ei(8)).bitAnd(Ei(255))),n.z.assign(i.shiftRight(Ei(16)).bitAnd(Ei(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ei(t).toVar(),n=Ei(e).toVar(),o=wi(Wb(n,i,s)).toVar(),a=Di().toVar();return a.x.assign(o.bitAnd(Ei(255))),a.y.assign(o.shiftRight(Ei(8)).bitAnd(Ei(255))),a.z.assign(o.shiftRight(Ei(16)).bitAnd(Ei(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),jb=Nm([_i((([e])=>{const t=Bi(e).toVar(),r=Ei().toVar(),s=Ei().toVar(),i=Ci(Rb(t.x,r)).toVar(),n=Ci(Rb(t.y,s)).toVar(),o=Ci($b(i)).toVar(),a=Ci($b(n)).toVar(),u=Ci(Cb(Bb(Wb(r,s),i,n),Bb(Wb(r.add(Ei(1)),s),i.sub(1),n),Bb(Wb(r,s.add(Ei(1))),i,n.sub(1)),Bb(Wb(r.add(Ei(1)),s.add(Ei(1))),i.sub(1),n.sub(1)),o,a)).toVar();return Db(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),_i((([e])=>{const t=Ii(e).toVar(),r=Ei().toVar(),s=Ei().toVar(),i=Ei().toVar(),n=Ci(Rb(t.x,r)).toVar(),o=Ci(Rb(t.y,s)).toVar(),a=Ci(Rb(t.z,i)).toVar(),u=Ci($b(n)).toVar(),l=Ci($b(o)).toVar(),d=Ci($b(a)).toVar(),c=Ci(Eb(Bb(Wb(r,s,i),n,o,a),Bb(Wb(r.add(Ei(1)),s,i),n.sub(1),o,a),Bb(Wb(r,s.add(Ei(1)),i),n,o.sub(1),a),Bb(Wb(r.add(Ei(1)),s.add(Ei(1)),i),n.sub(1),o.sub(1),a),Bb(Wb(r,s,i.add(Ei(1))),n,o,a.sub(1)),Bb(Wb(r.add(Ei(1)),s,i.add(Ei(1))),n.sub(1),o,a.sub(1)),Bb(Wb(r,s.add(Ei(1)),i.add(Ei(1))),n,o.sub(1),a.sub(1)),Bb(Wb(r.add(Ei(1)),s.add(Ei(1)),i.add(Ei(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return Vb(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),qb=Nm([_i((([e])=>{const t=Bi(e).toVar(),r=Ei().toVar(),s=Ei().toVar(),i=Ci(Rb(t.x,r)).toVar(),n=Ci(Rb(t.y,s)).toVar(),o=Ci($b(i)).toVar(),a=Ci($b(n)).toVar(),u=Ii(Cb(Pb(Hb(r,s),i,n),Pb(Hb(r.add(Ei(1)),s),i.sub(1),n),Pb(Hb(r,s.add(Ei(1))),i,n.sub(1)),Pb(Hb(r.add(Ei(1)),s.add(Ei(1))),i.sub(1),n.sub(1)),o,a)).toVar();return Db(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),_i((([e])=>{const t=Ii(e).toVar(),r=Ei().toVar(),s=Ei().toVar(),i=Ei().toVar(),n=Ci(Rb(t.x,r)).toVar(),o=Ci(Rb(t.y,s)).toVar(),a=Ci(Rb(t.z,i)).toVar(),u=Ci($b(n)).toVar(),l=Ci($b(o)).toVar(),d=Ci($b(a)).toVar(),c=Ii(Eb(Pb(Hb(r,s,i),n,o,a),Pb(Hb(r.add(Ei(1)),s,i),n.sub(1),o,a),Pb(Hb(r,s.add(Ei(1)),i),n,o.sub(1),a),Pb(Hb(r.add(Ei(1)),s.add(Ei(1)),i),n.sub(1),o.sub(1),a),Pb(Hb(r,s,i.add(Ei(1))),n,o,a.sub(1)),Pb(Hb(r.add(Ei(1)),s,i.add(Ei(1))),n.sub(1),o,a.sub(1)),Pb(Hb(r,s.add(Ei(1)),i.add(Ei(1))),n,o.sub(1),a.sub(1)),Pb(Hb(r.add(Ei(1)),s.add(Ei(1)),i.add(Ei(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return Vb(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),Kb=Nm([_i((([e])=>{const t=Ci(e).toVar(),r=Ei(Ab(t)).toVar();return zb(Wb(r))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),_i((([e])=>{const t=Bi(e).toVar(),r=Ei(Ab(t.x)).toVar(),s=Ei(Ab(t.y)).toVar();return zb(Wb(r,s))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),_i((([e])=>{const t=Ii(e).toVar(),r=Ei(Ab(t.x)).toVar(),s=Ei(Ab(t.y)).toVar(),i=Ei(Ab(t.z)).toVar();return zb(Wb(r,s,i))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),_i((([e])=>{const t=Oi(e).toVar(),r=Ei(Ab(t.x)).toVar(),s=Ei(Ab(t.y)).toVar(),i=Ei(Ab(t.z)).toVar(),n=Ei(Ab(t.w)).toVar();return zb(Wb(r,s,i,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),Xb=Nm([_i((([e])=>{const t=Ci(e).toVar(),r=Ei(Ab(t)).toVar();return Ii(zb(Wb(r,Ei(0))),zb(Wb(r,Ei(1))),zb(Wb(r,Ei(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),_i((([e])=>{const t=Bi(e).toVar(),r=Ei(Ab(t.x)).toVar(),s=Ei(Ab(t.y)).toVar();return Ii(zb(Wb(r,s,Ei(0))),zb(Wb(r,s,Ei(1))),zb(Wb(r,s,Ei(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),_i((([e])=>{const t=Ii(e).toVar(),r=Ei(Ab(t.x)).toVar(),s=Ei(Ab(t.y)).toVar(),i=Ei(Ab(t.z)).toVar();return Ii(zb(Wb(r,s,i,Ei(0))),zb(Wb(r,s,i,Ei(1))),zb(Wb(r,s,i,Ei(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),_i((([e])=>{const t=Oi(e).toVar(),r=Ei(Ab(t.x)).toVar(),s=Ei(Ab(t.y)).toVar(),i=Ei(Ab(t.z)).toVar(),n=Ei(Ab(t.w)).toVar();return Ii(zb(Wb(r,s,i,n,Ei(0))),zb(Wb(r,s,i,n,Ei(1))),zb(Wb(r,s,i,n,Ei(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),Yb=_i((([e,t,r,s])=>{const i=Ci(s).toVar(),n=Ci(r).toVar(),o=Ei(t).toVar(),a=Ii(e).toVar(),u=Ci(0).toVar(),l=Ci(1).toVar();return ic(o,(()=>{u.addAssign(l.mul(jb(a))),l.mulAssign(i),a.mulAssign(n)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),Qb=_i((([e,t,r,s])=>{const i=Ci(s).toVar(),n=Ci(r).toVar(),o=Ei(t).toVar(),a=Ii(e).toVar(),u=Ii(0).toVar(),l=Ci(1).toVar();return ic(o,(()=>{u.addAssign(l.mul(qb(a))),l.mulAssign(i),a.mulAssign(n)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),Zb=_i((([e,t,r,s])=>{const i=Ci(s).toVar(),n=Ci(r).toVar(),o=Ei(t).toVar(),a=Ii(e).toVar();return Bi(Yb(a,o,n,i),Yb(a.add(Ii(Ei(19),Ei(193),Ei(17))),o,n,i))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),Jb=_i((([e,t,r,s])=>{const i=Ci(s).toVar(),n=Ci(r).toVar(),o=Ei(t).toVar(),a=Ii(e).toVar(),u=Ii(Qb(a,o,n,i)).toVar(),l=Ci(Yb(a.add(Ii(Ei(19),Ei(193),Ei(17))),o,n,i)).toVar();return Oi(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),ex=Nm([_i((([e,t,r,s,i,n,o])=>{const a=Ei(o).toVar(),u=Ci(n).toVar(),l=Ei(i).toVar(),d=Ei(s).toVar(),c=Ei(r).toVar(),h=Ei(t).toVar(),p=Bi(e).toVar(),g=Ii(Xb(Bi(h.add(d),c.add(l)))).toVar(),m=Bi(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=Bi(Bi(Ci(h),Ci(c)).add(m)).toVar(),y=Bi(f.sub(p)).toVar();return Si(a.equal(Ei(2)),(()=>Po(y.x).add(Po(y.y)))),Si(a.equal(Ei(3)),(()=>Xo(Po(y.x),Po(y.y)))),ta(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),_i((([e,t,r,s,i,n,o,a,u])=>{const l=Ei(u).toVar(),d=Ci(a).toVar(),c=Ei(o).toVar(),h=Ei(n).toVar(),p=Ei(i).toVar(),g=Ei(s).toVar(),m=Ei(r).toVar(),f=Ei(t).toVar(),y=Ii(e).toVar(),b=Ii(Xb(Ii(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Ii(Ii(Ci(f),Ci(m),Ci(g)).add(b)).toVar(),T=Ii(x.sub(y)).toVar();return Si(l.equal(Ei(2)),(()=>Po(T.x).add(Po(T.y)).add(Po(T.z)))),Si(l.equal(Ei(3)),(()=>Xo(Xo(Po(T.x),Po(T.y)),Po(T.z)))),ta(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),tx=_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ci(t).toVar(),n=Bi(e).toVar(),o=Ei().toVar(),a=Ei().toVar(),u=Bi(Rb(n.x,o),Rb(n.y,a)).toVar(),l=Ci(1e6).toVar();return ic({start:-1,end:Ei(1),name:"x",condition:"<="},(({x:e})=>{ic({start:-1,end:Ei(1),name:"y",condition:"<="},(({y:t})=>{const r=Ci(ex(u,e,t,o,a,i,s)).toVar();l.assign(Ko(l,r))}))})),Si(s.equal(Ei(0)),(()=>{l.assign(vo(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),rx=_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ci(t).toVar(),n=Bi(e).toVar(),o=Ei().toVar(),a=Ei().toVar(),u=Bi(Rb(n.x,o),Rb(n.y,a)).toVar(),l=Bi(1e6,1e6).toVar();return ic({start:-1,end:Ei(1),name:"x",condition:"<="},(({x:e})=>{ic({start:-1,end:Ei(1),name:"y",condition:"<="},(({y:t})=>{const r=Ci(ex(u,e,t,o,a,i,s)).toVar();Si(r.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(r)})).ElseIf(r.lessThan(l.y),(()=>{l.y.assign(r)}))}))})),Si(s.equal(Ei(0)),(()=>{l.assign(vo(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),sx=_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ci(t).toVar(),n=Bi(e).toVar(),o=Ei().toVar(),a=Ei().toVar(),u=Bi(Rb(n.x,o),Rb(n.y,a)).toVar(),l=Ii(1e6,1e6,1e6).toVar();return ic({start:-1,end:Ei(1),name:"x",condition:"<="},(({x:e})=>{ic({start:-1,end:Ei(1),name:"y",condition:"<="},(({y:t})=>{const r=Ci(ex(u,e,t,o,a,i,s)).toVar();Si(r.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(r)})).ElseIf(r.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(r)})).ElseIf(r.lessThan(l.z),(()=>{l.z.assign(r)}))}))})),Si(s.equal(Ei(0)),(()=>{l.assign(vo(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),ix=Nm([tx,_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ci(t).toVar(),n=Ii(e).toVar(),o=Ei().toVar(),a=Ei().toVar(),u=Ei().toVar(),l=Ii(Rb(n.x,o),Rb(n.y,a),Rb(n.z,u)).toVar(),d=Ci(1e6).toVar();return ic({start:-1,end:Ei(1),name:"x",condition:"<="},(({x:e})=>{ic({start:-1,end:Ei(1),name:"y",condition:"<="},(({y:t})=>{ic({start:-1,end:Ei(1),name:"z",condition:"<="},(({z:r})=>{const n=Ci(ex(l,e,t,r,o,a,u,i,s)).toVar();d.assign(Ko(d,n))}))}))})),Si(s.equal(Ei(0)),(()=>{d.assign(vo(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),nx=Nm([rx,_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ci(t).toVar(),n=Ii(e).toVar(),o=Ei().toVar(),a=Ei().toVar(),u=Ei().toVar(),l=Ii(Rb(n.x,o),Rb(n.y,a),Rb(n.z,u)).toVar(),d=Bi(1e6,1e6).toVar();return ic({start:-1,end:Ei(1),name:"x",condition:"<="},(({x:e})=>{ic({start:-1,end:Ei(1),name:"y",condition:"<="},(({y:t})=>{ic({start:-1,end:Ei(1),name:"z",condition:"<="},(({z:r})=>{const n=Ci(ex(l,e,t,r,o,a,u,i,s)).toVar();Si(n.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.y.assign(n)}))}))}))})),Si(s.equal(Ei(0)),(()=>{d.assign(vo(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),ox=Nm([sx,_i((([e,t,r])=>{const s=Ei(r).toVar(),i=Ci(t).toVar(),n=Ii(e).toVar(),o=Ei().toVar(),a=Ei().toVar(),u=Ei().toVar(),l=Ii(Rb(n.x,o),Rb(n.y,a),Rb(n.z,u)).toVar(),d=Ii(1e6,1e6,1e6).toVar();return ic({start:-1,end:Ei(1),name:"x",condition:"<="},(({x:e})=>{ic({start:-1,end:Ei(1),name:"y",condition:"<="},(({y:t})=>{ic({start:-1,end:Ei(1),name:"z",condition:"<="},(({z:r})=>{const n=Ci(ex(l,e,t,r,o,a,u,i,s)).toVar();Si(n.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(n)})).ElseIf(n.lessThan(d.z),(()=>{d.z.assign(n)}))}))}))})),Si(s.equal(Ei(0)),(()=>{d.assign(vo(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),ax=_i((([e])=>{const t=e.y,r=e.z,s=Ii().toVar();return Si(t.lessThan(1e-4),(()=>{s.assign(Ii(r,r,r))})).Else((()=>{let i=e.x;i=i.sub(So(i)).mul(6).toVar();const n=Ei($o(i)),o=i.sub(Ci(n)),a=r.mul(t.oneMinus()),u=r.mul(t.mul(o).oneMinus()),l=r.mul(t.mul(o.oneMinus()).oneMinus());Si(n.equal(Ei(0)),(()=>{s.assign(Ii(r,l,a))})).ElseIf(n.equal(Ei(1)),(()=>{s.assign(Ii(u,r,a))})).ElseIf(n.equal(Ei(2)),(()=>{s.assign(Ii(a,r,l))})).ElseIf(n.equal(Ei(3)),(()=>{s.assign(Ii(a,u,r))})).ElseIf(n.equal(Ei(4)),(()=>{s.assign(Ii(l,a,r))})).Else((()=>{s.assign(Ii(r,a,u))}))})),s})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),ux=_i((([e])=>{const t=Ii(e).toVar(),r=Ci(t.x).toVar(),s=Ci(t.y).toVar(),i=Ci(t.z).toVar(),n=Ci(Ko(r,Ko(s,i))).toVar(),o=Ci(Xo(r,Xo(s,i))).toVar(),a=Ci(o.sub(n)).toVar(),u=Ci().toVar(),l=Ci().toVar(),d=Ci().toVar();return d.assign(o),Si(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),Si(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{Si(r.greaterThanEqual(o),(()=>{u.assign(s.sub(i).div(a))})).ElseIf(s.greaterThanEqual(o),(()=>{u.assign(On(2,i.sub(r).div(a)))})).Else((()=>{u.assign(On(4,r.sub(s).div(a)))})),u.mulAssign(1/6),Si(u.lessThan(0),(()=>{u.addAssign(1)}))})),Ii(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),lx=_i((([e])=>{const t=Ii(e).toVar(),r=Vi(qn(t,Ii(.04045))).toVar(),s=Ii(t.div(12.92)).toVar(),i=Ii(sa(Xo(t.add(Ii(.055)),Ii(0)).div(1.055),Ii(2.4))).toVar();return da(s,i,r)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),dx=(e,t)=>{e=Ci(e),t=Ci(t);const r=Bi(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return ga(e.sub(r),e.add(r),t)},cx=(e,t,r,s)=>da(e,t,r[s].clamp()),hx=(e,t,r,s,i)=>da(e,t,dx(r,s[i])),px=_i((([e,t,r])=>{const s=Ro(e).toVar("nDir"),i=Gn(Ci(.5).mul(t.sub(r)),Xu).div(s).toVar("rbmax"),n=Gn(Ci(-.5).mul(t.sub(r)),Xu).div(s).toVar("rbmin"),o=Ii().toVar("rbminmax");o.x=s.x.greaterThan(Ci(0)).select(i.x,n.x),o.y=s.y.greaterThan(Ci(0)).select(i.y,n.y),o.z=s.z.greaterThan(Ci(0)).select(i.z,n.z);const a=Ko(Ko(o.x,o.y),o.z).toVar("correction");return Xu.add(s.mul(a)).toVar("boxIntersection").sub(r)})),gx=_i((([e,t])=>{const r=e.x,s=e.y,i=e.z;let n=t.element(0).mul(.886227);return n=n.add(t.element(1).mul(1.023328).mul(s)),n=n.add(t.element(2).mul(1.023328).mul(i)),n=n.add(t.element(3).mul(1.023328).mul(r)),n=n.add(t.element(4).mul(.858086).mul(r).mul(s)),n=n.add(t.element(5).mul(.858086).mul(s).mul(i)),n=n.add(t.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),n=n.add(t.element(7).mul(.858086).mul(r).mul(i)),n=n.add(t.element(8).mul(.429043).mul(kn(r,r).sub(kn(s,s)))),n}));var mx=Object.freeze({__proto__:null,BRDF_GGX:kh,BRDF_Lambert:Rh,BasicShadowFilter:Jy,Break:nc,Continue:()=>au("continue").append(),DFGApprox:zh,D_GGX:Vh,Discard:uu,EPSILON:uo,F_Schlick:Ah,Fn:_i,INFINITY:lo,If:Si,Loop:ic,NodeAccess:Ss,NodeShaderStage:_s,NodeType:Ns,NodeUpdateType:vs,PCFShadowFilter:eb,PCFSoftShadowFilter:tb,PI:co,PI2:ho,Return:()=>au("return").append(),Schlick_to_F0:Wh,ScriptableNodeResources:py,ShaderNode:mi,TBNViewMatrix:$l,VSMShadowFilter:rb,V_GGX_SmithCorrelated:Lh,abs:Po,acesFilmicToneMapping:Jf,acos:Uo,add:On,addMethodChaining:$s,addNodeElement:function(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)},agxToneMapping:sy,all:po,alphaT:yn,and:Yn,anisotropy:bn,anisotropyB:Tn,anisotropyT:xn,any:go,append:Ai,arrayBuffer:e=>fi(new Gs(e,"ArrayBuffer")),asin:Bo,assign:In,atan:Fo,atan2:qo,atomicAdd:(e,t,r=null)=>Dy(Iy.ATOMIC_ADD,e,t,r),atomicAnd:(e,t,r=null)=>Dy(Iy.ATOMIC_AND,e,t,r),atomicFunc:Dy,atomicMax:(e,t,r=null)=>Dy(Iy.ATOMIC_MAX,e,t,r),atomicMin:(e,t,r=null)=>Dy(Iy.ATOMIC_MIN,e,t,r),atomicOr:(e,t,r=null)=>Dy(Iy.ATOMIC_OR,e,t,r),atomicStore:(e,t,r=null)=>Dy(Iy.ATOMIC_STORE,e,t,r),atomicSub:(e,t,r=null)=>Dy(Iy.ATOMIC_SUB,e,t,r),atomicXor:(e,t,r=null)=>Dy(Iy.ATOMIC_XOR,e,t,r),attenuationColor:Un,attenuationDistance:Bn,attribute:hu,attributeArray:(e,t="float")=>{const r=ms(t),s=new lf(e,r);return pf(s,t,e)},backgroundBlurriness:Tf,backgroundIntensity:_f,backgroundRotation:vf,batch:Jd,billboarding:wm,bitAnd:eo,bitNot:to,bitOr:ro,bitXor:so,bitangentGeometry:Dl,bitangentLocal:Vl,bitangentView:Ol,bitangentWorld:Gl,bitcast:Ho,blendBurn:Bf,blendColor:If,blendDodge:Uf,blendOverlay:Pf,blendScreen:Ff,blur:zp,bool:Mi,buffer:Tl,bufferAttribute:qa,bumpMap:Zl,burn:(...e)=>(console.warn('THREE.TSL: "burn" has been renamed. Use "blendBurn" instead.'),Bf(e)),bvec2:Pi,bvec3:Vi,bvec4:zi,bypass:ru,cache:eu,call:Dn,cameraFar:vu,cameraNear:_u,cameraNormalMatrix:Cu,cameraPosition:Eu,cameraProjectionMatrix:Nu,cameraProjectionMatrixInverse:Su,cameraViewMatrix:Au,cameraWorldMatrix:Ru,cbrt:ua,cdl:kf,ceil:Ao,checker:vb,cineonToneMapping:Qf,clamp:ca,clearcoat:dn,clearcoatRoughness:cn,code:oy,color:Ri,colorSpaceToWorking:Va,colorToDirection:e=>fi(e).mul(2).sub(1),compute:Za,cond:_a,context:Na,convert:qi,convertColorSpace:(e,t,r)=>fi(new Pa(fi(e),t,r)),convertToTexture:(e,...t)=>e.isTextureNode?e:e.isPassNode?e.getTextureNode():sf(e,...t),cos:wo,cross:ra,cubeTexture:bl,dFdx:Oo,dFdy:Go,dashSize:An,defaultBuildStages:Rs,defaultShaderStages:As,defined:pi,degrees:yo,deltaTime:Am,densityFog:_y,depth:zc,depthPass:(e,t)=>fi(new qf(qf.DEPTH,e,t)),difference:ea,diffuseColor:on,directPointLight:Tb,directionToColor:uh,dispersion:Fn,distance:Jo,div:zn,dodge:(...e)=>(console.warn('THREE.TSL: "dodge" has been renamed. Use "blendDodge" instead.'),Uf(e)),dot:ta,drawIndex:qd,dynamicBufferAttribute:Ka,element:ji,emissive:an,equal:Wn,equals:mo,equirectUV:hh,exp:bo,exp2:xo,expression:au,faceDirection:tl,faceForward:ma,float:Ci,floor:So,fog:yy,fract:Co,frameGroup:Qi,frameId:Rm,frontFacing:el,fwidth:Wo,gain:(e,t)=>e.lessThan(.5)?ym(e.mul(2),t).div(2):Gn(1,ym(kn(Gn(1,e),2),t).div(2)),gapSize:Rn,getConstNodeType:gi,getCurrentStack:Ni,getDirection:Vp,getDistanceAttenuation:db,getGeometryRoughness:Ph,getNormalFromDepth:af,getParallaxCorrectNormal:px,getRoughness:Ih,getScreenPosition:of,getShIrradianceAt:gx,getTextureIndex:pm,getViewPosition:nf,glsl:(e,t)=>oy(e,t,"glsl"),glslFn:(e,t)=>uy(e,t,"glsl"),grayscale:Lf,greaterThan:qn,greaterThanEqual:Xn,hash:fm,highPrecisionModelNormalViewMatrix:Hu,highPrecisionModelViewMatrix:Wu,hue:Of,instance:Xd,instanceIndex:$d,instancedArray:(e,t="float")=>{const r=ms(t),s=new uf(e,r);return pf(s,t,e)},instancedBufferAttribute:Xa,instancedDynamicBufferAttribute:Ya,instancedMesh:Qd,int:Ei,inverseSqrt:No,invocationLocalIndex:jd,invocationSubgroupIndex:Hd,ior:En,iridescence:gn,iridescenceIOR:mn,iridescenceThickness:fn,ivec2:Ui,ivec3:Li,ivec4:Gi,js:(e,t)=>oy(e,t,"js"),label:Sa,length:Lo,lengthSq:la,lessThan:jn,lessThanEqual:Kn,lightPosition:zy,lightProjectionUV:ky,lightShadowMatrix:Gy,lightTargetDirection:Hy,lightTargetPosition:$y,lightViewPosition:Wy,lightingContext:gc,lights:(e=[])=>fi(new Ky).setLights(e),linearDepth:$c,linearToneMapping:Xf,localId:My,log:To,log2:_o,logarithmicDepthToViewZ:(e,t,r)=>{const s=e.mul(To(r.div(t)));return Ci(Math.E).pow(s).mul(t).negate()},loop:(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),ic(...e)),luminance:Gf,mat2:$i,mat3:Wi,mat4:Hi,matcapUV:lg,materialAOMap:Dd,materialAlphaTest:td,materialAnisotropy:Td,materialAnisotropyVector:Vd,materialAttenuationColor:Ed,materialAttenuationDistance:Cd,materialClearcoat:gd,materialClearcoatNormal:fd,materialClearcoatRoughness:md,materialColor:rd,materialDispersion:Id,materialEmissive:id,materialIOR:Rd,materialIridescence:_d,materialIridescenceIOR:vd,materialIridescenceThickness:Nd,materialLightMap:Ld,materialLineDashOffset:Fd,materialLineDashSize:Md,materialLineGapSize:Bd,materialLineScale:wd,materialLineWidth:Ud,materialMetalness:hd,materialNormal:pd,materialOpacity:nd,materialPointWidth:Pd,materialReference:wl,materialReflectivity:dd,materialRefractionRatio:hl,materialRotation:yd,materialRoughness:cd,materialSheen:bd,materialSheenRoughness:xd,materialShininess:sd,materialSpecular:od,materialSpecularColor:ud,materialSpecularIntensity:ad,materialSpecularStrength:ld,materialThickness:Ad,materialTransmission:Sd,max:Xo,maxMipLevel:yu,metalness:ln,min:Ko,mix:da,mixElement:ya,mod:Yo,modInt:$n,modelDirection:Lu,modelNormalMatrix:ku,modelPosition:Vu,modelScale:Ou,modelViewMatrix:$u,modelViewPosition:Gu,modelViewProjection:Gd,modelWorldMatrix:Du,modelWorldMatrixInverse:zu,morphReference:dc,mrt:mm,mul:kn,mx_aastep:dx,mx_cell_noise_float:(e=pu())=>Kb(e.convert("vec2|vec3")),mx_contrast:(e,t=1,r=.5)=>Ci(e).sub(r).mul(t).add(r),mx_fractal_noise_float:(e=pu(),t=3,r=2,s=.5,i=1)=>Yb(e,Ei(t),r,s).mul(i),mx_fractal_noise_vec2:(e=pu(),t=3,r=2,s=.5,i=1)=>Zb(e,Ei(t),r,s).mul(i),mx_fractal_noise_vec3:(e=pu(),t=3,r=2,s=.5,i=1)=>Qb(e,Ei(t),r,s).mul(i),mx_fractal_noise_vec4:(e=pu(),t=3,r=2,s=.5,i=1)=>Jb(e,Ei(t),r,s).mul(i),mx_hsvtorgb:ax,mx_noise_float:(e=pu(),t=1,r=0)=>jb(e.convert("vec2|vec3")).mul(t).add(r),mx_noise_vec3:(e=pu(),t=1,r=0)=>qb(e.convert("vec2|vec3")).mul(t).add(r),mx_noise_vec4:(e=pu(),t=1,r=0)=>{e=e.convert("vec2|vec3");return Oi(qb(e),jb(e.add(Bi(19,73)))).mul(t).add(r)},mx_ramplr:(e,t,r=pu())=>cx(e,t,r,"x"),mx_ramptb:(e,t,r=pu())=>cx(e,t,r,"y"),mx_rgbtohsv:ux,mx_safepower:(e,t=1)=>(e=Ci(e)).abs().pow(t).mul(e.sign()),mx_splitlr:(e,t,r,s=pu())=>hx(e,t,r,s,"x"),mx_splittb:(e,t,r,s=pu())=>hx(e,t,r,s,"y"),mx_srgb_texture_to_lin_rec709:lx,mx_transform_uv:(e=1,t=0,r=pu())=>r.mul(e).add(t),mx_worley_noise_float:(e=pu(),t=1)=>ix(e.convert("vec2|vec3"),t,Ei(1)),mx_worley_noise_vec2:(e=pu(),t=1)=>nx(e.convert("vec2|vec3"),t,Ei(1)),mx_worley_noise_vec3:(e=pu(),t=1)=>ox(e.convert("vec2|vec3"),t,Ei(1)),negate:Do,neutralToneMapping:iy,nodeArray:bi,nodeImmutable:Ti,nodeObject:fi,nodeObjects:yi,nodeProxy:xi,normalFlat:il,normalGeometry:rl,normalLocal:sl,normalMap:Kl,normalView:nl,normalWorld:ol,normalize:Ro,not:Zn,notEqual:Hn,numWorkgroups:Ey,objectDirection:Mu,objectGroup:Ji,objectPosition:Uu,objectScale:Fu,objectViewPosition:Pu,objectWorldMatrix:Bu,oneMinus:Vo,or:Qn,orthographicDepthToViewZ:(e,t,r)=>t.sub(r).mul(e).sub(t),oscSawtooth:(e=Sm)=>e.fract(),oscSine:(e=Sm)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),oscSquare:(e=Sm)=>e.fract().round(),oscTriangle:(e=Sm)=>e.add(.5).fract().mul(2).sub(1).abs(),output:Sn,outputStruct:hm,overlay:(...e)=>(console.warn('THREE.TSL: "overlay" has been renamed. Use "blendOverlay" instead.'),Pf(e)),overloadingFn:Nm,parabola:ym,parallaxDirection:Wl,parallaxUV:(e,t)=>e.sub(Wl.mul(t)),parameter:(e,t)=>fi(new am(e,t)),pass:(e,t,r)=>fi(new qf(qf.COLOR,e,t,r)),passTexture:(e,t)=>fi(new Hf(e,t)),pcurve:(e,t,r)=>sa(zn(sa(e,t),On(sa(e,t),sa(Gn(1,e),r))),1/t),perspectiveDepthToViewZ:Oc,pmremTexture:qp,pointUV:ff,pointWidth:Cn,positionGeometry:ju,positionLocal:qu,positionPrevious:Ku,positionView:Qu,positionViewDirection:Zu,positionWorld:Xu,positionWorldDirection:Yu,posterize:$f,pow:sa,pow2:ia,pow3:na,pow4:oa,property:sn,radians:fo,rand:fa,range:Ay,rangeFog:xy,reciprocal:zo,reference:Rl,referenceBuffer:Cl,reflect:Zo,reflectVector:ml,reflectView:pl,reflector:e=>fi(new Xm(e)),refract:pa,refractVector:fl,refractView:gl,reinhardToneMapping:Yf,remainder:oo,remap:iu,remapClamp:nu,renderGroup:Zi,renderOutput:du,rendererReference:za,rotate:mg,rotateUV:Cm,roughness:un,round:ko,rtt:sf,sRGBTransferEOTF:Ma,sRGBTransferOETF:Ba,sampler:e=>(!0===e.isNode?e:xu(e)).convert("sampler"),saturate:ha,saturation:Df,screen:(...e)=>(console.warn('THREE.TSL: "screen" has been renamed. Use "blendScreen" instead.'),Ff(e)),screenCoordinate:_c,screenSize:Tc,screenUV:xc,scriptable:my,scriptableValue:dy,select:Ta,setCurrentStack:vi,shaderStages:Cs,shadow:ub,sharedUniformGroup:Yi,sheen:hn,sheenRoughness:pn,shiftLeft:io,shiftRight:no,shininess:Nn,sign:Io,sin:Eo,sinc:(e,t)=>Eo(co.mul(t.mul(e).sub(1))).div(co.mul(t.mul(e).sub(1))),skinning:e=>fi(new tc(e)),skinningReference:rc,smoothstep:ga,smoothstepElement:ba,specularColor:_n,specularF90:vn,spherizeUV:Em,split:(e,t)=>fi(new Ls(fi(e),t)),spritesheetUV:Um,sqrt:vo,stack:lm,step:Qo,storage:pf,storageBarrier:()=>Uy("storage").append(),storageObject:(e,t,r)=>(console.warn('THREE.TSL: "storageObject()" is deprecated. Use "storage().setPBO( true )" instead.'),pf(e,t,r).setPBO(!0)),storageTexture:Sf,string:(e="")=>fi(new Gs(e,"string")),sub:Gn,subgroupIndex:Wd,subgroupSize:By,tan:Mo,tangentGeometry:Ml,tangentLocal:Bl,tangentView:Ul,tangentWorld:Fl,temp:Ca,texture:xu,texture3D:Ng,textureBarrier:()=>Uy("texture").append(),textureBicubic:up,textureCubeUV:Op,textureLoad:Tu,textureSize:mu,textureStore:(e,t,r)=>{const s=Sf(e,t,r);return null!==r&&s.append(),s},thickness:Mn,threshold:(e,t)=>da(Ii(0),e,Gf(e).sub(t).max(0)),time:Sm,timerDelta:(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Am.mul(e)),timerGlobal:(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Sm.mul(e)),timerLocal:(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Sm.mul(e)),toOutputColorSpace:Ia,toWorkingColorSpace:La,toneMapping:Wa,toneMappingExposure:Ha,toonOutlinePass:(t,r,s=new e(0,0,0),i=.003,n=1)=>fi(new Kf(t,r,fi(s),fi(i),fi(n))),transformDirection:aa,transformNormal:dl,transformNormalToView:cl,transformedBentNormalView:Hl,transformedBitangentView:kl,transformedBitangentWorld:zl,transformedClearcoatNormalView:ll,transformedNormalView:al,transformedNormalWorld:ul,transformedTangentView:Pl,transformedTangentWorld:Il,transmission:wn,transpose:jo,tri:bm,tri3:xm,triNoise3D:Tm,triplanarTexture:(...e)=>Pm(...e),triplanarTextures:Pm,trunc:$o,tslFn:(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),_i(...e)),uint:wi,uniform:tn,uniformArray:Nl,uniformGroup:Xi,uniforms:(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),fi(new vl(e,t))),userData:(e,t,r)=>fi(new Af(e,t,r)),uv:pu,uvec2:Fi,uvec3:Di,uvec4:ki,varying:wa,varyingProperty:nn,vec2:Bi,vec3:Ii,vec4:Oi,vectorComponents:Es,velocity:Mf,vertexColor:(...e)=>fi(new gf(...e)),vertexIndex:zd,vibrance:Vf,viewZToLogarithmicDepth:Gc,viewZToOrthographicDepth:Dc,viewZToPerspectiveDepth:Vc,viewport:vc,viewportBottomLeft:Ec,viewportCoordinate:Sc,viewportDepthTexture:Ic,viewportLinearDepth:Wc,viewportMipTexture:Uc,viewportResolution:Rc,viewportSafeUV:Mm,viewportSharedTexture:nh,viewportSize:Nc,viewportTexture:Bc,viewportTopLeft:Cc,viewportUV:Ac,wgsl:(e,t)=>oy(e,t,"wgsl"),wgslFn:(e,t)=>uy(e,t,"wgsl"),workgroupArray:(e,t)=>fi(new Py("Workgroup",e,t)),workgroupBarrier:()=>Uy("workgroup").append(),workgroupId:wy,workingToColorSpace:Da,xor:Jn});const fx=new om;class yx extends Bg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,r){const s=this.renderer,i=this.nodes.getBackgroundNode(e)||e.background;let n=!1;if(null===i)s._clearColor.getRGB(fx,Ae),fx.a=s._clearColor.a;else if(!0===i.isColor)i.getRGB(fx,Ae),fx.a=1,n=!0;else if(!0===i.isNode){const r=this.get(e),n=i;fx.copy(s._clearColor);let o=r.backgroundMesh;if(void 0===o){const e=Na(Oi(n).mul(_f),{getUV:()=>vf.mul(ol),getTextureLevel:()=>Tf});let t=Gd();t=t.setZ(t.w);const s=new Yc;s.name="Background.material",s.side=x,s.depthTest=!1,s.depthWrite=!1,s.fog=!1,s.lights=!1,s.vertexNode=t,s.colorNode=e,r.backgroundMeshNode=e,r.backgroundMesh=o=new k(new Me(1,32,32),s),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,r){this.matrixWorld.copyPosition(r.matrixWorld)}}const a=n.getCacheKey();r.backgroundCacheKey!==a&&(r.backgroundMeshNode.node=Oi(n).mul(_f),r.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,r.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",i);if(!0===s.autoClear||!0===n){const e=r.clearColorValue;e.r=fx.r,e.g=fx.g,e.b=fx.b,e.a=fx.a,!0!==s.backend.isWebGLBackend&&!0!==s.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),r.depthClearValue=s._clearDepth,r.stencilClearValue=s._clearStencil,r.clearColor=!0===s.autoClearColor,r.clearDepth=!0===s.autoClearDepth,r.clearStencil=!0===s.autoClearStencil}else r.clearColor=!1,r.clearDepth=!1,r.clearStencil=!1}}let bx=0;class xx{constructor(e="",t=[],r=0,s=[]){this.name=e,this.bindings=t,this.index=r,this.bindingsReference=s,this.id=bx++}}class Tx{constructor(e,t,r,s,i,n,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=r,this.transforms=l,this.nodeAttributes=s,this.bindings=i,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const r=new xx(t.name,[],t.index,t);e.push(r);for(const e of t.bindings)r.bindings.push(e.clone())}else e.push(t)}return e}}class _x{constructor(e,t,r=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=r}}class vx{constructor(e,t,r){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=r.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class Nx{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class Sx extends Nx{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class Ax{constructor(e,t,r=""){this.name=e,this.type=t,this.code=r,Object.defineProperty(this,"isNodeCode",{value:!0})}}let Rx=0;class Cx{constructor(e=null){this.id=Rx++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class Ex{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class wx extends Ex{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class Mx extends Ex{constructor(e,r=new t){super(e,r),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class Bx extends Ex{constructor(e,t=new r){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Ux extends Ex{constructor(e,t=new s){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Fx extends Ex{constructor(t,r=new e){super(t,r),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Px extends Ex{constructor(e,t=new i){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class Ix extends Ex{constructor(e,t=new n){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class Lx extends wx{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Dx extends Mx{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Vx extends Bx{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Ox extends Ux{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class Gx extends Fx{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class kx extends Px{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class zx extends Ix{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}const $x=[.125,.215,.35,.446,.526,.582],Wx=20,Hx=new xe(-1,1,1,-1,0,1),jx=new Ue(90,1),qx=new e;let Kx=null,Xx=0,Yx=0;const Qx=(1+Math.sqrt(5))/2,Zx=1/Qx,Jx=[new r(-Qx,Zx,0),new r(Qx,Zx,0),new r(-Zx,0,Qx),new r(Zx,0,Qx),new r(0,Qx,-Zx),new r(0,Qx,Zx),new r(-1,1,-1),new r(1,1,-1),new r(-1,1,1),new r(1,1,1)],eT=[3,1,5,0,4,2],tT=Vp(pu(),hu("faceIndex")).normalize(),rT=Ii(tT.x,tT.y.negate(),tT.z);class sT{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,r=.1,s=100,i=null){if(this._setSize(256),!1===this._hasInitialized){console.warn("THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.");const n=i||this._allocateTargets();return this.fromSceneAsync(e,t,r,s,n),n}Kx=this._renderer.getRenderTarget(),Xx=this._renderer.getActiveCubeFace(),Yx=this._renderer.getActiveMipmapLevel();const n=i||this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,r,s,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}async fromSceneAsync(e,t=0,r=.1,s=100,i=null){return!1===this._hasInitialized&&await this._renderer.init(),this.fromScene(e,t,r,s,i)}fromEquirectangular(e,t=null){if(!1===this._hasInitialized){console.warn("THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead."),this._setSizeFromTexture(e);const r=t||this._allocateTargets();return this.fromEquirectangularAsync(e,r),r}return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return!1===this._hasInitialized&&await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(!1===this._hasInitialized){console.warn("THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead."),this._setSizeFromTexture(e);const r=t||this._allocateTargets();return this.fromCubemapAsync(e,t),r}return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return!1===this._hasInitialized&&await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=aT(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=uT(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===T||e.mapping===_?this._setSize(0===e.image.length?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=$x[a-e+4-1]:0===a&&(u=0),s.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,s=[t,r,0,t+2/3,r,0,t+2/3,r+1,0,t,r,0,t+2/3,r+1,0,t,r+1,0],i=eT[e];b.set(s,m*g*i),x.set(h,f*g*i);const n=[i,i,i,i,i,i];T.set(n,y*g*i)}const _=new Te;_.setAttribute("position",new ve(b,m)),_.setAttribute("uv",new ve(x,f)),_.setAttribute("faceIndex",new ve(T,y)),t.push(_),i.push(new k(_,null)),n>4&&n--}return{lodPlanes:t,sizeLods:r,sigmas:s,lodMeshes:i}}(i)),this._blurMaterial=function(e,t,s){const i=Nl(new Array(Wx).fill(0)),n=tn(new r(0,1,0)),o=tn(0),a=Ci(Wx),u=tn(0),l=tn(1),d=xu(null),c=tn(0),h=Ci(1/t),p=Ci(1/s),g=Ci(e),m={n:a,latitudinal:u,weights:i,poleAxis:n,outputDirection:rT,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=oT("blur");return f.uniforms=m,f.fragmentNode=zp({...m,latitudinal:u.equal(1)}),f}(i,e,t)}return i}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,Hx)}_sceneToCubeUV(e,t,r,s){const i=jx;i.near=t,i.far=r;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(qx),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new G,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(qx),d=!0),a.setRenderTarget(s),a.clear(),d&&a.render(l,i);for(let t=0;t<6;t++){const r=t%3;0===r?(i.up.set(0,n[t],0),i.lookAt(o[t],0,0)):1===r?(i.up.set(0,0,n[t]),i.lookAt(0,o[t],0)):(i.up.set(0,n[t],0),i.lookAt(0,0,o[t]));const u=this._cubeSize;nT(s,r*u,t>2?u:0,u,u),a.render(e,i)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const r=this._renderer,s=e.mapping===T||e.mapping===_;s?null===this._cubemapMaterial&&(this._cubemapMaterial=aT(e)):null===this._equirectMaterial&&(this._equirectMaterial=uT(e));const i=s?this._cubemapMaterial:this._equirectMaterial;i.fragmentNode.value=e;const n=this._lodMeshes[0];n.material=i;const o=this._cubeSize;nT(t,0,0,3*o,2*o),r.setRenderTarget(t),r.render(n,Hx)}_applyPMREM(e){const t=this._renderer,r=t.autoClear;t.autoClear=!1;const s=this._lodPlanes.length;for(let t=1;tWx&&console.warn(`sigmaRadians, ${i}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?s-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,Hx)}}function iT(e,t,r){const s=new ge(e,t,r);return s.texture.mapping=Be,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function nT(e,t,r,s,i){e.viewport.set(t,r,s,i),e.scissor.set(t,r,s,i)}function oT(e){const t=new Yc;return t.depthTest=!1,t.depthWrite=!1,t.blending=D,t.name=`PMREM_${e}`,t}function aT(e){const t=oT("cubemap");return t.fragmentNode=bl(e,rT),t}function uT(e){const t=oT("equirect");return t.fragmentNode=xu(e,hh(rT),0),t}const lT=new WeakMap,dT=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),cT=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class hT{constructor(e,t,r){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=r,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=lm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new Cx,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=lT.get(this.renderer);return void 0===e&&(e=new Rg,lT.set(this.renderer,e)),e}createRenderTarget(e,t,r){return new ge(e,t,r)}createCubeRenderTarget(e,t){return new ph(e,t)}createPMREMGenerator(){return new sT(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const r=this.getBindGroupsCache(),s=[];let i,n=!0;for(const e of t)s.push(e),n=n&&!0!==e.groupNode.shared;return n?(i=r.get(s),void 0===i&&(i=new xx(e,s,this.bindingsIndexes[e].group,s),r.set(s,i))):i=new xx(e,s,this.bindingsIndexes[e].group,s),i}getBindGroupArray(e,t){const r=this.bindings[t];let s=r[e];return void 0===s&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),r[e]=s=[]),s}getBindings(){let e=this.bindGroups;if(null===e){const t={},r=this.bindings;for(const e of Cs)for(const s in r[e]){const i=r[e][s];(t[s]||(t[s]=[])).push(...i)}e=[];for(const r in t){const s=t[r],i=this._getBindGroup(r,s);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(n)}u`:"0u";if("bool"===i)return n?"true":"false";if("color"===i)return`${this.getType("vec3")}( ${cT(n.r)}, ${cT(n.g)}, ${cT(n.b)} )`;const o=this.getTypeLength(i),a=this.getComponentType(i),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)} )`;if(3===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)} )`;if(4===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)}, ${u(n.w)} )`;if(o>4&&n&&(n.isMatrix3||n.isMatrix4))return`${this.getType(i)}( ${n.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(i)}()`;throw new Error(`NodeBuilder: Type '${i}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const r=this.attributes;for(const t of r)if(t.name===e)return t;const s=new _x(e,t);return r.push(s),s}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const r=gs(e);return("float"===t?"":t[0])+r}getTypeFromArray(e){return dT.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const r=t.array,s=e.itemSize,i=e.normalized;let n;return e instanceof Le||!0===i||(n=this.getTypeFromArray(r)),this.getTypeFromLength(s,n)}getTypeLength(e){const t=this.getVectorType(e),r=/vec([2-4])/.exec(t);return null!==r?Number(r[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=lm(this.stack),this.stacks.push(Ni()||this.stack),vi(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,vi(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,r=null){let s=(r=null===r?e.isGlobal(this)?this.globalCache:this.cache:r).getData(e);return void 0===s&&(s={},r.setData(e,s)),void 0===s[t]&&(s[t]={}),s[t]}getNodeProperties(e,t="any"){const r=this.getDataFromNode(e,t);return r.properties||(r.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const r=this.getDataFromNode(e);let s=r.bufferAttribute;if(void 0===s){const i=this.uniforms.index++;s=new _x("nodeAttribute"+i,t,e),this.bufferAttributes.push(s),r.bufferAttribute=s}return s}getStructTypeFromNode(e,t=this.shaderStage){const r=this.getDataFromNode(e,t);if(void 0===r.structType){const s=this.structs.index++;e.name=`StructType${s}`,this.structs[t].push(e),r.structType=e}return e}getUniformFromNode(e,t,r=this.shaderStage,s=null){const i=this.getDataFromNode(e,r,this.globalCache);let n=i.uniform;if(void 0===n){const o=this.uniforms.index++;n=new vx(s||"nodeUniform"+o,t,e),this.uniforms[r].push(n),i.uniform=n}return n}getVarFromNode(e,t=null,r=e.getNodeType(this),s=this.shaderStage){const i=this.getDataFromNode(e,s);let n=i.variable;if(void 0===n){const e=this.vars[s]||(this.vars[s]=[]);null===t&&(t="nodeVar"+e.length),n=new Nx(t,r),e.push(n),i.variable=n}return n}getVaryingFromNode(e,t=null,r=e.getNodeType(this)){const s=this.getDataFromNode(e,"any");let i=s.varying;if(void 0===i){const e=this.varyings,n=e.length;null===t&&(t="nodeVarying"+n),i=new Sx(t,r),e.push(i),s.varying=i}return i}getCodeFromNode(e,t,r=this.shaderStage){const s=this.getDataFromNode(e);let i=s.code;if(void 0===i){const e=this.codes[r]||(this.codes[r]=[]),n=e.length;i=new Ax("nodeCode"+n,t),e.push(i),s.code=i}return i}addFlowCodeHierarchy(e,t){const{flowCodes:r,flowCodeBlock:s}=this.getDataFromNode(e);let i=!0,n=t;for(;n;){if(!0===s.get(n)){i=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(i)for(const e of r)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,r){const s=this.getDataFromNode(e),i=s.flowCodes||(s.flowCodes=[]),n=s.flowCodeBlock||(s.flowCodeBlock=new WeakMap);i.push(t),n.set(r,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),r=this.flowChildNode(e,t);return this.flowsData.set(e,r),r}buildFunctionNode(e){const t=new ay,r=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=r,t}flowShaderNode(e){const t=e.layout,r={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)r[e.name]=new am(e.type,e.name);e.layout=null;const s=e.call(r),i=this.flowStagesNode(s,t.type);return e.layout=t,i}flowStagesNode(e,t=null){const r=this.flow,s=this.vars,i=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new Cx,this.stack=lm();for(const r of Rs)this.setBuildStage(r),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=r,this.vars=s,this.cache=i,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const r=this.flow,s={code:""};return this.flow=s,s.result=e.build(this,t),this.flow=r,s}flowNodeFromShaderStage(e,t,r=null,s=null){const i=this.shaderStage;this.setShaderStage(e);const n=this.flowChildNode(t,r);return null!==s&&(n.code+=`${this.tab+s} = ${n.result};\n`),this.flowCode[e]=this.flowCode[e]+n.code,this.setShaderStage(i),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const r=this.vars[e];if(void 0!==r)for(const e of r)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let r="";if(void 0!==t)for(const e of t)r+=e.code+"\n";return r}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:r}=this;if(null!==t){let e=r.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new Yc),e.build(this)}else this.addFlow("compute",e);for(const e of Rs){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Cs){this.setShaderStage(t);const r=this.flowNodes[t];for(const t of r)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new Lx(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new Dx(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new Vx(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new Ox(e);if("color"===t)return new Gx(e);if("mat3"===t)return new kx(e);if("mat4"===t)return new zx(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,r){if((t=this.getVectorType(t))===(r=this.getVectorType(r))||null===r||this.isReference(r))return e;const s=this.getTypeLength(t),i=this.getTypeLength(r);return 16===s&&9===i?`${this.getType(r)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===s&&4===i?`${this.getType(r)}(${e}[0].xy, ${e}[1].xy)`:s>4||i>4||0===i?e:s===i?`${this.getType(r)}( ${e} )`:s>i?this.format(`${e}.${"xyz".slice(0,i)}`,this.getTypeFromLength(i,this.getComponentType(t)),r):4===i&&s>1?`${this.getType(r)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===s?`${this.getType(r)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===s&&i>1&&t!==this.getComponentType(r)&&(e=`${this.getType(this.getComponentType(r))}( ${e} )`),`${this.getType(r)}( ${e} )`)}getSignature(){return`// Three.js r${De} - Node System\n`}}class pT{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let r=e.get(t);return void 0===r&&(r={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,r)),r}updateBeforeNode(e){const t=e.getUpdateBeforeType(),r=e.updateReference(this);if(t===vs.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,r);t.get(r)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(r,this.frameId)}else if(t===vs.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,r);t.get(r)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(r,this.renderId)}else t===vs.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),r=e.updateReference(this);if(t===vs.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,r);t.get(r)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(r,this.frameId)}else if(t===vs.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,r);t.get(r)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(r,this.renderId)}else t===vs.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),r=e.updateReference(this);if(t===vs.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,r);t.get(r)!==this.frameId&&!1!==e.update(this)&&t.set(r,this.frameId)}else if(t===vs.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,r);t.get(r)!==this.renderId&&!1!==e.update(this)&&t.set(r,this.renderId)}else t===vs.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class gT{constructor(e,t,r=null,s="",i=!1){this.type=e,this.name=t,this.count=r,this.qualifier=s,this.isConst=i}}gT.isNodeFunctionInput=!0;class mT extends lb{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,r=this.colorNode,s=Hy(this.light),i=e.context.reflectedLight;t.direct({lightDirection:s,lightColor:r,reflectedLight:i},e.stack,e)}}const fT=new n,yT=new n;let bT=null;class xT extends lb{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=tn(new r).setGroup(Zi),this.halfWidth=tn(new r).setGroup(Zi),this.updateType=vs.RENDER}update(e){super.update(e);const{light:t}=this,r=e.camera.matrixWorldInverse;yT.identity(),fT.copy(t.matrixWorld),fT.premultiply(r),yT.extractRotation(fT),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(yT),this.halfHeight.value.applyMatrix4(yT)}setup(e){let t,r;super.setup(e),e.isAvailable("float32Filterable")?(t=xu(bT.LTC_FLOAT_1),r=xu(bT.LTC_FLOAT_2)):(t=xu(bT.LTC_HALF_1),r=xu(bT.LTC_HALF_2));const{colorNode:s,light:i}=this,n=e.context.lightingModel,o=Wy(i),a=e.context.reflectedLight;n.directRectArea({lightColor:s,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:r},e.stack,e)}static setLTC(e){bT=e}}class TT extends lb{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=tn(0).setGroup(Zi),this.penumbraCosNode=tn(0).setGroup(Zi),this.cutoffDistanceNode=tn(0).setGroup(Zi),this.decayExponentNode=tn(0).setGroup(Zi)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:r}=this;return ga(t,r,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:r,cutoffDistanceNode:s,decayExponentNode:i,light:n}=this,o=Wy(n).sub(Qu),a=o.normalize(),u=a.dot(Hy(n)),l=this.getSpotAttenuation(u),d=o.length(),c=db({lightDistance:d,cutoffDistance:s,decayExponent:i});let h=r.mul(l).mul(c);if(n.map){const e=ky(n),t=xu(n.map,e.xy).onRenderUpdate((()=>n.map));h=e.mul(2).sub(1).abs().lessThan(1).all().select(h.mul(t),h)}const p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class _T extends TT{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let r=null;if(t&&!0===t.isTexture){const s=e.acos().mul(1/Math.PI);r=xu(t,Bi(s,0),0).r}else r=super.getSpotAttenuation(e);return r}}class vT extends lb{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class NT extends lb{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=zy(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=tn(new e).setGroup(Zi)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:r,lightDirectionNode:s}=this,i=nl.dot(s).mul(.5).add(.5),n=da(r,t,i);e.context.irradiance.addAssign(n)}}class ST extends lb{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new r);this.lightProbe=Nl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=gx(ol,this.lightProbe);e.context.irradiance.addAssign(t)}}class AT{parseFunction(){console.warn("Abstract function.")}}class RT{constructor(e,t,r="",s=""){this.type=e,this.inputs=t,this.name=r,this.precision=s}getCode(){console.warn("Abstract function.")}}RT.isNodeFunction=!0;const CT=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,ET=/[a-z_0-9]+/gi,wT="#pragma main";class MT extends RT{constructor(e){const{type:t,inputs:r,name:s,precision:i,inputsCode:n,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(wT),r=-1!==t?e.slice(t+12):e,s=r.match(CT);if(null!==s&&5===s.length){const i=s[4],n=[];let o=null;for(;null!==(o=ET.exec(i));)n.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==r||s){let s=null;if(!0===r.isCubeTexture||r.mapping===j||r.mapping===q||r.mapping===Be)if(e.backgroundBlurriness>0||r.mapping===Be)s=qp(r);else{let e;e=!0===r.isCubeTexture?bl(r):xu(r),s=bh(e)}else!0===r.isTexture?s=xu(r,xc.flipY()).setUpdateMatrix(!0):!0!==r.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",r);t.backgroundNode=s,t.background=r,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),r=e.fog;if(r){if(t.fog!==r){let e=null;if(r.isFogExp2){const t=Rl("color","color",r).setGroup(Zi),s=Rl("density","float",r).setGroup(Zi);e=_y(t,s)}else if(r.isFog){const t=Rl("color","color",r).setGroup(Zi),s=Rl("near","float",r).setGroup(Zi),i=Rl("far","float",r).setGroup(Zi);e=xy(t,s,i)}else console.error("WebGPUNodes: Unsupported fog configuration.",r);t.fogNode=e,t.fog=r}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),r=e.environment;if(r){if(t.environment!==r){let e=null;!0===r.isCubeTexture?e=bl(r):!0===r.isTexture?e=xu(r):console.error("Nodes: Unsupported environment configuration.",r),t.environmentNode=e,t.environment=r}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,r=null,s=null,i=null){const n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=r,n.camera=s,n.material=i,n}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return UT.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,r=this.getOutputCacheKey(),s=xu(e,xc).renderOutput(t.toneMapping,t.currentColorSpace);return UT.set(e,r),s}updateBefore(e){const t=e.getNodeBuilderState();for(const r of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(r)}updateAfter(e){const t=e.getNodeBuilderState();for(const r of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(r)}updateForCompute(e){const t=this.getNodeFrame(),r=this.getForCompute(e);for(const e of r.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),r=e.getNodeBuilderState();for(const e of r.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new pT,this.nodeBuilderCache=new Map}}const PT=new me;class IT{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new i,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,r){const s=e.length;for(let i=0;i{await this.compileAsync(e,t);const s=this._renderLists.get(e,t),i=this._renderContexts.get(e,t,this._renderTarget),n=e.overrideMaterial||r.material,o=this._objects.get(r,n,e,t,s.lightsNode,i,i.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let r=this.backend;try{await r.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=r=this._getFallback(e),await r.init(this)}catch(e){return void t(e)}}this._nodes=new FT(this,r),this._animation=new Ag(this._nodes,this.info),this._attributes=new Dg(r),this._background=new yx(this,this._nodes),this._geometries=new Gg(this._attributes,this.info),this._textures=new nm(this,r,this.info),this._pipelines=new qg(r,this._nodes),this._bindings=new Kg(r,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Mg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new Jg(this.lighting),this._bundles=new DT,this._renderContexts=new sm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,r=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const s=this._nodes.nodeFrame,i=s.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:kT;null===r&&(r=e);const l=this._renderTarget,d=this._renderContexts.get(r,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,s.renderId++,s.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new IT),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),r!==e&&r.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),s.renderId=i,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const r=this._renderScene(e,t);await this.backend.resolveTimestampAsync(r,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,r){const{bundleGroup:s,camera:i,renderList:n}=e,o=this._currentRenderContext,a=this._bundles.get(s,i),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=s.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=n.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,i,t,r),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=s.version}else{const{renderObjects:e}=u;for(let t=0,r=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals($T),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals($T),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new IT),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),HT.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),WT.setFromProjectionMatrix(HT,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:v,transparentDoublePass:N,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,v),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,v),!0===this.transparent&&S.length>0&&this._renderTransparents(S,N,t,u,v),this.backend.finishRender(p),i.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==s){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,r){this._width=e,this._height=t,this._pixelRatio=r,this.domElement.width=Math.floor(e*r),this.domElement.height=Math.floor(t*r),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,r=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===r&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,r,s){const i=this._scissor;e.isVector4?i.copy(e):i.set(e,t,r,s)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,r,s,i=0,n=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,r,s),o.minDepth=i,o.maxDepth=n}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,r=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,r);const s=this._renderTarget||this._getFrameBufferTarget();let i=null;if(null!==s&&(this._textures.updateRenderTarget(s),i=this._textures.get(s)),this.backend.clear(e,t,r,i),null!==s&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(s.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(s.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,r=!0){!1===this._initialized&&await this.init(),this.clear(e,t,r)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Ae:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,r=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=r}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,r=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const s=this.backend,i=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");s.beginCompute(e);for(const t of a){if(!1===i.has(t)){const e=()=>{t.removeEventListener("dispose",e),i.delete(t),n.delete(t),o.delete(t)};t.addEventListener("dispose",e);const r=t.onInitFunction;null!==r&&r.call(t,{renderer:this})}o.updateForCompute(t),n.updateForCompute(t);const r=n.getForCompute(t),a=i.getForCompute(t,r);s.compute(e,t,r,a)}s.finishCompute(e),t.renderId=r}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){!1===this._initialized&&await this.init(),this._textures.updateTexture(e)}initTexture(e){if(!1===this._initialized)return console.warn("THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead."),!1;this._textures.updateTexture(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=jT.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=jT.copy(t).floor()}else t=jT.set(0,0,e.image.width,e.image.height);let r,s=this._currentRenderContext;null!==s?r=s.renderTarget:(r=this._renderTarget||this._getFrameBufferTarget(),null!==r&&(this._textures.updateRenderTarget(r),s=this._textures.get(r))),this._textures.updateTexture(e,{renderTarget:r}),this.backend.copyFramebufferToTexture(e,s,t)}copyTextureToTexture(e,t,r=null,s=null,i=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,r,s,i)}readRenderTargetPixelsAsync(e,t,r,s,i,n=0,o=0){return this.backend.copyTextureToBuffer(e.textures[n],t,r,s,i,o)}_projectObject(e,t,r,s,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)r=e.renderOrder,e.isClippingGroup&&e.enabled&&(i=i.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)s.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||WT.intersectsSprite(e)){!0===this.sortObjects&&jT.setFromMatrixPosition(e.matrixWorld).applyMatrix4(HT);const{geometry:t,material:n}=e;n.visible&&s.push(e,t,n,r,jT.z,null,i)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||WT.intersectsObject(e))){const{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),jT.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(HT)),Array.isArray(n)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,r,s,i,"backSide");for(const{material:e}of t)e.side=Ge;this._renderObjects(e,r,s,i);for(const{material:e}of t)e.side=le}else this._renderObjects(e,r,s,i)}_renderObjects(e,t,r,s,i=null){for(let n=0,o=e.length;n0?s:"";t=`${e.name} {\n\t${r} ${i.name}[${n}];\n};\n`}else{t=`${this.getVectorType(i.type)} ${this.getPropertyName(i,e)};`,n=!0}const o=i.node.precision;if(null!==o&&(t=u_[o]+" "+t),n){t="\t"+t;const e=i.groupNode.name;(s[e]||(s[e]=[])).push(t)}else t="uniform "+t,r.push(t)}let i="";for(const t in s){const r=s[t];i+=this._getGLSLUniformStruct(e+"_"+t,r.join("\n"))+"\n"}return i+=r.join("\n"),i}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let r=e;e.isInterleavedBufferAttribute&&(r=e.data);const s=r.array;!1==(s instanceof Uint32Array||s instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let r=0;for(const s of e)t+=`layout( location = ${r++} ) in ${s.type} ${s.name};\n`}return t}getStructMembers(e){const t=[],r=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,r=this.shaderStage){const s=this.extensions[r]||(this.extensions[r]=new Map);!1===s.has(e)&&s.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const r=this.extensions[e];if(void 0!==r)for(const{name:e,behavior:s}of r.values())t.push(`#extension ${e} : ${s}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=l_[e];if(void 0===t){let r;switch(t=!1,e){case"float32Filterable":r="OES_texture_float_linear";break;case"clipDistance":r="WEBGL_clip_cull_distance"}if(void 0!==r){const e=this.renderer.backend.extensions;e.has(r)&&(e.get(r),t=!0)}l_[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let r=0;r0&&(r+="\n"),r+=`\t// flow -> ${n}\n\t`),r+=`${s.code}\n\t`,e===i&&"compute"!==t&&(r+="// result\n\t","vertex"===t?(r+="gl_Position = ",r+=`${s.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(r+="fragColor = ",r+=`${s.result};`)))}const n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=r}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,r,s=null){const i=super.getUniformFromNode(e,t,r,s),n=this.getDataFromNode(e,r,this.globalCache);let o=n.uniformGPU;if(void 0===o){const s=e.groupNode,a=s.name,u=this.getBindGroupArray(a,r);if("texture"===t)o=new i_(i.name,i.node,s),u.push(o);else if("cubeTexture"===t)o=new n_(i.name,i.node,s),u.push(o);else if("texture3D"===t)o=new o_(i.name,i.node,s),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,i.name=`buffer${e.id}`;const t=new ZT(e,s);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[r]||(this.uniformGroups[r]={});let n=e[a];void 0===n&&(n=new t_(r+"_"+a,s),e[a]=n,u.push(n)),o=this.getNodeUniform(i,t),n.addUniform(o)}n.uniformGPU=o}return i}}let h_=null,p_=null,g_=null;class m_{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:r}=e;return r.isInstancedBufferGeometry?r.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return h_=h_||new t,this.renderer.getDrawingBufferSize(h_)}getScissor(){return p_=p_||new s,this.renderer.getScissor(p_)}setScissorTest(){}getClearColor(){const e=this.renderer;return g_=g_||new om,e.getClearColor(g_),g_.getRGB(g_,this.renderer.currentColorSpace),g_}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Ze(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${De} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let f_=0;class y_{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class b_{constructor(e){this.backend=e}createAttribute(e,t){const r=this.backend,{gl:s}=r,i=e.array,n=e.usage||s.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=r.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(s,t,i,n),a.bufferGPU=l,a.bufferType=t,a.version=o.version),i instanceof Float32Array)u=s.FLOAT;else if(i instanceof Uint16Array)u=e.isFloat16BufferAttribute?s.HALF_FLOAT:s.UNSIGNED_SHORT;else if(i instanceof Int16Array)u=s.SHORT;else if(i instanceof Uint32Array)u=s.UNSIGNED_INT;else if(i instanceof Int32Array)u=s.INT;else if(i instanceof Int8Array)u=s.BYTE;else if(i instanceof Uint8Array)u=s.UNSIGNED_BYTE;else{if(!(i instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+i);u=s.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:i.byteLength,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===s.INT||u===s.UNSIGNED_INT||e.gpuType===y,id:f_++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(s,t,i,n);d=new y_(d,e)}r.set(e,d)}updateAttribute(e){const t=this.backend,{gl:r}=t,s=e.array,i=e.isInterleavedBufferAttribute?e.data:e,n=t.get(i),o=n.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(r.bindBuffer(o,n.bufferGPU),0===a.length)r.bufferSubData(o,0,s);else{for(let e=0,t=a.length;e1?this.enable(s.SAMPLE_ALPHA_TO_COVERAGE):this.disable(s.SAMPLE_ALPHA_TO_COVERAGE),r>0&&this.currentClippingPlanes!==r){const e=12288;for(let t=0;t<8;t++)t{!function i(){const n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED)return e.deleteSync(t),void s();n!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),r()):requestAnimationFrame(i)}()}))}}let S_,A_,R_,C_=!1;class E_{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===C_&&(this._init(this.gl),C_=!0)}_init(e){S_={[dr]:e.REPEAT,[cr]:e.CLAMP_TO_EDGE,[hr]:e.MIRRORED_REPEAT},A_={[pr]:e.NEAREST,[gr]:e.NEAREST_MIPMAP_NEAREST,[Ie]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Pe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},R_={[mr]:e.NEVER,[fr]:e.ALWAYS,[Re]:e.LESS,[yr]:e.LEQUAL,[br]:e.EQUAL,[xr]:e.GEQUAL,[Tr]:e.GREATER,[_r]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===pr||e===gr||e===Ie?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let r;return r=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,r}getInternalFormat(e,t,r,s,i=!1){const{gl:n,extensions:o}=this;if(null!==e){if(void 0!==n[e])return n[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===n.RED&&(r===n.FLOAT&&(a=n.R32F),r===n.HALF_FLOAT&&(a=n.R16F),r===n.UNSIGNED_BYTE&&(a=n.R8),r===n.UNSIGNED_SHORT&&(a=n.R16),r===n.UNSIGNED_INT&&(a=n.R32UI),r===n.BYTE&&(a=n.R8I),r===n.SHORT&&(a=n.R16I),r===n.INT&&(a=n.R32I)),t===n.RED_INTEGER&&(r===n.UNSIGNED_BYTE&&(a=n.R8UI),r===n.UNSIGNED_SHORT&&(a=n.R16UI),r===n.UNSIGNED_INT&&(a=n.R32UI),r===n.BYTE&&(a=n.R8I),r===n.SHORT&&(a=n.R16I),r===n.INT&&(a=n.R32I)),t===n.RG&&(r===n.FLOAT&&(a=n.RG32F),r===n.HALF_FLOAT&&(a=n.RG16F),r===n.UNSIGNED_BYTE&&(a=n.RG8),r===n.UNSIGNED_SHORT&&(a=n.RG16),r===n.UNSIGNED_INT&&(a=n.RG32UI),r===n.BYTE&&(a=n.RG8I),r===n.SHORT&&(a=n.RG16I),r===n.INT&&(a=n.RG32I)),t===n.RG_INTEGER&&(r===n.UNSIGNED_BYTE&&(a=n.RG8UI),r===n.UNSIGNED_SHORT&&(a=n.RG16UI),r===n.UNSIGNED_INT&&(a=n.RG32UI),r===n.BYTE&&(a=n.RG8I),r===n.SHORT&&(a=n.RG16I),r===n.INT&&(a=n.RG32I)),t===n.RGB&&(r===n.FLOAT&&(a=n.RGB32F),r===n.HALF_FLOAT&&(a=n.RGB16F),r===n.UNSIGNED_BYTE&&(a=n.RGB8),r===n.UNSIGNED_SHORT&&(a=n.RGB16),r===n.UNSIGNED_INT&&(a=n.RGB32UI),r===n.BYTE&&(a=n.RGB8I),r===n.SHORT&&(a=n.RGB16I),r===n.INT&&(a=n.RGB32I),r===n.UNSIGNED_BYTE&&(a=s===Ve&&!1===i?n.SRGB8:n.RGB8),r===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),r===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),r===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),r===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),t===n.RGB_INTEGER&&(r===n.UNSIGNED_BYTE&&(a=n.RGB8UI),r===n.UNSIGNED_SHORT&&(a=n.RGB16UI),r===n.UNSIGNED_INT&&(a=n.RGB32UI),r===n.BYTE&&(a=n.RGB8I),r===n.SHORT&&(a=n.RGB16I),r===n.INT&&(a=n.RGB32I)),t===n.RGBA&&(r===n.FLOAT&&(a=n.RGBA32F),r===n.HALF_FLOAT&&(a=n.RGBA16F),r===n.UNSIGNED_BYTE&&(a=n.RGBA8),r===n.UNSIGNED_SHORT&&(a=n.RGBA16),r===n.UNSIGNED_INT&&(a=n.RGBA32UI),r===n.BYTE&&(a=n.RGBA8I),r===n.SHORT&&(a=n.RGBA16I),r===n.INT&&(a=n.RGBA32I),r===n.UNSIGNED_BYTE&&(a=s===Ve&&!1===i?n.SRGB8_ALPHA8:n.RGBA8),r===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),r===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),t===n.RGBA_INTEGER&&(r===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),r===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),r===n.UNSIGNED_INT&&(a=n.RGBA32UI),r===n.BYTE&&(a=n.RGBA8I),r===n.SHORT&&(a=n.RGBA16I),r===n.INT&&(a=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(r===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),r===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&r===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:r,extensions:s,backend:i}=this;r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,t.flipY),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),r.pixelStorei(r.UNPACK_ALIGNMENT,t.unpackAlignment),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,r.NONE),r.texParameteri(e,r.TEXTURE_WRAP_S,S_[t.wrapS]),r.texParameteri(e,r.TEXTURE_WRAP_T,S_[t.wrapT]),e!==r.TEXTURE_3D&&e!==r.TEXTURE_2D_ARRAY||r.texParameteri(e,r.TEXTURE_WRAP_R,S_[t.wrapR]),r.texParameteri(e,r.TEXTURE_MAG_FILTER,A_[t.magFilter]);const n=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&n?M:t.minFilter;if(r.texParameteri(e,r.TEXTURE_MIN_FILTER,A_[o]),t.compareFunction&&(r.texParameteri(e,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(e,r.TEXTURE_COMPARE_FUNC,R_[t.compareFunction])),!0===s.has("EXT_texture_filter_anisotropic")){if(t.magFilter===pr)return;if(t.minFilter!==Ie&&t.minFilter!==M)return;if(t.type===E&&!1===s.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const n=s.get("EXT_texture_filter_anisotropic");r.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,i.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:r,defaultTextures:s}=this,i=this.getGLTextureType(e);let n=s[i];void 0===n&&(n=t.createTexture(),r.state.bindTexture(i,n),t.texParameteri(i,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(i,t.TEXTURE_MAG_FILTER,t.NEAREST),s[i]=n),r.set(e,{textureGPU:n,glTextureType:i,isDefault:!0})}createTexture(e,t){const{gl:r,backend:s}=this,{levels:i,width:n,height:o,depth:a}=t,u=s.utils.convert(e.format,e.colorSpace),l=s.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=r.createTexture(),h=this.getGLTextureType(e);s.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?r.texStorage3D(r.TEXTURE_2D_ARRAY,i,d,n,o,a):e.isData3DTexture?r.texStorage3D(r.TEXTURE_3D,i,d,n,o,a):e.isVideoTexture||r.texStorage2D(h,i,d,n,o),s.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:r,backend:s}=this,{textureGPU:i,glTextureType:n,glFormat:o,glType:a}=s.get(t),{width:u,height:l}=t.source.data;r.bindBuffer(r.PIXEL_UNPACK_BUFFER,e),s.state.bindTexture(n,i),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(n,0,0,0,u,l,o,a,0),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),s.state.unbindTexture()}updateTexture(e,t){const{gl:r}=this,{width:s,height:i}=t,{textureGPU:n,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===n)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,e),e.isCompressedTexture){const s=e.mipmaps,i=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const r=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=s.DEPTH_BUFFER_BIT,h=s.DEPTH_ATTACHMENT,t.stencil&&(d|=s.STENCIL_BUFFER_BIT)):(d=s.COLOR_BUFFER_BIT,h=s.COLOR_ATTACHMENT0),r){const e=this.backend.get(t.renderTarget),r=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;i.bindFramebuffer(s.DRAW_FRAMEBUFFER,r),i.bindFramebuffer(s.READ_FRAMEBUFFER,h);const p=c-a-l;s.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,s.NEAREST),i.bindFramebuffer(s.READ_FRAMEBUFFER,r),i.bindTexture(s.TEXTURE_2D,n),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,o,p,u,l),i.unbindTexture()}else{const e=s.createFramebuffer();i.bindFramebuffer(s.DRAW_FRAMEBUFFER,e),s.framebufferTexture2D(s.DRAW_FRAMEBUFFER,h,s.TEXTURE_2D,n,0),s.blitFramebuffer(0,0,u,l,0,0,u,l,d,s.NEAREST),s.deleteFramebuffer(e)}}else i.bindTexture(s.TEXTURE_2D,n),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,o,c-l-a,u,l),i.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:r}=this,s=t.renderTarget,{samples:i,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:u,height:l}=s;if(r.bindRenderbuffer(r.RENDERBUFFER,e),o&&!a){let t=r.DEPTH_COMPONENT24;i>0?(n&&n.isDepthTexture&&n.type===r.FLOAT&&(t=r.DEPTH_COMPONENT32F),r.renderbufferStorageMultisample(r.RENDERBUFFER,i,t,u,l)):r.renderbufferStorage(r.RENDERBUFFER,t,u,l),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,e)}else o&&a&&(i>0?r.renderbufferStorageMultisample(r.RENDERBUFFER,i,r.DEPTH24_STENCIL8,u,l):r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_STENCIL,u,l),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,r,s,i,n){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=s*i*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,r,s,i,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:r}=this;let s=0;return e===r.UNSIGNED_BYTE&&(s=1),e!==r.UNSIGNED_SHORT_4_4_4_4&&e!==r.UNSIGNED_SHORT_5_5_5_1&&e!==r.UNSIGNED_SHORT_5_6_5&&e!==r.UNSIGNED_SHORT&&e!==r.HALF_FLOAT||(s=2),e!==r.UNSIGNED_INT&&e!==r.FLOAT||(s=4),t===r.RGBA?4*s:t===r.RGB?3*s:t===r.ALPHA?s:void 0}}class w_{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class M_{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const r=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const B_={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class U_{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:r,mode:s,object:i,type:n,info:o,index:a}=this;0!==a?r.drawElements(s,t,n,e):r.drawArrays(s,e,t),o.update(i,t,s,1)}renderInstances(e,t,r){const{gl:s,mode:i,type:n,index:o,object:a,info:u}=this;0!==r&&(0!==o?s.drawElementsInstanced(i,t,n,e,r):s.drawArraysInstanced(i,e,t,r),u.update(a,t,i,r))}renderMultiDraw(e,t,r){const{extensions:s,mode:i,object:n,info:o}=this;if(0===r)return;const a=s.get("WEBGL_multi_draw");if(null===a)for(let s=0;s0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const r=this.get(e);r.gpuQueries||(r.gpuQueries=[]);for(let e=0;e0&&(r.currentOcclusionQueries=r.occlusionQueries,r.currentOcclusionQueryObjects=r.occlusionQueryObjects,r.lastOcclusionObject=null,r.occlusionQueries=new Array(s),r.occlusionQueryObjects=new Array(s),r.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:r}=this,s=this.get(e),i=s.previousContext,n=e.occlusionQueryCount;n>0&&(n>s.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const i=s.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT,o=s.msaaFrameBuffer,a=e.textures;r.bindFramebuffer(t.READ_FRAMEBUFFER,o),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,i);for(let r=0;r{let o=0;for(let t=0;t0&&e.add(s[t]),r[t]=null,i.deleteQuery(n),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,r,s,i,n){return this.textureUtils.copyTextureToBuffer(e,t,r,s,i,n)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new c_(e,t)}createProgram(e){const t=this.gl,{stage:r,code:s}=e,i="fragment"===r?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(i,s),t.compileShader(i),this.set(e,{shaderGPU:i})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const r=this.gl,s=e.pipeline,{fragmentProgram:i,vertexProgram:n}=s,o=r.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU;if(r.attachShader(o,a),r.attachShader(o,u),r.linkProgram(o),this.set(s,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const i=new Promise((t=>{const i=this.parallel,n=()=>{r.getProgramParameter(o,i.COMPLETION_STATUS_KHR)?(this._completeCompile(e,s),t()):requestAnimationFrame(n)};n()}));t.push(i)}else this._completeCompile(e,s)}_handleSource(e,t){const r=e.split("\n"),s=[],i=Math.max(t-6,0),n=Math.min(t+6,r.length);for(let e=i;e":" "} ${i}: ${r[e]}`)}return s.join("\n")}_getShaderErrors(e,t,r){const s=e.getShaderParameter(t,e.COMPILE_STATUS),i=e.getShaderInfoLog(t).trim();if(s&&""===i)return"";const n=/ERROR: 0:(\d+)/.exec(i);if(n){const s=parseInt(n[1]);return r.toUpperCase()+"\n\n"+i+"\n\n"+this._handleSource(e.getShaderSource(t),s)}return i}_logProgramError(e,t,r){if(this.renderer.debug.checkShaderErrors){const s=this.gl,i=s.getProgramInfoLog(e).trim();if(!1===s.getProgramParameter(e,s.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(s,e,r,t);else{const n=this._getShaderErrors(s,r,"vertex"),o=this._getShaderErrors(s,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(e,s.VALIDATE_STATUS)+"\n\nProgram Info Log: "+i+"\n"+n+"\n"+o)}else""!==i&&console.warn("THREE.WebGLProgram: Program Info Log:",i)}}_completeCompile(e,t){const{state:r,gl:s}=this,i=this.get(t),{programGPU:n,fragmentShader:o,vertexShader:a}=i;!1===s.getProgramParameter(n,s.LINK_STATUS)&&this._logProgramError(n,o,a),r.useProgram(n);const u=e.getBindings();this._setupBindings(u,n),this.set(t,{programGPU:n})}createComputePipeline(e,t){const{state:r,gl:s}=this,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:n}=e,o=s.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU,l=n.transforms,d=[],c=[];for(let e=0;eB_[t]===e)),r=this.extensions;for(let e=0;e0){if(void 0===d){const s=[];d=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,d);const i=[],l=e.textures;for(let r=0;r,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:V_,stripIndexFormat:tv},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:V_,stripIndexFormat:tv},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,r=0){const s=t.format,{width:i,height:n}=t.size,o=this.getTransferPipeline(s),a=this.getFlipYPipeline(s),u=this.device.createTexture({size:{width:i,height:n,depthOrArrayLayers:1},format:s,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Kv,baseArrayLayer:r}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:Kv,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,r)=>{const s=e.getBindGroupLayout(0),i=this.device.createBindGroup({layout:s,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),n=c.beginRenderPass({colorAttachments:[{view:r,loadOp:X_,storeOp:q_,clearValue:[0,0,0,0]}]});n.setPipeline(e),n.setBindGroup(0,i),n.draw(4,1,0,0),n.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,r=0){const s=this.get(e);void 0===s.useCount&&(s.useCount=0,s.layers=[]);const i=s.layers[r]||this._mipmapCreateBundles(e,t,r),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,i),this.device.queue.submit([n.finish()]),0!==s.useCount&&(s.layers[r]=i),s.useCount++}_mipmapCreateBundles(e,t,r){const s=this.getTransferPipeline(t.format),i=s.getBindGroupLayout(0);let n=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Kv,baseArrayLayer:r});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,s.msaaTexture=r.device.createTexture(e)}s.initialized=!0,s.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,r=t.get(e);void 0!==r.texture&&r.texture.destroy(),void 0!==r.msaaTexture&&r.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const r=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,pN=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,gN={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class mN extends RT{constructor(e){const{type:t,inputs:r,name:s,inputsCode:i,blockCode:n,outputType:o}=(e=>{const t=(e=e.trim()).match(hN);if(null!==t&&4===t.length){const r=t[2],s=[];let i=null;for(;null!==(i=pN.exec(r));)s.push({name:i[1],type:i[2]});const n=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class fN extends AT{parseFunction(e){return new mN(e)}}const yN="undefined"!=typeof self?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},bN={[Ss.READ_ONLY]:"read",[Ss.WRITE_ONLY]:"write",[Ss.READ_WRITE]:"read_write"},xN={[dr]:"repeat",[cr]:"clamp",[hr]:"mirror"},TN={vertex:yN?yN.VERTEX:1,fragment:yN?yN.FRAGMENT:2,compute:yN?yN.COMPUTE:4},_N={instance:!0,swizzleAssign:!1,storageBuffer:!0},vN={"^^":"tsl_xor"},NN={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},SN={},AN={tsl_xor:new ny("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new ny("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new ny("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new ny("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new ny("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new ny("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new ny("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new ny("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new ny("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new ny("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new ny("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new ny("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),biquadraticTexture:new ny("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},RN={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};"undefined"!=typeof navigator&&/Windows/g.test(navigator.userAgent)&&(AN.pow_float=new ny("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),AN.pow_vec2=new ny("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[AN.pow_float]),AN.pow_vec3=new ny("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[AN.pow_float]),AN.pow_vec4=new ny("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[AN.pow_float]),RN.pow_float="tsl_pow_float",RN.pow_vec2="tsl_pow_vec2",RN.pow_vec3="tsl_pow_vec3",RN.pow_vec4="tsl_pow_vec4");let CN="";!0!==("undefined"!=typeof navigator&&/Firefox|Deno/g.test(navigator.userAgent))&&(CN+="diagnostic( off, derivative_uniformity );\n");class EN extends hT{constructor(e,t){super(e,t,new fN),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,r,s,i=this.shaderStage){return"fragment"===i?s?`textureSample( ${t}, ${t}_sampler, ${r}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r):this.generateTextureLod(e,t,r,s,"0")}_generateVideoSample(e,t,r=this.shaderStage){if("fragment"===r)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${r} shader.`)}_generateTextureSampleLevel(e,t,r,s,i,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,s):this.generateTextureLod(e,t,r,i,s)}generateWrapFunction(e){const t=`tsl_coord_${xN[e.wrapS]}S_${xN[e.wrapT]}T`;let r=SN[t];if(void 0===r){const s=[];let i=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const n=(e,t)=>{e===dr?(s.push(AN.repeatWrapping_float),i+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===cr?(s.push(AN.clampWrapping_float),i+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===hr?(s.push(AN.mirrorWrapping_float),i+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(i+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};n(e.wrapS,"x"),i+=",\n",n(e.wrapT,"y"),i+="\n\t);\n\n}\n",SN[t]=r=new ny(i,s)}return r.build(this),t}generateTextureDimension(e,t,r){const s=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===s.dimensionsSnippet&&(s.dimensionsSnippet={});let i=s.dimensionsSnippet[r];if(void 0===s.dimensionsSnippet[r]){let n;n=!0===e.isMultisampleRenderTargetTexture?t:`${t}, u32( ${r} )`,i=new Aa(new ou(`textureDimensions( ${n} )`,"uvec2")),s.dimensionsSnippet[r]=i}return i.build(this)}generateFilteredTexture(e,t,r,s="0u"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${r} ), ${this.generateTextureDimension(e,t,s)}, u32( ${s} ) )`}generateTextureLod(e,t,r,s,i="0u"){const n=`vec2u( ${this.generateWrapFunction(e)}( ${r} ) * vec2f( ${this.generateTextureDimension(e,t,i)} ) )`;return this.generateTextureLoad(e,t,n,s,i)}generateTextureLoad(e,t,r,s,i="0u"){return!0===e.isVideoTexture||!0===e.isStorageTexture?`textureLoad( ${t}, ${r} )`:s?`textureLoad( ${t}, ${r}, ${s}, u32( ${i} ) )`:`textureLoad( ${t}, ${r}, u32( ${i} ) )`}generateTextureStore(e,t,r,s){return`textureStore( ${t}, ${r}, ${s} )`}isSampleCompare(e){return!0===e.isDepthTexture&&null!==e.compareFunction}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!1===this.isSampleCompare(e)&&e.minFilter===pr&&e.magFilter===pr||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,r,s,i=this.shaderStage){let n=null;return n=!0===e.isVideoTexture?this._generateVideoSample(t,r,i):this.isUnfilterable(e)?this.generateTextureLod(e,t,r,s,"0",i):this._generateTextureSample(e,t,r,s,i),n}generateTextureGrad(e,t,r,s,i,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s[0]}, ${s[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,r,s,i,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(e,t,r,s,i,n=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,r,n):this._generateTextureSampleLevel(e,t,r,s,i,n),o}generateTextureBias(e,t,r,s,i,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,r=e.type;return"texture"===r||"cubeTexture"===r||"storageTexture"===r||"texture3D"===r?t:"buffer"===r||"storageBuffer"===r||"indirectStorageBuffer"===r?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=vN[e];return void 0!==t?(this._include(t),t):null}getNodeAccess(e,t){return"compute"!==t?Ss.READ_ONLY:e.access}getStorageAccess(e,t){return bN[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,r,s=null){const i=super.getUniformFromNode(e,t,r,s),n=this.getDataFromNode(e,r,this.globalCache);if(void 0===n.uniformGPU){let s;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,r);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let n=null;const a=this.getNodeAccess(e,r);if("texture"===t||"storageTexture"===t?n=new i_(i.name,i.node,o,a):"cubeTexture"===t?n=new n_(i.name,i.node,o,a):"texture3D"===t&&(n=new o_(i.name,i.node,o,a)),n.store=!0===e.isStorageTextureNode,n.setVisibility(TN[r]),"fragment"===r&&!1===this.isUnfilterable(e.value)&&!1===n.store){const e=new sN(`${i.name}_sampler`,i.node,o);e.setVisibility(TN[r]),u.push(e,n),s=[e,n]}else u.push(n),s=[n]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const i=new("buffer"===t?ZT:oN)(e,o);i.setVisibility(TN[r]),u.push(i),s=i}else{const e=this.uniformGroups[r]||(this.uniformGroups[r]={});let n=e[a];void 0===n&&(n=new t_(a,o),n.setVisibility(TN[r]),e[a]=n,u.push(n)),s=this.getNodeUniform(i,t),n.addUniform(s)}n.uniformGPU=s}return i}getBuiltin(e,t,r,s=this.shaderStage){const i=this.builtins[s]||(this.builtins[s]=new Map);return!1===i.has(e)&&i.set(e,{name:e,property:t,type:r}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,r=this.flowShaderNode(e),s=[];for(const e of t.inputs)s.push(e.name+" : "+this.getType(e.type));let i=`fn ${t.name}( ${s.join(", ")} ) -> ${this.getType(t.type)} {\n${r.vars}\n${r.code}\n`;return r.result&&(i+=`\treturn ${r.result};\n`),i+="\n}\n",i}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],r=this.directives[e];if(void 0!==r)for(const e of r)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],r=this.builtins[e];if(void 0!==r)for(const{name:e,property:s,type:i}of r.values())t.push(`@builtin( ${e} ) ${s} : ${i}`);return t.join(",\n\t")}getScopedArray(e,t,r,s){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:r,bufferCount:s}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:r,bufferType:s,bufferCount:i}of this.scopedArrays.values()){const n=this.getType(s);t.push(`var<${r}> ${e}: array< ${n}, ${i} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const r=this.getAttributesArray();for(let e=0,s=r.length;e`)}const s=this.getBuiltins("output");return s&&t.push("\t"+s),t.join(",\n")}getStructs(e){const t=[],r=this.structs[e];for(let e=0,s=r.length;e output : ${i};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],r=this.vars[e];if(void 0!==r)for(const e of r)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const r=this.varyings,s=this.vars[e];for(let i=0;i";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)s="texture_2d_array";else if(!0===t.isDepthTexture)s=`texture_depth${n}_2d`;else if(!0===t.isVideoTexture)s="texture_external";else if(!0===t.isData3DTexture)s="texture_3d";else if(!0===i.node.isStorageTextureNode){s=`texture_storage_2d<${cN(t)}, ${this.getStorageAccess(i.node,e)}>`}else{s=`texture${n}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}r.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${i.name} : ${s};`)}else if("buffer"===i.type||"storageBuffer"===i.type||"indirectStorageBuffer"===i.type){const t=i.node,r=this.getType(t.bufferType),n=t.bufferCount,a=n>0&&"buffer"===i.type?", "+n:"",u=t.isAtomic?`atomic<${r}>`:`${r}`,l=`\t${i.name} : array< ${u}${a} >\n`,d=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t,e)}`:"uniform";s.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,l,d,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(i.type)),t=i.groupNode.name;(n[t]||(n[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${i.name} : ${e}`)}}for(const e in n){const t=n[e];i.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=r.join("\n");return o+=s.join("\n"),o+=i.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const r=e[t];r.uniforms=this.getUniforms(t),r.attributes=this.getAttributes(t),r.varyings=this.getVaryings(t),r.structs=this.getStructs(t),r.vars=this.getVars(t),r.codes=this.getCodes(t),r.directives=this.getDirectives(t),r.scopedArrays=this.getScopedArrays(t);let s="// code\n\n";s+=this.flowCode[t];const i=this.flowNodes[t],n=i[i.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of i){const i=this.getFlowData(e),u=e.name;if(u&&(s.length>0&&(s+="\n"),s+=`\t// flow -> ${u}\n\t`),s+=`${i.code}\n\t`,e===n&&"compute"!==t)if(s+="// result\n\n\t","vertex"===t)s+=`varyings.Vertex = ${i.result};`;else if("fragment"===t)if(a)r.returnType=o.nodeType,s+=`return ${i.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),r.returnType="OutputStruct",r.structs+=this._getWGSLStruct("OutputStruct",e),r.structs+="\nvar output : OutputStruct;\n\n",s+=`output.color = ${i.result};\n\n\treturn output;`}}r.flow=s}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let r;return null!==t&&(r=this._getWGSLMethod(e+"_"+t)),void 0===r&&(r=this._getWGSLMethod(e)),r||e}getType(e){return NN[e]||e}isAvailable(e){let t=_N[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),_N[e]=t),t}_getWGSLMethod(e){return void 0!==AN[e]&&this._include(e),RN[e]}_include(e){const t=AN[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${CN}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,r,s=0,i=0){const n=e+"Struct";return`${this._getWGSLStruct(n,t)}\n@binding( ${s} ) @group( ${i} )\nvar<${r}> ${e} : ${n};`}}class wN{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=rv.Depth24PlusStencil8:e.depth&&(t=rv.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?P_:e.isLineSegments||e.isMesh&&!0===t.wireframe?I_:e.isLine?L_:e.isMesh?D_:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?rv.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const MN=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),BN=new Map([[Le,["float16"]]]),UN=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class FN{constructor(e){this.backend=e}createAttribute(e,t){const r=this._getBufferAttribute(e),s=this.backend,i=s.get(r);let n=i.buffer;if(void 0===n){const o=s.device;let a=r.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[r]===s&&(a=o.groups[r])),void 0===a&&(a=this.createBindGroup(e,u),r>0&&(o.groups[r]=a,o.versions[r]=s)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,r=t.device,s=e.buffer,i=t.get(e).buffer;r.queue.writeBuffer(i,0,s,0)}createBindGroup(e,t){const r=this.backend,s=r.device;let i=0;const n=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=r.get(t);if(void 0===e.buffer){const r=t.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=s.createBuffer({label:"bindingBuffer_"+t.name,size:r,usage:i});e.buffer=n}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=r.get(t);if(void 0===e.buffer){const s=t.attribute;e.buffer=r.get(s).buffer}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=r.get(t.texture);n.push({binding:i,resource:e.sampler})}else if(t.isSampledTexture){const e=r.get(t.texture);let o;if(void 0!==e.externalTexture)o=s.importExternalTexture({source:e.externalTexture});else{const r=t.store?1:e.texture.mipLevelCount,s=`view-${e.texture.width}-${e.texture.height}-${r}`;if(o=e[s],void 0===o){const i=Zv;let n;n=t.isSampledCubeTexture?Yv:t.isSampledTexture3D?Qv:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?Xv:Kv,o=e[s]=e.texture.createView({aspect:i,dimension:n,mipLevelCount:r})}}n.push({binding:i,resource:o})}i++}return s.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}}class IN{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:r,material:s,geometry:i,pipeline:n}=e,{vertexProgram:o,fragmentProgram:a}=n,u=this.backend,l=u.device,d=u.utils,c=u.get(n),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===s.transparent&&s.blending!==D&&(g=this._getBlending(s));let m={};!0===s.stencilWrite&&(m={compare:this._getStencilCompare(s),failOp:this._getStencilOperation(s.stencilFail),depthFailOp:this._getStencilOperation(s.stencilZFail),passOp:this._getStencilOperation(s.stencilZPass)});const f=this._getColorWriteMask(s),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=v,A.depthWriteEnabled=s.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=s.stencilFuncMask,A.stencilWriteMask=s.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:r,device:s}=t,i=r.getCurrentDepthStencilFormat(e),n={label:"renderBundleEncoder",colorFormats:[r.getCurrentColorFormat(e)],depthStencilFormat:i,sampleCount:this._getSampleCount(e)};return s.createRenderBundleEncoder(n)}createComputePipeline(e,t){const r=this.backend,s=r.device,i=r.get(e.computeProgram).module,n=r.get(e),o=[];for(const e of t){const t=r.get(e);o.push(t.layout)}n.pipeline=s.createComputePipeline({compute:i,layout:s.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,r;const s=e.blending,i=e.blendSrc,n=e.blendDst,o=e.blendEquation;if(s===ft){const s=null!==e.blendSrcAlpha?e.blendSrcAlpha:i,a=null!==e.blendDstAlpha?e.blendDstAlpha:n,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},r={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const i=(e,s,i,n)=>{t={srcFactor:e,dstFactor:s,operation:_v},r={srcFactor:i,dstFactor:n,operation:_v}};if(e.premultipliedAlpha)switch(s){case F:i(lv,pv,lv,pv);break;case xt:i(lv,lv,lv,lv);break;case bt:i(uv,cv,uv,lv);break;case yt:i(uv,dv,uv,hv)}else switch(s){case F:i(hv,pv,lv,pv);break;case xt:i(hv,lv,hv,lv);break;case bt:i(uv,cv,uv,lv);break;case yt:i(uv,dv,uv,dv)}}if(void 0!==t&&void 0!==r)return{color:t,alpha:r};console.error("THREE.WebGPURenderer: Invalid blending: ",s)}_getBlendFactor(e){let t;switch(e){case rt:t=uv;break;case st:t=lv;break;case it:t=dv;break;case lt:t=cv;break;case nt:t=hv;break;case dt:t=pv;break;case at:t=gv;break;case ct:t=mv;break;case ut:t=fv;break;case ht:t=yv;break;case ot:t=bv;break;case 211:t=xv;break;case 212:t=Tv;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const r=e.stencilFunc;switch(r){case Mr:t=O_;break;case wr:t=j_;break;case Er:t=G_;break;case Cr:t=z_;break;case Rr:t=k_;break;case Ar:t=H_;break;case Sr:t=$_;break;case Nr:t=W_;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",r)}return t}_getStencilOperation(e){let t;switch(e){case Vr:t=Ev;break;case Dr:t=wv;break;case Lr:t=Mv;break;case Ir:t=Bv;break;case Pr:t=Uv;break;case Fr:t=Fv;break;case Ur:t=Pv;break;case Br:t=Iv;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Je:t=_v;break;case et:t=vv;break;case tt:t=Nv;break;case Gr:t=Sv;break;case Or:t=Av;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,r){const s={},i=this.backend.utils;switch(s.topology=i.getPrimitiveTopology(e,r),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(s.stripIndexFormat=t.index.array instanceof Uint16Array?ev:tv),r.side){case Ge:s.frontFace=Y_,s.cullMode=J_;break;case x:s.frontFace=Y_,s.cullMode=Z_;break;case le:s.frontFace=Y_,s.cullMode=Q_;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",r.side)}return s}_getColorWriteMask(e){return!0===e.colorWrite?Cv:Rv}_getDepthCompare(e){let t;if(!1===e.depthTest)t=j_;else{const r=e.depthFunc;switch(r){case Ct:t=O_;break;case Rt:t=j_;break;case At:t=G_;break;case St:t=z_;break;case Nt:t=k_;break;case vt:t=H_;break;case _t:t=$_;break;case Tt:t=W_;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",r)}}return t}}class LN extends m_{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new wN(this),this.attributeUtils=new FN(this),this.bindingUtils=new PN(this),this.pipelineUtils=new IN(this),this.textureUtils=new dN(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let r;if(void 0===t.device){const e={powerPreference:t.powerPreference},s="undefined"!=typeof navigator?await navigator.gpu.requestAdapter(e):null;if(null===s)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const i=Object.values(tN),n=[];for(const e of i)s.features.has(e)&&n.push(e);const o={requiredFeatures:n,requiredLimits:t.requiredLimits};r=await s.requestDevice(o)}else r=t.device;r.lost.then((t=>{const r={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(r)}));const s=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=r,this.context=s;const i=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(tN.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:i}),this.updateSize()}get coordinateSystem(){return v}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const r=e.colorAttachments[0];this.renderer.samples>0?r.view=this.colorBuffer.createView():r.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,r=this.get(t);let s=r.descriptors;if(void 0===s||r.width!==t.width||r.height!==t.height||r.activeMipmapLevel!==t.activeMipmapLevel||r.samples!==t.samples){s={},r.descriptors=s;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const i=e.getCacheKey();let n=s[i];if(void 0===n){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,i=r.createQuerySet({type:"occlusion",count:s,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=i,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(s),t.lastOcclusionObject=null),n=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,n),n.occlusionQuerySet=i;const o=n.depthStencilAttachment;if(null!==e.textures){const t=n.colorAttachments;for(let r=0;r0&&t.currentPass.executeBundles(t.renderBundles),r>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),r>0){const s=8*r;let i=this.occludedResolveCache.get(s);void 0===i&&(i=this.device.createBuffer({size:s,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(s,i));const n=this.device.createBuffer({size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,r,i,0),t.encoder.copyBufferToBuffer(i,0,n,0,s),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,i.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:r,context:s,pipeline:i}=e,n=e.getBindings(),o=this.get(s),a=this.get(i).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=n.length;e1?0:r;l.drawIndexed(t[r],s,e[r]/n,0,o)}}else if(!0===p){const{vertexCount:s,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(s,i,n,0,0);t.update(r,s,i)}else{const{vertexCount:s,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(s,i,n,0);t.update(r,s,i)}}needsRenderUpdate(e){const t=this.get(e),{object:r,material:s}=e,i=this.utils,n=i.getSampleCountRenderContext(e.context),o=i.getCurrentColorSpace(e.context),a=i.getCurrentColorFormat(e.context),u=i.getCurrentDepthStencilFormat(e.context),l=i.getPrimitiveTopology(r,s);let d=!1;return t.material===s&&t.materialVersion===s.version&&t.transparent===s.transparent&&t.blending===s.blending&&t.premultipliedAlpha===s.premultipliedAlpha&&t.blendSrc===s.blendSrc&&t.blendDst===s.blendDst&&t.blendEquation===s.blendEquation&&t.blendSrcAlpha===s.blendSrcAlpha&&t.blendDstAlpha===s.blendDstAlpha&&t.blendEquationAlpha===s.blendEquationAlpha&&t.colorWrite===s.colorWrite&&t.depthWrite===s.depthWrite&&t.depthTest===s.depthTest&&t.depthFunc===s.depthFunc&&t.stencilWrite===s.stencilWrite&&t.stencilFunc===s.stencilFunc&&t.stencilFail===s.stencilFail&&t.stencilZFail===s.stencilZFail&&t.stencilZPass===s.stencilZPass&&t.stencilFuncMask===s.stencilFuncMask&&t.stencilWriteMask===s.stencilWriteMask&&t.side===s.side&&t.alphaToCoverage===s.alphaToCoverage&&t.sampleCount===n&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=s,t.materialVersion=s.version,t.transparent=s.transparent,t.blending=s.blending,t.premultipliedAlpha=s.premultipliedAlpha,t.blendSrc=s.blendSrc,t.blendDst=s.blendDst,t.blendEquation=s.blendEquation,t.blendSrcAlpha=s.blendSrcAlpha,t.blendDstAlpha=s.blendDstAlpha,t.blendEquationAlpha=s.blendEquationAlpha,t.colorWrite=s.colorWrite,t.depthWrite=s.depthWrite,t.depthTest=s.depthTest,t.depthFunc=s.depthFunc,t.stencilWrite=s.stencilWrite,t.stencilFunc=s.stencilFunc,t.stencilFail=s.stencilFail,t.stencilZFail=s.stencilZFail,t.stencilZPass=s.stencilZPass,t.stencilFuncMask=s.stencilFuncMask,t.stencilWriteMask=s.stencilWriteMask,t.side=s.side,t.alphaToCoverage=s.alphaToCoverage,t.sampleCount=n,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:r}=e,s=this.utils,i=e.context;return[r.transparent,r.blending,r.premultipliedAlpha,r.blendSrc,r.blendDst,r.blendEquation,r.blendSrcAlpha,r.blendDstAlpha,r.blendEquationAlpha,r.colorWrite,r.depthWrite,r.depthTest,r.depthFunc,r.stencilWrite,r.stencilFunc,r.stencilFail,r.stencilZFail,r.stencilZPass,r.stencilFuncMask,r.stencilWriteMask,r.side,s.getSampleCountRenderContext(i),s.getCurrentColorSpace(i),s.getCurrentColorFormat(i),s.getCurrentDepthStencilFormat(i),s.getPrimitiveTopology(t,r),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,r,s,i,n){return this.textureUtils.copyTextureToBuffer(e,t,r,s,i,n)}initTimestampQuery(e,t){if(!this.trackTimestamp)return;const r=this.get(e);if(!r.timeStampQuerySet){const s=e.isComputeNode?"compute":"render",i=this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_${s}_${e.id}`}),n={querySet:i,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),r.timeStampQuerySet=i}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const r=this.get(e),s=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===r.currentTimestampQueryBuffers&&(r.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:s,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ})});const{resolveBuffer:i,resultBuffer:n}=r.currentTimestampQueryBuffers;t.resolveQuerySet(r.timeStampQuerySet,0,2,i,0),"unmapped"===n.mapState&&t.copyBufferToBuffer(i,0,n,0,s)}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const r=this.get(e);if(void 0===r.currentTimestampQueryBuffers)return;const{resultBuffer:s}=r.currentTimestampQueryBuffers;await this.device.queue.onSubmittedWorkDone(),"unmapped"===s.mapState&&s.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(s.getMappedRange()),r=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,r),s.unmap()}))}createNodeBuilder(e,t){return new EN(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const r=this.get(e),s=r.currentPass.finish();this.get(t).bundleGPU=s,r.currentSets=r._currentSets,r.currentPass=r._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,r,s){this.bindingUtils.createBindings(e,t,r,s)}updateBindings(e,t,r,s){this.bindingUtils.createBindings(e,t,r,s)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,r=null,s=null,i=0){let n=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==r&&(u=r.x,l=r.y,d=r.z||0,c=r.width,h=r.height),null!==s&&(n=s.x,o=s.y,a=s.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:i,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:i,origin:{x:n,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,r){const s=this.get(t);let i=null;i=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const n=this.get(e).texture;if(i.format!==n.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",i.format,n.format);let o;if(s.currentPass?(s.currentPass.end(),o=s.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:i,origin:[r.x,r.y,0]},{texture:n},[r.z,r.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),s.currentPass){const{descriptor:e}=s;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new F_(e)));super(new t(e),e),this.library=new VN,this.isWebGPURenderer=!0}}class GN extends es{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const kN=new Yc,zN=new ef(kN);class $N{constructor(e,t=Oi(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,kN.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,r=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Ae,zN.render(e),e.toneMapping=t,e.outputColorSpace=r}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,r=e.outputColorSpace;zN.material.fragmentNode=!0===this.outputColorTransform?du(this.outputNode,t,r):this.outputNode.context({toneMapping:t,outputColorSpace:r}),zN.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,r=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Ae,await zN.renderAsync(e),e.toneMapping=t,e.outputColorSpace=r}}function WN(t,r={}){return r.toneMapping=t.toneMapping,r.toneMappingExposure=t.toneMappingExposure,r.outputColorSpace=t.outputColorSpace,r.renderTarget=t.getRenderTarget(),r.activeCubeFace=t.getActiveCubeFace(),r.activeMipmapLevel=t.getActiveMipmapLevel(),r.renderObjectFunction=t.getRenderObjectFunction(),r.pixelRatio=t.getPixelRatio(),r.mrt=t.getMRT(),r.clearColor=t.getClearColor(r.clearColor||new e),r.clearAlpha=t.getClearAlpha(),r.autoClear=t.autoClear,r.scissorTest=t.getScissorTest(),r}function HN(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function jN(e,t,r={}){return(r=WN(e,r)).background=t.background,r.backgroundNode=t.backgroundNode,r.overrideMaterial=t.overrideMaterial,r}var qN=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,r){return r=jN(e,t,r),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,r},resetRendererState:function(e,t){return t=WN(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,r){HN(e,r),t.background=r.background,t.backgroundNode=r.backgroundNode,t.overrideMaterial=r.overrideMaterial},restoreRendererState:HN,saveRendererAndSceneState:jN,saveRendererState:WN});class KN extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class XN extends lf{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class YN extends ts{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,r,s){const i=new rs(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,(r=>{try{t(this.parse(JSON.parse(r)))}catch(t){s?s(t):console.error(t),this.manager.itemError(e)}}),r,s)}parseNodes(e){const t={};if(void 0!==e){for(const r of e){const{uuid:e,type:s}=r;t[e]=this.createNodeFromType(s),t[e].uuid=e}const r={nodes:t,textures:this.textures};for(const s of e){s.meta=r;t[s.uuid].deserialize(s),delete s.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const r={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=r,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Ci()):fi(new this.nodes[e])}}class QN extends ss{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),r=this.nodes,s=e.inputNodes;for(const e in s){const i=s[e];t[e]=r[i]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class ZN extends is{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const r=super.parse(e,t);return this._nodesJSON=null,r}parseNodes(e,t){if(void 0!==e){const r=new YN;return r.setNodes(this.nodes),r.setTextures(t),r.parseNodes(e)}return{}}parseMaterials(e,t){const r={};if(void 0!==e){const s=this.parseNodes(this._nodesJSON,t),i=new QN;i.setTextures(t),i.setNodes(s),i.setNodeMaterials(this.nodeMaterials);for(let t=0,s=e.length;t Math.PI ) min -= _twoPI; + + if ( max < - Math.PI ) max += _twoPI; else if ( max > Math.PI ) max -= _twoPI; + + if ( min <= max ) { + + this._spherical.theta = Math.max( min, Math.min( max, this._spherical.theta ) ); + + } else { + + this._spherical.theta = ( this._spherical.theta > ( min + max ) / 2 ) ? + Math.max( min, this._spherical.theta ) : + Math.min( max, this._spherical.theta ); + + } + + } + + // restrict phi to be between desired limits + this._spherical.phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, this._spherical.phi ) ); + + this._spherical.makeSafe(); + + + // move target to panned location + + if ( this.enableDamping === true ) { + + this.target.addScaledVector( this._panOffset, this.dampingFactor ); + + } else { + + this.target.add( this._panOffset ); + + } + + // Limit the target distance from the cursor to create a sphere around the center of interest + this.target.sub( this.cursor ); + this.target.clampLength( this.minTargetRadius, this.maxTargetRadius ); + this.target.add( this.cursor ); + + let zoomChanged = false; + // adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera + // we adjust zoom later in these cases + if ( this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera ) { + + this._spherical.radius = this._clampDistance( this._spherical.radius ); + + } else { + + const prevRadius = this._spherical.radius; + this._spherical.radius = this._clampDistance( this._spherical.radius * this._scale ); + zoomChanged = prevRadius != this._spherical.radius; + + } + + _v.setFromSpherical( this._spherical ); + + // rotate offset back to "camera-up-vector-is-up" space + _v.applyQuaternion( this._quatInverse ); + + position.copy( this.target ).add( _v ); + + this.object.lookAt( this.target ); + + if ( this.enableDamping === true ) { + + this._sphericalDelta.theta *= ( 1 - this.dampingFactor ); + this._sphericalDelta.phi *= ( 1 - this.dampingFactor ); + + this._panOffset.multiplyScalar( 1 - this.dampingFactor ); + + } else { + + this._sphericalDelta.set( 0, 0, 0 ); + + this._panOffset.set( 0, 0, 0 ); + + } + + // adjust camera position + if ( this.zoomToCursor && this._performCursorZoom ) { + + let newRadius = null; + if ( this.object.isPerspectiveCamera ) { + + // move the camera down the pointer ray + // this method avoids floating point error + const prevRadius = _v.length(); + newRadius = this._clampDistance( prevRadius * this._scale ); + + const radiusDelta = prevRadius - newRadius; + this.object.position.addScaledVector( this._dollyDirection, radiusDelta ); + this.object.updateMatrixWorld(); + + zoomChanged = !! radiusDelta; + + } else if ( this.object.isOrthographicCamera ) { + + // adjust the ortho camera position based on zoom changes + const mouseBefore = new Vector3( this._mouse.x, this._mouse.y, 0 ); + mouseBefore.unproject( this.object ); + + const prevZoom = this.object.zoom; + this.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / this._scale ) ); + this.object.updateProjectionMatrix(); + + zoomChanged = prevZoom !== this.object.zoom; + + const mouseAfter = new Vector3( this._mouse.x, this._mouse.y, 0 ); + mouseAfter.unproject( this.object ); + + this.object.position.sub( mouseAfter ).add( mouseBefore ); + this.object.updateMatrixWorld(); + + newRadius = _v.length(); + + } else { + + console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.' ); + this.zoomToCursor = false; + + } + + // handle the placement of the target + if ( newRadius !== null ) { + + if ( this.screenSpacePanning ) { + + // position the orbit target in front of the new camera position + this.target.set( 0, 0, - 1 ) + .transformDirection( this.object.matrix ) + .multiplyScalar( newRadius ) + .add( this.object.position ); + + } else { + + // get the ray and translation plane to compute target + _ray.origin.copy( this.object.position ); + _ray.direction.set( 0, 0, - 1 ).transformDirection( this.object.matrix ); + + // if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid + // extremely large values + if ( Math.abs( this.object.up.dot( _ray.direction ) ) < _TILT_LIMIT ) { + + this.object.lookAt( this.target ); + + } else { + + _plane.setFromNormalAndCoplanarPoint( this.object.up, this.target ); + _ray.intersectPlane( _plane, this.target ); + + } + + } + + } + + } else if ( this.object.isOrthographicCamera ) { + + const prevZoom = this.object.zoom; + this.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / this._scale ) ); + + if ( prevZoom !== this.object.zoom ) { + + this.object.updateProjectionMatrix(); + zoomChanged = true; + + } + + } + + this._scale = 1; + this._performCursorZoom = false; + + // update condition is: + // min(camera displacement, camera rotation in radians)^2 > EPS + // using small-angle approximation cos(x/2) = 1 - x^2 / 8 + + if ( zoomChanged || + this._lastPosition.distanceToSquared( this.object.position ) > _EPS || + 8 * ( 1 - this._lastQuaternion.dot( this.object.quaternion ) ) > _EPS || + this._lastTargetPosition.distanceToSquared( this.target ) > _EPS ) { + + this.dispatchEvent( _changeEvent ); + + this._lastPosition.copy( this.object.position ); + this._lastQuaternion.copy( this.object.quaternion ); + this._lastTargetPosition.copy( this.target ); + + return true; + + } + + return false; + + } + + _getAutoRotationAngle( deltaTime ) { + + if ( deltaTime !== null ) { + + return ( _twoPI / 60 * this.autoRotateSpeed ) * deltaTime; + + } else { + + return _twoPI / 60 / 60 * this.autoRotateSpeed; + + } + + } + + _getZoomScale( delta ) { + + const normalizedDelta = Math.abs( delta * 0.01 ); + return Math.pow( 0.95, this.zoomSpeed * normalizedDelta ); + + } + + _rotateLeft( angle ) { + + this._sphericalDelta.theta -= angle; + + } + + _rotateUp( angle ) { + + this._sphericalDelta.phi -= angle; + + } + + _panLeft( distance, objectMatrix ) { + + _v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix + _v.multiplyScalar( - distance ); + + this._panOffset.add( _v ); + + } + + _panUp( distance, objectMatrix ) { + + if ( this.screenSpacePanning === true ) { + + _v.setFromMatrixColumn( objectMatrix, 1 ); + + } else { + + _v.setFromMatrixColumn( objectMatrix, 0 ); + _v.crossVectors( this.object.up, _v ); + + } + + _v.multiplyScalar( distance ); + + this._panOffset.add( _v ); + + } + + // deltaX and deltaY are in pixels; right and down are positive + _pan( deltaX, deltaY ) { + + const element = this.domElement; + + if ( this.object.isPerspectiveCamera ) { + + // perspective + const position = this.object.position; + _v.copy( position ).sub( this.target ); + let targetDistance = _v.length(); + + // half of the fov is center to top of screen + targetDistance *= Math.tan( ( this.object.fov / 2 ) * Math.PI / 180.0 ); + + // we use only clientHeight here so aspect ratio does not distort speed + this._panLeft( 2 * deltaX * targetDistance / element.clientHeight, this.object.matrix ); + this._panUp( 2 * deltaY * targetDistance / element.clientHeight, this.object.matrix ); + + } else if ( this.object.isOrthographicCamera ) { + + // orthographic + this._panLeft( deltaX * ( this.object.right - this.object.left ) / this.object.zoom / element.clientWidth, this.object.matrix ); + this._panUp( deltaY * ( this.object.top - this.object.bottom ) / this.object.zoom / element.clientHeight, this.object.matrix ); + + } else { + + // camera neither orthographic nor perspective + console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' ); + this.enablePan = false; + + } + + } + + _dollyOut( dollyScale ) { + + if ( this.object.isPerspectiveCamera || this.object.isOrthographicCamera ) { + + this._scale /= dollyScale; + + } else { + + console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' ); + this.enableZoom = false; + + } + + } + + _dollyIn( dollyScale ) { + + if ( this.object.isPerspectiveCamera || this.object.isOrthographicCamera ) { + + this._scale *= dollyScale; + + } else { + + console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' ); + this.enableZoom = false; + + } + + } + + _updateZoomParameters( x, y ) { + + if ( ! this.zoomToCursor ) { + + return; + + } + + this._performCursorZoom = true; + + const rect = this.domElement.getBoundingClientRect(); + const dx = x - rect.left; + const dy = y - rect.top; + const w = rect.width; + const h = rect.height; + + this._mouse.x = ( dx / w ) * 2 - 1; + this._mouse.y = - ( dy / h ) * 2 + 1; + + this._dollyDirection.set( this._mouse.x, this._mouse.y, 1 ).unproject( this.object ).sub( this.object.position ).normalize(); + + } + + _clampDistance( dist ) { + + return Math.max( this.minDistance, Math.min( this.maxDistance, dist ) ); + + } + + // + // event callbacks - update the object state + // + + _handleMouseDownRotate( event ) { + + this._rotateStart.set( event.clientX, event.clientY ); + + } + + _handleMouseDownDolly( event ) { + + this._updateZoomParameters( event.clientX, event.clientX ); + this._dollyStart.set( event.clientX, event.clientY ); + + } + + _handleMouseDownPan( event ) { + + this._panStart.set( event.clientX, event.clientY ); + + } + + _handleMouseMoveRotate( event ) { + + this._rotateEnd.set( event.clientX, event.clientY ); + + this._rotateDelta.subVectors( this._rotateEnd, this._rotateStart ).multiplyScalar( this.rotateSpeed ); + + const element = this.domElement; + + this._rotateLeft( _twoPI * this._rotateDelta.x / element.clientHeight ); // yes, height + + this._rotateUp( _twoPI * this._rotateDelta.y / element.clientHeight ); + + this._rotateStart.copy( this._rotateEnd ); + + this.update(); + + } + + _handleMouseMoveDolly( event ) { + + this._dollyEnd.set( event.clientX, event.clientY ); + + this._dollyDelta.subVectors( this._dollyEnd, this._dollyStart ); + + if ( this._dollyDelta.y > 0 ) { + + this._dollyOut( this._getZoomScale( this._dollyDelta.y ) ); + + } else if ( this._dollyDelta.y < 0 ) { + + this._dollyIn( this._getZoomScale( this._dollyDelta.y ) ); + + } + + this._dollyStart.copy( this._dollyEnd ); + + this.update(); + + } + + _handleMouseMovePan( event ) { + + this._panEnd.set( event.clientX, event.clientY ); + + this._panDelta.subVectors( this._panEnd, this._panStart ).multiplyScalar( this.panSpeed ); + + this._pan( this._panDelta.x, this._panDelta.y ); + + this._panStart.copy( this._panEnd ); + + this.update(); + + } + + _handleMouseWheel( event ) { + + this._updateZoomParameters( event.clientX, event.clientY ); + + if ( event.deltaY < 0 ) { + + this._dollyIn( this._getZoomScale( event.deltaY ) ); + + } else if ( event.deltaY > 0 ) { + + this._dollyOut( this._getZoomScale( event.deltaY ) ); + + } + + this.update(); + + } + + _handleKeyDown( event ) { + + let needsUpdate = false; + + switch ( event.code ) { + + case this.keys.UP: + + if ( event.ctrlKey || event.metaKey || event.shiftKey ) { + + if ( this.enableRotate ) { + + this._rotateUp( _twoPI * this.rotateSpeed / this.domElement.clientHeight ); + + } + + } else { + + if ( this.enablePan ) { + + this._pan( 0, this.keyPanSpeed ); + + } + + } + + needsUpdate = true; + break; + + case this.keys.BOTTOM: + + if ( event.ctrlKey || event.metaKey || event.shiftKey ) { + + if ( this.enableRotate ) { + + this._rotateUp( - _twoPI * this.rotateSpeed / this.domElement.clientHeight ); + + } + + } else { + + if ( this.enablePan ) { + + this._pan( 0, - this.keyPanSpeed ); + + } + + } + + needsUpdate = true; + break; + + case this.keys.LEFT: + + if ( event.ctrlKey || event.metaKey || event.shiftKey ) { + + if ( this.enableRotate ) { + + this._rotateLeft( _twoPI * this.rotateSpeed / this.domElement.clientHeight ); + + } + + } else { + + if ( this.enablePan ) { + + this._pan( this.keyPanSpeed, 0 ); + + } + + } + + needsUpdate = true; + break; + + case this.keys.RIGHT: + + if ( event.ctrlKey || event.metaKey || event.shiftKey ) { + + if ( this.enableRotate ) { + + this._rotateLeft( - _twoPI * this.rotateSpeed / this.domElement.clientHeight ); + + } + + } else { + + if ( this.enablePan ) { + + this._pan( - this.keyPanSpeed, 0 ); + + } + + } + + needsUpdate = true; + break; + + } + + if ( needsUpdate ) { + + // prevent the browser from scrolling on cursor keys + event.preventDefault(); + + this.update(); + + } + + + } + + _handleTouchStartRotate( event ) { + + if ( this._pointers.length === 1 ) { + + this._rotateStart.set( event.pageX, event.pageY ); + + } else { + + const position = this._getSecondPointerPosition( event ); + + const x = 0.5 * ( event.pageX + position.x ); + const y = 0.5 * ( event.pageY + position.y ); + + this._rotateStart.set( x, y ); + + } + + } + + _handleTouchStartPan( event ) { + + if ( this._pointers.length === 1 ) { + + this._panStart.set( event.pageX, event.pageY ); + + } else { + + const position = this._getSecondPointerPosition( event ); + + const x = 0.5 * ( event.pageX + position.x ); + const y = 0.5 * ( event.pageY + position.y ); + + this._panStart.set( x, y ); + + } + + } + + _handleTouchStartDolly( event ) { + + const position = this._getSecondPointerPosition( event ); + + const dx = event.pageX - position.x; + const dy = event.pageY - position.y; + + const distance = Math.sqrt( dx * dx + dy * dy ); + + this._dollyStart.set( 0, distance ); + + } + + _handleTouchStartDollyPan( event ) { + + if ( this.enableZoom ) this._handleTouchStartDolly( event ); + + if ( this.enablePan ) this._handleTouchStartPan( event ); + + } + + _handleTouchStartDollyRotate( event ) { + + if ( this.enableZoom ) this._handleTouchStartDolly( event ); + + if ( this.enableRotate ) this._handleTouchStartRotate( event ); + + } + + _handleTouchMoveRotate( event ) { + + if ( this._pointers.length == 1 ) { + + this._rotateEnd.set( event.pageX, event.pageY ); + + } else { + + const position = this._getSecondPointerPosition( event ); + + const x = 0.5 * ( event.pageX + position.x ); + const y = 0.5 * ( event.pageY + position.y ); + + this._rotateEnd.set( x, y ); + + } + + this._rotateDelta.subVectors( this._rotateEnd, this._rotateStart ).multiplyScalar( this.rotateSpeed ); + + const element = this.domElement; + + this._rotateLeft( _twoPI * this._rotateDelta.x / element.clientHeight ); // yes, height + + this._rotateUp( _twoPI * this._rotateDelta.y / element.clientHeight ); + + this._rotateStart.copy( this._rotateEnd ); + + } + + _handleTouchMovePan( event ) { + + if ( this._pointers.length === 1 ) { + + this._panEnd.set( event.pageX, event.pageY ); + + } else { + + const position = this._getSecondPointerPosition( event ); + + const x = 0.5 * ( event.pageX + position.x ); + const y = 0.5 * ( event.pageY + position.y ); + + this._panEnd.set( x, y ); + + } + + this._panDelta.subVectors( this._panEnd, this._panStart ).multiplyScalar( this.panSpeed ); + + this._pan( this._panDelta.x, this._panDelta.y ); + + this._panStart.copy( this._panEnd ); + + } + + _handleTouchMoveDolly( event ) { + + const position = this._getSecondPointerPosition( event ); + + const dx = event.pageX - position.x; + const dy = event.pageY - position.y; + + const distance = Math.sqrt( dx * dx + dy * dy ); + + this._dollyEnd.set( 0, distance ); + + this._dollyDelta.set( 0, Math.pow( this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed ) ); + + this._dollyOut( this._dollyDelta.y ); + + this._dollyStart.copy( this._dollyEnd ); + + const centerX = ( event.pageX + position.x ) * 0.5; + const centerY = ( event.pageY + position.y ) * 0.5; + + this._updateZoomParameters( centerX, centerY ); + + } + + _handleTouchMoveDollyPan( event ) { + + if ( this.enableZoom ) this._handleTouchMoveDolly( event ); + + if ( this.enablePan ) this._handleTouchMovePan( event ); + + } + + _handleTouchMoveDollyRotate( event ) { + + if ( this.enableZoom ) this._handleTouchMoveDolly( event ); + + if ( this.enableRotate ) this._handleTouchMoveRotate( event ); + + } + + // pointers + + _addPointer( event ) { + + this._pointers.push( event.pointerId ); + + } + + _removePointer( event ) { + + delete this._pointerPositions[ event.pointerId ]; + + for ( let i = 0; i < this._pointers.length; i ++ ) { + + if ( this._pointers[ i ] == event.pointerId ) { + + this._pointers.splice( i, 1 ); + return; + + } + + } + + } + + _isTrackingPointer( event ) { + + for ( let i = 0; i < this._pointers.length; i ++ ) { + + if ( this._pointers[ i ] == event.pointerId ) return true; + + } + + return false; + + } + + _trackPointer( event ) { + + let position = this._pointerPositions[ event.pointerId ]; + + if ( position === undefined ) { + + position = new Vector2(); + this._pointerPositions[ event.pointerId ] = position; + + } + + position.set( event.pageX, event.pageY ); + + } + + _getSecondPointerPosition( event ) { + + const pointerId = ( event.pointerId === this._pointers[ 0 ] ) ? this._pointers[ 1 ] : this._pointers[ 0 ]; + + return this._pointerPositions[ pointerId ]; + + } + + // + + _customWheelEvent( event ) { + + const mode = event.deltaMode; + + // minimal wheel event altered to meet delta-zoom demand + const newEvent = { + clientX: event.clientX, + clientY: event.clientY, + deltaY: event.deltaY, + }; + + switch ( mode ) { + + case 1: // LINE_MODE + newEvent.deltaY *= 16; + break; + + case 2: // PAGE_MODE + newEvent.deltaY *= 100; + break; + + } + + // detect if event was triggered by pinching + if ( event.ctrlKey && ! this._controlActive ) { + + newEvent.deltaY *= 10; + + } + + return newEvent; + + } + +} + +function onPointerDown( event ) { + + if ( this.enabled === false ) return; + + if ( this._pointers.length === 0 ) { + + this.domElement.setPointerCapture( event.pointerId ); + + this.domElement.addEventListener( 'pointermove', this._onPointerMove ); + this.domElement.addEventListener( 'pointerup', this._onPointerUp ); + + } + + // + + if ( this._isTrackingPointer( event ) ) return; + + // + + this._addPointer( event ); + + if ( event.pointerType === 'touch' ) { + + this._onTouchStart( event ); + + } else { + + this._onMouseDown( event ); + + } + +} + +function onPointerMove( event ) { + + if ( this.enabled === false ) return; + + if ( event.pointerType === 'touch' ) { + + this._onTouchMove( event ); + + } else { + + this._onMouseMove( event ); + + } + +} + +function onPointerUp( event ) { + + this._removePointer( event ); + + switch ( this._pointers.length ) { + + case 0: + + this.domElement.releasePointerCapture( event.pointerId ); + + this.domElement.removeEventListener( 'pointermove', this._onPointerMove ); + this.domElement.removeEventListener( 'pointerup', this._onPointerUp ); + + this.dispatchEvent( _endEvent ); + + this.state = _STATE.NONE; + + break; + + case 1: + + const pointerId = this._pointers[ 0 ]; + const position = this._pointerPositions[ pointerId ]; + + // minimal placeholder event - allows state correction on pointer-up + this._onTouchStart( { pointerId: pointerId, pageX: position.x, pageY: position.y } ); + + break; + + } + +} + +function onMouseDown( event ) { + + let mouseAction; + + switch ( event.button ) { + + case 0: + + mouseAction = this.mouseButtons.LEFT; + break; + + case 1: + + mouseAction = this.mouseButtons.MIDDLE; + break; + + case 2: + + mouseAction = this.mouseButtons.RIGHT; + break; + + default: + + mouseAction = - 1; + + } + + switch ( mouseAction ) { + + case MOUSE.DOLLY: + + if ( this.enableZoom === false ) return; + + this._handleMouseDownDolly( event ); + + this.state = _STATE.DOLLY; + + break; + + case MOUSE.ROTATE: + + if ( event.ctrlKey || event.metaKey || event.shiftKey ) { + + if ( this.enablePan === false ) return; + + this._handleMouseDownPan( event ); + + this.state = _STATE.PAN; + + } else { + + if ( this.enableRotate === false ) return; + + this._handleMouseDownRotate( event ); + + this.state = _STATE.ROTATE; + + } + + break; + + case MOUSE.PAN: + + if ( event.ctrlKey || event.metaKey || event.shiftKey ) { + + if ( this.enableRotate === false ) return; + + this._handleMouseDownRotate( event ); + + this.state = _STATE.ROTATE; + + } else { + + if ( this.enablePan === false ) return; + + this._handleMouseDownPan( event ); + + this.state = _STATE.PAN; + + } + + break; + + default: + + this.state = _STATE.NONE; + + } + + if ( this.state !== _STATE.NONE ) { + + this.dispatchEvent( _startEvent ); + + } + +} + +function onMouseMove( event ) { + + switch ( this.state ) { + + case _STATE.ROTATE: + + if ( this.enableRotate === false ) return; + + this._handleMouseMoveRotate( event ); + + break; + + case _STATE.DOLLY: + + if ( this.enableZoom === false ) return; + + this._handleMouseMoveDolly( event ); + + break; + + case _STATE.PAN: + + if ( this.enablePan === false ) return; + + this._handleMouseMovePan( event ); + + break; + + } + +} + +function onMouseWheel( event ) { + + if ( this.enabled === false || this.enableZoom === false || this.state !== _STATE.NONE ) return; + + event.preventDefault(); + + this.dispatchEvent( _startEvent ); + + this._handleMouseWheel( this._customWheelEvent( event ) ); + + this.dispatchEvent( _endEvent ); + +} + +function onKeyDown( event ) { + + if ( this.enabled === false ) return; + + this._handleKeyDown( event ); + +} + +function onTouchStart( event ) { + + this._trackPointer( event ); + + switch ( this._pointers.length ) { + + case 1: + + switch ( this.touches.ONE ) { + + case TOUCH.ROTATE: + + if ( this.enableRotate === false ) return; + + this._handleTouchStartRotate( event ); + + this.state = _STATE.TOUCH_ROTATE; + + break; + + case TOUCH.PAN: + + if ( this.enablePan === false ) return; + + this._handleTouchStartPan( event ); + + this.state = _STATE.TOUCH_PAN; + + break; + + default: + + this.state = _STATE.NONE; + + } + + break; + + case 2: + + switch ( this.touches.TWO ) { + + case TOUCH.DOLLY_PAN: + + if ( this.enableZoom === false && this.enablePan === false ) return; + + this._handleTouchStartDollyPan( event ); + + this.state = _STATE.TOUCH_DOLLY_PAN; + + break; + + case TOUCH.DOLLY_ROTATE: + + if ( this.enableZoom === false && this.enableRotate === false ) return; + + this._handleTouchStartDollyRotate( event ); + + this.state = _STATE.TOUCH_DOLLY_ROTATE; + + break; + + default: + + this.state = _STATE.NONE; + + } + + break; + + default: + + this.state = _STATE.NONE; + + } + + if ( this.state !== _STATE.NONE ) { + + this.dispatchEvent( _startEvent ); + + } + +} + +function onTouchMove( event ) { + + this._trackPointer( event ); + + switch ( this.state ) { + + case _STATE.TOUCH_ROTATE: + + if ( this.enableRotate === false ) return; + + this._handleTouchMoveRotate( event ); + + this.update(); + + break; + + case _STATE.TOUCH_PAN: + + if ( this.enablePan === false ) return; + + this._handleTouchMovePan( event ); + + this.update(); + + break; + + case _STATE.TOUCH_DOLLY_PAN: + + if ( this.enableZoom === false && this.enablePan === false ) return; + + this._handleTouchMoveDollyPan( event ); + + this.update(); + + break; + + case _STATE.TOUCH_DOLLY_ROTATE: + + if ( this.enableZoom === false && this.enableRotate === false ) return; + + this._handleTouchMoveDollyRotate( event ); + + this.update(); + + break; + + default: + + this.state = _STATE.NONE; + + } + +} + +function onContextMenu( event ) { + + if ( this.enabled === false ) return; + + event.preventDefault(); + +} + +function interceptControlDown( event ) { + + if ( event.key === 'Control' ) { + + this._controlActive = true; + + const document = this.domElement.getRootNode(); // offscreen canvas compatibility + + document.addEventListener( 'keyup', this._interceptControlUp, { passive: true, capture: true } ); + + } + +} + +function interceptControlUp( event ) { + + if ( event.key === 'Control' ) { + + this._controlActive = false; + + const document = this.domElement.getRootNode(); // offscreen canvas compatibility + + document.removeEventListener( 'keyup', this._interceptControlUp, { passive: true, capture: true } ); + + } + +} + +export { OrbitControls }; diff --git a/libs/three.js/r171/examples/jsm/exporters/GLTFExporter.js b/libs/three.js/r171/examples/jsm/exporters/GLTFExporter.js new file mode 100644 index 000000000..4661958d1 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/exporters/GLTFExporter.js @@ -0,0 +1,3456 @@ +import { + BufferAttribute, + ClampToEdgeWrapping, + Color, + DoubleSide, + InterpolateDiscrete, + InterpolateLinear, + NoColorSpace, + LinearFilter, + LinearMipmapLinearFilter, + LinearMipmapNearestFilter, + MathUtils, + Matrix4, + MirroredRepeatWrapping, + NearestFilter, + NearestMipmapLinearFilter, + NearestMipmapNearestFilter, + PropertyBinding, + RGBAFormat, + RepeatWrapping, + Scene, + Source, + SRGBColorSpace, + CompressedTexture, + Vector3, + Quaternion, + REVISION +} from 'three'; + +/** + * The KHR_mesh_quantization extension allows these extra attribute component types + * + * @see https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md#extending-mesh-attributes + */ +const KHR_mesh_quantization_ExtraAttrTypes = { + POSITION: [ + 'byte', + 'byte normalized', + 'unsigned byte', + 'unsigned byte normalized', + 'short', + 'short normalized', + 'unsigned short', + 'unsigned short normalized', + ], + NORMAL: [ + 'byte normalized', + 'short normalized', + ], + TANGENT: [ + 'byte normalized', + 'short normalized', + ], + TEXCOORD: [ + 'byte', + 'byte normalized', + 'unsigned byte', + 'short', + 'short normalized', + 'unsigned short', + ], +}; + + +class GLTFExporter { + + constructor() { + + this.textureUtils = null; + + this.pluginCallbacks = []; + + this.register( function ( writer ) { + + return new GLTFLightExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsUnlitExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsTransmissionExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsVolumeExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsIorExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsSpecularExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsClearcoatExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsDispersionExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsIridescenceExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsSheenExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsAnisotropyExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsEmissiveStrengthExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMaterialsBumpExtension( writer ); + + } ); + + this.register( function ( writer ) { + + return new GLTFMeshGpuInstancing( writer ); + + } ); + + } + + register( callback ) { + + if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) { + + this.pluginCallbacks.push( callback ); + + } + + return this; + + } + + unregister( callback ) { + + if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) { + + this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 ); + + } + + return this; + + } + + setTextureUtils( utils ) { + + this.textureUtils = utils; + + return this; + + } + + /** + * Parse scenes and generate GLTF output + * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes + * @param {Function} onDone Callback on completed + * @param {Function} onError Callback on errors + * @param {Object} options options + */ + parse( input, onDone, onError, options ) { + + const writer = new GLTFWriter(); + const plugins = []; + + for ( let i = 0, il = this.pluginCallbacks.length; i < il; i ++ ) { + + plugins.push( this.pluginCallbacks[ i ]( writer ) ); + + } + + writer.setPlugins( plugins ); + writer.setTextureUtils( this.textureUtils ); + writer.writeAsync( input, onDone, options ).catch( onError ); + + } + + parseAsync( input, options ) { + + const scope = this; + + return new Promise( function ( resolve, reject ) { + + scope.parse( input, resolve, reject, options ); + + } ); + + } + +} + +//------------------------------------------------------------------------------ +// Constants +//------------------------------------------------------------------------------ + +const WEBGL_CONSTANTS = { + POINTS: 0x0000, + LINES: 0x0001, + LINE_LOOP: 0x0002, + LINE_STRIP: 0x0003, + TRIANGLES: 0x0004, + TRIANGLE_STRIP: 0x0005, + TRIANGLE_FAN: 0x0006, + + BYTE: 0x1400, + UNSIGNED_BYTE: 0x1401, + SHORT: 0x1402, + UNSIGNED_SHORT: 0x1403, + INT: 0x1404, + UNSIGNED_INT: 0x1405, + FLOAT: 0x1406, + + ARRAY_BUFFER: 0x8892, + ELEMENT_ARRAY_BUFFER: 0x8893, + + NEAREST: 0x2600, + LINEAR: 0x2601, + NEAREST_MIPMAP_NEAREST: 0x2700, + LINEAR_MIPMAP_NEAREST: 0x2701, + NEAREST_MIPMAP_LINEAR: 0x2702, + LINEAR_MIPMAP_LINEAR: 0x2703, + + CLAMP_TO_EDGE: 33071, + MIRRORED_REPEAT: 33648, + REPEAT: 10497 +}; + +const KHR_MESH_QUANTIZATION = 'KHR_mesh_quantization'; + +const THREE_TO_WEBGL = {}; + +THREE_TO_WEBGL[ NearestFilter ] = WEBGL_CONSTANTS.NEAREST; +THREE_TO_WEBGL[ NearestMipmapNearestFilter ] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST; +THREE_TO_WEBGL[ NearestMipmapLinearFilter ] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR; +THREE_TO_WEBGL[ LinearFilter ] = WEBGL_CONSTANTS.LINEAR; +THREE_TO_WEBGL[ LinearMipmapNearestFilter ] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST; +THREE_TO_WEBGL[ LinearMipmapLinearFilter ] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR; + +THREE_TO_WEBGL[ ClampToEdgeWrapping ] = WEBGL_CONSTANTS.CLAMP_TO_EDGE; +THREE_TO_WEBGL[ RepeatWrapping ] = WEBGL_CONSTANTS.REPEAT; +THREE_TO_WEBGL[ MirroredRepeatWrapping ] = WEBGL_CONSTANTS.MIRRORED_REPEAT; + +const PATH_PROPERTIES = { + scale: 'scale', + position: 'translation', + quaternion: 'rotation', + morphTargetInfluences: 'weights' +}; + +const DEFAULT_SPECULAR_COLOR = new Color(); + +// GLB constants +// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification + +const GLB_HEADER_BYTES = 12; +const GLB_HEADER_MAGIC = 0x46546C67; +const GLB_VERSION = 2; + +const GLB_CHUNK_PREFIX_BYTES = 8; +const GLB_CHUNK_TYPE_JSON = 0x4E4F534A; +const GLB_CHUNK_TYPE_BIN = 0x004E4942; + +//------------------------------------------------------------------------------ +// Utility functions +//------------------------------------------------------------------------------ + +/** + * Compare two arrays + * @param {Array} array1 Array 1 to compare + * @param {Array} array2 Array 2 to compare + * @return {Boolean} Returns true if both arrays are equal + */ +function equalArray( array1, array2 ) { + + return ( array1.length === array2.length ) && array1.every( function ( element, index ) { + + return element === array2[ index ]; + + } ); + +} + +/** + * Converts a string to an ArrayBuffer. + * @param {string} text + * @return {ArrayBuffer} + */ +function stringToArrayBuffer( text ) { + + return new TextEncoder().encode( text ).buffer; + +} + +/** + * Is identity matrix + * + * @param {Matrix4} matrix + * @returns {Boolean} Returns true, if parameter is identity matrix + */ +function isIdentityMatrix( matrix ) { + + return equalArray( matrix.elements, [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ] ); + +} + +/** + * Get the min and max vectors from the given attribute + * @param {BufferAttribute} attribute Attribute to find the min/max in range from start to start + count + * @param {Integer} start + * @param {Integer} count + * @return {Object} Object containing the `min` and `max` values (As an array of attribute.itemSize components) + */ +function getMinMax( attribute, start, count ) { + + const output = { + + min: new Array( attribute.itemSize ).fill( Number.POSITIVE_INFINITY ), + max: new Array( attribute.itemSize ).fill( Number.NEGATIVE_INFINITY ) + + }; + + for ( let i = start; i < start + count; i ++ ) { + + for ( let a = 0; a < attribute.itemSize; a ++ ) { + + let value; + + if ( attribute.itemSize > 4 ) { + + // no support for interleaved data for itemSize > 4 + + value = attribute.array[ i * attribute.itemSize + a ]; + + } else { + + if ( a === 0 ) value = attribute.getX( i ); + else if ( a === 1 ) value = attribute.getY( i ); + else if ( a === 2 ) value = attribute.getZ( i ); + else if ( a === 3 ) value = attribute.getW( i ); + + if ( attribute.normalized === true ) { + + value = MathUtils.normalize( value, attribute.array ); + + } + + } + + output.min[ a ] = Math.min( output.min[ a ], value ); + output.max[ a ] = Math.max( output.max[ a ], value ); + + } + + } + + return output; + +} + +/** + * Get the required size + padding for a buffer, rounded to the next 4-byte boundary. + * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment + * + * @param {Integer} bufferSize The size the original buffer. + * @returns {Integer} new buffer size with required padding. + * + */ +function getPaddedBufferSize( bufferSize ) { + + return Math.ceil( bufferSize / 4 ) * 4; + +} + +/** + * Returns a buffer aligned to 4-byte boundary. + * + * @param {ArrayBuffer} arrayBuffer Buffer to pad + * @param {Integer} paddingByte (Optional) + * @returns {ArrayBuffer} The same buffer if it's already aligned to 4-byte boundary or a new buffer + */ +function getPaddedArrayBuffer( arrayBuffer, paddingByte = 0 ) { + + const paddedLength = getPaddedBufferSize( arrayBuffer.byteLength ); + + if ( paddedLength !== arrayBuffer.byteLength ) { + + const array = new Uint8Array( paddedLength ); + array.set( new Uint8Array( arrayBuffer ) ); + + if ( paddingByte !== 0 ) { + + for ( let i = arrayBuffer.byteLength; i < paddedLength; i ++ ) { + + array[ i ] = paddingByte; + + } + + } + + return array.buffer; + + } + + return arrayBuffer; + +} + +function getCanvas() { + + if ( typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined' ) { + + return new OffscreenCanvas( 1, 1 ); + + } + + return document.createElement( 'canvas' ); + +} + +function getToBlobPromise( canvas, mimeType ) { + + if ( canvas.toBlob !== undefined ) { + + return new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) ); + + } + + let quality; + + // Blink's implementation of convertToBlob seems to default to a quality level of 100% + // Use the Blink default quality levels of toBlob instead so that file sizes are comparable. + if ( mimeType === 'image/jpeg' ) { + + quality = 0.92; + + } else if ( mimeType === 'image/webp' ) { + + quality = 0.8; + + } + + return canvas.convertToBlob( { + + type: mimeType, + quality: quality + + } ); + +} + +/** + * Writer + */ +class GLTFWriter { + + constructor() { + + this.plugins = []; + + this.options = {}; + this.pending = []; + this.buffers = []; + + this.byteOffset = 0; + this.buffers = []; + this.nodeMap = new Map(); + this.skins = []; + + this.extensionsUsed = {}; + this.extensionsRequired = {}; + + this.uids = new Map(); + this.uid = 0; + + this.json = { + asset: { + version: '2.0', + generator: 'THREE.GLTFExporter r' + REVISION + } + }; + + this.cache = { + meshes: new Map(), + attributes: new Map(), + attributesNormalized: new Map(), + materials: new Map(), + textures: new Map(), + images: new Map() + }; + + this.textureUtils = null; + + } + + setPlugins( plugins ) { + + this.plugins = plugins; + + } + + setTextureUtils( utils ) { + + this.textureUtils = utils; + + } + + /** + * Parse scenes and generate GLTF output + * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes + * @param {Function} onDone Callback on completed + * @param {Object} options options + */ + async writeAsync( input, onDone, options = {} ) { + + this.options = Object.assign( { + // default options + binary: false, + trs: false, + onlyVisible: true, + maxTextureSize: Infinity, + animations: [], + includeCustomExtensions: false + }, options ); + + if ( this.options.animations.length > 0 ) { + + // Only TRS properties, and not matrices, may be targeted by animation. + this.options.trs = true; + + } + + await this.processInputAsync( input ); + + await Promise.all( this.pending ); + + const writer = this; + const buffers = writer.buffers; + const json = writer.json; + options = writer.options; + + const extensionsUsed = writer.extensionsUsed; + const extensionsRequired = writer.extensionsRequired; + + // Merge buffers. + const blob = new Blob( buffers, { type: 'application/octet-stream' } ); + + // Declare extensions. + const extensionsUsedList = Object.keys( extensionsUsed ); + const extensionsRequiredList = Object.keys( extensionsRequired ); + + if ( extensionsUsedList.length > 0 ) json.extensionsUsed = extensionsUsedList; + if ( extensionsRequiredList.length > 0 ) json.extensionsRequired = extensionsRequiredList; + + // Update bytelength of the single buffer. + if ( json.buffers && json.buffers.length > 0 ) json.buffers[ 0 ].byteLength = blob.size; + + if ( options.binary === true ) { + + // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification + + const reader = new FileReader(); + reader.readAsArrayBuffer( blob ); + reader.onloadend = function () { + + // Binary chunk. + const binaryChunk = getPaddedArrayBuffer( reader.result ); + const binaryChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) ); + binaryChunkPrefix.setUint32( 0, binaryChunk.byteLength, true ); + binaryChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_BIN, true ); + + // JSON chunk. + const jsonChunk = getPaddedArrayBuffer( stringToArrayBuffer( JSON.stringify( json ) ), 0x20 ); + const jsonChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) ); + jsonChunkPrefix.setUint32( 0, jsonChunk.byteLength, true ); + jsonChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_JSON, true ); + + // GLB header. + const header = new ArrayBuffer( GLB_HEADER_BYTES ); + const headerView = new DataView( header ); + headerView.setUint32( 0, GLB_HEADER_MAGIC, true ); + headerView.setUint32( 4, GLB_VERSION, true ); + const totalByteLength = GLB_HEADER_BYTES + + jsonChunkPrefix.byteLength + jsonChunk.byteLength + + binaryChunkPrefix.byteLength + binaryChunk.byteLength; + headerView.setUint32( 8, totalByteLength, true ); + + const glbBlob = new Blob( [ + header, + jsonChunkPrefix, + jsonChunk, + binaryChunkPrefix, + binaryChunk + ], { type: 'application/octet-stream' } ); + + const glbReader = new FileReader(); + glbReader.readAsArrayBuffer( glbBlob ); + glbReader.onloadend = function () { + + onDone( glbReader.result ); + + }; + + }; + + } else { + + if ( json.buffers && json.buffers.length > 0 ) { + + const reader = new FileReader(); + reader.readAsDataURL( blob ); + reader.onloadend = function () { + + const base64data = reader.result; + json.buffers[ 0 ].uri = base64data; + onDone( json ); + + }; + + } else { + + onDone( json ); + + } + + } + + + } + + /** + * Serializes a userData. + * + * @param {THREE.Object3D|THREE.Material} object + * @param {Object} objectDef + */ + serializeUserData( object, objectDef ) { + + if ( Object.keys( object.userData ).length === 0 ) return; + + const options = this.options; + const extensionsUsed = this.extensionsUsed; + + try { + + const json = JSON.parse( JSON.stringify( object.userData ) ); + + if ( options.includeCustomExtensions && json.gltfExtensions ) { + + if ( objectDef.extensions === undefined ) objectDef.extensions = {}; + + for ( const extensionName in json.gltfExtensions ) { + + objectDef.extensions[ extensionName ] = json.gltfExtensions[ extensionName ]; + extensionsUsed[ extensionName ] = true; + + } + + delete json.gltfExtensions; + + } + + if ( Object.keys( json ).length > 0 ) objectDef.extras = json; + + } catch ( error ) { + + console.warn( 'THREE.GLTFExporter: userData of \'' + object.name + '\' ' + + 'won\'t be serialized because of JSON.stringify error - ' + error.message ); + + } + + } + + /** + * Returns ids for buffer attributes. + * @param {Object} object + * @return {Integer} + */ + getUID( attribute, isRelativeCopy = false ) { + + if ( this.uids.has( attribute ) === false ) { + + const uids = new Map(); + + uids.set( true, this.uid ++ ); + uids.set( false, this.uid ++ ); + + this.uids.set( attribute, uids ); + + } + + const uids = this.uids.get( attribute ); + + return uids.get( isRelativeCopy ); + + } + + /** + * Checks if normal attribute values are normalized. + * + * @param {BufferAttribute} normal + * @returns {Boolean} + */ + isNormalizedNormalAttribute( normal ) { + + const cache = this.cache; + + if ( cache.attributesNormalized.has( normal ) ) return false; + + const v = new Vector3(); + + for ( let i = 0, il = normal.count; i < il; i ++ ) { + + // 0.0005 is from glTF-validator + if ( Math.abs( v.fromBufferAttribute( normal, i ).length() - 1.0 ) > 0.0005 ) return false; + + } + + return true; + + } + + /** + * Creates normalized normal buffer attribute. + * + * @param {BufferAttribute} normal + * @returns {BufferAttribute} + * + */ + createNormalizedNormalAttribute( normal ) { + + const cache = this.cache; + + if ( cache.attributesNormalized.has( normal ) ) return cache.attributesNormalized.get( normal ); + + const attribute = normal.clone(); + const v = new Vector3(); + + for ( let i = 0, il = attribute.count; i < il; i ++ ) { + + v.fromBufferAttribute( attribute, i ); + + if ( v.x === 0 && v.y === 0 && v.z === 0 ) { + + // if values can't be normalized set (1, 0, 0) + v.setX( 1.0 ); + + } else { + + v.normalize(); + + } + + attribute.setXYZ( i, v.x, v.y, v.z ); + + } + + cache.attributesNormalized.set( normal, attribute ); + + return attribute; + + } + + /** + * Applies a texture transform, if present, to the map definition. Requires + * the KHR_texture_transform extension. + * + * @param {Object} mapDef + * @param {THREE.Texture} texture + */ + applyTextureTransform( mapDef, texture ) { + + let didTransform = false; + const transformDef = {}; + + if ( texture.offset.x !== 0 || texture.offset.y !== 0 ) { + + transformDef.offset = texture.offset.toArray(); + didTransform = true; + + } + + if ( texture.rotation !== 0 ) { + + transformDef.rotation = texture.rotation; + didTransform = true; + + } + + if ( texture.repeat.x !== 1 || texture.repeat.y !== 1 ) { + + transformDef.scale = texture.repeat.toArray(); + didTransform = true; + + } + + if ( didTransform ) { + + mapDef.extensions = mapDef.extensions || {}; + mapDef.extensions[ 'KHR_texture_transform' ] = transformDef; + this.extensionsUsed[ 'KHR_texture_transform' ] = true; + + } + + } + + async buildMetalRoughTextureAsync( metalnessMap, roughnessMap ) { + + if ( metalnessMap === roughnessMap ) return metalnessMap; + + function getEncodingConversion( map ) { + + if ( map.colorSpace === SRGBColorSpace ) { + + return function SRGBToLinear( c ) { + + return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 ); + + }; + + } + + return function LinearToLinear( c ) { + + return c; + + }; + + } + + if ( metalnessMap instanceof CompressedTexture ) { + + metalnessMap = await this.decompressTextureAsync( metalnessMap ); + + } + + if ( roughnessMap instanceof CompressedTexture ) { + + roughnessMap = await this.decompressTextureAsync( roughnessMap ); + + } + + const metalness = metalnessMap ? metalnessMap.image : null; + const roughness = roughnessMap ? roughnessMap.image : null; + + const width = Math.max( metalness ? metalness.width : 0, roughness ? roughness.width : 0 ); + const height = Math.max( metalness ? metalness.height : 0, roughness ? roughness.height : 0 ); + + const canvas = getCanvas(); + canvas.width = width; + canvas.height = height; + + const context = canvas.getContext( '2d', { + willReadFrequently: true, + } ); + context.fillStyle = '#00ffff'; + context.fillRect( 0, 0, width, height ); + + const composite = context.getImageData( 0, 0, width, height ); + + if ( metalness ) { + + context.drawImage( metalness, 0, 0, width, height ); + + const convert = getEncodingConversion( metalnessMap ); + const data = context.getImageData( 0, 0, width, height ).data; + + for ( let i = 2; i < data.length; i += 4 ) { + + composite.data[ i ] = convert( data[ i ] / 256 ) * 256; + + } + + } + + if ( roughness ) { + + context.drawImage( roughness, 0, 0, width, height ); + + const convert = getEncodingConversion( roughnessMap ); + const data = context.getImageData( 0, 0, width, height ).data; + + for ( let i = 1; i < data.length; i += 4 ) { + + composite.data[ i ] = convert( data[ i ] / 256 ) * 256; + + } + + } + + context.putImageData( composite, 0, 0 ); + + // + + const reference = metalnessMap || roughnessMap; + + const texture = reference.clone(); + + texture.source = new Source( canvas ); + texture.colorSpace = NoColorSpace; + texture.channel = ( metalnessMap || roughnessMap ).channel; + + if ( metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel ) { + + console.warn( 'THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.' ); + + } + + console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' ); + + return texture; + + } + + + async decompressTextureAsync( texture, maxTextureSize = Infinity ) { + + if ( this.textureUtils === null ) { + + throw new Error( 'THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.' ); + + } + + return await this.textureUtils.decompress( texture, maxTextureSize ); + + } + + /** + * Process a buffer to append to the default one. + * @param {ArrayBuffer} buffer + * @return {Integer} + */ + processBuffer( buffer ) { + + const json = this.json; + const buffers = this.buffers; + + if ( ! json.buffers ) json.buffers = [ { byteLength: 0 } ]; + + // All buffers are merged before export. + buffers.push( buffer ); + + return 0; + + } + + /** + * Process and generate a BufferView + * @param {BufferAttribute} attribute + * @param {number} componentType + * @param {number} start + * @param {number} count + * @param {number} target (Optional) Target usage of the BufferView + * @return {Object} + */ + processBufferView( attribute, componentType, start, count, target ) { + + const json = this.json; + + if ( ! json.bufferViews ) json.bufferViews = []; + + // Create a new dataview and dump the attribute's array into it + + let componentSize; + + switch ( componentType ) { + + case WEBGL_CONSTANTS.BYTE: + case WEBGL_CONSTANTS.UNSIGNED_BYTE: + + componentSize = 1; + + break; + + case WEBGL_CONSTANTS.SHORT: + case WEBGL_CONSTANTS.UNSIGNED_SHORT: + + componentSize = 2; + + break; + + default: + + componentSize = 4; + + } + + let byteStride = attribute.itemSize * componentSize; + + if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) { + + // Each element of a vertex attribute MUST be aligned to 4-byte boundaries + // inside a bufferView + byteStride = Math.ceil( byteStride / 4 ) * 4; + + } + + const byteLength = getPaddedBufferSize( count * byteStride ); + const dataView = new DataView( new ArrayBuffer( byteLength ) ); + let offset = 0; + + for ( let i = start; i < start + count; i ++ ) { + + for ( let a = 0; a < attribute.itemSize; a ++ ) { + + let value; + + if ( attribute.itemSize > 4 ) { + + // no support for interleaved data for itemSize > 4 + + value = attribute.array[ i * attribute.itemSize + a ]; + + } else { + + if ( a === 0 ) value = attribute.getX( i ); + else if ( a === 1 ) value = attribute.getY( i ); + else if ( a === 2 ) value = attribute.getZ( i ); + else if ( a === 3 ) value = attribute.getW( i ); + + if ( attribute.normalized === true ) { + + value = MathUtils.normalize( value, attribute.array ); + + } + + } + + if ( componentType === WEBGL_CONSTANTS.FLOAT ) { + + dataView.setFloat32( offset, value, true ); + + } else if ( componentType === WEBGL_CONSTANTS.INT ) { + + dataView.setInt32( offset, value, true ); + + } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_INT ) { + + dataView.setUint32( offset, value, true ); + + } else if ( componentType === WEBGL_CONSTANTS.SHORT ) { + + dataView.setInt16( offset, value, true ); + + } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ) { + + dataView.setUint16( offset, value, true ); + + } else if ( componentType === WEBGL_CONSTANTS.BYTE ) { + + dataView.setInt8( offset, value ); + + } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE ) { + + dataView.setUint8( offset, value ); + + } + + offset += componentSize; + + } + + if ( ( offset % byteStride ) !== 0 ) { + + offset += byteStride - ( offset % byteStride ); + + } + + } + + const bufferViewDef = { + + buffer: this.processBuffer( dataView.buffer ), + byteOffset: this.byteOffset, + byteLength: byteLength + + }; + + if ( target !== undefined ) bufferViewDef.target = target; + + if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) { + + // Only define byteStride for vertex attributes. + bufferViewDef.byteStride = byteStride; + + } + + this.byteOffset += byteLength; + + json.bufferViews.push( bufferViewDef ); + + // @TODO Merge bufferViews where possible. + const output = { + + id: json.bufferViews.length - 1, + byteLength: 0 + + }; + + return output; + + } + + /** + * Process and generate a BufferView from an image Blob. + * @param {Blob} blob + * @return {Promise} + */ + processBufferViewImage( blob ) { + + const writer = this; + const json = writer.json; + + if ( ! json.bufferViews ) json.bufferViews = []; + + return new Promise( function ( resolve ) { + + const reader = new FileReader(); + reader.readAsArrayBuffer( blob ); + reader.onloadend = function () { + + const buffer = getPaddedArrayBuffer( reader.result ); + + const bufferViewDef = { + buffer: writer.processBuffer( buffer ), + byteOffset: writer.byteOffset, + byteLength: buffer.byteLength + }; + + writer.byteOffset += buffer.byteLength; + resolve( json.bufferViews.push( bufferViewDef ) - 1 ); + + }; + + } ); + + } + + /** + * Process attribute to generate an accessor + * @param {BufferAttribute} attribute Attribute to process + * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range + * @param {Integer} start (Optional) + * @param {Integer} count (Optional) + * @return {Integer|null} Index of the processed accessor on the "accessors" array + */ + processAccessor( attribute, geometry, start, count ) { + + const json = this.json; + + const types = { + + 1: 'SCALAR', + 2: 'VEC2', + 3: 'VEC3', + 4: 'VEC4', + 9: 'MAT3', + 16: 'MAT4' + + }; + + let componentType; + + // Detect the component type of the attribute array + if ( attribute.array.constructor === Float32Array ) { + + componentType = WEBGL_CONSTANTS.FLOAT; + + } else if ( attribute.array.constructor === Int32Array ) { + + componentType = WEBGL_CONSTANTS.INT; + + } else if ( attribute.array.constructor === Uint32Array ) { + + componentType = WEBGL_CONSTANTS.UNSIGNED_INT; + + } else if ( attribute.array.constructor === Int16Array ) { + + componentType = WEBGL_CONSTANTS.SHORT; + + } else if ( attribute.array.constructor === Uint16Array ) { + + componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT; + + } else if ( attribute.array.constructor === Int8Array ) { + + componentType = WEBGL_CONSTANTS.BYTE; + + } else if ( attribute.array.constructor === Uint8Array ) { + + componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE; + + } else { + + throw new Error( 'THREE.GLTFExporter: Unsupported bufferAttribute component type: ' + attribute.array.constructor.name ); + + } + + if ( start === undefined ) start = 0; + if ( count === undefined || count === Infinity ) count = attribute.count; + + // Skip creating an accessor if the attribute doesn't have data to export + if ( count === 0 ) return null; + + const minMax = getMinMax( attribute, start, count ); + let bufferViewTarget; + + // If geometry isn't provided, don't infer the target usage of the bufferView. For + // animation samplers, target must not be set. + if ( geometry !== undefined ) { + + bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER; + + } + + const bufferView = this.processBufferView( attribute, componentType, start, count, bufferViewTarget ); + + const accessorDef = { + + bufferView: bufferView.id, + byteOffset: bufferView.byteOffset, + componentType: componentType, + count: count, + max: minMax.max, + min: minMax.min, + type: types[ attribute.itemSize ] + + }; + + if ( attribute.normalized === true ) accessorDef.normalized = true; + if ( ! json.accessors ) json.accessors = []; + + return json.accessors.push( accessorDef ) - 1; + + } + + /** + * Process image + * @param {Image} image to process + * @param {Integer} format of the image (RGBAFormat) + * @param {Boolean} flipY before writing out the image + * @param {String} mimeType export format + * @return {Integer} Index of the processed texture in the "images" array + */ + processImage( image, format, flipY, mimeType = 'image/png' ) { + + if ( image !== null ) { + + const writer = this; + const cache = writer.cache; + const json = writer.json; + const options = writer.options; + const pending = writer.pending; + + if ( ! cache.images.has( image ) ) cache.images.set( image, {} ); + + const cachedImages = cache.images.get( image ); + + const key = mimeType + ':flipY/' + flipY.toString(); + + if ( cachedImages[ key ] !== undefined ) return cachedImages[ key ]; + + if ( ! json.images ) json.images = []; + + const imageDef = { mimeType: mimeType }; + + const canvas = getCanvas(); + + canvas.width = Math.min( image.width, options.maxTextureSize ); + canvas.height = Math.min( image.height, options.maxTextureSize ); + + const ctx = canvas.getContext( '2d', { + willReadFrequently: true, + } ); + + if ( flipY === true ) { + + ctx.translate( 0, canvas.height ); + ctx.scale( 1, - 1 ); + + } + + if ( image.data !== undefined ) { // THREE.DataTexture + + if ( format !== RGBAFormat ) { + + console.error( 'GLTFExporter: Only RGBAFormat is supported.', format ); + + } + + if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) { + + console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image ); + + } + + const data = new Uint8ClampedArray( image.height * image.width * 4 ); + + for ( let i = 0; i < data.length; i += 4 ) { + + data[ i + 0 ] = image.data[ i + 0 ]; + data[ i + 1 ] = image.data[ i + 1 ]; + data[ i + 2 ] = image.data[ i + 2 ]; + data[ i + 3 ] = image.data[ i + 3 ]; + + } + + ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 ); + + } else { + + if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || + ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) || + ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) || + ( typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas ) ) { + + ctx.drawImage( image, 0, 0, canvas.width, canvas.height ); + + } else { + + throw new Error( 'THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.' ); + + } + + } + + if ( options.binary === true ) { + + pending.push( + + getToBlobPromise( canvas, mimeType ) + .then( blob => writer.processBufferViewImage( blob ) ) + .then( bufferViewIndex => { + + imageDef.bufferView = bufferViewIndex; + + } ) + + ); + + } else { + + if ( canvas.toDataURL !== undefined ) { + + imageDef.uri = canvas.toDataURL( mimeType ); + + } else { + + pending.push( + + getToBlobPromise( canvas, mimeType ) + .then( blob => new FileReader().readAsDataURL( blob ) ) + .then( dataURL => { + + imageDef.uri = dataURL; + + } ) + + ); + + } + + } + + const index = json.images.push( imageDef ) - 1; + cachedImages[ key ] = index; + return index; + + } else { + + throw new Error( 'THREE.GLTFExporter: No valid image data found. Unable to process texture.' ); + + } + + } + + /** + * Process sampler + * @param {Texture} map Texture to process + * @return {Integer} Index of the processed texture in the "samplers" array + */ + processSampler( map ) { + + const json = this.json; + + if ( ! json.samplers ) json.samplers = []; + + const samplerDef = { + magFilter: THREE_TO_WEBGL[ map.magFilter ], + minFilter: THREE_TO_WEBGL[ map.minFilter ], + wrapS: THREE_TO_WEBGL[ map.wrapS ], + wrapT: THREE_TO_WEBGL[ map.wrapT ] + }; + + return json.samplers.push( samplerDef ) - 1; + + } + + /** + * Process texture + * @param {Texture} map Map to process + * @return {Integer} Index of the processed texture in the "textures" array + */ + async processTextureAsync( map ) { + + const writer = this; + const options = writer.options; + const cache = this.cache; + const json = this.json; + + if ( cache.textures.has( map ) ) return cache.textures.get( map ); + + if ( ! json.textures ) json.textures = []; + + // make non-readable textures (e.g. CompressedTexture) readable by blitting them into a new texture + if ( map instanceof CompressedTexture ) { + + map = await this.decompressTextureAsync( map, options.maxTextureSize ); + + } + + let mimeType = map.userData.mimeType; + + if ( mimeType === 'image/webp' ) mimeType = 'image/png'; + + const textureDef = { + sampler: this.processSampler( map ), + source: this.processImage( map.image, map.format, map.flipY, mimeType ) + }; + + if ( map.name ) textureDef.name = map.name; + + await this._invokeAllAsync( async function ( ext ) { + + ext.writeTexture && await ext.writeTexture( map, textureDef ); + + } ); + + const index = json.textures.push( textureDef ) - 1; + cache.textures.set( map, index ); + return index; + + } + + /** + * Process material + * @param {THREE.Material} material Material to process + * @return {Integer|null} Index of the processed material in the "materials" array + */ + async processMaterialAsync( material ) { + + const cache = this.cache; + const json = this.json; + + if ( cache.materials.has( material ) ) return cache.materials.get( material ); + + if ( material.isShaderMaterial ) { + + console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' ); + return null; + + } + + if ( ! json.materials ) json.materials = []; + + // @QUESTION Should we avoid including any attribute that has the default value? + const materialDef = { pbrMetallicRoughness: {} }; + + if ( material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true ) { + + console.warn( 'GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.' ); + + } + + // pbrMetallicRoughness.baseColorFactor + const color = material.color.toArray().concat( [ material.opacity ] ); + + if ( ! equalArray( color, [ 1, 1, 1, 1 ] ) ) { + + materialDef.pbrMetallicRoughness.baseColorFactor = color; + + } + + if ( material.isMeshStandardMaterial ) { + + materialDef.pbrMetallicRoughness.metallicFactor = material.metalness; + materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness; + + } else { + + materialDef.pbrMetallicRoughness.metallicFactor = 0; + materialDef.pbrMetallicRoughness.roughnessFactor = 1; + + } + + // pbrMetallicRoughness.metallicRoughnessTexture + if ( material.metalnessMap || material.roughnessMap ) { + + const metalRoughTexture = await this.buildMetalRoughTextureAsync( material.metalnessMap, material.roughnessMap ); + + const metalRoughMapDef = { + index: await this.processTextureAsync( metalRoughTexture ), + texCoord: metalRoughTexture.channel + }; + this.applyTextureTransform( metalRoughMapDef, metalRoughTexture ); + materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef; + + } + + // pbrMetallicRoughness.baseColorTexture + if ( material.map ) { + + const baseColorMapDef = { + index: await this.processTextureAsync( material.map ), + texCoord: material.map.channel + }; + this.applyTextureTransform( baseColorMapDef, material.map ); + materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef; + + } + + if ( material.emissive ) { + + const emissive = material.emissive; + const maxEmissiveComponent = Math.max( emissive.r, emissive.g, emissive.b ); + + if ( maxEmissiveComponent > 0 ) { + + materialDef.emissiveFactor = material.emissive.toArray(); + + } + + // emissiveTexture + if ( material.emissiveMap ) { + + const emissiveMapDef = { + index: await this.processTextureAsync( material.emissiveMap ), + texCoord: material.emissiveMap.channel + }; + this.applyTextureTransform( emissiveMapDef, material.emissiveMap ); + materialDef.emissiveTexture = emissiveMapDef; + + } + + } + + // normalTexture + if ( material.normalMap ) { + + const normalMapDef = { + index: await this.processTextureAsync( material.normalMap ), + texCoord: material.normalMap.channel + }; + + if ( material.normalScale && material.normalScale.x !== 1 ) { + + // glTF normal scale is univariate. Ignore `y`, which may be flipped. + // Context: https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995 + normalMapDef.scale = material.normalScale.x; + + } + + this.applyTextureTransform( normalMapDef, material.normalMap ); + materialDef.normalTexture = normalMapDef; + + } + + // occlusionTexture + if ( material.aoMap ) { + + const occlusionMapDef = { + index: await this.processTextureAsync( material.aoMap ), + texCoord: material.aoMap.channel + }; + + if ( material.aoMapIntensity !== 1.0 ) { + + occlusionMapDef.strength = material.aoMapIntensity; + + } + + this.applyTextureTransform( occlusionMapDef, material.aoMap ); + materialDef.occlusionTexture = occlusionMapDef; + + } + + // alphaMode + if ( material.transparent ) { + + materialDef.alphaMode = 'BLEND'; + + } else { + + if ( material.alphaTest > 0.0 ) { + + materialDef.alphaMode = 'MASK'; + materialDef.alphaCutoff = material.alphaTest; + + } + + } + + // doubleSided + if ( material.side === DoubleSide ) materialDef.doubleSided = true; + if ( material.name !== '' ) materialDef.name = material.name; + + this.serializeUserData( material, materialDef ); + + await this._invokeAllAsync( async function ( ext ) { + + ext.writeMaterialAsync && await ext.writeMaterialAsync( material, materialDef ); + + } ); + + const index = json.materials.push( materialDef ) - 1; + cache.materials.set( material, index ); + return index; + + } + + /** + * Process mesh + * @param {THREE.Mesh} mesh Mesh to process + * @return {Integer|null} Index of the processed mesh in the "meshes" array + */ + async processMeshAsync( mesh ) { + + const cache = this.cache; + const json = this.json; + + const meshCacheKeyParts = [ mesh.geometry.uuid ]; + + if ( Array.isArray( mesh.material ) ) { + + for ( let i = 0, l = mesh.material.length; i < l; i ++ ) { + + meshCacheKeyParts.push( mesh.material[ i ].uuid ); + + } + + } else { + + meshCacheKeyParts.push( mesh.material.uuid ); + + } + + const meshCacheKey = meshCacheKeyParts.join( ':' ); + + if ( cache.meshes.has( meshCacheKey ) ) return cache.meshes.get( meshCacheKey ); + + const geometry = mesh.geometry; + + let mode; + + // Use the correct mode + if ( mesh.isLineSegments ) { + + mode = WEBGL_CONSTANTS.LINES; + + } else if ( mesh.isLineLoop ) { + + mode = WEBGL_CONSTANTS.LINE_LOOP; + + } else if ( mesh.isLine ) { + + mode = WEBGL_CONSTANTS.LINE_STRIP; + + } else if ( mesh.isPoints ) { + + mode = WEBGL_CONSTANTS.POINTS; + + } else { + + mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES; + + } + + const meshDef = {}; + const attributes = {}; + const primitives = []; + const targets = []; + + // Conversion between attributes names in threejs and gltf spec + const nameConversion = { + uv: 'TEXCOORD_0', + uv1: 'TEXCOORD_1', + uv2: 'TEXCOORD_2', + uv3: 'TEXCOORD_3', + color: 'COLOR_0', + skinWeight: 'WEIGHTS_0', + skinIndex: 'JOINTS_0' + }; + + const originalNormal = geometry.getAttribute( 'normal' ); + + if ( originalNormal !== undefined && ! this.isNormalizedNormalAttribute( originalNormal ) ) { + + console.warn( 'THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.' ); + + geometry.setAttribute( 'normal', this.createNormalizedNormalAttribute( originalNormal ) ); + + } + + // @QUESTION Detect if .vertexColors = true? + // For every attribute create an accessor + let modifiedAttribute = null; + + for ( let attributeName in geometry.attributes ) { + + // Ignore morph target attributes, which are exported later. + if ( attributeName.slice( 0, 5 ) === 'morph' ) continue; + + const attribute = geometry.attributes[ attributeName ]; + attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase(); + + // Prefix all geometry attributes except the ones specifically + // listed in the spec; non-spec attributes are considered custom. + const validVertexAttributes = + /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/; + + if ( ! validVertexAttributes.test( attributeName ) ) attributeName = '_' + attributeName; + + if ( cache.attributes.has( this.getUID( attribute ) ) ) { + + attributes[ attributeName ] = cache.attributes.get( this.getUID( attribute ) ); + continue; + + } + + // Enforce glTF vertex attribute requirements: + // - JOINTS_0 must be UNSIGNED_BYTE or UNSIGNED_SHORT + // - Only custom attributes may be INT or UNSIGNED_INT + modifiedAttribute = null; + const array = attribute.array; + + if ( attributeName === 'JOINTS_0' && + ! ( array instanceof Uint16Array ) && + ! ( array instanceof Uint8Array ) ) { + + console.warn( 'GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.' ); + modifiedAttribute = new BufferAttribute( new Uint16Array( array ), attribute.itemSize, attribute.normalized ); + + } else if ( ( array instanceof Uint32Array || array instanceof Int32Array ) && ! attributeName.startsWith( '_' ) ) { + + console.warn( `GLTFExporter: Attribute "${ attributeName }" converted to type FLOAT.` ); + modifiedAttribute = GLTFExporter.Utils.toFloat32BufferAttribute( attribute ); + + } + + const accessor = this.processAccessor( modifiedAttribute || attribute, geometry ); + + if ( accessor !== null ) { + + if ( ! attributeName.startsWith( '_' ) ) { + + this.detectMeshQuantization( attributeName, attribute ); + + } + + attributes[ attributeName ] = accessor; + cache.attributes.set( this.getUID( attribute ), accessor ); + + } + + } + + if ( originalNormal !== undefined ) geometry.setAttribute( 'normal', originalNormal ); + + // Skip if no exportable attributes found + if ( Object.keys( attributes ).length === 0 ) return null; + + // Morph targets + if ( mesh.morphTargetInfluences !== undefined && mesh.morphTargetInfluences.length > 0 ) { + + const weights = []; + const targetNames = []; + const reverseDictionary = {}; + + if ( mesh.morphTargetDictionary !== undefined ) { + + for ( const key in mesh.morphTargetDictionary ) { + + reverseDictionary[ mesh.morphTargetDictionary[ key ] ] = key; + + } + + } + + for ( let i = 0; i < mesh.morphTargetInfluences.length; ++ i ) { + + const target = {}; + let warned = false; + + for ( const attributeName in geometry.morphAttributes ) { + + // glTF 2.0 morph supports only POSITION/NORMAL/TANGENT. + // Three.js doesn't support TANGENT yet. + + if ( attributeName !== 'position' && attributeName !== 'normal' ) { + + if ( ! warned ) { + + console.warn( 'GLTFExporter: Only POSITION and NORMAL morph are supported.' ); + warned = true; + + } + + continue; + + } + + const attribute = geometry.morphAttributes[ attributeName ][ i ]; + const gltfAttributeName = attributeName.toUpperCase(); + + // Three.js morph attribute has absolute values while the one of glTF has relative values. + // + // glTF 2.0 Specification: + // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#morph-targets + + const baseAttribute = geometry.attributes[ attributeName ]; + + if ( cache.attributes.has( this.getUID( attribute, true ) ) ) { + + target[ gltfAttributeName ] = cache.attributes.get( this.getUID( attribute, true ) ); + continue; + + } + + // Clones attribute not to override + const relativeAttribute = attribute.clone(); + + if ( ! geometry.morphTargetsRelative ) { + + for ( let j = 0, jl = attribute.count; j < jl; j ++ ) { + + for ( let a = 0; a < attribute.itemSize; a ++ ) { + + if ( a === 0 ) relativeAttribute.setX( j, attribute.getX( j ) - baseAttribute.getX( j ) ); + if ( a === 1 ) relativeAttribute.setY( j, attribute.getY( j ) - baseAttribute.getY( j ) ); + if ( a === 2 ) relativeAttribute.setZ( j, attribute.getZ( j ) - baseAttribute.getZ( j ) ); + if ( a === 3 ) relativeAttribute.setW( j, attribute.getW( j ) - baseAttribute.getW( j ) ); + + } + + } + + } + + target[ gltfAttributeName ] = this.processAccessor( relativeAttribute, geometry ); + cache.attributes.set( this.getUID( baseAttribute, true ), target[ gltfAttributeName ] ); + + } + + targets.push( target ); + + weights.push( mesh.morphTargetInfluences[ i ] ); + + if ( mesh.morphTargetDictionary !== undefined ) targetNames.push( reverseDictionary[ i ] ); + + } + + meshDef.weights = weights; + + if ( targetNames.length > 0 ) { + + meshDef.extras = {}; + meshDef.extras.targetNames = targetNames; + + } + + } + + const isMultiMaterial = Array.isArray( mesh.material ); + + if ( isMultiMaterial && geometry.groups.length === 0 ) return null; + + let didForceIndices = false; + + if ( isMultiMaterial && geometry.index === null ) { + + const indices = []; + + for ( let i = 0, il = geometry.attributes.position.count; i < il; i ++ ) { + + indices[ i ] = i; + + } + + geometry.setIndex( indices ); + + didForceIndices = true; + + } + + const materials = isMultiMaterial ? mesh.material : [ mesh.material ]; + const groups = isMultiMaterial ? geometry.groups : [ { materialIndex: 0, start: undefined, count: undefined } ]; + + for ( let i = 0, il = groups.length; i < il; i ++ ) { + + const primitive = { + mode: mode, + attributes: attributes, + }; + + this.serializeUserData( geometry, primitive ); + + if ( targets.length > 0 ) primitive.targets = targets; + + if ( geometry.index !== null ) { + + let cacheKey = this.getUID( geometry.index ); + + if ( groups[ i ].start !== undefined || groups[ i ].count !== undefined ) { + + cacheKey += ':' + groups[ i ].start + ':' + groups[ i ].count; + + } + + if ( cache.attributes.has( cacheKey ) ) { + + primitive.indices = cache.attributes.get( cacheKey ); + + } else { + + primitive.indices = this.processAccessor( geometry.index, geometry, groups[ i ].start, groups[ i ].count ); + cache.attributes.set( cacheKey, primitive.indices ); + + } + + if ( primitive.indices === null ) delete primitive.indices; + + } + + const material = await this.processMaterialAsync( materials[ groups[ i ].materialIndex ] ); + + if ( material !== null ) primitive.material = material; + + primitives.push( primitive ); + + } + + if ( didForceIndices === true ) { + + geometry.setIndex( null ); + + } + + meshDef.primitives = primitives; + + if ( ! json.meshes ) json.meshes = []; + + await this._invokeAllAsync( function ( ext ) { + + ext.writeMesh && ext.writeMesh( mesh, meshDef ); + + } ); + + const index = json.meshes.push( meshDef ) - 1; + cache.meshes.set( meshCacheKey, index ); + return index; + + } + + /** + * If a vertex attribute with a + * [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview) + * is used, it is checked whether it is a valid data type according to the + * [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md) + * extension. + * In this case the extension is automatically added to the list of used extensions. + * + * @param {string} attributeName + * @param {THREE.BufferAttribute} attribute + */ + detectMeshQuantization( attributeName, attribute ) { + + if ( this.extensionsUsed[ KHR_MESH_QUANTIZATION ] ) return; + + let attrType = undefined; + + switch ( attribute.array.constructor ) { + + case Int8Array: + + attrType = 'byte'; + + break; + + case Uint8Array: + + attrType = 'unsigned byte'; + + break; + + case Int16Array: + + attrType = 'short'; + + break; + + case Uint16Array: + + attrType = 'unsigned short'; + + break; + + default: + + return; + + } + + if ( attribute.normalized ) attrType += ' normalized'; + + const attrNamePrefix = attributeName.split( '_', 1 )[ 0 ]; + + if ( KHR_mesh_quantization_ExtraAttrTypes[ attrNamePrefix ] && KHR_mesh_quantization_ExtraAttrTypes[ attrNamePrefix ].includes( attrType ) ) { + + this.extensionsUsed[ KHR_MESH_QUANTIZATION ] = true; + this.extensionsRequired[ KHR_MESH_QUANTIZATION ] = true; + + } + + } + + /** + * Process camera + * @param {THREE.Camera} camera Camera to process + * @return {Integer} Index of the processed mesh in the "camera" array + */ + processCamera( camera ) { + + const json = this.json; + + if ( ! json.cameras ) json.cameras = []; + + const isOrtho = camera.isOrthographicCamera; + + const cameraDef = { + type: isOrtho ? 'orthographic' : 'perspective' + }; + + if ( isOrtho ) { + + cameraDef.orthographic = { + xmag: camera.right * 2, + ymag: camera.top * 2, + zfar: camera.far <= 0 ? 0.001 : camera.far, + znear: camera.near < 0 ? 0 : camera.near + }; + + } else { + + cameraDef.perspective = { + aspectRatio: camera.aspect, + yfov: MathUtils.degToRad( camera.fov ), + zfar: camera.far <= 0 ? 0.001 : camera.far, + znear: camera.near < 0 ? 0 : camera.near + }; + + } + + // Question: Is saving "type" as name intentional? + if ( camera.name !== '' ) cameraDef.name = camera.type; + + return json.cameras.push( cameraDef ) - 1; + + } + + /** + * Creates glTF animation entry from AnimationClip object. + * + * Status: + * - Only properties listed in PATH_PROPERTIES may be animated. + * + * @param {THREE.AnimationClip} clip + * @param {THREE.Object3D} root + * @return {number|null} + */ + processAnimation( clip, root ) { + + const json = this.json; + const nodeMap = this.nodeMap; + + if ( ! json.animations ) json.animations = []; + + clip = GLTFExporter.Utils.mergeMorphTargetTracks( clip.clone(), root ); + + const tracks = clip.tracks; + const channels = []; + const samplers = []; + + for ( let i = 0; i < tracks.length; ++ i ) { + + const track = tracks[ i ]; + const trackBinding = PropertyBinding.parseTrackName( track.name ); + let trackNode = PropertyBinding.findNode( root, trackBinding.nodeName ); + const trackProperty = PATH_PROPERTIES[ trackBinding.propertyName ]; + + if ( trackBinding.objectName === 'bones' ) { + + if ( trackNode.isSkinnedMesh === true ) { + + trackNode = trackNode.skeleton.getBoneByName( trackBinding.objectIndex ); + + } else { + + trackNode = undefined; + + } + + } + + if ( ! trackNode || ! trackProperty ) { + + console.warn( 'THREE.GLTFExporter: Could not export animation track "%s".', track.name ); + continue; + + } + + const inputItemSize = 1; + let outputItemSize = track.values.length / track.times.length; + + if ( trackProperty === PATH_PROPERTIES.morphTargetInfluences ) { + + outputItemSize /= trackNode.morphTargetInfluences.length; + + } + + let interpolation; + + // @TODO export CubicInterpolant(InterpolateSmooth) as CUBICSPLINE + + // Detecting glTF cubic spline interpolant by checking factory method's special property + // GLTFCubicSplineInterpolant is a custom interpolant and track doesn't return + // valid value from .getInterpolation(). + if ( track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true ) { + + interpolation = 'CUBICSPLINE'; + + // itemSize of CUBICSPLINE keyframe is 9 + // (VEC3 * 3: inTangent, splineVertex, and outTangent) + // but needs to be stored as VEC3 so dividing by 3 here. + outputItemSize /= 3; + + } else if ( track.getInterpolation() === InterpolateDiscrete ) { + + interpolation = 'STEP'; + + } else { + + interpolation = 'LINEAR'; + + } + + samplers.push( { + input: this.processAccessor( new BufferAttribute( track.times, inputItemSize ) ), + output: this.processAccessor( new BufferAttribute( track.values, outputItemSize ) ), + interpolation: interpolation + } ); + + channels.push( { + sampler: samplers.length - 1, + target: { + node: nodeMap.get( trackNode ), + path: trackProperty + } + } ); + + } + + json.animations.push( { + name: clip.name || 'clip_' + json.animations.length, + samplers: samplers, + channels: channels + } ); + + return json.animations.length - 1; + + } + + /** + * @param {THREE.Object3D} object + * @return {number|null} + */ + processSkin( object ) { + + const json = this.json; + const nodeMap = this.nodeMap; + + const node = json.nodes[ nodeMap.get( object ) ]; + + const skeleton = object.skeleton; + + if ( skeleton === undefined ) return null; + + const rootJoint = object.skeleton.bones[ 0 ]; + + if ( rootJoint === undefined ) return null; + + const joints = []; + const inverseBindMatrices = new Float32Array( skeleton.bones.length * 16 ); + const temporaryBoneInverse = new Matrix4(); + + for ( let i = 0; i < skeleton.bones.length; ++ i ) { + + joints.push( nodeMap.get( skeleton.bones[ i ] ) ); + temporaryBoneInverse.copy( skeleton.boneInverses[ i ] ); + temporaryBoneInverse.multiply( object.bindMatrix ).toArray( inverseBindMatrices, i * 16 ); + + } + + if ( json.skins === undefined ) json.skins = []; + + json.skins.push( { + inverseBindMatrices: this.processAccessor( new BufferAttribute( inverseBindMatrices, 16 ) ), + joints: joints, + skeleton: nodeMap.get( rootJoint ) + } ); + + const skinIndex = node.skin = json.skins.length - 1; + + return skinIndex; + + } + + /** + * Process Object3D node + * @param {THREE.Object3D} node Object3D to processNodeAsync + * @return {Integer} Index of the node in the nodes list + */ + async processNodeAsync( object ) { + + const json = this.json; + const options = this.options; + const nodeMap = this.nodeMap; + + if ( ! json.nodes ) json.nodes = []; + + const nodeDef = {}; + + if ( options.trs ) { + + const rotation = object.quaternion.toArray(); + const position = object.position.toArray(); + const scale = object.scale.toArray(); + + if ( ! equalArray( rotation, [ 0, 0, 0, 1 ] ) ) { + + nodeDef.rotation = rotation; + + } + + if ( ! equalArray( position, [ 0, 0, 0 ] ) ) { + + nodeDef.translation = position; + + } + + if ( ! equalArray( scale, [ 1, 1, 1 ] ) ) { + + nodeDef.scale = scale; + + } + + } else { + + if ( object.matrixAutoUpdate ) { + + object.updateMatrix(); + + } + + if ( isIdentityMatrix( object.matrix ) === false ) { + + nodeDef.matrix = object.matrix.elements; + + } + + } + + // We don't export empty strings name because it represents no-name in Three.js. + if ( object.name !== '' ) nodeDef.name = String( object.name ); + + this.serializeUserData( object, nodeDef ); + + if ( object.isMesh || object.isLine || object.isPoints ) { + + const meshIndex = await this.processMeshAsync( object ); + + if ( meshIndex !== null ) nodeDef.mesh = meshIndex; + + } else if ( object.isCamera ) { + + nodeDef.camera = this.processCamera( object ); + + } + + if ( object.isSkinnedMesh ) this.skins.push( object ); + + if ( object.children.length > 0 ) { + + const children = []; + + for ( let i = 0, l = object.children.length; i < l; i ++ ) { + + const child = object.children[ i ]; + + if ( child.visible || options.onlyVisible === false ) { + + const nodeIndex = await this.processNodeAsync( child ); + + if ( nodeIndex !== null ) children.push( nodeIndex ); + + } + + } + + if ( children.length > 0 ) nodeDef.children = children; + + } + + await this._invokeAllAsync( function ( ext ) { + + ext.writeNode && ext.writeNode( object, nodeDef ); + + } ); + + const nodeIndex = json.nodes.push( nodeDef ) - 1; + nodeMap.set( object, nodeIndex ); + return nodeIndex; + + } + + /** + * Process Scene + * @param {Scene} node Scene to process + */ + async processSceneAsync( scene ) { + + const json = this.json; + const options = this.options; + + if ( ! json.scenes ) { + + json.scenes = []; + json.scene = 0; + + } + + const sceneDef = {}; + + if ( scene.name !== '' ) sceneDef.name = scene.name; + + json.scenes.push( sceneDef ); + + const nodes = []; + + for ( let i = 0, l = scene.children.length; i < l; i ++ ) { + + const child = scene.children[ i ]; + + if ( child.visible || options.onlyVisible === false ) { + + const nodeIndex = await this.processNodeAsync( child ); + + if ( nodeIndex !== null ) nodes.push( nodeIndex ); + + } + + } + + if ( nodes.length > 0 ) sceneDef.nodes = nodes; + + this.serializeUserData( scene, sceneDef ); + + } + + /** + * Creates a Scene to hold a list of objects and parse it + * @param {Array} objects List of objects to process + */ + async processObjectsAsync( objects ) { + + const scene = new Scene(); + scene.name = 'AuxScene'; + + for ( let i = 0; i < objects.length; i ++ ) { + + // We push directly to children instead of calling `add` to prevent + // modify the .parent and break its original scene and hierarchy + scene.children.push( objects[ i ] ); + + } + + await this.processSceneAsync( scene ); + + } + + /** + * @param {THREE.Object3D|Array} input + */ + async processInputAsync( input ) { + + const options = this.options; + + input = input instanceof Array ? input : [ input ]; + + await this._invokeAllAsync( function ( ext ) { + + ext.beforeParse && ext.beforeParse( input ); + + } ); + + const objectsWithoutScene = []; + + for ( let i = 0; i < input.length; i ++ ) { + + if ( input[ i ] instanceof Scene ) { + + await this.processSceneAsync( input[ i ] ); + + } else { + + objectsWithoutScene.push( input[ i ] ); + + } + + } + + if ( objectsWithoutScene.length > 0 ) { + + await this.processObjectsAsync( objectsWithoutScene ); + + } + + for ( let i = 0; i < this.skins.length; ++ i ) { + + this.processSkin( this.skins[ i ] ); + + } + + for ( let i = 0; i < options.animations.length; ++ i ) { + + this.processAnimation( options.animations[ i ], input[ 0 ] ); + + } + + await this._invokeAllAsync( function ( ext ) { + + ext.afterParse && ext.afterParse( input ); + + } ); + + } + + async _invokeAllAsync( func ) { + + for ( let i = 0, il = this.plugins.length; i < il; i ++ ) { + + await func( this.plugins[ i ] ); + + } + + } + +} + +/** + * Punctual Lights Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual + */ +class GLTFLightExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_lights_punctual'; + + } + + writeNode( light, nodeDef ) { + + if ( ! light.isLight ) return; + + if ( ! light.isDirectionalLight && ! light.isPointLight && ! light.isSpotLight ) { + + console.warn( 'THREE.GLTFExporter: Only directional, point, and spot lights are supported.', light ); + return; + + } + + const writer = this.writer; + const json = writer.json; + const extensionsUsed = writer.extensionsUsed; + + const lightDef = {}; + + if ( light.name ) lightDef.name = light.name; + + lightDef.color = light.color.toArray(); + + lightDef.intensity = light.intensity; + + if ( light.isDirectionalLight ) { + + lightDef.type = 'directional'; + + } else if ( light.isPointLight ) { + + lightDef.type = 'point'; + + if ( light.distance > 0 ) lightDef.range = light.distance; + + } else if ( light.isSpotLight ) { + + lightDef.type = 'spot'; + + if ( light.distance > 0 ) lightDef.range = light.distance; + + lightDef.spot = {}; + lightDef.spot.innerConeAngle = ( 1.0 - light.penumbra ) * light.angle; + lightDef.spot.outerConeAngle = light.angle; + + } + + if ( light.decay !== undefined && light.decay !== 2 ) { + + console.warn( 'THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, ' + + 'and expects light.decay=2.' ); + + } + + if ( light.target + && ( light.target.parent !== light + || light.target.position.x !== 0 + || light.target.position.y !== 0 + || light.target.position.z !== - 1 ) ) { + + console.warn( 'THREE.GLTFExporter: Light direction may be lost. For best results, ' + + 'make light.target a child of the light with position 0,0,-1.' ); + + } + + if ( ! extensionsUsed[ this.name ] ) { + + json.extensions = json.extensions || {}; + json.extensions[ this.name ] = { lights: [] }; + extensionsUsed[ this.name ] = true; + + } + + const lights = json.extensions[ this.name ].lights; + lights.push( lightDef ); + + nodeDef.extensions = nodeDef.extensions || {}; + nodeDef.extensions[ this.name ] = { light: lights.length - 1 }; + + } + +} + +/** + * Unlit Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit + */ +class GLTFMaterialsUnlitExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_unlit'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshBasicMaterial ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = {}; + + extensionsUsed[ this.name ] = true; + + materialDef.pbrMetallicRoughness.metallicFactor = 0.0; + materialDef.pbrMetallicRoughness.roughnessFactor = 0.9; + + } + +} + +/** + * Clearcoat Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat + */ +class GLTFMaterialsClearcoatExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_clearcoat'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.clearcoat === 0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.clearcoatFactor = material.clearcoat; + + if ( material.clearcoatMap ) { + + const clearcoatMapDef = { + index: await writer.processTextureAsync( material.clearcoatMap ), + texCoord: material.clearcoatMap.channel + }; + writer.applyTextureTransform( clearcoatMapDef, material.clearcoatMap ); + extensionDef.clearcoatTexture = clearcoatMapDef; + + } + + extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness; + + if ( material.clearcoatRoughnessMap ) { + + const clearcoatRoughnessMapDef = { + index: await writer.processTextureAsync( material.clearcoatRoughnessMap ), + texCoord: material.clearcoatRoughnessMap.channel + }; + writer.applyTextureTransform( clearcoatRoughnessMapDef, material.clearcoatRoughnessMap ); + extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef; + + } + + if ( material.clearcoatNormalMap ) { + + const clearcoatNormalMapDef = { + index: await writer.processTextureAsync( material.clearcoatNormalMap ), + texCoord: material.clearcoatNormalMap.channel + }; + + if ( material.clearcoatNormalScale.x !== 1 ) clearcoatNormalMapDef.scale = material.clearcoatNormalScale.x; + + writer.applyTextureTransform( clearcoatNormalMapDef, material.clearcoatNormalMap ); + extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef; + + } + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + + } + +} + +/** + * Materials dispersion Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_dispersion + */ +class GLTFMaterialsDispersionExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_dispersion'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.dispersion === 0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.dispersion = material.dispersion; + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Iridescence Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence + */ +class GLTFMaterialsIridescenceExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_iridescence'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.iridescence === 0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.iridescenceFactor = material.iridescence; + + if ( material.iridescenceMap ) { + + const iridescenceMapDef = { + index: await writer.processTextureAsync( material.iridescenceMap ), + texCoord: material.iridescenceMap.channel + }; + writer.applyTextureTransform( iridescenceMapDef, material.iridescenceMap ); + extensionDef.iridescenceTexture = iridescenceMapDef; + + } + + extensionDef.iridescenceIor = material.iridescenceIOR; + extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[ 0 ]; + extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[ 1 ]; + + if ( material.iridescenceThicknessMap ) { + + const iridescenceThicknessMapDef = { + index: await writer.processTextureAsync( material.iridescenceThicknessMap ), + texCoord: material.iridescenceThicknessMap.channel + }; + writer.applyTextureTransform( iridescenceThicknessMapDef, material.iridescenceThicknessMap ); + extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef; + + } + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Transmission Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission + */ +class GLTFMaterialsTransmissionExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_transmission'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.transmissionFactor = material.transmission; + + if ( material.transmissionMap ) { + + const transmissionMapDef = { + index: await writer.processTextureAsync( material.transmissionMap ), + texCoord: material.transmissionMap.channel + }; + writer.applyTextureTransform( transmissionMapDef, material.transmissionMap ); + extensionDef.transmissionTexture = transmissionMapDef; + + } + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Materials Volume Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume + */ +class GLTFMaterialsVolumeExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_volume'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.thicknessFactor = material.thickness; + + if ( material.thicknessMap ) { + + const thicknessMapDef = { + index: await writer.processTextureAsync( material.thicknessMap ), + texCoord: material.thicknessMap.channel + }; + writer.applyTextureTransform( thicknessMapDef, material.thicknessMap ); + extensionDef.thicknessTexture = thicknessMapDef; + + } + + if ( material.attenuationDistance !== Infinity ) { + + extensionDef.attenuationDistance = material.attenuationDistance; + + } + + extensionDef.attenuationColor = material.attenuationColor.toArray(); + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Materials ior Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior + */ +class GLTFMaterialsIorExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_ior'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.ior === 1.5 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.ior = material.ior; + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Materials specular Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular + */ +class GLTFMaterialsSpecularExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_specular'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || ( material.specularIntensity === 1.0 && + material.specularColor.equals( DEFAULT_SPECULAR_COLOR ) && + ! material.specularIntensityMap && ! material.specularColorMap ) ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + if ( material.specularIntensityMap ) { + + const specularIntensityMapDef = { + index: await writer.processTextureAsync( material.specularIntensityMap ), + texCoord: material.specularIntensityMap.channel + }; + writer.applyTextureTransform( specularIntensityMapDef, material.specularIntensityMap ); + extensionDef.specularTexture = specularIntensityMapDef; + + } + + if ( material.specularColorMap ) { + + const specularColorMapDef = { + index: await writer.processTextureAsync( material.specularColorMap ), + texCoord: material.specularColorMap.channel + }; + writer.applyTextureTransform( specularColorMapDef, material.specularColorMap ); + extensionDef.specularColorTexture = specularColorMapDef; + + } + + extensionDef.specularFactor = material.specularIntensity; + extensionDef.specularColorFactor = material.specularColor.toArray(); + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Sheen Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen + */ +class GLTFMaterialsSheenExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_sheen'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.sheen == 0.0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + if ( material.sheenRoughnessMap ) { + + const sheenRoughnessMapDef = { + index: await writer.processTextureAsync( material.sheenRoughnessMap ), + texCoord: material.sheenRoughnessMap.channel + }; + writer.applyTextureTransform( sheenRoughnessMapDef, material.sheenRoughnessMap ); + extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef; + + } + + if ( material.sheenColorMap ) { + + const sheenColorMapDef = { + index: await writer.processTextureAsync( material.sheenColorMap ), + texCoord: material.sheenColorMap.channel + }; + writer.applyTextureTransform( sheenColorMapDef, material.sheenColorMap ); + extensionDef.sheenColorTexture = sheenColorMapDef; + + } + + extensionDef.sheenRoughnessFactor = material.sheenRoughness; + extensionDef.sheenColorFactor = material.sheenColor.toArray(); + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Anisotropy Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_anisotropy + */ +class GLTFMaterialsAnisotropyExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_anisotropy'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshPhysicalMaterial || material.anisotropy == 0.0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + if ( material.anisotropyMap ) { + + const anisotropyMapDef = { index: await writer.processTextureAsync( material.anisotropyMap ) }; + writer.applyTextureTransform( anisotropyMapDef, material.anisotropyMap ); + extensionDef.anisotropyTexture = anisotropyMapDef; + + } + + extensionDef.anisotropyStrength = material.anisotropy; + extensionDef.anisotropyRotation = material.anisotropyRotation; + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * Materials Emissive Strength Extension + * + * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md + */ +class GLTFMaterialsEmissiveStrengthExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'KHR_materials_emissive_strength'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshStandardMaterial || material.emissiveIntensity === 1.0 ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + extensionDef.emissiveStrength = material.emissiveIntensity; + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + + +/** + * Materials bump Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump + */ +class GLTFMaterialsBumpExtension { + + constructor( writer ) { + + this.writer = writer; + this.name = 'EXT_materials_bump'; + + } + + async writeMaterialAsync( material, materialDef ) { + + if ( ! material.isMeshStandardMaterial || ( + material.bumpScale === 1 && + ! material.bumpMap ) ) return; + + const writer = this.writer; + const extensionsUsed = writer.extensionsUsed; + + const extensionDef = {}; + + if ( material.bumpMap ) { + + const bumpMapDef = { + index: await writer.processTextureAsync( material.bumpMap ), + texCoord: material.bumpMap.channel + }; + writer.applyTextureTransform( bumpMapDef, material.bumpMap ); + extensionDef.bumpTexture = bumpMapDef; + + } + + extensionDef.bumpFactor = material.bumpScale; + + materialDef.extensions = materialDef.extensions || {}; + materialDef.extensions[ this.name ] = extensionDef; + + extensionsUsed[ this.name ] = true; + + } + +} + +/** + * GPU Instancing Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing + */ +class GLTFMeshGpuInstancing { + + constructor( writer ) { + + this.writer = writer; + this.name = 'EXT_mesh_gpu_instancing'; + + } + + writeNode( object, nodeDef ) { + + if ( ! object.isInstancedMesh ) return; + + const writer = this.writer; + + const mesh = object; + + const translationAttr = new Float32Array( mesh.count * 3 ); + const rotationAttr = new Float32Array( mesh.count * 4 ); + const scaleAttr = new Float32Array( mesh.count * 3 ); + + const matrix = new Matrix4(); + const position = new Vector3(); + const quaternion = new Quaternion(); + const scale = new Vector3(); + + for ( let i = 0; i < mesh.count; i ++ ) { + + mesh.getMatrixAt( i, matrix ); + matrix.decompose( position, quaternion, scale ); + + position.toArray( translationAttr, i * 3 ); + quaternion.toArray( rotationAttr, i * 4 ); + scale.toArray( scaleAttr, i * 3 ); + + } + + const attributes = { + TRANSLATION: writer.processAccessor( new BufferAttribute( translationAttr, 3 ) ), + ROTATION: writer.processAccessor( new BufferAttribute( rotationAttr, 4 ) ), + SCALE: writer.processAccessor( new BufferAttribute( scaleAttr, 3 ) ), + }; + + if ( mesh.instanceColor ) + attributes._COLOR_0 = writer.processAccessor( mesh.instanceColor ); + + nodeDef.extensions = nodeDef.extensions || {}; + nodeDef.extensions[ this.name ] = { attributes }; + + writer.extensionsUsed[ this.name ] = true; + writer.extensionsRequired[ this.name ] = true; + + } + +} + +/** + * Static utility functions + */ +GLTFExporter.Utils = { + + insertKeyframe: function ( track, time ) { + + const tolerance = 0.001; // 1ms + const valueSize = track.getValueSize(); + + const times = new track.TimeBufferType( track.times.length + 1 ); + const values = new track.ValueBufferType( track.values.length + valueSize ); + const interpolant = track.createInterpolant( new track.ValueBufferType( valueSize ) ); + + let index; + + if ( track.times.length === 0 ) { + + times[ 0 ] = time; + + for ( let i = 0; i < valueSize; i ++ ) { + + values[ i ] = 0; + + } + + index = 0; + + } else if ( time < track.times[ 0 ] ) { + + if ( Math.abs( track.times[ 0 ] - time ) < tolerance ) return 0; + + times[ 0 ] = time; + times.set( track.times, 1 ); + + values.set( interpolant.evaluate( time ), 0 ); + values.set( track.values, valueSize ); + + index = 0; + + } else if ( time > track.times[ track.times.length - 1 ] ) { + + if ( Math.abs( track.times[ track.times.length - 1 ] - time ) < tolerance ) { + + return track.times.length - 1; + + } + + times[ times.length - 1 ] = time; + times.set( track.times, 0 ); + + values.set( track.values, 0 ); + values.set( interpolant.evaluate( time ), track.values.length ); + + index = times.length - 1; + + } else { + + for ( let i = 0; i < track.times.length; i ++ ) { + + if ( Math.abs( track.times[ i ] - time ) < tolerance ) return i; + + if ( track.times[ i ] < time && track.times[ i + 1 ] > time ) { + + times.set( track.times.slice( 0, i + 1 ), 0 ); + times[ i + 1 ] = time; + times.set( track.times.slice( i + 1 ), i + 2 ); + + values.set( track.values.slice( 0, ( i + 1 ) * valueSize ), 0 ); + values.set( interpolant.evaluate( time ), ( i + 1 ) * valueSize ); + values.set( track.values.slice( ( i + 1 ) * valueSize ), ( i + 2 ) * valueSize ); + + index = i + 1; + + break; + + } + + } + + } + + track.times = times; + track.values = values; + + return index; + + }, + + mergeMorphTargetTracks: function ( clip, root ) { + + const tracks = []; + const mergedTracks = {}; + const sourceTracks = clip.tracks; + + for ( let i = 0; i < sourceTracks.length; ++ i ) { + + let sourceTrack = sourceTracks[ i ]; + const sourceTrackBinding = PropertyBinding.parseTrackName( sourceTrack.name ); + const sourceTrackNode = PropertyBinding.findNode( root, sourceTrackBinding.nodeName ); + + if ( sourceTrackBinding.propertyName !== 'morphTargetInfluences' || sourceTrackBinding.propertyIndex === undefined ) { + + // Tracks that don't affect morph targets, or that affect all morph targets together, can be left as-is. + tracks.push( sourceTrack ); + continue; + + } + + if ( sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete + && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear ) { + + if ( sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) { + + // This should never happen, because glTF morph target animations + // affect all targets already. + throw new Error( 'THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.' ); + + } + + console.warn( 'THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.' ); + + sourceTrack = sourceTrack.clone(); + sourceTrack.setInterpolation( InterpolateLinear ); + + } + + const targetCount = sourceTrackNode.morphTargetInfluences.length; + const targetIndex = sourceTrackNode.morphTargetDictionary[ sourceTrackBinding.propertyIndex ]; + + if ( targetIndex === undefined ) { + + throw new Error( 'THREE.GLTFExporter: Morph target name not found: ' + sourceTrackBinding.propertyIndex ); + + } + + let mergedTrack; + + // If this is the first time we've seen this object, create a new + // track to store merged keyframe data for each morph target. + if ( mergedTracks[ sourceTrackNode.uuid ] === undefined ) { + + mergedTrack = sourceTrack.clone(); + + const values = new mergedTrack.ValueBufferType( targetCount * mergedTrack.times.length ); + + for ( let j = 0; j < mergedTrack.times.length; j ++ ) { + + values[ j * targetCount + targetIndex ] = mergedTrack.values[ j ]; + + } + + // We need to take into consideration the intended target node + // of our original un-merged morphTarget animation. + mergedTrack.name = ( sourceTrackBinding.nodeName || '' ) + '.morphTargetInfluences'; + mergedTrack.values = values; + + mergedTracks[ sourceTrackNode.uuid ] = mergedTrack; + tracks.push( mergedTrack ); + + continue; + + } + + const sourceInterpolant = sourceTrack.createInterpolant( new sourceTrack.ValueBufferType( 1 ) ); + + mergedTrack = mergedTracks[ sourceTrackNode.uuid ]; + + // For every existing keyframe of the merged track, write a (possibly + // interpolated) value from the source track. + for ( let j = 0; j < mergedTrack.times.length; j ++ ) { + + mergedTrack.values[ j * targetCount + targetIndex ] = sourceInterpolant.evaluate( mergedTrack.times[ j ] ); + + } + + // For every existing keyframe of the source track, write a (possibly + // new) keyframe to the merged track. Values from the previous loop may + // be written again, but keyframes are de-duplicated. + for ( let j = 0; j < sourceTrack.times.length; j ++ ) { + + const keyframeIndex = this.insertKeyframe( mergedTrack, sourceTrack.times[ j ] ); + mergedTrack.values[ keyframeIndex * targetCount + targetIndex ] = sourceTrack.values[ j ]; + + } + + } + + clip.tracks = tracks; + + return clip; + + }, + + toFloat32BufferAttribute: function ( srcAttribute ) { + + const dstAttribute = new BufferAttribute( new Float32Array( srcAttribute.count * srcAttribute.itemSize ), srcAttribute.itemSize, false ); + + if ( ! srcAttribute.normalized && ! srcAttribute.isInterleavedBufferAttribute ) { + + dstAttribute.array.set( srcAttribute.array ); + + return dstAttribute; + + } + + for ( let i = 0, il = srcAttribute.count; i < il; i ++ ) { + + for ( let j = 0; j < srcAttribute.itemSize; j ++ ) { + + dstAttribute.setComponent( i, j, srcAttribute.getComponent( i, j ) ); + + } + + } + + return dstAttribute; + + } + +}; + +export { GLTFExporter }; diff --git a/libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.js b/libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.js new file mode 100644 index 000000000..6f02a4ac8 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.js @@ -0,0 +1,19 @@ + +var BASIS = (() => { + var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined; + if (typeof __filename != 'undefined') _scriptName ||= __filename; + return ( +function(moduleArg = {}) { + var moduleRtn; + +var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;var readyPromise=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject});var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";if(ENVIRONMENT_IS_NODE){}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);var ret=fs.readFileSync(filename);return ret};readAsync=(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return new Promise((resolve,reject)=>{fs.readFile(filename,binary?undefined:"utf8",(err,data)=>{if(err)reject(err);else resolve(binary?data.buffer:data)})})};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptName){scriptDirectory=_scriptName}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=url=>{if(isFileURI(url)){return new Promise((reject,resolve)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response)}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}return fetch(url,{credentials:"same-origin"}).then(response=>{if(response.ok){return response.arrayBuffer()}return Promise.reject(new Error(response.status+" : "+response.url))})}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var EXITSTATUS;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function findWasmBinary(){var f="basis_transcoder.wasm";if(!isDataURI(f)){return locateFile(f)}return f}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary){return readAsync(binaryFile).then(response=>new Uint8Array(response),()=>getBinarySync(binaryFile))}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function getWasmImports(){return{a:wasmImports}}function createWasm(){var info=getWasmImports();function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["L"];updateMemoryViews();wasmTable=wasmExports["P"];addOnInit(wasmExports["M"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);readyPromiseReject(e)}}if(!wasmBinaryFile)wasmBinaryFile=findWasmBinary();instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult).catch(readyPromiseReject);return{}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var noExitRuntime=Module["noExitRuntime"]||true;class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>2]=type}get_type(){return HEAPU32[this.ptr+4>>2]}set_destructor(destructor){HEAPU32[this.ptr+8>>2]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>2]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12]=caught}get_caught(){return HEAP8[this.ptr+12]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13]=rethrown}get_rethrown(){return HEAP8[this.ptr+13]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>2]}get_exception_ptr(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr}}var exceptionLast=0;var uncaughtExceptionCount=0;var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw exceptionLast};var __abort_js=()=>{abort("")};var structRegistrations={};var runDestructors=destructors=>{while(destructors.length){var ptr=destructors.pop();var del=destructors.pop();del(ptr)}};function readPointer(pointer){return this["fromWireType"](HEAPU32[pointer>>2])}var awaitingDependencies={};var registeredTypes={};var typeDependencies={};var InternalError;var throwInternalError=message=>{throw new InternalError(message)};var whenDependentTypesAreResolved=(myTypes,dependentTypes,getTypeConverters)=>{myTypes.forEach(function(type){typeDependencies[type]=dependentTypes});function onComplete(typeConverters){var myTypeConverters=getTypeConverters(typeConverters);if(myTypeConverters.length!==myTypes.length){throwInternalError("Mismatched type converter count")}for(var i=0;i{if(registeredTypes.hasOwnProperty(dt)){typeConverters[i]=registeredTypes[dt]}else{unregisteredTypes.push(dt);if(!awaitingDependencies.hasOwnProperty(dt)){awaitingDependencies[dt]=[]}awaitingDependencies[dt].push(()=>{typeConverters[i]=registeredTypes[dt];++registered;if(registered===unregisteredTypes.length){onComplete(typeConverters)}})}});if(0===unregisteredTypes.length){onComplete(typeConverters)}};var __embind_finalize_value_object=structType=>{var reg=structRegistrations[structType];delete structRegistrations[structType];var rawConstructor=reg.rawConstructor;var rawDestructor=reg.rawDestructor;var fieldRecords=reg.fields;var fieldTypes=fieldRecords.map(field=>field.getterReturnType).concat(fieldRecords.map(field=>field.setterArgumentType));whenDependentTypesAreResolved([structType],fieldTypes,fieldTypes=>{var fields={};fieldRecords.forEach((field,i)=>{var fieldName=field.fieldName;var getterReturnType=fieldTypes[i];var getter=field.getter;var getterContext=field.getterContext;var setterArgumentType=fieldTypes[i+fieldRecords.length];var setter=field.setter;var setterContext=field.setterContext;fields[fieldName]={read:ptr=>getterReturnType["fromWireType"](getter(getterContext,ptr)),write:(ptr,o)=>{var destructors=[];setter(setterContext,ptr,setterArgumentType["toWireType"](destructors,o));runDestructors(destructors)}}});return[{name:reg.name,fromWireType:ptr=>{var rv={};for(var i in fields){rv[i]=fields[i].read(ptr)}rawDestructor(ptr);return rv},toWireType:(destructors,o)=>{for(var fieldName in fields){if(!(fieldName in o)){throw new TypeError(`Missing field: "${fieldName}"`)}}var ptr=rawConstructor();for(fieldName in fields){fields[fieldName].write(ptr,o[fieldName])}if(destructors!==null){destructors.push(rawDestructor,ptr)}return ptr},argPackAdvance:GenericWireTypeSize,readValueFromPointer:readPointer,destructorFunction:rawDestructor}]})};var __embind_register_bigint=(primitiveType,name,size,minRange,maxRange)=>{};var embind_init_charCodes=()=>{var codes=new Array(256);for(var i=0;i<256;++i){codes[i]=String.fromCharCode(i)}embind_charCodes=codes};var embind_charCodes;var readLatin1String=ptr=>{var ret="";var c=ptr;while(HEAPU8[c]){ret+=embind_charCodes[HEAPU8[c++]]}return ret};var BindingError;var throwBindingError=message=>{throw new BindingError(message)};function sharedRegisterType(rawType,registeredInstance,options={}){var name=registeredInstance.name;if(!rawType){throwBindingError(`type "${name}" must have a positive integer typeid pointer`)}if(registeredTypes.hasOwnProperty(rawType)){if(options.ignoreDuplicateRegistrations){return}else{throwBindingError(`Cannot register type '${name}' twice`)}}registeredTypes[rawType]=registeredInstance;delete typeDependencies[rawType];if(awaitingDependencies.hasOwnProperty(rawType)){var callbacks=awaitingDependencies[rawType];delete awaitingDependencies[rawType];callbacks.forEach(cb=>cb())}}function registerType(rawType,registeredInstance,options={}){if(!("argPackAdvance"in registeredInstance)){throw new TypeError("registerType registeredInstance requires argPackAdvance")}return sharedRegisterType(rawType,registeredInstance,options)}var GenericWireTypeSize=8;var __embind_register_bool=(rawType,name,trueValue,falseValue)=>{name=readLatin1String(name);registerType(rawType,{name:name,fromWireType:function(wt){return!!wt},toWireType:function(destructors,o){return o?trueValue:falseValue},argPackAdvance:GenericWireTypeSize,readValueFromPointer:function(pointer){return this["fromWireType"](HEAPU8[pointer])},destructorFunction:null})};var shallowCopyInternalPointer=o=>({count:o.count,deleteScheduled:o.deleteScheduled,preservePointerOnDelete:o.preservePointerOnDelete,ptr:o.ptr,ptrType:o.ptrType,smartPtr:o.smartPtr,smartPtrType:o.smartPtrType});var throwInstanceAlreadyDeleted=obj=>{function getInstanceTypeName(handle){return handle.$$.ptrType.registeredClass.name}throwBindingError(getInstanceTypeName(obj)+" instance already deleted")};var finalizationRegistry=false;var detachFinalizer=handle=>{};var runDestructor=$$=>{if($$.smartPtr){$$.smartPtrType.rawDestructor($$.smartPtr)}else{$$.ptrType.registeredClass.rawDestructor($$.ptr)}};var releaseClassHandle=$$=>{$$.count.value-=1;var toDelete=0===$$.count.value;if(toDelete){runDestructor($$)}};var downcastPointer=(ptr,ptrClass,desiredClass)=>{if(ptrClass===desiredClass){return ptr}if(undefined===desiredClass.baseClass){return null}var rv=downcastPointer(ptr,ptrClass,desiredClass.baseClass);if(rv===null){return null}return desiredClass.downcast(rv)};var registeredPointers={};var getInheritedInstanceCount=()=>Object.keys(registeredInstances).length;var getLiveInheritedInstances=()=>{var rv=[];for(var k in registeredInstances){if(registeredInstances.hasOwnProperty(k)){rv.push(registeredInstances[k])}}return rv};var deletionQueue=[];var flushPendingDeletes=()=>{while(deletionQueue.length){var obj=deletionQueue.pop();obj.$$.deleteScheduled=false;obj["delete"]()}};var delayFunction;var setDelayFunction=fn=>{delayFunction=fn;if(deletionQueue.length&&delayFunction){delayFunction(flushPendingDeletes)}};var init_embind=()=>{Module["getInheritedInstanceCount"]=getInheritedInstanceCount;Module["getLiveInheritedInstances"]=getLiveInheritedInstances;Module["flushPendingDeletes"]=flushPendingDeletes;Module["setDelayFunction"]=setDelayFunction};var registeredInstances={};var getBasestPointer=(class_,ptr)=>{if(ptr===undefined){throwBindingError("ptr should not be undefined")}while(class_.baseClass){ptr=class_.upcast(ptr);class_=class_.baseClass}return ptr};var getInheritedInstance=(class_,ptr)=>{ptr=getBasestPointer(class_,ptr);return registeredInstances[ptr]};var makeClassHandle=(prototype,record)=>{if(!record.ptrType||!record.ptr){throwInternalError("makeClassHandle requires ptr and ptrType")}var hasSmartPtrType=!!record.smartPtrType;var hasSmartPtr=!!record.smartPtr;if(hasSmartPtrType!==hasSmartPtr){throwInternalError("Both smartPtrType and smartPtr must be specified")}record.count={value:1};return attachFinalizer(Object.create(prototype,{$$:{value:record,writable:true}}))};function RegisteredPointer_fromWireType(ptr){var rawPointer=this.getPointee(ptr);if(!rawPointer){this.destructor(ptr);return null}var registeredInstance=getInheritedInstance(this.registeredClass,rawPointer);if(undefined!==registeredInstance){if(0===registeredInstance.$$.count.value){registeredInstance.$$.ptr=rawPointer;registeredInstance.$$.smartPtr=ptr;return registeredInstance["clone"]()}else{var rv=registeredInstance["clone"]();this.destructor(ptr);return rv}}function makeDefaultHandle(){if(this.isSmartPointer){return makeClassHandle(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:rawPointer,smartPtrType:this,smartPtr:ptr})}else{return makeClassHandle(this.registeredClass.instancePrototype,{ptrType:this,ptr:ptr})}}var actualType=this.registeredClass.getActualType(rawPointer);var registeredPointerRecord=registeredPointers[actualType];if(!registeredPointerRecord){return makeDefaultHandle.call(this)}var toType;if(this.isConst){toType=registeredPointerRecord.constPointerType}else{toType=registeredPointerRecord.pointerType}var dp=downcastPointer(rawPointer,this.registeredClass,toType.registeredClass);if(dp===null){return makeDefaultHandle.call(this)}if(this.isSmartPointer){return makeClassHandle(toType.registeredClass.instancePrototype,{ptrType:toType,ptr:dp,smartPtrType:this,smartPtr:ptr})}else{return makeClassHandle(toType.registeredClass.instancePrototype,{ptrType:toType,ptr:dp})}}var attachFinalizer=handle=>{if("undefined"===typeof FinalizationRegistry){attachFinalizer=handle=>handle;return handle}finalizationRegistry=new FinalizationRegistry(info=>{releaseClassHandle(info.$$)});attachFinalizer=handle=>{var $$=handle.$$;var hasSmartPtr=!!$$.smartPtr;if(hasSmartPtr){var info={$$:$$};finalizationRegistry.register(handle,info,handle)}return handle};detachFinalizer=handle=>finalizationRegistry.unregister(handle);return attachFinalizer(handle)};var init_ClassHandle=()=>{Object.assign(ClassHandle.prototype,{isAliasOf(other){if(!(this instanceof ClassHandle)){return false}if(!(other instanceof ClassHandle)){return false}var leftClass=this.$$.ptrType.registeredClass;var left=this.$$.ptr;other.$$=other.$$;var rightClass=other.$$.ptrType.registeredClass;var right=other.$$.ptr;while(leftClass.baseClass){left=leftClass.upcast(left);leftClass=leftClass.baseClass}while(rightClass.baseClass){right=rightClass.upcast(right);rightClass=rightClass.baseClass}return leftClass===rightClass&&left===right},clone(){if(!this.$$.ptr){throwInstanceAlreadyDeleted(this)}if(this.$$.preservePointerOnDelete){this.$$.count.value+=1;return this}else{var clone=attachFinalizer(Object.create(Object.getPrototypeOf(this),{$$:{value:shallowCopyInternalPointer(this.$$)}}));clone.$$.count.value+=1;clone.$$.deleteScheduled=false;return clone}},delete(){if(!this.$$.ptr){throwInstanceAlreadyDeleted(this)}if(this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete){throwBindingError("Object already scheduled for deletion")}detachFinalizer(this);releaseClassHandle(this.$$);if(!this.$$.preservePointerOnDelete){this.$$.smartPtr=undefined;this.$$.ptr=undefined}},isDeleted(){return!this.$$.ptr},deleteLater(){if(!this.$$.ptr){throwInstanceAlreadyDeleted(this)}if(this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete){throwBindingError("Object already scheduled for deletion")}deletionQueue.push(this);if(deletionQueue.length===1&&delayFunction){delayFunction(flushPendingDeletes)}this.$$.deleteScheduled=true;return this}})};function ClassHandle(){}var createNamedFunction=(name,body)=>Object.defineProperty(body,"name",{value:name});var ensureOverloadTable=(proto,methodName,humanName)=>{if(undefined===proto[methodName].overloadTable){var prevFunc=proto[methodName];proto[methodName]=function(...args){if(!proto[methodName].overloadTable.hasOwnProperty(args.length)){throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${args.length}) - expects one of (${proto[methodName].overloadTable})!`)}return proto[methodName].overloadTable[args.length].apply(this,args)};proto[methodName].overloadTable=[];proto[methodName].overloadTable[prevFunc.argCount]=prevFunc}};var exposePublicSymbol=(name,value,numArguments)=>{if(Module.hasOwnProperty(name)){if(undefined===numArguments||undefined!==Module[name].overloadTable&&undefined!==Module[name].overloadTable[numArguments]){throwBindingError(`Cannot register public name '${name}' twice`)}ensureOverloadTable(Module,name,name);if(Module.hasOwnProperty(numArguments)){throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`)}Module[name].overloadTable[numArguments]=value}else{Module[name]=value;if(undefined!==numArguments){Module[name].numArguments=numArguments}}};var char_0=48;var char_9=57;var makeLegalFunctionName=name=>{if(undefined===name){return"_unknown"}name=name.replace(/[^a-zA-Z0-9_]/g,"$");var f=name.charCodeAt(0);if(f>=char_0&&f<=char_9){return`_${name}`}return name};function RegisteredClass(name,constructor,instancePrototype,rawDestructor,baseClass,getActualType,upcast,downcast){this.name=name;this.constructor=constructor;this.instancePrototype=instancePrototype;this.rawDestructor=rawDestructor;this.baseClass=baseClass;this.getActualType=getActualType;this.upcast=upcast;this.downcast=downcast;this.pureVirtualFunctions=[]}var upcastPointer=(ptr,ptrClass,desiredClass)=>{while(ptrClass!==desiredClass){if(!ptrClass.upcast){throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`)}ptr=ptrClass.upcast(ptr);ptrClass=ptrClass.baseClass}return ptr};function constNoSmartPtrRawPointerToWireType(destructors,handle){if(handle===null){if(this.isReference){throwBindingError(`null is not a valid ${this.name}`)}return 0}if(!handle.$$){throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`)}if(!handle.$$.ptr){throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`)}var handleClass=handle.$$.ptrType.registeredClass;var ptr=upcastPointer(handle.$$.ptr,handleClass,this.registeredClass);return ptr}function genericPointerToWireType(destructors,handle){var ptr;if(handle===null){if(this.isReference){throwBindingError(`null is not a valid ${this.name}`)}if(this.isSmartPointer){ptr=this.rawConstructor();if(destructors!==null){destructors.push(this.rawDestructor,ptr)}return ptr}else{return 0}}if(!handle||!handle.$$){throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`)}if(!handle.$$.ptr){throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`)}if(!this.isConst&&handle.$$.ptrType.isConst){throwBindingError(`Cannot convert argument of type ${handle.$$.smartPtrType?handle.$$.smartPtrType.name:handle.$$.ptrType.name} to parameter type ${this.name}`)}var handleClass=handle.$$.ptrType.registeredClass;ptr=upcastPointer(handle.$$.ptr,handleClass,this.registeredClass);if(this.isSmartPointer){if(undefined===handle.$$.smartPtr){throwBindingError("Passing raw pointer to smart pointer is illegal")}switch(this.sharingPolicy){case 0:if(handle.$$.smartPtrType===this){ptr=handle.$$.smartPtr}else{throwBindingError(`Cannot convert argument of type ${handle.$$.smartPtrType?handle.$$.smartPtrType.name:handle.$$.ptrType.name} to parameter type ${this.name}`)}break;case 1:ptr=handle.$$.smartPtr;break;case 2:if(handle.$$.smartPtrType===this){ptr=handle.$$.smartPtr}else{var clonedHandle=handle["clone"]();ptr=this.rawShare(ptr,Emval.toHandle(()=>clonedHandle["delete"]()));if(destructors!==null){destructors.push(this.rawDestructor,ptr)}}break;default:throwBindingError("Unsupporting sharing policy")}}return ptr}function nonConstNoSmartPtrRawPointerToWireType(destructors,handle){if(handle===null){if(this.isReference){throwBindingError(`null is not a valid ${this.name}`)}return 0}if(!handle.$$){throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`)}if(!handle.$$.ptr){throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`)}if(handle.$$.ptrType.isConst){throwBindingError(`Cannot convert argument of type ${handle.$$.ptrType.name} to parameter type ${this.name}`)}var handleClass=handle.$$.ptrType.registeredClass;var ptr=upcastPointer(handle.$$.ptr,handleClass,this.registeredClass);return ptr}var init_RegisteredPointer=()=>{Object.assign(RegisteredPointer.prototype,{getPointee(ptr){if(this.rawGetPointee){ptr=this.rawGetPointee(ptr)}return ptr},destructor(ptr){this.rawDestructor?.(ptr)},argPackAdvance:GenericWireTypeSize,readValueFromPointer:readPointer,fromWireType:RegisteredPointer_fromWireType})};function RegisteredPointer(name,registeredClass,isReference,isConst,isSmartPointer,pointeeType,sharingPolicy,rawGetPointee,rawConstructor,rawShare,rawDestructor){this.name=name;this.registeredClass=registeredClass;this.isReference=isReference;this.isConst=isConst;this.isSmartPointer=isSmartPointer;this.pointeeType=pointeeType;this.sharingPolicy=sharingPolicy;this.rawGetPointee=rawGetPointee;this.rawConstructor=rawConstructor;this.rawShare=rawShare;this.rawDestructor=rawDestructor;if(!isSmartPointer&®isteredClass.baseClass===undefined){if(isConst){this["toWireType"]=constNoSmartPtrRawPointerToWireType;this.destructorFunction=null}else{this["toWireType"]=nonConstNoSmartPtrRawPointerToWireType;this.destructorFunction=null}}else{this["toWireType"]=genericPointerToWireType}}var replacePublicSymbol=(name,value,numArguments)=>{if(!Module.hasOwnProperty(name)){throwInternalError("Replacing nonexistent public symbol")}if(undefined!==Module[name].overloadTable&&undefined!==numArguments){Module[name].overloadTable[numArguments]=value}else{Module[name]=value;Module[name].argCount=numArguments}};var dynCallLegacy=(sig,ptr,args)=>{sig=sig.replace(/p/g,"i");var f=Module["dynCall_"+sig];return f(ptr,...args)};var wasmTableMirror=[];var wasmTable;var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func){if(funcPtr>=wasmTableMirror.length)wasmTableMirror.length=funcPtr+1;wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr)}return func};var dynCall=(sig,ptr,args=[])=>{if(sig.includes("j")){return dynCallLegacy(sig,ptr,args)}var rtn=getWasmTableEntry(ptr)(...args);return rtn};var getDynCaller=(sig,ptr)=>(...args)=>dynCall(sig,ptr,args);var embind__requireFunction=(signature,rawFunction)=>{signature=readLatin1String(signature);function makeDynCaller(){if(signature.includes("j")){return getDynCaller(signature,rawFunction)}return getWasmTableEntry(rawFunction)}var fp=makeDynCaller();if(typeof fp!="function"){throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`)}return fp};var extendError=(baseErrorType,errorName)=>{var errorClass=createNamedFunction(errorName,function(message){this.name=errorName;this.message=message;var stack=new Error(message).stack;if(stack!==undefined){this.stack=this.toString()+"\n"+stack.replace(/^Error(:[^\n]*)?\n/,"")}});errorClass.prototype=Object.create(baseErrorType.prototype);errorClass.prototype.constructor=errorClass;errorClass.prototype.toString=function(){if(this.message===undefined){return this.name}else{return`${this.name}: ${this.message}`}};return errorClass};var UnboundTypeError;var getTypeName=type=>{var ptr=___getTypeName(type);var rv=readLatin1String(ptr);_free(ptr);return rv};var throwUnboundTypeError=(message,types)=>{var unboundTypes=[];var seen={};function visit(type){if(seen[type]){return}if(registeredTypes[type]){return}if(typeDependencies[type]){typeDependencies[type].forEach(visit);return}unboundTypes.push(type);seen[type]=true}types.forEach(visit);throw new UnboundTypeError(`${message}: `+unboundTypes.map(getTypeName).join([", "]))};var __embind_register_class=(rawType,rawPointerType,rawConstPointerType,baseClassRawType,getActualTypeSignature,getActualType,upcastSignature,upcast,downcastSignature,downcast,name,destructorSignature,rawDestructor)=>{name=readLatin1String(name);getActualType=embind__requireFunction(getActualTypeSignature,getActualType);upcast&&=embind__requireFunction(upcastSignature,upcast);downcast&&=embind__requireFunction(downcastSignature,downcast);rawDestructor=embind__requireFunction(destructorSignature,rawDestructor);var legalFunctionName=makeLegalFunctionName(name);exposePublicSymbol(legalFunctionName,function(){throwUnboundTypeError(`Cannot construct ${name} due to unbound types`,[baseClassRawType])});whenDependentTypesAreResolved([rawType,rawPointerType,rawConstPointerType],baseClassRawType?[baseClassRawType]:[],base=>{base=base[0];var baseClass;var basePrototype;if(baseClassRawType){baseClass=base.registeredClass;basePrototype=baseClass.instancePrototype}else{basePrototype=ClassHandle.prototype}var constructor=createNamedFunction(name,function(...args){if(Object.getPrototypeOf(this)!==instancePrototype){throw new BindingError("Use 'new' to construct "+name)}if(undefined===registeredClass.constructor_body){throw new BindingError(name+" has no accessible constructor")}var body=registeredClass.constructor_body[args.length];if(undefined===body){throw new BindingError(`Tried to invoke ctor of ${name} with invalid number of parameters (${args.length}) - expected (${Object.keys(registeredClass.constructor_body).toString()}) parameters instead!`)}return body.apply(this,args)});var instancePrototype=Object.create(basePrototype,{constructor:{value:constructor}});constructor.prototype=instancePrototype;var registeredClass=new RegisteredClass(name,constructor,instancePrototype,rawDestructor,baseClass,getActualType,upcast,downcast);if(registeredClass.baseClass){registeredClass.baseClass.__derivedClasses??=[];registeredClass.baseClass.__derivedClasses.push(registeredClass)}var referenceConverter=new RegisteredPointer(name,registeredClass,true,false,false);var pointerConverter=new RegisteredPointer(name+"*",registeredClass,false,false,false);var constPointerConverter=new RegisteredPointer(name+" const*",registeredClass,false,true,false);registeredPointers[rawType]={pointerType:pointerConverter,constPointerType:constPointerConverter};replacePublicSymbol(legalFunctionName,constructor);return[referenceConverter,pointerConverter,constPointerConverter]})};var heap32VectorToArray=(count,firstElement)=>{var array=[];for(var i=0;i>2])}return array};function usesDestructorStack(argTypes){for(var i=1;i0?", ":"")+argsListWired}invokerFnBody+=(returns||isAsync?"var rv = ":"")+"invoker(fn"+(argsListWired.length>0?", ":"")+argsListWired+");\n";if(needsDestructorStack){invokerFnBody+="runDestructors(destructors);\n"}else{for(var i=isClassMethodFunc?1:2;i{var rawArgTypes=heap32VectorToArray(argCount,rawArgTypesAddr);invoker=embind__requireFunction(invokerSignature,invoker);whenDependentTypesAreResolved([],[rawClassType],classType=>{classType=classType[0];var humanName=`constructor ${classType.name}`;if(undefined===classType.registeredClass.constructor_body){classType.registeredClass.constructor_body=[]}if(undefined!==classType.registeredClass.constructor_body[argCount-1]){throw new BindingError(`Cannot register multiple constructors with identical number of parameters (${argCount-1}) for class '${classType.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`)}classType.registeredClass.constructor_body[argCount-1]=()=>{throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`,rawArgTypes)};whenDependentTypesAreResolved([],rawArgTypes,argTypes=>{argTypes.splice(1,0,null);classType.registeredClass.constructor_body[argCount-1]=craftInvokerFunction(humanName,argTypes,null,invoker,rawConstructor);return[]});return[]})};var getFunctionName=signature=>{signature=signature.trim();const argsIndex=signature.indexOf("(");if(argsIndex!==-1){return signature.substr(0,argsIndex)}else{return signature}};var __embind_register_class_function=(rawClassType,methodName,argCount,rawArgTypesAddr,invokerSignature,rawInvoker,context,isPureVirtual,isAsync)=>{var rawArgTypes=heap32VectorToArray(argCount,rawArgTypesAddr);methodName=readLatin1String(methodName);methodName=getFunctionName(methodName);rawInvoker=embind__requireFunction(invokerSignature,rawInvoker);whenDependentTypesAreResolved([],[rawClassType],classType=>{classType=classType[0];var humanName=`${classType.name}.${methodName}`;if(methodName.startsWith("@@")){methodName=Symbol[methodName.substring(2)]}if(isPureVirtual){classType.registeredClass.pureVirtualFunctions.push(methodName)}function unboundTypesHandler(){throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`,rawArgTypes)}var proto=classType.registeredClass.instancePrototype;var method=proto[methodName];if(undefined===method||undefined===method.overloadTable&&method.className!==classType.name&&method.argCount===argCount-2){unboundTypesHandler.argCount=argCount-2;unboundTypesHandler.className=classType.name;proto[methodName]=unboundTypesHandler}else{ensureOverloadTable(proto,methodName,humanName);proto[methodName].overloadTable[argCount-2]=unboundTypesHandler}whenDependentTypesAreResolved([],rawArgTypes,argTypes=>{var memberFunction=craftInvokerFunction(humanName,argTypes,classType,rawInvoker,context,isAsync);if(undefined===proto[methodName].overloadTable){memberFunction.argCount=argCount-2;proto[methodName]=memberFunction}else{proto[methodName].overloadTable[argCount-2]=memberFunction}return[]});return[]})};var __embind_register_constant=(name,type,value)=>{name=readLatin1String(name);whenDependentTypesAreResolved([],[type],type=>{type=type[0];Module[name]=type["fromWireType"](value);return[]})};var emval_freelist=[];var emval_handles=[];var __emval_decref=handle=>{if(handle>9&&0===--emval_handles[handle+1]){emval_handles[handle]=undefined;emval_freelist.push(handle)}};var count_emval_handles=()=>emval_handles.length/2-5-emval_freelist.length;var init_emval=()=>{emval_handles.push(0,1,undefined,1,null,1,true,1,false,1);Module["count_emval_handles"]=count_emval_handles};var Emval={toValue:handle=>{if(!handle){throwBindingError("Cannot use deleted val. handle = "+handle)}return emval_handles[handle]},toHandle:value=>{switch(value){case undefined:return 2;case null:return 4;case true:return 6;case false:return 8;default:{const handle=emval_freelist.pop()||emval_handles.length;emval_handles[handle]=value;emval_handles[handle+1]=1;return handle}}}};var EmValType={name:"emscripten::val",fromWireType:handle=>{var rv=Emval.toValue(handle);__emval_decref(handle);return rv},toWireType:(destructors,value)=>Emval.toHandle(value),argPackAdvance:GenericWireTypeSize,readValueFromPointer:readPointer,destructorFunction:null};var __embind_register_emval=rawType=>registerType(rawType,EmValType);var enumReadValueFromPointer=(name,width,signed)=>{switch(width){case 1:return signed?function(pointer){return this["fromWireType"](HEAP8[pointer])}:function(pointer){return this["fromWireType"](HEAPU8[pointer])};case 2:return signed?function(pointer){return this["fromWireType"](HEAP16[pointer>>1])}:function(pointer){return this["fromWireType"](HEAPU16[pointer>>1])};case 4:return signed?function(pointer){return this["fromWireType"](HEAP32[pointer>>2])}:function(pointer){return this["fromWireType"](HEAPU32[pointer>>2])};default:throw new TypeError(`invalid integer width (${width}): ${name}`)}};var __embind_register_enum=(rawType,name,size,isSigned)=>{name=readLatin1String(name);function ctor(){}ctor.values={};registerType(rawType,{name:name,constructor:ctor,fromWireType:function(c){return this.constructor.values[c]},toWireType:(destructors,c)=>c.value,argPackAdvance:GenericWireTypeSize,readValueFromPointer:enumReadValueFromPointer(name,size,isSigned),destructorFunction:null});exposePublicSymbol(name,ctor)};var requireRegisteredType=(rawType,humanName)=>{var impl=registeredTypes[rawType];if(undefined===impl){throwBindingError(`${humanName} has unknown type ${getTypeName(rawType)}`)}return impl};var __embind_register_enum_value=(rawEnumType,name,enumValue)=>{var enumType=requireRegisteredType(rawEnumType,"enum");name=readLatin1String(name);var Enum=enumType.constructor;var Value=Object.create(enumType.constructor.prototype,{value:{value:enumValue},constructor:{value:createNamedFunction(`${enumType.name}_${name}`,function(){})}});Enum.values[enumValue]=Value;Enum[name]=Value};var embindRepr=v=>{if(v===null){return"null"}var t=typeof v;if(t==="object"||t==="array"||t==="function"){return v.toString()}else{return""+v}};var floatReadValueFromPointer=(name,width)=>{switch(width){case 4:return function(pointer){return this["fromWireType"](HEAPF32[pointer>>2])};case 8:return function(pointer){return this["fromWireType"](HEAPF64[pointer>>3])};default:throw new TypeError(`invalid float width (${width}): ${name}`)}};var __embind_register_float=(rawType,name,size)=>{name=readLatin1String(name);registerType(rawType,{name:name,fromWireType:value=>value,toWireType:(destructors,value)=>value,argPackAdvance:GenericWireTypeSize,readValueFromPointer:floatReadValueFromPointer(name,size),destructorFunction:null})};var __embind_register_function=(name,argCount,rawArgTypesAddr,signature,rawInvoker,fn,isAsync)=>{var argTypes=heap32VectorToArray(argCount,rawArgTypesAddr);name=readLatin1String(name);name=getFunctionName(name);rawInvoker=embind__requireFunction(signature,rawInvoker);exposePublicSymbol(name,function(){throwUnboundTypeError(`Cannot call ${name} due to unbound types`,argTypes)},argCount-1);whenDependentTypesAreResolved([],argTypes,argTypes=>{var invokerArgsArray=[argTypes[0],null].concat(argTypes.slice(1));replacePublicSymbol(name,craftInvokerFunction(name,invokerArgsArray,null,rawInvoker,fn,isAsync),argCount-1);return[]})};var integerReadValueFromPointer=(name,width,signed)=>{switch(width){case 1:return signed?pointer=>HEAP8[pointer]:pointer=>HEAPU8[pointer];case 2:return signed?pointer=>HEAP16[pointer>>1]:pointer=>HEAPU16[pointer>>1];case 4:return signed?pointer=>HEAP32[pointer>>2]:pointer=>HEAPU32[pointer>>2];default:throw new TypeError(`invalid integer width (${width}): ${name}`)}};var __embind_register_integer=(primitiveType,name,size,minRange,maxRange)=>{name=readLatin1String(name);if(maxRange===-1){maxRange=4294967295}var fromWireType=value=>value;if(minRange===0){var bitshift=32-8*size;fromWireType=value=>value<>>bitshift}var isUnsignedType=name.includes("unsigned");var checkAssertions=(value,toTypeName)=>{};var toWireType;if(isUnsignedType){toWireType=function(destructors,value){checkAssertions(value,this.name);return value>>>0}}else{toWireType=function(destructors,value){checkAssertions(value,this.name);return value}}registerType(primitiveType,{name:name,fromWireType:fromWireType,toWireType:toWireType,argPackAdvance:GenericWireTypeSize,readValueFromPointer:integerReadValueFromPointer(name,size,minRange!==0),destructorFunction:null})};var __embind_register_memory_view=(rawType,dataTypeIndex,name)=>{var typeMapping=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];var TA=typeMapping[dataTypeIndex];function decodeMemoryView(handle){var size=HEAPU32[handle>>2];var data=HEAPU32[handle+4>>2];return new TA(HEAP8.buffer,data,size)}name=readLatin1String(name);registerType(rawType,{name:name,fromWireType:decodeMemoryView,argPackAdvance:GenericWireTypeSize,readValueFromPointer:decodeMemoryView},{ignoreDuplicateRegistrations:true})};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var lengthBytesUTF8=str=>{var len=0;for(var i=0;i=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder:undefined;var UTF8ArrayToString=(heapOrArray,idx,maxBytesToRead)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var __embind_register_std_string=(rawType,name)=>{name=readLatin1String(name);var stdStringIsUTF8=name==="std::string";registerType(rawType,{name:name,fromWireType(value){var length=HEAPU32[value>>2];var payload=value+4;var str;if(stdStringIsUTF8){var decodeStartPtr=payload;for(var i=0;i<=length;++i){var currentBytePtr=payload+i;if(i==length||HEAPU8[currentBytePtr]==0){var maxRead=currentBytePtr-decodeStartPtr;var stringSegment=UTF8ToString(decodeStartPtr,maxRead);if(str===undefined){str=stringSegment}else{str+=String.fromCharCode(0);str+=stringSegment}decodeStartPtr=currentBytePtr+1}}}else{var a=new Array(length);for(var i=0;i>2]=length;if(stdStringIsUTF8&&valueIsOfTypeString){stringToUTF8(value,ptr,length+1)}else{if(valueIsOfTypeString){for(var i=0;i255){_free(ptr);throwBindingError("String has UTF-16 code units that do not fit in 8 bits")}HEAPU8[ptr+i]=charCode}}else{for(var i=0;i{var endPtr=ptr;var idx=endPtr>>1;var maxIdx=idx+maxBytesToRead/2;while(!(idx>=maxIdx)&&HEAPU16[idx])++idx;endPtr=idx<<1;if(endPtr-ptr>32&&UTF16Decoder)return UTF16Decoder.decode(HEAPU8.subarray(ptr,endPtr));var str="";for(var i=0;!(i>=maxBytesToRead/2);++i){var codeUnit=HEAP16[ptr+i*2>>1];if(codeUnit==0)break;str+=String.fromCharCode(codeUnit)}return str};var stringToUTF16=(str,outPtr,maxBytesToWrite)=>{maxBytesToWrite??=2147483647;if(maxBytesToWrite<2)return 0;maxBytesToWrite-=2;var startPtr=outPtr;var numCharsToWrite=maxBytesToWrite>1]=codeUnit;outPtr+=2}HEAP16[outPtr>>1]=0;return outPtr-startPtr};var lengthBytesUTF16=str=>str.length*2;var UTF32ToString=(ptr,maxBytesToRead)=>{var i=0;var str="";while(!(i>=maxBytesToRead/4)){var utf32=HEAP32[ptr+i*4>>2];if(utf32==0)break;++i;if(utf32>=65536){var ch=utf32-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}else{str+=String.fromCharCode(utf32)}}return str};var stringToUTF32=(str,outPtr,maxBytesToWrite)=>{maxBytesToWrite??=2147483647;if(maxBytesToWrite<4)return 0;var startPtr=outPtr;var endPtr=startPtr+maxBytesToWrite-4;for(var i=0;i=55296&&codeUnit<=57343){var trailSurrogate=str.charCodeAt(++i);codeUnit=65536+((codeUnit&1023)<<10)|trailSurrogate&1023}HEAP32[outPtr>>2]=codeUnit;outPtr+=4;if(outPtr+4>endPtr)break}HEAP32[outPtr>>2]=0;return outPtr-startPtr};var lengthBytesUTF32=str=>{var len=0;for(var i=0;i=55296&&codeUnit<=57343)++i;len+=4}return len};var __embind_register_std_wstring=(rawType,charSize,name)=>{name=readLatin1String(name);var decodeString,encodeString,readCharAt,lengthBytesUTF;if(charSize===2){decodeString=UTF16ToString;encodeString=stringToUTF16;lengthBytesUTF=lengthBytesUTF16;readCharAt=pointer=>HEAPU16[pointer>>1]}else if(charSize===4){decodeString=UTF32ToString;encodeString=stringToUTF32;lengthBytesUTF=lengthBytesUTF32;readCharAt=pointer=>HEAPU32[pointer>>2]}registerType(rawType,{name:name,fromWireType:value=>{var length=HEAPU32[value>>2];var str;var decodeStartPtr=value+4;for(var i=0;i<=length;++i){var currentBytePtr=value+4+i*charSize;if(i==length||readCharAt(currentBytePtr)==0){var maxReadBytes=currentBytePtr-decodeStartPtr;var stringSegment=decodeString(decodeStartPtr,maxReadBytes);if(str===undefined){str=stringSegment}else{str+=String.fromCharCode(0);str+=stringSegment}decodeStartPtr=currentBytePtr+charSize}}_free(value);return str},toWireType:(destructors,value)=>{if(!(typeof value=="string")){throwBindingError(`Cannot pass non-string to C++ string type ${name}`)}var length=lengthBytesUTF(value);var ptr=_malloc(4+length+charSize);HEAPU32[ptr>>2]=length/charSize;encodeString(value,ptr+4,length+charSize);if(destructors!==null){destructors.push(_free,ptr)}return ptr},argPackAdvance:GenericWireTypeSize,readValueFromPointer:readPointer,destructorFunction(ptr){_free(ptr)}})};var __embind_register_value_object=(rawType,name,constructorSignature,rawConstructor,destructorSignature,rawDestructor)=>{structRegistrations[rawType]={name:readLatin1String(name),rawConstructor:embind__requireFunction(constructorSignature,rawConstructor),rawDestructor:embind__requireFunction(destructorSignature,rawDestructor),fields:[]}};var __embind_register_value_object_field=(structType,fieldName,getterReturnType,getterSignature,getter,getterContext,setterArgumentType,setterSignature,setter,setterContext)=>{structRegistrations[structType].fields.push({fieldName:readLatin1String(fieldName),getterReturnType:getterReturnType,getter:embind__requireFunction(getterSignature,getter),getterContext:getterContext,setterArgumentType:setterArgumentType,setter:embind__requireFunction(setterSignature,setter),setterContext:setterContext})};var __embind_register_void=(rawType,name)=>{name=readLatin1String(name);registerType(rawType,{isVoid:true,name:name,argPackAdvance:0,fromWireType:()=>undefined,toWireType:(destructors,o)=>undefined})};var __emscripten_memcpy_js=(dest,src,num)=>HEAPU8.copyWithin(dest,src,src+num);var emval_returnValue=(returnType,destructorsRef,handle)=>{var destructors=[];var result=returnType["toWireType"](destructors,handle);if(destructors.length){HEAPU32[destructorsRef>>2]=Emval.toHandle(destructors)}return result};var __emval_as=(handle,returnType,destructorsRef)=>{handle=Emval.toValue(handle);returnType=requireRegisteredType(returnType,"emval::as");return emval_returnValue(returnType,destructorsRef,handle)};var emval_methodCallers=[];var __emval_call=(caller,handle,destructorsRef,args)=>{caller=emval_methodCallers[caller];handle=Emval.toValue(handle);return caller(null,handle,destructorsRef,args)};var emval_symbols={};var getStringOrSymbol=address=>{var symbol=emval_symbols[address];if(symbol===undefined){return readLatin1String(address)}return symbol};var __emval_call_method=(caller,objHandle,methodName,destructorsRef,args)=>{caller=emval_methodCallers[caller];objHandle=Emval.toValue(objHandle);methodName=getStringOrSymbol(methodName);return caller(objHandle,objHandle[methodName],destructorsRef,args)};var emval_get_global=()=>{if(typeof globalThis=="object"){return globalThis}return function(){return Function}()("return this")()};var __emval_get_global=name=>{if(name===0){return Emval.toHandle(emval_get_global())}else{name=getStringOrSymbol(name);return Emval.toHandle(emval_get_global()[name])}};var emval_addMethodCaller=caller=>{var id=emval_methodCallers.length;emval_methodCallers.push(caller);return id};var emval_lookupTypes=(argCount,argTypes)=>{var a=new Array(argCount);for(var i=0;i>2],"parameter "+i)}return a};var reflectConstruct=Reflect.construct;var __emval_get_method_caller=(argCount,argTypes,kind)=>{var types=emval_lookupTypes(argCount,argTypes);var retType=types.shift();argCount--;var functionBody=`return function (obj, func, destructorsRef, args) {\n`;var offset=0;var argsList=[];if(kind===0){argsList.push("obj")}var params=["retType"];var args=[retType];for(var i=0;it.name).join(", ")}) => ${retType.name}>`;return emval_addMethodCaller(createNamedFunction(functionName,invokerFunction))};var __emval_get_module_property=name=>{name=getStringOrSymbol(name);return Emval.toHandle(Module[name])};var __emval_get_property=(handle,key)=>{handle=Emval.toValue(handle);key=Emval.toValue(key);return Emval.toHandle(handle[key])};var __emval_incref=handle=>{if(handle>9){emval_handles[handle+1]+=1}};var __emval_new_cstring=v=>Emval.toHandle(getStringOrSymbol(v));var __emval_run_destructors=handle=>{var destructors=Emval.toValue(handle);runDestructors(destructors);__emval_decref(handle)};var getHeapMax=()=>2147483648;var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}var alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var _fd_close=fd=>52;var convertI32PairToI53Checked=(lo,hi)=>hi+2097152>>>0<4194305-!!lo?(lo>>>0)+hi*4294967296:NaN;function _fd_seek(fd,offset_low,offset_high,whence,newOffset){var offset=convertI32PairToI53Checked(offset_low,offset_high);return 70}var printCharBuffers=[null,[],[]];var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}};var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j>2]=num;return 0};InternalError=Module["InternalError"]=class InternalError extends Error{constructor(message){super(message);this.name="InternalError"}};embind_init_charCodes();BindingError=Module["BindingError"]=class BindingError extends Error{constructor(message){super(message);this.name="BindingError"}};init_ClassHandle();init_embind();init_RegisteredPointer();UnboundTypeError=Module["UnboundTypeError"]=extendError(Error,"UnboundTypeError");init_emval();var wasmImports={K:___cxa_throw,G:__abort_js,s:__embind_finalize_value_object,C:__embind_register_bigint,I:__embind_register_bool,w:__embind_register_class,v:__embind_register_class_constructor,d:__embind_register_class_function,m:__embind_register_constant,H:__embind_register_emval,o:__embind_register_enum,a:__embind_register_enum_value,A:__embind_register_float,i:__embind_register_function,l:__embind_register_integer,f:__embind_register_memory_view,z:__embind_register_std_string,u:__embind_register_std_wstring,t:__embind_register_value_object,c:__embind_register_value_object_field,J:__embind_register_void,F:__emscripten_memcpy_js,n:__emval_as,q:__emval_call,p:__emval_call_method,b:__emval_decref,x:__emval_get_global,j:__emval_get_method_caller,r:__emval_get_module_property,g:__emval_get_property,k:__emval_incref,h:__emval_new_cstring,e:__emval_run_destructors,D:_emscripten_resize_heap,E:_fd_close,B:_fd_seek,y:_fd_write};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["M"])();var ___getTypeName=a0=>(___getTypeName=wasmExports["N"])(a0);var _malloc=a0=>(_malloc=wasmExports["O"])(a0);var _free=a0=>(_free=wasmExports["Q"])(a0);var ___cxa_is_pointer_type=a0=>(___cxa_is_pointer_type=wasmExports["R"])(a0);var dynCall_jiji=Module["dynCall_jiji"]=(a0,a1,a2,a3,a4)=>(dynCall_jiji=Module["dynCall_jiji"]=wasmExports["S"])(a0,a1,a2,a3,a4);var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();moduleRtn=readyPromise; + + + return moduleRtn; +} +); +})(); +if (typeof exports === 'object' && typeof module === 'object') + module.exports = BASIS; +else if (typeof define === 'function' && define['amd']) + define([], () => BASIS); diff --git a/libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.wasm b/libs/three.js/r171/examples/jsm/libs/basis/basis_transcoder.wasm new file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@y%Bm8+62)@LSLkKo1vQV9s_TIs-Qn@pZZ2g{=e(4 z{=RVrd7y36XJ;@EkHZ~Gd#gVLck{8`C*a-&JqZmhP0T6J&MBfUM^WgSh#PU}GaGg} z>{HOw(9qHZT(z5s+dDbM#f8QG?fMXh(xlJ!VEpZH2jjQ*{QK#MXqvihq0A8^Q literal 0 HcmV?d00001 diff --git a/libs/three.js/r171/examples/jsm/libs/dat.gui.module.js b/libs/three.js/r171/examples/jsm/libs/dat.gui.module.js new file mode 100644 index 000000000..8693a3ff9 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/dat.gui.module.js @@ -0,0 +1,3575 @@ +/** + * dat-gui JavaScript Controller Library + * http://code.google.com/p/dat-gui + * + * Copyright 2011 Data Arts Team, Google Creative Lab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ + +function ___$insertStyle( css ) { + + if ( ! css ) { + + return; + + } + if ( typeof window === 'undefined' ) { + + return; + + } + + var style = document.createElement( 'style' ); + + style.setAttribute( 'type', 'text/css' ); + style.innerHTML = css; + document.head.appendChild( style ); + + return css; + +} + +function colorToString( color, forceCSSHex ) { + + var colorFormat = color.__state.conversionName.toString(); + var r = Math.round( color.r ); + var g = Math.round( color.g ); + var b = Math.round( color.b ); + var a = color.a; + var h = Math.round( color.h ); + var s = color.s.toFixed( 1 ); + var v = color.v.toFixed( 1 ); + if ( forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX' ) { + + var str = color.hex.toString( 16 ); + while ( str.length < 6 ) { + + str = '0' + str; + + } + return '#' + str; + + } else if ( colorFormat === 'CSS_RGB' ) { + + return 'rgb(' + r + ',' + g + ',' + b + ')'; + + } else if ( colorFormat === 'CSS_RGBA' ) { + + return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; + + } else if ( colorFormat === 'HEX' ) { + + return '0x' + color.hex.toString( 16 ); + + } else if ( colorFormat === 'RGB_ARRAY' ) { + + return '[' + r + ',' + g + ',' + b + ']'; + + } else if ( colorFormat === 'RGBA_ARRAY' ) { + + return '[' + r + ',' + g + ',' + b + ',' + a + ']'; + + } else if ( colorFormat === 'RGB_OBJ' ) { + + return '{r:' + r + ',g:' + g + ',b:' + b + '}'; + + } else if ( colorFormat === 'RGBA_OBJ' ) { + + return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}'; + + } else if ( colorFormat === 'HSV_OBJ' ) { + + return '{h:' + h + ',s:' + s + ',v:' + v + '}'; + + } else if ( colorFormat === 'HSVA_OBJ' ) { + + return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}'; + + } + return 'unknown format'; + +} + +var ARR_EACH = Array.prototype.forEach; +var ARR_SLICE = Array.prototype.slice; +var Common = { + BREAK: {}, + extend: function extend( target ) { + + this.each( ARR_SLICE.call( arguments, 1 ), function ( obj ) { + + var keys = this.isObject( obj ) ? Object.keys( obj ) : []; + keys.forEach( function ( key ) { + + if ( ! this.isUndefined( obj[ key ] ) ) { + + target[ key ] = obj[ key ]; + + } + + }.bind( this ) ); + + }, this ); + return target; + + }, + defaults: function defaults( target ) { + + this.each( ARR_SLICE.call( arguments, 1 ), function ( obj ) { + + var keys = this.isObject( obj ) ? Object.keys( obj ) : []; + keys.forEach( function ( key ) { + + if ( this.isUndefined( target[ key ] ) ) { + + target[ key ] = obj[ key ]; + + } + + }.bind( this ) ); + + }, this ); + return target; + + }, + compose: function compose() { + + var toCall = ARR_SLICE.call( arguments ); + return function () { + + var args = ARR_SLICE.call( arguments ); + for ( var i = toCall.length - 1; i >= 0; i -- ) { + + args = [ toCall[ i ].apply( this, args ) ]; + + } + return args[ 0 ]; + + }; + + }, + each: function each( obj, itr, scope ) { + + if ( ! obj ) { + + return; + + } + if ( ARR_EACH && obj.forEach && obj.forEach === ARR_EACH ) { + + obj.forEach( itr, scope ); + + } else if ( obj.length === obj.length + 0 ) { + + var key = void 0; + var l = void 0; + for ( key = 0, l = obj.length; key < l; key ++ ) { + + if ( key in obj && itr.call( scope, obj[ key ], key ) === this.BREAK ) { + + return; + + } + + } + + } else { + + for ( var _key in obj ) { + + if ( itr.call( scope, obj[ _key ], _key ) === this.BREAK ) { + + return; + + } + + } + + } + + }, + defer: function defer( fnc ) { + + setTimeout( fnc, 0 ); + + }, + debounce: function debounce( func, threshold, callImmediately ) { + + var timeout = void 0; + return function () { + + var obj = this; + var args = arguments; + function delayed() { + + timeout = null; + if ( ! callImmediately ) func.apply( obj, args ); + + } + var callNow = callImmediately || ! timeout; + clearTimeout( timeout ); + timeout = setTimeout( delayed, threshold ); + if ( callNow ) { + + func.apply( obj, args ); + + } + + }; + + }, + toArray: function toArray( obj ) { + + if ( obj.toArray ) return obj.toArray(); + return ARR_SLICE.call( obj ); + + }, + isUndefined: function isUndefined( obj ) { + + return obj === undefined; + + }, + isNull: function isNull( obj ) { + + return obj === null; + + }, + isNaN: function ( _isNaN ) { + + function isNaN() { + + return _isNaN.apply( this, arguments ); + + } + isNaN.toString = function () { + + return _isNaN.toString(); + + }; + return isNaN; + + }( function ( obj ) { + + return isNaN( obj ); + + } ), + isArray: Array.isArray || function ( obj ) { + + return obj.constructor === Array; + + }, + isObject: function isObject( obj ) { + + return obj === Object( obj ); + + }, + isNumber: function isNumber( obj ) { + + return obj === obj + 0; + + }, + isString: function isString( obj ) { + + return obj === obj + ''; + + }, + isBoolean: function isBoolean( obj ) { + + return obj === false || obj === true; + + }, + isFunction: function isFunction( obj ) { + + return obj instanceof Function; + + } +}; + +var INTERPRETATIONS = [ + { + litmus: Common.isString, + conversions: { + THREE_CHAR_HEX: { + read: function read( original ) { + + var test = original.match( /^#([A-F0-9])([A-F0-9])([A-F0-9])$/i ); + if ( test === null ) { + + return false; + + } + return { + space: 'HEX', + hex: parseInt( '0x' + test[ 1 ].toString() + test[ 1 ].toString() + test[ 2 ].toString() + test[ 2 ].toString() + test[ 3 ].toString() + test[ 3 ].toString(), 0 ) + }; + + }, + write: colorToString + }, + SIX_CHAR_HEX: { + read: function read( original ) { + + var test = original.match( /^#([A-F0-9]{6})$/i ); + if ( test === null ) { + + return false; + + } + return { + space: 'HEX', + hex: parseInt( '0x' + test[ 1 ].toString(), 0 ) + }; + + }, + write: colorToString + }, + CSS_RGB: { + read: function read( original ) { + + var test = original.match( /^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/ ); + if ( test === null ) { + + return false; + + } + return { + space: 'RGB', + r: parseFloat( test[ 1 ] ), + g: parseFloat( test[ 2 ] ), + b: parseFloat( test[ 3 ] ) + }; + + }, + write: colorToString + }, + CSS_RGBA: { + read: function read( original ) { + + var test = original.match( /^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/ ); + if ( test === null ) { + + return false; + + } + return { + space: 'RGB', + r: parseFloat( test[ 1 ] ), + g: parseFloat( test[ 2 ] ), + b: parseFloat( test[ 3 ] ), + a: parseFloat( test[ 4 ] ) + }; + + }, + write: colorToString + } + } + }, + { + litmus: Common.isNumber, + conversions: { + HEX: { + read: function read( original ) { + + return { + space: 'HEX', + hex: original, + conversionName: 'HEX' + }; + + }, + write: function write( color ) { + + return color.hex; + + } + } + } + }, + { + litmus: Common.isArray, + conversions: { + RGB_ARRAY: { + read: function read( original ) { + + if ( original.length !== 3 ) { + + return false; + + } + return { + space: 'RGB', + r: original[ 0 ], + g: original[ 1 ], + b: original[ 2 ] + }; + + }, + write: function write( color ) { + + return [ color.r, color.g, color.b ]; + + } + }, + RGBA_ARRAY: { + read: function read( original ) { + + if ( original.length !== 4 ) return false; + return { + space: 'RGB', + r: original[ 0 ], + g: original[ 1 ], + b: original[ 2 ], + a: original[ 3 ] + }; + + }, + write: function write( color ) { + + return [ color.r, color.g, color.b, color.a ]; + + } + } + } + }, + { + litmus: Common.isObject, + conversions: { + RGBA_OBJ: { + read: function read( original ) { + + if ( Common.isNumber( original.r ) && Common.isNumber( original.g ) && Common.isNumber( original.b ) && Common.isNumber( original.a ) ) { + + return { + space: 'RGB', + r: original.r, + g: original.g, + b: original.b, + a: original.a + }; + + } + return false; + + }, + write: function write( color ) { + + return { + r: color.r, + g: color.g, + b: color.b, + a: color.a + }; + + } + }, + RGB_OBJ: { + read: function read( original ) { + + if ( Common.isNumber( original.r ) && Common.isNumber( original.g ) && Common.isNumber( original.b ) ) { + + return { + space: 'RGB', + r: original.r, + g: original.g, + b: original.b + }; + + } + return false; + + }, + write: function write( color ) { + + return { + r: color.r, + g: color.g, + b: color.b + }; + + } + }, + HSVA_OBJ: { + read: function read( original ) { + + if ( Common.isNumber( original.h ) && Common.isNumber( original.s ) && Common.isNumber( original.v ) && Common.isNumber( original.a ) ) { + + return { + space: 'HSV', + h: original.h, + s: original.s, + v: original.v, + a: original.a + }; + + } + return false; + + }, + write: function write( color ) { + + return { + h: color.h, + s: color.s, + v: color.v, + a: color.a + }; + + } + }, + HSV_OBJ: { + read: function read( original ) { + + if ( Common.isNumber( original.h ) && Common.isNumber( original.s ) && Common.isNumber( original.v ) ) { + + return { + space: 'HSV', + h: original.h, + s: original.s, + v: original.v + }; + + } + return false; + + }, + write: function write( color ) { + + return { + h: color.h, + s: color.s, + v: color.v + }; + + } + } + } + } ]; +var result = void 0; +var toReturn = void 0; +var interpret = function interpret() { + + toReturn = false; + var original = arguments.length > 1 ? Common.toArray( arguments ) : arguments[ 0 ]; + Common.each( INTERPRETATIONS, function ( family ) { + + if ( family.litmus( original ) ) { + + Common.each( family.conversions, function ( conversion, conversionName ) { + + result = conversion.read( original ); + if ( toReturn === false && result !== false ) { + + toReturn = result; + result.conversionName = conversionName; + result.conversion = conversion; + return Common.BREAK; + + } + + } ); + return Common.BREAK; + + } + + } ); + return toReturn; + +}; + +var tmpComponent = void 0; +var ColorMath = { + hsv_to_rgb: function hsv_to_rgb( h, s, v ) { + + var hi = Math.floor( h / 60 ) % 6; + var f = h / 60 - Math.floor( h / 60 ); + var p = v * ( 1.0 - s ); + var q = v * ( 1.0 - f * s ); + var t = v * ( 1.0 - ( 1.0 - f ) * s ); + var c = [[ v, t, p ], [ q, v, p ], [ p, v, t ], [ p, q, v ], [ t, p, v ], [ v, p, q ]][ hi ]; + return { + r: c[ 0 ] * 255, + g: c[ 1 ] * 255, + b: c[ 2 ] * 255 + }; + + }, + rgb_to_hsv: function rgb_to_hsv( r, g, b ) { + + var min = Math.min( r, g, b ); + var max = Math.max( r, g, b ); + var delta = max - min; + var h = void 0; + var s = void 0; + if ( max !== 0 ) { + + s = delta / max; + + } else { + + return { + h: NaN, + s: 0, + v: 0 + }; + + } + if ( r === max ) { + + h = ( g - b ) / delta; + + } else if ( g === max ) { + + h = 2 + ( b - r ) / delta; + + } else { + + h = 4 + ( r - g ) / delta; + + } + h /= 6; + if ( h < 0 ) { + + h += 1; + + } + return { + h: h * 360, + s: s, + v: max / 255 + }; + + }, + rgb_to_hex: function rgb_to_hex( r, g, b ) { + + var hex = this.hex_with_component( 0, 2, r ); + hex = this.hex_with_component( hex, 1, g ); + hex = this.hex_with_component( hex, 0, b ); + return hex; + + }, + component_from_hex: function component_from_hex( hex, componentIndex ) { + + return hex >> componentIndex * 8 & 0xFF; + + }, + hex_with_component: function hex_with_component( hex, componentIndex, value ) { + + return value << ( tmpComponent = componentIndex * 8 ) | hex & ~ ( 0xFF << tmpComponent ); + + } +}; + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function ( obj ) { + + return typeof obj; + +} : function ( obj ) { + + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + +}; + + + + + + + + + + + +var classCallCheck = function ( instance, Constructor ) { + + if ( ! ( instance instanceof Constructor ) ) { + + throw new TypeError( "Cannot call a class as a function" ); + + } + +}; + +var createClass = function () { + + function defineProperties( target, props ) { + + for ( var i = 0; i < props.length; i ++ ) { + + var descriptor = props[ i ]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ( "value" in descriptor ) descriptor.writable = true; + Object.defineProperty( target, descriptor.key, descriptor ); + + } + + } + + return function ( Constructor, protoProps, staticProps ) { + + if ( protoProps ) defineProperties( Constructor.prototype, protoProps ); + if ( staticProps ) defineProperties( Constructor, staticProps ); + return Constructor; + + }; + +}(); + + + + + + + +var get = function get( object, property, receiver ) { + + if ( object === null ) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor( object, property ); + + if ( desc === undefined ) { + + var parent = Object.getPrototypeOf( object ); + + if ( parent === null ) { + + return undefined; + + } else { + + return get( parent, property, receiver ); + + } + + } else if ( "value" in desc ) { + + return desc.value; + + } else { + + var getter = desc.get; + + if ( getter === undefined ) { + + return undefined; + + } + + return getter.call( receiver ); + + } + +}; + +var inherits = function ( subClass, superClass ) { + + if ( typeof superClass !== "function" && superClass !== null ) { + + throw new TypeError( "Super expression must either be null or a function, not " + typeof superClass ); + + } + + subClass.prototype = Object.create( superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + } ); + if ( superClass ) Object.setPrototypeOf ? Object.setPrototypeOf( subClass, superClass ) : subClass.__proto__ = superClass; + +}; + + + + + + + + + + + +var possibleConstructorReturn = function ( self, call ) { + + if ( ! self ) { + + throw new ReferenceError( "this hasn't been initialised - super() hasn't been called" ); + + } + + return call && ( typeof call === "object" || typeof call === "function" ) ? call : self; + +}; + +var Color = function () { + + function Color() { + + classCallCheck( this, Color ); + this.__state = interpret.apply( this, arguments ); + if ( this.__state === false ) { + + throw new Error( 'Failed to interpret color arguments' ); + + } + this.__state.a = this.__state.a || 1; + + } + createClass( Color, [ { + key: 'toString', + value: function toString() { + + return colorToString( this ); + + } + }, { + key: 'toHexString', + value: function toHexString() { + + return colorToString( this, true ); + + } + }, { + key: 'toOriginal', + value: function toOriginal() { + + return this.__state.conversion.write( this ); + + } + } ] ); + return Color; + +}(); +function defineRGBComponent( target, component, componentHexIndex ) { + + Object.defineProperty( target, component, { + get: function get$$1() { + + if ( this.__state.space === 'RGB' ) { + + return this.__state[ component ]; + + } + Color.recalculateRGB( this, component, componentHexIndex ); + return this.__state[ component ]; + + }, + set: function set$$1( v ) { + + if ( this.__state.space !== 'RGB' ) { + + Color.recalculateRGB( this, component, componentHexIndex ); + this.__state.space = 'RGB'; + + } + this.__state[ component ] = v; + + } + } ); + +} +function defineHSVComponent( target, component ) { + + Object.defineProperty( target, component, { + get: function get$$1() { + + if ( this.__state.space === 'HSV' ) { + + return this.__state[ component ]; + + } + Color.recalculateHSV( this ); + return this.__state[ component ]; + + }, + set: function set$$1( v ) { + + if ( this.__state.space !== 'HSV' ) { + + Color.recalculateHSV( this ); + this.__state.space = 'HSV'; + + } + this.__state[ component ] = v; + + } + } ); + +} +Color.recalculateRGB = function ( color, component, componentHexIndex ) { + + if ( color.__state.space === 'HEX' ) { + + color.__state[ component ] = ColorMath.component_from_hex( color.__state.hex, componentHexIndex ); + + } else if ( color.__state.space === 'HSV' ) { + + Common.extend( color.__state, ColorMath.hsv_to_rgb( color.__state.h, color.__state.s, color.__state.v ) ); + + } else { + + throw new Error( 'Corrupted color state' ); + + } + +}; +Color.recalculateHSV = function ( color ) { + + var result = ColorMath.rgb_to_hsv( color.r, color.g, color.b ); + Common.extend( color.__state, { + s: result.s, + v: result.v + } ); + if ( ! Common.isNaN( result.h ) ) { + + color.__state.h = result.h; + + } else if ( Common.isUndefined( color.__state.h ) ) { + + color.__state.h = 0; + + } + +}; +Color.COMPONENTS = [ 'r', 'g', 'b', 'h', 's', 'v', 'hex', 'a' ]; +defineRGBComponent( Color.prototype, 'r', 2 ); +defineRGBComponent( Color.prototype, 'g', 1 ); +defineRGBComponent( Color.prototype, 'b', 0 ); +defineHSVComponent( Color.prototype, 'h' ); +defineHSVComponent( Color.prototype, 's' ); +defineHSVComponent( Color.prototype, 'v' ); +Object.defineProperty( Color.prototype, 'a', { + get: function get$$1() { + + return this.__state.a; + + }, + set: function set$$1( v ) { + + this.__state.a = v; + + } +} ); +Object.defineProperty( Color.prototype, 'hex', { + get: function get$$1() { + + if ( this.__state.space !== 'HEX' ) { + + this.__state.hex = ColorMath.rgb_to_hex( this.r, this.g, this.b ); + this.__state.space = 'HEX'; + + } + return this.__state.hex; + + }, + set: function set$$1( v ) { + + this.__state.space = 'HEX'; + this.__state.hex = v; + + } +} ); + +var Controller = function () { + + function Controller( object, property ) { + + classCallCheck( this, Controller ); + this.initialValue = object[ property ]; + this.domElement = document.createElement( 'div' ); + this.object = object; + this.property = property; + this.__onChange = undefined; + this.__onFinishChange = undefined; + + } + createClass( Controller, [ { + key: 'onChange', + value: function onChange( fnc ) { + + this.__onChange = fnc; + return this; + + } + }, { + key: 'onFinishChange', + value: function onFinishChange( fnc ) { + + this.__onFinishChange = fnc; + return this; + + } + }, { + key: 'setValue', + value: function setValue( newValue ) { + + this.object[ this.property ] = newValue; + if ( this.__onChange ) { + + this.__onChange.call( this, newValue ); + + } + this.updateDisplay(); + return this; + + } + }, { + key: 'getValue', + value: function getValue() { + + return this.object[ this.property ]; + + } + }, { + key: 'updateDisplay', + value: function updateDisplay() { + + return this; + + } + }, { + key: 'isModified', + value: function isModified() { + + return this.initialValue !== this.getValue(); + + } + } ] ); + return Controller; + +}(); + +var EVENT_MAP = { + HTMLEvents: [ 'change' ], + MouseEvents: [ 'click', 'mousemove', 'mousedown', 'mouseup', 'mouseover' ], + KeyboardEvents: [ 'keydown' ] +}; +var EVENT_MAP_INV = {}; +Common.each( EVENT_MAP, function ( v, k ) { + + Common.each( v, function ( e ) { + + EVENT_MAP_INV[ e ] = k; + + } ); + +} ); +var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/; +function cssValueToPixels( val ) { + + if ( val === '0' || Common.isUndefined( val ) ) { + + return 0; + + } + var match = val.match( CSS_VALUE_PIXELS ); + if ( ! Common.isNull( match ) ) { + + return parseFloat( match[ 1 ] ); + + } + return 0; + +} +var dom = { + makeSelectable: function makeSelectable( elem, selectable ) { + + if ( elem === undefined || elem.style === undefined ) return; + elem.onselectstart = selectable ? function () { + + return false; + + } : function () {}; + elem.style.MozUserSelect = selectable ? 'auto' : 'none'; + elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none'; + elem.unselectable = selectable ? 'on' : 'off'; + + }, + makeFullscreen: function makeFullscreen( elem, hor, vert ) { + + var vertical = vert; + var horizontal = hor; + if ( Common.isUndefined( horizontal ) ) { + + horizontal = true; + + } + if ( Common.isUndefined( vertical ) ) { + + vertical = true; + + } + elem.style.position = 'absolute'; + if ( horizontal ) { + + elem.style.left = 0; + elem.style.right = 0; + + } + if ( vertical ) { + + elem.style.top = 0; + elem.style.bottom = 0; + + } + + }, + fakeEvent: function fakeEvent( elem, eventType, pars, aux ) { + + var params = pars || {}; + var className = EVENT_MAP_INV[ eventType ]; + if ( ! className ) { + + throw new Error( 'Event type ' + eventType + ' not supported.' ); + + } + var evt = document.createEvent( className ); + switch ( className ) { + + case 'MouseEvents': + { + + var clientX = params.x || params.clientX || 0; + var clientY = params.y || params.clientY || 0; + evt.initMouseEvent( eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, + 0, + clientX, + clientY, + false, false, false, false, 0, null ); + break; + + } + case 'KeyboardEvents': + { + + var init = evt.initKeyboardEvent || evt.initKeyEvent; + Common.defaults( params, { + cancelable: true, + ctrlKey: false, + altKey: false, + shiftKey: false, + metaKey: false, + keyCode: undefined, + charCode: undefined + } ); + init( eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode ); + break; + + } + default: + { + + evt.initEvent( eventType, params.bubbles || false, params.cancelable || true ); + break; + + } + + } + Common.defaults( evt, aux ); + elem.dispatchEvent( evt ); + + }, + bind: function bind( elem, event, func, newBool ) { + + var bool = newBool || false; + if ( elem.addEventListener ) { + + elem.addEventListener( event, func, bool ); + + } else if ( elem.attachEvent ) { + + elem.attachEvent( 'on' + event, func ); + + } + return dom; + + }, + unbind: function unbind( elem, event, func, newBool ) { + + var bool = newBool || false; + if ( elem.removeEventListener ) { + + elem.removeEventListener( event, func, bool ); + + } else if ( elem.detachEvent ) { + + elem.detachEvent( 'on' + event, func ); + + } + return dom; + + }, + addClass: function addClass( elem, className ) { + + if ( elem.className === undefined ) { + + elem.className = className; + + } else if ( elem.className !== className ) { + + var classes = elem.className.split( / +/ ); + if ( classes.indexOf( className ) === - 1 ) { + + classes.push( className ); + elem.className = classes.join( ' ' ).replace( /^\s+/, '' ).replace( /\s+$/, '' ); + + } + + } + return dom; + + }, + removeClass: function removeClass( elem, className ) { + + if ( className ) { + + if ( elem.className === className ) { + + elem.removeAttribute( 'class' ); + + } else { + + var classes = elem.className.split( / +/ ); + var index = classes.indexOf( className ); + if ( index !== - 1 ) { + + classes.splice( index, 1 ); + elem.className = classes.join( ' ' ); + + } + + } + + } else { + + elem.className = undefined; + + } + return dom; + + }, + hasClass: function hasClass( elem, className ) { + + return new RegExp( '(?:^|\\s+)' + className + '(?:\\s+|$)' ).test( elem.className ) || false; + + }, + getWidth: function getWidth( elem ) { + + var style = getComputedStyle( elem ); + return cssValueToPixels( style[ 'border-left-width' ] ) + cssValueToPixels( style[ 'border-right-width' ] ) + cssValueToPixels( style[ 'padding-left' ] ) + cssValueToPixels( style[ 'padding-right' ] ) + cssValueToPixels( style.width ); + + }, + getHeight: function getHeight( elem ) { + + var style = getComputedStyle( elem ); + return cssValueToPixels( style[ 'border-top-width' ] ) + cssValueToPixels( style[ 'border-bottom-width' ] ) + cssValueToPixels( style[ 'padding-top' ] ) + cssValueToPixels( style[ 'padding-bottom' ] ) + cssValueToPixels( style.height ); + + }, + getOffset: function getOffset( el ) { + + var elem = el; + var offset = { left: 0, top: 0 }; + if ( elem.offsetParent ) { + + do { + + offset.left += elem.offsetLeft; + offset.top += elem.offsetTop; + elem = elem.offsetParent; + + } while ( elem ); + + } + return offset; + + }, + isActive: function isActive( elem ) { + + return elem === document.activeElement && ( elem.type || elem.href ); + + } +}; + +var BooleanController = function ( _Controller ) { + + inherits( BooleanController, _Controller ); + function BooleanController( object, property ) { + + classCallCheck( this, BooleanController ); + var _this2 = possibleConstructorReturn( this, ( BooleanController.__proto__ || Object.getPrototypeOf( BooleanController ) ).call( this, object, property ) ); + var _this = _this2; + _this2.__prev = _this2.getValue(); + _this2.__checkbox = document.createElement( 'input' ); + _this2.__checkbox.setAttribute( 'type', 'checkbox' ); + function onChange() { + + _this.setValue( ! _this.__prev ); + + } + dom.bind( _this2.__checkbox, 'change', onChange, false ); + _this2.domElement.appendChild( _this2.__checkbox ); + _this2.updateDisplay(); + return _this2; + + } + createClass( BooleanController, [ { + key: 'setValue', + value: function setValue( v ) { + + var toReturn = get( BooleanController.prototype.__proto__ || Object.getPrototypeOf( BooleanController.prototype ), 'setValue', this ).call( this, v ); + if ( this.__onFinishChange ) { + + this.__onFinishChange.call( this, this.getValue() ); + + } + this.__prev = this.getValue(); + return toReturn; + + } + }, { + key: 'updateDisplay', + value: function updateDisplay() { + + if ( this.getValue() === true ) { + + this.__checkbox.setAttribute( 'checked', 'checked' ); + this.__checkbox.checked = true; + this.__prev = true; + + } else { + + this.__checkbox.checked = false; + this.__prev = false; + + } + return get( BooleanController.prototype.__proto__ || Object.getPrototypeOf( BooleanController.prototype ), 'updateDisplay', this ).call( this ); + + } + } ] ); + return BooleanController; + +}( Controller ); + +var OptionController = function ( _Controller ) { + + inherits( OptionController, _Controller ); + function OptionController( object, property, opts ) { + + classCallCheck( this, OptionController ); + var _this2 = possibleConstructorReturn( this, ( OptionController.__proto__ || Object.getPrototypeOf( OptionController ) ).call( this, object, property ) ); + var options = opts; + var _this = _this2; + _this2.__select = document.createElement( 'select' ); + if ( Common.isArray( options ) ) { + + var map = {}; + Common.each( options, function ( element ) { + + map[ element ] = element; + + } ); + options = map; + + } + Common.each( options, function ( value, key ) { + + var opt = document.createElement( 'option' ); + opt.innerHTML = key; + opt.setAttribute( 'value', value ); + _this.__select.appendChild( opt ); + + } ); + _this2.updateDisplay(); + dom.bind( _this2.__select, 'change', function () { + + var desiredValue = this.options[ this.selectedIndex ].value; + _this.setValue( desiredValue ); + + } ); + _this2.domElement.appendChild( _this2.__select ); + return _this2; + + } + createClass( OptionController, [ { + key: 'setValue', + value: function setValue( v ) { + + var toReturn = get( OptionController.prototype.__proto__ || Object.getPrototypeOf( OptionController.prototype ), 'setValue', this ).call( this, v ); + if ( this.__onFinishChange ) { + + this.__onFinishChange.call( this, this.getValue() ); + + } + return toReturn; + + } + }, { + key: 'updateDisplay', + value: function updateDisplay() { + + if ( dom.isActive( this.__select ) ) return this; + this.__select.value = this.getValue(); + return get( OptionController.prototype.__proto__ || Object.getPrototypeOf( OptionController.prototype ), 'updateDisplay', this ).call( this ); + + } + } ] ); + return OptionController; + +}( Controller ); + +var StringController = function ( _Controller ) { + + inherits( StringController, _Controller ); + function StringController( object, property ) { + + classCallCheck( this, StringController ); + var _this2 = possibleConstructorReturn( this, ( StringController.__proto__ || Object.getPrototypeOf( StringController ) ).call( this, object, property ) ); + var _this = _this2; + function onChange() { + + _this.setValue( _this.__input.value ); + + } + function onBlur() { + + if ( _this.__onFinishChange ) { + + _this.__onFinishChange.call( _this, _this.getValue() ); + + } + + } + _this2.__input = document.createElement( 'input' ); + _this2.__input.setAttribute( 'type', 'text' ); + dom.bind( _this2.__input, 'keyup', onChange ); + dom.bind( _this2.__input, 'change', onChange ); + dom.bind( _this2.__input, 'blur', onBlur ); + dom.bind( _this2.__input, 'keydown', function ( e ) { + + if ( e.keyCode === 13 ) { + + this.blur(); + + } + + } ); + _this2.updateDisplay(); + _this2.domElement.appendChild( _this2.__input ); + return _this2; + + } + createClass( StringController, [ { + key: 'updateDisplay', + value: function updateDisplay() { + + if ( ! dom.isActive( this.__input ) ) { + + this.__input.value = this.getValue(); + + } + return get( StringController.prototype.__proto__ || Object.getPrototypeOf( StringController.prototype ), 'updateDisplay', this ).call( this ); + + } + } ] ); + return StringController; + +}( Controller ); + +function numDecimals( x ) { + + var _x = x.toString(); + if ( _x.indexOf( '.' ) > - 1 ) { + + return _x.length - _x.indexOf( '.' ) - 1; + + } + return 0; + +} +var NumberController = function ( _Controller ) { + + inherits( NumberController, _Controller ); + function NumberController( object, property, params ) { + + classCallCheck( this, NumberController ); + var _this = possibleConstructorReturn( this, ( NumberController.__proto__ || Object.getPrototypeOf( NumberController ) ).call( this, object, property ) ); + var _params = params || {}; + _this.__min = _params.min; + _this.__max = _params.max; + _this.__step = _params.step; + if ( Common.isUndefined( _this.__step ) ) { + + if ( _this.initialValue === 0 ) { + + _this.__impliedStep = 1; + + } else { + + _this.__impliedStep = Math.pow( 10, Math.floor( Math.log( Math.abs( _this.initialValue ) ) / Math.LN10 ) ) / 10; + + } + + } else { + + _this.__impliedStep = _this.__step; + + } + _this.__precision = numDecimals( _this.__impliedStep ); + return _this; + + } + createClass( NumberController, [ { + key: 'setValue', + value: function setValue( v ) { + + var _v = v; + if ( this.__min !== undefined && _v < this.__min ) { + + _v = this.__min; + + } else if ( this.__max !== undefined && _v > this.__max ) { + + _v = this.__max; + + } + if ( this.__step !== undefined && _v % this.__step !== 0 ) { + + _v = Math.round( _v / this.__step ) * this.__step; + + } + return get( NumberController.prototype.__proto__ || Object.getPrototypeOf( NumberController.prototype ), 'setValue', this ).call( this, _v ); + + } + }, { + key: 'min', + value: function min( minValue ) { + + this.__min = minValue; + return this; + + } + }, { + key: 'max', + value: function max( maxValue ) { + + this.__max = maxValue; + return this; + + } + }, { + key: 'step', + value: function step( stepValue ) { + + this.__step = stepValue; + this.__impliedStep = stepValue; + this.__precision = numDecimals( stepValue ); + return this; + + } + } ] ); + return NumberController; + +}( Controller ); + +function roundToDecimal( value, decimals ) { + + var tenTo = Math.pow( 10, decimals ); + return Math.round( value * tenTo ) / tenTo; + +} +var NumberControllerBox = function ( _NumberController ) { + + inherits( NumberControllerBox, _NumberController ); + function NumberControllerBox( object, property, params ) { + + classCallCheck( this, NumberControllerBox ); + var _this2 = possibleConstructorReturn( this, ( NumberControllerBox.__proto__ || Object.getPrototypeOf( NumberControllerBox ) ).call( this, object, property, params ) ); + _this2.__truncationSuspended = false; + var _this = _this2; + var prevY = void 0; + function onChange() { + + var attempted = parseFloat( _this.__input.value ); + if ( ! Common.isNaN( attempted ) ) { + + _this.setValue( attempted ); + + } + + } + function onFinish() { + + if ( _this.__onFinishChange ) { + + _this.__onFinishChange.call( _this, _this.getValue() ); + + } + + } + function onBlur() { + + onFinish(); + + } + function onMouseDrag( e ) { + + var diff = prevY - e.clientY; + _this.setValue( _this.getValue() + diff * _this.__impliedStep ); + prevY = e.clientY; + + } + function onMouseUp() { + + dom.unbind( window, 'mousemove', onMouseDrag ); + dom.unbind( window, 'mouseup', onMouseUp ); + onFinish(); + + } + function onMouseDown( e ) { + + dom.bind( window, 'mousemove', onMouseDrag ); + dom.bind( window, 'mouseup', onMouseUp ); + prevY = e.clientY; + + } + _this2.__input = document.createElement( 'input' ); + _this2.__input.setAttribute( 'type', 'text' ); + dom.bind( _this2.__input, 'change', onChange ); + dom.bind( _this2.__input, 'blur', onBlur ); + dom.bind( _this2.__input, 'mousedown', onMouseDown ); + dom.bind( _this2.__input, 'keydown', function ( e ) { + + if ( e.keyCode === 13 ) { + + _this.__truncationSuspended = true; + this.blur(); + _this.__truncationSuspended = false; + onFinish(); + + } + + } ); + _this2.updateDisplay(); + _this2.domElement.appendChild( _this2.__input ); + return _this2; + + } + createClass( NumberControllerBox, [ { + key: 'updateDisplay', + value: function updateDisplay() { + + this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal( this.getValue(), this.__precision ); + return get( NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf( NumberControllerBox.prototype ), 'updateDisplay', this ).call( this ); + + } + } ] ); + return NumberControllerBox; + +}( NumberController ); + +function map( v, i1, i2, o1, o2 ) { + + return o1 + ( o2 - o1 ) * ( ( v - i1 ) / ( i2 - i1 ) ); + +} +var NumberControllerSlider = function ( _NumberController ) { + + inherits( NumberControllerSlider, _NumberController ); + function NumberControllerSlider( object, property, min, max, step ) { + + classCallCheck( this, NumberControllerSlider ); + var _this2 = possibleConstructorReturn( this, ( NumberControllerSlider.__proto__ || Object.getPrototypeOf( NumberControllerSlider ) ).call( this, object, property, { min: min, max: max, step: step } ) ); + var _this = _this2; + _this2.__background = document.createElement( 'div' ); + _this2.__foreground = document.createElement( 'div' ); + dom.bind( _this2.__background, 'mousedown', onMouseDown ); + dom.bind( _this2.__background, 'touchstart', onTouchStart ); + dom.addClass( _this2.__background, 'slider' ); + dom.addClass( _this2.__foreground, 'slider-fg' ); + function onMouseDown( e ) { + + document.activeElement.blur(); + dom.bind( window, 'mousemove', onMouseDrag ); + dom.bind( window, 'mouseup', onMouseUp ); + onMouseDrag( e ); + + } + function onMouseDrag( e ) { + + e.preventDefault(); + var bgRect = _this.__background.getBoundingClientRect(); + _this.setValue( map( e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max ) ); + return false; + + } + function onMouseUp() { + + dom.unbind( window, 'mousemove', onMouseDrag ); + dom.unbind( window, 'mouseup', onMouseUp ); + if ( _this.__onFinishChange ) { + + _this.__onFinishChange.call( _this, _this.getValue() ); + + } + + } + function onTouchStart( e ) { + + if ( e.touches.length !== 1 ) { + + return; + + } + dom.bind( window, 'touchmove', onTouchMove ); + dom.bind( window, 'touchend', onTouchEnd ); + onTouchMove( e ); + + } + function onTouchMove( e ) { + + var clientX = e.touches[ 0 ].clientX; + var bgRect = _this.__background.getBoundingClientRect(); + _this.setValue( map( clientX, bgRect.left, bgRect.right, _this.__min, _this.__max ) ); + + } + function onTouchEnd() { + + dom.unbind( window, 'touchmove', onTouchMove ); + dom.unbind( window, 'touchend', onTouchEnd ); + if ( _this.__onFinishChange ) { + + _this.__onFinishChange.call( _this, _this.getValue() ); + + } + + } + _this2.updateDisplay(); + _this2.__background.appendChild( _this2.__foreground ); + _this2.domElement.appendChild( _this2.__background ); + return _this2; + + } + createClass( NumberControllerSlider, [ { + key: 'updateDisplay', + value: function updateDisplay() { + + var pct = ( this.getValue() - this.__min ) / ( this.__max - this.__min ); + this.__foreground.style.width = pct * 100 + '%'; + return get( NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf( NumberControllerSlider.prototype ), 'updateDisplay', this ).call( this ); + + } + } ] ); + return NumberControllerSlider; + +}( NumberController ); + +var FunctionController = function ( _Controller ) { + + inherits( FunctionController, _Controller ); + function FunctionController( object, property, text ) { + + classCallCheck( this, FunctionController ); + var _this2 = possibleConstructorReturn( this, ( FunctionController.__proto__ || Object.getPrototypeOf( FunctionController ) ).call( this, object, property ) ); + var _this = _this2; + _this2.__button = document.createElement( 'div' ); + _this2.__button.innerHTML = text === undefined ? 'Fire' : text; + dom.bind( _this2.__button, 'click', function ( e ) { + + e.preventDefault(); + _this.fire(); + return false; + + } ); + dom.addClass( _this2.__button, 'button' ); + _this2.domElement.appendChild( _this2.__button ); + return _this2; + + } + createClass( FunctionController, [ { + key: 'fire', + value: function fire() { + + if ( this.__onChange ) { + + this.__onChange.call( this ); + + } + this.getValue().call( this.object ); + if ( this.__onFinishChange ) { + + this.__onFinishChange.call( this, this.getValue() ); + + } + + } + } ] ); + return FunctionController; + +}( Controller ); + +var ColorController = function ( _Controller ) { + + inherits( ColorController, _Controller ); + function ColorController( object, property ) { + + classCallCheck( this, ColorController ); + var _this2 = possibleConstructorReturn( this, ( ColorController.__proto__ || Object.getPrototypeOf( ColorController ) ).call( this, object, property ) ); + _this2.__color = new Color( _this2.getValue() ); + _this2.__temp = new Color( 0 ); + var _this = _this2; + _this2.domElement = document.createElement( 'div' ); + dom.makeSelectable( _this2.domElement, false ); + _this2.__selector = document.createElement( 'div' ); + _this2.__selector.className = 'selector'; + _this2.__saturation_field = document.createElement( 'div' ); + _this2.__saturation_field.className = 'saturation-field'; + _this2.__field_knob = document.createElement( 'div' ); + _this2.__field_knob.className = 'field-knob'; + _this2.__field_knob_border = '2px solid '; + _this2.__hue_knob = document.createElement( 'div' ); + _this2.__hue_knob.className = 'hue-knob'; + _this2.__hue_field = document.createElement( 'div' ); + _this2.__hue_field.className = 'hue-field'; + _this2.__input = document.createElement( 'input' ); + _this2.__input.type = 'text'; + _this2.__input_textShadow = '0 1px 1px '; + dom.bind( _this2.__input, 'keydown', function ( e ) { + + if ( e.keyCode === 13 ) { + + onBlur.call( this ); + + } + + } ); + dom.bind( _this2.__input, 'blur', onBlur ); + dom.bind( _this2.__selector, 'mousedown', function () { + + dom.addClass( this, 'drag' ).bind( window, 'mouseup', function () { + + dom.removeClass( _this.__selector, 'drag' ); + + } ); + + } ); + dom.bind( _this2.__selector, 'touchstart', function () { + + dom.addClass( this, 'drag' ).bind( window, 'touchend', function () { + + dom.removeClass( _this.__selector, 'drag' ); + + } ); + + } ); + var valueField = document.createElement( 'div' ); + Common.extend( _this2.__selector.style, { + width: '122px', + height: '102px', + padding: '3px', + backgroundColor: '#222', + boxShadow: '0px 1px 3px rgba(0,0,0,0.3)' + } ); + Common.extend( _this2.__field_knob.style, { + position: 'absolute', + width: '12px', + height: '12px', + border: _this2.__field_knob_border + ( _this2.__color.v < 0.5 ? '#fff' : '#000' ), + boxShadow: '0px 1px 3px rgba(0,0,0,0.5)', + borderRadius: '12px', + zIndex: 1 + } ); + Common.extend( _this2.__hue_knob.style, { + position: 'absolute', + width: '15px', + height: '2px', + borderRight: '4px solid #fff', + zIndex: 1 + } ); + Common.extend( _this2.__saturation_field.style, { + width: '100px', + height: '100px', + border: '1px solid #555', + marginRight: '3px', + display: 'inline-block', + cursor: 'pointer' + } ); + Common.extend( valueField.style, { + width: '100%', + height: '100%', + background: 'none' + } ); + linearGradient( valueField, 'top', 'rgba(0,0,0,0)', '#000' ); + Common.extend( _this2.__hue_field.style, { + width: '15px', + height: '100px', + border: '1px solid #555', + cursor: 'ns-resize', + position: 'absolute', + top: '3px', + right: '3px' + } ); + hueGradient( _this2.__hue_field ); + Common.extend( _this2.__input.style, { + outline: 'none', + textAlign: 'center', + color: '#fff', + border: 0, + fontWeight: 'bold', + textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)' + } ); + dom.bind( _this2.__saturation_field, 'mousedown', fieldDown ); + dom.bind( _this2.__saturation_field, 'touchstart', fieldDown ); + dom.bind( _this2.__field_knob, 'mousedown', fieldDown ); + dom.bind( _this2.__field_knob, 'touchstart', fieldDown ); + dom.bind( _this2.__hue_field, 'mousedown', fieldDownH ); + dom.bind( _this2.__hue_field, 'touchstart', fieldDownH ); + function fieldDown( e ) { + + setSV( e ); + dom.bind( window, 'mousemove', setSV ); + dom.bind( window, 'touchmove', setSV ); + dom.bind( window, 'mouseup', fieldUpSV ); + dom.bind( window, 'touchend', fieldUpSV ); + + } + function fieldDownH( e ) { + + setH( e ); + dom.bind( window, 'mousemove', setH ); + dom.bind( window, 'touchmove', setH ); + dom.bind( window, 'mouseup', fieldUpH ); + dom.bind( window, 'touchend', fieldUpH ); + + } + function fieldUpSV() { + + dom.unbind( window, 'mousemove', setSV ); + dom.unbind( window, 'touchmove', setSV ); + dom.unbind( window, 'mouseup', fieldUpSV ); + dom.unbind( window, 'touchend', fieldUpSV ); + onFinish(); + + } + function fieldUpH() { + + dom.unbind( window, 'mousemove', setH ); + dom.unbind( window, 'touchmove', setH ); + dom.unbind( window, 'mouseup', fieldUpH ); + dom.unbind( window, 'touchend', fieldUpH ); + onFinish(); + + } + function onBlur() { + + var i = interpret( this.value ); + if ( i !== false ) { + + _this.__color.__state = i; + _this.setValue( _this.__color.toOriginal() ); + + } else { + + this.value = _this.__color.toString(); + + } + + } + function onFinish() { + + if ( _this.__onFinishChange ) { + + _this.__onFinishChange.call( _this, _this.__color.toOriginal() ); + + } + + } + _this2.__saturation_field.appendChild( valueField ); + _this2.__selector.appendChild( _this2.__field_knob ); + _this2.__selector.appendChild( _this2.__saturation_field ); + _this2.__selector.appendChild( _this2.__hue_field ); + _this2.__hue_field.appendChild( _this2.__hue_knob ); + _this2.domElement.appendChild( _this2.__input ); + _this2.domElement.appendChild( _this2.__selector ); + _this2.updateDisplay(); + function setSV( e ) { + + if ( e.type.indexOf( 'touch' ) === - 1 ) { + + e.preventDefault(); + + } + var fieldRect = _this.__saturation_field.getBoundingClientRect(); + var _ref = e.touches && e.touches[ 0 ] || e, + clientX = _ref.clientX, + clientY = _ref.clientY; + var s = ( clientX - fieldRect.left ) / ( fieldRect.right - fieldRect.left ); + var v = 1 - ( clientY - fieldRect.top ) / ( fieldRect.bottom - fieldRect.top ); + if ( v > 1 ) { + + v = 1; + + } else if ( v < 0 ) { + + v = 0; + + } + if ( s > 1 ) { + + s = 1; + + } else if ( s < 0 ) { + + s = 0; + + } + _this.__color.v = v; + _this.__color.s = s; + _this.setValue( _this.__color.toOriginal() ); + return false; + + } + function setH( e ) { + + if ( e.type.indexOf( 'touch' ) === - 1 ) { + + e.preventDefault(); + + } + var fieldRect = _this.__hue_field.getBoundingClientRect(); + var _ref2 = e.touches && e.touches[ 0 ] || e, + clientY = _ref2.clientY; + var h = 1 - ( clientY - fieldRect.top ) / ( fieldRect.bottom - fieldRect.top ); + if ( h > 1 ) { + + h = 1; + + } else if ( h < 0 ) { + + h = 0; + + } + _this.__color.h = h * 360; + _this.setValue( _this.__color.toOriginal() ); + return false; + + } + return _this2; + + } + createClass( ColorController, [ { + key: 'updateDisplay', + value: function updateDisplay() { + + var i = interpret( this.getValue() ); + if ( i !== false ) { + + var mismatch = false; + Common.each( Color.COMPONENTS, function ( component ) { + + if ( ! Common.isUndefined( i[ component ] ) && ! Common.isUndefined( this.__color.__state[ component ] ) && i[ component ] !== this.__color.__state[ component ] ) { + + mismatch = true; + return {}; + + } + + }, this ); + if ( mismatch ) { + + Common.extend( this.__color.__state, i ); + + } + + } + Common.extend( this.__temp.__state, this.__color.__state ); + this.__temp.a = 1; + var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0; + var _flip = 255 - flip; + Common.extend( this.__field_knob.style, { + marginLeft: 100 * this.__color.s - 7 + 'px', + marginTop: 100 * ( 1 - this.__color.v ) - 7 + 'px', + backgroundColor: this.__temp.toHexString(), + border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')' + } ); + this.__hue_knob.style.marginTop = ( 1 - this.__color.h / 360 ) * 100 + 'px'; + this.__temp.s = 1; + this.__temp.v = 1; + linearGradient( this.__saturation_field, 'left', '#fff', this.__temp.toHexString() ); + this.__input.value = this.__color.toString(); + Common.extend( this.__input.style, { + backgroundColor: this.__color.toHexString(), + color: 'rgb(' + flip + ',' + flip + ',' + flip + ')', + textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)' + } ); + + } + } ] ); + return ColorController; + +}( Controller ); +var vendors = [ '-moz-', '-o-', '-webkit-', '-ms-', '' ]; +function linearGradient( elem, x, a, b ) { + + elem.style.background = ''; + Common.each( vendors, function ( vendor ) { + + elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); '; + + } ); + +} +function hueGradient( elem ) { + + elem.style.background = ''; + elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);'; + elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + +} + +var css = { + load: function load( url, indoc ) { + + var doc = indoc || document; + var link = doc.createElement( 'link' ); + link.type = 'text/css'; + link.rel = 'stylesheet'; + link.href = url; + doc.getElementsByTagName( 'head' )[ 0 ].appendChild( link ); + + }, + inject: function inject( cssContent, indoc ) { + + var doc = indoc || document; + var injected = document.createElement( 'style' ); + injected.type = 'text/css'; + injected.innerHTML = cssContent; + var head = doc.getElementsByTagName( 'head' )[ 0 ]; + try { + + head.appendChild( injected ); + + } catch ( e ) { + } + + } +}; + +var saveDialogContents = "

"; + +var ControllerFactory = function ControllerFactory( object, property ) { + + var initialValue = object[ property ]; + if ( Common.isArray( arguments[ 2 ] ) || Common.isObject( arguments[ 2 ] ) ) { + + return new OptionController( object, property, arguments[ 2 ] ); + + } + if ( Common.isNumber( initialValue ) ) { + + if ( Common.isNumber( arguments[ 2 ] ) && Common.isNumber( arguments[ 3 ] ) ) { + + if ( Common.isNumber( arguments[ 4 ] ) ) { + + return new NumberControllerSlider( object, property, arguments[ 2 ], arguments[ 3 ], arguments[ 4 ] ); + + } + return new NumberControllerSlider( object, property, arguments[ 2 ], arguments[ 3 ] ); + + } + if ( Common.isNumber( arguments[ 4 ] ) ) { + + return new NumberControllerBox( object, property, { min: arguments[ 2 ], max: arguments[ 3 ], step: arguments[ 4 ] } ); + + } + return new NumberControllerBox( object, property, { min: arguments[ 2 ], max: arguments[ 3 ] } ); + + } + if ( Common.isString( initialValue ) ) { + + return new StringController( object, property ); + + } + if ( Common.isFunction( initialValue ) ) { + + return new FunctionController( object, property, '' ); + + } + if ( Common.isBoolean( initialValue ) ) { + + return new BooleanController( object, property ); + + } + return null; + +}; + +function requestAnimationFrame( callback ) { + + setTimeout( callback, 1000 / 60 ); + +} +var requestAnimationFrame$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame; + +var CenteredDiv = function () { + + function CenteredDiv() { + + classCallCheck( this, CenteredDiv ); + this.backgroundElement = document.createElement( 'div' ); + Common.extend( this.backgroundElement.style, { + backgroundColor: 'rgba(0,0,0,0.8)', + top: 0, + left: 0, + display: 'none', + zIndex: '1000', + opacity: 0, + WebkitTransition: 'opacity 0.2s linear', + transition: 'opacity 0.2s linear' + } ); + dom.makeFullscreen( this.backgroundElement ); + this.backgroundElement.style.position = 'fixed'; + this.domElement = document.createElement( 'div' ); + Common.extend( this.domElement.style, { + position: 'fixed', + display: 'none', + zIndex: '1001', + opacity: 0, + WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear', + transition: 'transform 0.2s ease-out, opacity 0.2s linear' + } ); + document.body.appendChild( this.backgroundElement ); + document.body.appendChild( this.domElement ); + var _this = this; + dom.bind( this.backgroundElement, 'click', function () { + + _this.hide(); + + } ); + + } + createClass( CenteredDiv, [ { + key: 'show', + value: function show() { + + var _this = this; + this.backgroundElement.style.display = 'block'; + this.domElement.style.display = 'block'; + this.domElement.style.opacity = 0; + this.domElement.style.webkitTransform = 'scale(1.1)'; + this.layout(); + Common.defer( function () { + + _this.backgroundElement.style.opacity = 1; + _this.domElement.style.opacity = 1; + _this.domElement.style.webkitTransform = 'scale(1)'; + + } ); + + } + }, { + key: 'hide', + value: function hide() { + + var _this = this; + var hide = function hide() { + + _this.domElement.style.display = 'none'; + _this.backgroundElement.style.display = 'none'; + dom.unbind( _this.domElement, 'webkitTransitionEnd', hide ); + dom.unbind( _this.domElement, 'transitionend', hide ); + dom.unbind( _this.domElement, 'oTransitionEnd', hide ); + + }; + dom.bind( this.domElement, 'webkitTransitionEnd', hide ); + dom.bind( this.domElement, 'transitionend', hide ); + dom.bind( this.domElement, 'oTransitionEnd', hide ); + this.backgroundElement.style.opacity = 0; + this.domElement.style.opacity = 0; + this.domElement.style.webkitTransform = 'scale(1.1)'; + + } + }, { + key: 'layout', + value: function layout() { + + this.domElement.style.left = window.innerWidth / 2 - dom.getWidth( this.domElement ) / 2 + 'px'; + this.domElement.style.top = window.innerHeight / 2 - dom.getHeight( this.domElement ) / 2 + 'px'; + + } + } ] ); + return CenteredDiv; + +}(); + +var styleSheet = ___$insertStyle( ".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n" ); + +css.inject( styleSheet ); +var CSS_NAMESPACE = 'dg'; +var HIDE_KEY_CODE = 72; +var CLOSE_BUTTON_HEIGHT = 20; +var DEFAULT_DEFAULT_PRESET_NAME = 'Default'; +var SUPPORTS_LOCAL_STORAGE = function () { + + try { + + return !! window.localStorage; + + } catch ( e ) { + + return false; + + } + +}(); +var SAVE_DIALOGUE = void 0; +var autoPlaceVirgin = true; +var autoPlaceContainer = void 0; +var hide = false; +var hideableGuis = []; +var GUI = function GUI( pars ) { + + var _this = this; + var params = pars || {}; + this.domElement = document.createElement( 'div' ); + this.__ul = document.createElement( 'ul' ); + this.domElement.appendChild( this.__ul ); + dom.addClass( this.domElement, CSS_NAMESPACE ); + this.__folders = {}; + this.__controllers = []; + this.__rememberedObjects = []; + this.__rememberedObjectIndecesToControllers = []; + this.__listening = []; + params = Common.defaults( params, { + closeOnTop: false, + autoPlace: true, + width: GUI.DEFAULT_WIDTH + } ); + params = Common.defaults( params, { + resizable: params.autoPlace, + hideable: params.autoPlace + } ); + if ( ! Common.isUndefined( params.load ) ) { + + if ( params.preset ) { + + params.load.preset = params.preset; + + } + + } else { + + params.load = { preset: DEFAULT_DEFAULT_PRESET_NAME }; + + } + if ( Common.isUndefined( params.parent ) && params.hideable ) { + + hideableGuis.push( this ); + + } + params.resizable = Common.isUndefined( params.parent ) && params.resizable; + if ( params.autoPlace && Common.isUndefined( params.scrollable ) ) { + + params.scrollable = true; + + } + var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem( getLocalStorageHash( this, 'isLocal' ) ) === 'true'; + var saveToLocalStorage = void 0; + var titleRow = void 0; + Object.defineProperties( this, + { + parent: { + get: function get$$1() { + + return params.parent; + + } + }, + scrollable: { + get: function get$$1() { + + return params.scrollable; + + } + }, + autoPlace: { + get: function get$$1() { + + return params.autoPlace; + + } + }, + closeOnTop: { + get: function get$$1() { + + return params.closeOnTop; + + } + }, + preset: { + get: function get$$1() { + + if ( _this.parent ) { + + return _this.getRoot().preset; + + } + return params.load.preset; + + }, + set: function set$$1( v ) { + + if ( _this.parent ) { + + _this.getRoot().preset = v; + + } else { + + params.load.preset = v; + + } + setPresetSelectIndex( this ); + _this.revert(); + + } + }, + width: { + get: function get$$1() { + + return params.width; + + }, + set: function set$$1( v ) { + + params.width = v; + setWidth( _this, v ); + + } + }, + name: { + get: function get$$1() { + + return params.name; + + }, + set: function set$$1( v ) { + + params.name = v; + if ( titleRow ) { + + titleRow.innerHTML = params.name; + + } + + } + }, + closed: { + get: function get$$1() { + + return params.closed; + + }, + set: function set$$1( v ) { + + params.closed = v; + if ( params.closed ) { + + dom.addClass( _this.__ul, GUI.CLASS_CLOSED ); + + } else { + + dom.removeClass( _this.__ul, GUI.CLASS_CLOSED ); + + } + this.onResize(); + if ( _this.__closeButton ) { + + _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED; + + } + + } + }, + load: { + get: function get$$1() { + + return params.load; + + } + }, + useLocalStorage: { + get: function get$$1() { + + return useLocalStorage; + + }, + set: function set$$1( bool ) { + + if ( SUPPORTS_LOCAL_STORAGE ) { + + useLocalStorage = bool; + if ( bool ) { + + dom.bind( window, 'unload', saveToLocalStorage ); + + } else { + + dom.unbind( window, 'unload', saveToLocalStorage ); + + } + localStorage.setItem( getLocalStorageHash( _this, 'isLocal' ), bool ); + + } + + } + } + } ); + if ( Common.isUndefined( params.parent ) ) { + + this.closed = params.closed || false; + dom.addClass( this.domElement, GUI.CLASS_MAIN ); + dom.makeSelectable( this.domElement, false ); + if ( SUPPORTS_LOCAL_STORAGE ) { + + if ( useLocalStorage ) { + + _this.useLocalStorage = true; + var savedGui = localStorage.getItem( getLocalStorageHash( this, 'gui' ) ); + if ( savedGui ) { + + params.load = JSON.parse( savedGui ); + + } + + } + + } + this.__closeButton = document.createElement( 'div' ); + this.__closeButton.innerHTML = GUI.TEXT_CLOSED; + dom.addClass( this.__closeButton, GUI.CLASS_CLOSE_BUTTON ); + if ( params.closeOnTop ) { + + dom.addClass( this.__closeButton, GUI.CLASS_CLOSE_TOP ); + this.domElement.insertBefore( this.__closeButton, this.domElement.childNodes[ 0 ] ); + + } else { + + dom.addClass( this.__closeButton, GUI.CLASS_CLOSE_BOTTOM ); + this.domElement.appendChild( this.__closeButton ); + + } + dom.bind( this.__closeButton, 'click', function () { + + _this.closed = ! _this.closed; + + } ); + + } else { + + if ( params.closed === undefined ) { + + params.closed = true; + + } + var titleRowName = document.createTextNode( params.name ); + dom.addClass( titleRowName, 'controller-name' ); + titleRow = addRow( _this, titleRowName ); + var onClickTitle = function onClickTitle( e ) { + + e.preventDefault(); + _this.closed = ! _this.closed; + return false; + + }; + dom.addClass( this.__ul, GUI.CLASS_CLOSED ); + dom.addClass( titleRow, 'title' ); + dom.bind( titleRow, 'click', onClickTitle ); + if ( ! params.closed ) { + + this.closed = false; + + } + + } + if ( params.autoPlace ) { + + if ( Common.isUndefined( params.parent ) ) { + + if ( autoPlaceVirgin ) { + + autoPlaceContainer = document.createElement( 'div' ); + dom.addClass( autoPlaceContainer, CSS_NAMESPACE ); + dom.addClass( autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER ); + document.body.appendChild( autoPlaceContainer ); + autoPlaceVirgin = false; + + } + autoPlaceContainer.appendChild( this.domElement ); + dom.addClass( this.domElement, GUI.CLASS_AUTO_PLACE ); + + } + if ( ! this.parent ) { + + setWidth( _this, params.width ); + + } + + } + this.__resizeHandler = function () { + + _this.onResizeDebounced(); + + }; + dom.bind( window, 'resize', this.__resizeHandler ); + dom.bind( this.__ul, 'webkitTransitionEnd', this.__resizeHandler ); + dom.bind( this.__ul, 'transitionend', this.__resizeHandler ); + dom.bind( this.__ul, 'oTransitionEnd', this.__resizeHandler ); + this.onResize(); + if ( params.resizable ) { + + addResizeHandle( this ); + + } + saveToLocalStorage = function saveToLocalStorage() { + + if ( SUPPORTS_LOCAL_STORAGE && localStorage.getItem( getLocalStorageHash( _this, 'isLocal' ) ) === 'true' ) { + + localStorage.setItem( getLocalStorageHash( _this, 'gui' ), JSON.stringify( _this.getSaveObject() ) ); + + } + + }; + this.saveToLocalStorageIfPossible = saveToLocalStorage; + function resetWidth() { + + var root = _this.getRoot(); + root.width += 1; + Common.defer( function () { + + root.width -= 1; + + } ); + + } + if ( ! params.parent ) { + + resetWidth(); + + } + +}; +GUI.toggleHide = function () { + + hide = ! hide; + Common.each( hideableGuis, function ( gui ) { + + gui.domElement.style.display = hide ? 'none' : ''; + + } ); + +}; +GUI.CLASS_AUTO_PLACE = 'a'; +GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac'; +GUI.CLASS_MAIN = 'main'; +GUI.CLASS_CONTROLLER_ROW = 'cr'; +GUI.CLASS_TOO_TALL = 'taller-than-window'; +GUI.CLASS_CLOSED = 'closed'; +GUI.CLASS_CLOSE_BUTTON = 'close-button'; +GUI.CLASS_CLOSE_TOP = 'close-top'; +GUI.CLASS_CLOSE_BOTTOM = 'close-bottom'; +GUI.CLASS_DRAG = 'drag'; +GUI.DEFAULT_WIDTH = 245; +GUI.TEXT_CLOSED = 'Close Controls'; +GUI.TEXT_OPEN = 'Open Controls'; +GUI._keydownHandler = function ( e ) { + + if ( document.activeElement.type !== 'text' && ( e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE ) ) { + + GUI.toggleHide(); + + } + +}; +dom.bind( window, 'keydown', GUI._keydownHandler, false ); +Common.extend( GUI.prototype, + { + add: function add( object, property ) { + + return _add( this, object, property, { + factoryArgs: Array.prototype.slice.call( arguments, 2 ) + } ); + + }, + addColor: function addColor( object, property ) { + + return _add( this, object, property, { + color: true + } ); + + }, + remove: function remove( controller ) { + + this.__ul.removeChild( controller.__li ); + this.__controllers.splice( this.__controllers.indexOf( controller ), 1 ); + var _this = this; + Common.defer( function () { + + _this.onResize(); + + } ); + + }, + destroy: function destroy() { + + if ( this.parent ) { + + throw new Error( 'Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.' ); + + } + if ( this.autoPlace ) { + + autoPlaceContainer.removeChild( this.domElement ); + + } + var _this = this; + Common.each( this.__folders, function ( subfolder ) { + + _this.removeFolder( subfolder ); + + } ); + dom.unbind( window, 'keydown', GUI._keydownHandler, false ); + removeListeners( this ); + + }, + addFolder: function addFolder( name ) { + + if ( this.__folders[ name ] !== undefined ) { + + throw new Error( 'You already have a folder in this GUI by the' + ' name "' + name + '"' ); + + } + var newGuiParams = { name: name, parent: this }; + newGuiParams.autoPlace = this.autoPlace; + if ( this.load && + this.load.folders && + this.load.folders[ name ] ) { + + newGuiParams.closed = this.load.folders[ name ].closed; + newGuiParams.load = this.load.folders[ name ]; + + } + var gui = new GUI( newGuiParams ); + this.__folders[ name ] = gui; + var li = addRow( this, gui.domElement ); + dom.addClass( li, 'folder' ); + return gui; + + }, + removeFolder: function removeFolder( folder ) { + + this.__ul.removeChild( folder.domElement.parentElement ); + delete this.__folders[ folder.name ]; + if ( this.load && + this.load.folders && + this.load.folders[ folder.name ] ) { + + delete this.load.folders[ folder.name ]; + + } + removeListeners( folder ); + var _this = this; + Common.each( folder.__folders, function ( subfolder ) { + + folder.removeFolder( subfolder ); + + } ); + Common.defer( function () { + + _this.onResize(); + + } ); + + }, + open: function open() { + + this.closed = false; + + }, + close: function close() { + + this.closed = true; + + }, + hide: function hide() { + + this.domElement.style.display = 'none'; + + }, + show: function show() { + + this.domElement.style.display = ''; + + }, + onResize: function onResize() { + + var root = this.getRoot(); + if ( root.scrollable ) { + + var top = dom.getOffset( root.__ul ).top; + var h = 0; + Common.each( root.__ul.childNodes, function ( node ) { + + if ( ! ( root.autoPlace && node === root.__save_row ) ) { + + h += dom.getHeight( node ); + + } + + } ); + if ( window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h ) { + + dom.addClass( root.domElement, GUI.CLASS_TOO_TALL ); + root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px'; + + } else { + + dom.removeClass( root.domElement, GUI.CLASS_TOO_TALL ); + root.__ul.style.height = 'auto'; + + } + + } + if ( root.__resize_handle ) { + + Common.defer( function () { + + root.__resize_handle.style.height = root.__ul.offsetHeight + 'px'; + + } ); + + } + if ( root.__closeButton ) { + + root.__closeButton.style.width = root.width + 'px'; + + } + + }, + onResizeDebounced: Common.debounce( function () { + + this.onResize(); + + }, 50 ), + remember: function remember() { + + if ( Common.isUndefined( SAVE_DIALOGUE ) ) { + + SAVE_DIALOGUE = new CenteredDiv(); + SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents; + + } + if ( this.parent ) { + + throw new Error( 'You can only call remember on a top level GUI.' ); + + } + var _this = this; + Common.each( Array.prototype.slice.call( arguments ), function ( object ) { + + if ( _this.__rememberedObjects.length === 0 ) { + + addSaveMenu( _this ); + + } + if ( _this.__rememberedObjects.indexOf( object ) === - 1 ) { + + _this.__rememberedObjects.push( object ); + + } + + } ); + if ( this.autoPlace ) { + + setWidth( this, this.width ); + + } + + }, + getRoot: function getRoot() { + + var gui = this; + while ( gui.parent ) { + + gui = gui.parent; + + } + return gui; + + }, + getSaveObject: function getSaveObject() { + + var toReturn = this.load; + toReturn.closed = this.closed; + if ( this.__rememberedObjects.length > 0 ) { + + toReturn.preset = this.preset; + if ( ! toReturn.remembered ) { + + toReturn.remembered = {}; + + } + toReturn.remembered[ this.preset ] = getCurrentPreset( this ); + + } + toReturn.folders = {}; + Common.each( this.__folders, function ( element, key ) { + + toReturn.folders[ key ] = element.getSaveObject(); + + } ); + return toReturn; + + }, + save: function save() { + + if ( ! this.load.remembered ) { + + this.load.remembered = {}; + + } + this.load.remembered[ this.preset ] = getCurrentPreset( this ); + markPresetModified( this, false ); + this.saveToLocalStorageIfPossible(); + + }, + saveAs: function saveAs( presetName ) { + + if ( ! this.load.remembered ) { + + this.load.remembered = {}; + this.load.remembered[ DEFAULT_DEFAULT_PRESET_NAME ] = getCurrentPreset( this, true ); + + } + this.load.remembered[ presetName ] = getCurrentPreset( this ); + this.preset = presetName; + addPresetOption( this, presetName, true ); + this.saveToLocalStorageIfPossible(); + + }, + revert: function revert( gui ) { + + Common.each( this.__controllers, function ( controller ) { + + if ( ! this.getRoot().load.remembered ) { + + controller.setValue( controller.initialValue ); + + } else { + + recallSavedValue( gui || this.getRoot(), controller ); + + } + if ( controller.__onFinishChange ) { + + controller.__onFinishChange.call( controller, controller.getValue() ); + + } + + }, this ); + Common.each( this.__folders, function ( folder ) { + + folder.revert( folder ); + + } ); + if ( ! gui ) { + + markPresetModified( this.getRoot(), false ); + + } + + }, + listen: function listen( controller ) { + + var init = this.__listening.length === 0; + this.__listening.push( controller ); + if ( init ) { + + updateDisplays( this.__listening ); + + } + + }, + updateDisplay: function updateDisplay() { + + Common.each( this.__controllers, function ( controller ) { + + controller.updateDisplay(); + + } ); + Common.each( this.__folders, function ( folder ) { + + folder.updateDisplay(); + + } ); + + } + } ); +function addRow( gui, newDom, liBefore ) { + + var li = document.createElement( 'li' ); + if ( newDom ) { + + li.appendChild( newDom ); + + } + if ( liBefore ) { + + gui.__ul.insertBefore( li, liBefore ); + + } else { + + gui.__ul.appendChild( li ); + + } + gui.onResize(); + return li; + +} +function removeListeners( gui ) { + + dom.unbind( window, 'resize', gui.__resizeHandler ); + if ( gui.saveToLocalStorageIfPossible ) { + + dom.unbind( window, 'unload', gui.saveToLocalStorageIfPossible ); + + } + +} +function markPresetModified( gui, modified ) { + + var opt = gui.__preset_select[ gui.__preset_select.selectedIndex ]; + if ( modified ) { + + opt.innerHTML = opt.value + '*'; + + } else { + + opt.innerHTML = opt.value; + + } + +} +function augmentController( gui, li, controller ) { + + controller.__li = li; + controller.__gui = gui; + Common.extend( controller, { + options: function options( _options ) { + + if ( arguments.length > 1 ) { + + var nextSibling = controller.__li.nextElementSibling; + controller.remove(); + return _add( gui, controller.object, controller.property, { + before: nextSibling, + factoryArgs: [ Common.toArray( arguments ) ] + } ); + + } + if ( Common.isArray( _options ) || Common.isObject( _options ) ) { + + var _nextSibling = controller.__li.nextElementSibling; + controller.remove(); + return _add( gui, controller.object, controller.property, { + before: _nextSibling, + factoryArgs: [ _options ] + } ); + + } + + }, + name: function name( _name ) { + + controller.__li.firstElementChild.firstElementChild.innerHTML = _name; + return controller; + + }, + listen: function listen() { + + controller.__gui.listen( controller ); + return controller; + + }, + remove: function remove() { + + controller.__gui.remove( controller ); + return controller; + + } + } ); + if ( controller instanceof NumberControllerSlider ) { + + var box = new NumberControllerBox( controller.object, controller.property, { min: controller.__min, max: controller.__max, step: controller.__step } ); + Common.each( [ 'updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max' ], function ( method ) { + + var pc = controller[ method ]; + var pb = box[ method ]; + controller[ method ] = box[ method ] = function () { + + var args = Array.prototype.slice.call( arguments ); + pb.apply( box, args ); + return pc.apply( controller, args ); + + }; + + } ); + dom.addClass( li, 'has-slider' ); + controller.domElement.insertBefore( box.domElement, controller.domElement.firstElementChild ); + + } else if ( controller instanceof NumberControllerBox ) { + + var r = function r( returned ) { + + if ( Common.isNumber( controller.__min ) && Common.isNumber( controller.__max ) ) { + + var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML; + var wasListening = controller.__gui.__listening.indexOf( controller ) > - 1; + controller.remove(); + var newController = _add( gui, controller.object, controller.property, { + before: controller.__li.nextElementSibling, + factoryArgs: [ controller.__min, controller.__max, controller.__step ] + } ); + newController.name( oldName ); + if ( wasListening ) newController.listen(); + return newController; + + } + return returned; + + }; + controller.min = Common.compose( r, controller.min ); + controller.max = Common.compose( r, controller.max ); + + } else if ( controller instanceof BooleanController ) { + + dom.bind( li, 'click', function () { + + dom.fakeEvent( controller.__checkbox, 'click' ); + + } ); + dom.bind( controller.__checkbox, 'click', function ( e ) { + + e.stopPropagation(); + + } ); + + } else if ( controller instanceof FunctionController ) { + + dom.bind( li, 'click', function () { + + dom.fakeEvent( controller.__button, 'click' ); + + } ); + dom.bind( li, 'mouseover', function () { + + dom.addClass( controller.__button, 'hover' ); + + } ); + dom.bind( li, 'mouseout', function () { + + dom.removeClass( controller.__button, 'hover' ); + + } ); + + } else if ( controller instanceof ColorController ) { + + dom.addClass( li, 'color' ); + controller.updateDisplay = Common.compose( function ( val ) { + + li.style.borderLeftColor = controller.__color.toString(); + return val; + + }, controller.updateDisplay ); + controller.updateDisplay(); + + } + controller.setValue = Common.compose( function ( val ) { + + if ( gui.getRoot().__preset_select && controller.isModified() ) { + + markPresetModified( gui.getRoot(), true ); + + } + return val; + + }, controller.setValue ); + +} +function recallSavedValue( gui, controller ) { + + var root = gui.getRoot(); + var matchedIndex = root.__rememberedObjects.indexOf( controller.object ); + if ( matchedIndex !== - 1 ) { + + var controllerMap = root.__rememberedObjectIndecesToControllers[ matchedIndex ]; + if ( controllerMap === undefined ) { + + controllerMap = {}; + root.__rememberedObjectIndecesToControllers[ matchedIndex ] = controllerMap; + + } + controllerMap[ controller.property ] = controller; + if ( root.load && root.load.remembered ) { + + var presetMap = root.load.remembered; + var preset = void 0; + if ( presetMap[ gui.preset ] ) { + + preset = presetMap[ gui.preset ]; + + } else if ( presetMap[ DEFAULT_DEFAULT_PRESET_NAME ] ) { + + preset = presetMap[ DEFAULT_DEFAULT_PRESET_NAME ]; + + } else { + + return; + + } + if ( preset[ matchedIndex ] && preset[ matchedIndex ][ controller.property ] !== undefined ) { + + var value = preset[ matchedIndex ][ controller.property ]; + controller.initialValue = value; + controller.setValue( value ); + + } + + } + + } + +} +function _add( gui, object, property, params ) { + + if ( object[ property ] === undefined ) { + + throw new Error( 'Object "' + object + '" has no property "' + property + '"' ); + + } + var controller = void 0; + if ( params.color ) { + + controller = new ColorController( object, property ); + + } else { + + var factoryArgs = [ object, property ].concat( params.factoryArgs ); + controller = ControllerFactory.apply( gui, factoryArgs ); + + } + if ( params.before instanceof Controller ) { + + params.before = params.before.__li; + + } + recallSavedValue( gui, controller ); + dom.addClass( controller.domElement, 'c' ); + var name = document.createElement( 'span' ); + dom.addClass( name, 'property-name' ); + name.innerHTML = controller.property; + var container = document.createElement( 'div' ); + container.appendChild( name ); + container.appendChild( controller.domElement ); + var li = addRow( gui, container, params.before ); + dom.addClass( li, GUI.CLASS_CONTROLLER_ROW ); + if ( controller instanceof ColorController ) { + + dom.addClass( li, 'color' ); + + } else { + + dom.addClass( li, _typeof( controller.getValue() ) ); + + } + augmentController( gui, li, controller ); + gui.__controllers.push( controller ); + return controller; + +} +function getLocalStorageHash( gui, key ) { + + return document.location.href + '.' + key; + +} +function addPresetOption( gui, name, setSelected ) { + + var opt = document.createElement( 'option' ); + opt.innerHTML = name; + opt.value = name; + gui.__preset_select.appendChild( opt ); + if ( setSelected ) { + + gui.__preset_select.selectedIndex = gui.__preset_select.length - 1; + + } + +} +function showHideExplain( gui, explain ) { + + explain.style.display = gui.useLocalStorage ? 'block' : 'none'; + +} +function addSaveMenu( gui ) { + + var div = gui.__save_row = document.createElement( 'li' ); + dom.addClass( gui.domElement, 'has-save' ); + gui.__ul.insertBefore( div, gui.__ul.firstChild ); + dom.addClass( div, 'save-row' ); + var gears = document.createElement( 'span' ); + gears.innerHTML = ' '; + dom.addClass( gears, 'button gears' ); + var button = document.createElement( 'span' ); + button.innerHTML = 'Save'; + dom.addClass( button, 'button' ); + dom.addClass( button, 'save' ); + var button2 = document.createElement( 'span' ); + button2.innerHTML = 'New'; + dom.addClass( button2, 'button' ); + dom.addClass( button2, 'save-as' ); + var button3 = document.createElement( 'span' ); + button3.innerHTML = 'Revert'; + dom.addClass( button3, 'button' ); + dom.addClass( button3, 'revert' ); + var select = gui.__preset_select = document.createElement( 'select' ); + if ( gui.load && gui.load.remembered ) { + + Common.each( gui.load.remembered, function ( value, key ) { + + addPresetOption( gui, key, key === gui.preset ); + + } ); + + } else { + + addPresetOption( gui, DEFAULT_DEFAULT_PRESET_NAME, false ); + + } + dom.bind( select, 'change', function () { + + for ( var index = 0; index < gui.__preset_select.length; index ++ ) { + + gui.__preset_select[ index ].innerHTML = gui.__preset_select[ index ].value; + + } + gui.preset = this.value; + + } ); + div.appendChild( select ); + div.appendChild( gears ); + div.appendChild( button ); + div.appendChild( button2 ); + div.appendChild( button3 ); + if ( SUPPORTS_LOCAL_STORAGE ) { + + var explain = document.getElementById( 'dg-local-explain' ); + var localStorageCheckBox = document.getElementById( 'dg-local-storage' ); + var saveLocally = document.getElementById( 'dg-save-locally' ); + saveLocally.style.display = 'block'; + if ( localStorage.getItem( getLocalStorageHash( gui, 'isLocal' ) ) === 'true' ) { + + localStorageCheckBox.setAttribute( 'checked', 'checked' ); + + } + showHideExplain( gui, explain ); + dom.bind( localStorageCheckBox, 'change', function () { + + gui.useLocalStorage = ! gui.useLocalStorage; + showHideExplain( gui, explain ); + + } ); + + } + var newConstructorTextArea = document.getElementById( 'dg-new-constructor' ); + dom.bind( newConstructorTextArea, 'keydown', function ( e ) { + + if ( e.metaKey && ( e.which === 67 || e.keyCode === 67 ) ) { + + SAVE_DIALOGUE.hide(); + + } + + } ); + dom.bind( gears, 'click', function () { + + newConstructorTextArea.innerHTML = JSON.stringify( gui.getSaveObject(), undefined, 2 ); + SAVE_DIALOGUE.show(); + newConstructorTextArea.focus(); + newConstructorTextArea.select(); + + } ); + dom.bind( button, 'click', function () { + + gui.save(); + + } ); + dom.bind( button2, 'click', function () { + + var presetName = prompt( 'Enter a new preset name.' ); + if ( presetName ) { + + gui.saveAs( presetName ); + + } + + } ); + dom.bind( button3, 'click', function () { + + gui.revert(); + + } ); + +} +function addResizeHandle( gui ) { + + var pmouseX = void 0; + gui.__resize_handle = document.createElement( 'div' ); + Common.extend( gui.__resize_handle.style, { + width: '6px', + marginLeft: '-3px', + height: '200px', + cursor: 'ew-resize', + position: 'absolute' + } ); + function drag( e ) { + + e.preventDefault(); + gui.width += pmouseX - e.clientX; + gui.onResize(); + pmouseX = e.clientX; + return false; + + } + function dragStop() { + + dom.removeClass( gui.__closeButton, GUI.CLASS_DRAG ); + dom.unbind( window, 'mousemove', drag ); + dom.unbind( window, 'mouseup', dragStop ); + + } + function dragStart( e ) { + + e.preventDefault(); + pmouseX = e.clientX; + dom.addClass( gui.__closeButton, GUI.CLASS_DRAG ); + dom.bind( window, 'mousemove', drag ); + dom.bind( window, 'mouseup', dragStop ); + return false; + + } + dom.bind( gui.__resize_handle, 'mousedown', dragStart ); + dom.bind( gui.__closeButton, 'mousedown', dragStart ); + gui.domElement.insertBefore( gui.__resize_handle, gui.domElement.firstElementChild ); + +} +function setWidth( gui, w ) { + + gui.domElement.style.width = w + 'px'; + if ( gui.__save_row && gui.autoPlace ) { + + gui.__save_row.style.width = w + 'px'; + + } + if ( gui.__closeButton ) { + + gui.__closeButton.style.width = w + 'px'; + + } + +} +function getCurrentPreset( gui, useInitialValues ) { + + var toReturn = {}; + Common.each( gui.__rememberedObjects, function ( val, index ) { + + var savedValues = {}; + var controllerMap = gui.__rememberedObjectIndecesToControllers[ index ]; + Common.each( controllerMap, function ( controller, property ) { + + savedValues[ property ] = useInitialValues ? controller.initialValue : controller.getValue(); + + } ); + toReturn[ index ] = savedValues; + + } ); + return toReturn; + +} +function setPresetSelectIndex( gui ) { + + for ( var index = 0; index < gui.__preset_select.length; index ++ ) { + + if ( gui.__preset_select[ index ].value === gui.preset ) { + + gui.__preset_select.selectedIndex = index; + + } + + } + +} +function updateDisplays( controllerArray ) { + + if ( controllerArray.length !== 0 ) { + + requestAnimationFrame$1.call( window, function () { + + updateDisplays( controllerArray ); + + } ); + + } + Common.each( controllerArray, function ( c ) { + + c.updateDisplay(); + + } ); + +} + +var color = { + Color: Color, + math: ColorMath, + interpret: interpret +}; +var controllers = { + Controller: Controller, + BooleanController: BooleanController, + OptionController: OptionController, + StringController: StringController, + NumberController: NumberController, + NumberControllerBox: NumberControllerBox, + NumberControllerSlider: NumberControllerSlider, + FunctionController: FunctionController, + ColorController: ColorController +}; +var dom$1 = { dom: dom }; +var gui = { GUI: GUI }; +var GUI$1 = GUI; +var index = { + color: color, + controllers: controllers, + dom: dom$1, + gui: gui, + GUI: GUI$1 +}; + +export { color, controllers, dom$1 as dom, gui, GUI$1 as GUI }; +export default index; diff --git a/libs/three.js/r171/examples/jsm/libs/draco/draco_decoder.js b/libs/three.js/r171/examples/jsm/libs/draco/draco_decoder.js new file mode 100644 index 000000000..6629469b2 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/draco/draco_decoder.js @@ -0,0 +1,34 @@ + +var DracoDecoderModule = (() => { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; + return ( +function(DracoDecoderModule = {}) { + +var Module=typeof DracoDecoderModule!="undefined"?DracoDecoderModule:{};var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise(function(resolve,reject){readyPromiseResolve=resolve;readyPromiseReject=reject});var isRuntimeInitialized=false;var isModuleParsed=false;Module["onRuntimeInitialized"]=function(){isRuntimeInitialized=true;if(isModuleParsed){if(typeof Module["onModuleLoaded"]==="function"){Module["onModuleLoaded"](Module)}}};Module["onModuleParsed"]=function(){isModuleParsed=true;if(isRuntimeInitialized){if(typeof Module["onModuleLoaded"]==="function"){Module["onModuleLoaded"](Module)}}};function isVersionSupported(versionString){if(typeof versionString!=="string")return false;const version=versionString.split(".");if(version.length<2||version.length>3)return false;if(version[0]==1&&version[1]>=0&&version[1]<=5)return true;if(version[0]!=0||version[1]>10)return false;return true}Module["isVersionSupported"]=isVersionSupported;var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;function logExceptionOnExit(e){if(e instanceof ExitStatus)return;let toLog=e;err("exiting due to exception: "+toLog)}if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");if(ENVIRONMENT_IS_WORKER){scriptDirectory=nodePath.dirname(scriptDirectory)+"/"}else{scriptDirectory=__dirname+"/"}read_=(filename,binary)=>{var ret=tryParseAsDataURI(filename);if(ret){return binary?ret:ret.toString()}filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return fs.readFileSync(filename,binary?undefined:"utf8")};readBinary=filename=>{var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}return ret};readAsync=(filename,onload,onerror)=>{var ret=tryParseAsDataURI(filename);if(ret){onload(ret)}filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);fs.readFile(filename,function(err,data){if(err)onerror(err);else onload(data.buffer)})};if(process["argv"].length>1){thisProgram=process["argv"][1].replace(/\\/g,"/")}arguments_=process["argv"].slice(2);quit_=(status,toThrow)=>{if(keepRuntimeAlive()){process["exitCode"]=status;throw toThrow}logExceptionOnExit(toThrow);process["exit"](status)};Module["inspect"]=function(){return"[Emscripten Module object]"}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptDir){scriptDirectory=_scriptDir}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{try{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText}catch(err){var data=tryParseAsDataURI(url);if(data){return intArrayToString(data)}throw err}};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{try{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}catch(err){var data=tryParseAsDataURI(url);if(data){return data}throw err}}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}var data=tryParseAsDataURI(url);if(data){onload(data.buffer);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}setWindowTitle=title=>document.title=title}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;var WebAssembly={Memory:function(opts){this.buffer=new ArrayBuffer(opts["initial"]*65536)},Module:function(binary){},Instance:function(module,info){this.exports=( +// EMSCRIPTEN_START_ASM +function instantiate(na){function c(d){d.set=function(a,b){this[a]=b};d.get=function(a){return this[a]};return d}var e;var f=new Uint8Array(123);for(var a=25;a>=0;--a){f[48+a]=52+a;f[65+a]=a;f[97+a]=26+a}f[43]=62;f[47]=63;function l(m,n,o){var g,h,a=0,i=n,j=o.length,k=n+(j*3>>2)-(o[j-2]=="=")-(o[j-1]=="=");for(;a>4;if(i>2;if(i>2];s=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;a:{b:{c:{if(g>>>0>k>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break c}d=e+H[b>>2]|0;H[a>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[a>>2]>31){break c}s=H[b+8>>2];y=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>s>>>0&(d|0)>=(y|0)|(d|0)>(y|0)){break c}d=e+H[b>>2]|0;H[a+4>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;s=H[b+8>>2];y=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>s>>>0&(d|0)>=(y|0)|(d|0)>(y|0)){break c}d=e+H[b>>2]|0;H[a+12>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;d=H[a+20>>2];x=H[a+12>>2];if((x|0)!=(d|0)?d:0){break c}s=H[b+8>>2];y=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>s>>>0&(d|0)>=(y|0)|(d|0)>(y|0)){break c}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[a+16>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(e>>>0>=7){H[B>>2]=e;Qd(1713,B);break c}H[B+664>>2]=c;d:{if(!x){break d}e:{k=H[c>>2];if(x>>>0<=(H[c+8>>2]-k|0)/12>>>0){break e}if(x>>>0<357913942){l=H[c+4>>2];d=N(x,12);e=pa(d);g=d+e|0;e=e+N((l-k|0)/12|0,12)|0;d=e;if((k|0)!=(l|0)){while(1){d=d-12|0;l=l-12|0;H[d>>2]=H[l>>2];H[d+4>>2]=H[l+4>>2];H[d+8>>2]=H[l+8>>2];if((k|0)!=(l|0)){continue}break}}H[c+8>>2]=g;H[c+4>>2]=e;H[c>>2]=d;if(!k){break e}oa(k);break e}break b}f:{switch(H[a+16>>2]){case 0:i=wb(B+8|0,3);z=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;g:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break g}d=e+H[b>>2]|0;H[i>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[i>>2]>32){break g}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break g}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[i+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break g}H[i+8>>2]=0;if(!ua(i+16|0,b)){break g}if(!ua(i+36|0,b)){break g}if(!ua(i+56|0,b)){break g}if(!ua(i+76|0,b)){break g}A=H[i+4>>2];d=0;g=0;f=ca-32|0;ca=f;m=H[i+12>>2];H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;if(m){if(m>>>0>=1073741824){break b}b=m<<2;g=pa(b);H[f+8>>2]=g;d=b+g|0;H[f+16>>2]=d;ra(g,0,b);H[f+12>>2]=d}e=H[i+120>>2];b=H[e>>2];if(b){H[e+4>>2]=b;oa(b);m=H[i+12>>2];g=H[f+8>>2];d=H[f+12>>2]}H[e+4>>2]=d;H[e>>2]=g;H[e+8>>2]=H[f+16>>2];g=0;H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;h:{if(m){if(m>>>0>=1073741824){break b}b=m<<2;w=pa(b);H[f+8>>2]=w;g=b+w|0;H[f+16>>2]=g;ra(w,0,b);H[f+12>>2]=g}d=H[i+132>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);w=H[f+8>>2];g=H[f+12>>2]}H[d+4>>2]=g;H[d>>2]=w;H[d+8>>2]=H[f+16>>2];H[f+24>>2]=0;H[f+28>>2]=0;H[f+16>>2]=0;H[f+20>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;xa(f+8|0);d=H[f+24>>2]+H[f+28>>2]|0;b=(d>>>0)/341|0;b=H[H[f+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=A;m=H[f+28>>2]+1|0;H[f+28>>2]=m;i:{if(!m){break i}y=i+96|0;while(1){n=H[f+12>>2];g=H[f+24>>2];e=m-1|0;d=g+e|0;b=(d>>>0)/341|0;b=H[n+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;o=H[b+8>>2];k=H[b+4>>2];t=H[b>>2];H[f+28>>2]=e;b=H[f+16>>2];if((((b|0)!=(n|0)?N(b-n>>2,341)-1|0:0)-(g+m|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[f+16>>2]=H[f+16>>2]-4}b=0;if(t>>>0>A>>>0){break i}d=H[i+12>>2];m=(k|0)!=(d-1|0)?k+1|0:0;if(m>>>0>=d>>>0){break i}q=N(o,12);p=q+H[i+132>>2]|0;l=q+H[i+120>>2]|0;g=H[i>>2];r=m<<2;e=H[r+H[p>>2]>>2];j:{k:{if((g|0)==(e|0)){if(!t){break k}while(1){d=H[l>>2];x=H[d+8>>2];s=H[d+4>>2];n=H[d>>2];q=H[z>>2];m=H[q+4>>2];d=H[q+8>>2];l:{if(m>>>0>>0){H[m+8>>2]=x;H[m+4>>2]=s;H[m>>2]=n;H[q+4>>2]=m+12;break l}r=H[q>>2];g=(m-r|0)/12|0;k=g+1|0;if(k>>>0>=357913942){break b}e=(d-r|0)/12|0;d=e<<1;k=e>>>0>=178956970?357913941:d>>>0>k>>>0?d:k;if(k){if(k>>>0>=357913942){break a}d=pa(N(k,12))}else{d=0}w=d+N(g,12)|0;H[w+8>>2]=x;H[w+4>>2]=s;H[w>>2]=n;e=w+12|0;if((m|0)!=(r|0)){while(1){w=w-12|0;m=m-12|0;H[w>>2]=H[m>>2];H[w+4>>2]=H[m+4>>2];H[w+8>>2]=H[m+8>>2];if((m|0)!=(r|0)){continue}break}}H[q+8>>2]=d+N(k,12);H[q+4>>2]=e;H[q>>2]=w;if(!r){break l}oa(r)}H[i+8>>2]=H[i+8>>2]+1;b=b+1|0;if((t|0)!=(b|0)){continue}break}break k}m:{n:{o:{p:{if(t>>>0<=2){d=H[i+108>>2];H[d>>2]=m;w=1;g=H[i+12>>2];if(g>>>0>1){break p}break m}if(K[i+8>>2]>K[i+4>>2]){break i}b=H[i+120>>2];s=o+1|0;x=N(s,12);d=b+x|0;if((d|0)!=(l|0)){Aa(d,H[l>>2],H[l+4>>2]);b=H[i+120>>2]}b=r+H[b+x>>2]|0;H[b>>2]=H[b>>2]+(1<>2];e=32-k|0;q:{if((n|0)<=(e|0)){e=H[i+28>>2];if((e|0)==H[i+20>>2]){break o}d=H[e>>2];b=k+n|0;H[i+32>>2]=b;w=d<>>32-n|0;if((b|0)!=32){break q}H[i+32>>2]=0;H[i+28>>2]=e+4;break q}g=H[i+28>>2];b=g+4|0;if((b|0)==H[i+20>>2]){break o}d=H[g>>2];H[i+28>>2]=b;b=n-e|0;H[i+32>>2]=b;w=H[g+4>>2]>>>32-b|d<>>32-n}d=t>>>1|0;if(w>>>0>d>>>0){break i}break n}while(1){m=(g-1|0)!=(m|0)?m+1|0:0;H[d+(w<<2)>>2]=m;g=H[i+12>>2];w=w+1|0;if(g>>>0>w>>>0){continue}break}break m}d=t>>>1|0;w=0}r:{s:{e=d-w|0;b=t-e|0;t:{if((b|0)==(e|0)){b=e;break t}n=H[i+88>>2];if((n|0)==H[i+80>>2]){break s}k=H[n>>2];g=H[i+92>>2];d=g+1|0;H[i+92>>2]=d;g=k&-2147483648>>>g;u:{if((d|0)==32){H[i+92>>2]=0;H[i+88>>2]=n+4;if(g){break u}break s}if(!g){break s}}}d=b;b=e;break r}d=e}n=H[i+132>>2];k=n+q|0;g=H[k>>2];e=g+r|0;H[e>>2]=H[e>>2]+1;Aa(n+x|0,g,H[k+4>>2]);if(b){g=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];w=H[f+12>>2];if((g|0)==(((e|0)!=(w|0)?N(e-w>>2,341)-1|0:0)|0)){xa(f+8|0);w=H[f+12>>2];g=H[f+24>>2]+H[f+28>>2]|0}e=(g>>>0)/341|0;e=H[(e<<2)+w>>2]+N(g-N(e,341)|0,12)|0;H[e+8>>2]=o;H[e+4>>2]=m;H[e>>2]=b;H[f+28>>2]=H[f+28>>2]+1}if(!d){break k}g=H[f+28>>2]+H[f+24>>2]|0;b=H[f+16>>2];w=H[f+12>>2];if((g|0)==(((b|0)!=(w|0)?N(b-w>>2,341)-1|0:0)|0)){xa(f+8|0);w=H[f+12>>2];g=H[f+24>>2]+H[f+28>>2]|0}b=(g>>>0)/341|0;b=H[(b<<2)+w>>2]+N(g-N(b,341)|0,12)|0;H[b+8>>2]=s;H[b+4>>2]=m;H[b>>2]=d;m=H[f+28>>2]+1|0;H[f+28>>2]=m;break j}if(!t){break k}while(1){if(H[i+12>>2]){o=H[i+40>>2];n=H[p>>2];w=H[i+96>>2];k=H[i+108>>2];m=0;while(1){q=k+(m<<2)|0;H[w+(H[q>>2]<<2)>>2]=0;g=H[i>>2];e=H[q>>2]<<2;d=H[e+n>>2];v:{if((g|0)==(d|0)){break v}r=e+w|0;u=g-d|0;x=H[i+52>>2];g=32-x|0;if((u|0)<=(g|0)){e=H[i+48>>2];if((e|0)==(o|0)){break i}H[r>>2]=H[e>>2]<>>32-u;d=u+H[i+52>>2]|0;H[i+52>>2]=d;if((d|0)!=32){break v}H[i+52>>2]=0;H[i+48>>2]=e+4;break v}s=H[i+48>>2];d=s+4|0;if((d|0)==(o|0)){break i}e=H[s>>2];H[i+48>>2]=d;d=u-g|0;H[i+52>>2]=d;H[r>>2]=H[s+4>>2]>>>32-d|e<>>32-u}e=H[q>>2]<<2;d=e+w|0;H[d>>2]=H[d>>2]|H[e+H[l>>2]>>2];m=m+1|0;if(m>>>0>2]){continue}break}}jb(z,y);H[i+8>>2]=H[i+8>>2]+1;b=b+1|0;if((t|0)!=(b|0)){continue}break}}m=H[f+28>>2]}if(m){continue}break}}H[f+28>>2]=0;w=H[f+16>>2];m=H[f+12>>2];g=w-m|0;if(g>>>0>=9){while(1){oa(H[m>>2]);m=H[f+12>>2]+4|0;H[f+12>>2]=m;w=H[f+16>>2];g=w-m|0;if(g>>>0>8){continue}break}}b=170;w:{switch((g>>>2|0)-1|0){case 1:b=341;case 0:H[f+24>>2]=b;break;default:break w}}x:{if((m|0)==(w|0)){break x}while(1){oa(H[m>>2]);m=m+4|0;if((w|0)!=(m|0)){continue}break}d=H[f+16>>2];b=H[f+12>>2];if((d|0)==(b|0)){break x}H[f+16>>2]=d+((b-d|0)+3&-4)}b=H[f+8>>2];if(b){oa(b)}ca=f+32|0;break h}}xb(i);break d;case 1:i=wb(B+8|0,3);A=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;y:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break y}d=e+H[b>>2]|0;H[i>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[i>>2]>32){break y}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break y}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[i+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break y}H[i+8>>2]=0;if(!ua(i+16|0,b)){break y}if(!ua(i+36|0,b)){break y}if(!ua(i+56|0,b)){break y}if(!ua(i+76|0,b)){break y}p=H[i+4>>2];d=0;f=ca-32|0;ca=f;m=H[i+12>>2];H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;if(m){if(m>>>0>=1073741824){break b}b=m<<2;t=pa(b);H[f+8>>2]=t;d=b+t|0;H[f+16>>2]=d;ra(t,0,b);H[f+12>>2]=d}e=H[i+120>>2];b=H[e>>2];if(b){H[e+4>>2]=b;oa(b);m=H[i+12>>2];t=H[f+8>>2];d=H[f+12>>2]}H[e+4>>2]=d;H[e>>2]=t;H[e+8>>2]=H[f+16>>2];t=0;H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;z:{if(m){if(m>>>0>=1073741824){break b}b=m<<2;o=pa(b);H[f+8>>2]=o;t=b+o|0;H[f+16>>2]=t;ra(o,0,b);H[f+12>>2]=t}d=H[i+132>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);t=H[f+12>>2];o=H[f+8>>2]}H[d+4>>2]=t;H[d>>2]=o;H[d+8>>2]=H[f+16>>2];H[f+24>>2]=0;H[f+28>>2]=0;H[f+16>>2]=0;H[f+20>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;xa(f+8|0);d=H[f+24>>2]+H[f+28>>2]|0;b=(d>>>0)/341|0;b=H[H[f+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=p;m=H[f+28>>2]+1|0;H[f+28>>2]=m;A:{if(!m){break A}s=i+96|0;while(1){k=H[f+12>>2];g=H[f+24>>2];e=m-1|0;d=g+e|0;b=(d>>>0)/341|0;b=H[k+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;q=H[b+8>>2];d=H[b+4>>2];l=H[b>>2];H[f+28>>2]=e;b=H[f+16>>2];if((((b|0)!=(k|0)?N(b-k>>2,341)-1|0:0)-(g+m|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[f+16>>2]=H[f+16>>2]-4}if(l>>>0>p>>>0){break A}b=H[i+12>>2];m=(d|0)!=(b-1|0)?d+1|0:0;if(m>>>0>=b>>>0){break A}b=H[i+120>>2];r=N(q,12);u=b+r|0;e=H[i>>2];x=m<<2;n=r+H[i+132>>2]|0;d=H[x+H[n>>2]>>2];B:{C:{if((e|0)==(d|0)){x=0;if(!l){break C}while(1){b=H[u>>2];y=H[b+8>>2];n=H[b+4>>2];k=H[b>>2];q=H[A>>2];m=H[q+4>>2];b=H[q+8>>2];D:{if(m>>>0>>0){H[m+8>>2]=y;H[m+4>>2]=n;H[m>>2]=k;H[q+4>>2]=m+12;break D}r=H[q>>2];e=(m-r|0)/12|0;g=e+1|0;if(g>>>0>=357913942){break b}d=(b-r|0)/12|0;b=d<<1;g=d>>>0>=178956970?357913941:b>>>0>g>>>0?b:g;if(g){if(g>>>0>=357913942){break a}b=pa(N(g,12))}else{b=0}o=b+N(e,12)|0;H[o+8>>2]=y;H[o+4>>2]=n;H[o>>2]=k;d=o+12|0;if((m|0)!=(r|0)){while(1){o=o-12|0;m=m-12|0;H[o>>2]=H[m>>2];H[o+4>>2]=H[m+4>>2];H[o+8>>2]=H[m+8>>2];if((m|0)!=(r|0)){continue}break}}H[q+8>>2]=b+N(g,12);H[q+4>>2]=d;H[q>>2]=o;if(!r){break D}oa(r)}H[i+8>>2]=H[i+8>>2]+1;x=x+1|0;if((l|0)!=(x|0)){continue}break}break C}E:{F:{G:{H:{if(l>>>0<=2){b=H[i+108>>2];H[b>>2]=m;o=1;t=H[i+12>>2];if(t>>>0>1){break H}break E}if(K[i+8>>2]>K[i+4>>2]){break A}k=b;b=r+12|0;Aa(k+b|0,H[u>>2],H[u+4>>2]);b=x+H[b+H[i+120>>2]>>2]|0;H[b>>2]=H[b>>2]+(1<>2];e=32-k|0;I:{if((n|0)<=(e|0)){e=H[i+28>>2];if((e|0)==H[i+20>>2]){break G}d=H[e>>2];b=k+n|0;H[i+32>>2]=b;d=d<>>32-n|0;if((b|0)!=32){break I}H[i+32>>2]=0;H[i+28>>2]=e+4;break I}g=H[i+28>>2];b=g+4|0;if((b|0)==H[i+20>>2]){break G}d=H[g>>2];H[i+28>>2]=b;b=n-e|0;H[i+32>>2]=b;d=H[g+4>>2]>>>32-b|d<>>32-n}o=l>>>1|0;if(o>>>0>>0){break A}break F}while(1){m=(t-1|0)!=(m|0)?m+1|0:0;H[b+(o<<2)>>2]=m;o=o+1|0;t=H[i+12>>2];if(o>>>0>>0){continue}break}break E}o=l>>>1|0;d=0}y=q+1|0;J:{K:{e=o-d|0;d=l-e|0;L:{if((d|0)==(e|0)){b=e;break L}n=H[i+88>>2];if((n|0)==H[i+80>>2]){break K}k=H[n>>2];g=H[i+92>>2];b=g+1|0;H[i+92>>2]=b;g=k&-2147483648>>>g;M:{if((b|0)==32){H[i+92>>2]=0;H[i+88>>2]=n+4;if(g){break M}break K}if(!g){break K}}b=d}d=e;break J}b=e}n=H[i+132>>2];k=n+r|0;g=H[k>>2];e=g+x|0;H[e>>2]=H[e>>2]+1;Aa(n+N(y,12)|0,g,H[k+4>>2]);if(d){t=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];o=H[f+12>>2];if((t|0)==(((e|0)!=(o|0)?N(e-o>>2,341)-1|0:0)|0)){xa(f+8|0);t=H[f+24>>2]+H[f+28>>2]|0;o=H[f+12>>2]}e=(t>>>0)/341|0;e=H[o+(e<<2)>>2]+N(t-N(e,341)|0,12)|0;H[e+8>>2]=q;H[e+4>>2]=m;H[e>>2]=d;H[f+28>>2]=H[f+28>>2]+1}if(!b){break C}t=H[f+28>>2]+H[f+24>>2]|0;d=H[f+16>>2];o=H[f+12>>2];if((t|0)==(((d|0)!=(o|0)?N(d-o>>2,341)-1|0:0)|0)){xa(f+8|0);t=H[f+24>>2]+H[f+28>>2]|0;o=H[f+12>>2]}d=(t>>>0)/341|0;d=H[o+(d<<2)>>2]+N(t-N(d,341)|0,12)|0;H[d+8>>2]=y;H[d+4>>2]=m;H[d>>2]=b;m=H[f+28>>2]+1|0;H[f+28>>2]=m;break B}t=0;if(!l){break C}while(1){if(H[i+12>>2]){o=H[i+40>>2];k=H[n>>2];z=H[i+96>>2];g=H[i+108>>2];m=0;while(1){q=g+(m<<2)|0;H[z+(H[q>>2]<<2)>>2]=0;e=H[i>>2];d=H[q>>2]<<2;b=H[d+k>>2];N:{if((e|0)==(b|0)){break N}r=d+z|0;w=e-b|0;x=H[i+52>>2];e=32-x|0;if((w|0)<=(e|0)){d=H[i+48>>2];if((d|0)==(o|0)){break A}H[r>>2]=H[d>>2]<>>32-w;b=w+H[i+52>>2]|0;H[i+52>>2]=b;if((b|0)!=32){break N}H[i+52>>2]=0;H[i+48>>2]=d+4;break N}y=H[i+48>>2];b=y+4|0;if((b|0)==(o|0)){break A}d=H[y>>2];H[i+48>>2]=b;b=w-e|0;H[i+52>>2]=b;H[r>>2]=H[y+4>>2]>>>32-b|d<>>32-w}d=H[q>>2]<<2;b=d+z|0;H[b>>2]=H[b>>2]|H[d+H[u>>2]>>2];m=m+1|0;if(m>>>0>2]){continue}break}}jb(A,s);H[i+8>>2]=H[i+8>>2]+1;t=t+1|0;if((l|0)!=(t|0)){continue}break}}m=H[f+28>>2]}if(m){continue}break}}H[f+28>>2]=0;o=H[f+16>>2];m=H[f+12>>2];t=o-m|0;if(t>>>0>=9){while(1){oa(H[m>>2]);m=H[f+12>>2]+4|0;H[f+12>>2]=m;o=H[f+16>>2];t=o-m|0;if(t>>>0>8){continue}break}}b=170;O:{switch((t>>>2|0)-1|0){case 1:b=341;case 0:H[f+24>>2]=b;break;default:break O}}P:{if((m|0)==(o|0)){break P}while(1){oa(H[m>>2]);m=m+4|0;if((o|0)!=(m|0)){continue}break}d=H[f+16>>2];b=H[f+12>>2];if((d|0)==(b|0)){break P}H[f+16>>2]=d+((b-d|0)+3&-4)}b=H[f+8>>2];if(b){oa(b)}ca=f+32|0;break z}}xb(i);break d;case 2:f=ub(B+8|0,3);w=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;Q:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break Q}d=e+H[b>>2]|0;H[f>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[f>>2]>32){break Q}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break Q}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[f+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break Q}H[f+8>>2]=0;if(!ta(f+16|0,b)){break Q}if(!ua(f+32|0,b)){break Q}if(!ua(f+52|0,b)){break Q}if(!ua(f+72|0,b)){break Q}z=H[f+4>>2];g=0;b=0;h=ca-32|0;ca=h;j=H[f+12>>2];H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;if(j){if(j>>>0>=1073741824){break b}d=j<<2;g=pa(d);H[h+8>>2]=g;b=d+g|0;H[h+16>>2]=b;ra(g,0,d);H[h+12>>2]=b}e=H[f+116>>2];d=H[e>>2];if(d){H[e+4>>2]=d;oa(d);j=H[f+12>>2];g=H[h+8>>2];b=H[h+12>>2]}H[e+4>>2]=b;H[e>>2]=g;H[e+8>>2]=H[h+16>>2];g=0;H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;R:{if(j){if(j>>>0>=1073741824){break b}b=j<<2;u=pa(b);H[h+8>>2]=u;g=b+u|0;H[h+16>>2]=g;ra(u,0,b);H[h+12>>2]=g}d=H[f+128>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);u=H[h+8>>2];g=H[h+12>>2]}H[d+4>>2]=g;H[d>>2]=u;H[d+8>>2]=H[h+16>>2];H[h+24>>2]=0;H[h+28>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;xa(h+8|0);d=H[h+24>>2]+H[h+28>>2]|0;b=(d>>>0)/341|0;b=H[H[h+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=z;j=H[h+28>>2]+1|0;H[h+28>>2]=j;S:{if(!j){break S}x=f+92|0;y=f+16|0;while(1){n=H[h+12>>2];g=H[h+24>>2];e=j-1|0;d=g+e|0;b=(d>>>0)/341|0;b=H[n+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;p=H[b+8>>2];k=H[b+4>>2];i=H[b>>2];H[h+28>>2]=e;b=H[h+16>>2];if((((b|0)!=(n|0)?N(b-n>>2,341)-1|0:0)-(g+j|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[h+16>>2]=H[h+16>>2]-4}d=0;if(i>>>0>z>>>0){break S}b=H[f+12>>2];j=(k|0)!=(b-1|0)?k+1|0:0;if(j>>>0>=b>>>0){break S}o=N(p,12);A=o+H[f+128>>2]|0;t=o+H[f+116>>2]|0;g=H[f>>2];q=j<<2;e=H[q+H[A>>2]>>2];T:{if((g|0)==(e|0)){if(!i){break T}while(1){b=H[t>>2];r=H[b+8>>2];s=H[b+4>>2];n=H[b>>2];o=H[w>>2];j=H[o+4>>2];b=H[o+8>>2];U:{if(j>>>0>>0){H[j+8>>2]=r;H[j+4>>2]=s;H[j>>2]=n;H[o+4>>2]=j+12;break U}q=H[o>>2];g=(j-q|0)/12|0;k=g+1|0;if(k>>>0>=357913942){break b}e=(b-q|0)/12|0;b=e<<1;k=e>>>0>=178956970?357913941:b>>>0>k>>>0?b:k;if(k){if(k>>>0>=357913942){break a}b=pa(N(k,12))}else{b=0}u=b+N(g,12)|0;H[u+8>>2]=r;H[u+4>>2]=s;H[u>>2]=n;e=u+12|0;if((j|0)!=(q|0)){while(1){u=u-12|0;j=j-12|0;H[u>>2]=H[j>>2];H[u+4>>2]=H[j+4>>2];H[u+8>>2]=H[j+8>>2];if((j|0)!=(q|0)){continue}break}}H[o+8>>2]=b+N(k,12);H[o+4>>2]=e;H[o>>2]=u;if(!q){break U}oa(q)}H[f+8>>2]=H[f+8>>2]+1;d=d+1|0;if((i|0)!=(d|0)){continue}break}break T}V:{W:{X:{Y:{if(i>>>0<=2){b=H[f+104>>2];H[b>>2]=j;u=1;g=H[f+12>>2];if(g>>>0>1){break Y}break V}if(K[f+8>>2]>K[f+4>>2]){break S}b=H[f+116>>2];s=p+1|0;r=N(s,12);d=b+r|0;if((d|0)!=(t|0)){Aa(d,H[t>>2],H[t+4>>2]);b=H[f+116>>2]}b=q+H[b+r>>2]|0;H[b>>2]=H[b>>2]+(1<>2]=0;pc(y,Q(i)^31,h+4|0);d=i>>>1|0;b=H[h+4>>2];if(d>>>0>>0){break S}e=d-b|0;d=i-e|0;Z:{if((d|0)==(e|0)){b=e;break Z}n=H[f+84>>2];if((n|0)==H[f+76>>2]){break X}k=H[n>>2];g=H[f+88>>2];b=g+1|0;H[f+88>>2]=b;g=k&-2147483648>>>g;_:{if((b|0)==32){H[f+88>>2]=0;H[f+84>>2]=n+4;if(g){break _}break X}if(!g){break X}}b=d}d=e;break W}while(1){j=(g-1|0)!=(j|0)?j+1|0:0;H[b+(u<<2)>>2]=j;g=H[f+12>>2];u=u+1|0;if(g>>>0>u>>>0){continue}break}break V}b=e}n=H[f+128>>2];k=n+o|0;g=H[k>>2];e=g+q|0;H[e>>2]=H[e>>2]+1;Aa(n+r|0,g,H[k+4>>2]);if(d){g=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];u=H[h+12>>2];if((g|0)==(((e|0)!=(u|0)?N(e-u>>2,341)-1|0:0)|0)){xa(h+8|0);u=H[h+12>>2];g=H[h+24>>2]+H[h+28>>2]|0}e=(g>>>0)/341|0;e=H[(e<<2)+u>>2]+N(g-N(e,341)|0,12)|0;H[e+8>>2]=p;H[e+4>>2]=j;H[e>>2]=d;H[h+28>>2]=H[h+28>>2]+1}if(!b){break T}g=H[h+28>>2]+H[h+24>>2]|0;d=H[h+16>>2];u=H[h+12>>2];if((g|0)==(((d|0)!=(u|0)?N(d-u>>2,341)-1|0:0)|0)){xa(h+8|0);u=H[h+12>>2];g=H[h+24>>2]+H[h+28>>2]|0}d=(g>>>0)/341|0;d=H[(d<<2)+u>>2]+N(g-N(d,341)|0,12)|0;H[d+8>>2]=s;H[d+4>>2]=j;H[d>>2]=b;H[h+28>>2]=H[h+28>>2]+1;break T}if(!i){break T}while(1){if(H[f+12>>2]){p=H[f+36>>2];n=H[A>>2];u=H[f+92>>2];k=H[f+104>>2];j=0;while(1){o=k+(j<<2)|0;H[u+(H[o>>2]<<2)>>2]=0;g=H[f>>2];e=H[o>>2]<<2;b=H[e+n>>2];$:{if((g|0)==(b|0)){break $}q=e+u|0;l=g-b|0;r=H[f+48>>2];g=32-r|0;if((l|0)<=(g|0)){e=H[f+44>>2];if((e|0)==(p|0)){break S}H[q>>2]=H[e>>2]<>>32-l;b=l+H[f+48>>2]|0;H[f+48>>2]=b;if((b|0)!=32){break $}H[f+48>>2]=0;H[f+44>>2]=e+4;break $}s=H[f+44>>2];b=s+4|0;if((b|0)==(p|0)){break S}e=H[s>>2];H[f+44>>2]=b;b=l-g|0;H[f+48>>2]=b;H[q>>2]=H[s+4>>2]>>>32-b|e<>>32-l}e=H[o>>2]<<2;b=e+u|0;H[b>>2]=H[b>>2]|H[e+H[t>>2]>>2];j=j+1|0;if(j>>>0>2]){continue}break}}jb(w,x);H[f+8>>2]=H[f+8>>2]+1;d=d+1|0;if((i|0)!=(d|0)){continue}break}}j=H[h+28>>2];if(j){continue}break}}H[h+28>>2]=0;u=H[h+16>>2];j=H[h+12>>2];g=u-j|0;if(g>>>0>=9){while(1){oa(H[j>>2]);j=H[h+12>>2]+4|0;H[h+12>>2]=j;u=H[h+16>>2];g=u-j|0;if(g>>>0>8){continue}break}}b=170;aa:{switch((g>>>2|0)-1|0){case 1:b=341;case 0:H[h+24>>2]=b;break;default:break aa}}ba:{if((j|0)==(u|0)){break ba}while(1){oa(H[j>>2]);j=j+4|0;if((u|0)!=(j|0)){continue}break}d=H[h+16>>2];b=H[h+12>>2];if((d|0)==(b|0)){break ba}H[h+16>>2]=d+((b-d|0)+3&-4)}b=H[h+8>>2];if(b){oa(b)}ca=h+32|0;break R}}vb(f);break d;case 3:i=ub(B+8|0,3);z=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;ca:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break ca}d=e+H[b>>2]|0;H[i>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[i>>2]>32){break ca}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break ca}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[i+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break ca}H[i+8>>2]=0;if(!ta(i+16|0,b)){break ca}if(!ua(i+32|0,b)){break ca}if(!ua(i+52|0,b)){break ca}if(!ua(i+72|0,b)){break ca}A=H[i+4>>2];d=0;f=ca-32|0;ca=f;j=H[i+12>>2];H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;if(j){if(j>>>0>=1073741824){break b}b=j<<2;m=pa(b);H[f+8>>2]=m;d=b+m|0;H[f+16>>2]=d;ra(m,0,b);H[f+12>>2]=d}e=H[i+116>>2];b=H[e>>2];if(b){H[e+4>>2]=b;oa(b);j=H[i+12>>2];m=H[f+8>>2];d=H[f+12>>2]}H[e+4>>2]=d;H[e>>2]=m;H[e+8>>2]=H[f+16>>2];m=0;H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;da:{if(j){if(j>>>0>=1073741824){break b}b=j<<2;p=pa(b);H[f+8>>2]=p;m=b+p|0;H[f+16>>2]=m;ra(p,0,b);H[f+12>>2]=m}d=H[i+128>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);m=H[f+12>>2];p=H[f+8>>2]}H[d+4>>2]=m;H[d>>2]=p;H[d+8>>2]=H[f+16>>2];H[f+24>>2]=0;H[f+28>>2]=0;H[f+16>>2]=0;H[f+20>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;xa(f+8|0);d=H[f+24>>2]+H[f+28>>2]|0;b=(d>>>0)/341|0;b=H[H[f+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=A;j=H[f+28>>2]+1|0;H[f+28>>2]=j;ea:{if(!j){break ea}y=i+92|0;s=i+16|0;while(1){k=H[f+12>>2];g=H[f+24>>2];e=j-1|0;d=g+e|0;b=(d>>>0)/341|0;b=H[k+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;o=H[b+8>>2];d=H[b+4>>2];t=H[b>>2];H[f+28>>2]=e;b=H[f+16>>2];if((((b|0)!=(k|0)?N(b-k>>2,341)-1|0:0)-(g+j|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[f+16>>2]=H[f+16>>2]-4}if(t>>>0>A>>>0){break ea}b=H[i+12>>2];j=(d|0)!=(b-1|0)?d+1|0:0;if(j>>>0>=b>>>0){break ea}b=H[i+116>>2];q=N(o,12);l=b+q|0;e=H[i>>2];r=j<<2;n=q+H[i+128>>2]|0;d=H[r+H[n>>2]>>2];fa:{if((e|0)==(d|0)){r=0;if(!t){break fa}while(1){b=H[l>>2];x=H[b+8>>2];n=H[b+4>>2];k=H[b>>2];o=H[z>>2];j=H[o+4>>2];b=H[o+8>>2];ga:{if(j>>>0>>0){H[j+8>>2]=x;H[j+4>>2]=n;H[j>>2]=k;H[o+4>>2]=j+12;break ga}q=H[o>>2];e=(j-q|0)/12|0;g=e+1|0;if(g>>>0>=357913942){break b}d=(b-q|0)/12|0;b=d<<1;g=d>>>0>=178956970?357913941:b>>>0>g>>>0?b:g;if(g){if(g>>>0>=357913942){break a}b=pa(N(g,12))}else{b=0}p=b+N(e,12)|0;H[p+8>>2]=x;H[p+4>>2]=n;H[p>>2]=k;d=p+12|0;if((j|0)!=(q|0)){while(1){p=p-12|0;j=j-12|0;H[p>>2]=H[j>>2];H[p+4>>2]=H[j+4>>2];H[p+8>>2]=H[j+8>>2];if((j|0)!=(q|0)){continue}break}}H[o+8>>2]=b+N(g,12);H[o+4>>2]=d;H[o>>2]=p;if(!q){break ga}oa(q)}H[i+8>>2]=H[i+8>>2]+1;r=r+1|0;if((t|0)!=(r|0)){continue}break}break fa}ha:{ia:{ja:{ka:{if(t>>>0<=2){b=H[i+104>>2];H[b>>2]=j;p=1;m=H[i+12>>2];if(m>>>0>1){break ka}break ha}if(K[i+8>>2]>K[i+4>>2]){break ea}k=b;b=q+12|0;Aa(k+b|0,H[l>>2],H[l+4>>2]);b=r+H[b+H[i+116>>2]>>2]|0;H[b>>2]=H[b>>2]+(1<>2]=0;pc(s,Q(t)^31,f+4|0);d=t>>>1|0;b=H[f+4>>2];if(d>>>0>>0){break ea}x=o+1|0;e=d-b|0;d=t-e|0;la:{if((d|0)==(e|0)){b=e;break la}n=H[i+84>>2];if((n|0)==H[i+76>>2]){break ja}k=H[n>>2];g=H[i+88>>2];b=g+1|0;H[i+88>>2]=b;g=k&-2147483648>>>g;ma:{if((b|0)==32){H[i+88>>2]=0;H[i+84>>2]=n+4;if(g){break ma}break ja}if(!g){break ja}}b=d}d=e;break ia}while(1){j=(m-1|0)!=(j|0)?j+1|0:0;H[b+(p<<2)>>2]=j;m=H[i+12>>2];p=p+1|0;if(m>>>0>p>>>0){continue}break}break ha}b=e}n=H[i+128>>2];k=n+q|0;g=H[k>>2];e=g+r|0;H[e>>2]=H[e>>2]+1;Aa(n+N(x,12)|0,g,H[k+4>>2]);if(d){m=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];p=H[f+12>>2];if((m|0)==(((e|0)!=(p|0)?N(e-p>>2,341)-1|0:0)|0)){xa(f+8|0);m=H[f+24>>2]+H[f+28>>2]|0;p=H[f+12>>2]}e=(m>>>0)/341|0;e=H[p+(e<<2)>>2]+N(m-N(e,341)|0,12)|0;H[e+8>>2]=o;H[e+4>>2]=j;H[e>>2]=d;H[f+28>>2]=H[f+28>>2]+1}if(!b){break fa}m=H[f+28>>2]+H[f+24>>2]|0;d=H[f+16>>2];p=H[f+12>>2];if((m|0)==(((d|0)!=(p|0)?N(d-p>>2,341)-1|0:0)|0)){xa(f+8|0);m=H[f+24>>2]+H[f+28>>2]|0;p=H[f+12>>2]}d=(m>>>0)/341|0;d=H[p+(d<<2)>>2]+N(m-N(d,341)|0,12)|0;H[d+8>>2]=x;H[d+4>>2]=j;H[d>>2]=b;H[f+28>>2]=H[f+28>>2]+1;break fa}m=0;if(!t){break fa}while(1){if(H[i+12>>2]){p=H[i+36>>2];k=H[n>>2];w=H[i+92>>2];g=H[i+104>>2];j=0;while(1){o=g+(j<<2)|0;H[w+(H[o>>2]<<2)>>2]=0;e=H[i>>2];d=H[o>>2]<<2;b=H[d+k>>2];na:{if((e|0)==(b|0)){break na}q=d+w|0;u=e-b|0;r=H[i+48>>2];e=32-r|0;if((u|0)<=(e|0)){d=H[i+44>>2];if((d|0)==(p|0)){break ea}H[q>>2]=H[d>>2]<>>32-u;b=u+H[i+48>>2]|0;H[i+48>>2]=b;if((b|0)!=32){break na}H[i+48>>2]=0;H[i+44>>2]=d+4;break na}x=H[i+44>>2];b=x+4|0;if((b|0)==(p|0)){break ea}d=H[x>>2];H[i+44>>2]=b;b=u-e|0;H[i+48>>2]=b;H[q>>2]=H[x+4>>2]>>>32-b|d<>>32-u}d=H[o>>2]<<2;b=d+w|0;H[b>>2]=H[b>>2]|H[d+H[l>>2]>>2];j=j+1|0;if(j>>>0>2]){continue}break}}jb(z,y);H[i+8>>2]=H[i+8>>2]+1;m=m+1|0;if((t|0)!=(m|0)){continue}break}}j=H[f+28>>2];if(j){continue}break}}H[f+28>>2]=0;p=H[f+16>>2];j=H[f+12>>2];m=p-j|0;if(m>>>0>=9){while(1){oa(H[j>>2]);j=H[f+12>>2]+4|0;H[f+12>>2]=j;p=H[f+16>>2];m=p-j|0;if(m>>>0>8){continue}break}}b=170;oa:{switch((m>>>2|0)-1|0){case 1:b=341;case 0:H[f+24>>2]=b;break;default:break oa}}pa:{if((j|0)==(p|0)){break pa}while(1){oa(H[j>>2]);j=j+4|0;if((p|0)!=(j|0)){continue}break}d=H[f+16>>2];b=H[f+12>>2];if((d|0)==(b|0)){break pa}H[f+16>>2]=d+((b-d|0)+3&-4)}b=H[f+8>>2];if(b){oa(b)}ca=f+32|0;break da}}vb(i);break d;case 4:f=$a(B+8|0,3);w=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;qa:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break qa}d=e+H[b>>2]|0;H[f>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[f>>2]>32){break qa}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break qa}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[f+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break qa}H[f+8>>2]=0;if(!sb(f+16|0,b)){break qa}if(!ua(f+544|0,b)){break qa}if(!ua(f+564|0,b)){break qa}if(!ua(f+584|0,b)){break qa}z=H[f+4>>2];l=0;b=0;h=ca-32|0;ca=h;d=H[f+12>>2];H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;if(d){if(d>>>0>=1073741824){break b}e=d<<2;l=pa(e);H[h+8>>2]=l;b=e+l|0;H[h+16>>2]=b;ra(l,0,e);H[h+12>>2]=b}g=H[f+628>>2];e=H[g>>2];if(e){H[g+4>>2]=e;oa(e);d=H[f+12>>2];l=H[h+8>>2];b=H[h+12>>2]}H[g+4>>2]=b;H[g>>2]=l;H[g+8>>2]=H[h+16>>2];l=0;H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;ra:{if(d){if(d>>>0>=1073741824){break b}b=d<<2;j=pa(b);H[h+8>>2]=j;l=b+j|0;H[h+16>>2]=l;ra(j,0,b);H[h+12>>2]=l}d=H[f+640>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);j=H[h+8>>2];l=H[h+12>>2]}H[d+4>>2]=l;H[d>>2]=j;H[d+8>>2]=H[h+16>>2];H[h+24>>2]=0;H[h+28>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;xa(h+8|0);d=H[h+24>>2]+H[h+28>>2]|0;b=(d>>>0)/341|0;b=H[H[h+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=z;d=H[h+28>>2]+1|0;H[h+28>>2]=d;sa:{if(!d){break sa}x=f+604|0;y=f+16|0;while(1){n=H[h+12>>2];k=H[h+24>>2];g=d-1|0;e=k+g|0;b=(e>>>0)/341|0;b=H[n+(b<<2)>>2]+N(e-N(b,341)|0,12)|0;p=H[b+8>>2];e=H[b+4>>2];i=H[b>>2];H[h+28>>2]=g;b=H[h+16>>2];if((((b|0)!=(n|0)?N(b-n>>2,341)-1|0:0)-(d+k|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[h+16>>2]=H[h+16>>2]-4}if(i>>>0>z>>>0){break sa}b=H[f+12>>2];j=(e|0)!=(b-1|0)?e+1|0:0;if(j>>>0>=b>>>0){break sa}o=N(p,12);A=o+H[f+640>>2]|0;t=o+H[f+628>>2]|0;g=H[f>>2];q=j<<2;e=H[q+H[A>>2]>>2];ta:{ua:{if((g|0)==(e|0)){o=0;if(!i){break ua}while(1){b=H[t>>2];r=H[b+8>>2];s=H[b+4>>2];n=H[b>>2];p=H[w>>2];d=H[p+4>>2];b=H[p+8>>2];va:{if(d>>>0>>0){H[d+8>>2]=r;H[d+4>>2]=s;H[d>>2]=n;H[p+4>>2]=d+12;break va}q=H[p>>2];g=(d-q|0)/12|0;k=g+1|0;if(k>>>0>=357913942){break b}e=(b-q|0)/12|0;b=e<<1;k=e>>>0>=178956970?357913941:b>>>0>k>>>0?b:k;if(k){if(k>>>0>=357913942){break a}b=pa(N(k,12))}else{b=0}j=b+N(g,12)|0;H[j+8>>2]=r;H[j+4>>2]=s;H[j>>2]=n;e=j+12|0;if((d|0)!=(q|0)){while(1){j=j-12|0;d=d-12|0;H[j>>2]=H[d>>2];H[j+4>>2]=H[d+4>>2];H[j+8>>2]=H[d+8>>2];if((d|0)!=(q|0)){continue}break}}H[p+8>>2]=b+N(k,12);H[p+4>>2]=e;H[p>>2]=j;if(!q){break va}oa(q)}H[f+8>>2]=H[f+8>>2]+1;o=o+1|0;if((i|0)!=(o|0)){continue}break}break ua}wa:{xa:{ya:{if(i>>>0<=2){b=H[f+616>>2];H[b>>2]=j;d=1;l=H[f+12>>2];if(l>>>0>1){break ya}break wa}if(K[f+8>>2]>K[f+4>>2]){break sa}b=H[f+628>>2];s=p+1|0;r=N(s,12);d=b+r|0;if((d|0)!=(t|0)){Aa(d,H[t>>2],H[t+4>>2]);b=H[f+628>>2]}b=q+H[b+r>>2]|0;H[b>>2]=H[b>>2]+(1<>>1|0;break xa}while(1){l=Ba(y+(d<<4)|0)|l<<1;d=d+1|0;if((b|0)!=(d|0)){continue}break}d=i>>>1|0;if(l>>>0<=d>>>0){break xa}break sa}while(1){j=(l-1|0)!=(j|0)?j+1|0:0;H[b+(d<<2)>>2]=j;d=d+1|0;l=H[f+12>>2];if(d>>>0>>0){continue}break}break wa}za:{Aa:{e=d-l|0;d=i-e|0;Ba:{if((d|0)==(e|0)){b=e;break Ba}n=H[f+596>>2];if((n|0)==H[f+588>>2]){break Aa}k=H[n>>2];g=H[f+600>>2];b=g+1|0;H[f+600>>2]=b;g=k&-2147483648>>>g;Ca:{if((b|0)==32){H[f+600>>2]=0;H[f+596>>2]=n+4;if(g){break Ca}break Aa}if(!g){break Aa}}b=d}d=e;break za}b=e}n=H[f+640>>2];k=n+o|0;g=H[k>>2];e=g+q|0;H[e>>2]=H[e>>2]+1;Aa(n+r|0,g,H[k+4>>2]);if(d){g=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];l=H[h+12>>2];if((g|0)==(((e|0)!=(l|0)?N(e-l>>2,341)-1|0:0)|0)){xa(h+8|0);l=H[h+12>>2];g=H[h+24>>2]+H[h+28>>2]|0}e=(g>>>0)/341|0;e=H[(e<<2)+l>>2]+N(g-N(e,341)|0,12)|0;H[e+8>>2]=p;H[e+4>>2]=j;H[e>>2]=d;H[h+28>>2]=H[h+28>>2]+1}if(!b){break ua}l=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];d=H[h+12>>2];if((l|0)==(((d|0)!=(e|0)?N(e-d>>2,341)-1|0:0)|0)){xa(h+8|0);l=H[h+24>>2]+H[h+28>>2]|0;e=H[h+12>>2]}else{e=d}d=(l>>>0)/341|0;d=H[e+(d<<2)>>2]+N(l-N(d,341)|0,12)|0;H[d+8>>2]=s;H[d+4>>2]=j;H[d>>2]=b;d=H[h+28>>2]+1|0;H[h+28>>2]=d;break ta}j=0;if(!i){break ua}while(1){if(H[f+12>>2]){p=H[f+548>>2];n=H[A>>2];u=H[f+604>>2];k=H[f+616>>2];d=0;while(1){o=k+(d<<2)|0;H[u+(H[o>>2]<<2)>>2]=0;g=H[f>>2];e=H[o>>2]<<2;b=H[e+n>>2];Da:{if((g|0)==(b|0)){break Da}q=e+u|0;l=g-b|0;r=H[f+560>>2];g=32-r|0;if((l|0)<=(g|0)){e=H[f+556>>2];if((e|0)==(p|0)){break sa}H[q>>2]=H[e>>2]<>>32-l;b=l+H[f+560>>2]|0;H[f+560>>2]=b;if((b|0)!=32){break Da}H[f+560>>2]=0;H[f+556>>2]=e+4;break Da}s=H[f+556>>2];b=s+4|0;if((b|0)==(p|0)){break sa}e=H[s>>2];H[f+556>>2]=b;b=l-g|0;H[f+560>>2]=b;H[q>>2]=H[s+4>>2]>>>32-b|e<>>32-l}e=H[o>>2]<<2;b=e+u|0;H[b>>2]=H[b>>2]|H[e+H[t>>2]>>2];d=d+1|0;if(d>>>0>2]){continue}break}}jb(w,x);H[f+8>>2]=H[f+8>>2]+1;j=j+1|0;if((i|0)!=(j|0)){continue}break}}d=H[h+28>>2]}if(d){continue}break}}H[h+28>>2]=0;j=H[h+16>>2];d=H[h+12>>2];l=j-d|0;if(l>>>0>=9){while(1){oa(H[d>>2]);d=H[h+12>>2]+4|0;H[h+12>>2]=d;j=H[h+16>>2];l=j-d|0;if(l>>>0>8){continue}break}}b=170;Ea:{switch((l>>>2|0)-1|0){case 1:b=341;case 0:H[h+24>>2]=b;break;default:break Ea}}Fa:{if((d|0)==(j|0)){break Fa}while(1){oa(H[d>>2]);d=d+4|0;if((j|0)!=(d|0)){continue}break}d=H[h+16>>2];b=H[h+12>>2];if((d|0)==(b|0)){break Fa}H[h+16>>2]=d+((b-d|0)+3&-4)}b=H[h+8>>2];if(b){oa(b)}ca=h+32|0;break ra}}ab(f);break d;case 5:f=$a(B+8|0,3);w=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;Ga:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break Ga}d=e+H[b>>2]|0;H[f>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[f>>2]>32){break Ga}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break Ga}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[f+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break Ga}H[f+8>>2]=0;if(!sb(f+16|0,b)){break Ga}if(!ua(f+544|0,b)){break Ga}if(!ua(f+564|0,b)){break Ga}if(!ua(f+584|0,b)){break Ga}z=H[f+4>>2];l=0;b=0;h=ca-32|0;ca=h;d=H[f+12>>2];H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;if(d){if(d>>>0>=1073741824){break b}e=d<<2;l=pa(e);H[h+8>>2]=l;b=e+l|0;H[h+16>>2]=b;ra(l,0,e);H[h+12>>2]=b}g=H[f+628>>2];e=H[g>>2];if(e){H[g+4>>2]=e;oa(e);d=H[f+12>>2];l=H[h+8>>2];b=H[h+12>>2]}H[g+4>>2]=b;H[g>>2]=l;H[g+8>>2]=H[h+16>>2];l=0;H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;Ha:{if(d){if(d>>>0>=1073741824){break b}b=d<<2;p=pa(b);H[h+8>>2]=p;l=b+p|0;H[h+16>>2]=l;ra(p,0,b);H[h+12>>2]=l}d=H[f+640>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);l=H[h+12>>2];p=H[h+8>>2]}H[d+4>>2]=l;H[d>>2]=p;H[d+8>>2]=H[h+16>>2];H[h+24>>2]=0;H[h+28>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;xa(h+8|0);d=H[h+24>>2]+H[h+28>>2]|0;b=(d>>>0)/341|0;b=H[H[h+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=z;d=H[h+28>>2]+1|0;H[h+28>>2]=d;Ia:{if(!d){break Ia}x=f+604|0;y=f+16|0;while(1){n=H[h+12>>2];k=H[h+24>>2];g=d-1|0;e=k+g|0;b=(e>>>0)/341|0;b=H[n+(b<<2)>>2]+N(e-N(b,341)|0,12)|0;o=H[b+8>>2];e=H[b+4>>2];i=H[b>>2];H[h+28>>2]=g;b=H[h+16>>2];if((((b|0)!=(n|0)?N(b-n>>2,341)-1|0:0)-(d+k|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[h+16>>2]=H[h+16>>2]-4}if(i>>>0>z>>>0){break Ia}m=0;b=H[f+12>>2];p=(e|0)!=(b-1|0)?e+1|0:0;if(p>>>0>=b>>>0){break Ia}b=H[f+628>>2];q=N(o,12);t=b+q|0;e=H[f>>2];r=p<<2;s=q+H[f+640>>2]|0;d=H[r+H[s>>2]>>2];Ja:{Ka:{if((e|0)==(d|0)){if(!i){break Ka}while(1){b=H[t>>2];r=H[b+8>>2];s=H[b+4>>2];n=H[b>>2];o=H[w>>2];d=H[o+4>>2];b=H[o+8>>2];La:{if(d>>>0>>0){H[d+8>>2]=r;H[d+4>>2]=s;H[d>>2]=n;H[o+4>>2]=d+12;break La}q=H[o>>2];g=(d-q|0)/12|0;k=g+1|0;if(k>>>0>=357913942){break b}e=(b-q|0)/12|0;b=e<<1;k=e>>>0>=178956970?357913941:b>>>0>k>>>0?b:k;if(k){if(k>>>0>=357913942){break a}b=pa(N(k,12))}else{b=0}p=b+N(g,12)|0;H[p+8>>2]=r;H[p+4>>2]=s;H[p>>2]=n;e=p+12|0;if((d|0)!=(q|0)){while(1){p=p-12|0;d=d-12|0;H[p>>2]=H[d>>2];H[p+4>>2]=H[d+4>>2];H[p+8>>2]=H[d+8>>2];if((d|0)!=(q|0)){continue}break}}H[o+8>>2]=b+N(k,12);H[o+4>>2]=e;H[o>>2]=p;if(!q){break La}oa(q)}H[f+8>>2]=H[f+8>>2]+1;m=m+1|0;if((i|0)!=(m|0)){continue}break}break Ka}Ma:{Na:{Oa:{if(i>>>0<=2){b=H[f+616>>2];H[b>>2]=p;d=1;l=H[f+12>>2];if(l>>>0>1){break Oa}break Ma}if(K[f+8>>2]>K[f+4>>2]){break Ia}k=b;b=q+12|0;Aa(k+b|0,H[t>>2],H[t+4>>2]);b=r+H[b+H[f+628>>2]>>2]|0;H[b>>2]=H[b>>2]+(1<>>1|0;break Na}while(1){l=Ba(y+(d<<4)|0)|l<<1;d=d+1|0;if((b|0)!=(d|0)){continue}break}d=i>>>1|0;if(l>>>0<=d>>>0){break Na}break Ia}while(1){p=(l-1|0)!=(p|0)?p+1|0:0;H[b+(d<<2)>>2]=p;d=d+1|0;l=H[f+12>>2];if(d>>>0>>0){continue}break}break Ma}s=o+1|0;Pa:{Qa:{e=d-l|0;d=i-e|0;Ra:{if((d|0)==(e|0)){b=e;break Ra}n=H[f+596>>2];if((n|0)==H[f+588>>2]){break Qa}k=H[n>>2];g=H[f+600>>2];b=g+1|0;H[f+600>>2]=b;g=k&-2147483648>>>g;Sa:{if((b|0)==32){H[f+600>>2]=0;H[f+596>>2]=n+4;if(g){break Sa}break Qa}if(!g){break Qa}}b=d}d=e;break Pa}b=e}n=H[f+640>>2];k=n+q|0;g=H[k>>2];e=g+r|0;H[e>>2]=H[e>>2]+1;Aa(n+N(s,12)|0,g,H[k+4>>2]);if(d){m=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];l=H[h+12>>2];if((m|0)==(((e|0)!=(l|0)?N(e-l>>2,341)-1|0:0)|0)){xa(h+8|0);m=H[h+24>>2]+H[h+28>>2]|0;l=H[h+12>>2]}e=(m>>>0)/341|0;e=H[l+(e<<2)>>2]+N(m-N(e,341)|0,12)|0;H[e+8>>2]=o;H[e+4>>2]=p;H[e>>2]=d;H[h+28>>2]=H[h+28>>2]+1}if(!b){break Ka}l=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];d=H[h+12>>2];if((l|0)==(((d|0)!=(e|0)?N(e-d>>2,341)-1|0:0)|0)){xa(h+8|0);l=H[h+24>>2]+H[h+28>>2]|0;e=H[h+12>>2]}else{e=d}d=(l>>>0)/341|0;d=H[e+(d<<2)>>2]+N(l-N(d,341)|0,12)|0;H[d+8>>2]=s;H[d+4>>2]=p;H[d>>2]=b;d=H[h+28>>2]+1|0;H[h+28>>2]=d;break Ja}if(!i){break Ka}while(1){if(H[f+12>>2]){A=H[f+548>>2];n=H[s>>2];u=H[f+604>>2];k=H[f+616>>2];d=0;while(1){p=k+(d<<2)|0;H[u+(H[p>>2]<<2)>>2]=0;g=H[f>>2];e=H[p>>2]<<2;b=H[e+n>>2];Ta:{if((g|0)==(b|0)){break Ta}o=e+u|0;l=g-b|0;q=H[f+560>>2];g=32-q|0;if((l|0)<=(g|0)){e=H[f+556>>2];if((e|0)==(A|0)){break Ia}H[o>>2]=H[e>>2]<>>32-l;b=l+H[f+560>>2]|0;H[f+560>>2]=b;if((b|0)!=32){break Ta}H[f+560>>2]=0;H[f+556>>2]=e+4;break Ta}r=H[f+556>>2];b=r+4|0;if((b|0)==(A|0)){break Ia}e=H[r>>2];H[f+556>>2]=b;b=l-g|0;H[f+560>>2]=b;H[o>>2]=H[r+4>>2]>>>32-b|e<>>32-l}e=H[p>>2]<<2;b=e+u|0;H[b>>2]=H[b>>2]|H[e+H[t>>2]>>2];d=d+1|0;if(d>>>0>2]){continue}break}}jb(w,x);H[f+8>>2]=H[f+8>>2]+1;m=m+1|0;if((i|0)!=(m|0)){continue}break}}d=H[h+28>>2]}if(d){continue}break}}H[h+28>>2]=0;p=H[h+16>>2];d=H[h+12>>2];l=p-d|0;if(l>>>0>=9){while(1){oa(H[d>>2]);d=H[h+12>>2]+4|0;H[h+12>>2]=d;p=H[h+16>>2];l=p-d|0;if(l>>>0>8){continue}break}}b=170;Ua:{switch((l>>>2|0)-1|0){case 1:b=341;case 0:H[h+24>>2]=b;break;default:break Ua}}Va:{if((d|0)==(p|0)){break Va}while(1){oa(H[d>>2]);d=d+4|0;if((p|0)!=(d|0)){continue}break}d=H[h+16>>2];b=H[h+12>>2];if((d|0)==(b|0)){break Va}H[h+16>>2]=d+((b-d|0)+3&-4)}b=H[h+8>>2];if(b){oa(b)}ca=h+32|0;break Ha}}ab(f);break d;case 6:break f;default:break c}}f=$a(B+8|0,3);w=B+664|0;k=H[b+8>>2];n=H[b+12>>2];d=H[b+20>>2];e=H[b+16>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;Wa:{if(g>>>0>k>>>0&(d|0)>=(n|0)|(d|0)>(n|0)){break Wa}d=e+H[b>>2]|0;H[f>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[b+20>>2];k=d;g=H[b+16>>2];e=g+4|0;d=e>>>0<4?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;if(K[f>>2]>32){break Wa}n=H[b+8>>2];s=H[b+12>>2];d=k;g=g+8|0;d=g>>>0<8?d+1|0:d;if(g>>>0>n>>>0&(d|0)>=(s|0)|(d|0)>(s|0)){break Wa}d=e+H[b>>2]|0;e=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[f+4>>2]=e;g=H[b+20>>2];d=H[b+16>>2]+4|0;g=d>>>0<4?g+1|0:g;H[b+16>>2]=d;H[b+20>>2]=g;if(!e){break Wa}H[f+8>>2]=0;if(!sb(f+16|0,b)){break Wa}if(!ua(f+544|0,b)){break Wa}if(!ua(f+564|0,b)){break Wa}if(!ua(f+584|0,b)){break Wa}z=H[f+4>>2];l=0;b=0;h=ca-32|0;ca=h;d=H[f+12>>2];H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;if(d){if(d>>>0>=1073741824){break b}e=d<<2;l=pa(e);H[h+8>>2]=l;b=e+l|0;H[h+16>>2]=b;ra(l,0,e);H[h+12>>2]=b}g=H[f+628>>2];e=H[g>>2];if(e){H[g+4>>2]=e;oa(e);d=H[f+12>>2];l=H[h+8>>2];b=H[h+12>>2]}H[g+4>>2]=b;H[g>>2]=l;H[g+8>>2]=H[h+16>>2];l=0;H[h+16>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;Xa:{if(d){if(d>>>0>=1073741824){break b}b=d<<2;j=pa(b);H[h+8>>2]=j;l=b+j|0;H[h+16>>2]=l;ra(j,0,b);H[h+12>>2]=l}d=H[f+640>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b);j=H[h+8>>2];l=H[h+12>>2]}H[d+4>>2]=l;H[d>>2]=j;H[d+8>>2]=H[h+16>>2];H[h+24>>2]=0;H[h+28>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;H[h+8>>2]=0;H[h+12>>2]=0;xa(h+8|0);d=H[h+24>>2]+H[h+28>>2]|0;b=(d>>>0)/341|0;b=H[H[h+12>>2]+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;H[b+4>>2]=0;H[b+8>>2]=0;H[b>>2]=z;d=H[h+28>>2]+1|0;H[h+28>>2]=d;Ya:{if(!d){break Ya}x=f+604|0;y=f+16|0;while(1){n=H[h+12>>2];k=H[h+24>>2];g=d-1|0;e=k+g|0;b=(e>>>0)/341|0;b=H[n+(b<<2)>>2]+N(e-N(b,341)|0,12)|0;p=H[b+8>>2];i=H[b>>2];H[h+28>>2]=g;b=H[h+16>>2];if((((b|0)!=(n|0)?N(b-n>>2,341)-1|0:0)-(d+k|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[h+16>>2]=H[h+16>>2]-4}if(i>>>0>z>>>0){break Ya}b=H[f+628>>2];o=N(p,12);A=o+H[f+640>>2]|0;j=Vd(f,i,A);if(j>>>0>=K[f+12>>2]){break Ya}t=b+o|0;g=H[f>>2];q=j<<2;e=H[q+H[A>>2]>>2];Za:{_a:{if((g|0)==(e|0)){o=0;if(!i){break _a}while(1){b=H[t>>2];r=H[b+8>>2];s=H[b+4>>2];n=H[b>>2];p=H[w>>2];d=H[p+4>>2];b=H[p+8>>2];$a:{if(d>>>0>>0){H[d+8>>2]=r;H[d+4>>2]=s;H[d>>2]=n;H[p+4>>2]=d+12;break $a}q=H[p>>2];g=(d-q|0)/12|0;k=g+1|0;if(k>>>0>=357913942){break b}e=(b-q|0)/12|0;b=e<<1;k=e>>>0>=178956970?357913941:b>>>0>k>>>0?b:k;if(k){if(k>>>0>=357913942){break a}b=pa(N(k,12))}else{b=0}j=b+N(g,12)|0;H[j+8>>2]=r;H[j+4>>2]=s;H[j>>2]=n;e=j+12|0;if((d|0)!=(q|0)){while(1){j=j-12|0;d=d-12|0;H[j>>2]=H[d>>2];H[j+4>>2]=H[d+4>>2];H[j+8>>2]=H[d+8>>2];if((d|0)!=(q|0)){continue}break}}H[p+8>>2]=b+N(k,12);H[p+4>>2]=e;H[p>>2]=j;if(!q){break $a}oa(q)}H[f+8>>2]=H[f+8>>2]+1;o=o+1|0;if((i|0)!=(o|0)){continue}break}break _a}ab:{bb:{cb:{if(i>>>0<=2){b=H[f+616>>2];H[b>>2]=j;d=1;l=H[f+12>>2];if(l>>>0>1){break cb}break ab}if(K[f+8>>2]>K[f+4>>2]){break Ya}b=H[f+628>>2];s=p+1|0;r=N(s,12);d=b+r|0;if((d|0)!=(t|0)){Aa(d,H[t>>2],H[t+4>>2]);b=H[f+628>>2]}b=q+H[b+r>>2]|0;H[b>>2]=H[b>>2]+(1<>>1|0;break bb}while(1){l=Ba(y+(d<<4)|0)|l<<1;d=d+1|0;if((b|0)!=(d|0)){continue}break}d=i>>>1|0;if(l>>>0<=d>>>0){break bb}break Ya}while(1){j=(l-1|0)!=(j|0)?j+1|0:0;H[b+(d<<2)>>2]=j;d=d+1|0;l=H[f+12>>2];if(d>>>0>>0){continue}break}break ab}db:{eb:{e=d-l|0;d=i-e|0;fb:{if((d|0)==(e|0)){b=e;break fb}n=H[f+596>>2];if((n|0)==H[f+588>>2]){break eb}k=H[n>>2];g=H[f+600>>2];b=g+1|0;H[f+600>>2]=b;g=k&-2147483648>>>g;gb:{if((b|0)==32){H[f+600>>2]=0;H[f+596>>2]=n+4;if(g){break gb}break eb}if(!g){break eb}}b=d}d=e;break db}b=e}n=H[f+640>>2];k=n+o|0;g=H[k>>2];e=g+q|0;H[e>>2]=H[e>>2]+1;Aa(n+r|0,g,H[k+4>>2]);if(d){g=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];l=H[h+12>>2];if((g|0)==(((e|0)!=(l|0)?N(e-l>>2,341)-1|0:0)|0)){xa(h+8|0);l=H[h+12>>2];g=H[h+24>>2]+H[h+28>>2]|0}e=(g>>>0)/341|0;e=H[(e<<2)+l>>2]+N(g-N(e,341)|0,12)|0;H[e+8>>2]=p;H[e+4>>2]=j;H[e>>2]=d;H[h+28>>2]=H[h+28>>2]+1}if(!b){break _a}l=H[h+28>>2]+H[h+24>>2]|0;e=H[h+16>>2];d=H[h+12>>2];if((l|0)==(((d|0)!=(e|0)?N(e-d>>2,341)-1|0:0)|0)){xa(h+8|0);l=H[h+24>>2]+H[h+28>>2]|0;e=H[h+12>>2]}else{e=d}d=(l>>>0)/341|0;d=H[e+(d<<2)>>2]+N(l-N(d,341)|0,12)|0;H[d+8>>2]=s;H[d+4>>2]=j;H[d>>2]=b;d=H[h+28>>2]+1|0;H[h+28>>2]=d;break Za}j=0;if(!i){break _a}while(1){if(H[f+12>>2]){p=H[f+548>>2];n=H[A>>2];u=H[f+604>>2];k=H[f+616>>2];d=0;while(1){o=k+(d<<2)|0;H[u+(H[o>>2]<<2)>>2]=0;g=H[f>>2];e=H[o>>2]<<2;b=H[e+n>>2];hb:{if((g|0)==(b|0)){break hb}q=e+u|0;l=g-b|0;r=H[f+560>>2];g=32-r|0;if((l|0)<=(g|0)){e=H[f+556>>2];if((e|0)==(p|0)){break Ya}H[q>>2]=H[e>>2]<>>32-l;b=l+H[f+560>>2]|0;H[f+560>>2]=b;if((b|0)!=32){break hb}H[f+560>>2]=0;H[f+556>>2]=e+4;break hb}s=H[f+556>>2];b=s+4|0;if((b|0)==(p|0)){break Ya}e=H[s>>2];H[f+556>>2]=b;b=l-g|0;H[f+560>>2]=b;H[q>>2]=H[s+4>>2]>>>32-b|e<>>32-l}e=H[o>>2]<<2;b=e+u|0;H[b>>2]=H[b>>2]|H[e+H[t>>2]>>2];d=d+1|0;if(d>>>0>2]){continue}break}}jb(w,x);H[f+8>>2]=H[f+8>>2]+1;j=j+1|0;if((i|0)!=(j|0)){continue}break}}d=H[h+28>>2]}if(d){continue}break}}H[h+28>>2]=0;j=H[h+16>>2];d=H[h+12>>2];l=j-d|0;if(l>>>0>=9){while(1){oa(H[d>>2]);d=H[h+12>>2]+4|0;H[h+12>>2]=d;j=H[h+16>>2];l=j-d|0;if(l>>>0>8){continue}break}}b=170;ib:{switch((l>>>2|0)-1|0){case 1:b=341;case 0:H[h+24>>2]=b;break;default:break ib}}jb:{if((d|0)==(j|0)){break jb}while(1){oa(H[d>>2]);d=d+4|0;if((j|0)!=(d|0)){continue}break}d=H[h+16>>2];b=H[h+12>>2];if((d|0)==(b|0)){break jb}H[h+16>>2]=d+((b-d|0)+3&-4)}b=H[h+8>>2];if(b){oa(b)}ca=h+32|0;break Xa}}ab(f)}n=H[a+12>>2]==((H[c+4>>2]-H[c>>2]|0)/12|0)}ca=B+672|0;return n}sa();v()}wa();v()}function kd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0;if(!a){return 1}e=H[c+20>>2];g=H[c+12>>2];i=H[c+16>>2];a:{if((e|0)>=(g|0)&i>>>0>=K[c+8>>2]|(e|0)>(g|0)){break a}g=I[i+H[c>>2]|0];i=i+1|0;e=i?e:e+1|0;H[c+16>>2]=i;H[c+20>>2]=e;b:{switch(g|0){case 0:e=a;f=b;i=d;a=0;d=0;m=ca+-64|0;ca=m;H[m+56>>2]=0;H[m+48>>2]=0;H[m+52>>2]=0;H[m+40>>2]=0;H[m+44>>2]=0;H[m+32>>2]=0;H[m+36>>2]=0;H[m+24>>2]=0;H[m+28>>2]=0;H[m+16>>2]=0;H[m+20>>2]=0;H[m+8>>2]=0;H[m+12>>2]=0;c:{if(!Ne(m+8|0,c)){break c}if(!Me(m+8|0,c)|(H[m+20>>2]?0:e)){break c}Db(c,0,0);if(e){s=f<<2;t=H[m+36>>2];w=H[m+48>>2];x=H[m+24>>2];l=H[m+56>>2];j=H[m+52>>2];while(1){d:{if(l>>>0>16383){break d}while(1){if((j|0)<=0){break d}j=j-1|0;H[m+52>>2]=j;l=I[j+w|0]|l<<8;H[m+56>>2]=l;if(l>>>0<16384){continue}break}}a=l&4095;r=H[(a<<2)+x>>2];b=(r<<3)+t|0;l=(N(H[b>>2],l>>>12|0)+a|0)-H[b+4>>2]|0;H[m+56>>2]=l;if((f|0)>0){a=0;if(!I[c+36|0]|r>>>0>32){break c}g=d+f|0;e:{if(!r){ra(i+(d<<2)|0,0,s);break e}y=r&-2;z=r&1;b=H[c+32>>2];h=H[c+28>>2];n=H[c+24>>2];while(1){k=0;a=b;o=0;q=0;if((r|0)!=1){while(1){p=n+(a>>>3|0)|0;f:{if(p>>>0>=h>>>0){p=0;break f}p=I[p|0];b=a+1|0;H[c+32>>2]=b;p=p>>>(a&7)&1;a=b}p=p<>>3|0)|0;if(u>>>0>>0){o=I[u|0];b=a+1|0;H[c+32>>2]=b;o=o>>>(a&7)&1;a=b}u=k|1;k=k+2|0;o=p|o<>>3|0)|0;if(p>>>0>>0){p=I[p|0];b=a+1|0;H[c+32>>2]=b;a=p>>>(a&7)&1}else{a=0}o=a<>2]=o;d=d+1|0;if((g|0)!=(d|0)){continue}break}}d=g}v=f+v|0;if(e>>>0>v>>>0){continue}break}}F[c+36|0]=0;b=H[c+20>>2];e=0;d=H[c+32>>2]+7|0;e=d>>>0<7?1:e;d=(e&7)<<29|d>>>3;a=d+H[c+16>>2]|0;e=(e>>>3|0)+b|0;H[c+16>>2]=a;H[c+20>>2]=a>>>0>>0?e+1|0:e;a=1}b=H[m+36>>2];if(b){H[m+40>>2]=b;oa(b)}b=H[m+24>>2];if(b){H[m+28>>2]=b;oa(b)}b=H[m+8>>2];if(b){H[m+12>>2]=b;oa(b)}ca=m- -64|0;return a;case 1:break b;default:break a}}b=0;e=H[c+20>>2];g=H[c+12>>2];i=H[c+16>>2];g:{if((e|0)>=(g|0)&i>>>0>=K[c+8>>2]|(e|0)>(g|0)){break g}g=I[i+H[c>>2]|0];i=i+1|0;e=i?e:e+1|0;H[c+16>>2]=i;H[c+20>>2]=e;h:{switch(g-1|0){case 8:g=a;r=d;i=ca+-64|0;ca=i;H[i+56>>2]=0;H[i+48>>2]=0;H[i+52>>2]=0;H[i+40>>2]=0;H[i+44>>2]=0;H[i+32>>2]=0;H[i+36>>2]=0;H[i+24>>2]=0;H[i+28>>2]=0;H[i+16>>2]=0;H[i+20>>2]=0;H[i+8>>2]=0;H[i+12>>2]=0;j=i+8|0;a=J[c+38>>1];i:{j:{if(!a){break j}k:{if(a>>>0<=511){d=H[c+8>>2];b=H[c+12>>2];e=H[c+20>>2];a=H[c+16>>2];f=a+4|0;e=f>>>0<4?e+1|0:e;if(d>>>0>>0&(b|0)<=(e|0)|(b|0)<(e|0)){break j}a=a+H[c>>2]|0;h=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);H[j+12>>2]=h;e=H[c+20>>2];f=H[c+16>>2]+4|0;e=f>>>0<4?e+1|0:e;H[c+16>>2]=f;H[c+20>>2]=e;break k}if(!hb(1,j+12|0,c)){break j}f=H[c+16>>2];e=H[c+20>>2];h=H[j+12>>2]}a=H[c+8>>2];d=a-f|0;a=H[c+12>>2]-((a>>>0>>0)+e|0)|0;if(d>>>0>>6>>>0&(a|0)<=0|(a|0)<0){break j}b=H[j>>2];a=H[j+4>>2]-b>>2;l:{if(a>>>0>>0){ya(j,h-a|0);h=H[j+12>>2];break l}if(a>>>0<=h>>>0){break l}H[j+4>>2]=b+(h<<2)}d=1;if(!h){break i}f=H[c+16>>2];e=H[c+20>>2];s=H[j>>2];m=H[c+8>>2];n=H[c+12>>2];b=0;while(1){d=0;if((e|0)>=(n|0)&f>>>0>=m>>>0|(e|0)>(n|0)){break i}d=H[c>>2];p=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=p>>>2|0;l=0;m:{n:{o:{p:{t=p&3;switch(t|0){case 0:break n;case 3:break p;default:break o}}a=a+b|0;d=0;if(a>>>0>=h>>>0){break i}ra(s+(b<<2)|0,0,(p&252)+4|0);b=a;break m}while(1){if((f|0)==(m|0)&(e|0)==(n|0)){break j}h=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=h<<(l<<3|6)|a;l=l+1|0;if((t|0)!=(l|0)){continue}break}}H[s+(b<<2)>>2]=a}b=b+1|0;h=H[j+12>>2];if(b>>>0>>0){continue}break}a=j+16|0;n=H[j>>2];d=H[j+16>>2];b=H[j+20>>2]-d|0;q:{if(b>>>0<=32767){ya(a,8192-(b>>>2|0)|0);break q}if((b|0)==32768){break q}H[j+20>>2]=d+32768}d=j+28|0;b=H[d>>2];f=H[j+32>>2]-b>>3;r:{if(f>>>0>>0){ob(d,h-f|0);b=H[d>>2];break r}if(f>>>0>h>>>0){H[j+32>>2]=(h<<3)+b}if(!h){break j}}m=H[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;j=H[e>>2];l=(f<<3)+b|0;a=d;H[l+4>>2]=a;H[l>>2]=j;e=H[e>>2];d=e+a|0;if(d>>>0>8192){break j}s:{if(a>>>0>=d>>>0){break s}l=0;j=e&7;if(j){while(1){H[m+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((j|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break s}while(1){e=m+(a<<2)|0;H[e>>2]=f;H[e+28>>2]=f;H[e+24>>2]=f;H[e+20>>2]=f;H[e+16>>2]=f;H[e+12>>2]=f;H[e+8>>2]=f;H[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((h|0)!=(f|0)){continue}break}k=(d|0)==8192}d=k}t:{if(!d|(H[i+20>>2]?0:g)){break t}d=0;m=ca-16|0;ca=m;u:{v:{if(J[c+38>>1]<=511){b=H[c+8>>2];a=H[c+12>>2];h=a;e=H[c+20>>2];k=H[c+16>>2];f=k+8|0;e=f>>>0<8?e+1|0:e;if(b>>>0>>0&(a|0)<=(e|0)|(a|0)<(e|0)){break u}k=k+H[c>>2]|0;a=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);k=I[k+4|0]|I[k+5|0]<<8|(I[k+6|0]<<16|I[k+7|0]<<24);H[c+16>>2]=f;H[c+20>>2]=e;break v}if(!gb(1,m+8|0,c)){break u}f=H[c+16>>2];e=H[c+20>>2];b=H[c+8>>2];h=H[c+12>>2];a=H[m+8>>2];k=H[m+12>>2]}j=b-f|0;b=h-((b>>>0>>0)+e|0)|0;if((b|0)==(k|0)&a>>>0>j>>>0|b>>>0>>0){break u}e=e+k|0;b=a+f|0;e=b>>>0>>0?e+1|0:e;H[c+16>>2]=b;H[c+20>>2]=e;if((a|0)<=0){break u}b=H[c>>2]+f|0;H[i+48>>2]=b;c=a-1|0;f=c+b|0;e=I[f|0];w:{if(e>>>0<=63){H[i+52>>2]=c;a=I[f|0]&63;break w}x:{switch((e>>>6|0)-1|0){case 0:if(a>>>0<2){break u}a=a-2|0;H[i+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8&16128|I[a|0];break w;case 1:if(a>>>0<3){break u}a=a-3|0;H[i+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8|I[a+2|0]<<16&4128768|I[a|0];break w;default:break x}}a=a-4|0;H[i+52>>2]=a;a=a+b|0;a=(I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24))&1073741823}H[i+56>>2]=a+32768;d=a>>>0<8355840}ca=m+16|0;if(!d){break t}if(!g){o=1;break t}b=H[i+52>>2];a=H[i+56>>2];c=H[i+36>>2];d=H[i+48>>2];f=H[i+24>>2];while(1){y:{if(a>>>0>32767){break y}while(1){if((b|0)<=0){break y}b=b-1|0;H[i+52>>2]=b;a=I[b+d|0]|a<<8;H[i+56>>2]=a;if(a>>>0<32768){continue}break}}e=a&8191;o=H[f+(e<<2)>>2];k=c+(o<<3)|0;a=(N(H[k>>2],a>>>13|0)+e|0)-H[k+4>>2]|0;H[i+56>>2]=a;H[r+(q<<2)>>2]=o;o=1;q=q+1|0;if((g|0)!=(q|0)){continue}break}}a=H[i+36>>2];if(a){H[i+40>>2]=a;oa(a)}a=H[i+24>>2];if(a){H[i+28>>2]=a;oa(a)}a=H[i+8>>2];if(a){H[i+12>>2]=a;oa(a)}ca=i- -64|0;b=o;break g;case 9:m=a;r=d;g=ca+-64|0;ca=g;H[g+56>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;j=g+8|0;a=J[c+38>>1];z:{A:{if(!a){break A}B:{if(a>>>0<=511){d=H[c+8>>2];b=H[c+12>>2];e=H[c+20>>2];a=H[c+16>>2];f=a+4|0;e=f>>>0<4?e+1|0:e;if(d>>>0>>0&(b|0)<=(e|0)|(b|0)<(e|0)){break A}a=a+H[c>>2]|0;h=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);H[j+12>>2]=h;e=H[c+20>>2];f=H[c+16>>2]+4|0;e=f>>>0<4?e+1|0:e;H[c+16>>2]=f;H[c+20>>2]=e;break B}if(!hb(1,j+12|0,c)){break A}f=H[c+16>>2];e=H[c+20>>2];h=H[j+12>>2]}a=H[c+8>>2];d=a-f|0;a=H[c+12>>2]-((a>>>0>>0)+e|0)|0;if(d>>>0>>6>>>0&(a|0)<=0|(a|0)<0){break A}b=H[j>>2];a=H[j+4>>2]-b>>2;C:{if(a>>>0>>0){ya(j,h-a|0);h=H[j+12>>2];break C}if(a>>>0<=h>>>0){break C}H[j+4>>2]=b+(h<<2)}d=1;if(!h){break z}f=H[c+16>>2];e=H[c+20>>2];s=H[j>>2];i=H[c+8>>2];n=H[c+12>>2];b=0;while(1){d=0;if((e|0)>=(n|0)&f>>>0>=i>>>0|(e|0)>(n|0)){break z}d=H[c>>2];p=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=p>>>2|0;l=0;D:{E:{F:{G:{t=p&3;switch(t|0){case 0:break E;case 3:break G;default:break F}}a=a+b|0;d=0;if(a>>>0>=h>>>0){break z}ra(s+(b<<2)|0,0,(p&252)+4|0);b=a;break D}while(1){if((f|0)==(i|0)&(e|0)==(n|0)){break A}h=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=h<<(l<<3|6)|a;l=l+1|0;if((t|0)!=(l|0)){continue}break}}H[s+(b<<2)>>2]=a}b=b+1|0;h=H[j+12>>2];if(b>>>0>>0){continue}break}a=j+16|0;n=H[j>>2];d=H[j+16>>2];b=H[j+20>>2]-d|0;H:{if(b>>>0<=131071){ya(a,32768-(b>>>2|0)|0);break H}if((b|0)==131072){break H}H[j+20>>2]=d+131072}d=j+28|0;b=H[d>>2];f=H[j+32>>2]-b>>3;I:{if(f>>>0>>0){ob(d,h-f|0);b=H[d>>2];break I}if(f>>>0>h>>>0){H[j+32>>2]=(h<<3)+b}if(!h){break A}}i=H[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;j=H[e>>2];l=(f<<3)+b|0;a=d;H[l+4>>2]=a;H[l>>2]=j;e=H[e>>2];d=e+a|0;if(d>>>0>32768){break A}J:{if(a>>>0>=d>>>0){break J}l=0;j=e&7;if(j){while(1){H[i+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((j|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break J}while(1){e=i+(a<<2)|0;H[e>>2]=f;H[e+28>>2]=f;H[e+24>>2]=f;H[e+20>>2]=f;H[e+16>>2]=f;H[e+12>>2]=f;H[e+8>>2]=f;H[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((h|0)!=(f|0)){continue}break}k=(d|0)==32768}d=k}K:{if(!d|(H[g+20>>2]?0:m)){break K}d=0;j=ca-16|0;ca=j;L:{M:{if(J[c+38>>1]<=511){b=H[c+8>>2];a=H[c+12>>2];h=a;e=H[c+20>>2];k=H[c+16>>2];f=k+8|0;e=f>>>0<8?e+1|0:e;if(b>>>0>>0&(a|0)<=(e|0)|(a|0)<(e|0)){break L}k=k+H[c>>2]|0;a=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);k=I[k+4|0]|I[k+5|0]<<8|(I[k+6|0]<<16|I[k+7|0]<<24);H[c+16>>2]=f;H[c+20>>2]=e;break M}if(!gb(1,j+8|0,c)){break L}f=H[c+16>>2];e=H[c+20>>2];b=H[c+8>>2];h=H[c+12>>2];a=H[j+8>>2];k=H[j+12>>2]}i=b-f|0;b=h-((b>>>0>>0)+e|0)|0;if((b|0)==(k|0)&a>>>0>i>>>0|b>>>0>>0){break L}i=e+k|0;b=a+f|0;i=b>>>0>>0?i+1|0:i;H[c+16>>2]=b;H[c+20>>2]=i;if((a|0)<=0){break L}b=H[c>>2]+f|0;H[g+48>>2]=b;c=a-1|0;f=c+b|0;e=I[f|0];N:{if(e>>>0<=63){H[g+52>>2]=c;a=I[f|0]&63;break N}O:{switch((e>>>6|0)-1|0){case 0:if(a>>>0<2){break L}a=a-2|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8&16128|I[a|0];break N;case 1:if(a>>>0<3){break L}a=a-3|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8|I[a+2|0]<<16&4128768|I[a|0];break N;default:break O}}a=a-4|0;H[g+52>>2]=a;a=a+b|0;a=(I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24))&1073741823}H[g+56>>2]=a+131072;d=a>>>0<33423360}ca=j+16|0;if(!d){break K}if(!m){o=1;break K}b=H[g+52>>2];a=H[g+56>>2];c=H[g+36>>2];d=H[g+48>>2];f=H[g+24>>2];while(1){P:{if(a>>>0>131071){break P}while(1){if((b|0)<=0){break P}b=b-1|0;H[g+52>>2]=b;a=I[b+d|0]|a<<8;H[g+56>>2]=a;if(a>>>0<131072){continue}break}}e=a&32767;o=H[f+(e<<2)>>2];k=c+(o<<3)|0;a=(N(H[k>>2],a>>>15|0)+e|0)-H[k+4>>2]|0;H[g+56>>2]=a;H[r+(q<<2)>>2]=o;o=1;q=q+1|0;if((m|0)!=(q|0)){continue}break}}a=H[g+36>>2];if(a){H[g+40>>2]=a;oa(a)}a=H[g+24>>2];if(a){H[g+28>>2]=a;oa(a)}a=H[g+8>>2];if(a){H[g+12>>2]=a;oa(a)}ca=g- -64|0;b=o;break g;case 10:m=a;j=d;g=ca+-64|0;ca=g;H[g+56>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;n=g+8|0;a=J[c+38>>1];Q:{R:{if(!a){break R}S:{if(a>>>0<=511){d=H[c+8>>2];b=H[c+12>>2];e=H[c+20>>2];a=H[c+16>>2];f=a+4|0;e=f>>>0<4?e+1|0:e;if(d>>>0>>0&(b|0)<=(e|0)|(b|0)<(e|0)){break R}a=a+H[c>>2]|0;h=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);H[n+12>>2]=h;e=H[c+20>>2];f=H[c+16>>2]+4|0;e=f>>>0<4?e+1|0:e;H[c+16>>2]=f;H[c+20>>2]=e;break S}if(!hb(1,n+12|0,c)){break R}f=H[c+16>>2];e=H[c+20>>2];h=H[n+12>>2]}a=H[c+8>>2];d=a-f|0;a=H[c+12>>2]-((a>>>0>>0)+e|0)|0;if(d>>>0>>6>>>0&(a|0)<=0|(a|0)<0){break R}b=H[n>>2];a=H[n+4>>2]-b>>2;T:{if(a>>>0>>0){ya(n,h-a|0);h=H[n+12>>2];break T}if(a>>>0<=h>>>0){break T}H[n+4>>2]=b+(h<<2)}d=1;if(!h){break Q}f=H[c+16>>2];e=H[c+20>>2];t=H[n>>2];r=H[c+8>>2];p=H[c+12>>2];b=0;while(1){d=0;if((e|0)>=(p|0)&f>>>0>=r>>>0|(e|0)>(p|0)){break Q}d=H[c>>2];s=I[d+f|0];f=f+1|0;i=f?e:e+1|0;H[c+16>>2]=f;e=i;H[c+20>>2]=e;a=s>>>2|0;l=0;U:{V:{W:{X:{i=s&3;switch(i|0){case 0:break V;case 3:break X;default:break W}}a=a+b|0;d=0;if(a>>>0>=h>>>0){break Q}ra(t+(b<<2)|0,0,(s&252)+4|0);b=a;break U}while(1){if((f|0)==(r|0)&(e|0)==(p|0)){break R}h=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=h<<(l<<3|6)|a;l=l+1|0;if((i|0)!=(l|0)){continue}break}}H[t+(b<<2)>>2]=a}b=b+1|0;h=H[n+12>>2];if(b>>>0>>0){continue}break}a=n+16|0;r=H[n>>2];d=H[n+16>>2];b=H[n+20>>2]-d|0;Y:{if(b>>>0<=262143){ya(a,65536-(b>>>2|0)|0);break Y}if((b|0)==262144){break Y}H[n+20>>2]=d+262144}d=n+28|0;b=H[d>>2];f=H[n+32>>2]-b>>3;Z:{if(f>>>0>>0){ob(d,h-f|0);b=H[d>>2];break Z}if(f>>>0>h>>>0){H[n+32>>2]=(h<<3)+b}if(!h){break R}}i=H[a>>2];f=0;d=0;while(1){e=r+(f<<2)|0;l=H[e>>2];n=(f<<3)+b|0;a=d;H[n+4>>2]=a;H[n>>2]=l;e=H[e>>2];d=e+a|0;if(d>>>0>65536){break R}_:{if(a>>>0>=d>>>0){break _}l=0;n=e&7;if(n){while(1){H[i+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((n|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break _}while(1){e=i+(a<<2)|0;H[e>>2]=f;H[e+28>>2]=f;H[e+24>>2]=f;H[e+20>>2]=f;H[e+16>>2]=f;H[e+12>>2]=f;H[e+8>>2]=f;H[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((h|0)!=(f|0)){continue}break}k=(d|0)==65536}d=k}$:{if(!d|(H[g+20>>2]?0:m)){break $}d=0;i=ca-16|0;ca=i;aa:{ba:{if(J[c+38>>1]<=511){b=H[c+8>>2];a=H[c+12>>2];h=a;e=H[c+20>>2];k=H[c+16>>2];f=k+8|0;e=f>>>0<8?e+1|0:e;if(b>>>0>>0&(a|0)<=(e|0)|(a|0)<(e|0)){break aa}k=k+H[c>>2]|0;a=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);k=I[k+4|0]|I[k+5|0]<<8|(I[k+6|0]<<16|I[k+7|0]<<24);H[c+16>>2]=f;H[c+20>>2]=e;break ba}if(!gb(1,i+8|0,c)){break aa}f=H[c+16>>2];e=H[c+20>>2];b=H[c+8>>2];h=H[c+12>>2];a=H[i+8>>2];k=H[i+12>>2]}r=b-f|0;b=h-((b>>>0>>0)+e|0)|0;if((b|0)==(k|0)&a>>>0>r>>>0|b>>>0>>0){break aa}e=e+k|0;b=a+f|0;e=b>>>0>>0?e+1|0:e;H[c+16>>2]=b;H[c+20>>2]=e;if((a|0)<=0){break aa}b=H[c>>2]+f|0;H[g+48>>2]=b;c=a-1|0;f=c+b|0;e=I[f|0];ca:{if(e>>>0<=63){H[g+52>>2]=c;a=I[f|0]&63;break ca}da:{switch((e>>>6|0)-1|0){case 0:if(a>>>0<2){break aa}a=a-2|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8&16128|I[a|0];break ca;case 1:if(a>>>0<3){break aa}a=a-3|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8|I[a+2|0]<<16&4128768|I[a|0];break ca;default:break da}}a=a-4|0;H[g+52>>2]=a;a=a+b|0;a=(I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24))&1073741823}H[g+56>>2]=a+262144;d=a>>>0<66846720}ca=i+16|0;if(!d){break $}if(!m){o=1;break $}b=H[g+52>>2];a=H[g+56>>2];c=H[g+36>>2];d=H[g+48>>2];f=H[g+24>>2];while(1){ea:{if(a>>>0>262143){break ea}while(1){if((b|0)<=0){break ea}b=b-1|0;H[g+52>>2]=b;a=I[b+d|0]|a<<8;H[g+56>>2]=a;if(a>>>0<262144){continue}break}}e=a&65535;o=H[f+(e<<2)>>2];k=c+(o<<3)|0;a=(N(H[k>>2],a>>>16|0)+e|0)-H[k+4>>2]|0;H[g+56>>2]=a;H[j+(q<<2)>>2]=o;o=1;q=q+1|0;if((m|0)!=(q|0)){continue}break}}a=H[g+36>>2];if(a){H[g+40>>2]=a;oa(a)}a=H[g+24>>2];if(a){H[g+28>>2]=a;oa(a)}a=H[g+8>>2];if(a){H[g+12>>2]=a;oa(a)}ca=g- -64|0;b=o;break g;case 11:m=a;r=d;g=ca+-64|0;ca=g;H[g+56>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;j=g+8|0;a=J[c+38>>1];fa:{ga:{if(!a){break ga}ha:{if(a>>>0<=511){d=H[c+8>>2];b=H[c+12>>2];e=H[c+20>>2];a=H[c+16>>2];f=a+4|0;e=f>>>0<4?e+1|0:e;if(d>>>0>>0&(b|0)<=(e|0)|(b|0)<(e|0)){break ga}a=a+H[c>>2]|0;h=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);H[j+12>>2]=h;i=H[c+20>>2];f=H[c+16>>2]+4|0;i=f>>>0<4?i+1|0:i;H[c+16>>2]=f;e=i;H[c+20>>2]=e;break ha}if(!hb(1,j+12|0,c)){break ga}f=H[c+16>>2];e=H[c+20>>2];h=H[j+12>>2]}a=H[c+8>>2];d=a-f|0;a=H[c+12>>2]-((a>>>0>>0)+e|0)|0;if(d>>>0>>6>>>0&(a|0)<=0|(a|0)<0){break ga}b=H[j>>2];a=H[j+4>>2]-b>>2;ia:{if(a>>>0>>0){ya(j,h-a|0);h=H[j+12>>2];break ia}if(a>>>0<=h>>>0){break ia}H[j+4>>2]=b+(h<<2)}d=1;if(!h){break fa}f=H[c+16>>2];e=H[c+20>>2];s=H[j>>2];i=H[c+8>>2];n=H[c+12>>2];b=0;while(1){d=0;if((e|0)>=(n|0)&f>>>0>=i>>>0|(e|0)>(n|0)){break fa}d=H[c>>2];p=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=p>>>2|0;l=0;ja:{ka:{la:{ma:{t=p&3;switch(t|0){case 0:break ka;case 3:break ma;default:break la}}a=a+b|0;d=0;if(a>>>0>=h>>>0){break fa}ra(s+(b<<2)|0,0,(p&252)+4|0);b=a;break ja}while(1){if((f|0)==(i|0)&(e|0)==(n|0)){break ga}h=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=h<<(l<<3|6)|a;l=l+1|0;if((t|0)!=(l|0)){continue}break}}H[s+(b<<2)>>2]=a}b=b+1|0;h=H[j+12>>2];if(b>>>0>>0){continue}break}a=j+16|0;n=H[j>>2];d=H[j+16>>2];b=H[j+20>>2]-d|0;na:{if(b>>>0<=1048575){ya(a,262144-(b>>>2|0)|0);break na}if((b|0)==1048576){break na}H[j+20>>2]=d- -1048576}d=j+28|0;b=H[d>>2];f=H[j+32>>2]-b>>3;oa:{if(f>>>0>>0){ob(d,h-f|0);b=H[d>>2];break oa}if(f>>>0>h>>>0){H[j+32>>2]=(h<<3)+b}if(!h){break ga}}i=H[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;j=H[e>>2];l=(f<<3)+b|0;a=d;H[l+4>>2]=a;H[l>>2]=j;e=H[e>>2];d=e+a|0;if(d>>>0>262144){break ga}pa:{if(a>>>0>=d>>>0){break pa}l=0;j=e&7;if(j){while(1){H[i+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((j|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break pa}while(1){e=i+(a<<2)|0;H[e>>2]=f;H[e+28>>2]=f;H[e+24>>2]=f;H[e+20>>2]=f;H[e+16>>2]=f;H[e+12>>2]=f;H[e+8>>2]=f;H[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((h|0)!=(f|0)){continue}break}k=(d|0)==262144}d=k}qa:{if(!d|(H[g+20>>2]?0:m)){break qa}d=0;j=ca-16|0;ca=j;ra:{sa:{if(J[c+38>>1]<=511){b=H[c+8>>2];a=H[c+12>>2];h=a;i=H[c+20>>2];k=H[c+16>>2];f=k+8|0;i=f>>>0<8?i+1|0:i;e=i;if(b>>>0>>0&(e|0)>=(a|0)|(a|0)<(e|0)){break ra}k=k+H[c>>2]|0;a=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);k=I[k+4|0]|I[k+5|0]<<8|(I[k+6|0]<<16|I[k+7|0]<<24);H[c+16>>2]=f;H[c+20>>2]=e;break sa}if(!gb(1,j+8|0,c)){break ra}f=H[c+16>>2];e=H[c+20>>2];b=H[c+8>>2];h=H[c+12>>2];a=H[j+8>>2];k=H[j+12>>2]}i=b-f|0;b=h-((b>>>0>>0)+e|0)|0;if((b|0)==(k|0)&a>>>0>i>>>0|b>>>0>>0){break ra}e=e+k|0;b=a+f|0;e=b>>>0>>0?e+1|0:e;H[c+16>>2]=b;H[c+20>>2]=e;if((a|0)<=0){break ra}b=H[c>>2]+f|0;H[g+48>>2]=b;c=a-1|0;f=c+b|0;e=I[f|0];ta:{if(e>>>0<=63){H[g+52>>2]=c;a=I[f|0]&63;break ta}ua:{switch((e>>>6|0)-1|0){case 0:if(a>>>0<2){break ra}a=a-2|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8&16128|I[a|0];break ta;case 1:if(a>>>0<3){break ra}a=a-3|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8|I[a+2|0]<<16&4128768|I[a|0];break ta;default:break ua}}a=a-4|0;H[g+52>>2]=a;a=a+b|0;a=(I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24))&1073741823}H[g+56>>2]=a- -1048576;d=a>>>0<267386880}ca=j+16|0;if(!d){break qa}if(!m){o=1;break qa}b=H[g+52>>2];a=H[g+56>>2];c=H[g+36>>2];d=H[g+48>>2];f=H[g+24>>2];while(1){va:{if(a>>>0>1048575){break va}while(1){if((b|0)<=0){break va}b=b-1|0;H[g+52>>2]=b;a=I[b+d|0]|a<<8;H[g+56>>2]=a;if(a>>>0<1048576){continue}break}}e=a&262143;o=H[f+(e<<2)>>2];k=c+(o<<3)|0;a=(N(H[k>>2],a>>>18|0)+e|0)-H[k+4>>2]|0;H[g+56>>2]=a;H[r+(q<<2)>>2]=o;o=1;q=q+1|0;if((m|0)!=(q|0)){continue}break}}a=H[g+36>>2];if(a){H[g+40>>2]=a;oa(a)}a=H[g+24>>2];if(a){H[g+28>>2]=a;oa(a)}a=H[g+8>>2];if(a){H[g+12>>2]=a;oa(a)}ca=g- -64|0;b=o;break g;case 12:m=a;r=d;g=ca+-64|0;ca=g;H[g+56>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;j=g+8|0;a=J[c+38>>1];wa:{xa:{if(!a){break xa}ya:{if(a>>>0<=511){d=H[c+8>>2];b=H[c+12>>2];i=H[c+20>>2];a=H[c+16>>2];f=a+4|0;i=f>>>0<4?i+1|0:i;if(d>>>0>>0&(b|0)<=(i|0)|(b|0)<(i|0)){break xa}a=a+H[c>>2]|0;h=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);H[j+12>>2]=h;e=H[c+20>>2];f=H[c+16>>2]+4|0;e=f>>>0<4?e+1|0:e;H[c+16>>2]=f;H[c+20>>2]=e;break ya}if(!hb(1,j+12|0,c)){break xa}f=H[c+16>>2];e=H[c+20>>2];h=H[j+12>>2]}a=H[c+8>>2];d=a-f|0;a=H[c+12>>2]-((a>>>0>>0)+e|0)|0;if(d>>>0>>6>>>0&(a|0)<=0|(a|0)<0){break xa}b=H[j>>2];a=H[j+4>>2]-b>>2;za:{if(a>>>0>>0){ya(j,h-a|0);h=H[j+12>>2];break za}if(a>>>0<=h>>>0){break za}H[j+4>>2]=b+(h<<2)}d=1;if(!h){break wa}f=H[c+16>>2];e=H[c+20>>2];s=H[j>>2];i=H[c+8>>2];n=H[c+12>>2];b=0;while(1){d=0;if((e|0)>=(n|0)&f>>>0>=i>>>0|(e|0)>(n|0)){break wa}d=H[c>>2];p=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=p>>>2|0;l=0;Aa:{Ba:{Ca:{Da:{t=p&3;switch(t|0){case 0:break Ba;case 3:break Da;default:break Ca}}a=a+b|0;d=0;if(a>>>0>=h>>>0){break wa}ra(s+(b<<2)|0,0,(p&252)+4|0);b=a;break Aa}while(1){if((f|0)==(i|0)&(e|0)==(n|0)){break xa}h=I[d+f|0];f=f+1|0;e=f?e:e+1|0;H[c+16>>2]=f;H[c+20>>2]=e;a=h<<(l<<3|6)|a;l=l+1|0;if((t|0)!=(l|0)){continue}break}}H[s+(b<<2)>>2]=a}b=b+1|0;h=H[j+12>>2];if(b>>>0>>0){continue}break}a=j+16|0;n=H[j>>2];d=H[j+16>>2];b=H[j+20>>2]-d|0;Ea:{if(b>>>0<=2097151){ya(a,524288-(b>>>2|0)|0);break Ea}if((b|0)==2097152){break Ea}H[j+20>>2]=d+2097152}d=j+28|0;b=H[d>>2];f=H[j+32>>2]-b>>3;Fa:{if(f>>>0>>0){ob(d,h-f|0);b=H[d>>2];break Fa}if(f>>>0>h>>>0){H[j+32>>2]=(h<<3)+b}if(!h){break xa}}i=H[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;j=H[e>>2];l=(f<<3)+b|0;a=d;H[l+4>>2]=a;H[l>>2]=j;e=H[e>>2];d=e+a|0;if(d>>>0>524288){break xa}Ga:{if(a>>>0>=d>>>0){break Ga}l=0;j=e&7;if(j){while(1){H[i+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((j|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break Ga}while(1){e=i+(a<<2)|0;H[e>>2]=f;H[e+28>>2]=f;H[e+24>>2]=f;H[e+20>>2]=f;H[e+16>>2]=f;H[e+12>>2]=f;H[e+8>>2]=f;H[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((h|0)!=(f|0)){continue}break}k=(d|0)==524288}d=k}Ha:{if(!d|(H[g+20>>2]?0:m)){break Ha}d=0;i=ca-16|0;ca=i;Ia:{Ja:{if(J[c+38>>1]<=511){b=H[c+8>>2];a=H[c+12>>2];h=a;e=H[c+20>>2];k=H[c+16>>2];f=k+8|0;e=f>>>0<8?e+1|0:e;if(b>>>0>>0&(a|0)<=(e|0)|(a|0)<(e|0)){break Ia}k=k+H[c>>2]|0;a=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);k=I[k+4|0]|I[k+5|0]<<8|(I[k+6|0]<<16|I[k+7|0]<<24);H[c+16>>2]=f;H[c+20>>2]=e;break Ja}if(!gb(1,i+8|0,c)){break Ia}f=H[c+16>>2];e=H[c+20>>2];b=H[c+8>>2];h=H[c+12>>2];a=H[i+8>>2];k=H[i+12>>2]}j=b-f|0;b=h-((b>>>0>>0)+e|0)|0;if((b|0)==(k|0)&a>>>0>j>>>0|b>>>0>>0){break Ia}e=e+k|0;b=a+f|0;e=b>>>0>>0?e+1|0:e;H[c+16>>2]=b;H[c+20>>2]=e;if((a|0)<=0){break Ia}b=H[c>>2]+f|0;H[g+48>>2]=b;c=a-1|0;f=c+b|0;e=I[f|0];Ka:{if(e>>>0<=63){H[g+52>>2]=c;a=I[f|0]&63;break Ka}La:{switch((e>>>6|0)-1|0){case 0:if(a>>>0<2){break Ia}a=a-2|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8&16128|I[a|0];break Ka;case 1:if(a>>>0<3){break Ia}a=a-3|0;H[g+52>>2]=a;a=a+b|0;a=I[a+1|0]<<8|I[a+2|0]<<16&4128768|I[a|0];break Ka;default:break La}}a=a-4|0;H[g+52>>2]=a;a=a+b|0;a=(I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24))&1073741823}H[g+56>>2]=a+2097152;d=a>>>0<534773760}ca=i+16|0;if(!d){break Ha}if(!m){o=1;break Ha}b=H[g+52>>2];a=H[g+56>>2];c=H[g+36>>2];d=H[g+48>>2];f=H[g+24>>2];while(1){Ma:{if(a>>>0>2097151){break Ma}while(1){if((b|0)<=0){break Ma}b=b-1|0;H[g+52>>2]=b;a=I[b+d|0]|a<<8;H[g+56>>2]=a;if(a>>>0<2097152){continue}break}}e=a&524287;o=H[f+(e<<2)>>2];k=c+(o<<3)|0;a=(N(H[k>>2],a>>>19|0)+e|0)-H[k+4>>2]|0;H[g+56>>2]=a;H[r+(q<<2)>>2]=o;o=1;q=q+1|0;if((m|0)!=(q|0)){continue}break}}a=H[g+36>>2];if(a){H[g+40>>2]=a;oa(a)}a=H[g+24>>2];if(a){H[g+28>>2]=a;oa(a)}a=H[g+8>>2];if(a){H[g+12>>2]=a;oa(a)}ca=g- -64|0;b=o;break g;case 17:b=Le(a,c,d);break g;case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:b=ca+-64|0;ca=b;H[b+56>>2]=0;H[b+48>>2]=0;H[b+52>>2]=0;H[b+40>>2]=0;H[b+44>>2]=0;H[b+32>>2]=0;H[b+36>>2]=0;H[b+24>>2]=0;H[b+28>>2]=0;H[b+16>>2]=0;H[b+20>>2]=0;H[b+8>>2]=0;H[b+12>>2]=0;Na:{if(!Ne(b+8|0,c)|(H[b+20>>2]?0:a)){break Na}if(!Me(b+8|0,c)){break Na}if(!a){f=1;break Na}e=H[b+52>>2];c=H[b+56>>2];k=H[b+36>>2];i=H[b+48>>2];g=H[b+24>>2];while(1){Oa:{if(c>>>0>16383){break Oa}while(1){if((e|0)<=0){break Oa}e=e-1|0;H[b+52>>2]=e;c=I[e+i|0]|c<<8;H[b+56>>2]=c;if(c>>>0<16384){continue}break}}f=c&4095;m=H[g+(f<<2)>>2];r=k+(m<<3)|0;c=(N(H[r>>2],c>>>12|0)+f|0)-H[r+4>>2]|0;H[b+56>>2]=c;H[(o<<2)+d>>2]=m;f=1;o=o+1|0;if((o|0)!=(a|0)){continue}break}}a=H[b+36>>2];if(a){H[b+40>>2]=a;oa(a)}a=H[b+24>>2];if(a){H[b+28>>2]=a;oa(a)}a=H[b+8>>2];if(a){H[b+12>>2]=a;oa(a)}ca=b- -64|0;b=f;break g;case 13:case 14:case 15:case 16:break h;default:break g}}b=Le(a,c,d)}f=b}return f}function gi(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,L=0,M=0,O=0,P=0,Q=0,R=0;s=ca+-64|0;ca=s;H[a+132>>2]=0;if(H[a+148>>2]){c=H[a+144>>2];if(c){while(1){d=H[c>>2];oa(c);c=d;if(c){continue}break}}c=0;H[a+144>>2]=0;d=H[a+140>>2];a:{if(!d){break a}if(d>>>0>=4){g=d&-4;while(1){e=c<<2;H[e+H[a+136>>2]>>2]=0;H[H[a+136>>2]+(e|4)>>2]=0;H[H[a+136>>2]+(e|8)>>2]=0;H[H[a+136>>2]+(e|12)>>2]=0;c=c+4|0;b=b+4|0;if((g|0)!=(b|0)){continue}break}}b=d&3;if(!b){break a}while(1){H[H[a+136>>2]+(c<<2)>>2]=0;c=c+1|0;u=u+1|0;if((b|0)!=(u|0)){continue}break}}H[a+148>>2]=0}b:{c:{d:{c=H[a+4>>2];u=I[c+36|0];b=u<<8|I[c+37|0];if(b>>>0<=513){i=H[c+32>>2];e:{if(b>>>0<=511){b=H[i+20>>2];e=H[i+16>>2];d=e+4|0;b=d>>>0<4?b+1|0:b;g=b;h=H[i+12>>2];if(K[i+8>>2]>>0&(b|0)>=(h|0)|(b|0)>(h|0)){break d}b=e+H[i>>2]|0;b=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[i+16>>2]=d;H[i+20>>2]=g;break e}if(!Ea(1,s,i)){break d}c=H[a+4>>2];u=I[c+36|0];b=H[s>>2]}H[a+132>>2]=b}g=H[c+32>>2];f:{g:{h:{if((u&255)>>>0<=1){u=0;d=H[g+20>>2];e=H[g+16>>2];b=e+4|0;d=b>>>0<4?d+1|0:d;i=H[g+12>>2];if(K[g+8>>2]>>0&(i|0)<=(d|0)|(d|0)>(i|0)){break c}e=e+H[g>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[s+60>>2]=e;H[g+16>>2]=b;H[g+20>>2]=d;H[a+156>>2]=e;n=a+156|0;break h}u=0;if(!Ea(1,s+60|0,g)){break c}c=H[a+4>>2];b=I[c+36|0];H[a+156>>2]=H[s+60>>2];n=a+156|0;if(b>>>0>1){break g}}g=H[c+32>>2];h=H[g+8>>2];i=H[g+12>>2];c=H[g+20>>2];d=H[g+16>>2];b=d+4|0;c=b>>>0<4?c+1|0:c;e=b;if(b>>>0>h>>>0&(c|0)>=(i|0)|(c|0)>(i|0)){break c}b=d+H[g>>2]|0;b=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[s+56>>2]=b;H[g+16>>2]=e;H[g+20>>2]=c;break f}if(!Ea(1,s+56|0,H[c+32>>2])){break c}b=H[s+56>>2]}if(b>>>0>1431655765|K[n>>2]>N(b,3)>>>0){break c}f=H[a+4>>2];g=H[f+32>>2];c=g;e=H[c+8>>2];i=H[c+16>>2];j=H[c+12>>2];d=H[c+20>>2];c=d;if((j|0)<=(c|0)&e>>>0<=i>>>0|(c|0)>(j|0)){break c}n=H[g>>2];o=I[n+i|0];h=i+1|0;c=h?c:c+1|0;H[g+16>>2]=h;H[g+20>>2]=c;i:{if(I[f+36|0]<=1){f=e;c=j;e=i+5|0;d=e>>>0<5?d+1|0:d;if((c|0)<=(d|0)&e>>>0>f>>>0|(c|0)<(d|0)){break c}c=h+n|0;n=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[s+52>>2]=n;H[g+16>>2]=e;H[g+20>>2]=d;break i}if(!Ea(1,s+52|0,g)){break c}n=H[s+52>>2]}if(b>>>0>>0|((n>>>0)/3|0)+n>>>0>>0){break c}c=H[a+4>>2];i=H[c+32>>2];j:{if(I[c+36|0]<=1){c=H[i+20>>2];e=H[i+16>>2];d=e+4|0;c=d>>>0<4?c+1|0:c;g=d;f=K[i+8>>2]>>0;d=H[i+12>>2];if(f&(d|0)<=(c|0)|(c|0)>(d|0)){break c}d=e+H[i>>2]|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[s+48>>2]=d;H[i+16>>2]=g;H[i+20>>2]=c;break j}if(!Ea(1,s+48|0,i)){break c}d=H[s+48>>2]}if(d>>>0>n>>>0){break c}H[a+28>>2]=H[a+24>>2];e=$b(pa(88));c=H[a+8>>2];H[a+8>>2]=e;if(c){cb(c);if(!H[a+8>>2]){break c}}H[a+164>>2]=H[a+160>>2];Jb(a+160|0,b);H[a+176>>2]=H[a+172>>2];Jb(a+172|0,b);H[a- -64>>2]=0;H[a+92>>2]=-1;H[a+84>>2]=-1;H[a+88>>2]=-1;H[a+40>>2]=H[a+36>>2];H[a+52>>2]=H[a+48>>2];H[a+76>>2]=H[a+72>>2];B=a+216|0;ed(B);dd(B,o);if(!Lc(H[a+8>>2],b,H[a+156>>2]+d|0)){break c}c=H[a+156>>2];F[s|0]=1;Oa(a+120|0,c+d|0,s);c=H[a+4>>2];b=J[c+36>>1];b=(b<<8|b>>>8)&65535;k:{if(b>>>0<=513){i=H[c+32>>2];l:{if(b>>>0<=511){b=H[i+20>>2];e=H[i+16>>2];c=e+4|0;b=c>>>0<4?b+1|0:b;g=b;h=H[i+12>>2];if(K[i+8>>2]>>0&(b|0)>=(h|0)|(b|0)>(h|0)){break c}b=e+H[i>>2]|0;b=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[i+16>>2]=c;H[i+20>>2]=g;break l}if(!Ea(1,s+44|0,i)){break c}b=H[s+44>>2]}if(!b){break c}c=H[H[a+4>>2]+32>>2];e=H[c+8>>2];g=H[c+16>>2];i=e-g|0;c=H[c+12>>2]-(H[c+20>>2]+(e>>>0>>0)|0)|0;if((c|0)<=0&b>>>0>i>>>0|(c|0)<0){break c}c=Ha(s);e=H[H[a+4>>2]+32>>2];g=H[e+16>>2];i=(g+H[e>>2]|0)+b|0;g=H[e+8>>2]-g|0;G[c+38>>1]=J[e+38>>1];H[c>>2]=i;H[c+16>>2]=0;H[c+20>>2]=0;H[c+8>>2]=g-b;H[c+12>>2]=0;C=Ib(a,c);if((C|0)==-1){break c}M=C>>31;break k}C=-1;M=-1;if((Ib(a,H[c+32>>2])|0)==-1){break c}}e=a+232|0;Ee(e,a);H[a+372>>2]=o;H[a+384>>2]=H[a+156>>2]+d;O=Ha(s);g=O;b=0;j=ca-16|0;ca=j;m:{n:{c=H[e+144>>2];c=J[(ea[H[H[c>>2]+32>>2]](c)|0)+36>>1];if(((c<<8|c>>>8)&65535)>>>0<=513){c=H[e+4>>2];H[e+40>>2]=H[e>>2];H[e+44>>2]=c;c=H[e+36>>2];H[e+72>>2]=H[e+32>>2];H[e+76>>2]=c;d=H[e+28>>2];c=e- -64|0;H[c>>2]=H[e+24>>2];H[c+4>>2]=d;c=H[e+20>>2];H[e+56>>2]=H[e+16>>2];H[e+60>>2]=c;c=H[e+12>>2];H[e+48>>2]=H[e+8>>2];H[e+52>>2]=c;if(!Db(e+40|0,1,j+8|0)){break n}c=H[e+44>>2];H[e>>2]=H[e+40>>2];H[e+4>>2]=c;c=H[e+76>>2];H[e+32>>2]=H[e+72>>2];H[e+36>>2]=c;c=H[e+68>>2];H[e+24>>2]=H[e+64>>2];H[e+28>>2]=c;c=H[e+60>>2];h=c;d=H[e+56>>2];H[e+16>>2]=d;H[e+20>>2]=c;i=H[e+52>>2];f=i;c=H[e+48>>2];H[e+8>>2]=c;H[e+12>>2]=f;o=c-d|0;k=H[j+12>>2];c=f-((c>>>0>>0)+h|0)|0;i=H[j+8>>2];if((k|0)==(c|0)&o>>>0>>0|c>>>0>>0){break n}c=h+k|0;f=d;d=d+i|0;c=f>>>0>d>>>0?c+1|0:c;H[e+16>>2]=d;H[e+20>>2]=c}o:{if(J[e+38>>1]<=513){c=H[e+4>>2];H[e+96>>2]=H[e>>2];H[e+100>>2]=c;c=H[e+36>>2];H[e+128>>2]=H[e+32>>2];H[e+132>>2]=c;c=H[e+28>>2];H[e+120>>2]=H[e+24>>2];H[e+124>>2]=c;c=H[e+20>>2];H[e+112>>2]=H[e+16>>2];H[e+116>>2]=c;c=H[e+12>>2];H[e+104>>2]=H[e+8>>2];H[e+108>>2]=c;if(!Db(e+96|0,1,j+8|0)){break n}c=H[e+100>>2];H[e>>2]=H[e+96>>2];H[e+4>>2]=c;c=H[e+132>>2];H[e+32>>2]=H[e+128>>2];H[e+36>>2]=c;c=H[e+124>>2];H[e+24>>2]=H[e+120>>2];H[e+28>>2]=c;d=H[e+116>>2];h=d;c=H[e+112>>2];H[e+16>>2]=c;H[e+20>>2]=d;i=H[e+108>>2];f=i;d=H[e+104>>2];H[e+8>>2]=d;H[e+12>>2]=f;o=d-c|0;k=H[j+12>>2];d=f-((c>>>0>d>>>0)+h|0)|0;i=H[j+8>>2];if((k|0)==(d|0)&o>>>0>>0|d>>>0>>0){break n}d=h+k|0;f=c;c=c+i|0;d=f>>>0>c>>>0?d+1|0:d;H[e+16>>2]=c;H[e+20>>2]=d;break o}if(!ta(e+80|0,e)){break m}}if(!Fe(e)){break m}c=H[e+4>>2];H[g>>2]=H[e>>2];H[g+4>>2]=c;c=H[e+36>>2];H[g+32>>2]=H[e+32>>2];H[g+36>>2]=c;c=H[e+28>>2];H[g+24>>2]=H[e+24>>2];H[g+28>>2]=c;c=H[e+20>>2];H[g+16>>2]=H[e+16>>2];H[g+20>>2]=c;c=H[e+12>>2];H[g+8>>2]=H[e+8>>2];H[g+12>>2]=c;c=H[e+144>>2];c=J[(ea[H[H[c>>2]+32>>2]](c)|0)+36>>1];p:{if(((c<<8|c>>>8)&65535)>>>0<=513){c=H[e+144>>2];q:{if(I[(ea[H[H[c>>2]+32>>2]](c)|0)+36|0]<=1){c=H[g+20>>2];i=H[g+16>>2];d=i+4|0;c=d>>>0<4?c+1|0:c;h=d;f=K[g+8>>2]>>0;d=H[g+12>>2];if(f&(d|0)<=(c|0)|(c|0)>(d|0)){break m}d=i+H[g>>2]|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[g+16>>2]=h;H[g+20>>2]=c;break q}if(!Ea(1,j+8|0,g)){break m}d=H[j+8>>2]}c=H[e+152>>2];if(d>>>0>=c>>>0){break m}d=H[g+20>>2];h=H[g+12>>2];i=H[g+16>>2];if((d|0)>=(h|0)&i>>>0>=K[g+8>>2]|(d|0)>(h|0)){break m}h=I[i+H[g>>2]|0];i=i+1|0;d=i?d:d+1|0;H[g+16>>2]=i;H[g+20>>2]=d;if(h){break m}H[e+176>>2]=2;H[e+180>>2]=7;break p}H[e+176>>2]=2;H[e+180>>2]=7;c=H[e+152>>2]}if((c|0)<0){break m}H[j+8>>2]=0;b=2;h=H[e+156>>2];i=H[e+160>>2]-h>>2;r:{if(i>>>0>>0){Pa(e+156|0,c-i|0,j+8|0);b=H[e+176>>2];d=H[e+180>>2];break r}d=7;if(c>>>0>=i>>>0){break r}H[e+160>>2]=h+(c<<2)}i=e+184|0;b=(d-b|0)+1|0;c=H[e+188>>2];h=H[e+184>>2];d=(c-h|0)/12|0;s:{if(b>>>0>d>>>0){o=0;d=b-d|0;f=H[i+8>>2];c=H[i+4>>2];t:{if(d>>>0<=(f-c|0)/12>>>0){if(d){b=c;c=N(d,12)-12|0;c=(c-((c>>>0)%12|0)|0)+12|0;c=ra(b,0,c)+c|0}H[i+4>>2]=c;break t}u:{v:{w:{h=H[i>>2];k=(c-h|0)/12|0;b=k+d|0;if(b>>>0<357913942){f=(f-h|0)/12|0;l=f<<1;f=f>>>0>=178956970?357913941:b>>>0>>0?l:b;if(f){if(f>>>0>=357913942){break w}o=pa(N(f,12))}b=N(k,12)+o|0;d=N(d,12)-12|0;k=(d-((d>>>0)%12|0)|0)+12|0;d=ra(b,0,k);k=d+k|0;f=N(f,12)+o|0;if((c|0)==(h|0)){break v}while(1){b=b-12|0;c=c-12|0;H[b>>2]=H[c>>2];H[b+4>>2]=H[c+4>>2];H[b+8>>2]=H[c+8>>2];H[c+8>>2]=0;H[c>>2]=0;H[c+4>>2]=0;if((c|0)!=(h|0)){continue}break}H[i+8>>2]=f;d=H[i+4>>2];H[i+4>>2]=k;c=H[i>>2];H[i>>2]=b;if((c|0)==(d|0)){break u}while(1){b=d-12|0;h=H[b>>2];if(h){H[d-8>>2]=h;oa(h)}d=b;if((b|0)!=(c|0)){continue}break}break u}break b}wa();v()}H[i+8>>2]=f;H[i+4>>2]=k;H[i>>2]=d}if(c){oa(c)}}d=H[e+188>>2];break s}if(b>>>0>=d>>>0){d=c;break s}d=h+N(b,12)|0;if((d|0)!=(c|0)){while(1){b=c-12|0;h=H[b>>2];if(h){H[c-8>>2]=h;oa(h)}c=b;if((d|0)!=(b|0)){continue}break}}H[e+188>>2]=d}f=e+196|0;b=H[e+184>>2];c=(d-b|0)/12|0;o=H[e+196>>2];h=H[e+200>>2]-o>>2;x:{if(c>>>0>h>>>0){ya(f,c-h|0);b=H[e+184>>2];d=H[e+188>>2];break x}if(c>>>0>=h>>>0){break x}H[e+200>>2]=o+(c<<2)}if((b|0)==(d|0)){b=1;break m}c=0;while(1){if(!Ea(1,j+8|0,g)){break n}b=H[e+148>>2];d=(H[b+4>>2]-H[b>>2]>>2>>>0)/3|0;b=H[j+8>>2];if(d>>>0>>0){break n}if(b){k=N(c,12);h=k+H[i>>2]|0;d=H[h>>2];o=H[h+4>>2]-d>>2;y:{if(o>>>0>>0){ya(h,b-o|0);d=H[k+H[i>>2]>>2];break y}if(b>>>0>=o>>>0){break y}H[h+4>>2]=(b<<2)+d}kd(b,1,g,d);H[H[f>>2]+(c<<2)>>2]=b}b=1;c=c+1|0;if(c>>>0<(H[e+188>>2]-H[e+184>>2]|0)/12>>>0){continue}break}break m}b=0}ca=j+16|0;z:{if(!b){break z}d=0;c=0;g=0;i=0;o=0;l=ca-96|0;ca=l;H[l+72>>2]=0;H[l+64>>2]=0;H[l+68>>2]=0;H[l+48>>2]=0;H[l+52>>2]=0;H[l+40>>2]=0;H[l+44>>2]=0;H[l+56>>2]=1065353216;H[l+32>>2]=0;H[l+24>>2]=0;H[l+28>>2]=0;j=a;L=H[a+124>>2];A:{B:{C:{D:{E:{if((n|0)<=0){break E}r=j+232|0;P=H[j+216>>2]!=H[j+220>>2];D=1;while(1){h=i;i=h+1|0;a=H[r+172>>2];F:{G:{if((a|0)!=-1){b=H[r+196>>2]+(a<<2)|0;f=H[b>>2];a=f-1|0;H[b>>2]=a;b=9;if((f|0)<=0){break F}a=H[H[H[r+184>>2]+N(H[r+172>>2],12)>>2]+(a<<2)>>2];if(a>>>0>4){break F}b=H[(a<<2)+12144>>2];break G}b=7;a=H[r+144>>2];a=J[(ea[H[H[a>>2]+32>>2]](a)|0)+36>>1];if(((a<<8|a>>>8)&65535)>>>0>513|!I[r+76|0]){break G}b=0;m=H[r- -64>>2];k=H[r+72>>2];a=m+(k>>>3|0)|0;p=H[r+68>>2];if(a>>>0>=p>>>0){break G}f=I[a|0];a=k+1|0;H[r+72>>2]=a;f=f>>>(k&7)&1;if(!f){break G}q=a>>>3|0;b=m+q|0;H:{if(b>>>0>=p>>>0){b=a;a=0;break H}t=I[b|0];b=k+2|0;H[r+72>>2]=b;q=b>>>3|0;a=t>>>(a&7)&1}k=m+q|0;if(k>>>0

>>0){k=I[k|0];H[r+72>>2]=b+1;b=k>>>(b&7)<<1&2}else{b=0}b=(a|b)<<1|f}H[r+168>>2]=b}a=b;I:{J:{if(!a){if((c|0)==(g|0)){b=-1;break D}d=-1;m=H[j+8>>2];t=H[m+24>>2];D=c-4|0;f=H[D>>2];a=-1;K:{if((f|0)==-1){break K}k=f+1|0;k=(k>>>0)%3|0?k:f-2|0;a=-1;if((k|0)==-1){break K}a=H[H[m>>2]+(k<<2)>>2]}b=H[t+(a<<2)>>2];if((b|0)!=-1){d=b+1|0;d=(d>>>0)%3|0?d:b-2|0}if((d|0)==(f|0)){b=-1;break D}if((f|0)!=-1){b=-1;if(H[H[m+12>>2]+(f<<2)>>2]!=-1){break D}}k=H[m+12>>2];if((d|0)!=-1){b=-1;if(H[k+(d<<2)>>2]!=-1){break D}}p=N(h,3);b=p+1|0;H[k+(f<<2)>>2]=b;w=b<<2;H[w+k>>2]=f;q=p+2|0;H[k+(d<<2)>>2]=q;y=q<<2;H[y+k>>2]=d;k=-1;h=-1;L:{if((f|0)==-1){break L}M:{if((f>>>0)%3|0){b=f-1|0;break M}b=f+2|0;h=-1;if((b|0)==-1){break L}}h=H[H[m>>2]+(b<<2)>>2]}N:{if((d|0)==-1){break N}b=d+1|0;b=(b>>>0)%3|0?b:d-2|0;if((b|0)==-1){break N}k=H[H[m>>2]+(b<<2)>>2]}b=-1;if((a|0)==(h|0)|(a|0)==(k|0)){break D}b=H[m>>2];H[b+(p<<2)>>2]=a;H[b+w>>2]=k;H[b+y>>2]=h;if((h|0)!=-1){H[t+(h<<2)>>2]=q}b=H[j+120>>2]+(a>>>3&536870908)|0;d=H[b>>2];Q=b,R=Vj(a)&d,H[Q>>2]=R;H[D>>2]=p;k=H[c-4>>2];break J}b=-1;O:{P:{Q:{R:{S:{T:{U:{V:{W:{switch(a-1|0){case 2:case 4:if((c|0)==(g|0)){break D}t=c-4|0;d=H[t>>2];f=H[j+8>>2];m=H[f+12>>2];if((d|0)!=-1&H[m+(d<<2)>>2]!=-1){break D}k=N(h,3);p=(a|0)==5;q=k+(p?2:1)|0;w=q<<2;H[w+m>>2]=d;H[m+(d<<2)>>2]=q;Ka(f+24|0,11424);a=H[j+8>>2];m=H[a+24>>2];if(H[a+28>>2]-m>>2>(L|0)){break D}a=H[a>>2];y=a+w|0;b=H[f+28>>2];f=H[f+24>>2];w=(b-f>>2)-1|0;H[y>>2]=w;if((b|0)!=(f|0)){H[m+(w<<2)>>2]=q}b=p?k:k+2|0;q=a+(k+p<<2)|0;X:{if((d|0)==-1){H[a+(b<<2)>>2]=-1;b=-1;break X}Y:{Z:{_:{if((d>>>0)%3|0){f=d-1|0;break _}f=d+2|0;if((f|0)==-1){break Z}}f=H[a+(f<<2)>>2];H[a+(b<<2)>>2]=f;if((f|0)==-1){break Y}H[m+(f<<2)>>2]=b;break Y}H[a+(b<<2)>>2]=-1}f=d+1|0;d=(f>>>0)%3|0?f:d-2|0;b=-1;if((d|0)==-1){break X}b=H[a+(d<<2)>>2]}H[q>>2]=b;H[t>>2]=k;break V;case 0:if((c|0)==(d|0)){break D}a=c-4|0;m=H[a>>2];H[l+68>>2]=a;p=H[l+44>>2];$:{if(!p){c=a;break $}f=H[l+40>>2];q=Uj(p)>>>0>1;b=h&p+2147483647;aa:{if(!q){break aa}b=h;if(b>>>0

>>0){break aa}b=(h>>>0)%(p>>>0)|0}k=b;b=H[f+(k<<2)>>2];if(!b){c=a;break $}b=H[b>>2];if(!b){c=a;break $}ba:{if(!q){f=p-1|0;while(1){p=H[b+4>>2];ca:{if((p|0)!=(h|0)){if((k|0)==(f&p)){break ca}c=a;break $}if((h|0)==H[b+8>>2]){break ba}}b=H[b>>2];if(b){continue}break}c=a;break $}while(1){f=H[b+4>>2];da:{if((f|0)!=(h|0)){if(f>>>0>=p>>>0){f=(f>>>0)%(p>>>0)|0}if((f|0)==(k|0)){break da}c=a;break $}if((h|0)==H[b+8>>2]){break ba}}b=H[b>>2];if(b){continue}break}c=a;break $}if((a|0)!=(x|0)){H[a>>2]=H[b+12>>2];H[l+68>>2]=c;break $}a=x-d|0;g=a>>2;c=g+1|0;if(c>>>0>=1073741824){break b}f=a>>>1|0;f=a>>>0>=2147483644?1073741823:c>>>0>>0?f:c;if(f){if(f>>>0>=1073741824){break B}a=pa(f<<2)}else{a=0}g=a+(g<<2)|0;H[g>>2]=H[b+12>>2];c=g+4|0;if((d|0)!=(x|0)){while(1){g=g-4|0;x=x-4|0;H[g>>2]=H[x>>2];if((d|0)!=(x|0)){continue}break}}x=a+(f<<2)|0;H[l+72>>2]=x;H[l+68>>2]=c;H[l+64>>2]=g;if(d){oa(d)}}if((c|0)==(g|0)){break P}w=c-4|0;a=H[w>>2];if((a|0)==(m|0)){break P}b=(a|0)==-1;p=H[j+8>>2];if(!b&H[H[p+12>>2]+(a<<2)>>2]!=-1){break P}q=H[p+12>>2];if((m|0)!=-1&H[q+(m<<2)>>2]!=-1){break P}k=N(h,3);t=k+2|0;H[q+(a<<2)>>2]=t;h=t<<2;H[h+q>>2]=a;d=k+1|0;H[q+(m<<2)>>2]=d;y=d<<2;H[y+q>>2]=m;if(b){break T}if((a>>>0)%3|0){f=a-1|0;break S}f=a+2|0;if((f|0)!=-1){break S}d=H[p>>2];f=-1;break R;case 6:break W;default:break D}}k=H[j+8>>2];Ka(k+24|0,11424);f=H[j+8>>2];a=N(h,3);m=H[k+28>>2];p=H[k+24>>2];q=m-p|0;k=q>>2;t=k-1|0;H[H[f>>2]+(a<<2)>>2]=t;Ka(f+24|0,11424);w=a+1|0;H[H[f>>2]+(w<<2)>>2]=(H[f+28>>2]-H[f+24>>2]>>2)-1;f=H[j+8>>2];Ka(f+24|0,11424);y=a+2|0;H[H[f>>2]+(y<<2)>>2]=(H[f+28>>2]-H[f+24>>2]>>2)-1;E=H[j+8>>2];f=H[E+24>>2];if(H[E+28>>2]-f>>2>(L|0)){break D}ea:{fa:{if((m|0)!=(p|0)){H[f+(t<<2)>>2]=a;b=0;if((q|0)==-4){break fa}}H[f+(k<<2)>>2]=w;b=k+1|0;if((b|0)==-1){break ea}}H[f+(b<<2)>>2]=y}if((c|0)!=(x|0)){H[c>>2]=a;c=c+4|0;H[l+68>>2]=c;break U}b=c-d|0;k=b>>2;g=k+1|0;if(g>>>0>=1073741824){break b}f=b>>>1|0;b=b>>>0>=2147483644?1073741823:g>>>0>>0?f:g;if(b){if(b>>>0>=1073741824){break B}f=pa(b<<2)}else{f=0}g=f+(k<<2)|0;H[g>>2]=a;x=f+(b<<2)|0;a=g+4|0;if((c|0)!=(d|0)){while(1){g=g-4|0;c=c-4|0;H[g>>2]=H[c>>2];if((c|0)!=(d|0)){continue}break}}H[l+72>>2]=x;H[l+68>>2]=a;H[l+64>>2]=g;if(d){oa(d)}c=a}d=g}Ce(r,H[c-4>>2]);a=H[j+40>>2];if((a|0)==H[j+36>>2]){break I}b=a-12|0;f=H[b+4>>2];h=(h^-1)+n|0;if(f>>>0>h>>>0){break P}if((f|0)!=(h|0)){break I}k=I[a-4|0];f=H[b>>2];H[j+40>>2]=b;if((f|0)<0){break P}m=c-4|0;a=H[m>>2];H[l+20>>2]=(f^-1)+n;b=l+20|0;H[l+88>>2]=b;Gb(l,l+40|0,b,l+88|0);f=H[l>>2];ga:{if(k&1){b=-1;if((a|0)==-1){break ga}b=a+1|0;b=(b>>>0)%3|0?b:a-2|0;break ga}b=-1;if((a|0)==-1){break ga}b=a-1|0;if((a>>>0)%3|0){break ga}b=a+2|0}H[f+12>>2]=b;b=H[j+40>>2];if((b|0)==H[j+36>>2]){break I}while(1){a=b-12|0;f=H[a+4>>2];if(f>>>0>h>>>0){break P}if((f|0)!=(h|0)){break I}f=I[b-4|0];b=H[a>>2];H[j+40>>2]=a;if((b|0)<0){break P}a=H[m>>2];H[l+20>>2]=(b^-1)+n;b=l+20|0;H[l+88>>2]=b;Gb(l,l+40|0,b,l+88|0);k=H[l>>2];ha:{if(f&1){b=-1;if((a|0)==-1){break ha}b=a+1|0;b=(b>>>0)%3|0?b:a-2|0;break ha}b=-1;if((a|0)==-1){break ha}b=a-1|0;if((a>>>0)%3|0){break ha}b=a+2|0}H[k+12>>2]=b;b=H[j+40>>2];if((b|0)!=H[j+36>>2]){continue}break}break I}f=-1;d=H[p>>2];H[d+(k<<2)>>2]=-1;b=-1;break Q}d=H[p>>2];f=H[d+(f<<2)>>2]}H[(k<<2)+d>>2]=f;E=a+1|0;a=(E>>>0)%3|0?E:a-2|0;b=-1;if((a|0)==-1){break Q}b=H[(a<<2)+d>>2]}H[d+y>>2]=b;ia:{if((m|0)==-1){H[d+h>>2]=-1;t=-1;a=-1;break ia}ja:{ka:{la:{if((m>>>0)%3|0){b=m-1|0;break la}b=m+2|0;if((b|0)==-1){break ka}}a=H[(b<<2)+d>>2];H[d+h>>2]=a;if((a|0)==-1){break ja}H[H[p+24>>2]+(a<<2)>>2]=t;break ja}H[d+h>>2]=-1}t=-1;b=m+1|0;b=(b>>>0)%3|0?b:m-2|0;a=-1;if((b|0)==-1){break ia}t=H[(b<<2)+d>>2];a=b}b=H[j+388>>2];h=f<<2;m=b+h|0;y=b;b=t<<2;H[m>>2]=H[m>>2]+H[y+b>>2];m=b;b=H[p+24>>2];m=m+b|0;if((f|0)!=-1){H[b+h>>2]=H[m>>2]}b=a;while(1){if((b|0)==-1){break O}H[(b<<2)+d>>2]=f;p=b+1|0;b=(p>>>0)%3|0?p:b-2|0;h=-1;ma:{if((b|0)==-1){break ma}b=H[q+(b<<2)>>2];h=-1;if((b|0)==-1){break ma}h=b+1|0;h=(h>>>0)%3|0?h:b-2|0}b=h;if((a|0)!=(b|0)){continue}break}}b=-1;if(!D){break E}break D}H[m>>2]=-1;na:{if(P){break na}if((z|0)!=(A|0)){H[A>>2]=t;A=A+4|0;H[l+28>>2]=A;break na}a=z-o|0;h=a>>2;b=h+1|0;if(b>>>0>=1073741824){break b}d=a>>>1|0;d=a>>>0>=2147483644?1073741823:b>>>0>>0?d:b;if(d){if(d>>>0>=1073741824){break B}a=pa(d<<2)}else{a=0}b=a+(h<<2)|0;H[b>>2]=t;A=b+4|0;if((o|0)!=(z|0)){while(1){b=b-4|0;z=z-4|0;H[b>>2]=H[z>>2];if((o|0)!=(z|0)){continue}break}}z=a+(d<<2)|0;H[l+32>>2]=z;H[l+28>>2]=A;H[l+24>>2]=b;if(o){oa(o)}o=b}H[w>>2]=k}Ce(r,k);d=g}D=(i|0)<(n|0);if((i|0)!=(n|0)){continue}break}i=n}b=-1;d=H[j+8>>2];if(H[d+28>>2]-H[d+24>>2]>>2>(L|0)){break D}if((c|0)!=(g|0)){x=j+72|0;h=j+60|0;p=j+312|0;while(1){c=c-4|0;o=H[c>>2];H[l+68>>2]=c;oa:{pa:{qa:{if(J[j+270>>1]<=513){if(!I[j+364|0]){break pa}a=H[j+360>>2];b=H[j+352>>2]+(a>>>3|0)|0;if(b>>>0>=K[j+356>>2]){break qa}b=I[b|0];H[j+360>>2]=a+1;if(!(b>>>(a&7)&1)){break qa}break pa}if(Ba(p)){break pa}}b=H[j+64>>2];a=H[j+68>>2];if((b|0)==a<<5){if((b+1|0)<0){break b}if(b>>>0<=1073741822){a=a<<6;b=(b&-32)+32|0;a=a>>>0>b>>>0?a:b}else{a=2147483647}pb(h,a);b=H[j+64>>2]}H[j+64>>2]=b+1;a=H[j+60>>2]+(b>>>3&536870908)|0;d=H[a>>2];Q=a,R=Vj(b)&d,H[Q>>2]=R;b=H[j+76>>2];if((b|0)!=H[j+80>>2]){H[b>>2]=o;H[j+76>>2]=b+4;break oa}d=H[x>>2];a=b-d|0;k=a>>2;f=k+1|0;if(f>>>0<1073741824){n=a>>>1|0;n=a>>>0>=2147483644?1073741823:f>>>0>>0?n:f;if(n){if(n>>>0>=1073741824){break B}a=pa(n<<2)}else{a=0}f=a+(k<<2)|0;H[f>>2]=o;o=f+4|0;if((b|0)!=(d|0)){while(1){f=f-4|0;b=b-4|0;H[f>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[j+80>>2]=a+(n<<2);H[j+76>>2]=o;H[j+72>>2]=f;if(!d){break oa}oa(d);break oa}break b}m=H[j+8>>2];r=H[m>>2];if(((H[m+4>>2]-r>>2>>>0)/3|0)<=(i|0)){b=-1;break D}d=-1;q=H[m+24>>2];n=-1;ra:{if((o|0)==-1){break ra}g=o+1|0;g=(g>>>0)%3|0?g:o-2|0;n=-1;if((g|0)==-1){break ra}n=H[r+(g<<2)>>2]}a=H[q+(n<<2)>>2];sa:{if((a|0)==-1){k=1;f=-1;break sa}k=1;f=-1;b=a+1|0;a=(b>>>0)%3|0?b:a-2|0;if((a|0)==-1){break sa}k=0;d=a;b=a+1|0;b=(b>>>0)%3|0?b:a-2|0;if((b|0)!=-1){f=H[r+(b<<2)>>2]}}b=-1;g=-1;a=H[q+(f<<2)>>2];if((a|0)!=-1){g=a+1|0;g=(g>>>0)%3|0?g:a-2|0}if((d|0)==(o|0)|(g|0)==(o|0)|((o|0)!=-1&H[H[m+12>>2]+(o<<2)>>2]!=-1|(d|0)==(g|0))){break D}if(!k&H[H[m+12>>2]+(d<<2)>>2]!=-1){break D}k=-1;a=H[m+12>>2];m=-1;ta:{if((g|0)==-1){break ta}if(H[a+(g<<2)>>2]!=-1){break D}b=g+1|0;b=(b>>>0)%3|0?b:g-2|0;m=-1;if((b|0)==-1){break ta}m=H[r+(b<<2)>>2]}b=N(i,3);H[l>>2]=b;H[a+(b<<2)>>2]=o;H[a+(o<<2)>>2]=b;b=H[l>>2]+1|0;H[a+(b<<2)>>2]=d;H[a+(d<<2)>>2]=b;b=H[l>>2]+2|0;H[a+(b<<2)>>2]=g;H[a+(g<<2)>>2]=b;a=H[l>>2];H[r+(a<<2)>>2]=f;b=a+1|0;d=r+(b<<2)|0;H[d>>2]=m;g=a+2|0;o=r+(g<<2)|0;H[o>>2]=n;a=H[j+120>>2];f=b?f:-1;n=a+(f>>>3&536870908)|0;r=H[n>>2];Q=n,R=Vj(f)&r,H[Q>>2]=R;k=(b|0)!=-1?H[d>>2]:k;b=a+(k>>>3&536870908)|0;d=H[b>>2];Q=b,R=Vj(k)&d,H[Q>>2]=R;b=-1;b=(g|0)!=-1?H[o>>2]:b;a=a+(b>>>3&536870908)|0;d=H[a>>2];Q=a,R=Vj(b)&d,H[Q>>2]=R;F[l+88|0]=1;_c(h,l+88|0);Ka(x,l);i=i+1|0;g=H[l+64>>2]}if((c|0)!=(g|0)){continue}break}d=H[j+8>>2]}b=-1;if(((H[d+4>>2]-H[d>>2]>>2>>>0)/3|0)!=(i|0)){break D}b=H[d+28>>2]-H[d+24>>2]>>2;i=H[l+24>>2];f=H[l+28>>2];if((i|0)==(f|0)){break C}while(1){a=H[i>>2];h=H[d+24>>2];c=b-1|0;g=h+(c<<2)|0;if(H[g>>2]==-1){while(1){c=b-2|0;b=b-1|0;g=h+(c<<2)|0;if(H[g>>2]==-1){continue}break}}if(a>>>0<=c>>>0){H[l>>2]=d;g=H[g>>2];F[l+12|0]=1;H[l+8>>2]=g;H[l+4>>2]=g;if((g|0)!=-1){while(1){d=H[H[j+8>>2]>>2]+(g<<2)|0;if(H[d>>2]!=(c|0)){b=-1;break D}H[d>>2]=a;uc(l);g=H[l+8>>2];if((g|0)!=-1){continue}break}d=H[j+8>>2]}h=H[d+24>>2];g=h+(c<<2)|0;if((a|0)!=-1){H[h+(a<<2)>>2]=H[g>>2]}H[g>>2]=-1;g=1<>2];a=h+(a>>>3&536870908)|0;h=h+(c>>>3&536870908)|0;c=1<>2]&c){g=g|H[a>>2]}else{g=H[a>>2]&(g^-1)}H[a>>2]=g;H[h>>2]=H[h>>2]&(c^-1);b=b-1|0}i=i+4|0;if((f|0)!=(i|0)){continue}break}}i=H[l+24>>2]}if(i){oa(i)}a=H[l+48>>2];if(a){while(1){c=H[a>>2];oa(a);a=c;if(a){continue}break}}a=H[l+40>>2];H[l+40>>2]=0;if(a){oa(a)}a=H[l+64>>2];if(a){H[l+68>>2]=a;oa(a)}ca=l+96|0;break A}wa();v()}if((b|0)==-1){break z}a=O;c=H[a+16>>2];d=c+H[a>>2]|0;c=H[a+8>>2]-c|0;a=H[H[j+4>>2]+32>>2];G[a+38>>1]=J[a+38>>1];H[a>>2]=d;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=c;H[a+12>>2]=0;a=H[j+4>>2];c=J[a+36>>1];g=c<<8|c>>>8;if((g&65535)>>>0<=513){a=H[a+32>>2];c=H[a+16>>2];d=M+H[a+20>>2]|0;c=c+C|0;d=c>>>0>>0?d+1|0:d;H[a+16>>2]=c;H[a+20>>2]=d}ua:{if(H[j+216>>2]==H[j+220>>2]){break ua}c=H[j+8>>2];a=H[c>>2];c=H[c+4>>2];va:{if((g&65535)>>>0>=513){if((a|0)==(c|0)){break ua}c=0;break va}if((a|0)==(c|0)){break ua}c=0;while(1){if(cd(j,c)){c=c+3|0;a=H[j+8>>2];if(c>>>0>2]-H[a>>2]>>2>>>0){continue}break ua}break}break z}while(1){if(bd(j,c)){c=c+3|0;a=H[j+8>>2];if(c>>>0>2]-H[a>>2]>>2>>>0){continue}break ua}break}break z}ad(e);c=H[j+216>>2];if((c|0)!=H[j+220>>2]){n=0;while(1){d=N(n,144);Jc((d+c|0)+4|0,H[j+8>>2]);a=H[B>>2];e=a+d|0;c=H[e+132>>2];e=H[e+136>>2];if((c|0)!=(e|0)){while(1){Hc((d+H[B>>2]|0)+4|0,H[c>>2]);c=c+4|0;if((e|0)!=(c|0)){continue}break}a=H[B>>2]}if(!Ic((a+d|0)+4|0)){break z}n=n+1|0;c=H[j+216>>2];if(n>>>0<(H[j+220>>2]-c|0)/144>>>0){continue}break}}a=H[j+8>>2];Hb(j+184|0,H[a+28>>2]-H[a+24>>2]>>2);u=H[j+216>>2];if((u|0)!=H[j+220>>2]){c=0;while(1){a=N(c,144)+u|0;d=H[a+60>>2]-H[a+56>>2]>>2;f=a+104|0;a=H[j+8>>2];a=H[a+28>>2]-H[a+24>>2]>>2;Hb(f,(a|0)<(d|0)?d:a);c=c+1|0;u=H[j+216>>2];if(c>>>0<(H[j+220>>2]-u|0)/144>>>0){continue}break}}u=$c(j,b)}break c}u=0}ca=s- -64|0;return u|0}sa();v()}function ii(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,L=0,M=0,O=0,P=0,Q=0,R=0,S=0;u=ca+-64|0;ca=u;H[a+132>>2]=0;if(H[a+148>>2]){c=H[a+144>>2];if(c){while(1){b=H[c>>2];oa(c);c=b;if(b){continue}break}}c=0;H[a+144>>2]=0;l=H[a+140>>2];a:{if(!l){break a}if(l>>>0>=4){b=l&-4;while(1){e=c<<2;H[e+H[a+136>>2]>>2]=0;H[H[a+136>>2]+(e|4)>>2]=0;H[H[a+136>>2]+(e|8)>>2]=0;H[H[a+136>>2]+(e|12)>>2]=0;c=c+4|0;f=f+4|0;if((b|0)!=(f|0)){continue}break}}b=l&3;if(!b){break a}while(1){H[H[a+136>>2]+(c<<2)>>2]=0;c=c+1|0;w=w+1|0;if((b|0)!=(w|0)){continue}break}}H[a+148>>2]=0}b:{c:{c=H[a+4>>2];w=I[c+36|0];b=w<<8|I[c+37|0];if(b>>>0<=513){g=H[c+32>>2];d:{if(b>>>0<=511){f=H[g+20>>2];l=H[g+16>>2];e=l+4|0;f=e>>>0<4?f+1|0:f;b=f;d=H[g+12>>2];if(K[g+8>>2]>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break c}f=l+H[g>>2]|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[g+16>>2]=e;H[g+20>>2]=b;break d}if(!Ea(1,u,g)){break c}c=H[a+4>>2];w=I[c+36|0];f=H[u>>2]}H[a+132>>2]=f}d=H[c+32>>2];e:{f:{g:{if((w&255)>>>0<=1){w=0;b=H[d+20>>2];e=H[d+16>>2];f=e+4|0;b=f>>>0<4?b+1|0:b;l=H[d+12>>2];if(K[d+8>>2]>>0&(l|0)<=(b|0)|(b|0)>(l|0)){break b}e=e+H[d>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[u+60>>2]=e;H[d+16>>2]=f;H[d+20>>2]=b;H[a+156>>2]=e;t=a+156|0;break g}w=0;if(!Ea(1,u+60|0,d)){break b}c=H[a+4>>2];b=I[c+36|0];H[a+156>>2]=H[u+60>>2];t=a+156|0;if(b>>>0>1){break f}}d=H[c+32>>2];e=H[d+8>>2];l=H[d+12>>2];c=H[d+20>>2];f=H[d+16>>2];b=f+4|0;c=b>>>0<4?c+1|0:c;if(b>>>0>e>>>0&(c|0)>=(l|0)|(c|0)>(l|0)){break b}f=f+H[d>>2]|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[u+56>>2]=f;H[d+16>>2]=b;H[d+20>>2]=c;break e}if(!Ea(1,u+56|0,H[c+32>>2])){break b}f=H[u+56>>2]}if(f>>>0>1431655765|K[t>>2]>N(f,3)>>>0){break b}E=H[a+4>>2];x=H[E+32>>2];c=H[x+8>>2];d=H[x+12>>2];b=H[x+20>>2];h=H[x+16>>2];if((d|0)<=(b|0)&h>>>0>=c>>>0|(b|0)>(d|0)){break b}j=H[x>>2];k=I[j+h|0];e=x;l=h+1|0;g=l?b:b+1|0;H[e+16>>2]=l;H[e+20>>2]=g;h:{if(I[E+36|0]<=1){e=c;c=h+5|0;b=c>>>0<5?b+1|0:b;if(c>>>0>e>>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break b}e=j+l|0;t=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[u+52>>2]=t;H[x+16>>2]=c;H[x+20>>2]=b;break h}if(!Ea(1,u+52|0,x)){break b}t=H[u+52>>2]}if(f>>>0>>0|((t>>>0)/3|0)+t>>>0>>0){break b}c=H[a+4>>2];d=H[c+32>>2];i:{if(I[c+36|0]<=1){c=H[d+20>>2];b=H[d+16>>2];e=b+4|0;c=e>>>0<4?c+1|0:c;l=H[d+12>>2];if(K[d+8>>2]>>0&(l|0)<=(c|0)|(c|0)>(l|0)){break b}b=b+H[d>>2]|0;b=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[u+48>>2]=b;H[d+16>>2]=e;H[d+20>>2]=c;break i}if(!Ea(1,u+48|0,d)){break b}b=H[u+48>>2]}if(b>>>0>t>>>0){break b}H[a+28>>2]=H[a+24>>2];c=$b(pa(88));e=H[a+8>>2];H[a+8>>2]=c;if(e){cb(e);if(!H[a+8>>2]){break b}}H[a+164>>2]=H[a+160>>2];Jb(a+160|0,f);H[a+176>>2]=H[a+172>>2];Jb(a+172|0,f);H[a- -64>>2]=0;H[a+92>>2]=-1;H[a+84>>2]=-1;H[a+88>>2]=-1;H[a+40>>2]=H[a+36>>2];H[a+52>>2]=H[a+48>>2];H[a+76>>2]=H[a+72>>2];M=a+216|0;ed(M);dd(M,k);if(!Lc(H[a+8>>2],f,H[a+156>>2]+b|0)){break b}c=H[a+156>>2];F[u|0]=1;Oa(a+120|0,b+c|0,u);f=H[a+4>>2];c=J[f+36>>1];c=(c<<8|c>>>8)&65535;j:{if(c>>>0<=513){g=H[f+32>>2];k:{if(c>>>0<=511){f=H[g+20>>2];l=H[g+16>>2];e=l+4|0;f=e>>>0<4?f+1|0:f;c=f;d=H[g+12>>2];if(K[g+8>>2]>>0&(c|0)>=(d|0)|(c|0)>(d|0)){break b}f=l+H[g>>2]|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[g+16>>2]=e;H[g+20>>2]=c;break k}if(!Ea(1,u+44|0,g)){break b}f=H[u+44>>2]}if(!f){break b}d=H[H[a+4>>2]+32>>2];l=H[d+8>>2];c=H[d+16>>2];e=l-c|0;c=H[d+12>>2]-(H[d+20>>2]+(c>>>0>l>>>0)|0)|0;if((c|0)<=0&f>>>0>e>>>0|(c|0)<0){break b}g=Ha(u);d=H[H[a+4>>2]+32>>2];l=H[d+16>>2];e=(l+H[d>>2]|0)+f|0;c=H[d+8>>2]-l|0;G[g+38>>1]=J[d+38>>1];H[g>>2]=e;H[g+16>>2]=0;H[g+20>>2]=0;H[g+8>>2]=c-f;H[g+12>>2]=0;c=Ib(a,g);if((c|0)==-1){break b}E=c;P=c>>31;break j}E=-1;P=-1;if((Ib(a,H[f+32>>2])|0)==-1){break b}}B=a+232|0;Ee(B,a);H[a+372>>2]=k;H[a+384>>2]=H[a+156>>2]+b;x=Ha(u);g=x;d=0;l=ca-16|0;ca=l;l:{if(!Ge(B,g)){break l}b=H[g+20>>2];f=H[g+16>>2];c=f+4|0;b=c>>>0<4?b+1|0:b;e=H[g+12>>2];if(K[g+8>>2]>>0&(e|0)<=(b|0)|(b|0)>(e|0)){break l}f=f+H[g>>2]|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[g+16>>2]=c;H[g+20>>2]=b;if((f|0)<0){break l}b=f;f=H[B+152>>2];if((b|0)>=(f|0)){break l}H[l+12>>2]=0;c=H[B+156>>2];b=H[B+160>>2]-c>>2;m:{if(b>>>0>>0){Pa(B+156|0,f-b|0,l+12|0);break m}if(b>>>0<=f>>>0){break m}H[B+160>>2]=c+(f<<2)}d=ta(B+168|0,g)}ca=l+16|0;n:{if(!d){break n}d=0;c=0;f=0;l=0;i=ca-96|0;ca=i;H[i+72>>2]=0;H[i+64>>2]=0;H[i+68>>2]=0;H[i+48>>2]=0;H[i+52>>2]=0;H[i+40>>2]=0;H[i+44>>2]=0;H[i+56>>2]=1065353216;H[i+32>>2]=0;H[i+24>>2]=0;H[i+28>>2]=0;g=a;O=H[a+124>>2];o:{p:{q:{r:{s:{t:{if((t|0)<=0){break t}z=g+400|0;Q=g+232|0;C=H[g+216>>2]!=H[g+220>>2];y=1;while(1){e=l;l=e+1|0;u:{v:{w:{x:{y:{if(H[g+420>>2]!=-1){if(Ba(z)){break y}}if(!I[g+308|0]){break x}z:{o=H[g+296>>2];r=H[g+304>>2];a=o+(r>>>3|0)|0;k=H[g+300>>2];if(a>>>0>=k>>>0){break z}b=I[a|0];a=r+1|0;H[g+304>>2]=a;h=b>>>(r&7)&1;if(!h){break z}n=a>>>3|0;b=o+n|0;A:{if(b>>>0>=k>>>0){b=a;a=0;break A}j=I[b|0];b=r+2|0;H[g+304>>2]=b;n=b>>>3|0;a=j>>>(a&7)&1}j=n+o|0;if(j>>>0>>0){j=I[j|0];H[g+304>>2]=b+1;b=j>>>(b&7)<<1&2}else{b=0}p=(a|b)<<1|h;H[g+416>>2]=p;break w}H[g+416>>2]=0;break x}p=H[g+420>>2];H[g+416>>2]=p;if(p){break w}}if((c|0)==(f|0)){b=-1;break s}p=-1;n=H[g+8>>2];o=H[n+24>>2];j=c-4|0;m=H[j>>2];d=-1;B:{if((m|0)==-1){break B}b=m+1|0;b=(b>>>0)%3|0?b:m-2|0;d=-1;if((b|0)==-1){break B}d=H[H[n>>2]+(b<<2)>>2]}b=H[o+(d<<2)>>2];if((b|0)!=-1){a=b+1|0;p=(a>>>0)%3|0?a:b-2|0}if((m|0)==(p|0)){b=-1;break s}if((m|0)!=-1){b=-1;if(H[H[n+12>>2]+(m<<2)>>2]!=-1){break s}}k=H[n+12>>2];if((p|0)!=-1){b=-1;if(H[k+(p<<2)>>2]!=-1){break s}}q=N(e,3);a=q+1|0;H[k+(m<<2)>>2]=a;h=a<<2;H[h+k>>2]=m;r=q+2|0;H[k+(p<<2)>>2]=r;e=r<<2;H[e+k>>2]=p;k=-1;a=-1;C:{if((m|0)==-1){break C}D:{if((m>>>0)%3|0){b=m-1|0;break D}b=m+2|0;a=-1;if((b|0)==-1){break C}}a=H[H[n>>2]+(b<<2)>>2]}E:{if((p|0)==-1){break E}b=p+1|0;b=(b>>>0)%3|0?b:p-2|0;if((b|0)==-1){break E}k=H[H[n>>2]+(b<<2)>>2]}b=-1;if((a|0)==(d|0)|(d|0)==(k|0)){break s}b=H[n>>2];H[b+(q<<2)>>2]=d;H[b+h>>2]=k;H[b+e>>2]=a;if((a|0)!=-1){H[o+(a<<2)>>2]=r}b=H[g+120>>2]+(d>>>3&536870908)|0;a=H[b>>2];R=b,S=Vj(d)&a,H[R>>2]=S;H[j>>2]=q;p=H[c-4>>2];break v}b=-1;F:{G:{H:{I:{J:{K:{L:{M:{N:{O:{P:{switch(p-1|0){case 2:case 4:if((c|0)==(f|0)){break s}h=c-4|0;m=H[h>>2];r=H[g+8>>2];d=H[r+12>>2];if((m|0)!=-1&H[d+(m<<2)>>2]!=-1){break s}q=N(e,3);k=(p|0)==5;j=q+(k?2:1)|0;a=j<<2;H[a+d>>2]=m;H[d+(m<<2)>>2]=j;Ka(r+24|0,11424);d=H[g+8>>2];o=H[d+24>>2];if(H[d+28>>2]-o>>2>(O|0)){break s}n=H[d>>2];p=n+a|0;d=H[r+28>>2];b=H[r+24>>2];a=(d-b>>2)-1|0;H[p>>2]=a;if((b|0)!=(d|0)){H[o+(a<<2)>>2]=j}d=k?q:q+2|0;j=n+(k+q<<2)|0;Q:{if((m|0)==-1){H[n+(d<<2)>>2]=-1;b=-1;break Q}R:{S:{T:{if((m>>>0)%3|0){a=m-1|0;break T}a=m+2|0;if((a|0)==-1){break S}}a=H[n+(a<<2)>>2];H[n+(d<<2)>>2]=a;if((a|0)==-1){break R}H[o+(a<<2)>>2]=d;break R}H[n+(d<<2)>>2]=-1}a=m+1|0;a=(a>>>0)%3|0?a:m-2|0;b=-1;if((a|0)==-1){break Q}b=H[n+(a<<2)>>2]}H[j>>2]=b;H[h>>2]=q;break O;case 0:if((c|0)==(d|0)){break s}a=c-4|0;m=H[a>>2];H[i+68>>2]=a;k=H[i+44>>2];U:{if(!k){c=a;break U}o=H[i+40>>2];h=Uj(k)>>>0>1;b=e&k+2147483647;V:{if(!h){break V}b=e;if(b>>>0>>0){break V}b=(e>>>0)%(k>>>0)|0}j=b;b=H[o+(j<<2)>>2];if(!b){c=a;break U}b=H[b>>2];if(!b){c=a;break U}W:{if(!h){k=k-1|0;while(1){h=H[b+4>>2];X:{if((h|0)!=(e|0)){if((j|0)==(h&k)){break X}c=a;break U}if((e|0)==H[b+8>>2]){break W}}b=H[b>>2];if(b){continue}break}c=a;break U}while(1){h=H[b+4>>2];Y:{if((h|0)!=(e|0)){if(h>>>0>=k>>>0){h=(h>>>0)%(k>>>0)|0}if((h|0)==(j|0)){break Y}c=a;break U}if((e|0)==H[b+8>>2]){break W}}b=H[b>>2];if(b){continue}break}c=a;break U}if((a|0)!=(A|0)){H[a>>2]=H[b+12>>2];H[i+68>>2]=c;break U}h=A-d|0;c=h>>2;f=c+1|0;if(f>>>0>=1073741824){break M}a=h>>>1|0;h=h>>>0>=2147483644?1073741823:a>>>0>f>>>0?a:f;if(h){if(h>>>0>=1073741824){break p}a=pa(h<<2)}else{a=0}f=a+(c<<2)|0;H[f>>2]=H[b+12>>2];c=f+4|0;if((d|0)!=(A|0)){while(1){f=f-4|0;A=A-4|0;H[f>>2]=H[A>>2];if((d|0)!=(A|0)){continue}break}}A=a+(h<<2)|0;H[i+72>>2]=A;H[i+68>>2]=c;H[i+64>>2]=f;if(d){oa(d)}}if((c|0)==(f|0)){break G}j=c-4|0;n=H[j>>2];if((n|0)==(m|0)){break G}d=(n|0)==-1;q=H[g+8>>2];if(!d&H[H[q+12>>2]+(n<<2)>>2]!=-1){break G}r=H[q+12>>2];if((m|0)!=-1&H[r+(m<<2)>>2]!=-1){break G}p=N(e,3);e=p+2|0;H[r+(n<<2)>>2]=e;o=e<<2;H[o+r>>2]=n;a=p+1|0;H[r+(m<<2)>>2]=a;b=a<<2;H[b+r>>2]=m;if(d){break L}if((n>>>0)%3|0){k=n-1|0;break J}k=n+2|0;if((k|0)!=-1){break J}d=H[q>>2];a=-1;break I;case 6:break P;default:break s}}a=H[g+8>>2];Ka(a+24|0,11424);h=H[g+8>>2];p=N(e,3);q=H[a+28>>2];r=H[a+24>>2];o=q-r|0;n=o>>2;k=n-1|0;H[H[h>>2]+(p<<2)>>2]=k;Ka(h+24|0,11424);j=p+1|0;H[H[h>>2]+(j<<2)>>2]=(H[h+28>>2]-H[h+24>>2]>>2)-1;a=H[g+8>>2];Ka(a+24|0,11424);h=p+2|0;H[H[a>>2]+(h<<2)>>2]=(H[a+28>>2]-H[a+24>>2]>>2)-1;a=H[g+8>>2];m=H[a+24>>2];if(H[a+28>>2]-m>>2>(O|0)){break s}Z:{_:{if((q|0)!=(r|0)){H[m+(k<<2)>>2]=p;b=0;if((o|0)==-4){break _}}H[m+(n<<2)>>2]=j;b=n+1|0;if((b|0)==-1){break Z}}H[m+(b<<2)>>2]=h}if((c|0)!=(A|0)){H[c>>2]=p;c=c+4|0;H[i+68>>2]=c;break N}h=c-d|0;b=h>>2;f=b+1|0;if(f>>>0>=1073741824){break K}a=h>>>1|0;h=h>>>0>=2147483644?1073741823:a>>>0>f>>>0?a:f;if(h){if(h>>>0>=1073741824){break p}a=pa(h<<2)}else{a=0}f=a+(b<<2)|0;H[f>>2]=p;A=a+(h<<2)|0;a=f+4|0;if((c|0)!=(d|0)){while(1){f=f-4|0;c=c-4|0;H[f>>2]=H[c>>2];if((c|0)!=(d|0)){continue}break}}H[i+72>>2]=A;H[i+68>>2]=a;H[i+64>>2]=f;if(d){oa(d)}c=a}d=f}De(Q,H[c-4>>2]);h=H[g+40>>2];if((h|0)==H[g+36>>2]){break u}b=h-12|0;a=H[b+4>>2];k=(e^-1)+t|0;if(a>>>0>k>>>0){break G}if((a|0)!=(k|0)){break u}e=I[h-4|0];a=H[b>>2];H[g+40>>2]=b;if((a|0)<0){break G}h=c-4|0;j=H[h>>2];H[i+20>>2]=(a^-1)+t;a=i+20|0;H[i+88>>2]=a;Gb(i,i+40|0,a,i+88|0);b=H[i>>2];$:{if(e&1){a=-1;if((j|0)==-1){break $}a=j+1|0;a=(a>>>0)%3|0?a:j-2|0;break $}a=-1;if((j|0)==-1){break $}a=j-1|0;if((j>>>0)%3|0){break $}a=j+2|0}H[b+12>>2]=a;b=H[g+40>>2];if((b|0)==H[g+36>>2]){break u}while(1){j=b-12|0;a=H[j+4>>2];if(a>>>0>k>>>0){break G}if((a|0)!=(k|0)){break u}e=I[b-4|0];a=H[j>>2];H[g+40>>2]=j;if((a|0)<0){break G}j=H[h>>2];H[i+20>>2]=(a^-1)+t;a=i+20|0;H[i+88>>2]=a;Gb(i,i+40|0,a,i+88|0);b=H[i>>2];aa:{if(e&1){a=-1;if((j|0)==-1){break aa}a=j+1|0;a=(a>>>0)%3|0?a:j-2|0;break aa}a=-1;if((j|0)==-1){break aa}a=j-1|0;if((j>>>0)%3|0){break aa}a=j+2|0}H[b+12>>2]=a;b=H[g+40>>2];if((b|0)!=H[g+36>>2]){continue}break}break u}sa();v()}k=-1;d=H[q>>2];H[d+(p<<2)>>2]=-1;h=-1;break H}sa();v()}d=H[q>>2];a=H[d+(k<<2)>>2]}k=a;H[(p<<2)+d>>2]=a;a=n+1|0;a=(a>>>0)%3|0?a:n-2|0;h=-1;if((a|0)==-1){break H}h=H[(a<<2)+d>>2]}H[b+d>>2]=h;ba:{if((m|0)==-1){H[d+o>>2]=-1;n=-1;a=-1;break ba}ca:{da:{ea:{if((m>>>0)%3|0){b=m-1|0;break ea}b=m+2|0;if((b|0)==-1){break da}}a=H[(b<<2)+d>>2];H[d+o>>2]=a;if((a|0)==-1){break ca}H[H[q+24>>2]+(a<<2)>>2]=e;break ca}H[d+o>>2]=-1}n=-1;b=m+1|0;b=(b>>>0)%3|0?b:m-2|0;a=-1;if((b|0)==-1){break ba}n=H[(b<<2)+d>>2];a=b}h=H[g+388>>2];e=k<<2;b=h+e|0;o=b;m=H[b>>2];b=n<<2;H[o>>2]=m+H[b+h>>2];h=b;b=H[q+24>>2];o=h+b|0;if((k|0)!=-1){H[b+e>>2]=H[o>>2]}b=a;while(1){if((b|0)==-1){break F}H[(b<<2)+d>>2]=k;h=b+1|0;b=(h>>>0)%3|0?h:b-2|0;e=-1;fa:{if((b|0)==-1){break fa}h=H[r+(b<<2)>>2];e=-1;if((h|0)==-1){break fa}b=h+1|0;e=(b>>>0)%3|0?b:h-2|0}b=e;if((a|0)!=(b|0)){continue}break}}b=-1;if(!(y&1)){break t}break s}H[o>>2]=-1;ga:{if(C){break ga}if((D|0)!=(L|0)){H[L>>2]=n;L=L+4|0;H[i+28>>2]=L;break ga}d=D-s|0;b=d>>2;e=b+1|0;if(e>>>0>=1073741824){break q}a=d>>>1|0;e=d>>>0>=2147483644?1073741823:a>>>0>e>>>0?a:e;if(e){if(e>>>0>=1073741824){break p}a=pa(e<<2)}else{a=0}b=a+(b<<2)|0;H[b>>2]=n;L=b+4|0;if((s|0)!=(D|0)){while(1){b=b-4|0;D=D-4|0;H[b>>2]=H[D>>2];if((s|0)!=(D|0)){continue}break}}D=a+(e<<2)|0;H[i+32>>2]=D;H[i+28>>2]=L;H[i+24>>2]=b;if(s){oa(s)}s=b}H[j>>2]=p}De(Q,p);d=f}y=(l|0)<(t|0);if((l|0)!=(t|0)){continue}break}l=t}b=-1;y=H[g+8>>2];if(H[y+28>>2]-H[y+24>>2]>>2>(O|0)){break s}if((c|0)!=(f|0)){r=g+72|0;j=g+60|0;t=g+312|0;while(1){c=c-4|0;z=H[c>>2];H[i+68>>2]=c;ha:{ia:{ja:{if(J[g+270>>1]<=513){if(!I[g+364|0]){break ia}b=H[g+360>>2];a=H[g+352>>2]+(b>>>3|0)|0;if(a>>>0>=K[g+356>>2]){break ja}a=I[a|0];H[g+360>>2]=b+1;if(!(a>>>(b&7)&1)){break ja}break ia}if(Ba(t)){break ia}}ka:{la:{b=H[g+64>>2];e=H[g+68>>2];if((b|0)==e<<5){if((b+1|0)<0){break la}if(b>>>0<=1073741822){e=e<<6;b=(b&-32)+32|0;a=b>>>0>>0?e:b}else{a=2147483647}pb(j,a);b=H[g+64>>2]}H[g+64>>2]=b+1;e=H[g+60>>2]+(b>>>3&536870908)|0;a=H[e>>2];R=e,S=Vj(b)&a,H[R>>2]=S;b=H[g+76>>2];if((b|0)!=H[g+80>>2]){H[b>>2]=z;H[g+76>>2]=b+4;break ha}s=H[r>>2];h=b-s|0;e=h>>2;d=e+1|0;if(d>>>0>=1073741824){break ka}a=h>>>1|0;h=h>>>0>=2147483644?1073741823:a>>>0>d>>>0?a:d;if(h){if(h>>>0>=1073741824){break p}a=pa(h<<2)}else{a=0}d=a+(e<<2)|0;H[d>>2]=z;e=d+4|0;if((b|0)!=(s|0)){while(1){d=d-4|0;b=b-4|0;H[d>>2]=H[b>>2];if((b|0)!=(s|0)){continue}break}}H[g+80>>2]=a+(h<<2);H[g+76>>2]=e;H[g+72>>2]=d;if(!s){break ha}oa(s);break ha}sa();v()}sa();v()}q=H[g+8>>2];C=H[q>>2];if(((H[q+4>>2]-C>>2>>>0)/3|0)<=(l|0)){b=-1;break s}f=-1;b=-1;d=-1;s=H[q+24>>2];e=-1;ma:{if((z|0)==-1){break ma}a=z+1|0;a=(a>>>0)%3|0?a:z-2|0;e=-1;if((a|0)==-1){break ma}e=H[C+(a<<2)>>2]}o=H[s+(e<<2)>>2];na:{if((o|0)==-1){k=1;a=-1;break na}k=1;h=o+1|0;h=(h>>>0)%3|0?h:o-2|0;a=-1;if((h|0)==-1){break na}k=0;a=h+1|0;f=h;a=(a>>>0)%3|0?a:f-2|0;if((a|0)!=-1){a=H[C+(a<<2)>>2]}else{a=-1}}h=H[(a<<2)+s>>2];if((h|0)!=-1){d=h+1|0;d=(d>>>0)%3|0?d:h-2|0}if((f|0)==(z|0)|(d|0)==(z|0)|((z|0)!=-1&H[H[q+12>>2]+(z<<2)>>2]!=-1|(d|0)==(f|0))){break s}if(!k&H[H[q+12>>2]+(f<<2)>>2]!=-1){break s}k=-1;s=H[q+12>>2];h=-1;oa:{if((d|0)==-1){break oa}if(H[s+(d<<2)>>2]!=-1){break s}b=d+1|0;b=(b>>>0)%3|0?b:d-2|0;h=-1;if((b|0)==-1){break oa}h=H[C+(b<<2)>>2]}b=N(l,3);H[i>>2]=b;H[s+(b<<2)>>2]=z;H[s+(z<<2)>>2]=b;b=H[i>>2]+1|0;H[s+(b<<2)>>2]=f;H[s+(f<<2)>>2]=b;b=H[i>>2]+2|0;H[s+(b<<2)>>2]=d;H[s+(d<<2)>>2]=b;b=H[i>>2];H[C+(b<<2)>>2]=a;o=b+1|0;s=C+(o<<2)|0;H[s>>2]=h;h=b+2|0;d=C+(h<<2)|0;H[d>>2]=e;e=H[g+120>>2];f=o?a:-1;b=e+(f>>>3&536870908)|0;a=H[b>>2];R=b,S=Vj(f)&a,H[R>>2]=S;k=(o|0)!=-1?H[s>>2]:k;b=e+(k>>>3&536870908)|0;a=H[b>>2];R=b,S=Vj(k)&a,H[R>>2]=S;b=-1;b=(h|0)!=-1?H[d>>2]:b;f=e+(b>>>3&536870908)|0;a=H[f>>2];R=f,S=Vj(b)&a,H[R>>2]=S;F[i+88|0]=1;_c(j,i+88|0);Ka(r,i);l=l+1|0;f=H[i+64>>2]}if((c|0)!=(f|0)){continue}break}y=H[g+8>>2]}b=-1;if(((H[y+4>>2]-H[y>>2]>>2>>>0)/3|0)!=(l|0)){break s}b=H[y+28>>2]-H[y+24>>2]>>2;l=H[i+24>>2];e=H[i+28>>2];if((l|0)==(e|0)){break r}while(1){j=H[l>>2];a=H[y+24>>2];c=b-1|0;d=a+(c<<2)|0;if(H[d>>2]==-1){while(1){c=b-2|0;b=b-1|0;d=a+(c<<2)|0;if(H[d>>2]==-1){continue}break}}if(c>>>0>=j>>>0){H[i>>2]=y;d=H[d>>2];F[i+12|0]=1;H[i+8>>2]=d;H[i+4>>2]=d;if((d|0)!=-1){while(1){a=H[H[g+8>>2]>>2]+(d<<2)|0;if(H[a>>2]!=(c|0)){b=-1;break s}H[a>>2]=j;uc(i);d=H[i+8>>2];if((d|0)!=-1){continue}break}y=H[g+8>>2]}a=H[y+24>>2];f=a+(c<<2)|0;if((j|0)!=-1){H[a+(j<<2)>>2]=H[f>>2]}H[f>>2]=-1;h=1<>2];f=a+(j>>>3&536870908)|0;d=a+(c>>>3&536870908)|0;a=1<>2]&a){c=h|H[f>>2]}else{c=H[f>>2]&(h^-1)}H[f>>2]=c;H[d>>2]=H[d>>2]&(a^-1);b=b-1|0}l=l+4|0;if((e|0)!=(l|0)){continue}break}}l=H[i+24>>2]}if(l){oa(l)}a=H[i+48>>2];if(a){while(1){c=H[a>>2];oa(a);a=c;if(a){continue}break}}a=H[i+40>>2];H[i+40>>2]=0;if(a){oa(a)}a=H[i+64>>2];if(a){H[i+68>>2]=a;oa(a)}ca=i+96|0;break o}sa();v()}wa();v()}f=b;if((b|0)==-1){break n}b=H[x+16>>2];c=b+H[x>>2]|0;a=H[x+8>>2]-b|0;b=H[H[g+4>>2]+32>>2];G[b+38>>1]=J[b+38>>1];H[b>>2]=c;H[b+16>>2]=0;H[b+20>>2]=0;H[b+8>>2]=a;H[b+12>>2]=0;b=H[g+4>>2];a=J[b+36>>1];c=a<<8|a>>>8;if((c&65535)>>>0<=513){b=H[b+32>>2];e=b;a=H[b+16>>2];b=P+H[b+20>>2]|0;a=a+E|0;b=a>>>0>>0?b+1|0:b;H[e+16>>2]=a;H[e+20>>2]=b}pa:{if(H[g+216>>2]==H[g+220>>2]){break pa}a=H[g+8>>2];b=H[a>>2];a=H[a+4>>2];qa:{if((c&65535)>>>0>=513){if((a|0)==(b|0)){break pa}c=0;break qa}if((a|0)==(b|0)){break pa}c=0;while(1){if(cd(g,c)){c=c+3|0;a=H[g+8>>2];if(c>>>0>2]-H[a>>2]>>2>>>0){continue}break pa}break}break n}while(1){if(bd(g,c)){c=c+3|0;a=H[g+8>>2];if(c>>>0>2]-H[a>>2]>>2>>>0){continue}break pa}break}break n}ad(B);c=H[g+216>>2];if((c|0)!=H[g+220>>2]){t=0;while(1){e=N(t,144);Jc((e+c|0)+4|0,H[g+8>>2]);a=H[M>>2];b=a+e|0;c=H[b+132>>2];b=H[b+136>>2];if((c|0)!=(b|0)){while(1){Hc((e+H[M>>2]|0)+4|0,H[c>>2]);c=c+4|0;if((b|0)!=(c|0)){continue}break}a=H[M>>2]}if(!Ic((a+e|0)+4|0)){break n}t=t+1|0;c=H[g+216>>2];if(t>>>0<(H[g+220>>2]-c|0)/144>>>0){continue}break}}a=H[g+8>>2];Hb(g+184|0,H[a+28>>2]-H[a+24>>2]>>2);w=H[g+216>>2];if((w|0)!=H[g+220>>2]){c=0;while(1){a=N(c,144)+w|0;b=H[a+60>>2]-H[a+56>>2]>>2;e=a+104|0;a=H[g+8>>2];a=H[a+28>>2]-H[a+24>>2]>>2;Hb(e,(a|0)<(b|0)?b:a);c=c+1|0;w=H[g+216>>2];if(c>>>0<(H[g+220>>2]-w|0)/144>>>0){continue}break}}w=$c(g,f)}break b}w=0}ca=u- -64|0;return w|0}function ki(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,L=0,M=0,O=0,P=0,Q=0;t=ca+-64|0;ca=t;H[a+132>>2]=0;if(H[a+148>>2]){d=H[a+144>>2];if(d){while(1){b=H[d>>2];oa(d);d=b;if(b){continue}break}}d=0;H[a+144>>2]=0;k=H[a+140>>2];a:{if(!k){break a}if(k>>>0>=4){b=k&-4;while(1){c=d<<2;H[c+H[a+136>>2]>>2]=0;H[H[a+136>>2]+(c|4)>>2]=0;H[H[a+136>>2]+(c|8)>>2]=0;H[H[a+136>>2]+(c|12)>>2]=0;d=d+4|0;e=e+4|0;if((b|0)!=(e|0)){continue}break}}b=k&3;if(!b){break a}while(1){H[H[a+136>>2]+(d<<2)>>2]=0;d=d+1|0;x=x+1|0;if((b|0)!=(x|0)){continue}break}}H[a+148>>2]=0}b:{c:{d=H[a+4>>2];x=I[d+36|0];b=x<<8|I[d+37|0];if(b>>>0<=513){f=H[d+32>>2];d:{if(b>>>0<=511){b=H[f+20>>2];e=H[f+16>>2];c=e+4|0;b=c>>>0<4?b+1|0:b;k=H[f+12>>2];if(K[f+8>>2]>>0&(k|0)<=(b|0)|(b|0)>(k|0)){break c}e=e+H[f>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[f+16>>2]=c;H[f+20>>2]=b;break d}if(!Ea(1,t,f)){break c}d=H[a+4>>2];x=I[d+36|0];e=H[t>>2]}H[a+132>>2]=e}f=H[d+32>>2];e:{f:{g:{if((x&255)>>>0<=1){x=0;b=H[f+20>>2];c=H[f+16>>2];e=c+4|0;b=e>>>0<4?b+1|0:b;k=H[f+12>>2];if(K[f+8>>2]>>0&(k|0)<=(b|0)|(b|0)>(k|0)){break b}c=c+H[f>>2]|0;c=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[t+60>>2]=c;H[f+16>>2]=e;H[f+20>>2]=b;H[a+156>>2]=c;l=a+156|0;break g}x=0;if(!Ea(1,t+60|0,f)){break b}d=H[a+4>>2];b=I[d+36|0];H[a+156>>2]=H[t+60>>2];l=a+156|0;if(b>>>0>1){break f}}f=H[d+32>>2];c=H[f+8>>2];k=H[f+12>>2];d=H[f+20>>2];e=H[f+16>>2];b=e+4|0;d=b>>>0<4?d+1|0:d;if(b>>>0>c>>>0&(d|0)>=(k|0)|(d|0)>(k|0)){break b}e=e+H[f>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[t+56>>2]=e;H[f+16>>2]=b;H[f+20>>2]=d;break e}if(!Ea(1,t+56|0,H[d+32>>2])){break b}e=H[t+56>>2]}if(e>>>0>1431655765|K[l>>2]>N(e,3)>>>0){break b}j=H[a+4>>2];y=H[j+32>>2];d=H[y+8>>2];f=H[y+12>>2];b=H[y+20>>2];m=H[y+16>>2];if((f|0)<=(b|0)&m>>>0>=d>>>0|(b|0)>(f|0)){break b}l=H[y>>2];g=I[l+m|0];c=y;k=m+1|0;C=k?b:b+1|0;H[c+16>>2]=k;H[c+20>>2]=C;h:{if(I[j+36|0]<=1){c=d;d=m+5|0;b=d>>>0<5?b+1|0:b;if(c>>>0>>0&(b|0)>=(f|0)|(b|0)>(f|0)){break b}c=k+l|0;l=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[t+52>>2]=l;H[y+16>>2]=d;H[y+20>>2]=b;break h}if(!Ea(1,t+52|0,y)){break b}l=H[t+52>>2]}if(e>>>0>>0|((l>>>0)/3|0)+l>>>0>>0){break b}d=H[a+4>>2];f=H[d+32>>2];i:{if(I[d+36|0]<=1){d=H[f+20>>2];b=H[f+16>>2];c=b+4|0;d=c>>>0<4?d+1|0:d;k=H[f+12>>2];if(K[f+8>>2]>>0&(k|0)<=(d|0)|(d|0)>(k|0)){break b}b=b+H[f>>2]|0;b=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[t+48>>2]=b;H[f+16>>2]=c;H[f+20>>2]=d;break i}if(!Ea(1,t+48|0,f)){break b}b=H[t+48>>2]}if(b>>>0>l>>>0){break b}H[a+28>>2]=H[a+24>>2];d=$b(pa(88));c=H[a+8>>2];H[a+8>>2]=d;if(c){cb(c);if(!H[a+8>>2]){break b}}H[a+164>>2]=H[a+160>>2];Jb(a+160|0,e);H[a+176>>2]=H[a+172>>2];Jb(a+172|0,e);H[a- -64>>2]=0;H[a+92>>2]=-1;H[a+84>>2]=-1;H[a+88>>2]=-1;H[a+40>>2]=H[a+36>>2];H[a+52>>2]=H[a+48>>2];H[a+76>>2]=H[a+72>>2];E=a+216|0;ed(E);dd(E,g);if(!Lc(H[a+8>>2],e,H[a+156>>2]+b|0)){break b}d=H[a+156>>2];F[t|0]=1;Oa(a+120|0,b+d|0,t);b=H[a+4>>2];d=J[b+36>>1];d=(d<<8|d>>>8)&65535;j:{if(d>>>0<=513){k=H[b+32>>2];k:{if(d>>>0<=511){b=H[k+20>>2];e=H[k+16>>2];d=e+4|0;b=d>>>0<4?b+1|0:b;c=H[k+12>>2];if(K[k+8>>2]>>0&(c|0)<=(b|0)|(b|0)>(c|0)){break b}e=e+H[k>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[k+16>>2]=d;H[k+20>>2]=b;break k}if(!Ea(1,t+44|0,k)){break b}e=H[t+44>>2]}if(!e){break b}k=H[H[a+4>>2]+32>>2];c=H[k+8>>2];d=H[k+16>>2];b=c-d|0;d=H[k+12>>2]-(H[k+20>>2]+(c>>>0>>0)|0)|0;if(b>>>0>>0&(d|0)<=0|(d|0)<0){break b}f=Ha(t);k=H[H[a+4>>2]+32>>2];c=H[k+16>>2];b=(c+H[k>>2]|0)+e|0;d=H[k+8>>2]-c|0;G[f+38>>1]=J[k+38>>1];H[f>>2]=b;H[f+16>>2]=0;H[f+20>>2]=0;H[f+8>>2]=d-e;H[f+12>>2]=0;d=Ib(a,f);if((d|0)==-1){break b}y=d;M=d>>31;break j}y=-1;M=-1;if((Ib(a,H[b+32>>2])|0)==-1){break b}}O=a+232|0;e=O;H[e+144>>2]=a;d=H[(ea[H[H[a>>2]+32>>2]](a)|0)+32>>2];b=H[d>>2]+H[d+16>>2]|0;d=H[(ea[H[H[a>>2]+32>>2]](a)|0)+32>>2];d=H[d+8>>2]-H[d+16>>2]|0;P=e,Q=J[H[(ea[H[H[a>>2]+32>>2]](a)|0)+32>>2]+38>>1],G[P+38>>1]=Q;H[e>>2]=b;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=d;H[e+12>>2]=0;H[a+372>>2]=g;C=Ha(t);l:{if(!Ge(e,C)){break l}b=0;d=0;e=0;k=0;i=ca-96|0;ca=i;H[i+72>>2]=0;H[i+64>>2]=0;H[i+68>>2]=0;H[i+48>>2]=0;H[i+52>>2]=0;H[i+40>>2]=0;H[i+44>>2]=0;H[i+56>>2]=1065353216;H[i+32>>2]=0;H[i+24>>2]=0;H[i+28>>2]=0;h=a;L=H[a+124>>2];m:{n:{o:{p:{q:{r:{if((l|0)<=0){break r}A=H[h+216>>2]!=H[h+220>>2];s=1;while(1){f=k;k=f+1|0;s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{C:{D:{E:{F:{G:{if(!I[h+308|0]){break G}u=H[h+296>>2];g=H[h+304>>2];a=u+(g>>>3|0)|0;p=H[h+300>>2];if(a>>>0>=p>>>0){break G}c=I[a|0];a=g+1|0;H[h+304>>2]=a;m=c>>>(g&7)&1;if(!m){break G}n=0;j=a>>>3|0;c=u+j|0;H:{if(c>>>0>=p>>>0){g=a;a=0;break H}c=I[c|0];g=g+2|0;H[h+304>>2]=g;j=g>>>3|0;a=c>>>(a&7)&1}c=j+u|0;if(c>>>0

>>0){c=I[c|0];H[h+304>>2]=g+1;n=c>>>(g&7)<<1&2}j=-1;a=m|(a|n)<<1;switch(a-1|0){case 6:break D;case 0:break E;case 2:case 4:break F;default:break q}}if((d|0)==(e|0)){j=-1;break q}g=-1;q=H[h+8>>2];u=H[q+24>>2];p=d-4|0;s=H[p>>2];c=-1;I:{if((s|0)==-1){break I}b=s+1|0;b=(b>>>0)%3|0?b:s-2|0;c=-1;if((b|0)==-1){break I}c=H[H[q>>2]+(b<<2)>>2]}b=H[u+(c<<2)>>2];if((b|0)!=-1){a=b+1|0;g=(a>>>0)%3|0?a:b-2|0}if((g|0)==(s|0)){j=-1;break q}if((s|0)!=-1){j=-1;if(H[H[q+12>>2]+(s<<2)>>2]!=-1){break q}}b=H[q+12>>2];if((g|0)!=-1){j=-1;if(H[b+(g<<2)>>2]!=-1){break q}}n=N(f,3);a=n+1|0;H[b+(s<<2)>>2]=a;m=a<<2;H[m+b>>2]=s;r=n+2|0;H[b+(g<<2)>>2]=r;f=r<<2;H[f+b>>2]=g;o=-1;a=-1;J:{if((s|0)==-1){break J}K:{if((s>>>0)%3|0){b=s-1|0;break K}b=s+2|0;a=-1;if((b|0)==-1){break J}}a=H[H[q>>2]+(b<<2)>>2]}L:{if((g|0)==-1){break L}b=g+1|0;b=(b>>>0)%3|0?b:g-2|0;if((b|0)==-1){break L}o=H[H[q>>2]+(b<<2)>>2]}j=-1;if((a|0)==(c|0)|(c|0)==(o|0)){break q}b=H[q>>2];H[b+(n<<2)>>2]=c;H[b+m>>2]=o;H[b+f>>2]=a;if((a|0)!=-1){H[u+(a<<2)>>2]=r}b=H[h+120>>2]+(c>>>3&536870908)|0;a=H[b>>2];P=b,Q=Vj(c)&a,H[P>>2]=Q;H[p>>2]=n;b=e;break s}if((d|0)==(e|0)){break q}m=d-4|0;n=H[m>>2];r=H[h+8>>2];b=H[r+12>>2];if((n|0)!=-1&H[b+(n<<2)>>2]!=-1){break q}o=N(f,3);p=(a|0)==5;g=o+(p?2:1)|0;a=g<<2;H[a+b>>2]=n;H[b+(n<<2)>>2]=g;Ka(r+24|0,11424);b=H[h+8>>2];u=H[b+24>>2];if(H[b+28>>2]-u>>2>(L|0)){break q}j=H[b>>2];q=j+a|0;c=H[r+28>>2];b=H[r+24>>2];a=(c-b>>2)-1|0;H[q>>2]=a;if((b|0)!=(c|0)){H[u+(a<<2)>>2]=g}c=p?o:o+2|0;g=j+(o+p<<2)|0;M:{if((n|0)==-1){H[j+(c<<2)>>2]=-1;b=-1;break M}N:{O:{P:{if((n>>>0)%3|0){a=n-1|0;break P}a=n+2|0;if((a|0)==-1){break O}}a=H[j+(a<<2)>>2];H[j+(c<<2)>>2]=a;if((a|0)==-1){break N}H[u+(a<<2)>>2]=c;break N}H[j+(c<<2)>>2]=-1}a=n+1|0;a=(a>>>0)%3|0?a:n-2|0;b=-1;if((a|0)==-1){break M}b=H[j+(a<<2)>>2]}H[g>>2]=b;H[m>>2]=o;b=e;break y}if((b|0)==(d|0)){break q}a=d-4|0;q=H[a>>2];H[i+68>>2]=a;p=H[i+44>>2];Q:{if(!p){d=a;break Q}g=H[i+40>>2];j=Uj(p)>>>0>1;c=f&p+2147483647;R:{if(!j){break R}c=f;if(c>>>0

>>0){break R}c=(f>>>0)%(p>>>0)|0}m=c;c=H[g+(m<<2)>>2];if(!c){d=a;break Q}g=H[c>>2];if(!g){d=a;break Q}S:{if(!j){j=p-1|0;while(1){c=H[g+4>>2];T:{if((c|0)!=(f|0)){if((m|0)==(c&j)){break T}d=a;break Q}if((f|0)==H[g+8>>2]){break S}}g=H[g>>2];if(g){continue}break}d=a;break Q}while(1){c=H[g+4>>2];U:{if((c|0)!=(f|0)){if(c>>>0>=p>>>0){c=(c>>>0)%(p>>>0)|0}if((c|0)==(m|0)){break U}d=a;break Q}if((f|0)==H[g+8>>2]){break S}}g=H[g>>2];if(g){continue}break}d=a;break Q}if((a|0)!=(z|0)){H[a>>2]=H[g+12>>2];H[i+68>>2]=d;break Q}c=z-b|0;d=c>>2;e=d+1|0;if(e>>>0>=1073741824){break C}a=c>>>1|0;c=c>>>0>=2147483644?1073741823:a>>>0>e>>>0?a:e;if(c){if(c>>>0>=1073741824){break n}a=pa(c<<2)}else{a=0}e=a+(d<<2)|0;H[e>>2]=H[g+12>>2];d=e+4|0;if((b|0)!=(z|0)){while(1){e=e-4|0;z=z-4|0;H[e>>2]=H[z>>2];if((b|0)!=(z|0)){continue}break}}z=a+(c<<2)|0;H[i+72>>2]=z;H[i+68>>2]=d;H[i+64>>2]=e;if(b){oa(b)}}if((d|0)==(e|0)){break u}g=d-4|0;n=H[g>>2];if((n|0)==(q|0)){break u}b=(n|0)==-1;o=H[h+8>>2];if(!b&H[H[o+12>>2]+(n<<2)>>2]!=-1){break u}r=H[o+12>>2];if((q|0)!=-1&H[r+(q<<2)>>2]!=-1){break u}u=N(f,3);f=u+2|0;H[r+(n<<2)>>2]=f;p=f<<2;H[p+r>>2]=n;a=u+1|0;H[r+(q<<2)>>2]=a;c=a<<2;H[c+r>>2]=q;if(b){break B}if((n>>>0)%3|0){m=n-1|0;break x}m=n+2|0;if((m|0)!=-1){break x}a=H[o>>2];b=-1;break w}a=H[h+8>>2];Ka(a+24|0,11424);c=H[h+8>>2];q=N(f,3);r=H[a+28>>2];u=H[a+24>>2];p=r-u|0;o=p>>2;g=o-1|0;H[H[c>>2]+(q<<2)>>2]=g;Ka(c+24|0,11424);m=q+1|0;H[H[c>>2]+(m<<2)>>2]=(H[c+28>>2]-H[c+24>>2]>>2)-1;a=H[h+8>>2];Ka(a+24|0,11424);c=q+2|0;H[H[a>>2]+(c<<2)>>2]=(H[a+28>>2]-H[a+24>>2]>>2)-1;a=H[h+8>>2];n=H[a+24>>2];if(H[a+28>>2]-n>>2>(L|0)){break q}V:{W:{if((r|0)!=(u|0)){H[n+(g<<2)>>2]=q;j=0;if((p|0)==-4){break W}}H[n+(o<<2)>>2]=m;j=o+1|0;if((j|0)==-1){break V}}H[n+(j<<2)>>2]=c}if((d|0)!=(z|0)){H[d>>2]=q;d=d+4|0;H[i+68>>2]=d;break y}m=d-b|0;e=m>>2;c=e+1|0;if(c>>>0>=1073741824){break A}a=m>>>1|0;c=m>>>0>=2147483644?1073741823:a>>>0>c>>>0?a:c;if(c){if(c>>>0>=1073741824){break n}a=pa(c<<2)}else{a=0}e=a+(e<<2)|0;H[e>>2]=q;z=a+(c<<2)|0;a=e+4|0;if((b|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;H[e>>2]=H[d>>2];if((b|0)!=(d|0)){continue}break}}H[i+72>>2]=z;H[i+68>>2]=a;H[i+64>>2]=e;if(!b){break z}oa(b);break z}sa();v()}m=-1;a=H[o>>2];H[a+(u<<2)>>2]=-1;j=-1;break v}sa();v()}d=a;b=e}m=H[h+40>>2];if((m|0)==H[h+36>>2]){break s}c=m-12|0;a=H[c+4>>2];j=(f^-1)+l|0;if(a>>>0>j>>>0){break u}if((a|0)!=(j|0)){break s}f=I[m-4|0];a=H[c>>2];H[h+40>>2]=c;if((a|0)<0){break u}m=d-4|0;g=H[m>>2];H[i+20>>2]=(a^-1)+l;a=i+20|0;H[i+88>>2]=a;Gb(i,i+40|0,a,i+88|0);c=H[i>>2];X:{if(f&1){a=-1;if((g|0)==-1){break X}a=g+1|0;a=(a>>>0)%3|0?a:g-2|0;break X}a=-1;if((g|0)==-1){break X}a=g-1|0;if((g>>>0)%3|0){break X}a=g+2|0}H[c+12>>2]=a;g=H[h+40>>2];if((g|0)==H[h+36>>2]){break s}while(1){c=g-12|0;a=H[c+4>>2];if(a>>>0>j>>>0){break u}if((a|0)!=(j|0)){break s}f=I[g-4|0];a=H[c>>2];H[h+40>>2]=c;if((a|0)<0){break u}g=H[m>>2];H[i+20>>2]=(a^-1)+l;a=i+20|0;H[i+88>>2]=a;Gb(i,i+40|0,a,i+88|0);c=H[i>>2];Y:{if(f&1){a=-1;if((g|0)==-1){break Y}a=g+1|0;a=(a>>>0)%3|0?a:g-2|0;break Y}a=-1;if((g|0)==-1){break Y}a=g-1|0;if((g>>>0)%3|0){break Y}a=g+2|0}H[c+12>>2]=a;g=H[h+40>>2];if((g|0)!=H[h+36>>2]){continue}break}break s}a=H[o>>2];b=H[a+(m<<2)>>2]}m=b;H[(u<<2)+a>>2]=b;b=n+1|0;b=(b>>>0)%3|0?b:n-2|0;j=-1;if((b|0)==-1){break v}j=H[(b<<2)+a>>2]}H[a+c>>2]=j;Z:{if((q|0)==-1){H[a+p>>2]=-1;n=-1;c=-1;break Z}_:{$:{aa:{if((q>>>0)%3|0){b=q-1|0;break aa}b=q+2|0;if((b|0)==-1){break $}}b=H[(b<<2)+a>>2];H[a+p>>2]=b;if((b|0)==-1){break _}H[H[o+24>>2]+(b<<2)>>2]=f;break _}H[a+p>>2]=-1}n=-1;b=q+1|0;b=(b>>>0)%3|0?b:q-2|0;c=-1;if((b|0)==-1){break Z}n=H[(b<<2)+a>>2];c=b}b=H[o+24>>2];p=b+(n<<2)|0;if((m|0)!=-1){H[b+(m<<2)>>2]=H[p>>2]}b=c;while(1){if((b|0)==-1){break t}H[(b<<2)+a>>2]=m;j=b+1|0;b=(j>>>0)%3|0?j:b-2|0;f=-1;ba:{if((b|0)==-1){break ba}j=H[r+(b<<2)>>2];f=-1;if((j|0)==-1){break ba}b=j+1|0;f=(b>>>0)%3|0?b:j-2|0}b=f;if((c|0)!=(b|0)){continue}break}}j=-1;if(!(s&1)){break r}break q}H[p>>2]=-1;ca:{if(A){break ca}if((B|0)!=(D|0)){H[D>>2]=n;D=D+4|0;H[i+28>>2]=D;break ca}f=B-w|0;b=f>>2;c=b+1|0;if(c>>>0>=1073741824){break o}a=f>>>1|0;c=f>>>0>=2147483644?1073741823:a>>>0>c>>>0?a:c;if(c){if(c>>>0>=1073741824){break n}a=pa(c<<2)}else{a=0}b=a+(b<<2)|0;H[b>>2]=n;D=b+4|0;if((w|0)!=(B|0)){while(1){b=b-4|0;B=B-4|0;H[b>>2]=H[B>>2];if((w|0)!=(B|0)){continue}break}}B=a+(c<<2)|0;H[i+32>>2]=B;H[i+28>>2]=D;H[i+24>>2]=b;if(w){oa(w)}w=b}H[g>>2]=u;b=e}s=(k|0)<(l|0);if((k|0)!=(l|0)){continue}break}k=l}j=-1;a=H[h+8>>2];if(H[a+28>>2]-H[a+24>>2]>>2>(L|0)){break q}if((d|0)!=(e|0)){u=h+72|0;m=h+60|0;p=h+312|0;while(1){d=d-4|0;o=H[d>>2];H[i+68>>2]=d;da:{ea:{fa:{if(J[h+270>>1]<=513){if(!I[h+364|0]){break ea}b=H[h+360>>2];a=H[h+352>>2]+(b>>>3|0)|0;if(a>>>0>=K[h+356>>2]){break fa}a=I[a|0];H[h+360>>2]=b+1;if(!(a>>>(b&7)&1)){break fa}break ea}if(Ba(p)){break ea}}ga:{ha:{b=H[h+64>>2];c=H[h+68>>2];if((b|0)==c<<5){if((b+1|0)<0){break ha}if(b>>>0<=1073741822){c=c<<6;b=(b&-32)+32|0;a=b>>>0>>0?c:b}else{a=2147483647}pb(m,a);b=H[h+64>>2]}H[h+64>>2]=b+1;c=H[h+60>>2]+(b>>>3&536870908)|0;a=H[c>>2];P=c,Q=Vj(b)&a,H[P>>2]=Q;b=H[h+76>>2];if((b|0)!=H[h+80>>2]){H[b>>2]=o;H[h+76>>2]=b+4;break da}l=H[u>>2];w=b-l|0;c=w>>2;f=c+1|0;if(f>>>0>=1073741824){break ga}a=w>>>1|0;f=w>>>0>=2147483644?1073741823:a>>>0>f>>>0?a:f;if(f){if(f>>>0>=1073741824){break n}a=pa(f<<2)}else{a=0}g=a+(c<<2)|0;H[g>>2]=o;c=g+4|0;if((b|0)!=(l|0)){while(1){g=g-4|0;b=b-4|0;H[g>>2]=H[b>>2];if((b|0)!=(l|0)){continue}break}}H[h+80>>2]=a+(f<<2);H[h+76>>2]=c;H[h+72>>2]=g;if(!l){break da}oa(l);break da}sa();v()}sa();v()}r=H[h+8>>2];A=H[r>>2];if(((H[r+4>>2]-A>>2>>>0)/3|0)<=(k|0)){j=-1;break q}a=-1;j=-1;b=-1;w=H[r+24>>2];f=-1;ia:{if((o|0)==-1){break ia}e=o+1|0;e=(e>>>0)%3|0?e:o-2|0;f=-1;if((e|0)==-1){break ia}f=H[A+(e<<2)>>2]}l=H[w+(f<<2)>>2];ja:{if((l|0)==-1){g=1;e=-1;break ja}g=1;c=l+1|0;c=(c>>>0)%3|0?c:l-2|0;e=-1;if((c|0)==-1){break ja}g=0;a=c;e=a+1|0;e=(e>>>0)%3|0?e:a-2|0;if((e|0)!=-1){e=H[A+(e<<2)>>2]}else{e=-1}}c=H[(e<<2)+w>>2];if((c|0)!=-1){b=c+1|0;b=(b>>>0)%3|0?b:c-2|0}if((a|0)==(o|0)|(b|0)==(o|0)|((o|0)!=-1&H[H[r+12>>2]+(o<<2)>>2]!=-1|(a|0)==(b|0))){break q}if(!g&H[H[r+12>>2]+(a<<2)>>2]!=-1){break q}g=-1;l=H[r+12>>2];w=-1;ka:{if((b|0)==-1){break ka}if(H[l+(b<<2)>>2]!=-1){break q}c=b+1|0;c=(c>>>0)%3|0?c:b-2|0;w=-1;if((c|0)==-1){break ka}w=H[A+(c<<2)>>2]}c=N(k,3);H[i>>2]=c;H[l+(c<<2)>>2]=o;H[l+(o<<2)>>2]=c;c=H[i>>2]+1|0;H[l+(c<<2)>>2]=a;H[l+(a<<2)>>2]=c;a=H[i>>2]+2|0;H[l+(a<<2)>>2]=b;H[l+(b<<2)>>2]=a;a=H[i>>2];H[A+(a<<2)>>2]=e;j=a+1|0;l=A+(j<<2)|0;H[l>>2]=w;w=a+2|0;c=A+(w<<2)|0;H[c>>2]=f;f=H[h+120>>2];e=j?e:-1;b=f+(e>>>3&536870908)|0;a=H[b>>2];P=b,Q=Vj(e)&a,H[P>>2]=Q;g=(j|0)!=-1?H[l>>2]:g;b=f+(g>>>3&536870908)|0;a=H[b>>2];P=b,Q=Vj(g)&a,H[P>>2]=Q;b=-1;b=(w|0)!=-1?H[c>>2]:b;e=f+(b>>>3&536870908)|0;a=H[e>>2];P=e,Q=Vj(b)&a,H[P>>2]=Q;F[i+88|0]=1;_c(m,i+88|0);Ka(u,i);k=k+1|0;e=H[i+64>>2]}if((d|0)!=(e|0)){continue}break}a=H[h+8>>2]}j=-1;if(((H[a+4>>2]-H[a>>2]>>2>>>0)/3|0)!=(k|0)){break q}j=H[a+28>>2]-H[a+24>>2]>>2;s=H[i+24>>2];c=H[i+28>>2];if((s|0)==(c|0)){break p}while(1){k=H[s>>2];d=H[a+24>>2];b=j-1|0;g=d+(b<<2)|0;if(H[g>>2]==-1){while(1){b=j-2|0;j=j-1|0;g=d+(b<<2)|0;if(H[g>>2]==-1){continue}break}}if(b>>>0>=k>>>0){H[i>>2]=a;g=H[g>>2];F[i+12|0]=1;H[i+8>>2]=g;H[i+4>>2]=g;if((g|0)!=-1){while(1){a=H[H[h+8>>2]>>2]+(g<<2)|0;if(H[a>>2]!=(b|0)){j=-1;break q}H[a>>2]=k;uc(i);g=H[i+8>>2];if((g|0)!=-1){continue}break}a=H[h+8>>2]}d=H[a+24>>2];e=d+(b<<2)|0;if((k|0)!=-1){H[d+(k<<2)>>2]=H[e>>2]}H[e>>2]=-1;f=1<>2];e=d+(k>>>3&536870908)|0;k=d+(b>>>3&536870908)|0;d=1<>2]&d){b=f|H[e>>2]}else{b=H[e>>2]&(f^-1)}H[e>>2]=b;H[k>>2]=H[k>>2]&(d^-1);j=j-1|0}s=s+4|0;if((c|0)!=(s|0)){continue}break}}s=H[i+24>>2]}if(s){oa(s)}a=H[i+48>>2];if(a){while(1){d=H[a>>2];oa(a);a=d;if(a){continue}break}}a=H[i+40>>2];H[i+40>>2]=0;if(a){oa(a)}a=H[i+64>>2];if(a){H[i+68>>2]=a;oa(a)}ca=i+96|0;a=j;break m}sa();v()}wa();v()}e=a;if((a|0)==-1){break l}b=H[C+16>>2];d=b+H[C>>2]|0;a=H[C+8>>2]-b|0;b=H[H[h+4>>2]+32>>2];G[b+38>>1]=J[b+38>>1];H[b>>2]=d;H[b+16>>2]=0;H[b+20>>2]=0;H[b+8>>2]=a;H[b+12>>2]=0;b=H[h+4>>2];a=J[b+36>>1];d=a<<8|a>>>8;if((d&65535)>>>0<=513){b=H[b+32>>2];c=b;a=H[b+16>>2];b=M+H[b+20>>2]|0;a=a+y|0;b=a>>>0>>0?b+1|0:b;H[c+16>>2]=a;H[c+20>>2]=b}la:{if(H[h+216>>2]==H[h+220>>2]){break la}a=H[h+8>>2];b=H[a>>2];a=H[a+4>>2];ma:{if((d&65535)>>>0>=513){if((a|0)==(b|0)){break la}d=0;break ma}if((a|0)==(b|0)){break la}d=0;while(1){if(cd(h,d)){d=d+3|0;a=H[h+8>>2];if(d>>>0>2]-H[a>>2]>>2>>>0){continue}break la}break}break l}while(1){if(bd(h,d)){d=d+3|0;a=H[h+8>>2];if(d>>>0>2]-H[a>>2]>>2>>>0){continue}break la}break}break l}ad(O);d=H[h+216>>2];if((d|0)!=H[h+220>>2]){l=0;while(1){c=N(l,144);Jc((c+d|0)+4|0,H[h+8>>2]);a=H[E>>2];b=a+c|0;d=H[b+132>>2];b=H[b+136>>2];if((d|0)!=(b|0)){while(1){Hc((c+H[E>>2]|0)+4|0,H[d>>2]);d=d+4|0;if((b|0)!=(d|0)){continue}break}a=H[E>>2]}if(!Ic((a+c|0)+4|0)){break l}l=l+1|0;d=H[h+216>>2];if(l>>>0<(H[h+220>>2]-d|0)/144>>>0){continue}break}}a=H[h+8>>2];Hb(h+184|0,H[a+28>>2]-H[a+24>>2]>>2);x=H[h+216>>2];if((x|0)!=H[h+220>>2]){d=0;while(1){a=N(d,144)+x|0;b=H[a+60>>2]-H[a+56>>2]>>2;c=a+104|0;a=H[h+8>>2];a=H[a+28>>2]-H[a+24>>2]>>2;Hb(c,(a|0)<(b|0)?b:a);d=d+1|0;x=H[h+216>>2];if(d>>>0<(H[h+220>>2]-x|0)/144>>>0){continue}break}}x=$c(h,e)}break b}x=0}ca=t- -64|0;return x|0}function Bg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,G=0,J=0,K=0,L=0,M=0,O=0;B=c;c=0;m=ca-96|0;ca=m;l=m+16|0;ra(l,0,76);H[m+92>>2]=-1;H[m+8>>2]=0;H[m>>2]=0;H[m+4>>2]=0;r=ca-16|0;ca=r;H[l+68>>2]=0;H[l+72>>2]=0;H[l>>2]=b;s=ca-16|0;ca=s;u=b;a=H[b+20>>2];a:{if((H[b+24>>2]-a|0)<=0){break a}a=H[a>>2];if((a|0)==-1){break a}c=H[H[u+8>>2]+(a<<2)>>2]}b:{c:{d:{if(!c){a=0;break d}a=H[u+100>>2];e=H[u+96>>2];H[s+8>>2]=0;H[s>>2]=0;H[s+4>>2]=0;f=a-e|0;b=(f|0)/12|0;e:{if((a|0)==(e|0)){break e}if(b>>>0>=357913942){break c}d=pa(f);H[s>>2]=d;H[s+8>>2]=d+N(b,12);a=0;n=d;f=f-12|0;d=(f-((f>>>0)%12|0)|0)+12|0;f=ra(n,0,d);H[s+4>>2]=d+f;if(I[c+84|0]){c=b>>>0<=1?1:b;h=c&1;if(b>>>0>=2){g=c&-2;c=0;while(1){d=N(a,12);b=d+e|0;i=H[b+4>>2];j=H[b>>2];d=d+f|0;H[d+8>>2]=H[b+8>>2];H[d>>2]=j;H[d+4>>2]=i;d=N(a|1,12);b=d+e|0;i=H[b+4>>2];j=H[b>>2];d=d+f|0;H[d+8>>2]=H[b+8>>2];H[d>>2]=j;H[d+4>>2]=i;a=a+2|0;c=c+2|0;if((g|0)!=(c|0)){continue}break}}if(!h){break e}b=N(a,12);a=b+e|0;c=H[a+4>>2];e=H[a>>2];b=b+f|0;H[b+8>>2]=H[a+8>>2];H[b>>2]=e;H[b+4>>2]=c;break e}h=b>>>0<=1?1:b;a=H[c+68>>2];c=0;while(1){d=N(c,12);b=d+e|0;g=H[a+(H[b>>2]<<2)>>2];i=H[a+(H[b+4>>2]<<2)>>2];d=d+f|0;H[d+8>>2]=H[a+(H[b+8>>2]<<2)>>2];H[d+4>>2]=i;H[d>>2]=g;c=c+1|0;if((h|0)!=(c|0)){continue}break}}d=0;E=ca-16|0;ca=E;h=pa(88);$b(h);C=ca-16|0;ca=C;H[h+80>>2]=0;H[h+84>>2]=0;a=H[h+76>>2];H[h+76>>2]=0;if(a){oa(a)}H[h+68>>2]=0;H[h+72>>2]=0;b=h- -64|0;a=H[b>>2];H[b>>2]=0;if(a){oa(a)}g=H[s+4>>2];b=H[s>>2];c=(g-b|0)/12|0;a=N(c,3);f=H[h>>2];e=H[h+4>>2]-f>>2;f:{if(a>>>0>e>>>0){ue(h,a-e|0);g=H[s+4>>2];b=H[s>>2];c=(g-b|0)/12|0;break f}if(a>>>0>=e>>>0){break f}H[h+4>>2]=f+(a<<2)}g:{if((b|0)==(g|0)){break g}e=c>>>0<=1?1:c;g=e&1;a=H[h>>2];if(c>>>0>=2){i=e&-2;c=0;while(1){e=N(d,12);j=e+a|0;f=b+e|0;H[j>>2]=H[f>>2];H[a+(e|4)>>2]=H[f+4>>2];H[j+8>>2]=H[f+8>>2];f=N(d|1,12);e=f+a|0;f=b+f|0;H[e>>2]=H[f>>2];H[e+4>>2]=H[f+4>>2];H[e+8>>2]=H[f+8>>2];d=d+2|0;c=c+2|0;if((i|0)!=(c|0)){continue}break}}if(!g){break g}c=N(d,12);a=c+a|0;b=b+c|0;H[a>>2]=H[b>>2];H[a+4>>2]=H[b+4>>2];H[a+8>>2]=H[b+8>>2]}H[C+12>>2]=-1;a=0;e=0;g=0;f=ca-32|0;ca=f;h:{i:{w=C+12|0;j:{if(!w){break j}c=H[h+4>>2];j=H[h>>2];d=c-j|0;i=d>>2;n=H[h+12>>2];b=H[h+16>>2]-n>>2;k:{if(i>>>0>b>>>0){qb(h+12|0,i-b|0,13652);c=H[h+4>>2];j=H[h>>2];d=c-j|0;i=d>>2;break k}if(b>>>0<=i>>>0){break k}H[h+16>>2]=n+(i<<2)}H[f+24>>2]=0;H[f+16>>2]=0;H[f+20>>2]=0;b=(c|0)==(j|0);if(!b){if((d|0)<0){break i}e=pa(d);H[f+20>>2]=e;H[f+16>>2]=e;H[f+24>>2]=(i<<2)+e}l:{m:{n:{o:{p:{if(d){while(1){i=H[(a<<2)+j>>2];b=H[f+20>>2]-e>>2;q:{if(i>>>0>>0){break q}H[f>>2]=0;d=i+1|0;if(d>>>0>b>>>0){Pa(f+16|0,d-b|0,f);j=H[h>>2];c=H[h+4>>2];e=H[f+16>>2];break q}if(b>>>0<=d>>>0){break q}H[f+20>>2]=(d<<2)+e}b=(i<<2)+e|0;H[b>>2]=H[b>>2]+1;a=a+1|0;d=c-j|0;i=d>>2;if(a>>>0>>0){continue}break}break p}d=0;if(!b){break o}break n}if((c|0)==(j|0)){d=0;break n}if(d>>>0>=2147483645){break m}}d=pa(d<<1);ra(d,255,i<<3)}H[f+8>>2]=0;H[f>>2]=0;H[f+4>>2]=0;b=H[f+20>>2];a=b-e|0;t=a>>2;r:{s:{if((b|0)==(e|0)){break s}if((a|0)<0){break r}q=pa(a);H[f>>2]=q;H[f+8>>2]=(t<<2)+q;b=ra(q,0,a);H[f+4>>2]=b+a;c=t>>>0<=1?1:t;n=c&3;a=0;if(c-1>>>0>=3){o=c&-4;while(1){c=g<<2;H[c+b>>2]=a;x=c|4;a=H[c+e>>2]+a|0;H[x+b>>2]=a;y=c|8;a=a+H[e+x>>2]|0;H[y+b>>2]=a;c=c|12;a=a+H[e+y>>2]|0;H[c+b>>2]=a;a=a+H[c+e>>2]|0;g=g+4|0;p=p+4|0;if((o|0)!=(p|0)){continue}break}}if(!n){break s}while(1){c=g<<2;H[c+b>>2]=a;g=g+1|0;a=H[c+e>>2]+a|0;k=k+1|0;if((n|0)!=(k|0)){continue}break}}if(!i){break l}x=H[h+40>>2];y=H[h+12>>2];n=0;while(1){G=n<<2;a=G+j|0;k=-1;c=n+1|0;b=(c>>>0)%3|0?c:n-2|0;if((b|0)!=-1){k=H[(b<<2)+j>>2]}b=H[a>>2];t:{u:{if(!((n>>>0)%3|0)){p=-1;a=n+2|0;if((a|0)!=-1){p=H[(a<<2)+j>>2]}if(!((b|0)==(k|0)|(b|0)==(p|0))&(k|0)!=(p|0)){break u}x=x+1|0;H[h+40>>2]=x;c=n+3|0;break t}p=H[a-4>>2]}a=p<<2;A=H[a+e>>2];v:{w:{if((A|0)<=0){break w}a=H[a+q>>2];g=0;while(1){o=(a<<3)+d|0;z=H[o>>2];if((z|0)==-1){break w}x:{if((k|0)!=(z|0)){break x}o=H[o+4>>2];if((o|0)!=-1){z=H[(o<<2)+j>>2]}else{z=-1}if((z|0)==(b|0)){break x}while(1){y:{b=a;g=g+1|0;if((A|0)<=(g|0)){break y}a=b+1|0;J=(a<<3)+d|0;z=H[J>>2];K=(b<<3)+d|0;H[K+4>>2]=H[J+4>>2];H[K>>2]=z;if((z|0)!=-1){continue}}break}H[(b<<3)+d>>2]=-1;if((o|0)==-1){break w}H[y+G>>2]=o;H[y+(o<<2)>>2]=n;break v}a=a+1|0;g=g+1|0;if((A|0)!=(g|0)){continue}break}}a=k<<2;k=H[a+e>>2];if((k|0)<=0){break v}a=H[a+q>>2];g=0;while(1){b=(a<<3)+d|0;if(H[b>>2]==-1){H[b>>2]=p;H[b+4>>2]=n;break v}a=a+1|0;g=g+1|0;if((k|0)!=(g|0)){continue}break}}}n=c;if(n>>>0>>0){continue}break}break l}break i}sa();v()}H[w>>2]=t;if(q){oa(q)}if(d){oa(d)}a=H[f+16>>2];if(!a){break j}H[f+20>>2]=a;oa(a)}ca=f+32|0;x=(w|0)!=0;if(x){k=ca-32|0;ca=k;a=H[h>>2];g=H[h+4>>2];H[k+24>>2]=0;H[k+16>>2]=0;H[k+20>>2]=0;if((a|0)==(g|0)){c=g}else{a=g-a|0;if((a|0)<0){break i}a=a>>2;b=(a-1>>>5|0)+1|0;c=pa(b<<2);H[k+24>>2]=b;H[k+20>>2]=0;H[k+16>>2]=c;Mc(k+16|0,a);g=H[h>>2];c=H[h+4>>2]}H[k+8>>2]=0;H[k>>2]=0;while(1){z:{o=0;i=0;if((c|0)==(g|0)){break z}while(1){b=H[k+16>>2];A:{if(H[b+(i>>>3&536870908)>>2]>>>i&1){break A}c=H[k>>2];H[k+4>>2]=c;e=H[h+12>>2];a=i;while(1){B:{f=a+1|0;d=a;a=(f>>>0)%3|0?f:a-2|0;if((a|0)==-1){break B}a=H[e+(a<<2)>>2];if((a|0)==-1){break B}f=a+1|0;a=(f>>>0)%3|0?f:a-2|0;if((i|0)==(a|0)|(a|0)==-1){break B}if(!(H[b+(a>>>3&536870908)>>2]>>>a&1)){continue}}break}j=d;C:{D:{E:{while(1){a=H[k+16>>2]+(j>>>3&536870908)|0;H[a>>2]=H[a>>2]|1<>>0)%3|0?a:j-2|0;g=H[h>>2];y=(j>>>0)%3|0;b=(y?-1:2)+j|0;n=H[k>>2];A=(n|0)==(c|0);F:{if(A){break F}w=H[(f<<2)+g>>2];q=H[h+12>>2];a=n;if((b|0)!=-1){e=q+(b<<2)|0;while(1){G:{if((w|0)!=H[a>>2]){break G}p=H[a+4>>2];t=H[e>>2];if((p|0)==(t|0)){break G}e=b;c=-1;a=-1;if((p|0)==-1){break C}break D}a=a+8|0;if((c|0)!=(a|0)){continue}break}break F}while(1){if((w|0)==H[a>>2]){t=-1;e=-1;p=H[a+4>>2];if((p|0)!=-1){break D}}a=a+8|0;if((c|0)!=(a|0)){continue}break}}b=H[(b<<2)+g>>2];H:{if(H[k+8>>2]!=(c|0)){H[c>>2]=b;H[c+4>>2]=f;c=c+8|0;H[k+4>>2]=c;break H}a=c-n|0;p=a>>3;e=p+1|0;if(e>>>0>=536870912){break i}g=a>>>2|0;g=a>>>0>=2147483640?536870911:e>>>0>>0?g:e;if(g){if(g>>>0>=536870912){break E}e=pa(g<<3)}else{e=0}a=e+(p<<3)|0;H[a>>2]=b;H[a+4>>2]=f;b=a+8|0;if(!A){while(1){c=c-8|0;f=H[c+4>>2];a=a-8|0;H[a>>2]=H[c>>2];H[a+4>>2]=f;if((c|0)!=(n|0)){continue}break}c=H[k>>2]}H[k+8>>2]=e+(g<<3);H[k+4>>2]=b;H[k>>2]=a;if(c){oa(c)}c=b}I:{J:{if(y){a=j-1|0;break J}a=j+2|0;if((a|0)==-1){break I}}a=H[H[h+12>>2]+(a<<2)>>2];if((a|0)==-1){break I}j=a+((a>>>0)%3|0?-1:2)|0;if((d|0)==(j|0)){break I}if((j|0)!=-1){continue}}break}g=H[h>>2];break A}wa();v()}c=H[q+(p<<2)>>2];b=e;a=p}if((t|0)!=-1){H[q+(t<<2)>>2]=-1}if((c|0)!=-1){H[q+(c<<2)>>2]=-1}H[q+(b<<2)>>2]=-1;H[q+(a<<2)>>2]=-1;o=1}i=i+1|0;c=H[h+4>>2];if(i>>>0>2>>>0){continue}break}if(o){continue}}break}a=H[k>>2];if(a){oa(a)}a=H[k+16>>2];if(a){oa(a)}ca=k+32|0;n=0;g=ca-32|0;ca=g;e=H[C+12>>2];H[h+36>>2]=e;p=h+24|0;b=H[h+24>>2];a=H[h+28>>2]-b>>2;K:{L:{if(a>>>0>>0){qb(p,e-a|0,13652);H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;break L}if(a>>>0>e>>>0){H[h+28>>2]=b+(e<<2)}H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;if(!e){break K}}if((e|0)<0){break i}a=(e-1>>>5|0)+1|0;b=pa(a<<2);H[g+24>>2]=a;H[g+20>>2]=0;H[g+16>>2]=b;Mc(g+16|0,e)}a=H[h>>2];b=H[h+4>>2];H[g+8>>2]=0;H[g>>2]=0;H[g+4>>2]=0;M:{if((a|0)==(b|0)){a=b}else{a=b-a|0;if((a|0)<0){break i}a=a>>2;b=(a-1>>>5|0)+1|0;c=pa(b<<2);H[g+8>>2]=b;H[g+4>>2]=0;H[g>>2]=c;Mc(g,a);b=H[h>>2];a=H[h+4>>2]}if(a-b>>>0<12){break M}N:{while(1){q=N(n,3);d=(q<<2)+b|0;f=H[d>>2];c=-1;i=q+1|0;if((i|0)!=-1){c=H[(i<<2)+b>>2]}O:{if((c|0)==(f|0)){break O}i=f;f=H[d+8>>2];if((i|0)==(f|0)|(c|0)==(f|0)){break O}k=0;i=H[g>>2];while(1){f=k+q|0;if(!(H[(f>>>3&536870908)+i>>2]>>>f&1)){a=H[(f<<2)+b>>2];c=1<>2];b=a>>>5|0;i=H[d+(b<<2)>>2];t=c&i;if(t){c=H[h+28>>2];P:{if((c|0)!=H[h+32>>2]){H[c>>2]=-1;H[h+28>>2]=c+4;break P}i=H[p>>2];b=c-i|0;o=b>>2;d=o+1|0;if(d>>>0>=1073741824){break i}j=b>>>1|0;j=b>>>0>=2147483644?1073741823:d>>>0>>0?j:d;if(j){if(j>>>0>=1073741824){break N}b=pa(j<<2)}else{b=0}d=b+(o<<2)|0;H[d>>2]=-1;o=d+4|0;if((c|0)!=(i|0)){while(1){d=d-4|0;c=c-4|0;H[d>>2]=H[c>>2];if((c|0)!=(i|0)){continue}break}}H[h+32>>2]=b+(j<<2);H[h+28>>2]=o;H[h+24>>2]=d;if(!i){break P}oa(i)}c=H[h+52>>2];Q:{if((c|0)!=H[h+56>>2]){H[c>>2]=a;H[h+52>>2]=c+4;break Q}i=H[h+48>>2];b=c-i|0;o=b>>2;d=o+1|0;if(d>>>0>=1073741824){break i}j=b>>>1|0;j=b>>>0>=2147483644?1073741823:d>>>0>>0?j:d;if(j){if(j>>>0>=1073741824){break N}b=pa(j<<2)}else{b=0}d=b+(o<<2)|0;H[d>>2]=a;a=d+4|0;if((c|0)!=(i|0)){while(1){d=d-4|0;c=c-4|0;H[d>>2]=H[c>>2];if((c|0)!=(i|0)){continue}break}}H[h+56>>2]=b+(j<<2);H[h+52>>2]=a;H[h+48>>2]=d;if(!i){break Q}oa(i)}c=H[g+20>>2];a=H[g+24>>2];if((c|0)==a<<5){if((c+1|0)<0){break i}b=g+16|0;if(c>>>0<=1073741822){a=a<<6;c=(c&-32)+32|0;a=a>>>0>c>>>0?a:c}else{a=2147483647}pb(b,a);c=H[g+20>>2]}H[g+20>>2]=c+1;d=H[g+16>>2];a=d+(c>>>3&536870908)|0;b=H[a>>2];M=a,O=Vj(c)&b,H[M>>2]=O;c=1<>>5|0;i=H[(b<<2)+d>>2];a=e;e=a+1|0}H[(b<<2)+d>>2]=c|i;o=H[h+24>>2]+(a<<2)|0;j=H[h+12>>2];b=H[h>>2];i=H[g>>2];c=f;R:{S:{T:{while(1){if((c|0)==-1){break T}d=(c>>>3&536870908)+i|0;H[d>>2]=H[d>>2]|1<>2]=c;if(t){H[(c<<2)+b>>2]=a}w=c+1|0;c=(w>>>0)%3|0?w:c-2|0;d=-1;U:{if((c|0)==-1){break U}c=H[j+(c<<2)>>2];d=-1;if((c|0)==-1){break U}d=c+1|0;d=(d>>>0)%3|0?d:c-2|0}c=d;if((f|0)!=(c|0)){continue}break}if((f|0)!=-1){break R}c=1;break S}if((f>>>0)%3|0){c=f-1|0;break S}c=f+2|0;if((c|0)==-1){break R}}c=H[j+(c<<2)>>2];if((c|0)==-1){break R}V:{if((c>>>0)%3|0){c=c-1|0;break V}c=c+2|0;if((c|0)==-1){break R}}f=H[h+12>>2];b=H[h>>2];while(1){d=(c>>>3&536870908)+i|0;H[d>>2]=H[d>>2]|1<>2]=a}W:{if((c>>>0)%3|0){c=c-1|0;break W}c=c+2|0;if((c|0)==-1){break R}}c=H[f+(c<<2)>>2];if((c|0)==-1){break R}c=c+((c>>>0)%3|0?-1:2)|0;if((c|0)!=-1){continue}break}}}k=k+1|0;if((k|0)!=3){continue}break}b=H[h>>2];a=H[h+4>>2]}n=n+1|0;if(n>>>0<(a-b>>2>>>0)/3>>>0){continue}break}break M}wa();v()}c=0;H[h+44>>2]=0;a=H[g+16>>2];b=H[g+20>>2];if(b){e=b&31;b=(b>>>3&536870908)+a|0;d=a;i=0;while(1){if(!(H[d>>2]>>>c&1)){i=i+1|0;H[h+44>>2]=i}f=(c|0)==31;c=f?0:c+1|0;d=(f<<2)+d|0;if((b|0)!=(d|0)|(c|0)!=(e|0)){continue}break}}b=H[g>>2];if(b){oa(b);a=H[g+16>>2]}if(a){oa(a)}ca=g+32|0}ca=C+16|0;if(!x){H[E+8>>2]=0;cb(h);h=0}ca=E+16|0;a=h;break h}sa();v()}b=H[s>>2];if(!b){break d}H[s+4>>2]=b;oa(b)}ca=s+16|0;break b}sa();v()}c=H[l+4>>2];b=a;H[l+4>>2]=a;if(c){cb(c);b=H[l+4>>2]}X:{if(!b){break X}a=H[u+100>>2];c=H[u+96>>2];F[r+12|0]=0;Oa(l+56|0,(a-c|0)/12|0,r+12|0);a=H[u+100>>2];c=H[u+96>>2];if((a|0)==(c|0)){break X}while(1){if(!(H[H[l+56>>2]+(D>>>3&536870908)>>2]>>>D&1)){a=N(D,3);Gc(l,0,a);c=H[l+8>>2];e=H[l+12>>2];Gc(l,1,a+1|0);f=H[l+20>>2];d=H[l+24>>2];Gc(l,2,a+2|0);n=(c|0)==(e|0)?-1:0;a=d-f>>2;c=e-c>>2;e=a>>>0>c>>>0;c=H[l+36>>2]-H[l+32>>2]>>2>>>0>(e?a:c)>>>0?2:e?1:n;Y:{if(H[l+68>>2]<=0){break Y}H[r+12>>2]=H[l+76>>2];H[r+8>>2]=m;bb(r+8|0,r+12|0);a=H[((c<<2)+l|0)+44>>2];if((a|0)<0){a=-1}else{e=(a>>>0)/3|0;a=H[(H[H[l>>2]+96>>2]+N(e,12)|0)+(a-N(e,3)<<2)>>2]}H[r+12>>2]=a;H[r+8>>2]=m;bb(r+8|0,r+12|0);e=H[l+72>>2];H[l+72>>2]=e+2;if(!(e&1)){break Y}H[r+12>>2]=a;H[r+8>>2]=m;bb(r+8|0,r+12|0);H[l+72>>2]=H[l+72>>2]+1}d=0;e=ca-16|0;ca=e;H[l+68>>2]=H[l+68>>2]+1;a=N(c,12)+l|0;a=H[a+12>>2]-H[a+8>>2]|0;if((a|0)>0){a=a>>>2|0;h=a>>>0<=1?1:a;c=H[((c<<2)+l|0)+44>>2];while(1){a=c;f=(a>>>0)/3|0;c=(a|0)==-1;g=c?-1:f;i=H[l+56>>2]+(g>>>3&536870908)|0;H[i>>2]=H[i>>2]|1<>2]=H[l+72>>2]+1;Z:{_:{$:{aa:{ba:{if(!d){ca:{if((a|0)>=0){H[e+12>>2]=H[(H[H[l>>2]+96>>2]+N(f,12)|0)+((a>>>0)%3<<2)>>2];H[e+8>>2]=m;bb(e+8|0,e+12|0);break ca}H[e+12>>2]=-1;H[e+8>>2]=m;bb(e+8|0,e+12|0);if(c){break ba}}c=-1;f=a+1|0;f=(f>>>0)%3|0?f:a-2|0;if((f|0)>=0){g=(f>>>0)/3|0;f=H[(H[H[l>>2]+96>>2]+N(g,12)|0)+(f-N(g,3)<<2)>>2]}else{f=-1}H[e+12>>2]=f;H[e+8>>2]=m;bb(e+8|0,e+12|0);f=((a>>>0)%3|0?-1:2)+a|0;if((f|0)<0){break aa}c=(f>>>0)/3|0;c=H[(H[H[l>>2]+96>>2]+N(c,12)|0)+(f-N(c,3)<<2)>>2];break aa}c=(a|0)<0?-1:H[(H[H[l>>2]+96>>2]+N(f,12)|0)+((a>>>0)%3<<2)>>2];H[l+76>>2]=c;H[e+12>>2]=c;H[e+8>>2]=m;bb(e+8|0,e+12|0);if(d&1){c=-1;if((a|0)==-1){break Z}if((N(f,3)|0)!=(a|0)){a=a-1|0;break _}a=a+2|0;break $}c=-1;if((a|0)==-1){break Z}c=a+1|0;a=(c>>>0)%3|0?c:a-2|0;break $}c=-1;H[e+12>>2]=-1;H[e+8>>2]=m;bb(e+8|0,e+12|0)}H[l+76>>2]=c;H[e+12>>2]=c;H[e+8>>2]=m;bb(e+8|0,e+12|0)}c=-1;if((a|0)==-1){break Z}}c=H[H[H[l+4>>2]+12>>2]+(a<<2)>>2]}d=d+1|0;if((h|0)!=(d|0)){continue}break}}ca=e+16|0;c=H[u+96>>2];a=H[u+100>>2]}D=D+1|0;if(D>>>0<(a-c|0)/12>>>0){continue}break}}ca=r+16|0;da:{if(b){a=H[B>>2];if(a){H[B+4>>2]=a;oa(a)}H[B>>2]=H[m>>2];H[B+4>>2]=H[m+4>>2];H[B+8>>2]=H[m+8>>2];L=H[m+84>>2];break da}a=H[m>>2];if(!a){break da}H[m+4>>2]=a;oa(a)}a=H[m+72>>2];if(a){oa(a)}a=H[m+48>>2];if(a){H[m+52>>2]=a;oa(a)}a=H[m+36>>2];if(a){H[m+40>>2]=a;oa(a)}a=H[m+24>>2];if(a){H[m+28>>2]=a;oa(a)}a=H[m+20>>2];H[m+20>>2]=0;if(a){cb(a)}ca=m+96|0;return L|0}function qg(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;i=b;a=0;b=0;a:{b:{switch(d-1|0){case 0:j=H[i+80>>2];h=I[c+24|0];c:{if((N(j,h)|0)!=(e|0)){break c}d=H[c+28>>2]!=1;b=I[c+84|0];if(!(d|!b)){qa(f,H[H[c>>2]>>2]+H[c+48>>2]|0,e);b=1;break c}if(h){a=pa(h);ra(a,0,h)}d:{if(!j){b=1;break d}if(!d){if(h){d=0;e=0;while(1){i=d+f|0;k=H[H[c>>2]>>2];m=H[c+48>>2];g=H[c+40>>2];b=Rj(g,H[c+44>>2],I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],0);n=b;b=b+m|0;qa(i,qa(a,b+k|0,g),h);d=d+h|0;b=1;e=e+1|0;if((j|0)!=(e|0)){continue}break}break d}if(b){b=1;h=H[c>>2];e=H[c+48>>2];f=H[c+40>>2];i=H[c+44>>2];if((j|0)!=1){g=j&-2;c=0;d=0;while(1){k=H[h>>2];m=Rj(f,i,c,0)+e|0;k=qa(a,k+m|0,f);m=H[h>>2];n=Rj(f,i,c|1,0)+e|0;qa(k,m+n|0,f);c=c+2|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}g=c}if(!(j&1)){break d}c=H[h>>2];d=Rj(g,0,f,i)+e|0;qa(a,c+d|0,f);break d}b=1;h=H[c>>2];e=H[c+48>>2];g=H[c+68>>2];f=H[c+40>>2];i=H[c+44>>2];c=0;if((j|0)!=1){k=j&-2;d=0;while(1){m=H[h>>2];n=c<<2;l=Rj(f,i,H[n+g>>2],0)+e|0;m=qa(a,m+l|0,f);l=H[h>>2];n=Rj(f,i,H[g+(n|4)>>2],0)+e|0;qa(m,l+n|0,f);c=c+2|0;d=d+2|0;if((k|0)!=(d|0)){continue}break}}if(!(j&1)){break d}d=H[h>>2];c=Rj(f,i,H[g+(c<<2)>>2],0)+e|0;qa(a,c+d|0,f);break d}b=0;if(!h){d=0;while(1){if(!ic(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],a)){break d}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break d}d=0;e=0;while(1){if(!ic(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],a)){break d}qa(d+f|0,a,h);d=d+h|0;e=e+1|0;b=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}}if(!a){break c}oa(a)}break a;case 2:n=I[c+24|0];l=n<<1;j=H[i+80>>2];e:{if((N(l,j)|0)!=(e|0)){break e}i=H[c+28>>2]!=3;d=I[c+84|0];if(!(i|!d)){qa(f,H[H[c>>2]>>2]+H[c+48>>2]|0,e);a=1;break e}f:{if(!n){e=0;break f}e=pa(l);ra(e,0,l)}g:{if(!j){a=1;break g}if(!i){o=H[c+68>>2];k=H[c>>2];b=H[c+48>>2];i=H[c+40>>2];m=H[c+44>>2];if(n){if(!d){c=0;d=0;while(1){a=1;g=H[k>>2];p=Rj(i,m,H[o+(d<<2)>>2],0)+b|0;qa((c<<1)+f|0,qa(e,g+p|0,i),l);c=c+n|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break g}c=0;while(1){a=1;o=H[k>>2];p=Rj(g,h,i,m)+b|0;qa((c<<1)+f|0,qa(e,o+p|0,i),l);c=c+n|0;d=h;g=g+1|0;d=g?d:d+1|0;h=d;if((j|0)!=(g|0)|d){continue}break}break g}if(!d){a=1;c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=H[k>>2];g=c<<2;n=Rj(i,m,H[g+o>>2],0)+b|0;h=qa(e,h+n|0,i);n=H[k>>2];g=Rj(i,m,H[o+(g|4)>>2],0)+b|0;qa(h,g+n|0,i);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break g}d=H[k>>2];b=Rj(i,m,H[o+(c<<2)>>2],0)+b|0;qa(e,b+d|0,i);break g}n=j&1;a=1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){d=H[k>>2];l=Rj(g,h,i,m)+b|0;d=qa(e,d+l|0,i);l=H[k>>2];o=Rj(i,m,g|1,h)+b|0;qa(d,l+o|0,i);g=g+2|0;h=g>>>0<2?h+1|0:h;f=f+2|0;d=f>>>0<2?c+1|0:c;c=d;if((f|0)!=(j|0)|c){continue}break}}if(!n){break g}c=H[k>>2];b=Rj(g,h,i,m)+b|0;qa(e,b+c|0,i);break g}if(!n){d=0;while(1){if(!gc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break g}d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break g}d=0;while(1){if(!gc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break g}qa((b<<1)+f|0,e,l);b=b+n|0;d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break e}oa(e)}b=a;break a;case 4:l=I[c+24|0];o=l<<2;j=H[i+80>>2];h:{if((N(o,j)|0)!=(e|0)){break h}i=H[c+28>>2]!=5;d=I[c+84|0];if(!(i|!d)){qa(f,H[H[c>>2]>>2]+H[c+48>>2]|0,e);b=1;break h}i:{if(!l){e=0;break i}e=pa(o);ra(e,0,o)}b=1;j:{if(!j){break j}if(!i){a=H[c+68>>2];m=H[c>>2];i=H[c+48>>2];k=H[c+40>>2];n=H[c+44>>2];if(l){if(!d){c=0;d=0;while(1){g=H[m>>2];p=Rj(k,n,H[a+(d<<2)>>2],0)+i|0;qa((c<<2)+f|0,qa(e,g+p|0,k),o);c=c+l|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break j}c=0;while(1){d=H[m>>2];p=Rj(g,h,k,n)+i|0;qa((c<<2)+f|0,qa(e,d+p|0,k),o);c=c+l|0;g=g+1|0;a=g?h:h+1|0;h=a;if((j|0)!=(g|0)|h){continue}break}break j}if(!d){c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=H[m>>2];g=c<<2;l=Rj(k,n,H[g+a>>2],0)+i|0;h=qa(e,h+l|0,k);l=H[m>>2];g=Rj(k,n,H[a+(g|4)>>2],0)+i|0;qa(h,g+l|0,k);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break j}d=H[m>>2];a=Rj(k,n,H[a+(c<<2)>>2],0)+i|0;qa(e,a+d|0,k);break j}l=j&1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){a=H[m>>2];d=Rj(g,h,k,n)+i|0;a=qa(e,a+d|0,k);d=H[m>>2];o=Rj(k,n,g|1,h)+i|0;qa(a,d+o|0,k);d=h;g=g+2|0;h=g>>>0<2?d+1|0:d;f=f+2|0;a=f>>>0<2?c+1|0:c;c=a;if((f|0)!=(j|0)|c){continue}break}}if(!l){break j}a=H[m>>2];c=Rj(g,h,k,n)+i|0;qa(e,a+c|0,k);break j}b=0;if(!l){d=0;while(1){if(!ec(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break j}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break j}d=0;while(1){if(!ec(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break j}qa((a<<2)+f|0,e,o);a=a+l|0;d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break h}oa(e)}break a;case 1:j=H[i+80>>2];h=I[c+24|0];k:{if((N(j,h)|0)!=(e|0)){break k}d=H[c+28>>2]!=2;b=I[c+84|0];if(!(d|!b)){qa(f,H[H[c>>2]>>2]+H[c+48>>2]|0,e);b=1;break k}if(h){a=pa(h);ra(a,0,h)}l:{if(!j){b=1;break l}if(!d){if(h){d=0;e=0;while(1){i=d+f|0;k=H[H[c>>2]>>2];m=H[c+48>>2];g=H[c+40>>2];b=Rj(g,H[c+44>>2],I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],0);n=b;b=b+m|0;qa(i,qa(a,b+k|0,g),h);d=d+h|0;b=1;e=e+1|0;if((j|0)!=(e|0)){continue}break}break l}if(b){b=1;h=H[c>>2];e=H[c+48>>2];f=H[c+40>>2];i=H[c+44>>2];if((j|0)!=1){g=j&-2;c=0;d=0;while(1){k=H[h>>2];m=Rj(f,i,c,0)+e|0;k=qa(a,k+m|0,f);m=H[h>>2];n=Rj(f,i,c|1,0)+e|0;qa(k,m+n|0,f);c=c+2|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}g=c}if(!(j&1)){break l}c=H[h>>2];d=Rj(g,0,f,i)+e|0;qa(a,c+d|0,f);break l}b=1;h=H[c>>2];e=H[c+48>>2];g=H[c+68>>2];f=H[c+40>>2];i=H[c+44>>2];c=0;if((j|0)!=1){k=j&-2;d=0;while(1){m=H[h>>2];n=c<<2;l=Rj(f,i,H[n+g>>2],0)+e|0;m=qa(a,m+l|0,f);l=H[h>>2];n=Rj(f,i,H[g+(n|4)>>2],0)+e|0;qa(m,l+n|0,f);c=c+2|0;d=d+2|0;if((k|0)!=(d|0)){continue}break}}if(!(j&1)){break l}d=H[h>>2];c=Rj(f,i,H[g+(c<<2)>>2],0)+e|0;qa(a,c+d|0,f);break l}b=0;if(!h){d=0;while(1){if(!hc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],a)){break l}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break l}d=0;e=0;while(1){if(!hc(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],a)){break l}qa(d+f|0,a,h);d=d+h|0;e=e+1|0;b=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}}if(!a){break k}oa(a)}break a;case 3:n=I[c+24|0];l=n<<1;j=H[i+80>>2];m:{if((N(l,j)|0)!=(e|0)){break m}i=H[c+28>>2]!=4;d=I[c+84|0];if(!(i|!d)){qa(f,H[H[c>>2]>>2]+H[c+48>>2]|0,e);a=1;break m}n:{if(!n){e=0;break n}e=pa(l);ra(e,0,l)}o:{if(!j){a=1;break o}if(!i){o=H[c+68>>2];k=H[c>>2];b=H[c+48>>2];i=H[c+40>>2];m=H[c+44>>2];if(n){if(!d){c=0;d=0;while(1){a=1;g=H[k>>2];p=Rj(i,m,H[o+(d<<2)>>2],0)+b|0;qa((c<<1)+f|0,qa(e,g+p|0,i),l);c=c+n|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break o}c=0;while(1){a=1;o=H[k>>2];p=Rj(g,h,i,m)+b|0;qa((c<<1)+f|0,qa(e,o+p|0,i),l);c=c+n|0;d=h;g=g+1|0;d=g?d:d+1|0;h=d;if((j|0)!=(g|0)|d){continue}break}break o}if(!d){a=1;c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=H[k>>2];g=c<<2;n=Rj(i,m,H[g+o>>2],0)+b|0;h=qa(e,h+n|0,i);n=H[k>>2];g=Rj(i,m,H[o+(g|4)>>2],0)+b|0;qa(h,g+n|0,i);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break o}d=H[k>>2];b=Rj(i,m,H[o+(c<<2)>>2],0)+b|0;qa(e,b+d|0,i);break o}n=j&1;a=1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){d=H[k>>2];l=Rj(g,h,i,m)+b|0;d=qa(e,d+l|0,i);l=H[k>>2];o=Rj(i,m,g|1,h)+b|0;qa(d,l+o|0,i);g=g+2|0;h=g>>>0<2?h+1|0:h;f=f+2|0;d=f>>>0<2?c+1|0:c;c=d;if((f|0)!=(j|0)|c){continue}break}}if(!n){break o}c=H[k>>2];b=Rj(g,h,i,m)+b|0;qa(e,b+c|0,i);break o}if(!n){d=0;while(1){if(!fc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break o}d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break o}d=0;while(1){if(!fc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break o}qa((b<<1)+f|0,e,l);b=b+n|0;d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break m}oa(e)}b=a;break a;case 5:l=I[c+24|0];o=l<<2;j=H[i+80>>2];p:{if((N(o,j)|0)!=(e|0)){break p}i=H[c+28>>2]!=6;d=I[c+84|0];if(!(i|!d)){qa(f,H[H[c>>2]>>2]+H[c+48>>2]|0,e);b=1;break p}q:{if(!l){e=0;break q}e=pa(o);ra(e,0,o)}b=1;r:{if(!j){break r}if(!i){a=H[c+68>>2];m=H[c>>2];i=H[c+48>>2];k=H[c+40>>2];n=H[c+44>>2];if(l){if(!d){c=0;d=0;while(1){g=H[m>>2];p=Rj(k,n,H[a+(d<<2)>>2],0)+i|0;qa((c<<2)+f|0,qa(e,g+p|0,k),o);c=c+l|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break r}c=0;while(1){d=H[m>>2];p=Rj(g,h,k,n)+i|0;qa((c<<2)+f|0,qa(e,d+p|0,k),o);c=c+l|0;g=g+1|0;a=g?h:h+1|0;h=a;if((j|0)!=(g|0)|h){continue}break}break r}if(!d){c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=H[m>>2];g=c<<2;l=Rj(k,n,H[g+a>>2],0)+i|0;h=qa(e,h+l|0,k);l=H[m>>2];g=Rj(k,n,H[a+(g|4)>>2],0)+i|0;qa(h,g+l|0,k);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break r}d=H[m>>2];a=Rj(k,n,H[a+(c<<2)>>2],0)+i|0;qa(e,a+d|0,k);break r}l=j&1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){a=H[m>>2];d=Rj(g,h,k,n)+i|0;a=qa(e,a+d|0,k);d=H[m>>2];o=Rj(k,n,g|1,h)+i|0;qa(a,d+o|0,k);d=h;g=g+2|0;h=g>>>0<2?d+1|0:d;f=f+2|0;a=f>>>0<2?c+1|0:c;c=a;if((f|0)!=(j|0)|c){continue}break}}if(!l){break r}a=H[m>>2];c=Rj(g,h,k,n)+i|0;qa(e,a+c|0,k);break r}b=0;if(!l){d=0;while(1){if(!dc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break r}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break r}d=0;while(1){if(!dc(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],e)){break r}qa((a<<2)+f|0,e,o);a=a+l|0;d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break p}oa(e)}break a;case 8:p=I[c+24|0];q=p<<2;k=H[i+80>>2];s:{if((N(q,k)|0)!=(e|0)){break s}i=H[c+28>>2];t:{if(!p){break t}a=pa(q);d=a;m=q-4|0;l=(m>>>2|0)+1&7;if(l){e=0;while(1){H[d>>2]=-1073741824;d=d+4|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}if(m>>>0<28){break t}e=(p<<2)+a|0;while(1){H[d+24>>2]=-1073741824;H[d+28>>2]=-1073741824;H[d+16>>2]=-1073741824;H[d+20>>2]=-1073741824;H[d+8>>2]=-1073741824;H[d+12>>2]=-1073741824;H[d>>2]=-1073741824;H[d+4>>2]=-1073741824;d=d+32|0;if((e|0)!=(d|0)){continue}break}}u:{if(!k){b=1;break u}if((i|0)==9){r=H[c+68>>2];l=H[c>>2];i=H[c+48>>2];s=I[c+84|0];m=H[c+44>>2];c=H[c+40>>2];o=c;if(p){e=0;d=0;while(1){h=(e<<2)+f|0;g=H[l>>2];b=Rj(c,m,s?d:H[r+(d<<2)>>2],0)+i|0;qa(h,qa(a,b+g|0,o),q);e=e+p|0;b=1;d=d+1|0;if((k|0)!=(d|0)){continue}break}break u}if(!s){b=1;d=0;if((k|0)!=1){f=k&-2;e=0;while(1){h=H[l>>2];g=d<<2;j=Rj(c,m,H[g+r>>2],0)+i|0;h=qa(a,h+j|0,o);j=H[l>>2];g=Rj(c,m,H[r+(g|4)>>2],0)+i|0;qa(h,j+g|0,o);d=d+2|0;e=e+2|0;if((f|0)!=(e|0)){continue}break}}if(!(k&1)){break u}e=H[l>>2];c=Rj(c,m,H[r+(d<<2)>>2],0)+i|0;qa(a,c+e|0,o);break u}f=k&1;b=1;if((k|0)!=1){k=k&-2;while(1){d=H[l>>2];e=Rj(g,h,c,m)+i|0;d=qa(a,d+e|0,o);e=H[l>>2];p=Rj(c,m,g|1,h)+i|0;qa(d,e+p|0,o);g=g+2|0;h=g>>>0<2?h+1|0:h;d=j;e=n+2|0;d=e>>>0<2?d+1|0:d;n=e;j=d;if((e|0)!=(k|0)|d){continue}break}}if(!f){break u}d=H[l>>2];c=Rj(g,h,c,m)+i|0;qa(a,c+d|0,o);break u}if(!p){d=0;while(1){if(!Va(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],a)){break u}d=d+1|0;b=k>>>0<=d>>>0;if((d|0)!=(k|0)){continue}break}break u}e=0;d=0;while(1){if(!Va(c,I[c+84|0]?d:H[H[c+68>>2]+(d<<2)>>2],F[c+24|0],a)){break u}qa((e<<2)+f|0,a,q);e=e+p|0;d=d+1|0;b=k>>>0<=d>>>0;if((d|0)!=(k|0)){continue}break}}if(!a){break s}oa(a)}a=b;break;default:break b}}b=a}return b|0}function ef(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;i=ca-48|0;ca=i;a:{b:{if((c|0)!=1){break b}c=H[a+4>>2];g=H[a+12>>2];H[i+40>>2]=0;a=i;H[a+32>>2]=0;H[a+36>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0;e=a+8|0;c:{if((b|0)==-2){break c}l=H[H[H[c+4>>2]+8>>2]+(g<<2)>>2];if((ea[H[H[c>>2]+8>>2]](c)|0)==1){a=J[c+36>>1];j=(a<<8|a>>>8)&65535;a=0;h=ca-32|0;ca=h;d=H[H[H[c+4>>2]+8>>2]+(g<<2)>>2];d:{if((ea[H[H[c>>2]+8>>2]](c)|0)!=1|b-1>>>0>5){break d}k=ea[H[H[c>>2]+36>>2]](c)|0;f=ea[H[H[c>>2]+44>>2]](c,g)|0;if(!k|!f){break d}a=ea[H[H[c>>2]+40>>2]](c,g)|0;if(a){c=H[c+44>>2];H[h+12>>2]=a;H[h+8>>2]=c;H[h+20>>2]=f;H[h+16>>2]=f+12;c=h+8|0;a=0;e:{f:{switch(b-1|0){case 0:a=pa(60);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a>>2]=2564;break e;case 1:a=pa(60);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a>>2]=3328;break e;case 3:a=pa(112);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a+60>>2]=0;H[a+64>>2]=0;H[a>>2]=3564;H[a+68>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+88>>2]=0;H[a+92>>2]=0;H[a+96>>2]=0;H[a+100>>2]=0;H[a+104>>2]=0;H[a+108>>2]=0;break e;case 2:a=pa(92);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a+60>>2]=0;H[a+64>>2]=0;H[a>>2]=3812;H[a+68>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+88>>2]=j;break e;case 4:a=pa(104);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a+84>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+60>>2]=0;H[a+64>>2]=0;H[a>>2]=4040;b=H[c+4>>2];H[a+88>>2]=H[c>>2];H[a+92>>2]=b;b=H[c+12>>2];H[a+96>>2]=H[c+8>>2];H[a+100>>2]=b;break e;case 5:break f;default:break e}}a=pa(128);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;g:{b=H[e+28>>2];d=H[e+24>>2];if((b|0)!=(d|0)){d=b-d|0;if((d|0)<0){break a}b=pa(d);H[a+36>>2]=b;H[a+32>>2]=b;H[a+40>>2]=(d&-4)+b;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}}H[a+36>>2]=b}H[a>>2]=3216;b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;b=a- -64|0;H[b>>2]=0;H[b+4>>2]=0;H[a+60>>2]=4904;H[a>>2]=4276;b=H[c+4>>2];H[a+72>>2]=H[c>>2];H[a+76>>2]=b;b=H[c+12>>2];H[a+80>>2]=H[c+8>>2];H[a+84>>2]=b;H[a+104>>2]=1065353216;H[a+108>>2]=-1;H[a+96>>2]=-1;H[a+100>>2]=-1;H[a+88>>2]=1;H[a+92>>2]=-1;H[a+60>>2]=4512;H[a+112>>2]=0;H[a+116>>2]=0;F[a+117|0]=0;F[a+118|0]=0;F[a+119|0]=0;F[a+120|0]=0;F[a+121|0]=0;F[a+122|0]=0;F[a+123|0]=0;F[a+124|0]=0;break g}}break d}a=H[c+44>>2];H[h+12>>2]=k;H[h+8>>2]=a;H[h+20>>2]=f;H[h+16>>2]=f+12;c=h+8|0;a=0;h:{i:{switch(b-1|0){case 0:a=pa(60);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a>>2]=4932;break h;case 1:a=pa(60);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a>>2]=5356;break h;case 3:a=pa(112);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a+60>>2]=0;H[a+64>>2]=0;H[a>>2]=5580;H[a+68>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+88>>2]=0;H[a+92>>2]=0;H[a+96>>2]=0;H[a+100>>2]=0;H[a+104>>2]=0;H[a+108>>2]=0;break h;case 2:a=pa(92);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a+60>>2]=0;H[a+64>>2]=0;H[a>>2]=5816;H[a+68>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+88>>2]=j;break h;case 4:a=pa(104);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){g=f-d|0;if((g|0)<0){break a}b=pa(g);H[a+32>>2]=b;H[a+40>>2]=(g&-4)+b;while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}H[a+36>>2]=b}b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;H[a+84>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+60>>2]=0;H[a+64>>2]=0;H[a>>2]=6032;b=H[c+4>>2];H[a+88>>2]=H[c>>2];H[a+92>>2]=b;b=H[c+12>>2];H[a+96>>2]=H[c+8>>2];H[a+100>>2]=b;break h;case 5:break i;default:break h}}a=pa(128);H[a+4>>2]=d;H[a>>2]=3272;b=H[e+4>>2];H[a+8>>2]=H[e>>2];H[a+12>>2]=b;b=H[e+12>>2];H[a+16>>2]=H[e+8>>2];H[a+20>>2]=b;b=H[e+20>>2];H[a+24>>2]=H[e+16>>2];H[a+28>>2]=b;H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;j:{b=H[e+28>>2];d=H[e+24>>2];if((b|0)!=(d|0)){d=b-d|0;if((d|0)<0){break a}b=pa(d);H[a+36>>2]=b;H[a+32>>2]=b;H[a+40>>2]=(d&-4)+b;d=H[e+24>>2];f=H[e+28>>2];if((d|0)!=(f|0)){while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((f|0)!=(d|0)){continue}break}}H[a+36>>2]=b}H[a>>2]=5300;b=H[c+4>>2];H[a+44>>2]=H[c>>2];H[a+48>>2]=b;b=H[c+12>>2];H[a+52>>2]=H[c+8>>2];H[a+56>>2]=b;b=a- -64|0;H[b>>2]=0;H[b+4>>2]=0;H[a+60>>2]=6840;H[a>>2]=6256;b=H[c+4>>2];H[a+72>>2]=H[c>>2];H[a+76>>2]=b;b=H[c+12>>2];H[a+80>>2]=H[c+8>>2];H[a+84>>2]=b;H[a+104>>2]=1065353216;H[a+108>>2]=-1;H[a+96>>2]=-1;H[a+100>>2]=-1;H[a+88>>2]=1;H[a+92>>2]=-1;H[a+60>>2]=6476;H[a+112>>2]=0;H[a+116>>2]=0;F[a+117|0]=0;F[a+118|0]=0;F[a+119|0]=0;F[a+120|0]=0;F[a+121|0]=0;F[a+122|0]=0;F[a+123|0]=0;F[a+124|0]=0;break j}}}ca=h+32|0;d=a;if(a){break c}}d=pa(44);H[d+4>>2]=l;H[d>>2]=3272;a=H[e+4>>2];H[d+8>>2]=H[e>>2];H[d+12>>2]=a;a=H[e+12>>2];H[d+16>>2]=H[e+8>>2];H[d+20>>2]=a;a=H[e+20>>2];H[d+24>>2]=H[e+16>>2];H[d+28>>2]=a;H[d+40>>2]=0;H[d+32>>2]=0;H[d+36>>2]=0;c=H[e+24>>2];a=H[e+28>>2];if((c|0)!=(a|0)){b=a-c|0;if((b|0)<0){break a}e=pa(b);H[d+32>>2]=e;H[d+40>>2]=(b&-4)+e;while(1){H[e>>2]=H[c>>2];e=e+4|0;c=c+4|0;if((a|0)!=(c|0)){continue}break}H[d+36>>2]=e}H[d>>2]=6868;break c}e=d;a=H[i+32>>2];if(!a){break b}H[i+36>>2]=a;oa(a)}ca=i+48|0;return e|0}sa();v()}function Ec(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;l=ca-16|0;ca=l;a:{b:{c:{d:{e:{f:{g:{h:{i:{if(a>>>0<=244){g=H[4298];h=a>>>0<11?16:a+11&-8;c=h>>>3|0;b=g>>>c|0;if(b&3){c=c+((b^-1)&1)|0;a=c<<3;b=a+17232|0;d=H[a+17240>>2];a=H[d+8>>2];j:{if((b|0)==(a|0)){m=17192,n=Vj(c)&g,H[m>>2]=n;break j}H[a+12>>2]=b;H[b+8>>2]=a}a=d+8|0;b=c<<3;H[d+4>>2]=b|3;b=b+d|0;H[b+4>>2]=H[b+4>>2]|1;break a}k=H[4300];if(k>>>0>=h>>>0){break i}if(b){a=2<>2];a=H[e+8>>2];k:{if((b|0)==(a|0)){g=Vj(d)&g;H[4298]=g;break k}H[a+12>>2]=b;H[b+8>>2]=a}H[e+4>>2]=h|3;c=e+h|0;a=d<<3;d=a-h|0;H[c+4>>2]=d|1;H[a+e>>2]=d;if(k){b=(k&-8)+17232|0;f=H[4303];a=1<<(k>>>3);l:{if(!(a&g)){H[4298]=a|g;a=b;break l}a=H[b+8>>2]}H[b+8>>2]=f;H[a+12>>2]=f;H[f+12>>2]=b;H[f+8>>2]=a}a=e+8|0;H[4303]=c;H[4300]=d;break a}j=H[4299];if(!j){break i}c=H[(Qj(0-j&j)<<2)+17496>>2];f=(H[c+4>>2]&-8)-h|0;b=c;while(1){m:{a=H[b+16>>2];if(!a){a=H[b+20>>2];if(!a){break m}}b=(H[a+4>>2]&-8)-h|0;d=b>>>0>>0;f=d?b:f;c=d?a:c;b=a;continue}break}i=H[c+24>>2];d=H[c+12>>2];if((d|0)!=(c|0)){a=H[c+8>>2];H[a+12>>2]=d;H[d+8>>2]=a;break b}b=c+20|0;a=H[b>>2];if(!a){a=H[c+16>>2];if(!a){break h}b=c+16|0}while(1){e=b;d=a;b=a+20|0;a=H[b>>2];if(a){continue}b=d+16|0;a=H[d+16>>2];if(a){continue}break}H[e>>2]=0;break b}h=-1;if(a>>>0>4294967231){break i}a=a+11|0;h=a&-8;j=H[4299];if(!j){break i}f=0-h|0;g=0;n:{if(h>>>0<256){break n}g=31;if(h>>>0>16777215){break n}a=Q(a>>>8|0);g=((h>>>38-a&1)-(a<<1)|0)+62|0}b=H[(g<<2)+17496>>2];o:{p:{q:{if(!b){a=0;break q}a=0;c=h<<((g|0)!=31?25-(g>>>1|0)|0:0);while(1){r:{e=(H[b+4>>2]&-8)-h|0;if(e>>>0>=f>>>0){break r}d=b;f=e;if(e){break r}f=0;a=b;break p}e=H[b+20>>2];b=H[((c>>>29&4)+b|0)+16>>2];a=e?(e|0)==(b|0)?a:e:a;c=c<<1;if(b){continue}break}}if(!(a|d)){d=0;a=2<>2]}if(!a){break o}}while(1){b=(H[a+4>>2]&-8)-h|0;c=b>>>0>>0;f=c?b:f;d=c?a:d;b=H[a+16>>2];if(b){a=b}else{a=H[a+20>>2]}if(a){continue}break}}if(!d|H[4300]-h>>>0<=f>>>0){break i}g=H[d+24>>2];c=H[d+12>>2];if((d|0)!=(c|0)){a=H[d+8>>2];H[a+12>>2]=c;H[c+8>>2]=a;break c}b=d+20|0;a=H[b>>2];if(!a){a=H[d+16>>2];if(!a){break g}b=d+16|0}while(1){e=b;c=a;b=a+20|0;a=H[b>>2];if(a){continue}b=c+16|0;a=H[c+16>>2];if(a){continue}break}H[e>>2]=0;break c}a=H[4300];if(a>>>0>=h>>>0){d=H[4303];b=a-h|0;s:{if(b>>>0>=16){c=d+h|0;H[c+4>>2]=b|1;H[a+d>>2]=b;H[d+4>>2]=h|3;break s}H[d+4>>2]=a|3;a=a+d|0;H[a+4>>2]=H[a+4>>2]|1;c=0;b=0}H[4300]=b;H[4303]=c;a=d+8|0;break a}i=H[4301];if(i>>>0>h>>>0){b=i-h|0;H[4301]=b;c=H[4304];a=c+h|0;H[4304]=a;H[a+4>>2]=b|1;H[c+4>>2]=h|3;a=c+8|0;break a}a=0;j=h+47|0;if(H[4416]){c=H[4418]}else{H[4419]=-1;H[4420]=-1;H[4417]=4096;H[4418]=4096;H[4416]=l+12&-16^1431655768;H[4421]=0;H[4409]=0;c=4096}e=j+c|0;f=0-c|0;b=e&f;if(b>>>0<=h>>>0){break a}d=H[4408];if(d){c=H[4406];g=c+b|0;if(d>>>0>>0|c>>>0>=g>>>0){break a}}t:{if(!(I[17636]&4)){u:{v:{w:{x:{d=H[4304];if(d){a=17640;while(1){c=H[a>>2];if(c>>>0<=d>>>0&d>>>0>2]>>>0){break x}a=H[a+8>>2];if(a){continue}break}}c=zb(0);if((c|0)==-1){break u}g=b;d=H[4417];a=d-1|0;if(a&c){g=(b-c|0)+(a+c&0-d)|0}if(g>>>0<=h>>>0){break u}d=H[4408];if(d){a=H[4406];f=a+g|0;if(d>>>0>>0|a>>>0>=f>>>0){break u}}a=zb(g);if((c|0)!=(a|0)){break w}break t}g=f&e-i;c=zb(g);if((c|0)==(H[a>>2]+H[a+4>>2]|0)){break v}a=c}if((a|0)==-1){break u}if(h+48>>>0<=g>>>0){c=a;break t}c=H[4418];c=c+(j-g|0)&0-c;if((zb(c)|0)==-1){break u}g=c+g|0;c=a;break t}if((c|0)!=-1){break t}}H[4409]=H[4409]|4}c=zb(b);a=zb(0);if((c|0)==-1|(a|0)==-1|a>>>0<=c>>>0){break d}g=a-c|0;if(g>>>0<=h+40>>>0){break d}}a=H[4406]+g|0;H[4406]=a;if(a>>>0>K[4407]){H[4407]=a}y:{e=H[4304];if(e){a=17640;while(1){d=H[a>>2];b=H[a+4>>2];if((d+b|0)==(c|0)){break y}a=H[a+8>>2];if(a){continue}break}break f}a=H[4302];if(!(a>>>0<=c>>>0?a:0)){H[4302]=c}a=0;H[4411]=g;H[4410]=c;H[4306]=-1;H[4307]=H[4416];H[4413]=0;while(1){d=a<<3;b=d+17232|0;H[d+17240>>2]=b;H[d+17244>>2]=b;a=a+1|0;if((a|0)!=32){continue}break}d=g-40|0;a=c+8&7?-8-c&7:0;b=d-a|0;H[4301]=b;a=a+c|0;H[4304]=a;H[a+4>>2]=b|1;H[(c+d|0)+4>>2]=40;H[4305]=H[4420];break e}if(I[a+12|0]&8|d>>>0>e>>>0|c>>>0<=e>>>0){break f}H[a+4>>2]=b+g;a=e+8&7?-8-e&7:0;c=a+e|0;H[4304]=c;b=H[4301]+g|0;a=b-a|0;H[4301]=a;H[c+4>>2]=a|1;H[(b+e|0)+4>>2]=40;H[4305]=H[4420];break e}d=0;break b}c=0;break c}if(K[4302]>c>>>0){H[4302]=c}b=c+g|0;a=17640;z:{A:{B:{C:{D:{E:{while(1){if((b|0)!=H[a>>2]){a=H[a+8>>2];if(a){continue}break E}break}if(!(I[a+12|0]&8)){break D}}a=17640;while(1){b=H[a>>2];if(b>>>0<=e>>>0){f=b+H[a+4>>2]|0;if(f>>>0>e>>>0){break C}}a=H[a+8>>2];continue}}H[a>>2]=c;H[a+4>>2]=H[a+4>>2]+g;j=(c+8&7?-8-c&7:0)+c|0;H[j+4>>2]=h|3;g=b+(b+8&7?-8-b&7:0)|0;i=h+j|0;a=g-i|0;if((e|0)==(g|0)){H[4304]=i;a=H[4301]+a|0;H[4301]=a;H[i+4>>2]=a|1;break A}if(H[4303]==(g|0)){H[4303]=i;a=H[4300]+a|0;H[4300]=a;H[i+4>>2]=a|1;H[a+i>>2]=a;break A}f=H[g+4>>2];if((f&3)==1){e=f&-8;F:{if(f>>>0<=255){d=H[g+8>>2];b=f>>>3|0;c=H[g+12>>2];if((c|0)==(d|0)){m=17192,n=H[4298]&Vj(b),H[m>>2]=n;break F}H[d+12>>2]=c;H[c+8>>2]=d;break F}h=H[g+24>>2];c=H[g+12>>2];G:{if((g|0)!=(c|0)){b=H[g+8>>2];H[b+12>>2]=c;H[c+8>>2]=b;break G}H:{f=g+20|0;b=H[f>>2];if(b){break H}f=g+16|0;b=H[f>>2];if(b){break H}c=0;break G}while(1){d=f;c=b;f=c+20|0;b=H[f>>2];if(b){continue}f=c+16|0;b=H[c+16>>2];if(b){continue}break}H[d>>2]=0}if(!h){break F}d=H[g+28>>2];b=(d<<2)+17496|0;I:{if(H[b>>2]==(g|0)){H[b>>2]=c;if(c){break I}m=17196,n=H[4299]&Vj(d),H[m>>2]=n;break F}H[h+(H[h+16>>2]==(g|0)?16:20)>>2]=c;if(!c){break F}}H[c+24>>2]=h;b=H[g+16>>2];if(b){H[c+16>>2]=b;H[b+24>>2]=c}b=H[g+20>>2];if(!b){break F}H[c+20>>2]=b;H[b+24>>2]=c}g=e+g|0;f=H[g+4>>2];a=a+e|0}H[g+4>>2]=f&-2;H[i+4>>2]=a|1;H[a+i>>2]=a;if(a>>>0<=255){b=(a&-8)+17232|0;c=H[4298];a=1<<(a>>>3);J:{if(!(c&a)){H[4298]=a|c;a=b;break J}a=H[b+8>>2]}H[b+8>>2]=i;H[a+12>>2]=i;H[i+12>>2]=b;H[i+8>>2]=a;break A}f=31;if(a>>>0<=16777215){b=Q(a>>>8|0);f=((a>>>38-b&1)-(b<<1)|0)+62|0}H[i+28>>2]=f;H[i+16>>2]=0;H[i+20>>2]=0;b=(f<<2)+17496|0;d=H[4299];c=1<>2]=i;break K}f=a<<((f|0)!=31?25-(f>>>1|0)|0:0);c=H[b>>2];while(1){b=c;if((H[c+4>>2]&-8)==(a|0)){break B}c=f>>>29|0;f=f<<1;d=(c&4)+b|0;c=H[d+16>>2];if(c){continue}break}H[d+16>>2]=i}H[i+24>>2]=b;H[i+12>>2]=i;H[i+8>>2]=i;break A}d=g-40|0;a=c+8&7?-8-c&7:0;b=d-a|0;H[4301]=b;a=a+c|0;H[4304]=a;H[a+4>>2]=b|1;H[(c+d|0)+4>>2]=40;H[4305]=H[4420];a=(f+(f-39&7?39-f&7:0)|0)-47|0;d=a>>>0>>0?e:a;H[d+4>>2]=27;a=H[4413];H[d+16>>2]=H[4412];H[d+20>>2]=a;a=H[4411];H[d+8>>2]=H[4410];H[d+12>>2]=a;H[4412]=d+8;H[4411]=g;H[4410]=c;H[4413]=0;a=d+24|0;while(1){H[a+4>>2]=7;b=a+8|0;a=a+4|0;if(b>>>0>>0){continue}break}if((d|0)==(e|0)){break e}H[d+4>>2]=H[d+4>>2]&-2;f=d-e|0;H[e+4>>2]=f|1;H[d>>2]=f;if(f>>>0<=255){b=(f&-8)+17232|0;c=H[4298];a=1<<(f>>>3);L:{if(!(c&a)){H[4298]=a|c;a=b;break L}a=H[b+8>>2]}H[b+8>>2]=e;H[a+12>>2]=e;H[e+12>>2]=b;H[e+8>>2]=a;break e}a=31;if(f>>>0<=16777215){a=Q(f>>>8|0);a=((f>>>38-a&1)-(a<<1)|0)+62|0}H[e+28>>2]=a;H[e+16>>2]=0;H[e+20>>2]=0;b=(a<<2)+17496|0;d=H[4299];c=1<>2]=e;break M}a=f<<((a|0)!=31?25-(a>>>1|0)|0:0);d=H[b>>2];while(1){b=d;if((f|0)==(H[b+4>>2]&-8)){break z}c=a>>>29|0;a=a<<1;c=(c&4)+b|0;d=H[c+16>>2];if(d){continue}break}H[c+16>>2]=e}H[e+24>>2]=b;H[e+12>>2]=e;H[e+8>>2]=e;break e}a=H[b+8>>2];H[a+12>>2]=i;H[b+8>>2]=i;H[i+24>>2]=0;H[i+12>>2]=b;H[i+8>>2]=a}a=j+8|0;break a}a=H[b+8>>2];H[a+12>>2]=e;H[b+8>>2]=e;H[e+24>>2]=0;H[e+12>>2]=b;H[e+8>>2]=a}a=H[4301];if(a>>>0<=h>>>0){break d}b=a-h|0;H[4301]=b;c=H[4304];a=c+h|0;H[4304]=a;H[a+4>>2]=b|1;H[c+4>>2]=h|3;a=c+8|0;break a}H[3992]=48;a=0;break a}N:{if(!g){break N}b=H[d+28>>2];a=(b<<2)+17496|0;O:{if(H[a>>2]==(d|0)){H[a>>2]=c;if(c){break O}j=Vj(b)&j;H[4299]=j;break N}H[g+(H[g+16>>2]==(d|0)?16:20)>>2]=c;if(!c){break N}}H[c+24>>2]=g;a=H[d+16>>2];if(a){H[c+16>>2]=a;H[a+24>>2]=c}a=H[d+20>>2];if(!a){break N}H[c+20>>2]=a;H[a+24>>2]=c}P:{if(f>>>0<=15){a=f+h|0;H[d+4>>2]=a|3;a=a+d|0;H[a+4>>2]=H[a+4>>2]|1;break P}H[d+4>>2]=h|3;e=d+h|0;H[e+4>>2]=f|1;H[e+f>>2]=f;if(f>>>0<=255){b=(f&-8)+17232|0;c=H[4298];a=1<<(f>>>3);Q:{if(!(c&a)){H[4298]=a|c;a=b;break Q}a=H[b+8>>2]}H[b+8>>2]=e;H[a+12>>2]=e;H[e+12>>2]=b;H[e+8>>2]=a;break P}a=31;if(f>>>0<=16777215){a=Q(f>>>8|0);a=((f>>>38-a&1)-(a<<1)|0)+62|0}H[e+28>>2]=a;H[e+16>>2]=0;H[e+20>>2]=0;b=(a<<2)+17496|0;R:{c=1<>2]=e;break S}a=f<<((a|0)!=31?25-(a>>>1|0)|0:0);h=H[b>>2];while(1){b=h;if((H[b+4>>2]&-8)==(f|0)){break R}c=a>>>29|0;a=a<<1;c=(c&4)+b|0;h=H[c+16>>2];if(h){continue}break}H[c+16>>2]=e}H[e+24>>2]=b;H[e+12>>2]=e;H[e+8>>2]=e;break P}a=H[b+8>>2];H[a+12>>2]=e;H[b+8>>2]=e;H[e+24>>2]=0;H[e+12>>2]=b;H[e+8>>2]=a}a=d+8|0;break a}T:{if(!i){break T}b=H[c+28>>2];a=(b<<2)+17496|0;U:{if(H[a>>2]==(c|0)){H[a>>2]=d;if(d){break U}m=17196,n=Vj(b)&j,H[m>>2]=n;break T}H[i+(H[i+16>>2]==(c|0)?16:20)>>2]=d;if(!d){break T}}H[d+24>>2]=i;a=H[c+16>>2];if(a){H[d+16>>2]=a;H[a+24>>2]=d}a=H[c+20>>2];if(!a){break T}H[d+20>>2]=a;H[a+24>>2]=d}V:{if(f>>>0<=15){a=f+h|0;H[c+4>>2]=a|3;a=a+c|0;H[a+4>>2]=H[a+4>>2]|1;break V}H[c+4>>2]=h|3;d=c+h|0;H[d+4>>2]=f|1;H[d+f>>2]=f;if(k){b=(k&-8)+17232|0;e=H[4303];a=1<<(k>>>3);W:{if(!(a&g)){H[4298]=a|g;a=b;break W}a=H[b+8>>2]}H[b+8>>2]=e;H[a+12>>2]=e;H[e+12>>2]=b;H[e+8>>2]=a}H[4303]=d;H[4300]=f}a=c+8|0}ca=l+16|0;return a|0}function ce(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0;m=ca-32|0;ca=m;o=pa(12);H[o+8>>2]=0;H[o+4>>2]=b;H[o>>2]=0;s=o+12|0;b=s;a:{b:{c:{while(1){b=b-12|0;w=H[b+8>>2];j=H[b+4>>2];t=H[b>>2];if(t){if((w|0)>1e3){break a}H[m+24>>2]=0;H[m+16>>2]=0;H[m+20>>2]=0;d=1;c=H[a>>2];e=H[c+8>>2];h=H[c+12>>2];g=H[c+20>>2];f=H[c+16>>2];d:{if((h|0)<=(g|0)&f>>>0>=e>>>0|(g|0)>(h|0)){break d}e=I[f+H[c>>2]|0];h=c;c=g;f=f+1|0;c=f?c:c+1|0;H[h+16>>2]=f;H[h+20>>2]=c;Cc(m+16|0,e);if(e){c=H[a>>2];n=Dc(m+16|0);p=H[c+8>>2];g=H[c+12>>2];h=H[c+20>>2];f=H[c+16>>2];k=f+e|0;h=k>>>0>>0?h+1|0:h;if((g|0)<=(h|0)&k>>>0>p>>>0|(g|0)<(h|0)){break d}qa(n,f+H[c>>2]|0,e);d=H[c+20>>2];f=e;e=e+H[c+16>>2]|0;d=f>>>0>e>>>0?d+1|0:d;H[c+16>>2]=e;H[c+20>>2]=d}j=pa(24);c=j;H[c+4>>2]=0;H[c+8>>2]=0;c=c+16|0;H[c>>2]=0;H[c+4>>2]=0;H[j>>2]=j+4;H[j+12>>2]=c;e=ca-32|0;ca=e;h=t+12|0;c=m+16|0;u=nb(h,c);i=t+16|0;e:{if((u|0)==(i|0)){H[e+16>>2]=c;f:{g:{d=H[h+4>>2];h:{if(!d){f=h+4|0;c=f;break h}f=I[c+11|0];g=f<<24>>24<0;n=g?H[c>>2]:c;g=g?H[c+4>>2]:f;while(1){c=d;d=I[c+27|0];f=d<<24>>24<0;d=f?H[c+20>>2]:d;p=d>>>0>>0;i:{j:{k:{l:{k=p?d:g;m:{if(k){f=f?H[c+16>>2]:c+16|0;q=Fa(n,f,k);if(!q){if(d>>>0>g>>>0){break m}break l}if((q|0)>=0){break l}break m}if(d>>>0<=g>>>0){break k}}f=c;d=H[c>>2];if(d){continue}break h}d=Fa(f,n,k);if(d){break j}}if(p){break i}break g}if((d|0)>=0){break g}}d=H[c+4>>2];if(d){continue}break}f=c+4|0}d=pa(32);n=d+16|0;g=H[e+16>>2];n:{if(F[g+11|0]>=0){p=H[g+4>>2];H[n>>2]=H[g>>2];H[n+4>>2]=p;H[n+8>>2]=H[g+8>>2];break n}za(n,H[g>>2],H[g+4>>2])}H[d+8>>2]=c;H[d>>2]=0;H[d+4>>2]=0;H[d+28>>2]=0;H[f>>2]=d;c=d;g=H[H[h>>2]>>2];if(g){H[h>>2]=g;c=H[f>>2]}Sb(H[h+4>>2],c);H[h+8>>2]=H[h+8>>2]+1;c=1;break f}d=c;c=0}F[e+28|0]=c;H[e+24>>2]=d;d=H[e+24>>2];c=H[d+28>>2];H[d+28>>2]=j;if(!c){break e}Ra(c+12|0,H[c+16>>2]);Qa(c,H[c+4>>2]);oa(c);break e}if(!j){break e}Ra(j+12|0,H[j+16>>2]);Qa(j,H[j+4>>2]);oa(j)}ca=e+32|0;d=(i|0)!=(u|0)}if(F[m+27|0]<0){oa(H[m+16>>2])}if(d){break a}}if(!j){break a}H[m+16>>2]=0;if(!Bb(1,m+16|0,H[a>>2])){break a}q=0;x=H[m+16>>2];if(x){while(1){d=0;i=ca-32|0;ca=i;H[i+24>>2]=0;H[i+16>>2]=0;H[i+20>>2]=0;c=H[a>>2];f=H[c+8>>2];o:{p:{h=H[c+12>>2];g=H[c+20>>2];e=H[c+16>>2];q:{if((h|0)<=(g|0)&e>>>0>=f>>>0|(g|0)>(h|0)){break q}f=I[e+H[c>>2]|0];h=c;c=g;e=e+1|0;c=e?c:c+1|0;H[h+16>>2]=e;H[h+20>>2]=c;Cc(i+16|0,f);if(f){e=H[a>>2];n=Dc(i+16|0);p=H[e+8>>2];g=H[e+12>>2];c=H[e+20>>2];h=H[e+16>>2];k=h+f|0;c=k>>>0>>0?c+1|0:c;if(k>>>0>p>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break q}qa(n,h+H[e>>2]|0,f);c=H[e+20>>2];g=f;f=f+H[e+16>>2]|0;c=g>>>0>f>>>0?c+1|0:c;H[e+16>>2]=f;H[e+20>>2]=c}H[i+12>>2]=0;if(!Bb(1,i+12|0,H[a>>2])){break q}f=H[i+12>>2];if(!f){break q}e=H[a>>2];c=H[e+8>>2];h=H[e+16>>2];g=c-h|0;c=H[e+12>>2]-(H[e+20>>2]+(c>>>0>>0)|0)|0;if((c|0)<=0&f>>>0>g>>>0|(c|0)<0){break q}H[i+8>>2]=0;H[i>>2]=0;H[i+4>>2]=0;if((f|0)<0){break p}d=pa(f);H[i>>2]=d;c=d+f|0;H[i+8>>2]=c;l=ra(d,0,f);H[i+4>>2]=c;h=H[e+12>>2];y=h;p=H[e+8>>2];c=H[e+20>>2];k=H[e+16>>2];g=f+k|0;c=g>>>0>>0?c+1|0:c;u=g;n=c;r:{if((c|0)<=(h|0)&g>>>0<=p>>>0|(c|0)<(h|0)){qa(l,H[e>>2]+k|0,f);d=H[e+20>>2];c=f+H[e+16>>2]|0;d=c>>>0>>0?d+1|0:d;H[e+16>>2]=c;H[e+20>>2]=d;h=ca-48|0;ca=h;e=nb(j,i+16|0);if((e|0)!=(j+4|0)){c=H[e+4>>2];s:{if(!c){c=e;while(1){d=H[c+8>>2];f=H[d>>2]!=(c|0);c=d;if(f){continue}break}break s}while(1){d=c;c=H[c>>2];if(c){continue}break}}if((e|0)==H[j>>2]){H[j>>2]=d}H[j+8>>2]=H[j+8>>2]-1;f=H[j+4>>2];t:{u:{g=e;d=e;e=H[d>>2];if(e){c=H[g+4>>2];if(!c){break u}while(1){d=c;c=H[c>>2];if(c){continue}break}}e=H[d+4>>2];if(e){break u}e=0;k=1;break t}H[e+8>>2]=H[d+8>>2];k=0}l=H[d+8>>2];c=H[l>>2];v:{if((d|0)==(c|0)){H[l>>2]=e;if((d|0)==(f|0)){c=0;f=e;break v}c=H[l+4>>2];break v}H[l+4>>2]=e}r=!I[d+12|0];if((d|0)!=(g|0)){l=H[g+8>>2];H[d+8>>2]=l;H[l+(((g|0)!=H[H[g+8>>2]>>2])<<2)>>2]=d;l=H[g>>2];H[d>>2]=l;H[l+8>>2]=d;l=H[g+4>>2];H[d+4>>2]=l;if(l){H[l+8>>2]=d}F[d+12|0]=I[g+12|0];f=(f|0)==(g|0)?d:f}w:{if(r|!f){break w}if(k){while(1){e=I[c+12|0];x:{d=H[c+8>>2];if(H[d>>2]!=(c|0)){if(!e){F[c+12|0]=1;F[d+12|0]=0;e=H[d+4>>2];k=H[e>>2];H[d+4>>2]=k;if(k){H[k+8>>2]=d}H[e+8>>2]=H[d+8>>2];k=H[d+8>>2];H[(((d|0)!=H[k>>2])<<2)+k>>2]=e;H[e>>2]=d;H[d+8>>2]=e;d=c;c=H[c>>2];f=(c|0)==(f|0)?d:f;c=H[c+4>>2]}y:{z:{d=H[c>>2];A:{if(!(I[d+12|0]?0:d)){e=H[c+4>>2];if(I[e+12|0]?0:e){break A}F[c+12|0]=0;c=H[c+8>>2];B:{if((f|0)==(c|0)){c=f;break B}if(I[c+12|0]){break x}}F[c+12|0]=1;break w}e=H[c+4>>2];if(!e){break z}}if(I[e+12|0]){break z}d=c;break y}F[d+12|0]=1;F[c+12|0]=0;e=H[d+4>>2];H[c>>2]=e;if(e){H[e+8>>2]=c}H[d+8>>2]=H[c+8>>2];e=H[c+8>>2];H[((H[e>>2]!=(c|0))<<2)+e>>2]=d;H[d+4>>2]=c;H[c+8>>2]=d;e=c}c=H[d+8>>2];F[d+12|0]=I[c+12|0];F[c+12|0]=1;F[e+12|0]=1;d=H[c+4>>2];e=H[d>>2];H[c+4>>2]=e;if(e){H[e+8>>2]=c}H[d+8>>2]=H[c+8>>2];e=H[c+8>>2];H[(((c|0)!=H[e>>2])<<2)+e>>2]=d;H[d>>2]=c;H[c+8>>2]=d;break w}if(!e){F[c+12|0]=1;F[d+12|0]=0;e=H[c+4>>2];H[d>>2]=e;if(e){H[e+8>>2]=d}H[c+8>>2]=H[d+8>>2];e=H[d+8>>2];H[(((d|0)!=H[e>>2])<<2)+e>>2]=c;H[c+4>>2]=d;H[d+8>>2]=c;f=(d|0)==(f|0)?c:f;c=H[d>>2]}e=H[c>>2];C:{if(!(!e|I[e+12|0])){d=c;break C}d=H[c+4>>2];if(!(I[d+12|0]?0:d)){F[c+12|0]=0;c=H[c+8>>2];if((c|0)!=(f|0)?I[c+12|0]:0){break x}F[c+12|0]=1;break w}if(e){if(!I[e+12|0]){d=c;break C}d=H[c+4>>2]}F[d+12|0]=1;F[c+12|0]=0;e=H[d>>2];H[c+4>>2]=e;if(e){H[e+8>>2]=c}H[d+8>>2]=H[c+8>>2];e=H[c+8>>2];H[((H[e>>2]!=(c|0))<<2)+e>>2]=d;H[d>>2]=c;H[c+8>>2]=d;e=c}c=H[d+8>>2];F[d+12|0]=I[c+12|0];F[c+12|0]=1;F[e+12|0]=1;d=H[c>>2];e=H[d+4>>2];H[c>>2]=e;if(e){H[e+8>>2]=c}H[d+8>>2]=H[c+8>>2];e=H[c+8>>2];H[(((c|0)!=H[e>>2])<<2)+e>>2]=d;H[d+4>>2]=c;H[c+8>>2]=d;break w}d=c;c=H[c+8>>2];c=H[(((d|0)==H[c>>2])<<2)+c>>2];continue}}F[e+12|0]=1}c=H[g+28>>2];if(c){H[g+32>>2]=c;oa(c)}if(F[g+27|0]<0){oa(H[g+16>>2])}oa(g)}H[h+8>>2]=0;H[h>>2]=0;H[h+4>>2]=0;c=H[i+4>>2];d=H[i>>2];f=c-d|0;e=0;D:{E:{if((c|0)!=(d|0)){if((f|0)<0){break E}e=pa(f);c=ra(e,0,f);g=c+f|0;H[h+8>>2]=g;H[h+4>>2]=g;H[h>>2]=c;c=d}qa(e,c,f);F:{if(F[i+27|0]>=0){H[h+24>>2]=H[i+24>>2];c=H[i+20>>2];H[h+16>>2]=H[i+16>>2];H[h+20>>2]=c;break F}za(h+16|0,H[i+16>>2],H[i+20>>2])}ae(h+28|0,h);f=h+16|0;c=f;G:{H:{d=H[j+4>>2];I:{if(!d){e=j+4|0;c=e;break I}e=I[c+11|0];g=e<<24>>24<0;k=g?H[c>>2]:c;g=g?H[c+4>>2]:e;while(1){c=d;d=I[c+27|0];e=d<<24>>24<0;d=e?H[c+20>>2]:d;l=d>>>0>>0;J:{K:{L:{M:{r=l?d:g;N:{if(r){e=e?H[c+16>>2]:c+16|0;z=Fa(k,e,r);if(!z){if(d>>>0>g>>>0){break N}break M}if((z|0)>=0){break M}break N}if(d>>>0<=g>>>0){break L}}e=c;d=H[c>>2];if(d){continue}break I}d=Fa(e,k,r);if(d){break K}}if(l){break J}break H}if((d|0)>=0){break H}}d=H[c+4>>2];if(d){continue}break}e=c+4|0}d=pa(40);H[d+24>>2]=H[f+8>>2];g=H[f+4>>2];H[d+16>>2]=H[f>>2];H[d+20>>2]=g;H[f>>2]=0;H[f+4>>2]=0;H[f+8>>2]=0;ae(d+28|0,f+12|0);H[d+8>>2]=c;H[d>>2]=0;H[d+4>>2]=0;H[e>>2]=d;c=d;f=H[H[j>>2]>>2];if(f){H[j>>2]=f;c=H[e>>2]}Sb(H[j+4>>2],c);H[j+8>>2]=H[j+8>>2]+1;c=1;break G}d=c;c=0}F[h+44|0]=c;H[h+40>>2]=d;c=H[h+28>>2];if(c){H[h+32>>2]=c;oa(c)}if(F[h+27|0]<0){oa(H[h+16>>2])}c=H[h>>2];if(c){H[h+4>>2]=c;oa(c)}ca=h+48|0;break D}sa();v()}d=H[i>>2];if(!d){break r}}H[i+4>>2]=d;oa(d)}d=(n|0)<=(y|0)&p>>>0>=u>>>0|(n|0)<(y|0)}if(F[i+27|0]<0){oa(H[i+16>>2])}ca=i+32|0;break o}sa();v()}if(!d){break a}q=q+1|0;if((x|0)!=(q|0)){continue}break}}H[m+12>>2]=0;if(!Bb(1,m+12|0,H[a>>2])){break a}c=H[a>>2];e=H[c+8>>2];f=H[c+16>>2];h=e-f|0;d=H[m+12>>2];c=H[c+12>>2]-(H[c+20>>2]+(e>>>0>>0)|0)|0;if(h>>>0>>0&(c|0)<=0|(c|0)<0){break a}if(d){q=0;h=((t|0)!=0)+w|0;while(1){O:{if(b>>>0>>0){H[b+8>>2]=h;H[b+4>>2]=0;H[b>>2]=j;b=b+12|0;d=H[m+12>>2];break O}c=b-o|0;g=(c|0)/12|0;b=g+1|0;if(b>>>0>=357913942){break c}e=(s-o|0)/12|0;f=e<<1;e=e>>>0>=178956970?357913941:b>>>0>>0?f:b;if(e){if(e>>>0>=357913942){break b}f=pa(N(e,12))}else{f=0}b=f+N(g,12)|0;H[b+8>>2]=h;H[b+4>>2]=0;H[b>>2]=j;c=va(b+N((c|0)/-12|0,12)|0,o,c);s=f+N(e,12)|0;b=b+12|0;if(o){oa(o)}o=c}q=q+1|0;if(q>>>0>>0){continue}break}}if((b|0)!=(o|0)){continue}break}A=1;break a}sa();v()}wa();v()}if(o){oa(o)}ca=m+32|0;return A}function Af(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=O(0),q=0,r=0;e=ca-720|0;ca=e;a:{b:{c:{d:{e:{f:{g:{h:{i:{if(J[b+38>>1]>=515){H[e+680>>2]=0;H[e+672>>2]=0;H[e+676>>2]=0;if((ea[H[H[a>>2]+24>>2]](a)|0)<=0){break d}while(1){c=ea[H[H[a>>2]+20>>2]](a,n)|0;d=H[H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+8>>2]+(c<<2)>>2];if(H[d+28>>2]==9){f=H[e+672>>2];c=H[e+676>>2]-f>>2;k=I[d+24|0];j:{if(c>>>0>>0){ya(e+672|0,k-c|0);break j}if(c>>>0<=k>>>0){break j}H[e+676>>2]=f+(k<<2)}j=0;i=H[b+8>>2];h=H[b+12>>2];c=H[b+20>>2];d=k<<2;f=H[b+16>>2];l=f+d|0;c=d>>>0>l>>>0?c+1|0:c;if(i>>>0>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break b}qa(H[e+672>>2],f+H[b>>2]|0,d);c=H[b+20>>2];f=d;d=d+H[b+16>>2]|0;c=f>>>0>d>>>0?c+1|0:c;i=d;H[b+16>>2]=d;H[b+20>>2]=c;l=H[b+12>>2];g=H[b+8>>2];h=d+4|0;f=h>>>0<4?c+1|0:c;d=f;if(g>>>0>>0&(d|0)>=(l|0)|(d|0)>(l|0)){break b}o=H[b>>2];f=o+i|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=h;H[b+20>>2]=d;if(g>>>0<=h>>>0&(d|0)>=(l|0)|(d|0)>(l|0)){break b}d=I[h+o|0];h=i+5|0;c=h>>>0<5?c+1|0:c;H[b+16>>2]=h;H[b+20>>2]=c;if(d>>>0>31){break b}p=(A(2,f),B());H[e+20>>2]=-1;H[e+16>>2]=1832;H[e+32>>2]=0;H[e+36>>2]=0;H[e+24>>2]=0;H[e+28>>2]=0;c=H[e+672>>2];o=d-1|0;if(o>>>0<=29){H[e+20>>2]=d;k:{h=c+(k<<2)|0;l=h-c|0;f=l>>2;i=H[e+32>>2];d=H[e+24>>2];if(f>>>0<=i-d>>2>>>0){i=H[e+28>>2]-d|0;l=i>>2;i=f>>>0>l>>>0?c+i|0:h;g=i-c|0;if((c|0)!=(i|0)){va(d,c,g)}if(f>>>0>l>>>0){c=h-i|0;d=H[e+28>>2];if((h|0)!=(i|0)){va(d,i,c)}H[e+28>>2]=c+d;break k}H[e+28>>2]=d+g;break k}if(d){H[e+28>>2]=d;oa(d);H[e+32>>2]=0;H[e+24>>2]=0;H[e+28>>2]=0;i=0}l:{if((l|0)<0){break l}d=i>>>1|0;d=i>>>0>=2147483644?1073741823:d>>>0>f>>>0?d:f;if(d>>>0>=1073741824){break l}i=d<<2;d=pa(i);H[e+28>>2]=d;H[e+24>>2]=d;H[e+32>>2]=d+i;if((c|0)!=(h|0)){qa(d,c,l)}H[e+28>>2]=d+(f<<2);break k}sa();v()}L[e+36>>2]=p}m:{if(o>>>0>=30){break m}if(!Xc(e+16|0,H[H[a+60>>2]+((H[a+40>>2]-H[a+36>>2]|0)/24<<2)>>2])){break m}c=H[a+40>>2];n:{if((c|0)!=H[a+44>>2]){H[c>>2]=1832;d=H[e+20>>2];H[c+16>>2]=0;H[c+8>>2]=0;H[c+12>>2]=0;H[c+4>>2]=d;d=H[e+28>>2];f=H[e+24>>2];if((d|0)!=(f|0)){d=d-f|0;if((d|0)<0){break i}g=pa(d);H[c+12>>2]=g;H[c+8>>2]=g;H[c+16>>2]=(d&-4)+g;k=H[e+24>>2];d=H[e+28>>2];if((k|0)!=(d|0)){while(1){L[g>>2]=L[k>>2];g=g+4|0;k=k+4|0;if((d|0)!=(k|0)){continue}break}}H[c+12>>2]=g}L[c+20>>2]=L[e+36>>2];H[a+40>>2]=c+24;break n}d=0;o:{p:{q:{r:{j=H[a+40>>2];f=H[a+36>>2];i=(j-f|0)/24|0;c=i+1|0;if(c>>>0<178956971){h=(H[a+44>>2]-f|0)/24|0;l=h<<1;h=h>>>0>=89478485?178956970:c>>>0>>0?l:c;if(h){if(h>>>0>=178956971){break r}d=pa(N(h,24))}g=N(i,24)+d|0;H[g>>2]=1832;c=H[e+20>>2];H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;H[g+4>>2]=c;c=H[e+24>>2];i=H[e+28>>2];if((c|0)!=(i|0)){l=i-c|0;if((l|0)<0){break q}k=pa(l);H[g+8>>2]=k;H[g+16>>2]=(l&-4)+k;while(1){L[k>>2]=L[c>>2];k=k+4|0;c=c+4|0;if((i|0)!=(c|0)){continue}break}H[g+12>>2]=k}c=N(h,24)+d|0;L[g+20>>2]=L[e+36>>2];d=g+24|0;if((f|0)==(j|0)){break p}while(1){g=g-24|0;H[g>>2]=1832;j=j-24|0;H[g+4>>2]=H[j+4>>2];H[g+8>>2]=H[j+8>>2];H[g+12>>2]=H[j+12>>2];H[g+16>>2]=H[j+16>>2];H[j+16>>2]=0;H[j+8>>2]=0;H[j+12>>2]=0;L[g+20>>2]=L[j+20>>2];if((f|0)!=(j|0)){continue}break}H[a+44>>2]=c;k=H[a+40>>2];H[a+40>>2]=d;j=H[a+36>>2];H[a+36>>2]=g;if((j|0)==(k|0)){break o}while(1){k=k-24|0;ea[H[H[k>>2]>>2]](k)|0;if((j|0)!=(k|0)){continue}break}break o}sa();v()}wa();v()}sa();v()}H[a+44>>2]=c;H[a+40>>2]=d;H[a+36>>2]=g}if(j){oa(j)}}j=1}H[e+16>>2]=1832;c=H[e+24>>2];if(c){H[e+28>>2]=c;oa(c)}if(!j){break c}}n=n+1|0;if((ea[H[H[a>>2]+24>>2]](a)|0)>(n|0)){continue}break}break d}k=ea[H[H[a>>2]+24>>2]](a)|0;H[e+712>>2]=0;H[e+704>>2]=0;H[e+708>>2]=0;if(k){if(k>>>0>=214748365){break h}c=N(k,20);d=pa(c);H[e+704>>2]=d;H[e+712>>2]=c+d;c=c-20|0;c=(c-((c>>>0)%20|0)|0)+20|0;q=e,r=ra(d,0,c)+c|0,H[q+708>>2]=r;while(1){c=ea[H[H[a>>2]+20>>2]](a,m)|0;d=H[H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+8>>2]+(c<<2)>>2];f=H[d+28>>2];c=f-1|0;if(c>>>0<=10){c=H[(c<<2)+13584>>2]}else{c=-1}h=(c|0)>0?c:0;if(h>>>0>4){break f}c=H[e+704>>2]+N(m,20)|0;i=I[d+24|0];H[c+16>>2]=i;H[c+12>>2]=h;H[c+8>>2]=f;H[c+4>>2]=g;H[c>>2]=d;g=g+i|0;m=m+1|0;if((k|0)!=(m|0)){continue}break}}c=ea[H[H[a>>2]+20>>2]](a,0)|0;m=H[H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+8>>2]+(c<<2)>>2];F[m+84|0]=1;H[m+72>>2]=H[m+68>>2];h=H[b+12>>2];c=h;d=H[b+20>>2];f=H[b+8>>2];i=H[b+16>>2];if((c|0)<=(d|0)&f>>>0<=i>>>0|(c|0)<(d|0)){break f}n=H[b>>2];o=I[n+i|0];c=d;l=i+1|0;c=l?c:c+1|0;H[b+16>>2]=l;H[b+20>>2]=c;s:{switch(o|0){case 0:a=H[e+704>>2];if((H[e+708>>2]-a|0)!=20){break e}if(H[a+16>>2]!=3){break f}t:{if(f>>>0<=l>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break t}c=d;a=i+2|0;c=a>>>0<2?c+1|0:c;l=a;H[b+16>>2]=a;H[b+20>>2]=c;c=d;a=i+6|0;c=a>>>0<6?c+1|0:c;if(a>>>0>f>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break t}d=l+n|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=a;H[b+20>>2]=c;mb(m,d);j=e+672|0;H[j+20>>2]=0;H[j+12>>2]=0;H[j+16>>2]=0;H[j>>2]=0;H[j+4>>2]=0;H[j+20>>2]=d;d=Ac(e+16|0,e+704|0);k=0;g=ca-32|0;ca=g;H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;f=H[b+12>>2];m=f;i=H[b+8>>2];c=H[b+20>>2];l=c;h=H[b+16>>2];a=h+4|0;c=a>>>0<4?c+1|0:c;u:{if(a>>>0>i>>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break u}n=H[b>>2];f=n+h|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=a;H[b+20>>2]=c;v:{w:{switch(f-2|0){case 1:if((c|0)>=(m|0)&a>>>0>=i>>>0|(c|0)>(m|0)){break u}a=F[a+n|0];c=l;f=h+5|0;c=f>>>0<5?c+1|0:c;H[b+16>>2]=f;H[b+20>>2]=c;H[j+8>>2]=a;if((a|0)==1){if(Ud(j,b,g+16|0)){break v}break u}Rd(1799,23,H[3443]);break u;default:Rd(1774,24,H[3443]);break u;case 0:break w}}if(!Ud(j,b,g+16|0)){break u}}H[g+8>>2]=H[g+16>>2];H[g>>2]=H[g+20>>2];c=ca-32|0;ca=c;a=H[j>>2];p=L[j+4>>2];H[c+24>>2]=1065353216;h=-1<0){L[c+24>>2]=p/O(a|0)}m=H[g+8>>2];n=H[g>>2];if((m|0)!=(n|0)){a=H[d+28>>2];while(1){b=H[m>>2];f=H[m+4>>2];p=L[c+24>>2];L[c+16>>2]=p*O(H[m+8>>2]-h|0);L[c+12>>2]=p*O(f-h|0);L[c+8>>2]=p*O(b-h|0);b=a;i=H[d+16>>2];f=H[i>>2];if(!I[f+84|0]){b=H[H[f+68>>2]+(a<<2)>>2]}if(K[f+80>>2]>b>>>0){a=H[f+40>>2];qa(H[H[f>>2]>>2]+N(a,b)|0,(c+8|0)+(H[i+4>>2]<<2)|0,a);n=H[g>>2];a=H[d+28>>2]}a=a+1|0;H[d+28>>2]=a;m=m+12|0;if((n|0)!=(m|0)){continue}break}}ca=c+32|0;k=1}a=H[g+16>>2];if(a){H[g+20>>2]=a;oa(a)}ca=g+32|0;yc(d);j=1;if(k){break f}}j=0;break f;case 1:break s;default:break f}}if(f>>>0<=l>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break f}o=I[l+n|0];c=d;l=i+2|0;c=l>>>0<2?c+1|0:c;H[b+16>>2]=l;H[b+20>>2]=c;if(o>>>0>=7){H[e>>2]=o;Qd(1651,e);break f}c=d;d=i+6|0;c=d>>>0<6?c+1|0:c;if(d>>>0>f>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break f}f=l+n|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=d;H[b+20>>2]=c;if(k){m=0;while(1){c=ea[H[H[a>>2]+20>>2]](a,m)|0;c=H[H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+8>>2]+(c<<2)>>2];mb(c,f);F[c+84|0]=1;H[c+72>>2]=H[c+68>>2];m=m+1|0;if((k|0)!=(m|0)){continue}break}}a=Ac(e+672|0,e+704|0);x:{y:{switch(o|0){case 1:c=wb(e+16|0,g);b=zd(c,b,a,-1);xb(c);if(!b){break g}break x;case 2:c=ub(e+16|0,g);b=yd(c,b,a,-1);vb(c);if(!b){break g}break x;case 3:c=ub(e+16|0,g);b=xd(c,b,a,-1);vb(c);if(!b){break g}break x;case 4:c=$a(e+16|0,g);b=wd(c,b,a,-1);ab(c);if(!b){break g}break x;case 5:c=$a(e+16|0,g);b=vd(c,b,a,-1);ab(c);if(!b){break g}break x;case 6:c=$a(e+16|0,g);b=ud(c,b,a,-1);ab(c);if(b){break x}break g;case 0:break y;default:break g}}c=wb(e+16|0,g);b=Bd(c,b,a,-1);xb(c);if(!b){break g}}yc(a);j=1;break f}sa();v()}sa();v()}yc(a)}a=H[e+704>>2]}if(!a){break a}H[e+708>>2]=a;oa(a);break a}j=1;if(H[a+52>>2]==H[a+48>>2]){break b}while(1){if(!td(1,e+16|0,b)){break c}c=H[a+48>>2];d=H[e+16>>2];H[c+(m<<2)>>2]=d>>>1^0-(d&1);m=m+1|0;if(m>>>0>2]-c>>2>>>0){continue}break}break b}j=0}a=H[e+672>>2];if(!a){break a}H[e+676>>2]=a;oa(a)}ca=e+720|0;return j|0}function te(a,b,c,d,e){var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;h=ca-32|0;ca=h;H[b+32>>2]=d;H[b+40>>2]=c;H[b+4>>2]=e;nc(a,d,h+16|0);a:{if(H[a>>2]){break a}if(F[a+15|0]<0){oa(H[a+4>>2])}d=I[h+23|0];if((ea[H[H[b>>2]+8>>2]](b)|0)!=(d|0)){b=pa(64);F[b+50|0]=0;c=I[1314]|I[1315]<<8;F[b+48|0]=c;F[b+49|0]=c>>>8;c=I[1310]|I[1311]<<8|(I[1312]<<16|I[1313]<<24);d=I[1306]|I[1307]<<8|(I[1308]<<16|I[1309]<<24);F[b+40|0]=d;F[b+41|0]=d>>>8;F[b+42|0]=d>>>16;F[b+43|0]=d>>>24;F[b+44|0]=c;F[b+45|0]=c>>>8;F[b+46|0]=c>>>16;F[b+47|0]=c>>>24;c=I[1302]|I[1303]<<8|(I[1304]<<16|I[1305]<<24);d=I[1298]|I[1299]<<8|(I[1300]<<16|I[1301]<<24);F[b+32|0]=d;F[b+33|0]=d>>>8;F[b+34|0]=d>>>16;F[b+35|0]=d>>>24;F[b+36|0]=c;F[b+37|0]=c>>>8;F[b+38|0]=c>>>16;F[b+39|0]=c>>>24;c=I[1294]|I[1295]<<8|(I[1296]<<16|I[1297]<<24);d=I[1290]|I[1291]<<8|(I[1292]<<16|I[1293]<<24);F[b+24|0]=d;F[b+25|0]=d>>>8;F[b+26|0]=d>>>16;F[b+27|0]=d>>>24;F[b+28|0]=c;F[b+29|0]=c>>>8;F[b+30|0]=c>>>16;F[b+31|0]=c>>>24;c=I[1286]|I[1287]<<8|(I[1288]<<16|I[1289]<<24);d=I[1282]|I[1283]<<8|(I[1284]<<16|I[1285]<<24);F[b+16|0]=d;F[b+17|0]=d>>>8;F[b+18|0]=d>>>16;F[b+19|0]=d>>>24;F[b+20|0]=c;F[b+21|0]=c>>>8;F[b+22|0]=c>>>16;F[b+23|0]=c>>>24;c=I[1278]|I[1279]<<8|(I[1280]<<16|I[1281]<<24);d=I[1274]|I[1275]<<8|(I[1276]<<16|I[1277]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1270]|I[1271]<<8|(I[1272]<<16|I[1273]<<24);d=I[1266]|I[1267]<<8|(I[1268]<<16|I[1269]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;H[a>>2]=-1;za(a+4|0,b,50);oa(b);break a}c=I[h+21|0];F[b+36|0]=c;e=I[h+22|0];F[b+37|0]=e;if((c-3&255)>>>0<=253){b=pa(32);F[b+22|0]=0;c=I[1427]|I[1428]<<8|(I[1429]<<16|I[1430]<<24);d=I[1423]|I[1424]<<8|(I[1425]<<16|I[1426]<<24);F[b+14|0]=d;F[b+15|0]=d>>>8;F[b+16|0]=d>>>16;F[b+17|0]=d>>>24;F[b+18|0]=c;F[b+19|0]=c>>>8;F[b+20|0]=c>>>16;F[b+21|0]=c>>>24;c=I[1421]|I[1422]<<8|(I[1423]<<16|I[1424]<<24);d=I[1417]|I[1418]<<8|(I[1419]<<16|I[1420]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1413]|I[1414]<<8|(I[1415]<<16|I[1416]<<24);d=I[1409]|I[1410]<<8|(I[1411]<<16|I[1412]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;H[a>>2]=-5;za(a+4|0,b,22);oa(b);break a}if(!((c|0)!=2|e>>>0<=(d?2:3)>>>0)){b=pa(32);F[b+22|0]=0;c=I[1404]|I[1405]<<8|(I[1406]<<16|I[1407]<<24);d=I[1400]|I[1401]<<8|(I[1402]<<16|I[1403]<<24);F[b+14|0]=d;F[b+15|0]=d>>>8;F[b+16|0]=d>>>16;F[b+17|0]=d>>>24;F[b+18|0]=c;F[b+19|0]=c>>>8;F[b+20|0]=c>>>16;F[b+21|0]=c>>>24;c=I[1398]|I[1399]<<8|(I[1400]<<16|I[1401]<<24);d=I[1394]|I[1395]<<8|(I[1396]<<16|I[1397]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1390]|I[1391]<<8|(I[1392]<<16|I[1393]<<24);d=I[1386]|I[1387]<<8|(I[1388]<<16|I[1389]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;H[a>>2]=-5;za(a+4|0,b,22);oa(b);break a}c=e|c<<8;G[H[b+32>>2]+38>>1]=c;b:{if((c&65535)>>>0<259|G[h+26>>1]>=0){break b}i=ca-16|0;ca=i;e=pa(36);c=e;H[c+4>>2]=0;H[c+8>>2]=0;H[c+24>>2]=0;H[c+28>>2]=0;c=c+16|0;H[c>>2]=0;H[c+4>>2]=0;H[e>>2]=e+4;H[e+32>>2]=0;H[e+12>>2]=c;H[i>>2]=0;d=H[b+32>>2];j=ca-16|0;ca=j;c=0;c:{if(!e){break c}H[i>>2]=d;H[j+12>>2]=0;c=0;if(!Bb(1,j+12|0,d)){break c}m=H[j+12>>2];if(m){while(1){d:{if(Bb(1,j+8|0,H[i>>2])){c=pa(28);H[c+4>>2]=0;H[c+8>>2]=0;d=c+16|0;H[d>>2]=0;H[d+4>>2]=0;H[c>>2]=c+4;H[c+12>>2]=d;H[c+24>>2]=H[j+8>>2];if(ce(i,c)){break d}Ra(c+12|0,H[c+16>>2]);Qa(c,H[c+4>>2]);oa(c)}c=0;break c}f=ca-16|0;ca=f;H[f+8>>2]=c;e:{if(!c){break e}d=H[e+28>>2];f:{if(d>>>0>2]){H[f+8>>2]=0;H[d>>2]=c;H[e+28>>2]=d+4;break f}d=0;g:{h:{i:{g=H[e+24>>2];l=H[e+28>>2]-g>>2;c=l+1|0;if(c>>>0<1073741824){g=H[e+32>>2]-g|0;k=g>>>1|0;g=g>>>0>=2147483644?1073741823:c>>>0>>0?k:c;if(g){if(g>>>0>=1073741824){break i}d=pa(g<<2)}k=H[f+8>>2];H[f+8>>2]=0;c=(l<<2)+d|0;H[c>>2]=k;g=(g<<2)+d|0;l=c+4|0;d=H[e+28>>2];k=H[e+24>>2];if((d|0)==(k|0)){break h}while(1){d=d-4|0;o=H[d>>2];H[d>>2]=0;c=c-4|0;H[c>>2]=o;if((d|0)!=(k|0)){continue}break}H[e+32>>2]=g;g=H[e+28>>2];H[e+28>>2]=l;d=H[e+24>>2];H[e+24>>2]=c;if((d|0)==(g|0)){break g}while(1){g=g-4|0;c=H[g>>2];H[g>>2]=0;if(c){Ra(c+12|0,H[c+16>>2]);Qa(c,H[c+4>>2]);oa(c)}if((d|0)!=(g|0)){continue}break}break g}sa();v()}wa();v()}H[e+32>>2]=g;H[e+28>>2]=l;H[e+24>>2]=c}if(d){oa(d)}}c=H[f+8>>2];H[f+8>>2]=0;if(!c){break e}Ra(c+12|0,H[c+16>>2]);Qa(c,H[c+4>>2]);oa(c)}ca=f+16|0;n=n+1|0;if((m|0)!=(n|0)){continue}break}}c=ce(i,e)}ca=j+16|0;j:{if(c){d=H[b+4>>2];c=H[d+4>>2];H[d+4>>2]=e;if(c){Uc(c)}H[a>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0;break j}c=pa(32);F[c+26|0]=0;d=I[1579]|I[1580]<<8;F[c+24|0]=d;F[c+25|0]=d>>>8;d=I[1575]|I[1576]<<8|(I[1577]<<16|I[1578]<<24);f=I[1571]|I[1572]<<8|(I[1573]<<16|I[1574]<<24);F[c+16|0]=f;F[c+17|0]=f>>>8;F[c+18|0]=f>>>16;F[c+19|0]=f>>>24;F[c+20|0]=d;F[c+21|0]=d>>>8;F[c+22|0]=d>>>16;F[c+23|0]=d>>>24;d=I[1567]|I[1568]<<8|(I[1569]<<16|I[1570]<<24);f=I[1563]|I[1564]<<8|(I[1565]<<16|I[1566]<<24);F[c+8|0]=f;F[c+9|0]=f>>>8;F[c+10|0]=f>>>16;F[c+11|0]=f>>>24;F[c+12|0]=d;F[c+13|0]=d>>>8;F[c+14|0]=d>>>16;F[c+15|0]=d>>>24;d=I[1559]|I[1560]<<8|(I[1561]<<16|I[1562]<<24);f=I[1555]|I[1556]<<8|(I[1557]<<16|I[1558]<<24);F[c|0]=f;F[c+1|0]=f>>>8;F[c+2|0]=f>>>16;F[c+3|0]=f>>>24;F[c+4|0]=d;F[c+5|0]=d>>>8;F[c+6|0]=d>>>16;F[c+7|0]=d>>>24;H[a>>2]=-1;za(a+4|0,c,26);oa(c);H[i+8>>2]=0;Uc(e)}ca=i+16|0;if(H[a>>2]){break a}if(F[a+15|0]>=0){break b}oa(H[a+4>>2])}if(!(ea[H[H[b>>2]+12>>2]](b)|0)){b=pa(48);F[b+33|0]=0;F[b+32|0]=I[1384];c=I[1380]|I[1381]<<8|(I[1382]<<16|I[1383]<<24);d=I[1376]|I[1377]<<8|(I[1378]<<16|I[1379]<<24);F[b+24|0]=d;F[b+25|0]=d>>>8;F[b+26|0]=d>>>16;F[b+27|0]=d>>>24;F[b+28|0]=c;F[b+29|0]=c>>>8;F[b+30|0]=c>>>16;F[b+31|0]=c>>>24;c=I[1372]|I[1373]<<8|(I[1374]<<16|I[1375]<<24);d=I[1368]|I[1369]<<8|(I[1370]<<16|I[1371]<<24);F[b+16|0]=d;F[b+17|0]=d>>>8;F[b+18|0]=d>>>16;F[b+19|0]=d>>>24;F[b+20|0]=c;F[b+21|0]=c>>>8;F[b+22|0]=c>>>16;F[b+23|0]=c>>>24;c=I[1364]|I[1365]<<8|(I[1366]<<16|I[1367]<<24);d=I[1360]|I[1361]<<8|(I[1362]<<16|I[1363]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1356]|I[1357]<<8|(I[1358]<<16|I[1359]<<24);d=I[1352]|I[1353]<<8|(I[1354]<<16|I[1355]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;H[a>>2]=-1;za(a+4|0,b,33);oa(b);break a}if(!(ea[H[H[b>>2]+20>>2]](b)|0)){b=mc(h,1582);H[a>>2]=-1;a=a+4|0;if(F[b+11|0]>=0){c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c;H[a+8>>2]=H[b+8>>2];break a}za(a,H[b>>2],H[b+4>>2]);if(F[b+11|0]>=0){break a}oa(H[b>>2]);break a}if(!(ea[H[H[b>>2]+24>>2]](b)|0)){b=mc(h,1317);H[a>>2]=-1;a=a+4|0;if(F[b+11|0]>=0){c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c;H[a+8>>2]=H[b+8>>2];break a}za(a,H[b>>2],H[b+4>>2]);if(F[b+11|0]>=0){break a}oa(H[b>>2]);break a}H[a>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0}ca=h+32|0}function pg(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0;m=ca-16|0;ca=m;H[m+12>>2]=b;b=pa(32);H[m>>2]=b;H[m+4>>2]=24;H[m+8>>2]=-2147483616;c=I[1206]|I[1207]<<8|(I[1208]<<16|I[1209]<<24);d=I[1202]|I[1203]<<8|(I[1204]<<16|I[1205]<<24);F[b+16|0]=d;F[b+17|0]=d>>>8;F[b+18|0]=d>>>16;F[b+19|0]=d>>>24;F[b+20|0]=c;F[b+21|0]=c>>>8;F[b+22|0]=c>>>16;F[b+23|0]=c>>>24;c=I[1198]|I[1199]<<8|(I[1200]<<16|I[1201]<<24);d=I[1194]|I[1195]<<8|(I[1196]<<16|I[1197]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1190]|I[1191]<<8|(I[1192]<<16|I[1193]<<24);d=I[1186]|I[1187]<<8|(I[1188]<<16|I[1189]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;F[b+24|0]=0;l=ca-48|0;ca=l;f=H[m+12>>2];d=a;a=a+16|0;b=H[a>>2];a:{b:{if(!b){break b}c=a;while(1){e=(f|0)>H[b+16>>2];c=e?c:b;b=H[(e?b+4|0:b)>>2];if(b){continue}break}if((a|0)==(c|0)){break b}if((f|0)>=H[c+16>>2]){break a}}H[l+28>>2]=0;H[l+32>>2]=0;y=l+24|0;H[l+24>>2]=y|4;a=l+16|0;H[a>>2]=0;H[a+4>>2]=0;H[l+8>>2]=f;H[l+12>>2]=a;t=l+8|0;a=t;x=ca-16|0;ca=x;u=d+12|0;c=H[u+4>>2];c:{d:{if(!c){o=u+4|0;d=o;break d}a=H[a>>2];while(1){d=c;b=H[c+16>>2];if((b|0)>(a|0)){o=d;c=H[d>>2];if(c){continue}break d}if((a|0)<=(b|0)){g=d;a=0;break c}c=H[d+4>>2];if(c){continue}break}o=d+4|0}g=pa(32);b=H[t>>2];q=g+24|0;a=q;H[a>>2]=0;H[a+4>>2]=0;H[g+16>>2]=b;r=g+20|0;H[r>>2]=a;c=H[t+4>>2];z=t+8|0;if((c|0)!=(z|0)){while(1){p=ca-16|0;ca=p;a=p+8|0;k=c+16|0;e:{f:{g:{h:{i:{j:{k:{f=q;e=r+4|0;l:{if((f|0)==(e|0)){break l}b=I[f+27|0];h=b<<24>>24<0;i=I[k+11|0];n=i<<24>>24;j=(n|0)<0;i=j?H[k+4>>2]:i;b=h?H[f+20>>2]:b;s=i>>>0>b>>>0;w=s?b:i;if(w){j=j?H[k>>2]:k;h=h?H[f+16>>2]:f+16|0;A=Fa(j,h,w);if(!A){if(b>>>0>i>>>0){break l}break k}if((A|0)>=0){break k}break l}if(b>>>0<=i>>>0){break j}}h=H[f>>2];m:{a=f;n:{if((a|0)==H[r>>2]){break n}o:{if(!h){b=f;while(1){a=H[b+8>>2];i=H[a>>2]==(b|0);b=a;if(i){continue}break}break o}b=h;while(1){a=b;b=H[b+4>>2];if(b){continue}break}}i=I[k+11|0];s=i<<24>>24;b=(s|0)<0;j=I[a+27|0];n=j<<24>>24<0;p:{i=b?H[k+4>>2]:i;j=n?H[a+20>>2]:j;w=i>>>0>>0?i:j;if(w){b=Fa(n?H[a+16>>2]:a+16|0,b?H[k>>2]:k,w);if(b){break p}}if(i>>>0>j>>>0){break n}break m}if((b|0)>=0){break m}}if(!h){H[p+12>>2]=f;a=f;break e}H[p+12>>2]=a;a=a+4|0;break e}b=H[e>>2];if(!b){H[p+12>>2]=e;a=e;break e}h=(s|0)<0?H[k>>2]:k;f=e;while(1){a=b;b=I[b+27|0];e=b<<24>>24<0;b=e?H[a+20>>2]:b;k=b>>>0>>0;q:{r:{s:{t:{n=k?b:i;u:{if(n){e=e?H[a+16>>2]:a+16|0;j=Fa(h,e,n);if(!j){if(b>>>0>i>>>0){break u}break t}if((j|0)>=0){break t}break u}if(b>>>0<=i>>>0){break s}}f=a;b=H[a>>2];if(b){continue}break g}b=Fa(e,h,n);if(b){break r}}if(k){break q}break g}if((b|0)>=0){break g}}f=a+4|0;b=H[a+4>>2];if(b){continue}break}break g}b=Fa(h,j,w);if(b){break i}}if(s){break h}break f}if((b|0)>=0){break f}}h=H[f+4>>2];v:{if(!h){b=f;while(1){a=H[b+8>>2];j=H[a>>2]!=(b|0);b=a;if(j){continue}break}break v}b=h;while(1){a=b;b=H[b>>2];if(b){continue}break}}w:{x:{if((a|0)==(e|0)){break x}j=I[a+27|0];b=j<<24>>24<0;y:{j=b?H[a+20>>2]:j;s=i>>>0>j>>>0?j:i;if(s){b=Fa((n|0)<0?H[k>>2]:k,b?H[a+16>>2]:a+16|0,s);if(b){break y}}if(i>>>0>>0){break x}break w}if((b|0)>=0){break w}}if(!h){H[p+12>>2]=f;a=f+4|0;break e}H[p+12>>2]=a;break e}b=H[e>>2];if(!b){H[p+12>>2]=e;a=e;break e}h=(n|0)<0?H[k>>2]:k;f=e;while(1){a=b;b=I[b+27|0];e=b<<24>>24<0;b=e?H[a+20>>2]:b;k=b>>>0>>0;z:{A:{B:{C:{n=k?b:i;D:{if(n){e=e?H[a+16>>2]:a+16|0;j=Fa(h,e,n);if(!j){if(b>>>0>i>>>0){break D}break C}if((j|0)>=0){break C}break D}if(b>>>0<=i>>>0){break B}}f=a;b=H[a>>2];if(b){continue}break g}b=Fa(e,h,n);if(b){break A}}if(k){break z}break g}if((b|0)>=0){break g}}f=a+4|0;b=H[a+4>>2];if(b){continue}break}}H[p+12>>2]=a;a=f;break e}H[p+12>>2]=f;H[a>>2]=f}f=a;a=H[a>>2];if(a){b=0}else{a=pa(40);b=a+16|0;E:{if(F[c+27|0]>=0){e=H[c+20>>2];H[b>>2]=H[c+16>>2];H[b+4>>2]=e;H[b+8>>2]=H[c+24>>2];break E}za(b,H[c+16>>2],H[c+20>>2])}b=a+28|0;F:{if(F[c+39|0]>=0){e=H[c+32>>2];H[b>>2]=H[c+28>>2];H[b+4>>2]=e;H[b+8>>2]=H[c+36>>2];break F}za(b,H[c+28>>2],H[c+32>>2])}H[a+8>>2]=H[p+12>>2];H[a>>2]=0;H[a+4>>2]=0;H[f>>2]=a;b=a;e=H[H[r>>2]>>2];if(e){H[r>>2]=e;b=H[f>>2]}Sb(H[r+4>>2],b);H[r+8>>2]=H[r+8>>2]+1;b=1}F[x+12|0]=b;H[x+8>>2]=a;ca=p+16|0;b=H[c+4>>2];G:{if(b){while(1){c=b;b=H[b>>2];if(b){continue}break G}}while(1){a=c;c=H[c+8>>2];if((a|0)!=H[c>>2]){continue}break}}if((c|0)!=(z|0)){continue}break}}H[g+8>>2]=d;H[g>>2]=0;H[g+4>>2]=0;H[o>>2]=g;c=g;a=H[H[u>>2]>>2];if(a){H[u>>2]=a;c=H[o>>2]}Sb(H[u+4>>2],c);H[u+8>>2]=H[u+8>>2]+1;a=1}F[l+44|0]=a;H[l+40>>2]=g;ca=x+16|0;c=H[l+40>>2];Kb(t|4,H[l+16>>2]);Kb(y,H[l+28>>2])}f=ca-48|0;ca=f;d=f+8|0;g=ca-32|0;ca=g;o=g+32|0;b=o;a=g+21|0;H:{if((b|0)==(a|0)){break H}}e=b-a|0;I:{if((e|0)<=9){h=61;if((e|0)<(K[3660]<=1|0)){break I}}F[a|0]=49;b=a+1|0;h=0}H[g+12>>2]=h;H[g+8>>2]=b;h=ca-16|0;ca=h;e=ca-16|0;ca=e;J:{q=H[g+8>>2];g=q-a|0;if(g>>>0<=2147483631){K:{if(g>>>0<11){F[d+11|0]=g|I[d+11|0]&128;F[d+11|0]=I[d+11|0]&127;b=d;break K}t=e+8|0;if(g>>>0>=11){k=g+16&-16;b=k-1|0;b=(b|0)==11?k:b}else{b=10}Zb(t,b+1|0);b=H[e+8>>2];H[d>>2]=b;H[d+8>>2]=H[d+8>>2]&-2147483648|H[e+12>>2]&2147483647;H[d+8>>2]=H[d+8>>2]|-2147483648;H[d+4>>2]=g}while(1){if((a|0)!=(q|0)){F[b|0]=I[a|0];b=b+1|0;a=a+1|0;continue}break}F[e+7|0]=0;F[b|0]=I[e+7|0];ca=e+16|0;break J}Na();v()}ca=h+16|0;ca=o;H[f+32>>2]=m;L:{M:{a=c+20|0;d=H[a+4>>2];N:{if(!d){g=a+4|0;c=g;break N}b=I[m+11|0];c=b<<24>>24<0;e=c?H[m>>2]:m;b=c?H[m+4>>2]:b;while(1){c=d;d=I[c+27|0];g=d<<24>>24<0;d=g?H[c+20>>2]:d;o=d>>>0>>0;O:{P:{Q:{R:{h=o?d:b;S:{if(h){g=g?H[c+16>>2]:c+16|0;q=Fa(e,g,h);if(!q){if(b>>>0>>0){break S}break R}if((q|0)>=0){break R}break S}if(b>>>0>=d>>>0){break Q}}g=c;d=H[c>>2];if(d){continue}break N}d=Fa(g,e,h);if(d){break P}}if(o){break O}break M}if((d|0)>=0){break M}}d=H[c+4>>2];if(d){continue}break}g=c+4|0}d=pa(40);e=d+16|0;b=H[f+32>>2];T:{if(F[b+11|0]>=0){o=H[b+4>>2];H[e>>2]=H[b>>2];H[e+4>>2]=o;H[e+8>>2]=H[b+8>>2];break T}za(e,H[b>>2],H[b+4>>2])}H[d+8>>2]=c;H[d>>2]=0;H[d+4>>2]=0;H[d+36>>2]=0;H[d+28>>2]=0;H[d+32>>2]=0;H[g>>2]=d;c=d;b=H[H[a>>2]>>2];if(b){H[a>>2]=b;c=H[g>>2]}Sb(H[a+4>>2],c);H[a+8>>2]=H[a+8>>2]+1;a=1;break L}d=c;a=0}F[f+44|0]=a;H[f+40>>2]=d;a=H[f+40>>2];if(F[a+39|0]<0){oa(H[a+28>>2])}b=H[f+12>>2];H[a+28>>2]=H[f+8>>2];H[a+32>>2]=b;H[a+36>>2]=H[f+16>>2];ca=f+48|0;ca=l+48|0;if(F[m+11|0]<0){oa(H[m>>2])}ca=m+16|0}function Bd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0;j=H[b+8>>2];e=H[b+12>>2];g=H[b+20>>2];h=H[b+16>>2];k=h+4|0;g=k>>>0<4?g+1|0:g;a:{if(j>>>0>>0&(e|0)<=(g|0)|(e|0)<(g|0)){break a}h=h+H[b>>2]|0;H[a>>2]=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);h=H[b+20>>2];e=h;j=H[b+16>>2];g=j+4|0;h=g>>>0<4?e+1|0:e;H[b+16>>2]=g;H[b+20>>2]=h;if(K[a>>2]>32){break a}l=H[b+8>>2];k=H[b+12>>2];h=e;e=j+8|0;h=e>>>0<8?h+1|0:h;if(e>>>0>l>>>0&(h|0)>=(k|0)|(h|0)>(k|0)){break a}h=H[b>>2]+g|0;g=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);H[a+4>>2]=g;h=H[b+20>>2];e=H[b+16>>2]+4|0;h=e>>>0<4?h+1|0:h;H[b+16>>2]=e;H[b+20>>2]=h;if(!g){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!ua(a+16|0,b)){break a}if(!ua(a+36|0,b)){break a}if(!ua(a+56|0,b)){break a}if(!ua(a+76|0,b)){break a}s=H[a+4>>2];h=c;b=0;g=0;e=ca-32|0;ca=e;d=a;a=H[a+12>>2];H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}c=a<<2;b=pa(c);H[e+8>>2]=b;g=b+c|0;H[e+16>>2]=g;ra(b,0,c);H[e+12>>2]=g}c=H[d+120>>2];i=H[c>>2];if(i){H[c+4>>2]=i;oa(i);g=H[e+12>>2];b=H[e+8>>2];a=H[d+12>>2]}H[c+4>>2]=g;H[c>>2]=b;H[c+8>>2]=H[e+16>>2];b=0;H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;f=pa(a);H[e+8>>2]=f;b=a+f|0;H[e+16>>2]=b;ra(f,0,a);H[e+12>>2]=b}a=H[d+132>>2];c=H[a>>2];if(c){H[a+4>>2]=c;oa(c);f=H[e+8>>2];b=H[e+12>>2]}H[a+4>>2]=b;H[a>>2]=f;H[a+8>>2]=H[e+16>>2];H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;xa(e+8|0);a=H[e+24>>2]+H[e+28>>2]|0;b=(a>>>0)/341|0;a=H[H[e+12>>2]+(b<<2)>>2]+N(a-N(b,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=s;c=1;a=H[e+28>>2]+1|0;H[e+28>>2]=a;e:{if(!a){break e}while(1){b=H[e+12>>2];f=H[e+24>>2];k=a-1|0;c=f+k|0;i=(c>>>0)/341|0;c=H[b+(i<<2)>>2]+N(c-N(i,341)|0,12)|0;g=H[c+8>>2];i=H[c+4>>2];j=H[c>>2];H[e+28>>2]=k;c=H[e+16>>2];if((((b|0)!=(c|0)?N(c-b>>2,341)-1|0:0)-(a+f|0)|0)+1>>>0>=682){oa(H[c-4>>2]);H[e+16>>2]=H[e+16>>2]-4}c=0;if(j>>>0>s>>>0){break e}b=H[d+12>>2];a=(b-1|0)!=(i|0)?i+1|0:0;if(a>>>0>=b>>>0){break e}f=N(g,12);o=f+H[d+132>>2]|0;k=f+H[d+120>>2]|0;i=H[d>>2];l=a<<2;m=H[l+H[o>>2]>>2];f:{g:{if((i|0)==(m|0)){if(!j){break g}o=0;b=H[h+20>>2];g=H[h+16>>2];if((b|0)==(g|0)){a=H[d+8>>2];H[h+28>>2]=j+H[h+28>>2];H[d+8>>2]=a+j;break g}while(1){c=(b|0)==(g|0);a=b;i=0;b=g;h:{if(c){break h}while(1){f=H[h+28>>2];b=a;c=N(i,20)+g|0;l=H[c>>2];if(!I[l+84|0]){f=H[H[l+68>>2]+(f<<2)>>2]}if(K[l+80>>2]<=f>>>0){break h}m=H[k>>2]+(H[c+4>>2]<<2)|0;g=H[c+12>>2];b=m;i:{if(g>>>0>3){break i}a=0;b=H[h+12>>2];if(!H[c+16>>2]){break i}while(1){b=qa(b,m+(a<<2)|0,g);g=H[c+12>>2];b=b+g|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[h+12>>2]}a=H[l+40>>2];qa(H[H[l>>2]>>2]+N(a,f)|0,b,a);i=i+1|0;a=H[h+20>>2];b=a;g=H[h+16>>2];if(i>>>0<(b-g|0)/20>>>0){continue}break}}H[h+28>>2]=H[h+28>>2]+1;H[d+8>>2]=H[d+8>>2]+1;o=o+1|0;if((j|0)!=(o|0)){continue}break}break g}j:{k:{l:{m:{if(j>>>0<=2){c=H[d+108>>2];H[c>>2]=a;f=1;b=H[d+12>>2];if(b>>>0>1){break m}break j}if(K[d+8>>2]>K[d+4>>2]){break e}b=H[d+120>>2];n=g+1|0;o=N(n,12);p=b+o|0;if((p|0)!=(k|0)){Aa(p,H[k>>2],H[k+4>>2]);b=H[d+120>>2]}b=l+H[b+o>>2]|0;H[b>>2]=H[b>>2]+(1<>2];m=32-i|0;n:{if((b|0)<=(m|0)){k=H[d+28>>2];if((k|0)==H[d+20>>2]){break l}m=H[k>>2];p=b+i|0;H[d+32>>2]=p;b=m<>>32-b|0;if((p|0)!=32){break n}H[d+32>>2]=0;H[d+28>>2]=k+4;break n}k=H[d+28>>2];p=k+4|0;if((p|0)==H[d+20>>2]){break l}r=H[k>>2];H[d+28>>2]=p;m=b-m|0;H[d+32>>2]=m;b=H[k+4>>2]>>>32-m|r<>>32-b}i=j>>>1|0;if(i>>>0>>0){break e}break k}while(1){a=(b-1|0)!=(a|0)?a+1|0:0;H[c+(f<<2)>>2]=a;b=H[d+12>>2];f=f+1|0;if(b>>>0>f>>>0){continue}break}break j}i=j>>>1|0;b=0}o:{p:{b=i-b|0;c=j-b|0;q:{if((c|0)==(b|0)){c=b;break q}i=H[d+88>>2];if((i|0)==H[d+80>>2]){break p}j=H[i>>2];k=H[d+92>>2];m=k+1|0;H[d+92>>2]=m;j=j&-2147483648>>>k;r:{if((m|0)==32){H[d+92>>2]=0;H[d+88>>2]=i+4;if(j){break r}break p}if(!j){break p}}}i=c;c=b;break o}i=b}b=H[d+132>>2];j=b+f|0;f=H[j>>2];k=f+l|0;H[k>>2]=H[k>>2]+1;Aa(b+o|0,f,H[j+4>>2]);if(c){b=H[e+28>>2]+H[e+24>>2]|0;j=H[e+16>>2];f=H[e+12>>2];if((b|0)==(((f|0)!=(j|0)?N(j-f>>2,341)-1|0:0)|0)){xa(e+8|0);f=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}j=(b>>>0)/341|0;b=H[(j<<2)+f>>2]+N(b-N(j,341)|0,12)|0;H[b+8>>2]=g;H[b+4>>2]=a;H[b>>2]=c;H[e+28>>2]=H[e+28>>2]+1}if(!i){break g}b=H[e+28>>2]+H[e+24>>2]|0;c=H[e+16>>2];f=H[e+12>>2];if((b|0)==(((c|0)!=(f|0)?N(c-f>>2,341)-1|0:0)|0)){xa(e+8|0);f=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}c=(b>>>0)/341|0;b=H[(c<<2)+f>>2]+N(b-N(c,341)|0,12)|0;H[b+8>>2]=n;H[b+4>>2]=a;H[b>>2]=i;a=H[e+28>>2]+1|0;H[e+28>>2]=a;break f}m=0;if(!j){break g}while(1){if(H[d+12>>2]){i=H[d+40>>2];p=H[o>>2];c=H[d+96>>2];r=H[d+108>>2];a=0;while(1){g=r+(a<<2)|0;H[c+(H[g>>2]<<2)>>2]=0;b=H[d>>2];f=H[g>>2]<<2;l=H[f+p>>2];s:{if((b|0)==(l|0)){break s}f=c+f|0;b=b-l|0;l=H[d+52>>2];q=32-l|0;if((b|0)<=(q|0)){n=H[d+48>>2];if((n|0)==(i|0)){c=0;break e}H[f>>2]=H[n>>2]<>>32-b;b=b+H[d+52>>2]|0;H[d+52>>2]=b;if((b|0)!=32){break s}H[d+52>>2]=0;H[d+48>>2]=n+4;break s}n=H[d+48>>2];t=n+4|0;if((i|0)==(t|0)){c=0;break e}u=H[n>>2];H[d+48>>2]=t;q=b-q|0;H[d+52>>2]=q;H[f>>2]=H[n+4>>2]>>>32-q|u<>>32-b}b=H[g>>2]<<2;g=b+c|0;H[g>>2]=H[g>>2]|H[b+H[k>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}i=0;a=H[h+16>>2];t:{if((a|0)==H[h+20>>2]){break t}while(1){f=H[h+28>>2];c=N(i,20)+a|0;l=H[c>>2];if(!I[l+84|0]){f=H[H[l+68>>2]+(f<<2)>>2]}if(K[l+80>>2]<=f>>>0){break t}n=H[d+96>>2]+(H[c+4>>2]<<2)|0;g=H[c+12>>2];b=n;u:{if(g>>>0>3){break u}a=0;b=H[h+12>>2];if(!H[c+16>>2]){break u}while(1){b=qa(b,n+(a<<2)|0,g);g=H[c+12>>2];b=b+g|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[h+12>>2]}a=H[l+40>>2];qa(H[H[l>>2]>>2]+N(a,f)|0,b,a);i=i+1|0;a=H[h+16>>2];if(i>>>0<(H[h+20>>2]-a|0)/20>>>0){continue}break}}H[h+28>>2]=H[h+28>>2]+1;H[d+8>>2]=H[d+8>>2]+1;m=m+1|0;if((j|0)!=(m|0)){continue}break}}a=H[e+28>>2]}if(a){continue}break}c=1}H[e+28>>2]=0;f=H[e+16>>2];a=H[e+12>>2];b=f-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[e+12>>2]+4|0;H[e+12>>2]=a;f=H[e+16>>2];b=f-a|0;if(b>>>0>8){continue}break}}g=170;v:{switch((b>>>2|0)-1|0){case 1:g=341;case 0:H[e+24>>2]=g;break;default:break v}}w:{if((a|0)==(f|0)){break w}while(1){oa(H[a>>2]);a=a+4|0;if((f|0)!=(a|0)){continue}break}a=H[e+16>>2];b=H[e+12>>2];if((a|0)==(b|0)){break w}H[e+16>>2]=a+((b-a|0)+3&-4)}a=H[e+8>>2];if(a){oa(a)}ca=e+32|0;break b}sa();v()}sa();v()}i=c}return i}function zd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0;j=H[b+8>>2];l=H[b+12>>2];k=H[b+20>>2];i=H[b+16>>2];f=i+4|0;k=f>>>0<4?k+1|0:k;a:{if(f>>>0>j>>>0&(k|0)>=(l|0)|(k|0)>(l|0)){break a}i=i+H[b>>2]|0;H[a>>2]=I[i|0]|I[i+1|0]<<8|(I[i+2|0]<<16|I[i+3|0]<<24);i=H[b+20>>2];j=i;f=H[b+16>>2];i=f+4|0;l=i>>>0<4?j+1|0:j;H[b+16>>2]=i;H[b+20>>2]=l;if(K[a>>2]>32){break a}l=H[b+8>>2];k=H[b+12>>2];f=f+8|0;j=f>>>0<8?j+1|0:j;if((k|0)<=(j|0)&f>>>0>l>>>0|(k|0)<(j|0)){break a}i=H[b>>2]+i|0;f=I[i|0]|I[i+1|0]<<8|(I[i+2|0]<<16|I[i+3|0]<<24);H[a+4>>2]=f;j=H[b+20>>2];i=H[b+16>>2]+4|0;j=i>>>0<4?j+1|0:j;H[b+16>>2]=i;H[b+20>>2]=j;if(!f){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!ua(a+16|0,b)){break a}if(!ua(a+36|0,b)){break a}if(!ua(a+56|0,b)){break a}if(!ua(a+76|0,b)){break a}t=H[a+4>>2];i=c;b=0;c=0;e=ca-32|0;ca=e;f=a;a=H[a+12>>2];H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}d=a<<2;b=pa(d);H[e+8>>2]=b;c=b+d|0;H[e+16>>2]=c;ra(b,0,d);H[e+12>>2]=c}g=H[f+120>>2];d=H[g>>2];if(d){H[g+4>>2]=d;oa(d);c=H[e+12>>2];b=H[e+8>>2];a=H[f+12>>2]}H[g+4>>2]=c;H[g>>2]=b;H[g+8>>2]=H[e+16>>2];b=0;H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;h=pa(a);H[e+8>>2]=h;b=a+h|0;H[e+16>>2]=b;ra(h,0,a);H[e+12>>2]=b}c=H[f+132>>2];a=H[c>>2];if(a){H[c+4>>2]=a;oa(a);h=H[e+8>>2];b=H[e+12>>2]}H[c+4>>2]=b;H[c>>2]=h;H[c+8>>2]=H[e+16>>2];H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;xa(e+8|0);b=H[e+24>>2]+H[e+28>>2]|0;a=(b>>>0)/341|0;a=H[H[e+12>>2]+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=t;d=1;a=H[e+28>>2]+1|0;H[e+28>>2]=a;e:{if(!a){break e}while(1){j=H[e+12>>2];g=H[e+24>>2];d=a-1|0;c=g+d|0;b=(c>>>0)/341|0;b=H[j+(b<<2)>>2]+N(c-N(b,341)|0,12)|0;n=H[b+8>>2];c=H[b+4>>2];m=H[b>>2];H[e+28>>2]=d;b=H[e+16>>2];if((((b|0)!=(j|0)?N(b-j>>2,341)-1|0:0)-(a+g|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[e+16>>2]=H[e+16>>2]-4}if(m>>>0>t>>>0){d=0;break e}d=0;b=H[f+12>>2];a=(c|0)!=(b-1|0)?c+1|0:0;if(a>>>0>=b>>>0){break e}b=H[f+120>>2];o=N(n,12);q=b+o|0;g=H[f>>2];h=a<<2;l=o+H[f+132>>2]|0;c=H[h+H[l>>2]>>2];f:{g:{if((g|0)==(c|0)){if(!m){break g}h=0;b=H[i+20>>2];c=H[i+16>>2];if((b|0)==(c|0)){a=H[f+8>>2];H[i+28>>2]=m+H[i+28>>2];H[f+8>>2]=a+m;break g}while(1){d=(b|0)==(c|0);a=b;g=0;b=c;h:{if(d){break h}while(1){d=H[i+28>>2];b=a;k=N(g,20)+c|0;l=H[k>>2];if(!I[l+84|0]){d=H[H[l+68>>2]+(d<<2)>>2]}if(K[l+80>>2]<=d>>>0){break h}j=H[q>>2]+(H[k+4>>2]<<2)|0;c=H[k+12>>2];b=j;i:{if(c>>>0>3){break i}a=0;b=H[i+12>>2];if(!H[k+16>>2]){break i}while(1){b=qa(b,j+(a<<2)|0,c);c=H[k+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[i+12>>2]}a=H[l+40>>2];qa(H[H[l>>2]>>2]+N(a,d)|0,b,a);g=g+1|0;a=H[i+20>>2];b=a;c=H[i+16>>2];if(g>>>0<(b-c|0)/20>>>0){continue}break}}H[i+28>>2]=H[i+28>>2]+1;H[f+8>>2]=H[f+8>>2]+1;h=h+1|0;if((m|0)!=(h|0)){continue}break}break g}j:{k:{l:{m:{if(m>>>0<=2){c=H[f+108>>2];H[c>>2]=a;h=1;b=H[f+12>>2];if(b>>>0>1){break m}break j}if(K[f+8>>2]>K[f+4>>2]){break e}j=b;b=o+12|0;Aa(j+b|0,H[q>>2],H[q+4>>2]);b=h+H[b+H[f+120>>2]>>2]|0;H[b>>2]=H[b>>2]+(1<>2];g=32-l|0;n:{if((k|0)<=(g|0)){g=H[f+28>>2];if((g|0)==H[f+20>>2]){break l}c=H[g>>2];b=k+l|0;H[f+32>>2]=b;c=c<>>32-k|0;if((b|0)!=32){break n}H[f+32>>2]=0;H[f+28>>2]=g+4;break n}j=H[f+28>>2];b=j+4|0;if((b|0)==H[f+20>>2]){break l}c=H[j>>2];H[f+28>>2]=b;b=k-g|0;H[f+32>>2]=b;c=H[j+4>>2]>>>32-b|c<>>32-k}g=m>>>1|0;if(g>>>0>>0){break e}break k}while(1){a=(b-1|0)!=(a|0)?a+1|0:0;H[c+(h<<2)>>2]=a;b=H[f+12>>2];h=h+1|0;if(b>>>0>h>>>0){continue}break}break j}g=m>>>1|0;c=0}k=n+1|0;o:{p:{b=g-c|0;c=m-b|0;q:{if((c|0)==(b|0)){c=b;break q}l=H[f+88>>2];if((l|0)==H[f+80>>2]){break p}j=H[l>>2];g=H[f+92>>2];d=g+1|0;H[f+92>>2]=d;g=j&-2147483648>>>g;r:{if((d|0)==32){H[f+92>>2]=0;H[f+88>>2]=l+4;if(g){break r}break p}if(!g){break p}}}g=c;c=b;break o}g=b}l=H[f+132>>2];j=l+o|0;d=H[j>>2];b=d+h|0;H[b>>2]=H[b>>2]+1;Aa(l+N(k,12)|0,d,H[j+4>>2]);if(c){b=H[e+28>>2]+H[e+24>>2]|0;d=H[e+16>>2];h=H[e+12>>2];if((b|0)==(((d|0)!=(h|0)?N(d-h>>2,341)-1|0:0)|0)){xa(e+8|0);h=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}d=(b>>>0)/341|0;b=H[(d<<2)+h>>2]+N(b-N(d,341)|0,12)|0;H[b+8>>2]=n;H[b+4>>2]=a;H[b>>2]=c;H[e+28>>2]=H[e+28>>2]+1}if(!g){break g}b=H[e+28>>2]+H[e+24>>2]|0;c=H[e+16>>2];h=H[e+12>>2];if((b|0)==(((c|0)!=(h|0)?N(c-h>>2,341)-1|0:0)|0)){xa(e+8|0);h=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}c=(b>>>0)/341|0;b=H[(c<<2)+h>>2]+N(b-N(c,341)|0,12)|0;H[b+8>>2]=k;H[b+4>>2]=a;H[b>>2]=g;a=H[e+28>>2]+1|0;H[e+28>>2]=a;break f}r=0;if(!m){break g}while(1){if(H[f+12>>2]){u=H[f+40>>2];j=H[l>>2];s=H[f+96>>2];g=H[f+108>>2];a=0;while(1){n=(a<<2)+g|0;H[s+(H[n>>2]<<2)>>2]=0;d=H[f>>2];c=H[n>>2]<<2;b=H[c+j>>2];s:{if((d|0)==(b|0)){break s}o=c+s|0;p=d-b|0;h=H[f+52>>2];d=32-h|0;if((p|0)<=(d|0)){c=H[f+48>>2];if((c|0)==(u|0)){d=0;break e}H[o>>2]=H[c>>2]<>>32-p;b=p+H[f+52>>2]|0;H[f+52>>2]=b;if((b|0)!=32){break s}H[f+52>>2]=0;H[f+48>>2]=c+4;break s}k=H[f+48>>2];b=k+4|0;if((u|0)==(b|0)){d=0;break e}c=H[k>>2];H[f+48>>2]=b;b=p-d|0;H[f+52>>2]=b;H[o>>2]=H[k+4>>2]>>>32-b|c<>>32-p}c=H[n>>2]<<2;b=c+s|0;H[b>>2]=H[b>>2]|H[c+H[q>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}g=0;a=H[i+16>>2];t:{if((a|0)==H[i+20>>2]){break t}while(1){d=H[i+28>>2];h=N(g,20)+a|0;k=H[h>>2];if(!I[k+84|0]){d=H[H[k+68>>2]+(d<<2)>>2]}if(K[k+80>>2]<=d>>>0){break t}j=H[f+96>>2]+(H[h+4>>2]<<2)|0;c=H[h+12>>2];b=j;u:{if(c>>>0>3){break u}a=0;b=H[i+12>>2];if(!H[h+16>>2]){break u}while(1){b=qa(b,j+(a<<2)|0,c);c=H[h+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[i+12>>2]}a=H[k+40>>2];qa(H[H[k>>2]>>2]+N(a,d)|0,b,a);g=g+1|0;a=H[i+16>>2];if(g>>>0<(H[i+20>>2]-a|0)/20>>>0){continue}break}}H[i+28>>2]=H[i+28>>2]+1;H[f+8>>2]=H[f+8>>2]+1;r=r+1|0;if((m|0)!=(r|0)){continue}break}}a=H[e+28>>2]}if(a){continue}break}d=1}H[e+28>>2]=0;h=H[e+16>>2];a=H[e+12>>2];b=h-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[e+12>>2]+4|0;H[e+12>>2]=a;h=H[e+16>>2];b=h-a|0;if(b>>>0>8){continue}break}}c=170;v:{switch((b>>>2|0)-1|0){case 1:c=341;case 0:H[e+24>>2]=c;break;default:break v}}w:{if((a|0)==(h|0)){break w}while(1){oa(H[a>>2]);a=a+4|0;if((h|0)!=(a|0)){continue}break}b=H[e+16>>2];a=H[e+12>>2];if((b|0)==(a|0)){break w}H[e+16>>2]=b+((a-b|0)+3&-4)}a=H[e+8>>2];if(a){oa(a)}ca=e+32|0;g=d;break b}sa();v()}sa();v()}}return g}function wd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;i=H[b+8>>2];j=H[b+12>>2];n=H[b+20>>2];e=H[b+16>>2];h=e+4|0;n=h>>>0<4?n+1|0:n;a:{if(i>>>0>>0&(j|0)<=(n|0)|(j|0)<(n|0)){break a}e=e+H[b>>2]|0;H[a>>2]=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);e=H[b+20>>2];i=e;h=H[b+16>>2];e=h+4|0;j=e>>>0<4?i+1|0:i;H[b+16>>2]=e;H[b+20>>2]=j;if(K[a>>2]>32){break a}j=H[b+8>>2];n=H[b+12>>2];h=h+8|0;i=h>>>0<8?i+1|0:i;if(h>>>0>j>>>0&(i|0)>=(n|0)|(i|0)>(n|0)){break a}e=H[b>>2]+e|0;h=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[a+4>>2]=h;i=H[b+20>>2];e=H[b+16>>2]+4|0;i=e>>>0<4?i+1|0:i;H[b+16>>2]=e;H[b+20>>2]=i;if(!h){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!sb(a+16|0,b)){break a}if(!ua(a+544|0,b)){break a}if(!ua(a+564|0,b)){break a}if(!ua(a+584|0,b)){break a}u=H[a+4>>2];d=c;b=0;c=0;f=ca-32|0;ca=f;g=a;a=H[a+12>>2];H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}e=a<<2;b=pa(e);H[f+8>>2]=b;c=b+e|0;H[f+16>>2]=c;ra(b,0,e);H[f+12>>2]=c}h=H[g+628>>2];e=H[h>>2];if(e){H[h+4>>2]=e;oa(e);c=H[f+12>>2];b=H[f+8>>2];a=H[g+12>>2]}H[h+4>>2]=c;H[h>>2]=b;H[h+8>>2]=H[f+16>>2];b=0;H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;k=pa(a);H[f+8>>2]=k;b=a+k|0;H[f+16>>2]=b;ra(k,0,a);H[f+12>>2]=b}c=H[g+640>>2];a=H[c>>2];if(a){H[c+4>>2]=a;oa(a);k=H[f+8>>2];b=H[f+12>>2]}H[c+4>>2]=b;H[c>>2]=k;H[c+8>>2]=H[f+16>>2];H[f+24>>2]=0;H[f+28>>2]=0;H[f+16>>2]=0;H[f+20>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;xa(f+8|0);b=H[f+24>>2]+H[f+28>>2]|0;a=(b>>>0)/341|0;a=H[H[f+12>>2]+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=u;c=1;a=H[f+28>>2]+1|0;H[f+28>>2]=a;e:{if(!a){break e}n=g+16|0;while(1){j=H[f+12>>2];h=H[f+24>>2];e=a-1|0;c=h+e|0;b=(c>>>0)/341|0;b=H[j+(b<<2)>>2]+N(c-N(b,341)|0,12)|0;q=H[b+8>>2];i=H[b+4>>2];o=H[b>>2];H[f+28>>2]=e;b=H[f+16>>2];if((((b|0)!=(j|0)?N(b-j>>2,341)-1|0:0)-(a+h|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[f+16>>2]=H[f+16>>2]-4}c=0;if(o>>>0>u>>>0){break e}a=H[g+12>>2];k=(i|0)!=(a-1|0)?i+1|0:0;if(k>>>0>=a>>>0){break e}p=N(q,12);w=p+H[g+640>>2]|0;r=p+H[g+628>>2]|0;h=H[g>>2];l=k<<2;e=H[l+H[w>>2]>>2];f:{g:{if((h|0)==(e|0)){if(!o){break g}c=H[d+16>>2];b=H[d+20>>2];m=0;while(1){e=(b|0)==(c|0);a=b;j=0;b=c;h:{if(e){break h}while(1){l=H[d+28>>2];b=a;i=N(j,20)+c|0;h=H[i>>2];if(!I[h+84|0]){l=H[H[h+68>>2]+(l<<2)>>2]}if(K[h+80>>2]<=l>>>0){break h}e=H[r>>2]+(H[i+4>>2]<<2)|0;c=H[i+12>>2];b=e;i:{if(c>>>0>3){break i}a=0;b=H[d+12>>2];if(!H[i+16>>2]){break i}while(1){b=qa(b,e+(a<<2)|0,c);c=H[i+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[d+12>>2]}a=H[h+40>>2];qa(H[H[h>>2]>>2]+N(a,l)|0,b,a);a=H[d+20>>2];b=a;j=j+1|0;c=H[d+16>>2];if(j>>>0<(a-c|0)/20>>>0){continue}break}}H[d+28>>2]=H[d+28>>2]+1;H[g+8>>2]=H[g+8>>2]+1;m=m+1|0;if((o|0)!=(m|0)){continue}break}break g}j:{k:{l:{if(o>>>0<=2){c=H[g+616>>2];H[c>>2]=k;a=1;b=H[g+12>>2];if(b>>>0>1){break l}break j}if(K[g+8>>2]>K[g+4>>2]){break e}a=H[g+628>>2];j=q+1|0;m=N(j,12);b=a+m|0;if((b|0)!=(r|0)){Aa(b,H[r>>2],H[r+4>>2]);a=H[g+628>>2]}a=l+H[a+m>>2]|0;H[a>>2]=H[a>>2]+(1<>>1|0;break k}while(1){b=Ba((a<<4)+n|0)|b<<1;a=a+1|0;if((c|0)!=(a|0)){continue}break}a=o>>>1|0;if(b>>>0<=a>>>0){break k}c=0;break e}while(1){k=(b-1|0)!=(k|0)?k+1|0:0;H[c+(a<<2)>>2]=k;a=a+1|0;b=H[g+12>>2];if(a>>>0>>0){continue}break}break j}m:{n:{b=a-b|0;a=o-b|0;o:{if((a|0)==(b|0)){a=b;break o}i=H[g+596>>2];if((i|0)==H[g+588>>2]){break n}h=H[i>>2];e=H[g+600>>2];c=e+1|0;H[g+600>>2]=c;e=h&-2147483648>>>e;p:{if((c|0)==32){H[g+600>>2]=0;H[g+596>>2]=i+4;if(e){break p}break n}if(!e){break n}}}c=a;a=b;break m}c=b}i=H[g+640>>2];h=i+p|0;e=H[h>>2];b=e+l|0;H[b>>2]=H[b>>2]+1;Aa(i+m|0,e,H[h+4>>2]);if(a){m=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];b=H[f+12>>2];if((m|0)==(((b|0)!=(e|0)?N(e-b>>2,341)-1|0:0)|0)){xa(f+8|0);m=H[f+24>>2]+H[f+28>>2]|0;e=H[f+12>>2]}else{e=b}b=(m>>>0)/341|0;b=H[e+(b<<2)>>2]+N(m-N(b,341)|0,12)|0;H[b+8>>2]=q;H[b+4>>2]=k;H[b>>2]=a;H[f+28>>2]=H[f+28>>2]+1}if(!c){break g}b=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];a=H[f+12>>2];if((b|0)==(((a|0)!=(e|0)?N(e-a>>2,341)-1|0:0)|0)){xa(f+8|0);b=H[f+24>>2]+H[f+28>>2]|0;e=H[f+12>>2]}else{e=a}a=(b>>>0)/341|0;a=H[e+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+8>>2]=j;H[a+4>>2]=k;H[a>>2]=c;a=H[f+28>>2]+1|0;H[f+28>>2]=a;break f}k=0;if(!o){break g}while(1){if(H[g+12>>2]){q=H[g+548>>2];i=H[w>>2];t=H[g+604>>2];h=H[g+616>>2];a=0;while(1){p=(a<<2)+h|0;H[t+(H[p>>2]<<2)>>2]=0;e=H[g>>2];c=H[p>>2]<<2;b=H[c+i>>2];q:{if((e|0)==(b|0)){break q}l=c+t|0;s=e-b|0;m=H[g+560>>2];e=32-m|0;if((s|0)<=(e|0)){c=H[g+556>>2];if((c|0)==(q|0)){c=0;break e}H[l>>2]=H[c>>2]<>>32-s;b=s+H[g+560>>2]|0;H[g+560>>2]=b;if((b|0)!=32){break q}H[g+560>>2]=0;H[g+556>>2]=c+4;break q}j=H[g+556>>2];b=j+4|0;if((q|0)==(b|0)){c=0;break e}c=H[j>>2];H[g+556>>2]=b;b=s-e|0;H[g+560>>2]=b;H[l>>2]=H[j+4>>2]>>>32-b|c<>>32-s}c=H[p>>2]<<2;b=c+t|0;H[b>>2]=H[b>>2]|H[c+H[r>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}j=0;a=H[d+16>>2];r:{if((a|0)==H[d+20>>2]){break r}while(1){l=H[d+28>>2];i=N(j,20)+a|0;h=H[i>>2];if(!I[h+84|0]){l=H[H[h+68>>2]+(l<<2)>>2]}if(K[h+80>>2]<=l>>>0){break r}e=H[g+604>>2]+(H[i+4>>2]<<2)|0;c=H[i+12>>2];b=e;s:{if(c>>>0>3){break s}a=0;b=H[d+12>>2];if(!H[i+16>>2]){break s}while(1){b=qa(b,e+(a<<2)|0,c);c=H[i+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[d+12>>2]}a=H[h+40>>2];qa(H[H[h>>2]>>2]+N(a,l)|0,b,a);j=j+1|0;a=H[d+16>>2];if(j>>>0<(H[d+20>>2]-a|0)/20>>>0){continue}break}}H[d+28>>2]=H[d+28>>2]+1;H[g+8>>2]=H[g+8>>2]+1;k=k+1|0;if((o|0)!=(k|0)){continue}break}}a=H[f+28>>2]}if(a){continue}break}c=1}H[f+28>>2]=0;k=H[f+16>>2];a=H[f+12>>2];b=k-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[f+12>>2]+4|0;H[f+12>>2]=a;k=H[f+16>>2];b=k-a|0;if(b>>>0>8){continue}break}}d=170;t:{switch((b>>>2|0)-1|0){case 1:d=341;case 0:H[f+24>>2]=d;break;default:break t}}u:{if((a|0)==(k|0)){break u}while(1){oa(H[a>>2]);a=a+4|0;if((k|0)!=(a|0)){continue}break}b=H[f+16>>2];a=H[f+12>>2];if((b|0)==(a|0)){break u}H[f+16>>2]=b+((a-b|0)+3&-4)}a=H[f+8>>2];if(a){oa(a)}ca=f+32|0;break b}sa();v()}sa();v()}g=c}return g}function ud(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;i=H[b+8>>2];k=H[b+12>>2];o=H[b+20>>2];e=H[b+16>>2];h=e+4|0;o=h>>>0<4?o+1|0:o;a:{if(i>>>0>>0&(k|0)<=(o|0)|(k|0)<(o|0)){break a}e=e+H[b>>2]|0;H[a>>2]=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);e=H[b+20>>2];i=e;h=H[b+16>>2];e=h+4|0;k=e>>>0<4?i+1|0:i;H[b+16>>2]=e;H[b+20>>2]=k;if(K[a>>2]>32){break a}k=H[b+8>>2];o=H[b+12>>2];h=h+8|0;i=h>>>0<8?i+1|0:i;if(h>>>0>k>>>0&(i|0)>=(o|0)|(i|0)>(o|0)){break a}e=H[b>>2]+e|0;h=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[a+4>>2]=h;i=H[b+20>>2];e=H[b+16>>2]+4|0;i=e>>>0<4?i+1|0:i;H[b+16>>2]=e;H[b+20>>2]=i;if(!h){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!sb(a+16|0,b)){break a}if(!ua(a+544|0,b)){break a}if(!ua(a+564|0,b)){break a}if(!ua(a+584|0,b)){break a}w=H[a+4>>2];d=c;b=0;c=0;f=ca-32|0;ca=f;g=a;a=H[a+12>>2];H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}e=a<<2;b=pa(e);H[f+8>>2]=b;c=b+e|0;H[f+16>>2]=c;ra(b,0,e);H[f+12>>2]=c}h=H[g+628>>2];e=H[h>>2];if(e){H[h+4>>2]=e;oa(e);c=H[f+12>>2];b=H[f+8>>2];a=H[g+12>>2]}H[h+4>>2]=c;H[h>>2]=b;H[h+8>>2]=H[f+16>>2];b=0;H[f+16>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;j=pa(a);H[f+8>>2]=j;b=a+j|0;H[f+16>>2]=b;ra(j,0,a);H[f+12>>2]=b}c=H[g+640>>2];a=H[c>>2];if(a){H[c+4>>2]=a;oa(a);j=H[f+8>>2];b=H[f+12>>2]}H[c+4>>2]=b;H[c>>2]=j;H[c+8>>2]=H[f+16>>2];H[f+24>>2]=0;H[f+28>>2]=0;H[f+16>>2]=0;H[f+20>>2]=0;H[f+8>>2]=0;H[f+12>>2]=0;xa(f+8|0);b=H[f+24>>2]+H[f+28>>2]|0;a=(b>>>0)/341|0;a=H[H[f+12>>2]+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=w;c=1;a=H[f+28>>2]+1|0;H[f+28>>2]=a;e:{if(!a){break e}o=g+16|0;while(1){i=H[f+12>>2];h=H[f+24>>2];e=a-1|0;c=h+e|0;b=(c>>>0)/341|0;b=H[i+(b<<2)>>2]+N(c-N(b,341)|0,12)|0;q=H[b+8>>2];n=H[b>>2];H[f+28>>2]=e;b=H[f+16>>2];if((((b|0)!=(i|0)?N(b-i>>2,341)-1|0:0)-(a+h|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[f+16>>2]=H[f+16>>2]-4}c=0;if(n>>>0>w>>>0){break e}a=H[g+628>>2];p=N(q,12);t=p+H[g+640>>2]|0;j=Vd(g,n,t);if(j>>>0>=K[g+12>>2]){break e}r=a+p|0;h=H[g>>2];l=j<<2;e=H[l+H[t>>2]>>2];f:{g:{if((h|0)==(e|0)){if(!n){break g}c=H[d+16>>2];b=H[d+20>>2];m=0;while(1){e=(b|0)==(c|0);a=b;k=0;b=c;h:{if(e){break h}while(1){l=H[d+28>>2];b=a;i=N(k,20)+c|0;h=H[i>>2];if(!I[h+84|0]){l=H[H[h+68>>2]+(l<<2)>>2]}if(K[h+80>>2]<=l>>>0){break h}e=H[r>>2]+(H[i+4>>2]<<2)|0;c=H[i+12>>2];b=e;i:{if(c>>>0>3){break i}a=0;b=H[d+12>>2];if(!H[i+16>>2]){break i}while(1){b=qa(b,e+(a<<2)|0,c);c=H[i+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[d+12>>2]}a=H[h+40>>2];qa(H[H[h>>2]>>2]+N(a,l)|0,b,a);a=H[d+20>>2];b=a;k=k+1|0;c=H[d+16>>2];if(k>>>0<(a-c|0)/20>>>0){continue}break}}H[d+28>>2]=H[d+28>>2]+1;H[g+8>>2]=H[g+8>>2]+1;m=m+1|0;if((n|0)!=(m|0)){continue}break}break g}j:{k:{l:{if(n>>>0<=2){c=H[g+616>>2];H[c>>2]=j;a=1;b=H[g+12>>2];if(b>>>0>1){break l}break j}if(K[g+8>>2]>K[g+4>>2]){break e}a=H[g+628>>2];k=q+1|0;m=N(k,12);b=a+m|0;if((b|0)!=(r|0)){Aa(b,H[r>>2],H[r+4>>2]);a=H[g+628>>2]}a=l+H[a+m>>2]|0;H[a>>2]=H[a>>2]+(1<>>1|0;break k}while(1){b=Ba((a<<4)+o|0)|b<<1;a=a+1|0;if((c|0)!=(a|0)){continue}break}a=n>>>1|0;if(b>>>0<=a>>>0){break k}c=0;break e}while(1){j=(b-1|0)!=(j|0)?j+1|0:0;H[c+(a<<2)>>2]=j;a=a+1|0;b=H[g+12>>2];if(a>>>0>>0){continue}break}break j}m:{n:{b=a-b|0;a=n-b|0;o:{if((a|0)==(b|0)){a=b;break o}i=H[g+596>>2];if((i|0)==H[g+588>>2]){break n}h=H[i>>2];e=H[g+600>>2];c=e+1|0;H[g+600>>2]=c;e=h&-2147483648>>>e;p:{if((c|0)==32){H[g+600>>2]=0;H[g+596>>2]=i+4;if(e){break p}break n}if(!e){break n}}}c=a;a=b;break m}c=b}i=H[g+640>>2];h=i+p|0;e=H[h>>2];b=e+l|0;H[b>>2]=H[b>>2]+1;Aa(i+m|0,e,H[h+4>>2]);if(a){m=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];b=H[f+12>>2];if((m|0)==(((b|0)!=(e|0)?N(e-b>>2,341)-1|0:0)|0)){xa(f+8|0);m=H[f+24>>2]+H[f+28>>2]|0;e=H[f+12>>2]}else{e=b}b=(m>>>0)/341|0;b=H[e+(b<<2)>>2]+N(m-N(b,341)|0,12)|0;H[b+8>>2]=q;H[b+4>>2]=j;H[b>>2]=a;H[f+28>>2]=H[f+28>>2]+1}if(!c){break g}b=H[f+28>>2]+H[f+24>>2]|0;e=H[f+16>>2];a=H[f+12>>2];if((b|0)==(((a|0)!=(e|0)?N(e-a>>2,341)-1|0:0)|0)){xa(f+8|0);b=H[f+24>>2]+H[f+28>>2]|0;e=H[f+12>>2]}else{e=a}a=(b>>>0)/341|0;a=H[e+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+8>>2]=k;H[a+4>>2]=j;H[a>>2]=c;a=H[f+28>>2]+1|0;H[f+28>>2]=a;break f}j=0;if(!n){break g}while(1){if(H[g+12>>2]){q=H[g+548>>2];i=H[t>>2];u=H[g+604>>2];h=H[g+616>>2];a=0;while(1){p=(a<<2)+h|0;H[u+(H[p>>2]<<2)>>2]=0;e=H[g>>2];c=H[p>>2]<<2;b=H[c+i>>2];q:{if((e|0)==(b|0)){break q}l=c+u|0;s=e-b|0;m=H[g+560>>2];e=32-m|0;if((s|0)<=(e|0)){c=H[g+556>>2];if((c|0)==(q|0)){c=0;break e}H[l>>2]=H[c>>2]<>>32-s;b=s+H[g+560>>2]|0;H[g+560>>2]=b;if((b|0)!=32){break q}H[g+560>>2]=0;H[g+556>>2]=c+4;break q}k=H[g+556>>2];b=k+4|0;if((q|0)==(b|0)){c=0;break e}c=H[k>>2];H[g+556>>2]=b;b=s-e|0;H[g+560>>2]=b;H[l>>2]=H[k+4>>2]>>>32-b|c<>>32-s}c=H[p>>2]<<2;b=c+u|0;H[b>>2]=H[b>>2]|H[c+H[r>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}k=0;a=H[d+16>>2];r:{if((a|0)==H[d+20>>2]){break r}while(1){l=H[d+28>>2];i=N(k,20)+a|0;h=H[i>>2];if(!I[h+84|0]){l=H[H[h+68>>2]+(l<<2)>>2]}if(K[h+80>>2]<=l>>>0){break r}e=H[g+604>>2]+(H[i+4>>2]<<2)|0;c=H[i+12>>2];b=e;s:{if(c>>>0>3){break s}a=0;b=H[d+12>>2];if(!H[i+16>>2]){break s}while(1){b=qa(b,e+(a<<2)|0,c);c=H[i+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[d+12>>2]}a=H[h+40>>2];qa(H[H[h>>2]>>2]+N(a,l)|0,b,a);k=k+1|0;a=H[d+16>>2];if(k>>>0<(H[d+20>>2]-a|0)/20>>>0){continue}break}}H[d+28>>2]=H[d+28>>2]+1;H[g+8>>2]=H[g+8>>2]+1;j=j+1|0;if((n|0)!=(j|0)){continue}break}}a=H[f+28>>2]}if(a){continue}break}c=1}H[f+28>>2]=0;j=H[f+16>>2];a=H[f+12>>2];b=j-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[f+12>>2]+4|0;H[f+12>>2]=a;j=H[f+16>>2];b=j-a|0;if(b>>>0>8){continue}break}}d=170;t:{switch((b>>>2|0)-1|0){case 1:d=341;case 0:H[f+24>>2]=d;break;default:break t}}u:{if((a|0)==(j|0)){break u}while(1){oa(H[a>>2]);a=a+4|0;if((j|0)!=(a|0)){continue}break}b=H[f+16>>2];a=H[f+12>>2];if((b|0)==(a|0)){break u}H[f+16>>2]=b+((a-b|0)+3&-4)}a=H[f+8>>2];if(a){oa(a)}ca=f+32|0;break b}sa();v()}sa();v()}g=c}return g}function vd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;i=H[b+8>>2];k=H[b+12>>2];m=H[b+20>>2];f=H[b+16>>2];h=f+4|0;m=h>>>0<4?m+1|0:m;a:{if(i>>>0>>0&(k|0)<=(m|0)|(k|0)<(m|0)){break a}f=f+H[b>>2]|0;H[a>>2]=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);f=H[b+20>>2];i=f;h=H[b+16>>2];f=h+4|0;k=f>>>0<4?i+1|0:i;H[b+16>>2]=f;H[b+20>>2]=k;if(K[a>>2]>32){break a}k=H[b+8>>2];m=H[b+12>>2];h=h+8|0;i=h>>>0<8?i+1|0:i;if(h>>>0>k>>>0&(i|0)>=(m|0)|(i|0)>(m|0)){break a}f=f+H[b>>2]|0;h=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[a+4>>2]=h;i=H[b+20>>2];f=H[b+16>>2]+4|0;i=f>>>0<4?i+1|0:i;H[b+16>>2]=f;H[b+20>>2]=i;if(!h){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!sb(a+16|0,b)){break a}if(!ua(a+544|0,b)){break a}if(!ua(a+564|0,b)){break a}if(!ua(a+584|0,b)){break a}u=H[a+4>>2];b=0;e=ca-32|0;ca=e;f=a;a=H[a+12>>2];H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}d=a<<2;b=pa(d);H[e+8>>2]=b;g=b+d|0;H[e+16>>2]=g;ra(b,0,d);H[e+12>>2]=g}h=H[f+628>>2];d=H[h>>2];if(d){H[h+4>>2]=d;oa(d);g=H[e+12>>2];b=H[e+8>>2];a=H[f+12>>2]}H[h+4>>2]=g;H[h>>2]=b;H[h+8>>2]=H[e+16>>2];b=0;H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;j=pa(a);H[e+8>>2]=j;b=a+j|0;H[e+16>>2]=b;ra(j,0,a);H[e+12>>2]=b}d=H[f+640>>2];a=H[d>>2];if(a){H[d+4>>2]=a;oa(a);j=H[e+8>>2];b=H[e+12>>2]}H[d+4>>2]=b;H[d>>2]=j;H[d+8>>2]=H[e+16>>2];H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;xa(e+8|0);b=H[e+24>>2]+H[e+28>>2]|0;a=(b>>>0)/341|0;a=H[H[e+12>>2]+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=u;d=1;a=H[e+28>>2]+1|0;H[e+28>>2]=a;e:{if(!a){break e}m=f+16|0;while(1){k=H[e+12>>2];h=H[e+24>>2];g=a-1|0;d=h+g|0;b=(d>>>0)/341|0;b=H[k+(b<<2)>>2]+N(d-N(b,341)|0,12)|0;q=H[b+8>>2];i=H[b+4>>2];n=H[b>>2];H[e+28>>2]=g;b=H[e+16>>2];if((((b|0)!=(k|0)?N(b-k>>2,341)-1|0:0)-(a+h|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[e+16>>2]=H[e+16>>2]-4}if(n>>>0>u>>>0){d=0;break e}d=0;a=H[f+12>>2];j=(i|0)!=(a-1|0)?i+1|0:0;if(j>>>0>=a>>>0){break e}a=H[f+628>>2];o=N(q,12);s=a+o|0;g=H[f>>2];l=j<<2;k=o+H[f+640>>2]|0;b=H[l+H[k>>2]>>2];f:{g:{if((g|0)==(b|0)){if(!n){break g}g=H[c+16>>2];b=H[c+20>>2];p=0;while(1){d=(b|0)==(g|0);a=b;j=0;b=g;h:{if(d){break h}while(1){d=H[c+28>>2];b=a;k=N(j,20)+g|0;i=H[k>>2];if(!I[i+84|0]){d=H[H[i+68>>2]+(d<<2)>>2]}if(K[i+80>>2]<=d>>>0){break h}h=H[s>>2]+(H[k+4>>2]<<2)|0;g=H[k+12>>2];b=h;i:{if(g>>>0>3){break i}a=0;b=H[c+12>>2];if(!H[k+16>>2]){break i}while(1){b=qa(b,h+(a<<2)|0,g);g=H[k+12>>2];b=b+g|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[c+12>>2]}a=H[i+40>>2];qa(H[H[i>>2]>>2]+N(a,d)|0,b,a);a=H[c+20>>2];b=a;j=j+1|0;g=H[c+16>>2];if(j>>>0<(a-g|0)/20>>>0){continue}break}}H[c+28>>2]=H[c+28>>2]+1;H[f+8>>2]=H[f+8>>2]+1;p=p+1|0;if((p|0)!=(n|0)){continue}break}break g}j:{k:{l:{if(n>>>0<=2){d=H[f+616>>2];H[d>>2]=j;a=1;b=H[f+12>>2];if(b>>>0>1){break l}break j}if(K[f+8>>2]>K[f+4>>2]){break e}d=a;a=o+12|0;Aa(d+a|0,H[s>>2],H[s+4>>2]);a=l+H[a+H[f+628>>2]>>2]|0;H[a>>2]=H[a>>2]+(1<>>1|0;break k}while(1){b=Ba((a<<4)+m|0)|b<<1;a=a+1|0;if((d|0)!=(a|0)){continue}break}a=n>>>1|0;if(b>>>0<=a>>>0){break k}d=0;break e}while(1){j=(b-1|0)!=(j|0)?j+1|0:0;H[d+(a<<2)>>2]=j;a=a+1|0;b=H[f+12>>2];if(a>>>0>>0){continue}break}break j}k=q+1|0;m:{n:{b=a-b|0;a=n-b|0;o:{if((a|0)==(b|0)){a=b;break o}i=H[f+596>>2];if((i|0)==H[f+588>>2]){break n}h=H[i>>2];g=H[f+600>>2];d=g+1|0;H[f+600>>2]=d;g=h&-2147483648>>>g;p:{if((d|0)==32){H[f+600>>2]=0;H[f+596>>2]=i+4;if(g){break p}break n}if(!g){break n}}}d=a;a=b;break m}d=b}i=H[f+640>>2];h=i+o|0;g=H[h>>2];b=g+l|0;H[b>>2]=H[b>>2]+1;Aa(i+N(k,12)|0,g,H[h+4>>2]);if(a){h=H[e+28>>2]+H[e+24>>2]|0;g=H[e+16>>2];b=H[e+12>>2];if((h|0)==(((b|0)!=(g|0)?N(g-b>>2,341)-1|0:0)|0)){xa(e+8|0);h=H[e+24>>2]+H[e+28>>2]|0;g=H[e+12>>2]}else{g=b}b=(h>>>0)/341|0;b=H[g+(b<<2)>>2]+N(h-N(b,341)|0,12)|0;H[b+8>>2]=q;H[b+4>>2]=j;H[b>>2]=a;H[e+28>>2]=H[e+28>>2]+1}if(!d){break g}b=H[e+28>>2]+H[e+24>>2]|0;g=H[e+16>>2];a=H[e+12>>2];if((b|0)==(((a|0)!=(g|0)?N(g-a>>2,341)-1|0:0)|0)){xa(e+8|0);b=H[e+24>>2]+H[e+28>>2]|0;g=H[e+12>>2]}else{g=a}a=(b>>>0)/341|0;a=H[g+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+8>>2]=k;H[a+4>>2]=j;H[a>>2]=d;a=H[e+28>>2]+1|0;H[e+28>>2]=a;break f}p=0;if(!n){break g}while(1){if(H[f+12>>2]){w=H[f+548>>2];i=H[k>>2];t=H[f+604>>2];h=H[f+616>>2];a=0;while(1){j=h+(a<<2)|0;H[(H[j>>2]<<2)+t>>2]=0;g=H[f>>2];d=H[j>>2]<<2;b=H[d+i>>2];q:{if((g|0)==(b|0)){break q}q=d+t|0;r=g-b|0;o=H[f+560>>2];g=32-o|0;if((r|0)<=(g|0)){d=H[f+556>>2];if((d|0)==(w|0)){d=0;break e}H[q>>2]=H[d>>2]<>>32-r;b=H[f+560>>2]+r|0;H[f+560>>2]=b;if((b|0)!=32){break q}H[f+560>>2]=0;H[f+556>>2]=d+4;break q}l=H[f+556>>2];b=l+4|0;if((b|0)==(w|0)){d=0;break e}d=H[l>>2];H[f+556>>2]=b;b=r-g|0;H[f+560>>2]=b;H[q>>2]=H[l+4>>2]>>>32-b|d<>>32-r}d=H[j>>2]<<2;b=d+t|0;H[b>>2]=H[b>>2]|H[d+H[s>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}j=0;a=H[c+16>>2];r:{if((a|0)==H[c+20>>2]){break r}while(1){d=H[c+28>>2];l=N(j,20)+a|0;i=H[l>>2];if(!I[i+84|0]){d=H[H[i+68>>2]+(d<<2)>>2]}if(K[i+80>>2]<=d>>>0){break r}h=H[f+604>>2]+(H[l+4>>2]<<2)|0;g=H[l+12>>2];b=h;s:{if(g>>>0>3){break s}a=0;b=H[c+12>>2];if(!H[l+16>>2]){break s}while(1){b=qa(b,h+(a<<2)|0,g);g=H[l+12>>2];b=b+g|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[c+12>>2]}a=H[i+40>>2];qa(H[H[i>>2]>>2]+N(a,d)|0,b,a);j=j+1|0;a=H[c+16>>2];if(j>>>0<(H[c+20>>2]-a|0)/20>>>0){continue}break}}H[c+28>>2]=H[c+28>>2]+1;H[f+8>>2]=H[f+8>>2]+1;p=p+1|0;if((p|0)!=(n|0)){continue}break}}a=H[e+28>>2]}if(a){continue}break}d=1}H[e+28>>2]=0;j=H[e+16>>2];a=H[e+12>>2];b=j-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[e+12>>2]+4|0;H[e+12>>2]=a;j=H[e+16>>2];b=j-a|0;if(b>>>0>8){continue}break}}g=170;t:{switch((b>>>2|0)-1|0){case 1:g=341;case 0:H[e+24>>2]=g;break;default:break t}}u:{if((a|0)==(j|0)){break u}while(1){oa(H[a>>2]);a=a+4|0;if((j|0)!=(a|0)){continue}break}b=H[e+16>>2];a=H[e+12>>2];if((b|0)==(a|0)){break u}H[e+16>>2]=b+((a-b|0)+3&-4)}a=H[e+8>>2];if(a){oa(a)}ca=e+32|0;break b}sa();v()}sa();v()}g=d}return g}function yd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;j=H[b+8>>2];e=H[b+12>>2];g=H[b+20>>2];h=H[b+16>>2];l=h+4|0;g=l>>>0<4?g+1|0:g;a:{if(j>>>0>>0&(e|0)<=(g|0)|(e|0)<(g|0)){break a}h=h+H[b>>2]|0;H[a>>2]=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);h=H[b+20>>2];e=h;j=H[b+16>>2];g=j+4|0;h=g>>>0<4?e+1|0:e;H[b+16>>2]=g;H[b+20>>2]=h;if(K[a>>2]>32){break a}k=H[b+8>>2];l=H[b+12>>2];h=e;e=j+8|0;h=e>>>0<8?h+1|0:h;if(e>>>0>k>>>0&(h|0)>=(l|0)|(h|0)>(l|0)){break a}h=H[b>>2]+g|0;g=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);H[a+4>>2]=g;h=H[b+20>>2];e=H[b+16>>2]+4|0;h=e>>>0<4?h+1|0:h;H[b+16>>2]=e;H[b+20>>2]=h;if(!g){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!ta(a+16|0,b)){break a}if(!ua(a+32|0,b)){break a}if(!ua(a+52|0,b)){break a}if(!ua(a+72|0,b)){break a}r=H[a+4>>2];h=c;b=0;g=0;e=ca-32|0;ca=e;d=a;a=H[a+12>>2];H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}c=a<<2;b=pa(c);H[e+8>>2]=b;g=b+c|0;H[e+16>>2]=g;ra(b,0,c);H[e+12>>2]=g}c=H[d+116>>2];i=H[c>>2];if(i){H[c+4>>2]=i;oa(i);g=H[e+12>>2];b=H[e+8>>2];a=H[d+12>>2]}H[c+4>>2]=g;H[c>>2]=b;H[c+8>>2]=H[e+16>>2];b=0;H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;f=pa(a);H[e+8>>2]=f;b=a+f|0;H[e+16>>2]=b;ra(f,0,a);H[e+12>>2]=b}a=H[d+128>>2];c=H[a>>2];if(c){H[a+4>>2]=c;oa(c);f=H[e+8>>2];b=H[e+12>>2]}H[a+4>>2]=b;H[a>>2]=f;H[a+8>>2]=H[e+16>>2];H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;xa(e+8|0);a=H[e+24>>2]+H[e+28>>2]|0;b=(a>>>0)/341|0;a=H[H[e+12>>2]+(b<<2)>>2]+N(a-N(b,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=r;c=1;a=H[e+28>>2]+1|0;H[e+28>>2]=a;e:{if(!a){break e}t=d+16|0;while(1){b=H[e+12>>2];f=H[e+24>>2];l=a-1|0;c=f+l|0;i=(c>>>0)/341|0;c=H[b+(i<<2)>>2]+N(c-N(i,341)|0,12)|0;g=H[c+8>>2];i=H[c+4>>2];j=H[c>>2];H[e+28>>2]=l;c=H[e+16>>2];if((((b|0)!=(c|0)?N(c-b>>2,341)-1|0:0)-(a+f|0)|0)+1>>>0>=682){oa(H[c-4>>2]);H[e+16>>2]=H[e+16>>2]-4}c=0;if(j>>>0>r>>>0){break e}b=H[d+12>>2];a=(b-1|0)!=(i|0)?i+1|0:0;if(a>>>0>=b>>>0){break e}f=N(g,12);o=f+H[d+128>>2]|0;l=f+H[d+116>>2]|0;i=H[d>>2];k=a<<2;n=H[k+H[o>>2]>>2];f:{if((i|0)==(n|0)){if(!j){break f}o=0;b=H[h+20>>2];g=H[h+16>>2];if((b|0)==(g|0)){a=H[d+8>>2];H[h+28>>2]=j+H[h+28>>2];H[d+8>>2]=a+j;break f}while(1){c=(b|0)==(g|0);a=b;i=0;b=g;g:{if(c){break g}while(1){f=H[h+28>>2];b=a;c=N(i,20)+g|0;k=H[c>>2];if(!I[k+84|0]){f=H[H[k+68>>2]+(f<<2)>>2]}if(K[k+80>>2]<=f>>>0){break g}n=H[l>>2]+(H[c+4>>2]<<2)|0;g=H[c+12>>2];b=n;h:{if(g>>>0>3){break h}a=0;b=H[h+12>>2];if(!H[c+16>>2]){break h}while(1){b=qa(b,n+(a<<2)|0,g);g=H[c+12>>2];b=b+g|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[h+12>>2]}a=H[k+40>>2];qa(H[H[k>>2]>>2]+N(a,f)|0,b,a);i=i+1|0;a=H[h+20>>2];b=a;g=H[h+16>>2];if(i>>>0<(b-g|0)/20>>>0){continue}break}}H[h+28>>2]=H[h+28>>2]+1;H[d+8>>2]=H[d+8>>2]+1;o=o+1|0;if((j|0)!=(o|0)){continue}break}break f}i:{j:{k:{l:{if(j>>>0<=2){c=H[d+104>>2];H[c>>2]=a;f=1;b=H[d+12>>2];if(b>>>0>1){break l}break i}if(K[d+8>>2]>K[d+4>>2]){break e}b=H[d+116>>2];m=g+1|0;o=N(m,12);q=b+o|0;if((q|0)!=(l|0)){Aa(q,H[l>>2],H[l+4>>2]);b=H[d+116>>2]}b=k+H[b+o>>2]|0;H[b>>2]=H[b>>2]+(1<>2]=0;pc(t,Q(j)^31,e+4|0);b=j>>>1|0;i=H[e+4>>2];if(b>>>0>>0){break e}b=b-i|0;c=j-b|0;m:{if((c|0)==(b|0)){c=b;break m}i=H[d+84>>2];if((i|0)==H[d+76>>2]){break k}j=H[i>>2];l=H[d+88>>2];n=l+1|0;H[d+88>>2]=n;j=j&-2147483648>>>l;n:{if((n|0)==32){H[d+88>>2]=0;H[d+84>>2]=i+4;if(j){break n}break k}if(!j){break k}}}i=c;c=b;break j}while(1){a=(b-1|0)!=(a|0)?a+1|0:0;H[c+(f<<2)>>2]=a;b=H[d+12>>2];f=f+1|0;if(b>>>0>f>>>0){continue}break}break i}i=b}b=H[d+128>>2];j=b+f|0;f=H[j>>2];l=f+k|0;H[l>>2]=H[l>>2]+1;Aa(b+o|0,f,H[j+4>>2]);if(c){b=H[e+28>>2]+H[e+24>>2]|0;j=H[e+16>>2];f=H[e+12>>2];if((b|0)==(((f|0)!=(j|0)?N(j-f>>2,341)-1|0:0)|0)){xa(e+8|0);f=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}j=(b>>>0)/341|0;b=H[(j<<2)+f>>2]+N(b-N(j,341)|0,12)|0;H[b+8>>2]=g;H[b+4>>2]=a;H[b>>2]=c;H[e+28>>2]=H[e+28>>2]+1}if(!i){break f}b=H[e+28>>2]+H[e+24>>2]|0;c=H[e+16>>2];f=H[e+12>>2];if((b|0)==(((c|0)!=(f|0)?N(c-f>>2,341)-1|0:0)|0)){xa(e+8|0);f=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}c=(b>>>0)/341|0;b=H[(c<<2)+f>>2]+N(b-N(c,341)|0,12)|0;H[b+8>>2]=m;H[b+4>>2]=a;H[b>>2]=i;H[e+28>>2]=H[e+28>>2]+1;break f}n=0;if(!j){break f}while(1){if(H[d+12>>2]){i=H[d+36>>2];q=H[o>>2];c=H[d+92>>2];u=H[d+104>>2];a=0;while(1){g=(a<<2)+u|0;H[c+(H[g>>2]<<2)>>2]=0;b=H[d>>2];f=H[g>>2]<<2;k=H[f+q>>2];o:{if((b|0)==(k|0)){break o}f=c+f|0;b=b-k|0;k=H[d+48>>2];p=32-k|0;if((b|0)<=(p|0)){m=H[d+44>>2];if((m|0)==(i|0)){c=0;break e}H[f>>2]=H[m>>2]<>>32-b;b=b+H[d+48>>2]|0;H[d+48>>2]=b;if((b|0)!=32){break o}H[d+48>>2]=0;H[d+44>>2]=m+4;break o}m=H[d+44>>2];s=m+4|0;if((i|0)==(s|0)){c=0;break e}w=H[m>>2];H[d+44>>2]=s;p=b-p|0;H[d+48>>2]=p;H[f>>2]=H[m+4>>2]>>>32-p|w<>>32-b}b=H[g>>2]<<2;g=b+c|0;H[g>>2]=H[g>>2]|H[b+H[l>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}i=0;a=H[h+16>>2];p:{if((a|0)==H[h+20>>2]){break p}while(1){f=H[h+28>>2];c=N(i,20)+a|0;k=H[c>>2];if(!I[k+84|0]){f=H[H[k+68>>2]+(f<<2)>>2]}if(K[k+80>>2]<=f>>>0){break p}m=H[d+92>>2]+(H[c+4>>2]<<2)|0;g=H[c+12>>2];b=m;q:{if(g>>>0>3){break q}a=0;b=H[h+12>>2];if(!H[c+16>>2]){break q}while(1){b=qa(b,m+(a<<2)|0,g);g=H[c+12>>2];b=b+g|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[h+12>>2]}a=H[k+40>>2];qa(H[H[k>>2]>>2]+N(a,f)|0,b,a);i=i+1|0;a=H[h+16>>2];if(i>>>0<(H[h+20>>2]-a|0)/20>>>0){continue}break}}H[h+28>>2]=H[h+28>>2]+1;H[d+8>>2]=H[d+8>>2]+1;n=n+1|0;if((j|0)!=(n|0)){continue}break}}a=H[e+28>>2];if(a){continue}break}c=1}H[e+28>>2]=0;f=H[e+16>>2];a=H[e+12>>2];b=f-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[e+12>>2]+4|0;H[e+12>>2]=a;f=H[e+16>>2];b=f-a|0;if(b>>>0>8){continue}break}}g=170;r:{switch((b>>>2|0)-1|0){case 1:g=341;case 0:H[e+24>>2]=g;break;default:break r}}s:{if((a|0)==(f|0)){break s}while(1){oa(H[a>>2]);a=a+4|0;if((f|0)!=(a|0)){continue}break}a=H[e+16>>2];b=H[e+12>>2];if((a|0)==(b|0)){break s}H[e+16>>2]=a+((b-a|0)+3&-4)}a=H[e+8>>2];if(a){oa(a)}ca=e+32|0;break b}sa();v()}sa();v()}i=c}return i}function xd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;i=H[b+8>>2];k=H[b+12>>2];n=H[b+20>>2];h=H[b+16>>2];f=h+4|0;n=f>>>0<4?n+1|0:n;a:{if((k|0)<=(n|0)&f>>>0>i>>>0|(k|0)<(n|0)){break a}h=h+H[b>>2]|0;H[a>>2]=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);h=H[b+20>>2];i=h;f=H[b+16>>2];h=f+4|0;k=h>>>0<4?i+1|0:i;H[b+16>>2]=h;H[b+20>>2]=k;if(K[a>>2]>32){break a}k=H[b+8>>2];n=H[b+12>>2];f=f+8|0;i=f>>>0<8?i+1|0:i;if(f>>>0>k>>>0&(i|0)>=(n|0)|(i|0)>(n|0)){break a}h=H[b>>2]+h|0;f=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);H[a+4>>2]=f;i=H[b+20>>2];h=H[b+16>>2]+4|0;i=h>>>0<4?i+1|0:i;H[b+16>>2]=h;H[b+20>>2]=i;if(!f){return 1}if(d>>>0>>0){break a}H[a+8>>2]=0;if(!ta(a+16|0,b)){break a}if(!ua(a+32|0,b)){break a}if(!ua(a+52|0,b)){break a}if(!ua(a+72|0,b)){break a}u=H[a+4>>2];h=c;b=0;c=0;e=ca-32|0;ca=e;f=a;a=H[a+12>>2];H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;b:{c:{if(a){if(a>>>0>=1073741824){break c}d=a<<2;b=pa(d);H[e+8>>2]=b;c=b+d|0;H[e+16>>2]=c;ra(b,0,d);H[e+12>>2]=c}j=H[f+116>>2];d=H[j>>2];if(d){H[j+4>>2]=d;oa(d);c=H[e+12>>2];b=H[e+8>>2];a=H[f+12>>2]}H[j+4>>2]=c;H[j>>2]=b;H[j+8>>2]=H[e+16>>2];b=0;H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;d:{if(a){if(a>>>0>=1073741824){break d}a=a<<2;g=pa(a);H[e+8>>2]=g;b=a+g|0;H[e+16>>2]=b;ra(g,0,a);H[e+12>>2]=b}c=H[f+128>>2];a=H[c>>2];if(a){H[c+4>>2]=a;oa(a);g=H[e+8>>2];b=H[e+12>>2]}H[c+4>>2]=b;H[c>>2]=g;H[c+8>>2]=H[e+16>>2];H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;xa(e+8|0);b=H[e+24>>2]+H[e+28>>2]|0;a=(b>>>0)/341|0;a=H[H[e+12>>2]+(a<<2)>>2]+N(b-N(a,341)|0,12)|0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=u;d=1;a=H[e+28>>2]+1|0;H[e+28>>2]=a;e:{if(!a){break e}n=f+16|0;while(1){i=H[e+12>>2];j=H[e+24>>2];d=a-1|0;c=j+d|0;b=(c>>>0)/341|0;b=H[i+(b<<2)>>2]+N(c-N(b,341)|0,12)|0;o=H[b+8>>2];c=H[b+4>>2];m=H[b>>2];H[e+28>>2]=d;b=H[e+16>>2];if((((b|0)!=(i|0)?N(b-i>>2,341)-1|0:0)-(a+j|0)|0)+1>>>0>=682){oa(H[b-4>>2]);H[e+16>>2]=H[e+16>>2]-4}if(m>>>0>u>>>0){d=0;break e}d=0;b=H[f+12>>2];a=(c|0)!=(b-1|0)?c+1|0:0;if(a>>>0>=b>>>0){break e}b=H[f+116>>2];p=N(o,12);r=b+p|0;j=H[f>>2];g=a<<2;k=p+H[f+128>>2]|0;c=H[g+H[k>>2]>>2];f:{if((j|0)==(c|0)){if(!m){break f}b=H[h+20>>2];c=H[h+16>>2];if((b|0)==(c|0)){a=H[f+8>>2];H[h+28>>2]=m+H[h+28>>2];H[f+8>>2]=a+m;break f}while(1){i=(b|0)==(c|0);a=b;j=0;b=c;g:{if(i){break g}while(1){g=H[h+28>>2];b=a;l=N(j,20)+c|0;k=H[l>>2];if(!I[k+84|0]){g=H[H[k+68>>2]+(g<<2)>>2]}if(K[k+80>>2]<=g>>>0){break g}i=H[r>>2]+(H[l+4>>2]<<2)|0;c=H[l+12>>2];b=i;h:{if(c>>>0>3){break h}a=0;b=H[h+12>>2];if(!H[l+16>>2]){break h}while(1){b=qa(b,i+(a<<2)|0,c);c=H[l+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[h+12>>2]}a=H[k+40>>2];qa(H[H[k>>2]>>2]+N(a,g)|0,b,a);j=j+1|0;a=H[h+20>>2];b=a;c=H[h+16>>2];if(j>>>0<(b-c|0)/20>>>0){continue}break}}H[h+28>>2]=H[h+28>>2]+1;H[f+8>>2]=H[f+8>>2]+1;d=d+1|0;if((m|0)!=(d|0)){continue}break}break f}i:{j:{k:{l:{if(m>>>0<=2){c=H[f+104>>2];H[c>>2]=a;g=1;b=H[f+12>>2];if(b>>>0>1){break l}break i}if(K[f+8>>2]>K[f+4>>2]){break e}i=b;b=p+12|0;Aa(i+b|0,H[r>>2],H[r+4>>2]);b=g+H[b+H[f+116>>2]>>2]|0;H[b>>2]=H[b>>2]+(1<>2]=0;pc(n,Q(m)^31,e+4|0);c=m>>>1|0;b=H[e+4>>2];if(c>>>0>>0){break e}l=o+1|0;b=c-b|0;c=m-b|0;m:{if((c|0)==(b|0)){c=b;break m}k=H[f+84>>2];if((k|0)==H[f+76>>2]){break k}i=H[k>>2];j=H[f+88>>2];d=j+1|0;H[f+88>>2]=d;j=i&-2147483648>>>j;n:{if((d|0)==32){H[f+88>>2]=0;H[f+84>>2]=k+4;if(j){break n}break k}if(!j){break k}}}j=c;c=b;break j}while(1){a=(b-1|0)!=(a|0)?a+1|0:0;H[c+(g<<2)>>2]=a;b=H[f+12>>2];g=g+1|0;if(b>>>0>g>>>0){continue}break}break i}j=b}k=H[f+128>>2];i=k+p|0;d=H[i>>2];b=d+g|0;H[b>>2]=H[b>>2]+1;Aa(k+N(l,12)|0,d,H[i+4>>2]);if(c){b=H[e+28>>2]+H[e+24>>2]|0;d=H[e+16>>2];g=H[e+12>>2];if((b|0)==(((d|0)!=(g|0)?N(d-g>>2,341)-1|0:0)|0)){xa(e+8|0);g=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}d=(b>>>0)/341|0;b=H[(d<<2)+g>>2]+N(b-N(d,341)|0,12)|0;H[b+8>>2]=o;H[b+4>>2]=a;H[b>>2]=c;H[e+28>>2]=H[e+28>>2]+1}if(!j){break f}b=H[e+28>>2]+H[e+24>>2]|0;c=H[e+16>>2];g=H[e+12>>2];if((b|0)==(((c|0)!=(g|0)?N(c-g>>2,341)-1|0:0)|0)){xa(e+8|0);g=H[e+12>>2];b=H[e+24>>2]+H[e+28>>2]|0}c=(b>>>0)/341|0;b=H[(c<<2)+g>>2]+N(b-N(c,341)|0,12)|0;H[b+8>>2]=l;H[b+4>>2]=a;H[b>>2]=j;H[e+28>>2]=H[e+28>>2]+1;break f}s=0;if(!m){break f}while(1){if(H[f+12>>2]){w=H[f+36>>2];i=H[k>>2];t=H[f+92>>2];j=H[f+104>>2];a=0;while(1){o=(a<<2)+j|0;H[t+(H[o>>2]<<2)>>2]=0;d=H[f>>2];c=H[o>>2]<<2;b=H[c+i>>2];o:{if((d|0)==(b|0)){break o}p=c+t|0;q=d-b|0;g=H[f+48>>2];d=32-g|0;if((q|0)<=(d|0)){c=H[f+44>>2];if((c|0)==(w|0)){d=0;break e}H[p>>2]=H[c>>2]<>>32-q;b=q+H[f+48>>2]|0;H[f+48>>2]=b;if((b|0)!=32){break o}H[f+48>>2]=0;H[f+44>>2]=c+4;break o}l=H[f+44>>2];b=l+4|0;if((w|0)==(b|0)){d=0;break e}c=H[l>>2];H[f+44>>2]=b;b=q-d|0;H[f+48>>2]=b;H[p>>2]=H[l+4>>2]>>>32-b|c<>>32-q}c=H[o>>2]<<2;b=c+t|0;H[b>>2]=H[b>>2]|H[c+H[r>>2]>>2];a=a+1|0;if(a>>>0>2]){continue}break}}j=0;a=H[h+16>>2];p:{if((a|0)==H[h+20>>2]){break p}while(1){g=H[h+28>>2];l=N(j,20)+a|0;i=H[l>>2];if(!I[i+84|0]){g=H[H[i+68>>2]+(g<<2)>>2]}if(K[i+80>>2]<=g>>>0){break p}d=H[f+92>>2]+(H[l+4>>2]<<2)|0;c=H[l+12>>2];b=d;q:{if(c>>>0>3){break q}a=0;b=H[h+12>>2];if(!H[l+16>>2]){break q}while(1){b=qa(b,d+(a<<2)|0,c);c=H[l+12>>2];b=b+c|0;a=a+1|0;if(a>>>0>2]){continue}break}b=H[h+12>>2]}a=H[i+40>>2];qa(H[H[i>>2]>>2]+N(a,g)|0,b,a);j=j+1|0;a=H[h+16>>2];if(j>>>0<(H[h+20>>2]-a|0)/20>>>0){continue}break}}H[h+28>>2]=H[h+28>>2]+1;H[f+8>>2]=H[f+8>>2]+1;s=s+1|0;if((m|0)!=(s|0)){continue}break}}a=H[e+28>>2];if(a){continue}break}d=1}H[e+28>>2]=0;g=H[e+16>>2];a=H[e+12>>2];b=g-a|0;if(b>>>0>=9){while(1){oa(H[a>>2]);a=H[e+12>>2]+4|0;H[e+12>>2]=a;g=H[e+16>>2];b=g-a|0;if(b>>>0>8){continue}break}}c=170;r:{switch((b>>>2|0)-1|0){case 1:c=341;case 0:H[e+24>>2]=c;break;default:break r}}s:{if((a|0)==(g|0)){break s}while(1){oa(H[a>>2]);a=a+4|0;if((g|0)!=(a|0)){continue}break}b=H[e+16>>2];a=H[e+12>>2];if((b|0)==(a|0)){break s}H[e+16>>2]=b+((a-b|0)+3&-4)}a=H[e+8>>2];if(a){oa(a)}ca=e+32|0;j=d;break b}sa();v()}sa();v()}}return j}function $c(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;h=ca-32|0;ca=h;g=H[H[a+4>>2]+44>>2];c=H[a+8>>2];d=H[c>>2];c=H[c+4>>2];H[h+24>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;d=(c-d>>2>>>0)/3|0;c=H[g+96>>2];f=(H[g+100>>2]-c|0)/12|0;a:{if(d>>>0>f>>>0){e=d-f|0;i=H[g+104>>2];c=H[g+100>>2];if(e>>>0<=(i-c|0)/12>>>0){b:{if(!e){break b}d=c;f=N(e,12)-12|0;i=((f>>>0)/12|0)+1&3;if(i){while(1){l=H[h+20>>2];H[d>>2]=H[h+16>>2];H[d+4>>2]=l;H[d+8>>2]=H[h+24>>2];d=d+12|0;j=j+1|0;if((i|0)!=(j|0)){continue}break}}c=N(e,12)+c|0;if(f>>>0<36){break b}while(1){f=H[h+20>>2];H[d>>2]=H[h+16>>2];H[d+4>>2]=f;H[d+8>>2]=H[h+24>>2];H[d+20>>2]=H[h+24>>2];f=H[h+20>>2];H[d+12>>2]=H[h+16>>2];H[d+16>>2]=f;H[d+32>>2]=H[h+24>>2];f=H[h+20>>2];H[d+24>>2]=H[h+16>>2];H[d+28>>2]=f;f=H[h+20>>2];H[d+36>>2]=H[h+16>>2];H[d+40>>2]=f;H[d+44>>2]=H[h+24>>2];d=d+48|0;if((d|0)!=(c|0)){continue}break}}H[g+100>>2]=c;break a}c:{f=H[g+96>>2];n=(c-f|0)/12|0;d=n+e|0;if(d>>>0<357913942){f=(i-f|0)/12|0;i=f<<1;i=f>>>0>=178956970?357913941:d>>>0>>0?i:d;if(i){if(i>>>0>=357913942){break c}l=pa(N(i,12))}f=N(n,12)+l|0;d=f;e=N(e,12);n=e-12|0;q=((n>>>0)/12|0)+1&3;if(q){while(1){r=H[h+20>>2];H[d>>2]=H[h+16>>2];H[d+4>>2]=r;H[d+8>>2]=H[h+24>>2];d=d+12|0;j=j+1|0;if((q|0)!=(j|0)){continue}break}}e=e+f|0;if(n>>>0>=36){while(1){j=H[h+20>>2];H[d>>2]=H[h+16>>2];H[d+4>>2]=j;H[d+8>>2]=H[h+24>>2];H[d+20>>2]=H[h+24>>2];j=H[h+20>>2];H[d+12>>2]=H[h+16>>2];H[d+16>>2]=j;H[d+32>>2]=H[h+24>>2];j=H[h+20>>2];H[d+24>>2]=H[h+16>>2];H[d+28>>2]=j;j=H[h+20>>2];H[d+36>>2]=H[h+16>>2];H[d+40>>2]=j;H[d+44>>2]=H[h+24>>2];d=d+48|0;if((e|0)!=(d|0)){continue}break}}j=H[g+96>>2];if((j|0)!=(c|0)){while(1){c=c-12|0;n=H[c+4>>2];f=f-12|0;d=f;H[d>>2]=H[c>>2];H[d+4>>2]=n;H[d+8>>2]=H[c+8>>2];if((c|0)!=(j|0)){continue}break}c=H[g+96>>2]}H[g+104>>2]=N(i,12)+l;H[g+100>>2]=e;H[g+96>>2]=f;if(c){oa(c)}break a}sa();v()}wa();v()}if(d>>>0>=f>>>0){break a}H[g+100>>2]=c+N(d,12)}d:{if(H[a+216>>2]==H[a+220>>2]){j=H[a+4>>2];c=H[j+44>>2];d=H[c+100>>2];f=H[c+96>>2];if((d|0)!=(f|0)){c=(d-f|0)/12|0;o=c>>>0<=1?1:c;c=0;while(1){d=H[a+8>>2];i=f+N(c,12)|0;g=N(c,3);e:{f:{if((g|0)==-1){e=H[(H[d>>2]+(g<<2)|0)+4>>2];k=-1;g=1;break f}e=-1;k=H[H[d>>2]+(g<<2)>>2];l=g+1|0;if((l|0)==-1){g=0;break f}e=H[H[d>>2]+(l<<2)>>2];g=g+2|0;m=-1;if((g|0)==-1){break e}}m=H[H[d>>2]+(g<<2)>>2]}H[i+8>>2]=m;H[i+4>>2]=e;H[i>>2]=k;c=c+1|0;if((o|0)!=(c|0)){continue}break}}H[H[j+4>>2]+80>>2]=b;c=1;break d}d=0;H[h+24>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;l=H[a+8>>2];c=H[l>>2];g=H[l+4>>2];H[h+8>>2]=0;H[h>>2]=0;H[h+4>>2]=0;b=0;g:{h:{i:{j:{k:{l:{if((c|0)!=(g|0)){c=g-c|0;if((c|0)<0){break l}b=pa(c);H[h>>2]=b;H[h+8>>2]=(c&-4)+b;u=h,w=ra(b,0,c)+c|0,H[u+4>>2]=w}c=H[l+24>>2];if((H[l+28>>2]-c|0)<4){break h}f=0;while(1){g=H[(p<<2)+c>>2];m:{if((g|0)==-1){break m}n:{if(H[H[a+120>>2]+(p>>>3&536870908)>>2]>>>p&1){break n}n=H[a+216>>2];c=H[a+220>>2];if((n|0)==(c|0)){break n}e=g+2|0;i=(g>>>0)%3|0;q=i?g-1|0:e;c=(c-n|0)/144|0;r=c>>>0<=1?1:c;j=0;t=(i|0)!=0|(e|0)!=-1;while(1){s=g<<2;i=N(j,144)+n|0;c=H[s+H[H[i+68>>2]>>2]>>2];o:{if(!(H[H[i+16>>2]+(c>>>3&536870908)>>2]>>>c&1)){break o}c=-1;p:{if(!t){break p}e=H[H[l+12>>2]+(q<<2)>>2];c=-1;if((e|0)==-1){break p}c=e-1|0;if((e>>>0)%3|0){break p}c=e+2|0}if((g|0)==(c|0)){break o}e=s;s=H[i+32>>2];i=H[e+s>>2];while(1){e=0;if((c|0)==-1){break g}if((i|0)!=H[s+(c<<2)>>2]){g=c;break n}q:{r:{if((c>>>0)%3|0){e=c-1|0;break r}e=c+2|0;m=-1;if((e|0)==-1){break q}}c=H[H[l+12>>2]+(e<<2)>>2];m=-1;if((c|0)==-1){break q}m=c-1|0;if((c>>>0)%3|0){break q}m=c+2|0}c=m;if((g|0)!=(c|0)){continue}break}}j=j+1|0;if((r|0)!=(j|0)){continue}break}}i=k-f|0;e=i>>2;H[(g<<2)+b>>2]=e;s:{if(k>>>0>>0){H[k>>2]=g;k=k+4|0;H[h+20>>2]=k;break s}c=e+1|0;if(c>>>0>=1073741824){break k}d=o-f|0;k=d>>>1|0;c=d>>>0>=2147483644?1073741823:c>>>0>>0?k:c;if(c){if(c>>>0>=1073741824){break j}d=pa(c<<2)}else{d=0}e=d+(e<<2)|0;H[e>>2]=g;m=c<<2;c=va(d,f,i);o=m+c|0;H[h+24>>2]=o;k=e+4|0;H[h+20>>2]=k;H[h+16>>2]=c;if(f){oa(f);l=H[a+8>>2]}f=c}if((g|0)==-1){break m}t:{if((g>>>0)%3|0){c=g-1|0;break t}c=g+2|0;if((c|0)==-1){break m}}c=H[H[l+12>>2]+(c<<2)>>2];if((c|0)==-1){break m}c=c+((c>>>0)%3|0?-1:2)|0;if((c|0)==-1){break m}e=g;if((c|0)==(g|0)){break m}while(1){i=c;u:{v:{c=H[a+220>>2];j=H[a+216>>2];if((c|0)==(j|0)){break v}c=(c-j|0)/144|0;n=c>>>0<=1?1:c;c=0;while(1){q=H[(j+N(c,144)|0)+32>>2];r=i<<2;if(H[q+r>>2]==H[q+(e<<2)>>2]){c=c+1|0;if((n|0)!=(c|0)){continue}break v}break}j=k-d|0;e=j>>2;H[b+r>>2]=e;if(k>>>0>>0){H[k>>2]=i;k=k+4|0;H[h+20>>2]=k;f=d;break u}c=e+1|0;if(c>>>0>=1073741824){break i}f=o-d|0;k=f>>>1|0;c=f>>>0>=2147483644?1073741823:c>>>0>>0?k:c;if(c){if(c>>>0>=1073741824){break j}f=pa(c<<2)}else{f=0}e=f+(e<<2)|0;H[e>>2]=i;m=c<<2;c=va(f,d,j);o=m+c|0;H[h+24>>2]=o;k=e+4|0;H[h+20>>2]=k;H[h+16>>2]=c;if(!d){d=c;break u}oa(d);l=H[a+8>>2];d=c;break u}H[(i<<2)+b>>2]=H[(e<<2)+b>>2]}if((i|0)==-1){break m}w:{if((i>>>0)%3|0){c=i-1|0;break w}c=i+2|0;if((c|0)==-1){break m}}c=H[H[l+12>>2]+(c<<2)>>2];if((c|0)==-1){break m}c=c+((c>>>0)%3|0?-1:2)|0;if((c|0)==-1){break m}e=i;if((c|0)!=(g|0)){continue}break}}p=p+1|0;c=H[l+24>>2];if((p|0)>2]-c>>2){continue}break}break h}sa();v()}sa();v()}wa();v()}sa();v()}i=H[a+4>>2];a=H[i+44>>2];c=H[a+100>>2];a=H[a+96>>2];x:{if((c|0)==(a|0)){break x}g=(c-a|0)/12|0;f=g>>>0<=1?1:g;l=f&1;c=0;if(g>>>0>=2){j=f&-2;g=0;while(1){e=N(c,12);f=e+b|0;o=H[f>>2];p=H[f+4>>2];e=a+e|0;H[e+8>>2]=H[f+8>>2];H[e>>2]=o;H[e+4>>2]=p;e=N(c|1,12);f=e+b|0;o=H[f>>2];p=H[f+4>>2];e=a+e|0;H[e+8>>2]=H[f+8>>2];H[e>>2]=o;H[e+4>>2]=p;c=c+2|0;g=g+2|0;if((j|0)!=(g|0)){continue}break}}if(!l){break x}g=N(c,12);c=g+b|0;f=H[c>>2];e=H[c+4>>2];a=a+g|0;H[a+8>>2]=H[c+8>>2];H[a>>2]=f;H[a+4>>2]=e}H[H[i+4>>2]+80>>2]=k-d>>2;e=1}c=e;if(b){oa(b)}if(!d){break d}H[h+20>>2]=d;oa(d)}ca=h+32|0;return c}function Fj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,I=0,J=0,K=0,L=0,M=0,O=0,P=0;g=ca+-64|0;ca=g;H[a+8>>2]=e;y=a+32|0;f=H[y>>2];d=H[a+36>>2]-f>>2;a:{b:{if(d>>>0>>0){ya(y,e-d|0);H[g+56>>2]=0;H[g+60>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g>>2]=0;break b}if(d>>>0>e>>>0){H[a+36>>2]=f+(e<<2)}H[g+56>>2]=0;H[g+60>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g>>2]=0;d=0;if(!e){break a}}Pa(g+16|0,e,g);h=H[g+28>>2];d=H[g+32>>2]}H[g>>2]=0;d=d-h>>2;c:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break c}H[g+32>>2]=(e<<2)+h;break c}Pa(g+16|12,e-d|0,g)}H[g>>2]=0;f=H[g+40>>2];d=H[g+44>>2]-f>>2;d:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break d}H[g+44>>2]=f+(e<<2);break d}Pa(g+40|0,e-d|0,g)}H[g>>2]=0;f=H[g+52>>2];d=H[g+56>>2]-f>>2;e:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break e}H[g+56>>2]=f+(e<<2);break e}Pa(g+52|0,e-d|0,g)}f:{if(H[a+8>>2]<=0){break f}i=H[g+16>>2];j=H[a+32>>2];h=0;while(1){d=h<<2;f=H[d+i>>2];m=H[a+16>>2];g:{if((f|0)>(m|0)){H[d+j>>2]=m;break g}d=d+j|0;m=H[a+12>>2];if((m|0)>(f|0)){H[d>>2]=m;break g}H[d>>2]=f}h=h+1|0;d=H[a+8>>2];if((h|0)<(d|0)){continue}break}if((d|0)<=0){break f}d=0;while(1){i=d<<2;f=i+c|0;i=H[b+i>>2]+H[j+i>>2]|0;H[f>>2]=i;h:{if((i|0)>H[a+16>>2]){i=i-H[a+20>>2]|0}else{if((i|0)>=H[a+12>>2]){break h}i=i+H[a+20>>2]|0}H[f>>2]=i}d=d+1|0;if((d|0)>2]){continue}break}}G=H[a+52>>2];t=H[a+48>>2];z=pa(16);d=z;H[d>>2]=0;H[d+4>>2]=0;H[d+8>>2]=0;H[d+12>>2]=0;H[g+8>>2]=0;H[g>>2]=0;H[g+4>>2]=0;i:{if(e){if(e>>>0>=1073741824){break i}d=e<<2;r=pa(d);H[g>>2]=r;H[g+8>>2]=d+r;ra(r,0,d)}A=1;d=H[a+56>>2];B=H[d>>2];d=H[d+4>>2]-B|0;j:{if((d|0)<8){break j}w=d>>2;I=(w|0)<=2?2:w;J=w>>>0<=1?1:w;C=e&-2;D=e&1;K=e&-4;E=e&3;F=e-1|0;L=e<<2;M=e>>>0<4;A=0;m=1;while(1){k:{l:{m:{n:{if((m|0)!=(J|0)){o:{p:{f=H[(m<<2)+B>>2];if((f|0)==-1){break p}k=1;d=f+2|0;j=(f>>>0)%3|0;x=j?f-1|0:d;s=1<>2];O=n+(x>>>3&536870908)|0;i=0;P=(j|0)!=0|(d|0)!=-1;d=f;q:{while(1){r:{if(H[n+(d>>>3&536870908)>>2]>>>d&1){break r}j=H[H[H[t+64>>2]+12>>2]+(d<<2)>>2];if((j|0)==-1){break r}l=H[G>>2];h=H[t+28>>2];p=H[l+(H[h+(j<<2)>>2]<<2)>>2];if((p|0)>=(m|0)){break r}q=j+1|0;q=H[l+(H[h+(((q>>>0)%3|0?q:j-2|0)<<2)>>2]<<2)>>2];if((q|0)>=(m|0)){break r}h=H[l+(H[h+(j+((j>>>0)%3|0?-1:2)<<2)>>2]<<2)>>2];if((h|0)>=(m|0)){break r}s:{if(!e){break s}j=H[(g+16|0)+N(i,12)>>2];l=N(e,h);q=N(e,q);p=N(e,p);h=0;o=0;if(F){while(1){H[j+(h<<2)>>2]=(H[(h+l<<2)+c>>2]+H[(h+q<<2)+c>>2]|0)-H[(h+p<<2)+c>>2];u=h|1;H[j+(u<<2)>>2]=(H[(l+u<<2)+c>>2]+H[(q+u<<2)+c>>2]|0)-H[(p+u<<2)+c>>2];h=h+2|0;o=o+2|0;if((C|0)!=(o|0)){continue}break}}if(!D){break s}H[j+(h<<2)>>2]=(H[(h+l<<2)+c>>2]+H[(h+q<<2)+c>>2]|0)-H[(h+p<<2)+c>>2]}j=4;i=i+1|0;if((i|0)==4){break q}}t:{if(k&1){h=d-2|0;j=d+1|0;d=-1;j=(j>>>0)%3|0?j:h;if((j|0)==-1|H[n+(j>>>3&536870908)>>2]>>>j&1){break t}j=H[H[H[t+64>>2]+12>>2]+(j<<2)>>2];if((j|0)==-1){break t}d=j+1|0;d=(d>>>0)%3|0?d:j-2|0;break t}u:{if((d>>>0)%3|0){h=d-1|0;break u}h=d+2|0;d=-1;if((h|0)==-1){break t}}d=-1;if(H[n+(h>>>3&536870908)>>2]>>>h&1){break t}j=H[H[H[t+64>>2]+12>>2]+(h<<2)>>2];if((j|0)==-1){break t}if((j>>>0)%3|0){d=j-1|0;break t}d=j+2|0}v:{if((d|0)==(f|0)){break v}if((d|0)==-1&k){if(!P|s&H[O>>2]){break v}d=H[H[H[t+64>>2]+12>>2]+(x<<2)>>2];if((d|0)==-1){break v}k=0;d=(d>>>0)%3|0?d-1|0:d+2|0}if((d|0)!=-1){continue}}break}j=i;if((j|0)<=0){break p}}if(e){ra(r,0,L)}d=j-1|0;q=(d<<2)+z|0;d=N(d,12)+a|0;u=d;x=H[d- -64>>2];k=0;d=H[g>>2];f=0;while(1){i=H[q>>2];H[q>>2]=i+1;if(i>>>0>=x>>>0){break j}w:{if(H[H[u+60>>2]+(i>>>3&536870908)>>2]>>>i&1){break w}f=f+1|0;if(!e){break w}n=H[(g+16|0)+N(k,12)>>2];i=0;h=0;p=0;if(!M){while(1){l=h<<2;o=l+d|0;H[o>>2]=H[l+n>>2]+H[o>>2];o=l|4;s=o+d|0;H[s>>2]=H[n+o>>2]+H[s>>2];o=l|8;s=o+d|0;H[s>>2]=H[n+o>>2]+H[s>>2];l=l|12;o=l+d|0;H[o>>2]=H[l+n>>2]+H[o>>2];h=h+4|0;p=p+4|0;if((K|0)!=(p|0)){continue}break}}if(!E){break w}while(1){l=h<<2;p=l+d|0;H[p>>2]=H[l+n>>2]+H[p>>2];h=h+1|0;i=i+1|0;if((E|0)!=(i|0)){continue}break}}k=k+1|0;if((k|0)!=(j|0)){continue}break}i=N(e,m);if(!f){break o}if(!e){break l}h=0;d=0;if(F){break n}break m}i=N(e,m)}if(H[a+8>>2]<=0){break k}k=(N(m-1|0,e)<<2)+c|0;j=H[y>>2];h=0;while(1){d=h<<2;f=H[d+k>>2];n=H[a+16>>2];x:{if((f|0)>(n|0)){H[d+j>>2]=n;break x}d=d+j|0;n=H[a+12>>2];if((n|0)>(f|0)){H[d>>2]=n;break x}H[d>>2]=f}h=h+1|0;f=H[a+8>>2];if((h|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=i<<2;h=f+c|0;k=b+f|0;while(1){i=d<<2;f=i+h|0;i=H[i+k>>2]+H[j+i>>2]|0;H[f>>2]=i;y:{if((i|0)>H[a+16>>2]){i=i-H[a+20>>2]|0}else{if((i|0)>=H[a+12>>2]){break y}i=i+H[a+20>>2]|0}H[f>>2]=i}d=d+1|0;if((d|0)>2]){continue}break}break k}Ca();v()}while(1){j=h<<2;k=j+r|0;H[k>>2]=H[k>>2]/(f|0);j=(j|4)+r|0;H[j>>2]=H[j>>2]/(f|0);h=h+2|0;d=d+2|0;if((C|0)!=(d|0)){continue}break}}if(!D){break l}d=(h<<2)+r|0;H[d>>2]=H[d>>2]/(f|0)}if(H[a+8>>2]<=0){break k}j=H[y>>2];h=0;while(1){d=h<<2;f=H[d+r>>2];k=H[a+16>>2];z:{if((f|0)>(k|0)){H[d+j>>2]=k;break z}d=d+j|0;k=H[a+12>>2];if((k|0)>(f|0)){H[d>>2]=k;break z}H[d>>2]=f}h=h+1|0;f=H[a+8>>2];if((h|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=i<<2;h=f+c|0;k=b+f|0;while(1){i=d<<2;f=i+h|0;i=H[i+k>>2]+H[j+i>>2]|0;H[f>>2]=i;A:{if((i|0)>H[a+16>>2]){i=i-H[a+20>>2]|0}else{if((i|0)>=H[a+12>>2]){break A}i=i+H[a+20>>2]|0}H[f>>2]=i}d=d+1|0;if((d|0)>2]){continue}break}}m=m+1|0;A=(w|0)<=(m|0);if((m|0)!=(I|0)){continue}break}}a=H[g>>2];if(a){oa(a)}oa(z);a=H[g+52>>2];if(a){H[g+56>>2]=a;oa(a)}a=H[g+40>>2];if(a){H[g+44>>2]=a;oa(a)}a=H[g+28>>2];if(a){H[g+32>>2]=a;oa(a)}a=H[g+16>>2];if(a){H[g+20>>2]=a;oa(a)}ca=g- -64|0;return A|0}sa();v()}function oj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,I=0,J=0,K=0,L=0,M=0;h=ca+-64|0;ca=h;H[a+8>>2]=e;x=a+32|0;f=H[x>>2];d=H[a+36>>2]-f>>2;a:{b:{if(d>>>0>>0){ya(x,e-d|0);H[h+56>>2]=0;H[h+60>>2]=0;H[h+48>>2]=0;H[h+52>>2]=0;H[h+40>>2]=0;H[h+44>>2]=0;H[h+32>>2]=0;H[h+36>>2]=0;H[h+24>>2]=0;H[h+28>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;H[h>>2]=0;break b}if(d>>>0>e>>>0){H[a+36>>2]=f+(e<<2)}H[h+56>>2]=0;H[h+60>>2]=0;H[h+48>>2]=0;H[h+52>>2]=0;H[h+40>>2]=0;H[h+44>>2]=0;H[h+32>>2]=0;H[h+36>>2]=0;H[h+24>>2]=0;H[h+28>>2]=0;H[h+16>>2]=0;H[h+20>>2]=0;H[h>>2]=0;d=0;if(!e){break a}}Pa(h+16|0,e,h);i=H[h+28>>2];d=H[h+32>>2]}H[h>>2]=0;d=d-i>>2;c:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break c}H[h+32>>2]=(e<<2)+i;break c}Pa(h+16|12,e-d|0,h)}H[h>>2]=0;f=H[h+40>>2];d=H[h+44>>2]-f>>2;d:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break d}H[h+44>>2]=f+(e<<2);break d}Pa(h+40|0,e-d|0,h)}H[h>>2]=0;f=H[h+52>>2];d=H[h+56>>2]-f>>2;e:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break e}H[h+56>>2]=f+(e<<2);break e}Pa(h+52|0,e-d|0,h)}f:{if(H[a+8>>2]<=0){break f}g=H[h+16>>2];j=H[a+32>>2];i=0;while(1){d=i<<2;f=H[d+g>>2];m=H[a+16>>2];g:{if((f|0)>(m|0)){H[d+j>>2]=m;break g}d=d+j|0;m=H[a+12>>2];if((m|0)>(f|0)){H[d>>2]=m;break g}H[d>>2]=f}i=i+1|0;d=H[a+8>>2];if((i|0)<(d|0)){continue}break}if((d|0)<=0){break f}d=0;while(1){g=d<<2;f=g+c|0;g=H[b+g>>2]+H[g+j>>2]|0;H[f>>2]=g;h:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break h}g=g+H[a+20>>2]|0}H[f>>2]=g}d=d+1|0;if((d|0)>2]){continue}break}}G=H[a+52>>2];A=H[a+48>>2];y=pa(16);d=y;H[d>>2]=0;H[d+4>>2]=0;H[d+8>>2]=0;H[d+12>>2]=0;H[h+8>>2]=0;H[h>>2]=0;H[h+4>>2]=0;i:{if(e){if(e>>>0>=1073741824){break i}d=e<<2;t=pa(d);H[h>>2]=t;H[h+8>>2]=d+t;ra(t,0,d)}z=1;d=H[a+56>>2];B=H[d>>2];d=H[d+4>>2]-B|0;j:{if((d|0)<8){break j}w=d>>2;I=(w|0)<=2?2:w;J=w>>>0<=1?1:w;C=e&-2;D=e&1;K=e&-4;E=e&3;F=e-1|0;L=e<<2;M=e>>>0<4;z=0;m=1;while(1){k:{l:{m:{n:{if((m|0)!=(J|0)){o:{p:{f=H[(m<<2)+B>>2];if((f|0)==-1){break p}n=H[A+12>>2];d=f+2|0;g=(f>>>0)%3|0;q=n+((g?f-1|0:d)<<2)|0;j=0;u=(g|0)!=0|(d|0)!=-1;k=1;d=f;q:{while(1){g=H[n+(d<<2)>>2];r:{if((g|0)==-1){break r}l=-1;p=H[G>>2];r=H[A>>2];i=p+(H[r+(g<<2)>>2]<<2)|0;o=g+1|0;o=(o>>>0)%3|0?o:g-2|0;if((o|0)!=-1){l=H[r+(o<<2)>>2]}o=H[i>>2];s:{t:{if((g>>>0)%3|0){i=g-1|0;break t}i=g+2|0;s=-1;if((i|0)==-1){break s}}s=H[r+(i<<2)>>2]}if((m|0)<=(o|0)){break r}i=H[p+(l<<2)>>2];if((i|0)>=(m|0)){break r}l=H[p+(s<<2)>>2];if((l|0)>=(m|0)){break r}g=H[(h+16|0)+N(j,12)>>2];u:{if(!e){break u}l=N(e,l);r=N(e,i);p=N(e,o);i=0;s=0;if(F){while(1){H[g+(i<<2)>>2]=(H[(i+l<<2)+c>>2]+H[(i+r<<2)+c>>2]|0)-H[(i+p<<2)+c>>2];o=i|1;H[g+(o<<2)>>2]=(H[(l+o<<2)+c>>2]+H[(o+r<<2)+c>>2]|0)-H[(o+p<<2)+c>>2];i=i+2|0;s=s+2|0;if((C|0)!=(s|0)){continue}break}}if(!D){break u}H[g+(i<<2)>>2]=(H[(i+l<<2)+c>>2]+H[(i+r<<2)+c>>2]|0)-H[(i+p<<2)+c>>2]}g=4;j=j+1|0;if((j|0)==4){break q}}v:{if(k&1){i=d+1|0;d=(i>>>0)%3|0?i:d-2|0;g=-1;if((d|0)==-1){break v}d=H[n+(d<<2)>>2];g=-1;if((d|0)==-1){break v}g=d+1|0;g=(g>>>0)%3|0?g:d-2|0;break v}w:{if((d>>>0)%3|0){i=d-1|0;break w}i=d+2|0;g=-1;if((i|0)==-1){break v}}d=H[n+(i<<2)>>2];g=-1;if((d|0)==-1){break v}g=d-1|0;if((d>>>0)%3|0){break v}g=d+2|0}d=g;x:{if((f|0)==(d|0)){break x}if((d|0)==-1&k){if(!u){break x}d=H[q>>2];if((d|0)==-1){break x}k=0;d=(d>>>0)%3|0?d-1|0:d+2|0}if((d|0)!=-1){continue}}break}g=j;if((g|0)<=0){break p}}if(e){ra(t,0,L)}d=g-1|0;r=(d<<2)+y|0;d=N(d,12)+a|0;o=d;s=H[d- -64>>2];k=0;d=H[h>>2];f=0;while(1){j=H[r>>2];H[r>>2]=j+1;if(j>>>0>=s>>>0){break j}y:{if(H[H[o+60>>2]+(j>>>3&536870908)>>2]>>>j&1){break y}f=f+1|0;if(!e){break y}j=H[(h+16|0)+N(k,12)>>2];l=0;i=0;p=0;if(!M){while(1){n=i<<2;q=n+d|0;H[q>>2]=H[j+n>>2]+H[q>>2];q=n|4;u=q+d|0;H[u>>2]=H[j+q>>2]+H[u>>2];q=n|8;u=q+d|0;H[u>>2]=H[j+q>>2]+H[u>>2];n=n|12;q=n+d|0;H[q>>2]=H[j+n>>2]+H[q>>2];i=i+4|0;p=p+4|0;if((K|0)!=(p|0)){continue}break}}if(!E){break y}while(1){n=i<<2;p=n+d|0;H[p>>2]=H[j+n>>2]+H[p>>2];i=i+1|0;l=l+1|0;if((E|0)!=(l|0)){continue}break}}k=k+1|0;if((k|0)!=(g|0)){continue}break}g=N(e,m);if(!f){break o}if(!e){break l}i=0;d=0;if(F){break n}break m}g=N(e,m)}if(H[a+8>>2]<=0){break k}k=(N(m-1|0,e)<<2)+c|0;j=H[x>>2];i=0;while(1){d=i<<2;f=H[d+k>>2];l=H[a+16>>2];z:{if((f|0)>(l|0)){H[d+j>>2]=l;break z}d=d+j|0;l=H[a+12>>2];if((l|0)>(f|0)){H[d>>2]=l;break z}H[d>>2]=f}i=i+1|0;f=H[a+8>>2];if((i|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=g<<2;i=f+c|0;k=b+f|0;while(1){g=d<<2;f=g+i|0;g=H[g+k>>2]+H[g+j>>2]|0;H[f>>2]=g;A:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break A}g=g+H[a+20>>2]|0}H[f>>2]=g}d=d+1|0;if((d|0)>2]){continue}break}break k}Ca();v()}while(1){j=i<<2;k=j+t|0;H[k>>2]=H[k>>2]/(f|0);j=(j|4)+t|0;H[j>>2]=H[j>>2]/(f|0);i=i+2|0;d=d+2|0;if((C|0)!=(d|0)){continue}break}}if(!D){break l}d=(i<<2)+t|0;H[d>>2]=H[d>>2]/(f|0)}if(H[a+8>>2]<=0){break k}j=H[x>>2];i=0;while(1){d=i<<2;f=H[d+t>>2];k=H[a+16>>2];B:{if((f|0)>(k|0)){H[d+j>>2]=k;break B}d=d+j|0;k=H[a+12>>2];if((k|0)>(f|0)){H[d>>2]=k;break B}H[d>>2]=f}i=i+1|0;f=H[a+8>>2];if((i|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=g<<2;i=f+c|0;k=b+f|0;while(1){g=d<<2;f=g+i|0;g=H[g+k>>2]+H[g+j>>2]|0;H[f>>2]=g;C:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break C}g=g+H[a+20>>2]|0}H[f>>2]=g}d=d+1|0;if((d|0)>2]){continue}break}}m=m+1|0;z=(w|0)<=(m|0);if((m|0)!=(I|0)){continue}break}}a=H[h>>2];if(a){oa(a)}oa(y);a=H[h+52>>2];if(a){H[h+56>>2]=a;oa(a)}a=H[h+40>>2];if(a){H[h+44>>2]=a;oa(a)}a=H[h+28>>2];if(a){H[h+32>>2]=a;oa(a)}a=H[h+16>>2];if(a){H[h+20>>2]=a;oa(a)}ca=h- -64|0;return z|0}sa();v()}function Od(a,b,c,d,e){var f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0;i=ca-80|0;ca=i;H[i+76>>2]=b;y=i+55|0;r=i+56|0;a:{b:{c:{d:{e:while(1){h=b;if((o^2147483647)<(f|0)){break d}o=f+o|0;f:{g:{h:{f=h;g=I[f|0];if(g){while(1){i:{b=g&255;j:{if(!b){b=f;break j}if((b|0)!=37){break i}g=f;while(1){if(I[g+1|0]!=37){b=g;break j}f=f+1|0;j=I[g+2|0];b=g+2|0;g=b;if((j|0)==37){continue}break}}f=f-h|0;x=o^2147483647;if((f|0)>(x|0)){break d}if(a){Ab(a,h,f)}if(f){continue e}H[i+76>>2]=b;f=b+1|0;p=-1;if(!(I[b+2|0]!=36|F[b+1|0]-48>>>0>=10)){p=F[b+1|0]-48|0;s=1;f=b+3|0}H[i+76>>2]=f;n=0;g=F[f|0];b=g-32|0;k:{if(b>>>0>31){k=f;break k}k=f;b=1<>2]=k;n=b|n;g=F[f+1|0];b=g-32|0;if(b>>>0>=32){break k}f=k;b=1<>>0>=10)){H[((F[k+1|0]<<2)+e|0)-192>>2]=10;g=k+3|0;s=1;b=H[((F[k+1|0]<<3)+d|0)-384>>2];break m}if(s){break h}g=k+1|0;if(!a){H[i+76>>2]=g;s=0;q=0;break l}b=H[c>>2];H[c>>2]=b+4;s=0;b=H[b>>2]}H[i+76>>2]=g;q=b;if((b|0)>=0){break l}q=0-q|0;n=n|8192;break l}q=Nd(i+76|0);if((q|0)<0){break d}g=H[i+76>>2]}f=0;m=-1;n:{if(I[g|0]!=46){b=g;u=0;break n}if(I[g+1|0]==42){o:{if(!(I[g+3|0]!=36|F[g+2|0]-48>>>0>=10)){H[((F[g+2|0]<<2)+e|0)-192>>2]=10;b=g+4|0;m=H[((F[g+2|0]<<3)+d|0)-384>>2];break o}if(s){break h}b=g+2|0;m=0;if(!a){break o}j=H[c>>2];H[c>>2]=j+4;m=H[j>>2]}H[i+76>>2]=b;u=(m^-1)>>>31|0;break n}H[i+76>>2]=g+1;m=Nd(i+76|0);b=H[i+76>>2];u=1}while(1){g=f;k=28;l=b;f=F[b|0];if(f-123>>>0<4294967238){break c}b=l+1|0;f=I[(f+N(g,58)|0)+13711|0];if(f-1>>>0<8){continue}break}H[i+76>>2]=b;p:{q:{if((f|0)!=27){if(!f){break c}if((p|0)>=0){H[(p<<2)+e>>2]=f;j=(p<<3)+d|0;f=H[j+4>>2];H[i+64>>2]=H[j>>2];H[i+68>>2]=f;break q}if(!a){break f}Md(i- -64|0,f,c);break p}if((p|0)>=0){break c}}f=0;if(!a){continue e}}j=n&-65537;n=n&8192?j:n;p=0;t=1132;k=r;r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{C:{D:{E:{F:{G:{f=F[l|0];f=g?(f&15)==3?f&-33:f:f;switch(f-88|0){case 11:break r;case 9:case 13:case 14:case 15:break s;case 27:break x;case 12:case 17:break A;case 23:break B;case 0:case 32:break C;case 24:break D;case 22:break E;case 29:break F;case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 10:case 16:case 18:case 19:case 20:case 21:case 25:case 26:case 28:case 30:case 31:break g;default:break G}}H:{switch(f-65|0){case 0:case 4:case 5:case 6:break s;case 2:break v;case 1:case 3:break g;default:break H}}if((f|0)==83){break w}break g}l=H[i+64>>2];j=H[i+68>>2];t=1132;break z}f=0;I:{switch(g&255){case 0:H[H[i+64>>2]>>2]=o;continue e;case 1:H[H[i+64>>2]>>2]=o;continue e;case 2:h=H[i+64>>2];H[h>>2]=o;H[h+4>>2]=o>>31;continue e;case 3:G[H[i+64>>2]>>1]=o;continue e;case 4:F[H[i+64>>2]]=o;continue e;case 6:H[H[i+64>>2]>>2]=o;continue e;case 7:break I;default:continue e}}h=H[i+64>>2];H[h>>2]=o;H[h+4>>2]=o>>31;continue e}m=m>>>0<=8?8:m;n=n|8;f=120}h=r;l=H[i+64>>2];j=H[i+68>>2];if(l|j){z=f&32;while(1){h=h-1|0;F[h|0]=z|I[(l&15)+14240|0];w=!j&l>>>0>15|(j|0)!=0;g=j;j=g>>>4|0;l=(g&15)<<28|l>>>4;if(w){continue}break}}if(!(H[i+64>>2]|H[i+68>>2])|!(n&8)){break y}t=(f>>>4|0)+1132|0;p=2;break y}f=r;h=H[i+68>>2];j=h;l=H[i+64>>2];if(h|l){while(1){f=f-1|0;F[f|0]=l&7|48;g=!j&l>>>0>7|(j|0)!=0;h=j;j=h>>>3|0;l=(h&7)<<29|l>>>3;if(g){continue}break}}h=f;if(!(n&8)){break y}f=r-h|0;m=(f|0)<(m|0)?m:f+1|0;break y}l=H[i+64>>2];h=H[i+68>>2];j=h;if((h|0)<0){f=0-(((l|0)!=0)+j|0)|0;j=f;l=0-l|0;H[i+64>>2]=l;H[i+68>>2]=f;p=1;t=1132;break z}if(n&2048){p=1;t=1133;break z}p=n&1;t=p?1134:1132}g=r;if(j){while(1){g=g-1|0;f=j;w=Tj(l,f,10,0);h=da;A=g,B=l-Rj(w,h,10,0)|48,F[A|0]=B;l=w;j=h;if(f>>>0>9){continue}break}}h=l;if(h){while(1){g=g-1|0;f=(h>>>0)/10|0;F[g|0]=h-N(f,10)|48;j=h>>>0>9;h=f;if(j){continue}break}}h=g}if((m|0)<0?u:0){break d}n=u?n&-65537:n;f=H[i+64>>2];j=H[i+68>>2];if(!(m|(f|j)!=0)){h=r;m=0;break g}f=!(f|j)+(r-h|0)|0;m=(f|0)<(m|0)?m:f;break g}g=m>>>0>=2147483647?2147483647:m;k=g;n=(g|0)!=0;h=H[i+64>>2];h=h?h:1614;f=h;J:{K:{L:{M:{if(!(f&3)|!g){break M}while(1){if(!I[f|0]){break L}k=k-1|0;n=(k|0)!=0;f=f+1|0;if(!(f&3)){break M}if(k){continue}break}}if(!n){break K}if(!(!I[f|0]|k>>>0<4)){while(1){l=H[f>>2];if((l^-1)&l-16843009&-2139062144){break L}f=f+4|0;k=k-4|0;if(k>>>0>3){continue}break}}if(!k){break K}}while(1){if(!I[f|0]){break J}f=f+1|0;k=k-1|0;if(k){continue}break}}f=0}f=f?f-h|0:g;k=f+h|0;if((m|0)>=0){n=j;m=f;break g}n=j;m=f;if(I[k|0]){break d}break g}if(m){g=H[i+64>>2];break u}f=0;ib(a,32,q,0,n);break t}H[i+12>>2]=0;H[i+8>>2]=H[i+64>>2];g=i+8|0;H[i+64>>2]=g;m=-1}f=0;N:{while(1){h=H[g>>2];if(!h){break N}j=Ld(i+4|0,h);h=(j|0)<0;if(!(h|j>>>0>m-f>>>0)){g=g+4|0;f=f+j|0;if(m>>>0>f>>>0){continue}break N}break}if(h){break b}}k=61;if((f|0)<0){break c}ib(a,32,q,f,n);if(!f){f=0;break t}k=0;g=H[i+64>>2];while(1){h=H[g>>2];if(!h){break t}h=Ld(i+4|0,h);k=h+k|0;if(k>>>0>f>>>0){break t}Ab(a,i+4|0,h);g=g+4|0;if(f>>>0>k>>>0){continue}break}}ib(a,32,q,f,n^8192);f=(f|0)<(q|0)?q:f;continue e}if((m|0)<0?u:0){break d}v()}F[i+55|0]=H[i+64>>2];m=1;h=y;n=j;break g}g=I[f+1|0];f=f+1|0;continue}}if(a){break a}if(!s){break f}f=1;while(1){a=H[(f<<2)+e>>2];if(a){Md((f<<3)+d|0,a,c);o=1;f=f+1|0;if((f|0)!=10){continue}break a}break}o=1;if(f>>>0>=10){break a}while(1){if(H[(f<<2)+e>>2]){break h}f=f+1|0;if((f|0)!=10){continue}break}break a}k=28;break c}l=k-h|0;j=(m|0)>(l|0)?m:l;if((j|0)>(p^2147483647)){break d}k=61;g=j+p|0;f=(g|0)<(q|0)?q:g;if((x|0)<(f|0)){break c}ib(a,32,f,g,n);Ab(a,t,p);ib(a,48,f,g,n^65536);ib(a,48,j,l,0);Ab(a,h,l);ib(a,32,f,g,n^8192);continue}break}o=0;break a}k=61}H[3992]=k}o=-1}ca=i+80|0;return o}function hj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,G=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,Z=0,_=0;a:{b:{if((e|0)!=2){break b}H[a+8>>2]=2;H[a- -64>>2]=f;M=a+32|0;e=H[M>>2];d=H[a+36>>2]-e|0;c:{if(d>>>0<=7){ya(M,2-(d>>>2|0)|0);break c}if((d|0)==8){break c}H[a+36>>2]=e+8}i=1;d=H[a+56>>2];d=H[d+4>>2]-H[d>>2]|0;if((d|0)<=0){break b}o=a+60|0;d=d>>>2|0;X=d>>>0<=1?1:d;Y=a+68|0;d=0;while(1){f=H[a+56>>2];e=H[f>>2];if(H[f+4>>2]-e>>2>>>0<=d>>>0){break a}k=ca-80|0;ca=k;f=-1;d:{e:{e=H[e+(d<<2)>>2];if((e|0)==-1){break e}i=H[o+32>>2];g=e+1|0;g=(g>>>0)%3|0?g:e-2|0;if((g|0)!=-1){f=H[H[i>>2]+(g<<2)>>2]}p=-1;e=e+((e>>>0)%3|0?-1:2)|0;if((e|0)!=-1){p=H[H[i>>2]+(e<<2)>>2]}i=H[o+36>>2];e=H[i>>2];i=H[i+4>>2]-e>>2;if(i>>>0<=f>>>0|i>>>0<=p>>>0){break e}f:{g:{h:{i:{j:{k:{j=H[e+(p<<2)>>2];f=H[e+(f<<2)>>2];if((j|0)>=(d|0)|(f|0)>=(d|0)){break k}i=(j<<3)+c|0;w=H[i+4>>2];g=(f<<3)+c|0;e=H[g+4>>2];l=H[i>>2];i=H[g>>2];if(!((l|0)!=(i|0)|(e|0)!=(w|0))){H[o+8>>2]=i;H[o+12>>2]=e;break j}p=H[H[o+4>>2]+(d<<2)>>2];H[k+72>>2]=0;H[k+76>>2]=0;g=k- -64|0;H[g>>2]=0;H[g+4>>2]=0;H[k+56>>2]=0;H[k+60>>2]=0;g=H[o>>2];if(!I[g+84|0]){p=H[H[g+68>>2]+(p<<2)>>2]}Sa(g,p,F[g+24|0],k+56|0);p=H[H[o+4>>2]+(f<<2)>>2];H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f);i=g+n|0;f=da+x|0;f=g>>>0>i>>>0?f+1|0:f;n=i;g=Sj(Rj(j,q,C,J),da,r,s);i=g+B|0;h=da+P|0;h=g>>>0>i>>>0?h+1|0:h;g=m-i|0;i=V-((i>>>0>m>>>0)+h|0)|0;m=Rj(g,i,g,i);i=m+n|0;g=da+f|0;f=Rj(i,i>>>0>>0?g+1|0:g,r,s);i=da;m=i;if(!i&f>>>0<=1){break i}h=f;while(1){g=e<<1|l>>>31;l=l<<1;e=g;n=!i&h>>>0>7|(i|0)!=0;h=(i&3)<<30|h>>>2;i=i>>>2|0;if(n){continue}break}break h}if((d|0)>(f|0)){e=f<<1}else{if((d|0)<=0){H[o+8>>2]=0;H[o+12>>2]=0;break j}e=(d<<1)-2|0}e=(e<<2)+c|0;H[o+8>>2]=H[e>>2];H[o+12>>2]=H[e+4>>2]}p=1;break f}e=m;l=f;if(f-1|0){break g}}while(1){i=Tj(f,m,l,e);h=e+da|0;e=i+l|0;h=e>>>0>>0?h+1|0:h;l=(h&1)<<31|e>>>1;e=h>>>1|0;i=Rj(l,e,l,e);g=da;if((m|0)==(g|0)&f>>>0>>0|g>>>0>m>>>0){continue}break}}f=H[o+20>>2];if(!f){break f}g=f-1|0;h=H[H[o+16>>2]+(g>>>3&536870908)>>2];H[o+20>>2]=g;p=1;f=Rj(j,q,y,w);i=da;n=Rj(r,s,K,S);m=n+f|0;f=da+i|0;f=m>>>0>>0?f+1|0:f;i=Rj(l,e,D,W);g=h>>>g&1;h=g?0-i|0:i;m=h+m|0;n=f;f=da;i=n+(g?0-(f+((i|0)!=0)|0)|0:f)|0;Z=o,_=Sj(m,h>>>0>m>>>0?i+1|0:i,r,s),H[Z+12>>2]=_;f=Rj(j,q,D,W);i=da;j=Rj(r,s,Q,R);f=j+f|0;h=da+i|0;e=Rj(l,e,y,w);i=0-e|0;l=da;h=(f>>>0>>0?h+1|0:h)+(g?l:0-(((e|0)!=0)+l|0)|0)|0;i=g?e:i;f=i+f|0;Z=o,_=Sj(f,f>>>0>>0?h+1|0:h,r,s),H[Z+8>>2]=_}ca=k+80|0;e=p;break d}Ca();v()}i=e;if(!e){return 0}l:{if(H[a+8>>2]<=0){break l}l=H[M>>2];e=0;while(1){f=e<<2;g=H[f+Y>>2];j=H[a+16>>2];m:{if((g|0)>(j|0)){H[f+l>>2]=j;break m}f=f+l|0;j=H[a+12>>2];if((j|0)>(g|0)){H[f>>2]=j;break m}H[f>>2]=g}e=e+1|0;g=H[a+8>>2];if((e|0)<(g|0)){continue}break}f=0;if((g|0)<=0){break l}e=d<<3;j=e+c|0;q=b+e|0;while(1){g=f<<2;e=g+j|0;g=H[g+q>>2]+H[g+l>>2]|0;H[e>>2]=g;n:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break n}g=g+H[a+20>>2]|0}H[e>>2]=g}f=f+1|0;if((f|0)>2]){continue}break}}d=d+1|0;if((X|0)!=(d|0)){continue}break}}return i|0}Ca();v()}function xj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,G=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,Z=0,_=0;a:{b:{if((e|0)!=2){break b}H[a+8>>2]=2;H[a- -64>>2]=f;M=a+32|0;e=H[M>>2];d=H[a+36>>2]-e|0;c:{if(d>>>0<=7){ya(M,2-(d>>>2|0)|0);break c}if((d|0)==8){break c}H[a+36>>2]=e+8}p=1;d=H[a+56>>2];d=H[d+4>>2]-H[d>>2]|0;if((d|0)<=0){break b}o=a+60|0;d=d>>>2|0;X=d>>>0<=1?1:d;Y=a+68|0;d=0;while(1){e=H[a+56>>2];h=H[e>>2];if(H[e+4>>2]-h>>2>>>0<=d>>>0){break a}k=ca-80|0;ca=k;f=-1;h=H[h+(d<<2)>>2];e=-1;d:{if((h|0)==-1){break d}e=h+1|0;f=(e>>>0)%3|0?e:h-2|0;e=h-1|0;if((h>>>0)%3|0){break d}e=h+2|0}g=H[o+36>>2];h=H[g>>2];e:{f:{g:{h:{i:{g=H[g+4>>2]-h>>2;i=f<<2;f=H[H[o+32>>2]+28>>2];j=H[i+f>>2];if(g>>>0<=j>>>0){break i}e=H[f+(e<<2)>>2];if(e>>>0>=g>>>0){break i}j:{k:{l=H[h+(e<<2)>>2];f=H[h+(j<<2)>>2];if((l|0)>=(d|0)|(f|0)>=(d|0)){break k}h=(l<<3)+c|0;w=H[h+4>>2];g=(f<<3)+c|0;e=H[g+4>>2];j=H[h>>2];h=H[g>>2];if(!((j|0)!=(h|0)|(e|0)!=(w|0))){H[o+8>>2]=h;H[o+12>>2]=e;break j}p=H[H[o+4>>2]+(d<<2)>>2];H[k+72>>2]=0;H[k+76>>2]=0;g=k- -64|0;H[g>>2]=0;H[g+4>>2]=0;H[k+56>>2]=0;H[k+60>>2]=0;g=H[o>>2];if(!I[g+84|0]){p=H[H[g+68>>2]+(p<<2)>>2]}Sa(g,p,F[g+24|0],k+56|0);p=H[H[o+4>>2]+(f<<2)>>2];H[k+48>>2]=0;H[k+52>>2]=0;H[k+40>>2]=0;H[k+44>>2]=0;H[k+32>>2]=0;H[k+36>>2]=0;g=H[o>>2];if(!I[g+84|0]){p=H[H[g+68>>2]+(p<<2)>>2]}Sa(g,p,F[g+24|0],k+32|0);p=H[H[o+4>>2]+(l<<2)>>2];H[k+24>>2]=0;H[k+28>>2]=0;H[k+16>>2]=0;H[k+20>>2]=0;H[k+8>>2]=0;H[k+12>>2]=0;g=H[o>>2];if(!I[g+84|0]){p=H[H[g+68>>2]+(p<<2)>>2]}Sa(g,p,F[g+24|0],k+8|0);g=H[k+16>>2];n=H[k+40>>2];x=g-n|0;N=H[k+44>>2];g=H[k+20>>2]-(N+(g>>>0>>0)|0)|0;E=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0}e=(e<<2)+c|0;H[o+8>>2]=H[e>>2];H[o+12>>2]=H[e+4>>2]}p=1;break e}Ca();v()}e=m;j=f;if(f-1|0){break f}}while(1){h=Tj(f,m,j,e);i=e+da|0;e=h+j|0;i=e>>>0>>0?i+1|0:i;j=(i&1)<<31|e>>>1;e=i>>>1|0;h=Rj(j,e,j,e);g=da;if((m|0)==(g|0)&f>>>0>>0|g>>>0>m>>>0){continue}break}}f=H[o+20>>2];if(!f){break e}g=f-1|0;i=H[H[o+16>>2]+(g>>>3&536870908)>>2];H[o+20>>2]=g;p=1;f=Rj(l,q,y,w);h=da;n=Rj(r,s,K,S);m=n+f|0;f=da+h|0;f=m>>>0>>0?f+1|0:f;h=Rj(j,e,D,W);g=i>>>g&1;i=g?0-h|0:h;m=i+m|0;n=f;f=da;h=n+(g?0-(f+((h|0)!=0)|0)|0:f)|0;Z=o,_=Sj(m,i>>>0>m>>>0?h+1|0:h,r,s),H[Z+12>>2]=_;f=Rj(l,q,D,W);h=da;l=Rj(r,s,Q,R);f=l+f|0;i=da+h|0;e=Rj(j,e,y,w);h=0-e|0;j=da;i=(f>>>0>>0?i+1|0:i)+(g?j:0-(((e|0)!=0)+j|0)|0)|0;h=g?e:h;f=h+f|0;Z=o,_=Sj(f,f>>>0>>0?i+1|0:i,r,s),H[Z+8>>2]=_}ca=k+80|0;if(!p){return 0}l:{if(H[a+8>>2]<=0){break l}g=H[M>>2];e=0;while(1){f=e<<2;h=H[f+Y>>2];j=H[a+16>>2];m:{if((h|0)>(j|0)){H[f+g>>2]=j;break m}f=f+g|0;j=H[a+12>>2];if((j|0)>(h|0)){H[f>>2]=j;break m}H[f>>2]=h}e=e+1|0;h=H[a+8>>2];if((e|0)<(h|0)){continue}break}f=0;if((h|0)<=0){break l}e=d<<3;j=e+c|0;l=b+e|0;while(1){h=f<<2;e=h+j|0;h=H[h+l>>2]+H[h+g>>2]|0;H[e>>2]=h;n:{if((h|0)>H[a+16>>2]){i=h-H[a+20>>2]|0}else{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2]=0;H[a+548>>2]=0;H[a+560>>2]=0;H[a+552>>2]=0;H[a+556>>2]=0;H[a+564>>2]=0;H[a+568>>2]=0;H[a+580>>2]=0;H[a+572>>2]=0;H[a+576>>2]=0;H[a+584>>2]=0;H[a+588>>2]=0;H[a+600>>2]=0;H[a+592>>2]=0;H[a+596>>2]=0;H[a+612>>2]=0;H[a+604>>2]=0;H[a+608>>2]=0;g=a+628|0;a:{b:{if(b){if(b>>>0<1073741824){break b}sa();v()}H[a+616>>2]=0;H[a+620>>2]=0;H[a+624>>2]=0;H[e+8>>2]=0;H[e>>2]=0;H[e+4>>2]=0;d=1;break a}d=b<<2;c=pa(d);H[a+604>>2]=c;f=c+d|0;H[a+612>>2]=f;ra(c,0,d);H[a+624>>2]=0;H[a+616>>2]=0;H[a+620>>2]=0;H[a+608>>2]=f;c=pa(d);H[a+616>>2]=c;f=c+d|0;H[a+624>>2]=f;ra(c,0,d);H[a+620>>2]=f;c=pa(d);H[e>>2]=c;f=c+d|0;H[e+8>>2]=f;ra(c,0,d);H[e+4>>2]=f;d=b<<5|1}tb(g,d,e);c=H[e>>2];if(c){H[e+4>>2]=c;oa(c)}H[e+8>>2]=0;H[e>>2]=0;H[e+4>>2]=0;if(b){b=b<<2;c=pa(b);H[e>>2]=c;f=b+c|0;H[e+8>>2]=f;ra(c,0,b);H[e+4>>2]=f}tb(a+640|0,d,e);b=H[e>>2];if(b){H[e+4>>2]=b;oa(b)}ca=e+16|0;return a}function gc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=O(0),n=O(0),o=0;a:{b:{if(!d){break b}c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=F[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=J[b>>1];b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=G[b>>1];if((e|0)<0){break b}G[(g<<1)+d>>1]=e;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=H[b>>2];if(e+32768>>>0>65535){break b}G[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=H[b>>2];if(e>>>0>32767){break b}G[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;k=H[e+4>>2];while(1){if(b>>>0>=k>>>0){break b}h=H[b+4>>2];e=H[b>>2];i=e+32768|0;h=i>>>0<32768?h+1|0:h;if(!h&i>>>0>65535|h){break b}G[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=H[b+4>>2];e=H[b>>2];if(!k&e>>>0>32767|k){break b}G[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=H[a>>2];j=H[e>>2];g=j;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-j|0;if(!I[a+32|0]){j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(32767)|m>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(32767)|mO(1)){break d}e=(b<<1)+d|0;l=T(+m*32767+.5);f:{if(P(l)<2147483648){i=~~l;break f}i=-2147483648}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=1;if(c>>>0<=e>>>0){break d}ra((e<<1)+d|0,0,c-e<<1)}return j;case 9:g:{h:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=H[a>>2];j=H[e>>2];g=j;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-j|0;if(!I[a+32|0]){j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=M[g>>3];if(l>=32767|l<-32768|l!=l){break g}o=P(l);if(o==Infinity){break g}e=(b<<1)+d|0;if(o<2147483648){i=~~l}else{i=-2147483648}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=M[g>>3];if(l>=32767|l<-32768|(P(l)==Infinity|l!=l)){break g}if(l<0|l>1){break g}e=(b<<1)+d|0;l=T(l*32767+.5);i:{if(P(l)<2147483648){i=~~l;break i}i=-2147483648}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=1;if(c>>>0<=e>>>0){break g}ra((e<<1)+d|0,0,c-e<<1)}return j;case 10:break c;default:break b}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}ra((e<<1)+d|0,0,(c&255)-e<<1)}return j}ra((e<<1)+d|0,0,(c&255)-e<<1);return 1}function ec(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=O(0),n=O(0),o=0;a:{b:{if(!d){break b}c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=F[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=G[b>>1];b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=J[b>>1];b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=H[b>>2];b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=H[b>>2];if((e|0)<0){break b}H[(g<<2)+d>>2]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;k=H[e+4>>2];while(1){if(b>>>0>=k>>>0){break b}h=H[b+4>>2];e=H[b>>2];if(e- -2147483648>>>0<2147483648?h+1|0:h){break b}H[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=H[b+4>>2];e=H[b>>2];if(!k&e>>>0>2147483647|k){break b}H[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=H[a>>2];j=H[e>>2];g=j;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-j|0;if(!I[a+32|0]){j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(2147483648)|m>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(2147483648)|mO(1)){break d}e=(b<<2)+d|0;l=T(+m*2147483647+.5);f:{if(P(l)<2147483648){i=~~l;break f}i=-2147483648}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=1;if(c>>>0<=e>>>0){break d}ra((e<<2)+d|0,0,c-e<<2)}return j;case 9:g:{h:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=H[a>>2];j=H[e>>2];g=j;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-j|0;if(!I[a+32|0]){j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=M[g>>3];if(l>=2147483647|l<-2147483648|l!=l){break g}o=P(l);if(o==Infinity){break g}e=(b<<2)+d|0;if(o<2147483648){i=~~l}else{i=-2147483648}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=M[g>>3];if(l>=2147483647|l<-2147483648|(P(l)==Infinity|l!=l)){break g}if(l<0|l>1){break g}e=(b<<2)+d|0;l=T(l*2147483647+.5);i:{if(P(l)<2147483648){i=~~l;break i}i=-2147483648}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=1;if(c>>>0<=e>>>0){break g}ra((e<<2)+d|0,0,c-e<<2)}return j;case 10:break c;default:break b}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}ra((e<<2)+d|0,0,(c&255)-e<<2)}return j}ra((e<<2)+d|0,0,(c&255)-e<<2);return 1}function fc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=O(0);a:{b:{if(!d){break b}c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=F[b|0];if((e|0)<0){break b}G[(g<<1)+d>>1]=e&255;b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=G[b>>1];if((e|0)<0){break b}G[(g<<1)+d>>1]=e;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=J[b>>1];b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=H[b>>2];if(e>>>0>65535){break b}G[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=H[b>>2];if(e>>>0>65535){break b}G[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=H[b+4>>2];e=H[b>>2];if(!k&e>>>0>65535|k){break b}G[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=H[b+4>>2];e=H[b>>2];if(!k&e>>>0>65535|k){break b}G[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=H[a>>2];l=H[e>>2];g=l;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-l|0;if(!I[a+32|0]){l=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(65535)|m=O(0)){i=~~m>>>0}else{i=0}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}l=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(65535)|mO(1)){break d}e=(b<<1)+d|0;j=T(+m*65535+.5);f:{if(j<4294967296&j>=0){i=~~j>>>0;break f}i=0}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}l=1;if(c>>>0<=e>>>0){break d}ra((e<<1)+d|0,0,c-e<<1)}return l;case 9:g:{h:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=H[a>>2];l=H[e>>2];g=l;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-l|0;if(!I[a+32|0]){l=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=M[g>>3];if(j>=65535|j<0|(P(j)==Infinity|j!=j)){break g}e=(b<<1)+d|0;if(j<4294967296&j>=0){i=~~j>>>0}else{i=0}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}l=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=M[g>>3];if(j>=65535|j<0|(P(j)==Infinity|j!=j)){break g}if(j>1){break g}e=(b<<1)+d|0;j=T(j*65535+.5);i:{if(j<4294967296&j>=0){i=~~j>>>0;break i}i=0}G[e>>1]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}l=1;if(c>>>0<=e>>>0){break g}ra((e<<1)+d|0,0,c-e<<1)}return l;case 10:break c;default:break b}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];k=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}G[(g<<1)+d>>1]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}ra((e<<1)+d|0,0,(c&255)-e<<1)}return l}ra((e<<1)+d|0,0,(c&255)-e<<1);return 1}function Sa(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=O(0),l=0,m=0,n=O(0),o=0;a:{if(!d){break a}b:{c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;i=F[b|0];H[e>>2]=i;H[e+4>>2]=i>>31;b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;H[e>>2]=I[b|0];H[e+4>>2]=0;b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;i=G[b>>1];H[e>>2]=i;H[e+4>>2]=i>>31;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;H[e>>2]=J[b>>1];H[e+4>>2]=0;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;i=H[b>>2];H[e>>2]=i;H[e+4>>2]=i>>31;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;H[e>>2]=H[b>>2];H[e+4>>2]=0;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}i=H[b+4>>2];e=(g<<3)+d|0;H[e>>2]=H[b>>2];H[e+4>>2]=i;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=H[b>>2];i=H[b+4>>2];if((i|0)<0){break a}j=(g<<3)+d|0;H[j>>2]=e;H[j+4>>2]=i;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 8:d:{e=I[a+24|0];f=c&255;if(!(e>>>0>>0?e:f)){break d}if(I[a+32|0]){break a}e=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+e|0;e=H[a>>2];i=H[e+4>>2];e=H[e>>2];if((b|0)>=(i-e|0)){break a}g=b+e|0;h=c&255;b=0;while(1){k=L[g>>2];if(k>=O(0x8000000000000000)|k=O(1)?~~(k>O(0)?O(R(O(T(O(k*O(2.3283064365386963e-10)))),O(4294967296))):O(U(O(O(k-O(~~k>>>0>>>0))*O(2.3283064365386963e-10)))))>>>0:0;m=~~k>>>0;break e}j=-2147483648;m=0}H[e>>2]=m;H[e+4>>2]=j;b=b+1|0;e=I[a+24|0];if(b>>>0>=(e>>>0>>0?e:h)>>>0){break d}g=g+4|0;if(i>>>0>g>>>0){continue}break}break a}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 9:f:{e=I[a+24|0];f=c&255;if(!(e>>>0>>0?e:f)){break f}if(I[a+32|0]){break a}e=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+e|0;e=H[a>>2];i=H[e+4>>2];e=H[e>>2];if((b|0)>=(i-e|0)){break a}g=b+e|0;h=c&255;b=0;while(1){l=M[g>>3];if(l>=0x8000000000000000|l<-0x8000000000000000|l!=l){break a}o=P(l);if(o==Infinity){break a}e=(b<<3)+d|0;g:{if(o<0x8000000000000000){j=P(l)>=1?~~(l>0?R(T(l*2.3283064365386963e-10),4294967295):U((l-+(~~l>>>0>>>0))*2.3283064365386963e-10))>>>0:0;m=~~l>>>0;break g}j=-2147483648;m=0}H[e>>2]=m;H[e+4>>2]=j;b=b+1|0;e=I[a+24|0];if(b>>>0>=(e>>>0>>0?e:h)>>>0){break f}g=g+8|0;if(i>>>0>g>>>0){continue}break}break a}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 10:break c;default:break a}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;H[e>>2]=I[b|0];H[e+4>>2]=0;b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0}ra(d,0,a<<3)}}function Oj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;j=a;a:{b:{c:{d:{e:{f:{g:{h:{a=H[a+8>>2];switch(H[a+28>>2]-1|0){case 4:break c;case 5:break d;case 2:break e;case 3:break f;case 0:break g;case 1:break h;default:break a}}f=I[a+24|0];c=pa(f);a=H[j+16>>2];if(H[a+80>>2]){g=H[H[a>>2]>>2]+H[a+48>>2]|0}else{g=0}if(!b){break b}if(f){o=f&252;l=f&3;h=f>>>0<4;while(1){a=0;e=0;if(!h){while(1){k=g+(d<<2)|0;F[a+c|0]=H[k>>2];F[(a|1)+c|0]=H[k+4>>2];F[(a|2)+c|0]=H[k+8>>2];F[(a|3)+c|0]=H[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){F[a+c|0]=H[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[H[H[j+8>>2]+64>>2]>>2]+m|0,c,f);m=f+m|0;n=n+1|0;if((n|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,f);a=a+f|0;qa(a+H[H[H[j+8>>2]+64>>2]>>2]|0,c,f);a=a+f|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,f);break b}f=I[a+24|0];c=pa(f);a=H[j+16>>2];if(H[a+80>>2]){g=H[H[a>>2]>>2]+H[a+48>>2]|0}else{g=0}if(!b){break b}if(f){o=f&252;l=f&3;h=f>>>0<4;while(1){a=0;e=0;if(!h){while(1){k=g+(d<<2)|0;F[a+c|0]=H[k>>2];F[(a|1)+c|0]=H[k+4>>2];F[(a|2)+c|0]=H[k+8>>2];F[(a|3)+c|0]=H[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){F[a+c|0]=H[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[H[H[j+8>>2]+64>>2]>>2]+m|0,c,f);m=f+m|0;n=n+1|0;if((n|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,f);a=a+f|0;qa(a+H[H[H[j+8>>2]+64>>2]>>2]|0,c,f);a=a+f|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,f);break b}h=I[a+24|0];i=h<<1;c=pa(i);a=H[j+16>>2];if(H[a+80>>2]){g=H[H[a>>2]>>2]+H[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<1;k=g+(d<<2)|0;G[f+c>>1]=H[k>>2];G[(f|2)+c>>1]=H[k+4>>2];G[(f|4)+c>>1]=H[k+8>>2];G[(f|6)+c>>1]=H[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){G[(a<<1)+c>>1]=H[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[H[H[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;qa(a+H[H[H[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);break b}h=I[a+24|0];i=h<<1;c=pa(i);a=H[j+16>>2];if(H[a+80>>2]){g=H[H[a>>2]>>2]+H[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<1;k=g+(d<<2)|0;G[f+c>>1]=H[k>>2];G[(f|2)+c>>1]=H[k+4>>2];G[(f|4)+c>>1]=H[k+8>>2];G[(f|6)+c>>1]=H[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){G[(a<<1)+c>>1]=H[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[H[H[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;qa(a+H[H[H[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);break b}h=I[a+24|0];i=h<<2;c=pa(i);a=H[j+16>>2];if(H[a+80>>2]){g=H[H[a>>2]>>2]+H[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<2;k=g+(d<<2)|0;H[f+c>>2]=H[k>>2];H[(f|4)+c>>2]=H[k+4>>2];H[(f|8)+c>>2]=H[k+8>>2];H[(f|12)+c>>2]=H[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){H[(a<<2)+c>>2]=H[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[H[H[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;qa(a+H[H[H[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);break b}h=I[a+24|0];i=h<<2;c=pa(i);a=H[j+16>>2];if(H[a+80>>2]){g=H[H[a>>2]>>2]+H[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<2;k=g+(d<<2)|0;H[f+c>>2]=H[k>>2];H[(f|4)+c>>2]=H[k+4>>2];H[(f|8)+c>>2]=H[k+8>>2];H[(f|12)+c>>2]=H[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){H[(a<<2)+c>>2]=H[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[H[H[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;qa(a+H[H[H[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}qa(H[H[H[j+8>>2]+64>>2]>>2]+a|0,c,i)}oa(c);c=1}return c|0}function dc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=O(0);a:{b:{if(!d){break b}c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=F[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=G[b>>1];b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=J[b>>1];b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=H[b>>2];b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=H[b>>2];b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=H[b>>2];if(H[b+4>>2]){break b}H[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=H[b>>2];if(H[b+4>>2]){break b}H[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=H[a>>2];k=H[e>>2];g=k;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-k|0;if(!I[a+32|0]){k=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(4294967296)|m=O(0)){i=~~m>>>0}else{i=0}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}k=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=L[g>>2];if(m>=O(4294967296)|mO(1)){break d}e=(b<<2)+d|0;j=T(+m*4294967295+.5);f:{if(j<4294967296&j>=0){i=~~j>>>0;break f}i=0}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}k=1;if(c>>>0<=e>>>0){break d}ra((e<<2)+d|0,0,c-e<<2)}return k;case 9:g:{h:{e=I[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=H[a>>2];k=H[e>>2];g=k;f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=H[e+4>>2];e=f-k|0;if(!I[a+32|0]){k=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=M[g>>3];if(j>=4294967295|j<0|(P(j)==Infinity|j!=j)){break g}e=(b<<2)+d|0;if(j<4294967296&j>=0){i=~~j>>>0}else{i=0}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}k=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=M[g>>3];if(j>=4294967295|j<0|(P(j)==Infinity|j!=j)){break g}if(j>1){break g}e=(b<<2)+d|0;j=T(j*4294967295+.5);i:{if(j<4294967296&j>=0){i=~~j>>>0;break i}i=0}H[e>>2]=i;b=b+1|0;e=I[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}k=1;if(c>>>0<=e>>>0){break g}ra((e<<2)+d|0,0,c-e<<2)}return k;case 10:break c;default:break b}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];h=H[e>>2];l=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=H[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}H[(g<<2)+d>>2]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}ra((e<<2)+d|0,0,(c&255)-e<<2)}return k}ra((e<<2)+d|0,0,(c&255)-e<<2);return 1}function ye(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;a:{b:{c:{d:{e:{if(H[a+92>>2]==H[a+88>>2]){break e}c=H[a+52>>2];f:{if((c|0)!=H[a+56>>2]){H[c>>2]=b;H[a+52>>2]=c+4;break f}h=H[a+48>>2];g=c-h|0;d=g>>2;f=d+1|0;if(f>>>0>=1073741824){break a}e=g>>>1|0;g=g>>>0>=2147483644?1073741823:f>>>0>>0?e:f;if(g){if(g>>>0>=1073741824){break d}e=pa(g<<2)}else{e=0}f=e+(d<<2)|0;H[f>>2]=b;d=f+4|0;if((c|0)!=(h|0)){while(1){f=f-4|0;c=c-4|0;H[f>>2]=H[c>>2];if((c|0)!=(h|0)){continue}break}}H[a+56>>2]=e+(g<<2);H[a+52>>2]=d;H[a+48>>2]=f;if(!h){break f}oa(h)}H[a+84>>2]=0;c=-1;e=-1;g:{if((b|0)==-1){break g}d=H[a+4>>2];e=b+1|0;e=(e>>>0)%3|0?e:b-2|0;if((e|0)!=-1){c=H[H[d>>2]+(e<<2)>>2]}h:{if((b>>>0)%3|0){l=b-1|0;break h}l=b+2|0;e=-1;if((l|0)==-1){break g}}e=H[H[d>>2]+(l<<2)>>2]}i=e>>>3&536870908;d=H[a+36>>2];h=d+(c>>>3&536870908)|0;g=H[h>>2];f=1<>2]=f|g;f=a+8|0;if((b|0)!=-1){d=b+1|0;d=(d>>>0)%3|0?d:b-2|0}else{d=-1}Ua(f,c,d);d=H[a+36>>2]}f=d+i|0;d=H[f>>2];c=1<>2]=c|d;d=a+8|0;c=-1;i:{if((b|0)==-1){break i}c=b-1|0;if((b>>>0)%3|0){break i}c=b+2|0}Ua(d,e,c)}c=-1;c=(b|0)!=-1?H[H[H[a+4>>2]>>2]+(b<<2)>>2]:c;f=H[a+36>>2]+(c>>>3&536870908)|0;d=H[f>>2];e=1<>2]=d|e;Ua(a+8|0,c,b)}d=H[a+84>>2];if((d|0)>2){break e}while(1){e=N(d,12)+a|0;b=H[e+52>>2];if((b|0)==H[e+48>>2]){d=d+1|0;if((d|0)!=3){continue}break e}b=b-4|0;c=H[b>>2];H[e+52>>2]=b;H[a+84>>2]=d;if((c|0)==-1){break e}f=H[a+24>>2];b=(c>>>0)/3|0;j:{if(H[f+(b>>>3&268435452)>>2]>>>b&1){break j}k:{while(1){k=(c>>>0)/3|0;b=(k>>>3&268435452)+f|0;H[b>>2]=H[b>>2]|1<>2]>>2]+(c<<2)>>2]:d;f=H[a+36>>2]+(d>>>3&536870908)|0;e=H[f>>2];b=1<>2]=b|e;i=H[(H[H[a+16>>2]+96>>2]+N(k,12)|0)+((c>>>0)%3<<2)>>2];l=H[H[a+20>>2]+4>>2];f=H[l+4>>2];t:{if((f|0)!=H[l+8>>2]){H[f>>2]=i;H[l+4>>2]=f+4;break t}j=H[l>>2];h=f-j|0;g=h>>2;e=g+1|0;if(e>>>0>=1073741824){break s}b=h>>>1|0;h=h>>>0>=2147483644?1073741823:b>>>0>e>>>0?b:e;if(h){if(h>>>0>=1073741824){break d}e=pa(h<<2)}else{e=0}b=e+(g<<2)|0;H[b>>2]=i;g=b+4|0;if((f|0)!=(j|0)){while(1){b=b-4|0;f=f-4|0;H[b>>2]=H[f>>2];if((f|0)!=(j|0)){continue}break}}H[l+8>>2]=e+(h<<2);H[l+4>>2]=g;H[l>>2]=b;if(!j){break t}oa(j)}j=H[a+12>>2];f=H[j+4>>2];u:{if((f|0)!=H[j+8>>2]){H[f>>2]=c;H[j+4>>2]=f+4;break u}i=H[j>>2];h=f-i|0;g=h>>2;e=g+1|0;if(e>>>0>=1073741824){break r}b=h>>>1|0;h=h>>>0>=2147483644?1073741823:b>>>0>e>>>0?b:e;if(h){if(h>>>0>=1073741824){break d}e=pa(h<<2)}else{e=0}b=e+(g<<2)|0;H[b>>2]=c;g=b+4|0;if((f|0)!=(i|0)){while(1){b=b-4|0;f=f-4|0;H[b>>2]=H[f>>2];if((f|0)!=(i|0)){continue}break}}H[j+8>>2]=e+(h<<2);H[j+4>>2]=g;H[j>>2]=b;if(!i){break u}oa(i)}b=H[a+12>>2];H[H[b+12>>2]+(d<<2)>>2]=H[b+24>>2];H[b+24>>2]=H[b+24>>2]+1}if((c|0)==-1){break k}g=H[a+4>>2];f=-1;b=c+1|0;b=(b>>>0)%3|0?b:c-2|0;if((b|0)!=-1){f=H[H[g+12>>2]+(b<<2)>>2]}v:{w:{if((N(k,3)|0)!=(c|0)){d=c-1|0;break w}d=c+2|0;c=-1;if((d|0)==-1){break v}}c=H[H[g+12>>2]+(d<<2)>>2]}d=(c|0)==-1;e=(c>>>0)/3|0;if((f|0)!=-1){b=(f>>>0)/3|0;b=H[H[a+24>>2]+(b>>>3&268435452)>>2]&1<>2]+(b>>>3&536870908)>>2]>>>b&1){break x}k=0;b=H[H[g>>2]+(c<<2)>>2];if(!(H[H[a+36>>2]+(b>>>3&536870908)>>2]>>>b&1)){b=H[a+88>>2]+(b<<2)|0;e=H[b>>2];H[b>>2]=e+1;k=(e|0)<=0?2:1}if(H[a+84>>2]>=(k|0)&l){break m}j=N(k,12)+a|0;b=H[j+52>>2];y:{if((b|0)!=H[j+56>>2]){H[b>>2]=c;H[j+52>>2]=b+4;break y}i=H[j+48>>2];h=b-i|0;d=h>>2;g=d+1|0;if(g>>>0>=1073741824){break c}e=h>>>1|0;g=h>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(g){if(g>>>0>=1073741824){break d}e=pa(g<<2)}else{e=0}d=e+(d<<2)|0;H[d>>2]=c;c=d+4|0;if((b|0)!=(i|0)){while(1){d=d-4|0;b=b-4|0;H[d>>2]=H[b>>2];if((b|0)!=(i|0)){continue}break}}H[j+48>>2]=d;H[j+52>>2]=c;H[j+56>>2]=e+(g<<2);if(!i){break y}oa(i)}if(H[a+84>>2]<=(k|0)){break x}H[a+84>>2]=k}if(l){break k}c=-1;if((f|0)==-1){break n}}c=H[H[H[a+4>>2]>>2]+(f<<2)>>2]}b=0;if(!(H[H[a+36>>2]+(c>>>3&536870908)>>2]>>>c&1)){b=H[a+88>>2]+(c<<2)|0;c=H[b>>2];H[b>>2]=c+1;b=(c|0)<=0?2:1}if(H[a+84>>2]<(b|0)){break l}c=f}f=H[a+24>>2];continue}break}k=N(b,12)+a|0;c=H[k+52>>2];z:{if((c|0)!=H[k+56>>2]){H[c>>2]=f;H[k+52>>2]=c+4;break z}i=H[k+48>>2];h=c-i|0;d=h>>2;g=d+1|0;if(g>>>0>=1073741824){break b}e=h>>>1|0;g=h>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(g){if(g>>>0>=1073741824){break d}e=pa(g<<2)}else{e=0}d=e+(d<<2)|0;H[d>>2]=f;f=d+4|0;if((c|0)!=(i|0)){while(1){d=d-4|0;c=c-4|0;H[d>>2]=H[c>>2];if((c|0)!=(i|0)){continue}break}}H[k+48>>2]=d;H[k+52>>2]=f;H[k+56>>2]=e+(g<<2);if(!i){break z}oa(i)}d=H[a+84>>2];if((d|0)<=(b|0)){break j}H[a+84>>2]=b;d=b;break j}d=H[a+84>>2]}if((d|0)<3){continue}break}}return 1}wa();v()}sa();v()}sa();v()}sa();v()}function gd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;n=ca-96|0;ca=n;o=H[a+4>>2];d=H[o+32>>2];i=H[d+8>>2];j=H[d+12>>2];e=j;c=H[d+20>>2];f=H[d+16>>2];a:{if((e|0)<=(c|0)&f>>>0>=i>>>0|(c|0)>(e|0)){break a}p=H[d>>2];g=I[p+f|0];h=f+1|0;e=h?c:c+1|0;H[d+16>>2]=h;H[d+20>>2]=e;if((e|0)>=(j|0)&h>>>0>=i>>>0|(e|0)>(j|0)){break a}m=I[h+p|0];h=f+2|0;e=h>>>0<2?c+1|0:c;H[d+16>>2]=h;H[d+20>>2]=e;l=g<<24>>24;b:{if((l|0)>=0){k=H[a+216>>2];if(g>>>0>=(H[a+220>>2]-k|0)/144>>>0){break a}k=k+N(g,144)|0;if(H[k>>2]<0){break b}break a}if(H[a+212>>2]>=0){break a}k=a+212|0}H[k>>2]=b;c:{d:{e:{f:{g:{h:{k=J[o+36>>1];i:{if(((k<<8|k>>>8)&65535)>>>0>=258){if((e|0)>=(j|0)&h>>>0>=i>>>0|(e|0)>(j|0)){break a}e=I[h+p|0];f=f+3|0;c=f>>>0<3?c+1|0:c;H[d+16>>2]=f;H[d+20>>2]=c;if(e>>>0>1){break a}d=e>>>0<2?e:0;if(!m){break i}if(!d){break h}break a}if(m){break g}d=0}if((l|0)<0){e=a+184|0}else{c=H[a+216>>2]+N(g,144)|0;F[c+100|0]=0;e=c+104|0}if((d|0)!=1){break e}c=ca-112|0;ca=c;h=H[H[a+4>>2]+44>>2];d=pa(120);H[d>>2]=12172;H[d+4>>2]=0;H[d+116>>2]=0;H[d+112>>2]=e;H[d+108>>2]=h;H[d+12>>2]=0;H[d+16>>2]=0;H[d+20>>2]=0;H[d+24>>2]=0;H[d+28>>2]=0;H[d+32>>2]=0;H[d+36>>2]=0;H[d+40>>2]=0;H[d+44>>2]=0;H[d+48>>2]=0;H[d+52>>2]=0;H[d+56>>2]=0;H[d+60>>2]=0;H[d+8>>2]=12384;f=d- -64|0;H[f>>2]=0;H[f+4>>2]=0;H[d+72>>2]=0;H[d+76>>2]=0;H[d+80>>2]=0;H[d+84>>2]=0;H[d+88>>2]=0;H[d+104>>2]=0;H[d+96>>2]=0;H[d+100>>2]=0;f=H[a+8>>2];H[c+48>>2]=0;H[c+52>>2]=0;H[c+40>>2]=0;H[c+44>>2]=0;i=c+32|0;H[i>>2]=0;H[i+4>>2]=0;H[c+24>>2]=0;H[c+28>>2]=0;g=c- -64|0;H[g>>2]=0;H[g+4>>2]=0;H[c+72>>2]=0;H[c+76>>2]=0;H[c+80>>2]=0;H[c+84>>2]=0;H[c+88>>2]=0;H[c+104>>2]=0;H[c+16>>2]=0;H[c+20>>2]=0;H[c+56>>2]=0;H[c+60>>2]=0;H[c+8>>2]=12384;H[c+96>>2]=0;H[c+100>>2]=0;H[c+12>>2]=f;g=H[f>>2];j=H[f+4>>2];F[c+111|0]=0;m=i;i=c+111|0;Oa(m,(j-g>>2>>>0)/3|0,i);g=H[c+12>>2];j=H[g+28>>2];g=H[g+24>>2];F[c+111|0]=0;Oa(c+44|0,j-g>>2,i);H[c+28>>2]=d;H[c+24>>2]=h;H[c+20>>2]=e;H[c+16>>2]=f;f=d+8|0;e=c+8|0;fd(f,e);j:{if((e|0)==(f|0)){H[d+92>>2]=H[e+84>>2];break j}Cb(d+56|0,H[e+48>>2],H[e+52>>2]);Cb(d+68|0,H[e+60>>2],H[e- -64>>2]);Cb(d+80|0,H[e+72>>2],H[e+76>>2]);H[d+92>>2]=H[e+84>>2];Aa(d+96|0,H[e+88>>2],H[e+92>>2])}H[c+8>>2]=12384;e=H[c+96>>2];if(e){H[c+100>>2]=e;oa(e)}e=H[c+80>>2];if(e){H[c+84>>2]=e;oa(e)}e=H[c+68>>2];if(e){H[c+72>>2]=e;oa(e)}e=H[c+56>>2];if(e){H[c+60>>2]=e;oa(e)}H[c+8>>2]=12620;e=H[c+44>>2];if(e){oa(e)}e=H[c+32>>2];if(e){oa(e)}ca=c+112|0;break d}if((l|0)>=0){break f}break a}if((l|0)<0){break a}}e=H[a+216>>2];c=H[o+44>>2];d=pa(80);H[d>>2]=12932;H[d+4>>2]=0;H[d+76>>2]=0;H[d+68>>2]=c;H[d+8>>2]=11872;H[d+12>>2]=0;H[d+16>>2]=0;H[d+20>>2]=0;H[d+24>>2]=0;H[d+28>>2]=0;H[d+32>>2]=0;H[d+36>>2]=0;H[d+40>>2]=0;H[d+44>>2]=0;H[d+48>>2]=0;H[d+52>>2]=0;e=e+N(g,144)|0;f=e+104|0;H[d+72>>2]=f;H[d- -64>>2]=0;H[d+56>>2]=0;H[d+60>>2]=0;H[n+24>>2]=c;c=n;H[c+68>>2]=0;H[c+72>>2]=0;H[c+60>>2]=0;H[c+64>>2]=0;H[c+52>>2]=0;H[c+56>>2]=0;H[c+44>>2]=0;H[c+48>>2]=0;H[c+84>>2]=0;H[c+88>>2]=0;H[c+76>>2]=0;H[c+80>>2]=0;H[c+28>>2]=d;h=H[c+28>>2];H[c+8>>2]=H[c+24>>2];H[c+12>>2]=h;H[c+20>>2]=f;f=e+4|0;H[c+16>>2]=f;H[c+36>>2]=0;H[c+40>>2]=0;H[c+32>>2]=11872;e=H[c+20>>2];H[c>>2]=H[c+16>>2];H[c+4>>2]=e;e=c+32|0;Ie(e,f,c);c=d+8|0;fd(c,e);if((c|0)!=(e|0)){Cb(d+56|0,H[e+48>>2],H[e+52>>2])}He(e);break c}c=ca+-64|0;ca=c;h=H[H[a+4>>2]+44>>2];d=pa(80);H[d>>2]=12640;H[d+4>>2]=0;H[d+76>>2]=0;H[d+72>>2]=e;H[d+68>>2]=h;H[d+8>>2]=12804;H[d+12>>2]=0;H[d+16>>2]=0;H[d+20>>2]=0;H[d+24>>2]=0;H[d+28>>2]=0;H[d+32>>2]=0;H[d+36>>2]=0;H[d+40>>2]=0;H[d+44>>2]=0;H[d+48>>2]=0;H[d+52>>2]=0;H[d- -64>>2]=0;i=d+56|0;f=i;H[f>>2]=0;H[f+4>>2]=0;f=H[a+8>>2];H[c+40>>2]=0;H[c+44>>2]=0;H[c+32>>2]=0;H[c+36>>2]=0;g=c+24|0;H[g>>2]=0;H[g+4>>2]=0;H[c+16>>2]=0;H[c+20>>2]=0;H[c+56>>2]=0;H[c+8>>2]=0;H[c+12>>2]=0;H[c+48>>2]=0;H[c+52>>2]=0;H[c>>2]=12804;H[c+4>>2]=f;j=H[f>>2];l=H[f+4>>2];F[c+63|0]=0;m=g;g=c+63|0;Oa(m,(l-j>>2>>>0)/3|0,g);j=H[c+4>>2];l=H[j+28>>2];j=H[j+24>>2];F[c+63|0]=0;Oa(c+36|0,l-j>>2,g);H[c+20>>2]=d;H[c+16>>2]=h;H[c+12>>2]=e;H[c+8>>2]=f;fd(d+8|0,c);Cb(i,H[c+48>>2],H[c+52>>2]);H[c>>2]=12804;e=H[c+48>>2];if(e){H[c+52>>2]=e;oa(e)}H[c>>2]=12620;e=H[c+36>>2];if(e){oa(e)}e=H[c+24>>2];if(e){oa(e)}ca=c- -64|0}if(!d){break a}}d=od(pa(64),d);c=H[a+4>>2];a=d;d=b;k:{l:{if((d|0)>=0){h=c+8|0;b=H[c+12>>2];i=H[c+8>>2];e=b-i>>2;m:{if((e|0)>(d|0)){break m}f=d+1|0;if(d>>>0>=e>>>0){Vb(h,f-e|0);break m}if(e>>>0<=f>>>0){break m}f=i+(f<<2)|0;if((f|0)!=(b|0)){while(1){b=b-4|0;e=H[b>>2];H[b>>2]=0;if(e){ea[H[H[e>>2]+4>>2]](e)}if((b|0)!=(f|0)){continue}break}}H[c+12>>2]=f}c=H[h>>2]+(d<<2)|0;b=H[c>>2];H[c>>2]=a;if(b){break l}break k}b=a;if(!a){break k}}ea[H[H[b>>2]+4>>2]](b)}q=(d^-1)>>>31|0}ca=n+96|0;return q|0}function Kd(a){var b=0,c=0,d=0,e=0,f=0,g=0;e=ca-16|0;ca=e;H[e+12>>2]=a;a:{if(a>>>0<=211){d=H[Jd(14256,14448,e+12|0)>>2];break a}if(a>>>0>=4294967292){X();v()}f=(a>>>0)/210|0;d=N(f,210);H[e+8>>2]=a-d;g=Jd(14448,14640,e+8|0)-14448>>2;while(1){d=H[(g<<2)+14448>>2]+d|0;a=5;while(1){b:{if((a|0)==47){a=211;while(1){b=(d>>>0)/(a>>>0)|0;if(b>>>0>>0){break a}if((N(a,b)|0)==(d|0)){break b}b=a+10|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+12|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+16|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+18|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+22|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+28|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+30|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+36|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+40|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+42|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+46|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+52|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+58|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+60|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+66|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+70|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+72|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+78|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+82|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+88|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+96|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+100|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+102|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+106|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+108|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+112|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+120|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+126|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+130|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+136|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+138|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+142|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+148|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+150|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+156|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+162|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+166|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+168|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+172|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+178|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+180|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+186|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+190|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+192|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+196|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+198|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((N(b,c)|0)==(d|0)){break b}b=a+208|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}a=a+210|0;if((N(b,c)|0)!=(d|0)){continue}break}break b}b=H[(a<<2)+14256>>2];c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}a=a+1|0;if((N(b,c)|0)!=(d|0)){continue}}break}d=g+1|0;a=(d|0)==48;g=a?0:d;f=a+f|0;d=N(f,210);continue}}ca=e+16|0;return d}function Ib(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;j=ca-16|0;ca=j;a:{b:{c:{d:{if(I[H[a+4>>2]+36|0]<=1){k=-1;c=H[b+20>>2];d=H[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;g=H[b+12>>2];if(K[b+8>>2]>>0&(g|0)<=(c|0)|(c|0)>(g|0)){break c}d=d+H[b>>2]|0;l=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[j+12>>2]=l;H[b+16>>2]=e;H[b+20>>2]=c;break d}k=-1;if(!Ea(1,j+12|0,b)){break c}l=H[j+12>>2]}e:{f:{g:{h:{i:{if(!l){break i}c=H[a+8>>2];if((H[c+4>>2]-H[c>>2]>>2>>>0)/3>>>0>>0){break c}c=J[H[a+4>>2]+36>>1];if(((c<<8|c>>>8)&65535)>>>0>=258){j:{while(1){if(!Ea(1,j+8|0,b)){break c}c=H[j+8>>2];if(!Ea(1,j+8|0,b)){break c}f=c+f|0;c=H[j+8>>2];if(f>>>0>>0){break c}g=f-c|0;c=H[a+40>>2];k:{if((c|0)!=H[a+44>>2]){H[c+4>>2]=f;H[c>>2]=g;H[a+40>>2]=c+12;l=H[j+12>>2];break k}m=H[a+36>>2];d=c-m|0;o=(d|0)/12|0;e=o+1|0;if(e>>>0>=357913942){break j}c=o<<1;h=o>>>0>=178956970?357913941:c>>>0>e>>>0?c:e;if(h){if(h>>>0>=357913942){break b}i=pa(N(h,12))}else{i=0}e=i+N(o,12)|0;H[e+4>>2]=f;H[e>>2]=g;c=va(e+N((d|0)/-12|0,12)|0,m,d);H[a+44>>2]=i+N(h,12);H[a+40>>2]=e+12;H[a+36>>2]=c;if(!m){break k}oa(m)}p=p+1|0;if(l>>>0>p>>>0){continue}break}k=0;Db(b,0,0);if(l){while(1){e=I[b+36|0];c=J[H[a+4>>2]+36>>1];l:{m:{if(((c<<8|c>>>8)&65535)>>>0<=513){if(!e){break l}p=0;c=H[b+32>>2];n=c>>>3|0;g=H[b+24>>2];e=n+g|0;d=H[b+28>>2];n:{if(e>>>0>=d>>>0){f=c;break n}e=I[e|0];f=c+1|0;H[b+32>>2]=f;n=f>>>3|0;p=e>>>(c&7)&1}if(d>>>0>g+n>>>0){break m}break l}if(!e){break l}p=0;f=H[b+32>>2];c=H[b+24>>2]+(f>>>3|0)|0;if(c>>>0>=K[b+28>>2]){break l}p=I[c|0]>>>(f&7)&1}H[b+32>>2]=f+1}c=H[a+36>>2]+N(k,12)|0;F[c+8|0]=I[c+8|0]&254|p&1;k=k+1|0;if((k|0)!=(l|0)){continue}break}}F[b+36|0]=0;f=H[b+20>>2];e=0;d=H[b+32>>2]+7|0;e=d>>>0<7?1:e;c=e>>>3|0;e=(e&7)<<29|d>>>3;d=e+H[b+16>>2]|0;c=c+f|0;H[b+16>>2]=d;H[b+20>>2]=d>>>0>>0?c+1|0:c;break i}sa();v()}while(1){d=H[b+8>>2];c=H[b+12>>2];g=c;c=H[b+20>>2];e=c;h=H[b+16>>2];f=h+4|0;c=f>>>0<4?c+1|0:c;i=f;if(f>>>0>d>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break c}m=H[b>>2];f=m+h|0;o=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=i;H[b+20>>2]=c;c=e;f=h+8|0;c=f>>>0<8?c+1|0:c;if(d>>>0>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break c}i=i+m|0;i=I[i|0]|I[i+1|0]<<8|(I[i+2|0]<<16|I[i+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=c;if(d>>>0<=f>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break c}d=I[f+m|0];c=h+9|0;e=c>>>0<9?e+1|0:e;H[b+16>>2]=c;H[b+20>>2]=e;f=d&1;c=H[a+40>>2];o:{if((c|0)!=H[a+44>>2]){F[c+8|0]=f;H[c+4>>2]=i;H[c>>2]=o;H[a+40>>2]=c+12;l=H[j+12>>2];break o}m=H[a+36>>2];d=c-m|0;h=(d|0)/12|0;e=h+1|0;if(e>>>0>=357913942){break h}c=h<<1;g=h>>>0>=178956970?357913941:c>>>0>e>>>0?c:e;if(g){if(g>>>0>=357913942){break b}e=pa(N(g,12))}else{e=0}h=e+N(h,12)|0;F[h+8|0]=f;H[h+4>>2]=i;H[h>>2]=o;c=va(h+N((d|0)/-12|0,12)|0,m,d);H[a+44>>2]=e+N(g,12);H[a+40>>2]=h+12;H[a+36>>2]=c;if(!m){break o}oa(m)}n=n+1|0;if(l>>>0>n>>>0){continue}break}}H[j+8>>2]=0;c=J[H[a+4>>2]+36>>1];c=(c<<8|c>>>8)&65535;p:{if(c>>>0<=511){k=-1;c=H[b+20>>2];d=H[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;f=H[b+12>>2];if(K[b+8>>2]>>0&(f|0)<=(c|0)|(c|0)>(f|0)){break c}d=d+H[b>>2]|0;f=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;break p}if((c|0)!=512){break e}k=-1;if(!Ea(1,j+8|0,b)){break c}f=H[j+8>>2]}if(!f){break e}c=J[H[a+4>>2]+36>>1];if(((c<<8|c>>>8)&65535)>>>0<258){break f}n=0;l=0;while(1){if(!Ea(1,j+4|0,b)){break c}l=H[j+4>>2]+l|0;c=H[a+52>>2];q:{if((c|0)!=H[a+56>>2]){H[c>>2]=l;H[a+52>>2]=c+4;break q}i=H[a+48>>2];g=c-i|0;e=g>>2;d=e+1|0;if(d>>>0>=1073741824){break g}c=g>>>1|0;d=g>>>0>=2147483644?1073741823:c>>>0>d>>>0?c:d;if(d){if(d>>>0>=1073741824){break b}c=pa(d<<2)}else{c=0}e=c+(e<<2)|0;H[e>>2]=l;c=va(c,i,g);H[a+56>>2]=c+(d<<2);H[a+52>>2]=e+4;H[a+48>>2]=c;if(!i){break q}oa(i)}n=n+1|0;if((n|0)!=(f|0)){continue}break}break e}sa();v()}sa();v()}k=0;while(1){c=H[b+20>>2];d=H[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;g=H[b+12>>2];if(K[b+8>>2]>>0&(g|0)<=(c|0)|(c|0)>(g|0)){k=-1;break c}d=d+H[b>>2]|0;g=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;c=H[a+52>>2];r:{if((c|0)!=H[a+56>>2]){H[c>>2]=g;H[a+52>>2]=c+4;break r}h=H[a+48>>2];i=c-h|0;e=i>>2;d=e+1|0;if(d>>>0>=1073741824){break a}c=i>>>1|0;d=i>>>0>=2147483644?1073741823:c>>>0>d>>>0?c:d;if(d){if(d>>>0>=1073741824){break b}c=pa(d<<2)}else{c=0}e=c+(e<<2)|0;H[e>>2]=g;c=va(c,h,i);H[a+56>>2]=c+(d<<2);H[a+52>>2]=e+4;H[a+48>>2]=c;if(!h){break r}oa(h)}k=k+1|0;if((k|0)!=(f|0)){continue}break}}k=H[b+16>>2]}ca=j+16|0;return k}wa();v()}sa();v()}function Va(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=O(0),k=0,l=0;a:{if(!d){break a}b:{c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(F[b|0]);L[(h<<2)+d>>2]=i?O(j/O(127)):j;b=b+1|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(I[b|0]);L[(h<<2)+d>>2]=i?O(j/O(255)):j;b=b+1|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(G[b>>1]);L[(h<<2)+d>>2]=i?O(j/O(32767)):j;b=b+2|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(J[b>>1]);L[(h<<2)+d>>2]=i?O(j/O(65535)):j;b=b+2|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(H[b>>2]);L[(h<<2)+d>>2]=i?O(j*O(4.656612873077393e-10)):j;b=b+4|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(K[b>>2]);L[(h<<2)+d>>2]=i?O(j*O(2.3283064365386963e-10)):j;b=b+4|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(+K[b>>2]+ +H[b+4>>2]*4294967296);L[(h<<2)+d>>2]=i?O(j*O(10842021724855044e-35)):j;b=b+8|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];i=I[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=O(+K[b>>2]+ +K[b+4>>2]*4294967296);L[(h<<2)+d>>2]=i?O(j*O(5.421010862427522e-20)):j;b=b+8|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 8:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];while(1){if(b>>>0>=g>>>0){break a}L[(h<<2)+d>>2]=L[b>>2];b=b+4|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 9:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];while(1){if(b>>>0>=g>>>0){break a}L[(h<<2)+d>>2]=M[b>>3];b=b+8|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 10:break c;default:break a}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[a>>2];g=H[e>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=H[e+4>>2];while(1){if(b>>>0>=g>>>0){break a}L[(h<<2)+d>>2]=I[b|0]?O(1):O(0);b=b+1|0;h=h+1|0;e=I[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0}ra(d,0,a<<2)}return l}function ic(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=O(0),m=O(0);a:{b:{if(!d){break b}c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}F[d+g|0]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){return 0}e=F[b|0];if((e|0)<0){break b}F[d+g|0]=e;b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=J[b>>1];if((e+128&65535)>>>0>255){break b}F[d+g|0]=e;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=J[b>>1];if(e>>>0>127){break b}F[d+g|0]=e;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>2];if(e+128>>>0>255){break b}F[d+g|0]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>2];if(e>>>0>127){break b}F[d+g|0]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}i=H[b+4>>2];e=H[b>>2];h=e+128|0;i=h>>>0<128?i+1|0:i;if(!i&h>>>0>255|i){break b}F[d+g|0]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}i=H[b+4>>2];e=H[b>>2];if(!i&e>>>0>127|i){break b}F[d+g|0]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 8:e=I[a+24|0];c=c&255;d:{if(c>>>0>e>>>0?e:c){e=H[H[a>>2]>>2];f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+f|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break d}l=L[b>>2];if(l>=O(127)|lO(1)){break d}j=T(+l*127+.5);if(!(P(j)<2147483648)){break f}h=~~j;break e}if(!(m>>0<(c>>>0>e>>>0?e:c)>>>0){continue}break}}k=1;if(c>>>0<=e>>>0){break d}ra(d+e|0,0,c-e|0)}return k;case 9:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}j=M[b>>3];if(j>=127|j<-128|(P(j)==Infinity|j!=j)){break b}e=d+g|0;if(I[a+32|0]){if(j<0|j>1){break b}j=T(j*127+.5)}g:{if(P(j)<2147483648){h=~~j;break g}h=-2147483648}F[e|0]=h;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 10:break c;default:break b}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}F[d+g|0]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}ra(d+e|0,0,(c&255)-e|0)}return k}ra(d+e|0,0,(c&255)-e|0);return 1}function hc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=O(0);a:{b:{if(!d){break b}c:{switch(H[a+28>>2]-1|0){case 0:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){return 0}e=F[b|0];if((e|0)<0){break b}F[d+g|0]=e;b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}F[d+g|0]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=J[b>>1];if(e>>>0>255){break b}F[d+g|0]=e;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=J[b>>1];if(e>>>0>255){break b}F[d+g|0]=e;b=b+2|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>2];if(e>>>0>255){break b}F[d+g|0]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>2];if(e>>>0>255){break b}F[d+g|0]=e;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}i=H[b+4>>2];e=H[b>>2];if(!i&e>>>0>255|i){break b}F[d+g|0]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}i=H[b+4>>2];e=H[b>>2];if(!i&e>>>0>255|i){break b}F[d+g|0]=e;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 8:e=I[a+24|0];c=c&255;d:{if(c>>>0>e>>>0?e:c){e=H[H[a>>2]>>2];f=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+f|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break d}l=L[b>>2];if(l>=O(255)|lO(1)){break d}j=T(+l*255+.5);if(!(j<4294967296&j>=0)){break f}h=~~j>>>0;break e}if(!(l=O(0))){break f}h=~~l>>>0;break e}h=0}F[e|0]=h;b=b+4|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(c>>>0>e>>>0?e:c)>>>0){continue}break}}k=1;if(c>>>0<=e>>>0){break d}ra(d+e|0,0,c-e|0)}return k;case 9:e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}j=M[b>>3];if(j>=255|j<0|(P(j)==Infinity|j!=j)){break b}e=d+g|0;if(I[a+32|0]){if(j>1){break b}j=T(j*255+.5)}g:{if(j<4294967296&j>=0){h=~~j>>>0;break g}h=0}F[e|0]=h;b=b+8|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 10:break c;default:break b}}e=I[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=H[H[a>>2]>>2];i=H[a+48>>2];b=Rj(H[a+40>>2],H[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(K[H[a>>2]+4>>2]<=b>>>0){break b}F[d+g|0]=I[b|0];b=b+1|0;g=g+1|0;e=I[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}ra(d+e|0,0,(c&255)-e|0)}return k}ra(d+e|0,0,(c&255)-e|0);return 1}function Hh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;g=ca-32|0;ca=g;i=H[a+32>>2];b=J[a+36>>1];a:{b:{if(((b<<8|b>>>8)&65535)>>>0<=513){b=H[i+8>>2];d=H[i+12>>2];c=b;b=H[i+20>>2];e=b;j=H[i+16>>2];f=j+4|0;b=f>>>0<4?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break a}n=H[i>>2];k=n+j|0;k=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);H[i+16>>2]=f;H[i+20>>2]=b;h=c;c=d;b=e;d=j+8|0;b=d>>>0<8?b+1|0:b;if(d>>>0>h>>>0&(b|0)>=(c|0)|(b|0)>(c|0)){break a}c=f+n|0;n=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[i+16>>2]=d;H[i+20>>2]=b;break b}if(!Fb(1,g+28|0,i)){break a}if(!Fb(1,g+24|0,H[a+32>>2])){break a}k=H[g+28>>2];n=H[g+24>>2]}if(k>>>0>1431655765){break a}d=H[a+32>>2];b=d;j=H[b+8>>2];c=H[b+16>>2];f=H[b+12>>2];b=H[b+20>>2];e=Sj(j-c|0,f-(b+(c>>>0>j>>>0)|0)|0,3,0);if(!da&e>>>0>>0){break a}e=Rj(k,0,3,0);if(!da&e>>>0>>0|((b|0)>=(f|0)&c>>>0>=j>>>0|(b|0)>(f|0))){break a}j=I[c+H[d>>2]|0];c=c+1|0;b=c?b:b+1|0;H[d+16>>2]=c;H[d+20>>2]=b;c:{d:{if(!j){d=0;c=ca-32|0;ca=c;H[c+24>>2]=0;H[c+16>>2]=0;H[c+20>>2]=0;e:{f:{b=N(k,3);if(b){if(b>>>0>=1073741824){break f}j=N(k,12);d=pa(j);ra(d,0,j)}b=kd(b,1,H[a+32>>2],d);g:{h:{if(!(!k|!b)){j=0;while(1){i:{b=(j<<2)+d|0;f=H[b>>2];e=f>>>1|0;f=(f&1?0-e|0:e)+l|0;if((f|0)<0){break i}H[c>>2]=f;e=H[b+4>>2];h=e>>>1|0;f=f+(e&1?0-h|0:h)|0;if((f|0)<0){break i}H[c+4>>2]=f;b=H[b+8>>2];e=b>>>1|0;l=f+(b&1?0-e|0:e)|0;if((l|0)<0){break i}H[c+8>>2]=l;Rb(H[a+44>>2]+96|0,c);j=j+3|0;b=1;o=o+1|0;if((o|0)!=(k|0)){continue}break h}break}b=0;break h}if(!d){break g}}oa(d)}ca=c+32|0;break e}sa();v()}if(b){break d}break a}if(n>>>0<=255){if(!k){break d}while(1){j:{H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;d=H[a+32>>2];b=d;j=H[b+16>>2];e=H[b+8>>2];c=H[b+20>>2];h=H[b+12>>2];b=h;if(e>>>0<=j>>>0&(c|0)>=(b|0)|(b|0)<(c|0)){break j}i=H[d>>2];l=I[i+j|0];b=c;f=j+1|0;b=f?b:b+1|0;H[d+16>>2]=f;H[d+20>>2]=b;H[g+8>>2]=l;l=e>>>0>>0&(c|0)>=(h|0)|(c|0)>(h|0);e=l?j:e;h=l?c:h;if((e|0)==(f|0)&(h|0)==(b|0)){break j}l=I[f+i|0];b=c;f=j+2|0;b=f>>>0<2?b+1|0:b;H[d+16>>2]=f;H[d+20>>2]=b;H[g+12>>2]=l;if((e|0)==(f|0)&(b|0)==(h|0)){break j}f=I[f+i|0];b=c;c=j+3|0;b=c>>>0<3?b+1|0:b;H[d+16>>2]=c;H[d+20>>2]=b;H[g+16>>2]=f;Rb(H[a+44>>2]+96|0,g+8|0);m=m+1|0;if((m|0)!=(k|0)){continue}break d}break}m=0;break a}if(n>>>0<=65535){if(!k){break d}while(1){k:{H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;i=H[a+32>>2];b=i;c=H[b+8>>2];d=H[b+12>>2];f=H[b+16>>2];b=H[b+20>>2];j=b;e=f+2|0;b=e>>>0<2?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break k}l=H[i>>2];h=l+f|0;h=I[h|0]|I[h+1|0]<<8;H[i+16>>2]=e;H[i+20>>2]=b;H[g+8>>2]=h;b=j;h=f+4|0;b=h>>>0<4?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break k}e=e+l|0;e=I[e|0]|I[e+1|0]<<8;H[i+16>>2]=h;H[i+20>>2]=b;H[g+12>>2]=e;e=c;b=j;c=f+6|0;b=c>>>0<6?b+1|0:b;if(c>>>0>e>>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break k}d=h+l|0;d=I[d|0]|I[d+1|0]<<8;H[i+16>>2]=c;H[i+20>>2]=b;H[g+16>>2]=d;Rb(H[a+44>>2]+96|0,g+8|0);m=m+1|0;if((m|0)!=(k|0)){continue}break d}break}m=0;break a}l:{if(n>>>0>2097151){break l}b=J[a+36>>1];if(((b<<8|b>>>8)&65535)>>>0<514){break l}if(!k){break d}while(1){m:{H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;if(!Fb(1,g+4|0,H[a+32>>2])){break m}H[g+8>>2]=H[g+4>>2];if(!Fb(1,g+4|0,H[a+32>>2])){break m}H[g+12>>2]=H[g+4>>2];if(!Fb(1,g+4|0,H[a+32>>2])){break m}H[g+16>>2]=H[g+4>>2];Rb(H[a+44>>2]+96|0,g+8|0);m=m+1|0;if((m|0)!=(k|0)){continue}break d}break}m=0;break a}if(!k){break d}while(1){H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;i=H[a+32>>2];b=i;c=H[b+8>>2];d=H[b+12>>2];f=H[b+16>>2];b=H[b+20>>2];j=b;e=f+4|0;b=e>>>0<4?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break c}l=H[i>>2];h=l+f|0;h=I[h|0]|I[h+1|0]<<8|(I[h+2|0]<<16|I[h+3|0]<<24);H[i+16>>2]=e;H[i+20>>2]=b;H[g+8>>2]=h;b=j;h=f+8|0;b=h>>>0<8?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break c}e=e+l|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[i+16>>2]=h;H[i+20>>2]=b;H[g+12>>2]=e;e=c;b=j;c=f+12|0;b=c>>>0<12?b+1|0:b;if(c>>>0>e>>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break c}d=h+l|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[i+16>>2]=c;H[i+20>>2]=b;H[g+16>>2]=d;Rb(H[a+44>>2]+96|0,g+8|0);m=m+1|0;if((m|0)!=(k|0)){continue}break}}H[H[a+4>>2]+80>>2]=n;m=1;break a}m=0}ca=g+32|0;return m|0}function zf(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=O(0),w=0;p=ca-16|0;ca=p;a:{if(!(H[a+60>>2]!=H[a- -64>>2]|H[a+48>>2]!=H[a+52>>2])){j=1;break a}j=1;if((ea[H[H[a>>2]+24>>2]](a)|0)<=0){break a}while(1){b:{b=ea[H[H[a>>2]+20>>2]](a,w)|0;c:{d:{e:{f=H[H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+8>>2]+(b<<2)>>2];switch(H[f+28>>2]-1|0){case 8:break d;case 0:case 2:case 4:break e;default:break c}}b=I[f+24|0];f:{if(!b){n=0;j=0;break f}j=0;b=b<<2;n=pa(b);ra(n,0,b);b=I[f+24|0];if(!b){break f}b=b<<2;j=pa(b);ra(j,0,b)}g:{h:{i:{switch(H[f+28>>2]-1|0){case 4:i=0;h=0;d=0;b=0;k=0;e=I[f+24|0];j:{if(!e){g=0;break j}e=e<<2;h=pa(e);ra(h,0,e);g=pa(e);ra(g,0,e)}k:{if(H[f+80>>2]){while(1){o=H[f>>2];c=H[o>>2];m=H[f+48>>2];e=H[f+40>>2];l=Rj(e,H[f+44>>2],d,b);m=m+l|0;s=c+m|0;c=e;m=qa(h,s,c);l=I[f+24|0];if(l){t=H[a+48>>2];e=0;while(1){r=e<<2;s=H[r+m>>2];if((s|0)<0){break k}H[g+r>>2]=s+H[t+(e+u<<2)>>2];e=e+1|0;if((l|0)!=(e|0)){continue}break}}qa(H[o>>2]+N(d,c)|0,g,c);d=d+1|0;b=d?b:b+1|0;if(!b&K[f+80>>2]>d>>>0){continue}break}}k=1}if(g){oa(g)}if(h){oa(h)}if(k){break h}break g;case 2:g=0;e=0;d=0;b=0;c=I[f+24|0];if(c){c=c<<1;e=pa(c);ra(e,0,c);g=pa(c);ra(g,0,c)}if(H[f+80>>2]){while(1){l=H[f>>2];h=H[l>>2];i=H[f+48>>2];c=H[f+40>>2];k=Rj(c,H[f+44>>2],d,b);i=i+k|0;k=qa(e,h+i|0,c);o=I[f+24|0];l:{if(!o){break l}m=H[a+48>>2];h=0;if((o|0)!=1){t=o&254;i=0;while(1){r=h<<1;G[r+g>>1]=J[k+r>>1]+J[m+(h+u<<2)>>1];r=h|1;s=r<<1;G[s+g>>1]=J[k+s>>1]+J[m+(r+u<<2)>>1];h=h+2|0;i=i+2|0;if((t|0)!=(i|0)){continue}break}}if(!(o&1)){break l}i=h<<1;G[i+g>>1]=J[i+k>>1]+J[m+(h+u<<2)>>1]}qa(H[l>>2]+N(d,c)|0,g,c);d=d+1|0;b=d?b:b+1|0;if(!b&K[f+80>>2]>d>>>0){continue}break}}if(g){oa(g)}if(e){oa(e)}break h;case 0:break i;default:break h}}h=0;e=0;d=0;b=0;c=I[f+24|0];if(c){e=pa(c);ra(e,0,c);h=pa(c);ra(h,0,c)}if(H[f+80>>2]){while(1){t=H[f>>2];g=H[t>>2];i=H[f+48>>2];c=H[f+40>>2];k=Rj(c,H[f+44>>2],d,b);i=i+k|0;k=qa(e,g+i|0,c);o=I[f+24|0];m:{if(!o){break m}m=H[a+48>>2];g=0;if((o|0)!=1){r=o&254;i=0;while(1){F[g+h|0]=I[g+k|0]+I[m+(g+u<<2)|0];l=g|1;F[l+h|0]=I[k+l|0]+I[m+(l+u<<2)|0];g=g+2|0;i=i+2|0;if((r|0)!=(i|0)){continue}break}}if(!(o&1)){break m}F[g+h|0]=I[g+k|0]+I[m+(g+u<<2)|0]}qa(H[t>>2]+N(d,c)|0,h,c);d=d+1|0;b=d?b:b+1|0;if(!b&K[f+80>>2]>d>>>0){continue}break}}if(h){oa(h)}if(e){oa(e)}}u=I[f+24|0]+u|0;i=1}if(j){oa(j)}if(n){oa(n)}if(i){break c}j=0;break a}e=H[H[a+60>>2]+(q<<2)>>2];h=H[a+36>>2];g=H[(ea[H[H[a>>2]+28>>2]](a)|0)+40>>2];H[p+12>>2]=H[f+56>>2];b=pa(32);H[p>>2]=b;H[p+4>>2]=24;H[p+8>>2]=-2147483616;d=I[1206]|I[1207]<<8|(I[1208]<<16|I[1209]<<24);c=I[1202]|I[1203]<<8|(I[1204]<<16|I[1205]<<24);F[b+16|0]=c;F[b+17|0]=c>>>8;F[b+18|0]=c>>>16;F[b+19|0]=c>>>24;F[b+20|0]=d;F[b+21|0]=d>>>8;F[b+22|0]=d>>>16;F[b+23|0]=d>>>24;d=I[1198]|I[1199]<<8|(I[1200]<<16|I[1201]<<24);c=I[1194]|I[1195]<<8|(I[1196]<<16|I[1197]<<24);F[b+8|0]=c;F[b+9|0]=c>>>8;F[b+10|0]=c>>>16;F[b+11|0]=c>>>24;F[b+12|0]=d;F[b+13|0]=d>>>8;F[b+14|0]=d>>>16;F[b+15|0]=d>>>24;d=I[1190]|I[1191]<<8|(I[1192]<<16|I[1193]<<24);c=I[1186]|I[1187]<<8|(I[1188]<<16|I[1189]<<24);F[b|0]=c;F[b+1|0]=c>>>8;F[b+2|0]=c>>>16;F[b+3|0]=c>>>24;F[b+4|0]=d;F[b+5|0]=d>>>8;F[b+6|0]=d>>>16;F[b+7|0]=d>>>24;F[b+24|0]=0;d=sd(g,p+12|0,p);if(F[p+11|0]<0){oa(H[p>>2])}b=q+1|0;n:{if(d){oe(f,e);break n}g=h+N(q,24)|0;q=H[g+4>>2];c=I[f+24|0];h=c<<2;d=pa(h);H[p>>2]=1065353216;v=L[g+20>>2];q=-1<0){L[p>>2]=v/O(q|0)}if((q|0)<=0){break b}o:{if(!H[e+80>>2]){break o}if(!c){n=0;j=0;while(1){qa(H[H[f+64>>2]>>2]+j|0,d,h);j=h+j|0;n=n+1|0;if(n>>>0>2]){continue}break}break o}o=H[H[e>>2]>>2]+H[e+48>>2]|0;t=c&254;r=c&1;i=0;k=0;j=0;while(1){q=H[g+8>>2];v=L[p>>2];n=0;m=0;if((c|0)!=1){while(1){l=n<<2;s=o+(j<<2)|0;L[l+d>>2]=O(v*O(H[s>>2]))+L[l+q>>2];l=l|4;L[l+d>>2]=O(v*O(H[s+4>>2]))+L[l+q>>2];n=n+2|0;j=j+2|0;m=m+2|0;if((t|0)!=(m|0)){continue}break}}if(r){n=n<<2;L[n+d>>2]=O(v*O(H[o+(j<<2)>>2]))+L[n+q>>2];j=j+1|0}qa(H[H[f+64>>2]>>2]+k|0,d,h);k=h+k|0;i=i+1|0;if(i>>>0>2]){continue}break}}oa(d)}q=b}j=1;w=w+1|0;if((ea[H[H[a>>2]+24>>2]](a)|0)>(w|0)){continue}break a}break}oa(d);j=0}ca=p+16|0;return j|0}function Le(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;g=ca+-64|0;ca=g;H[g+56>>2]=0;H[g+48>>2]=0;H[g+52>>2]=0;H[g+40>>2]=0;H[g+44>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;H[g+24>>2]=0;H[g+28>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;j=g+8|0;d=J[b+38>>1];a:{b:{if(!d){break b}c:{if(d>>>0<=511){h=H[b+8>>2];f=H[b+12>>2];e=H[b+20>>2];d=H[b+16>>2];i=d+4|0;e=i>>>0<4?e+1|0:e;if(h>>>0>>0&(e|0)>=(f|0)|(e|0)>(f|0)){break b}d=d+H[b>>2]|0;l=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[j+12>>2]=l;e=H[b+20>>2];d=H[b+16>>2]+4|0;e=d>>>0<4?e+1|0:e;H[b+16>>2]=d;H[b+20>>2]=e;break c}if(!hb(1,j+12|0,b)){break b}d=H[b+16>>2];e=H[b+20>>2];l=H[j+12>>2]}f=H[b+8>>2];i=f-d|0;d=H[b+12>>2]-((d>>>0>f>>>0)+e|0)|0;if(i>>>0>>6>>>0&(d|0)<=0|(d|0)<0){break b}e=H[j>>2];d=H[j+4>>2]-e>>2;d:{if(d>>>0>>0){ya(j,l-d|0);l=H[j+12>>2];break d}if(d>>>0<=l>>>0){break d}H[j+4>>2]=e+(l<<2)}i=1;if(!l){break a}d=H[b+16>>2];e=H[b+20>>2];r=H[j>>2];k=H[b+8>>2];o=H[b+12>>2];h=0;while(1){i=0;if((e|0)>=(o|0)&d>>>0>=k>>>0|(e|0)>(o|0)){break a}i=H[b>>2];p=I[i+d|0];d=d+1|0;e=d?e:e+1|0;H[b+16>>2]=d;H[b+20>>2]=e;f=p>>>2|0;m=0;e:{f:{g:{h:{s=p&3;switch(s|0){case 0:break f;case 3:break h;default:break g}}f=f+h|0;i=0;if(f>>>0>=l>>>0){break a}ra(r+(h<<2)|0,0,(p&252)+4|0);h=f;break e}while(1){if((d|0)==(k|0)&(e|0)==(o|0)){break b}l=I[d+i|0];d=d+1|0;e=d?e:e+1|0;H[b+16>>2]=d;H[b+20>>2]=e;f=l<<(m<<3|6)|f;m=m+1|0;if((s|0)!=(m|0)){continue}break}}H[r+(h<<2)>>2]=f}l=H[j+12>>2];h=h+1|0;if(l>>>0>h>>>0){continue}break}d=j+16|0;o=H[j>>2];f=H[j+16>>2];e=H[j+20>>2]-f|0;i:{if(e>>>0<=4194303){ya(d,1048576-(e>>>2|0)|0);break i}if((e|0)==4194304){break i}H[j+20>>2]=f+4194304}e=j+28|0;h=H[e>>2];f=H[j+32>>2]-h>>3;j:{if(f>>>0>>0){ob(e,l-f|0);h=H[e>>2];break j}if(f>>>0>l>>>0){H[j+32>>2]=(l<<3)+h}if(!l){break b}}k=H[d>>2];d=0;i=0;while(1){e=o+(d<<2)|0;j=H[e>>2];m=(d<<3)+h|0;f=i;H[m+4>>2]=f;H[m>>2]=j;e=H[e>>2];i=e+f|0;if(i>>>0>1048576){break b}k:{if(f>>>0>=i>>>0){break k}m=0;j=e&7;if(j){while(1){H[k+(f<<2)>>2]=d;f=f+1|0;m=m+1|0;if((j|0)!=(m|0)){continue}break}}if(e-1>>>0<=6){break k}while(1){e=k+(f<<2)|0;H[e>>2]=d;H[e+28>>2]=d;H[e+24>>2]=d;H[e+20>>2]=d;H[e+16>>2]=d;H[e+12>>2]=d;H[e+8>>2]=d;H[e+4>>2]=d;f=f+8|0;if((i|0)!=(f|0)){continue}break}}d=d+1|0;if((l|0)!=(d|0)){continue}break}n=(i|0)==1048576}i=n}l:{if(!i|(H[g+20>>2]?0:a)){break l}i=0;n=ca-16|0;ca=n;m:{n:{if(J[b+38>>1]<=511){h=H[b+8>>2];f=H[b+12>>2];j=f;e=H[b+20>>2];k=H[b+16>>2];d=k+8|0;e=d>>>0<8?e+1|0:e;if(d>>>0>h>>>0&(e|0)>=(f|0)|(e|0)>(f|0)){break m}k=k+H[b>>2]|0;f=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);k=I[k+4|0]|I[k+5|0]<<8|(I[k+6|0]<<16|I[k+7|0]<<24);H[b+16>>2]=d;H[b+20>>2]=e;break n}if(!gb(1,n+8|0,b)){break m}d=H[b+16>>2];e=H[b+20>>2];h=H[b+8>>2];j=H[b+12>>2];f=H[n+8>>2];k=H[n+12>>2]}l=h-d|0;h=j-((d>>>0>h>>>0)+e|0)|0;if((h|0)==(k|0)&f>>>0>l>>>0|h>>>0>>0){break m}e=e+k|0;h=d+f|0;e=h>>>0>>0?e+1|0:e;H[b+16>>2]=h;H[b+20>>2]=e;if((f|0)<=0){break m}b=H[b>>2]+d|0;H[g+48>>2]=b;d=f-1|0;e=d+b|0;h=I[e|0];o:{if(h>>>0<=63){H[g+52>>2]=d;b=I[e|0]&63;break o}p:{switch((h>>>6|0)-1|0){case 0:if(f>>>0<2){break m}d=f-2|0;H[g+52>>2]=d;b=b+d|0;b=I[b+1|0]<<8&16128|I[b|0];break o;case 1:if(f>>>0<3){break m}d=f-3|0;H[g+52>>2]=d;b=b+d|0;b=I[b+1|0]<<8|I[b+2|0]<<16&4128768|I[b|0];break o;default:break p}}d=f-4|0;H[g+52>>2]=d;b=b+d|0;b=(I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24))&1073741823}H[g+56>>2]=b+4194304;i=b>>>0<1069547520}ca=n+16|0;if(!i){break l}if(!a){t=1;break l}b=H[g+52>>2];f=H[g+56>>2];d=H[g+36>>2];e=H[g+48>>2];h=H[g+24>>2];while(1){q:{if(f>>>0>4194303){break q}while(1){if((b|0)<=0){break q}b=b-1|0;H[g+52>>2]=b;f=I[b+e|0]|f<<8;H[g+56>>2]=f;if(f>>>0<4194304){continue}break}}i=f&1048575;k=H[h+(i<<2)>>2];n=d+(k<<3)|0;f=(N(H[n>>2],f>>>20|0)+i|0)-H[n+4>>2]|0;H[g+56>>2]=f;H[(q<<2)+c>>2]=k;t=1;q=q+1|0;if((q|0)!=(a|0)){continue}break}}a=H[g+36>>2];if(a){H[g+40>>2]=a;oa(a)}a=H[g+24>>2];if(a){H[g+28>>2]=a;oa(a)}a=H[g+8>>2];if(a){H[g+12>>2]=a;oa(a)}ca=g- -64|0;return t}function nc(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;e=ca-48|0;ca=e;f=J[6677]|J[6678]<<16;d=J[6675]|J[6676]<<16;G[e+38>>1]=d;G[e+40>>1]=d>>>16;G[e+42>>1]=f;G[e+44>>1]=f>>>16;d=H[3337];H[e+32>>2]=H[3336];H[e+36>>2]=d;d=H[3335];H[e+24>>2]=H[3334];H[e+28>>2]=d;d=H[3333];H[e+16>>2]=H[3332];H[e+20>>2]=d;g=H[b+8>>2];i=H[b+12>>2];h=H[b+20>>2];d=H[b+16>>2];f=d+5|0;h=f>>>0<5?h+1|0:h;a:{b:{if(g>>>0>>0&(h|0)>=(i|0)|(h|0)>(i|0)){d=Ma(e+16|0);if(d>>>0>=2147483632){break a}c:{d:{if(d>>>0>=11){b=(d|15)+1|0;c=pa(b);H[e+8>>2]=b|-2147483648;H[e>>2]=c;H[e+4>>2]=d;b=c+d|0;break d}F[e+11|0]=d;b=d+e|0;c=e;if(!d){break c}}qa(c,e+16|0,d)}F[b|0]=0;H[a>>2]=-2;b=a+4|0;if(F[e+11|0]>=0){a=H[e+4>>2];H[b>>2]=H[e>>2];H[b+4>>2]=a;H[b+8>>2]=H[e+8>>2];break b}za(b,H[e>>2],H[e+4>>2]);if(F[e+11|0]>=0){break b}oa(H[e>>2]);break b}f=d+H[b>>2]|0;d=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);F[c|0]=d;F[c+1|0]=d>>>8;F[c+2|0]=d>>>16;F[c+3|0]=d>>>24;F[c+4|0]=I[f+4|0];d=H[b+20>>2];f=H[b+16>>2]+5|0;d=f>>>0<5?d+1|0:d;H[b+16>>2]=f;H[b+20>>2]=d;if(Fa(c,1260,5)){d=pa(32);F[d+17|0]=0;F[d+16|0]=I[1496];c=I[1492]|I[1493]<<8|(I[1494]<<16|I[1495]<<24);b=I[1488]|I[1489]<<8|(I[1490]<<16|I[1491]<<24);F[d+8|0]=b;F[d+9|0]=b>>>8;F[d+10|0]=b>>>16;F[d+11|0]=b>>>24;F[d+12|0]=c;F[d+13|0]=c>>>8;F[d+14|0]=c>>>16;F[d+15|0]=c>>>24;c=I[1484]|I[1485]<<8|(I[1486]<<16|I[1487]<<24);b=I[1480]|I[1481]<<8|(I[1482]<<16|I[1483]<<24);F[d|0]=b;F[d+1|0]=b>>>8;F[d+2|0]=b>>>16;F[d+3|0]=b>>>24;F[d+4|0]=c;F[d+5|0]=c>>>8;F[d+6|0]=c>>>16;F[d+7|0]=c>>>24;H[a>>2]=-1;za(a+4|0,d,17);oa(d);break b}g=H[b+12>>2];if((g|0)<=(d|0)&K[b+8>>2]<=f>>>0|(d|0)>(g|0)){d=Ma(e+16|0);if(d>>>0>=2147483632){break a}e:{f:{if(d>>>0>=11){b=(d|15)+1|0;c=pa(b);H[e+8>>2]=b|-2147483648;H[e>>2]=c;H[e+4>>2]=d;b=c+d|0;break f}F[e+11|0]=d;b=d+e|0;c=e;if(!d){break e}}qa(c,e+16|0,d)}F[b|0]=0;H[a>>2]=-2;b=a+4|0;if(F[e+11|0]>=0){a=H[e+4>>2];H[b>>2]=H[e>>2];H[b+4>>2]=a;H[b+8>>2]=H[e+8>>2];break b}za(b,H[e>>2],H[e+4>>2]);if(F[e+11|0]>=0){break b}oa(H[e>>2]);break b}F[c+5|0]=I[f+H[b>>2]|0];g=H[b+20>>2];d=H[b+16>>2]+1|0;g=d?g:g+1|0;H[b+16>>2]=d;H[b+20>>2]=g;f=H[b+12>>2];if((f|0)<=(g|0)&K[b+8>>2]<=d>>>0|(g|0)>(f|0)){d=Ma(e+16|0);if(d>>>0>=2147483632){break a}g:{h:{if(d>>>0>=11){b=(d|15)+1|0;c=pa(b);H[e+8>>2]=b|-2147483648;H[e>>2]=c;H[e+4>>2]=d;b=c+d|0;break h}F[e+11|0]=d;b=d+e|0;c=e;if(!d){break g}}qa(c,e+16|0,d)}F[b|0]=0;H[a>>2]=-2;b=a+4|0;if(F[e+11|0]>=0){a=H[e+4>>2];H[b>>2]=H[e>>2];H[b+4>>2]=a;H[b+8>>2]=H[e+8>>2];break b}za(b,H[e>>2],H[e+4>>2]);if(F[e+11|0]>=0){break b}oa(H[e>>2]);break b}F[c+6|0]=I[d+H[b>>2]|0];h=H[b+20>>2];d=H[b+16>>2]+1|0;h=d?h:h+1|0;H[b+16>>2]=d;H[b+20>>2]=h;f=H[b+12>>2];if((f|0)<=(h|0)&K[b+8>>2]<=d>>>0|(f|0)<(h|0)){d=Ma(e+16|0);if(d>>>0>=2147483632){break a}i:{j:{if(d>>>0>=11){b=(d|15)+1|0;c=pa(b);H[e+8>>2]=b|-2147483648;H[e>>2]=c;H[e+4>>2]=d;b=c+d|0;break j}F[e+11|0]=d;b=d+e|0;c=e;if(!d){break i}}qa(c,e+16|0,d)}F[b|0]=0;H[a>>2]=-2;b=a+4|0;if(F[e+11|0]>=0){a=H[e+4>>2];H[b>>2]=H[e>>2];H[b+4>>2]=a;H[b+8>>2]=H[e+8>>2];break b}za(b,H[e>>2],H[e+4>>2]);if(F[e+11|0]>=0){break b}oa(H[e>>2]);break b}F[c+7|0]=I[d+H[b>>2]|0];g=H[b+20>>2];d=H[b+16>>2]+1|0;g=d?g:g+1|0;H[b+16>>2]=d;H[b+20>>2]=g;f=H[b+12>>2];if((f|0)<=(g|0)&K[b+8>>2]<=d>>>0|(g|0)>(f|0)){c=mc(e,e+16|0);H[a>>2]=-2;b=a+4|0;if(F[c+11|0]>=0){a=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=a;H[b+8>>2]=H[c+8>>2];break b}za(b,H[c>>2],H[c+4>>2]);if(F[c+11|0]>=0){break b}oa(H[c>>2]);break b}F[c+8|0]=I[d+H[b>>2]|0];d=H[b+20>>2];g=H[b+16>>2];f=g+1|0;i=f?d:d+1|0;H[b+16>>2]=f;H[b+20>>2]=i;i=H[b+8>>2];h=H[b+12>>2];g=g+3|0;d=g>>>0<3?d+1|0:d;if(g>>>0>i>>>0&(d|0)>=(h|0)|(d|0)>(h|0)){c=mc(e,e+16|0);H[a>>2]=-2;b=a+4|0;if(F[c+11|0]>=0){a=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=a;H[b+8>>2]=H[c+8>>2];break b}za(b,H[c>>2],H[c+4>>2]);if(F[c+11|0]>=0){break b}oa(H[c>>2]);break b}d=c;c=H[b>>2]+f|0;G[d+10>>1]=I[c|0]|I[c+1|0]<<8;g=H[b+20>>2];c=H[b+16>>2]+2|0;g=c>>>0<2?g+1|0:g;H[b+16>>2]=c;H[b+20>>2]=g;H[a+8>>2]=0;H[a+12>>2]=0;H[a>>2]=0;H[a+4>>2]=0}ca=e+48|0;return}Na();v()}function Nb(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0;e=ca-96|0;ca=e;f=H[a+16>>2];F[e+92|0]=1;H[e+88>>2]=b;H[e+84>>2]=b;H[e+80>>2]=f;j=H[a+20>>2];d=H[j>>2];a:{b:{f=H[H[f+28>>2]+(b<<2)>>2];if(f>>>0>2]-d>>2>>>0){d=H[H[a+8>>2]+(H[d+(f<<2)>>2]<<2)>>2];f=H[a+4>>2];if(!I[f+84|0]){d=H[H[f+68>>2]+(d<<2)>>2]}H[e+72>>2]=0;H[e+76>>2]=0;j=e- -64|0;H[j>>2]=0;H[j+4>>2]=0;H[e+56>>2]=0;H[e+60>>2]=0;Sa(f,d,F[f+24|0],e+56|0);if((b|0)!=-1){f=b+1|0;j=(f>>>0)%3|0?f:b-2|0;m=((b>>>0)%3|0?-1:2)+b|0;while(1){d=j;f=m;c:{if(!H[a+28>>2]){break c}f=b+1|0;d=(f>>>0)%3|0?f:b-2|0;f=b-1|0;if((b>>>0)%3|0){break c}f=b+2|0}n=H[a+20>>2];b=H[n>>2];d=H[H[H[a+16>>2]+28>>2]+(d<<2)>>2];if(d>>>0>=H[n+4>>2]-b>>2>>>0){break b}d=H[H[a+8>>2]+(H[b+(d<<2)>>2]<<2)>>2];b=H[a+4>>2];if(!I[b+84|0]){d=H[H[b+68>>2]+(d<<2)>>2]}H[e+48>>2]=0;H[e+52>>2]=0;H[e+40>>2]=0;H[e+44>>2]=0;H[e+32>>2]=0;H[e+36>>2]=0;Sa(b,d,F[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=b+1|0;b=(d>>>0)%3|0?d:b-2|0;if((b|0)==-1|H[H[f>>2]+(b>>>3&536870908)>>2]>>>b&1){break h}b=H[H[H[f+64>>2]+12>>2]+(b<<2)>>2];if((b|0)!=-1){break g}}H[e+88>>2]=-1;break f}d=b+1|0;b=(d>>>0)%3|0?d:b-2|0;H[e+88>>2]=b;if((b|0)!=-1){break e}}b=H[e+84>>2];d=-1;i:{if((b|0)==-1){break i}j:{if((b>>>0)%3|0){b=b-1|0;break j}b=b+2|0;d=-1;if((b|0)==-1){break i}}d=-1;if(H[H[f>>2]+(b>>>3&536870908)>>2]>>>b&1){break i}b=H[H[H[f+64>>2]+12>>2]+(b<<2)>>2];d=-1;if((b|0)==-1){break i}d=b-1|0;if((b>>>0)%3|0){break i}d=b+2|0}F[e+92|0]=0;H[e+88>>2]=d;break d}if((b|0)!=H[e+84>>2]){break d}H[e+88>>2]=-1;break d}d=-1;k:{if((b|0)==-1){break k}l:{if((b>>>0)%3|0){b=b-1|0;break l}b=b+2|0;d=-1;if((b|0)==-1){break k}}d=-1;if(H[H[f>>2]+(b>>>3&536870908)>>2]>>>b&1){break k}b=H[H[H[f+64>>2]+12>>2]+(b<<2)>>2];d=-1;if((b|0)==-1){break k}d=b-1|0;if((b>>>0)%3|0){break k}d=b+2|0}H[e+88>>2]=d}b=H[e+88>>2];if((b|0)!=-1){continue}break}}b=s>>31;f=b^r;d=f-b|0;b=(b^s)-((b>>>0>f>>>0)+b|0)|0;m=-1;f=2147483647;g=q>>31;h=g^l;j=h-g|0;n=(g^q)-((h>>>0>>0)+g|0)|0;h=n;k=j^-1;g=h^2147483647;n=i;m:{n:{if(!H[a+28>>2]){if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break m}b=b+h|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;f=a;g=i;a=g>>31;d=a;m=d^o;a=m-d|0;i=a;d=(d^g)-((d>>>0>m>>>0)+d|0)|0;a=a+f|0;d=d^2147483647;i=(d|0)==(b|0)&(i^-1)>>>0>>0|b>>>0>d>>>0;a=i?-1:a;if(!(i&0)&(a|0)<=536870912|(a|0)<536870912){break m}b=0;a=a>>>29|0;break n}o:{if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break o}b=b+h|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;k=i;d=i>>31;h=d^o;i=h-d|0;j=(d^k)-((d>>>0>h>>>0)+d|0)|0;g=j^2147483647;d=a;a=i;if((g|0)==(b|0)&d>>>0>(a^-1)>>>0|b>>>0>g>>>0){break o}b=b+j|0;m=a+d|0;b=m>>>0>>0?b+1|0:b;f=b;if(!b&m>>>0<536870913){break m}}b=f>>>29|0;a=(f&536870911)<<3|m>>>29}o=Sj(o,n,a,b);l=Sj(l,q,a,b);r=Sj(r,s,a,b)}H[c+8>>2]=o;H[c+4>>2]=l;H[c>>2]=r;ca=e+96|0;return}Ca();v()}Ca();v()}Ca();v()}function Jj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0;H[a+8>>2]=e;r=a+32|0;g=H[r>>2];f=H[a+36>>2]-g>>2;a:{if(f>>>0>>0){ya(r,e-f|0);d=H[a+8>>2];break a}d=e;if(d>>>0>=f>>>0){break a}H[a+36>>2]=g+(e<<2);d=e}w=e<<2;f=e>>>0>1073741823?-1:w;m=ra(pa(f),0,f);p=ra(pa(f),0,f);b:{if((d|0)<=0){break b}i=H[a+32>>2];while(1){d=h<<2;f=H[d+m>>2];g=H[a+16>>2];c:{if((f|0)>(g|0)){H[d+i>>2]=g;break c}d=d+i|0;g=H[a+12>>2];if((g|0)>(f|0)){H[d>>2]=g;break c}H[d>>2]=f}d=H[a+8>>2];h=h+1|0;if((d|0)>(h|0)){continue}break}if((d|0)<=0){break b}f=0;while(1){g=f<<2;d=g+c|0;g=H[b+g>>2]+H[g+i>>2]|0;H[d>>2]=g;d:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break d}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}f=H[a+56>>2];x=H[f>>2];f=H[f+4>>2]-x|0;if((f|0)>=5){D=H[a+52>>2];s=H[a+48>>2];u=f>>>2|0;E=u>>>0<=2?2:u;y=e&-2;z=e&1;F=e&-4;A=e&3;B=e-1|0;n=1;while(1){e:{f:{g:{h:{if((n|0)!=(u|0)){g=H[(n<<2)+x>>2];t=(e|0)<=0;if(!t){ra(m,0,w)}if((g|0)==-1){i=N(e,n);break f}C=H[s>>2];l=0;f=g;while(1){i:{if(H[(f>>>3&536870908)+C>>2]>>>f&1){break i}i=H[H[H[s+64>>2]+12>>2]+(f<<2)>>2];if((i|0)==-1){break i}j=H[D>>2];h=H[s+28>>2];o=H[j+(H[h+(i<<2)>>2]<<2)>>2];if((o|0)>=(n|0)){break i}k=i+1|0;k=H[j+(H[h+(((k>>>0)%3|0?k:i-2|0)<<2)>>2]<<2)>>2];if((k|0)>=(n|0)){break i}i=H[j+(H[h+(i+((i>>>0)%3|0?-1:2)<<2)>>2]<<2)>>2];if((i|0)>=(n|0)){break i}j:{if(t){break j}i=N(e,i);j=N(e,k);o=N(e,o);h=0;q=0;if(B){while(1){H[(h<<2)+p>>2]=(H[(h+i<<2)+c>>2]+H[(h+j<<2)+c>>2]|0)-H[(h+o<<2)+c>>2];k=h|1;H[(k<<2)+p>>2]=(H[(i+k<<2)+c>>2]+H[(j+k<<2)+c>>2]|0)-H[(k+o<<2)+c>>2];h=h+2|0;q=q+2|0;if((y|0)!=(q|0)){continue}break}}if(z){H[(h<<2)+p>>2]=(H[(h+i<<2)+c>>2]+H[(h+j<<2)+c>>2]|0)-H[(h+o<<2)+c>>2]}if(t){break j}o=0;h=0;i=0;if(e>>>0>3){while(1){j=h<<2;k=j+m|0;H[k>>2]=H[j+p>>2]+H[k>>2];k=j|4;q=k+m|0;H[q>>2]=H[k+p>>2]+H[q>>2];k=j|8;q=k+m|0;H[q>>2]=H[k+p>>2]+H[q>>2];j=j|12;k=j+m|0;H[k>>2]=H[j+p>>2]+H[k>>2];h=h+4|0;i=i+4|0;if((F|0)!=(i|0)){continue}break}}if(!A){break j}while(1){i=h<<2;j=i+m|0;H[j>>2]=H[i+p>>2]+H[j>>2];h=h+1|0;o=o+1|0;if((A|0)!=(o|0)){continue}break}}l=l+1|0}k:{l:{if((f>>>0)%3|0){h=f-1|0;break l}h=f+2|0;i=-1;if((h|0)==-1){break k}}i=-1;if(H[(h>>>3&536870908)+C>>2]>>>h&1){break k}f=H[H[H[s+64>>2]+12>>2]+(h<<2)>>2];i=-1;if((f|0)==-1){break k}i=f-1|0;if((f>>>0)%3|0){break k}i=f+2|0}f=i;if((g|0)!=(f|0)&(f|0)!=-1){continue}break}i=N(e,n);if(!l){break f}if(t){break g}h=0;f=0;if(!B){break h}while(1){g=h<<2;j=g+m|0;H[j>>2]=H[j>>2]/(l|0);g=(g|4)+m|0;H[g>>2]=H[g>>2]/(l|0);h=h+2|0;f=f+2|0;if((y|0)!=(f|0)){continue}break}break h}Ca();v()}if(!z){break g}f=(h<<2)+m|0;H[f>>2]=H[f>>2]/(l|0)}if((d|0)<=0){break e}l=H[r>>2];h=0;while(1){d=h<<2;f=H[d+m>>2];g=H[a+16>>2];m:{if((f|0)>(g|0)){H[d+l>>2]=g;break m}d=d+l|0;g=H[a+12>>2];if((g|0)>(f|0)){H[d>>2]=g;break m}H[d>>2]=f}d=H[a+8>>2];h=h+1|0;if((d|0)>(h|0)){continue}break}f=0;if((d|0)<=0){break e}d=i<<2;i=d+c|0;h=b+d|0;while(1){g=f<<2;d=g+i|0;g=H[h+g>>2]+H[g+l>>2]|0;H[d>>2]=g;n:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break n}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}break e}if((d|0)<=0){break e}g=(N(n-1|0,e)<<2)+c|0;l=H[r>>2];h=0;while(1){d=h<<2;f=H[d+g>>2];j=H[a+16>>2];o:{if((f|0)>(j|0)){H[d+l>>2]=j;break o}d=d+l|0;j=H[a+12>>2];if((j|0)>(f|0)){H[d>>2]=j;break o}H[d>>2]=f}d=H[a+8>>2];h=h+1|0;if((d|0)>(h|0)){continue}break}f=0;if((d|0)<=0){break e}d=i<<2;i=d+c|0;h=b+d|0;while(1){g=f<<2;d=g+i|0;g=H[h+g>>2]+H[g+l>>2]|0;H[d>>2]=g;p:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break p}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}n=n+1|0;if((E|0)!=(n|0)){continue}break}}oa(p);oa(m);return 1}function sj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0;H[a+8>>2]=e;r=a+32|0;f=H[r>>2];j=H[a+36>>2]-f>>2;a:{if(j>>>0>>0){ya(r,e-j|0);d=H[a+8>>2];break a}d=e;if(e>>>0>=j>>>0){break a}H[a+36>>2]=f+(e<<2);d=e}u=e<<2;f=e>>>0>1073741823?-1:u;m=ra(pa(f),0,f);p=ra(pa(f),0,f);b:{if((d|0)<=0){break b}i=H[a+32>>2];while(1){f=h<<2;j=H[f+m>>2];d=H[a+16>>2];c:{if((j|0)>(d|0)){H[f+i>>2]=d;break c}f=f+i|0;d=H[a+12>>2];if((d|0)>(j|0)){H[f>>2]=d;break c}H[f>>2]=j}d=H[a+8>>2];h=h+1|0;if((d|0)>(h|0)){continue}break}if((d|0)<=0){break b}f=0;while(1){j=f<<2;d=j+c|0;j=H[b+j>>2]+H[j+i>>2]|0;H[d>>2]=j;d:{if((j|0)>H[a+16>>2]){j=j-H[a+20>>2]|0}else{if((j|0)>=H[a+12>>2]){break d}j=j+H[a+20>>2]|0}H[d>>2]=j}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}f=H[a+56>>2];w=H[f>>2];f=H[f+4>>2]-w|0;if((f|0)>=5){D=H[a+52>>2];x=H[a+48>>2];t=f>>>2|0;E=t>>>0<=2?2:t;y=e&-2;z=e&1;F=e&-4;A=e&3;B=e-1|0;n=1;while(1){e:{f:{g:{h:{if((n|0)!=(t|0)){j=H[(n<<2)+w>>2];s=(e|0)<=0;if(!s){ra(m,0,u)}if((j|0)==-1){g=N(e,n);break f}C=H[x+12>>2];q=0;f=j;while(1){h=H[(f<<2)+C>>2];i:{if((h|0)==-1){break i}o=H[D>>2];l=H[x>>2];k=H[o+(H[l+(h<<2)>>2]<<2)>>2];i=h+1|0;i=(i>>>0)%3|0?i:h-2|0;if((i|0)!=-1){g=H[l+(i<<2)>>2]}else{g=-1}j:{k:{if((h>>>0)%3|0){h=h-1|0;break k}h=h+2|0;i=-1;if((h|0)==-1){break j}}i=H[l+(h<<2)>>2]}if((k|0)>=(n|0)){break i}g=H[(g<<2)+o>>2];if((g|0)>=(n|0)){break i}i=H[o+(i<<2)>>2];if((i|0)>=(n|0)){break i}l:{if(s){break l}l=N(e,i);o=N(e,g);k=N(e,k);h=0;i=0;if(B){while(1){H[(h<<2)+p>>2]=(H[(h+l<<2)+c>>2]+H[(h+o<<2)+c>>2]|0)-H[(h+k<<2)+c>>2];g=h|1;H[(g<<2)+p>>2]=(H[(g+l<<2)+c>>2]+H[(g+o<<2)+c>>2]|0)-H[(g+k<<2)+c>>2];h=h+2|0;i=i+2|0;if((y|0)!=(i|0)){continue}break}}if(z){H[(h<<2)+p>>2]=(H[(h+l<<2)+c>>2]+H[(h+o<<2)+c>>2]|0)-H[(h+k<<2)+c>>2]}if(s){break l}o=0;h=0;k=0;if(e>>>0>3){while(1){l=h<<2;i=l+m|0;H[i>>2]=H[l+p>>2]+H[i>>2];g=l|4;i=g+m|0;H[i>>2]=H[g+p>>2]+H[i>>2];g=l|8;i=g+m|0;H[i>>2]=H[g+p>>2]+H[i>>2];g=l|12;i=g+m|0;H[i>>2]=H[g+p>>2]+H[i>>2];h=h+4|0;k=k+4|0;if((F|0)!=(k|0)){continue}break}}if(!A){break l}while(1){g=h<<2;i=g+m|0;H[i>>2]=H[g+p>>2]+H[i>>2];h=h+1|0;o=o+1|0;if((A|0)!=(o|0)){continue}break}}q=q+1|0}m:{n:{if((f>>>0)%3|0){h=f-1|0;break n}h=f+2|0;g=-1;if((h|0)==-1){break m}}f=H[(h<<2)+C>>2];g=-1;if((f|0)==-1){break m}g=f-1|0;if((f>>>0)%3|0){break m}g=f+2|0}f=g;if((j|0)!=(f|0)&(f|0)!=-1){continue}break}g=N(e,n);if(!q){break f}if(s){break g}h=0;f=0;if(!B){break h}while(1){i=h<<2;j=i+m|0;H[j>>2]=H[j>>2]/(q|0);j=(i|4)+m|0;H[j>>2]=H[j>>2]/(q|0);h=h+2|0;f=f+2|0;if((y|0)!=(f|0)){continue}break}break h}Ca();v()}if(!z){break g}f=(h<<2)+m|0;H[f>>2]=H[f>>2]/(q|0)}if((d|0)<=0){break e}k=H[r>>2];h=0;while(1){f=h<<2;j=H[f+m>>2];d=H[a+16>>2];o:{if((j|0)>(d|0)){H[f+k>>2]=d;break o}f=f+k|0;d=H[a+12>>2];if((d|0)>(j|0)){H[f>>2]=d;break o}H[f>>2]=j}d=H[a+8>>2];h=h+1|0;if((d|0)>(h|0)){continue}break}f=0;if((d|0)<=0){break e}d=g<<2;i=d+c|0;j=b+d|0;while(1){g=f<<2;d=g+i|0;g=H[g+j>>2]+H[g+k>>2]|0;H[d>>2]=g;p:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break p}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}break e}if((d|0)<=0){break e}f=(N(n-1|0,e)<<2)+c|0;k=H[r>>2];h=0;while(1){j=h<<2;i=H[j+f>>2];d=H[a+16>>2];q:{if((i|0)>(d|0)){H[j+k>>2]=d;break q}j=j+k|0;d=H[a+12>>2];if((d|0)>(i|0)){H[j>>2]=d;break q}H[j>>2]=i}d=H[a+8>>2];h=h+1|0;if((d|0)>(h|0)){continue}break}f=0;if((d|0)<=0){break e}d=g<<2;i=d+c|0;j=b+d|0;while(1){g=f<<2;d=g+i|0;g=H[g+j>>2]+H[g+k>>2]|0;H[d>>2]=g;r:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break r}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}n=n+1|0;if((E|0)!=(n|0)){continue}break}}oa(p);oa(m);return 1}function xa(a){var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;f=ca-32|0;ca=f;a:{b=H[a+16>>2];b:{if(b>>>0>=341){H[a+16>>2]=b-341;b=H[a+4>>2];j=H[b>>2];c=b+4|0;H[a+4>>2]=c;b=H[a+8>>2];c:{if((b|0)!=H[a+12>>2]){d=b;break c}k=H[a>>2];if(k>>>0>>0){e=((c-k>>2)+1|0)/-2<<2;b=b-c|0;d=va(e+c|0,c,b)+b|0;H[a+8>>2]=d;H[a+4>>2]=e+H[a+4>>2];break c}d=(b|0)==(k|0)?1:b-k>>1;if(d>>>0>=1073741824){break a}e=d<<2;h=pa(e);l=e+h|0;e=h+(d&-4)|0;d=e;d:{if((b|0)==(c|0)){break d}b=b-c|0;m=b&-4;i=b-4|0;g=(i>>>2|0)+1&7;e:{if(!g){b=e;break e}d=0;b=e;while(1){H[b>>2]=H[c>>2];c=c+4|0;b=b+4|0;d=d+1|0;if((g|0)!=(d|0)){continue}break}}d=e+m|0;if(i>>>0<28){break d}while(1){H[b>>2]=H[c>>2];H[b+4>>2]=H[c+4>>2];H[b+8>>2]=H[c+8>>2];H[b+12>>2]=H[c+12>>2];H[b+16>>2]=H[c+16>>2];H[b+20>>2]=H[c+20>>2];H[b+24>>2]=H[c+24>>2];H[b+28>>2]=H[c+28>>2];c=c+32|0;b=b+32|0;if((d|0)!=(b|0)){continue}break}}H[a+12>>2]=l;H[a+8>>2]=d;H[a+4>>2]=e;H[a>>2]=h;if(!k){break c}oa(k);d=H[a+8>>2]}H[d>>2]=j;H[a+8>>2]=H[a+8>>2]+4;break b}c=H[a+8>>2];b=H[a+4>>2];l=c-b|0;h=l>>2;g=H[a+12>>2];d=H[a>>2];e=g-d|0;if(h>>>0>2>>>0){if((c|0)!=(g|0)){n=f,o=pa(4092),H[n+8>>2]=o;d=a;f:{g:{b=H[a+8>>2];h:{if((b|0)!=H[a+12>>2]){e=b;break h}c=H[d+4>>2];h=H[d>>2];if(c>>>0>h>>>0){g=((c-h>>2)+1|0)/-2<<2;a=b-c|0;e=va(g+c|0,c,a)+a|0;H[d+8>>2]=e;H[d+4>>2]=g+H[d+4>>2];break h}e=(b|0)==(h|0)?1:b-h>>1;if(e>>>0>=1073741824){break g}a=e<<2;j=pa(a);l=a+j|0;a=j+(e&-4)|0;e=a;i:{if((b|0)==(c|0)){break i}b=b-c|0;m=b&-4;i=b-4|0;g=(i>>>2|0)+1&7;j:{if(!g){b=a;break j}e=0;b=a;while(1){H[b>>2]=H[c>>2];c=c+4|0;b=b+4|0;e=e+1|0;if((g|0)!=(e|0)){continue}break}}e=a+m|0;if(i>>>0<28){break i}while(1){H[b>>2]=H[c>>2];H[b+4>>2]=H[c+4>>2];H[b+8>>2]=H[c+8>>2];H[b+12>>2]=H[c+12>>2];H[b+16>>2]=H[c+16>>2];H[b+20>>2]=H[c+20>>2];H[b+24>>2]=H[c+24>>2];H[b+28>>2]=H[c+28>>2];c=c+32|0;b=b+32|0;if((e|0)!=(b|0)){continue}break}}H[d+12>>2]=l;H[d+8>>2]=e;H[d+4>>2]=a;H[d>>2]=j;if(!h){break h}oa(h);e=H[d+8>>2]}H[e>>2]=H[f+8>>2];H[d+8>>2]=H[d+8>>2]+4;break f}wa();v()}break b}n=f,o=pa(4092),H[n+8>>2]=o;qd(a,f+8|0);b=H[a+4>>2];j=H[b>>2];c=b+4|0;H[a+4>>2]=c;b=H[a+8>>2];k:{if((b|0)!=H[a+12>>2]){d=b;break k}k=H[a>>2];if(k>>>0>>0){e=((c-k>>2)+1|0)/-2<<2;b=b-c|0;d=va(e+c|0,c,b)+b|0;H[a+8>>2]=d;H[a+4>>2]=e+H[a+4>>2];break k}d=(b|0)==(k|0)?1:b-k>>1;if(d>>>0>=1073741824){break a}e=d<<2;h=pa(e);l=e+h|0;e=h+(d&-4)|0;d=e;l:{if((b|0)==(c|0)){break l}b=b-c|0;m=b&-4;i=b-4|0;g=(i>>>2|0)+1&7;m:{if(!g){b=e;break m}d=0;b=e;while(1){H[b>>2]=H[c>>2];c=c+4|0;b=b+4|0;d=d+1|0;if((g|0)!=(d|0)){continue}break}}d=e+m|0;if(i>>>0<28){break l}while(1){H[b>>2]=H[c>>2];H[b+4>>2]=H[c+4>>2];H[b+8>>2]=H[c+8>>2];H[b+12>>2]=H[c+12>>2];H[b+16>>2]=H[c+16>>2];H[b+20>>2]=H[c+20>>2];H[b+24>>2]=H[c+24>>2];H[b+28>>2]=H[c+28>>2];c=c+32|0;b=b+32|0;if((d|0)!=(b|0)){continue}break}}H[a+12>>2]=l;H[a+8>>2]=d;H[a+4>>2]=e;H[a>>2]=h;if(!k){break k}oa(k);d=H[a+8>>2]}H[d>>2]=j;H[a+8>>2]=H[a+8>>2]+4;break b}H[f+24>>2]=a+12;m=(d|0)==(g|0)?1:e>>1;if(m>>>0>=1073741824){break a}e=m<<2;g=pa(e);H[f+8>>2]=g;j=e+g|0;H[f+20>>2]=j;d=(h<<2)+g|0;H[f+12>>2]=d;i=pa(4092);n:{if((h|0)!=(m|0)){break n}if((l|0)>0){d=((h+1|0)/-2<<2)+d|0;H[f+12>>2]=d;break n}d=(b|0)==(c|0)?1:l>>1;if(d>>>0>=1073741824){break a}b=d<<2;e=pa(b);H[f+8>>2]=e;j=b+e|0;H[f+20>>2]=j;d=e+(d&-4)|0;H[f+12>>2]=d;oa(g);b=H[a+4>>2];c=H[a+8>>2];g=e}H[d>>2]=i;i=d+4|0;H[f+16>>2]=i;e=b;if((b|0)!=(c|0)){while(1){c=c-4|0;qd(f+8|0,c);if(H[a+4>>2]!=(c|0)){continue}break}j=H[f+20>>2];i=H[f+16>>2];d=H[f+12>>2];g=H[f+8>>2];e=c;b=H[a+8>>2]}c=H[a>>2];H[a>>2]=g;H[f+8>>2]=c;H[a+4>>2]=d;H[f+12>>2]=e;H[a+8>>2]=i;H[f+16>>2]=b;d=H[a+12>>2];H[a+12>>2]=j;H[f+20>>2]=d;if((b|0)!=(e|0)){H[f+16>>2]=((e-b|0)+3&-4)+b}if(!c){break b}oa(c)}ca=f+32|0;return}wa();v()}function Aj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=O(0),j=0,k=0,l=0,m=O(0),n=O(0),o=O(0),p=O(0),q=O(0),r=0,s=O(0),t=O(0),u=O(0),w=O(0),x=0,y=O(0),z=O(0),A=O(0),B=0;a:{b:{if((e|0)!=2){break b}H[a+64>>2]=f;H[a+72>>2]=2;e=pa(8);d=H[a+68>>2];H[a+68>>2]=e;if(d){oa(d)}H[a+8>>2]=2;x=a+32|0;e=H[x>>2];d=H[a+36>>2]-e|0;c:{if(d>>>0<=7){ya(x,2-(d>>>2|0)|0);break c}if((d|0)==8){break c}H[a+36>>2]=e+8}h=1;d=H[a+56>>2];d=H[d+4>>2]-H[d>>2]|0;if((d|0)<=0){break b}d=d>>>2|0;B=d>>>0<=1?1:d;d=0;while(1){e=H[a+56>>2];h=H[e>>2];if(H[e+4>>2]-h>>2>>>0<=d>>>0){break a}q=O(0);g=ca-48|0;ca=g;e=-1;h=H[h+(d<<2)>>2];f=-1;d:{if((h|0)==-1){break d}e=h+1|0;e=(e>>>0)%3|0?e:h-2|0;f=h-1|0;if((h>>>0)%3|0){break d}f=h+2|0}j=H[a+52>>2];h=H[j>>2];e:{f:{j=H[j+4>>2]-h>>2;l=e<<2;e=H[H[a+48>>2]+28>>2];r=H[l+e>>2];if(j>>>0<=r>>>0){break f}e=H[e+(f<<2)>>2];if(e>>>0>=j>>>0){break f}j=H[h+(e<<2)>>2];f=H[h+(r<<2)>>2];g:{if(!((j|0)>=(d|0)|(f|0)>=(d|0))){e=H[a+72>>2];h=(N(e,j)<<2)+c|0;m=O(H[h+4>>2]);e=(N(e,f)<<2)+c|0;p=O(H[e+4>>2]);y=O(H[e>>2]);n=O(H[h>>2]);if(!(y!=n|m!=p)){h=+m>2147483647;e=H[a+68>>2];if(O(P(m))>2]=m2147483647;if(O(P(n))>2]=n>2]+(d<<2)>>2];H[g+40>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;h=H[a+60>>2];if(!I[h+84|0]){e=H[H[h+68>>2]+(e<<2)>>2]}Va(h,e,F[h+24|0],g+32|0);f=H[H[a+64>>2]+(f<<2)>>2];H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;e=H[a+60>>2];if(!I[e+84|0]){f=H[H[e+68>>2]+(f<<2)>>2]}Va(e,f,F[e+24|0],g+16|0);f=H[H[a+64>>2]+(j<<2)>>2];H[g+8>>2]=0;H[g>>2]=0;H[g+4>>2]=0;e=H[a+60>>2];if(!I[e+84|0]){f=H[H[e+68>>2]+(f<<2)>>2]}Va(e,f,F[e+24|0],g);o=L[g+24>>2];s=O(L[g+8>>2]-o);t=L[g+20>>2];u=O(L[g+4>>2]-t);A=L[g+16>>2];w=O(L[g>>2]-A);z=O(O(s*s)+O(O(u*u)+O(O(w*w)+O(0))));h:{if(H[a+88>>2]>=258){i=O(0);if(!(z>O(0))){break h}}i=O(L[g+40>>2]-o);o=O(L[g+36>>2]-t);t=O(L[g+32>>2]-A);q=O(O(O(s*i)+O(O(u*o)+O(O(w*t)+O(0))))/z);i=O(i-O(s*q));s=O(i*i);i=O(o-O(u*q));o=O(i*i);i=O(t-O(w*q));i=O(W(O(O(s+O(o+O(O(i*i)+O(0))))/z)))}f=H[a+80>>2];if(f){e=f-1|0;h=H[H[a+76>>2]+(e>>>3&536870908)>>2];H[a+80>>2]=e;m=O(m-p);o=O(O(m*q)+p);n=O(n-y);p=O(n*i);e=h>>>e&1;p=O(o+(e?p:O(-p)));i=O(i*m);k=T(+O(O(O(n*q)+y)+(e?O(-i):i))+.5);i:{if(k<-2147483648|k!=k|k>2147483647){e=H[a+68>>2];H[e>>2]=-2147483648;break i}e=H[a+68>>2];if(P(k)<2147483648){h=~~k}else{h=-2147483648}H[e>>2]=h}k=T(+p+.5);j=k>2147483647;if(P(k)<2147483648){h=~~k}else{h=-2147483648}H[e+4>>2]=k<-2147483648?-2147483648:k!=k?-2147483648:j?-2147483648:h}f=(f|0)!=0;break g}j:{if((d|0)>(f|0)){e=H[a+72>>2];h=N(f,e);break j}if((d|0)<=0){f=1;if(H[a+72>>2]<=0){break g}h=H[a+68>>2];e=0;while(1){H[h+(e<<2)>>2]=0;e=e+1|0;if((e|0)>2]){continue}break}break g}e=H[a+72>>2];h=N(e,d-1|0)}f=1;if((e|0)<=0){break g}j=H[a+68>>2];e=0;while(1){H[j+(e<<2)>>2]=H[(e+h<<2)+c>>2];e=e+1|0;if((e|0)>2]){continue}break}}ca=g+48|0;break e}Ca();v()}h=f;if(!h){return 0}k:{if(H[a+8>>2]<=0){break k}r=H[a+68>>2];j=H[x>>2];e=0;while(1){f=e<<2;g=H[f+r>>2];l=H[a+16>>2];l:{if((g|0)>(l|0)){H[f+j>>2]=l;break l}f=f+j|0;l=H[a+12>>2];if((l|0)>(g|0)){H[f>>2]=l;break l}H[f>>2]=g}e=e+1|0;g=H[a+8>>2];if((e|0)<(g|0)){continue}break}f=0;if((g|0)<=0){break k}e=d<<3;r=e+c|0;l=b+e|0;while(1){g=f<<2;e=g+r|0;g=H[g+l>>2]+H[g+j>>2]|0;H[e>>2]=g;m:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break m}g=g+H[a+20>>2]|0}H[e>>2]=g}f=f+1|0;if((f|0)>2]){continue}break}}d=d+1|0;if((B|0)!=(d|0)){continue}break}}return h|0}Ca();v()}function kj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=O(0),j=0,k=0,l=O(0),m=O(0),n=O(0),o=O(0),p=0,q=O(0),r=O(0),s=O(0),t=O(0),u=O(0),w=0,x=O(0),y=O(0),z=0,A=O(0),B=0;a:{b:{if((e|0)!=2){break b}H[a+64>>2]=f;H[a+72>>2]=2;e=pa(8);d=H[a+68>>2];H[a+68>>2]=e;if(d){oa(d)}H[a+8>>2]=2;w=a+32|0;e=H[w>>2];d=H[a+36>>2]-e|0;c:{if(d>>>0<=7){ya(w,2-(d>>>2|0)|0);break c}if((d|0)==8){break c}H[a+36>>2]=e+8}h=1;d=H[a+56>>2];d=H[d+4>>2]-H[d>>2]|0;if((d|0)<=0){break b}d=d>>>2|0;B=d>>>0<=1?1:d;d=0;while(1){f=H[a+56>>2];e=H[f>>2];if(H[f+4>>2]-e>>2>>>0<=d>>>0){break a}q=O(0);g=ca-48|0;ca=g;h=-1;d:{e:{e=H[e+(d<<2)>>2];if((e|0)==-1){break e}j=H[a+48>>2];f=e+1|0;f=(f>>>0)%3|0?f:e-2|0;if((f|0)!=-1){h=H[H[j>>2]+(f<<2)>>2]}f=-1;e=e+((e>>>0)%3|0?-1:2)|0;if((e|0)!=-1){f=H[H[j>>2]+(e<<2)>>2]}e=H[a+52>>2];j=H[e>>2];e=H[e+4>>2]-j>>2;if(e>>>0<=h>>>0|e>>>0<=f>>>0){break e}e=H[j+(h<<2)>>2];j=H[j+(f<<2)>>2];f:{if(!((d|0)<=(e|0)|(j|0)>=(d|0))){f=H[a+72>>2];h=(N(f,j)<<2)+c|0;l=O(H[h+4>>2]);f=(N(e,f)<<2)+c|0;o=O(H[f+4>>2]);x=O(H[f>>2]);m=O(H[h>>2]);if(!(x!=m|l!=o)){h=+l>2147483647;e=H[a+68>>2];if(O(P(l))>2]=l2147483647;if(O(P(m))>2]=m>2]+(d<<2)>>2];H[g+40>>2]=0;H[g+32>>2]=0;H[g+36>>2]=0;h=H[a+60>>2];if(!I[h+84|0]){f=H[H[h+68>>2]+(f<<2)>>2]}Va(h,f,F[h+24|0],g+32|0);f=H[H[a+64>>2]+(e<<2)>>2];H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;e=H[a+60>>2];if(!I[e+84|0]){f=H[H[e+68>>2]+(f<<2)>>2]}Va(e,f,F[e+24|0],g+16|0);h=H[H[a+64>>2]+(j<<2)>>2];H[g+8>>2]=0;H[g>>2]=0;H[g+4>>2]=0;e=H[a+60>>2];if(!I[e+84|0]){h=H[H[e+68>>2]+(h<<2)>>2]}Va(e,h,F[e+24|0],g);n=L[g+24>>2];r=O(L[g+8>>2]-n);s=L[g+20>>2];t=O(L[g+4>>2]-s);A=L[g+16>>2];u=O(L[g>>2]-A);y=O(O(r*r)+O(O(t*t)+O(O(u*u)+O(0))));g:{if(H[a+88>>2]>=258){i=O(0);if(!(y>O(0))){break g}}i=O(L[g+40>>2]-n);n=O(L[g+36>>2]-s);s=O(L[g+32>>2]-A);q=O(O(O(r*i)+O(O(t*n)+O(O(u*s)+O(0))))/y);i=O(i-O(r*q));r=O(i*i);i=O(n-O(t*q));n=O(i*i);i=O(s-O(u*q));i=O(W(O(O(r+O(n+O(O(i*i)+O(0))))/y)))}e=H[a+80>>2];if(e){f=e-1|0;h=H[H[a+76>>2]+(f>>>3&536870908)>>2];H[a+80>>2]=f;l=O(l-o);n=O(O(l*q)+o);m=O(m-x);o=O(m*i);f=h>>>f&1;o=O(n+(f?o:O(-o)));i=O(i*l);k=T(+O(O(O(m*q)+x)+(f?O(-i):i))+.5);h:{if(k<-2147483648|k!=k|k>2147483647){h=H[a+68>>2];H[h>>2]=-2147483648;break h}h=H[a+68>>2];if(P(k)<2147483648){f=~~k}else{f=-2147483648}H[h>>2]=f}k=T(+o+.5);j=k>2147483647;if(P(k)<2147483648){f=~~k}else{f=-2147483648}H[h+4>>2]=k<-2147483648?-2147483648:k!=k?-2147483648:j?-2147483648:f}h=(e|0)!=0;break f}i:{if((d|0)>(e|0)){f=H[a+72>>2];e=N(e,f);break i}if((d|0)<=0){h=1;if(H[a+72>>2]<=0){break f}e=H[a+68>>2];f=0;while(1){H[e+(f<<2)>>2]=0;f=f+1|0;if((f|0)>2]){continue}break}break f}f=H[a+72>>2];e=N(f,d-1|0)}h=1;if((f|0)<=0){break f}j=H[a+68>>2];f=0;while(1){H[j+(f<<2)>>2]=H[(e+f<<2)+c>>2];f=f+1|0;if((f|0)>2]){continue}break}}ca=g+48|0;break d}Ca();v()}if(!h){return 0}j:{if(H[a+8>>2]<=0){break j}z=H[a+68>>2];j=H[w>>2];e=0;while(1){f=e<<2;g=H[f+z>>2];p=H[a+16>>2];k:{if((g|0)>(p|0)){H[f+j>>2]=p;break k}f=f+j|0;p=H[a+12>>2];if((p|0)>(g|0)){H[f>>2]=p;break k}H[f>>2]=g}e=e+1|0;g=H[a+8>>2];if((e|0)<(g|0)){continue}break}f=0;if((g|0)<=0){break j}e=d<<3;z=e+c|0;p=b+e|0;while(1){g=f<<2;e=g+z|0;g=H[g+p>>2]+H[g+j>>2]|0;H[e>>2]=g;l:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break l}g=g+H[a+20>>2]|0}H[e>>2]=g}f=f+1|0;if((f|0)>2]){continue}break}}d=d+1|0;if((B|0)!=(d|0)){continue}break}}return h|0}Ca();v()}function Of(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;f=ca-704|0;ca=f;n=1;a:{b:{c:{d:{if(J[b+38>>1]<515){break d}n=0;c=H[b+20>>2];d=H[b+12>>2];g=H[b+16>>2];if((c|0)>=(d|0)&g>>>0>=K[b+8>>2]|(c|0)>(d|0)){break d}p=I[H[b>>2]+g|0];g=g+1|0;c=g?c:c+1|0;H[b+16>>2]=g;H[b+20>>2]=c;g=H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+80>>2];c=ea[H[H[a>>2]+24>>2]](a)|0;H[f+40>>2]=0;H[f+32>>2]=0;H[f+36>>2]=0;if(c){if(c>>>0>=214748365){break c}c=N(c,20);d=pa(c);H[f+32>>2]=d;H[f+40>>2]=c+d;c=c-20|0;c=(c-((c>>>0)%20|0)|0)+20|0;q=f,r=ra(d,0,c)+c|0,H[q+36>>2]=r}e:{if((ea[H[H[a>>2]+24>>2]](a)|0)>0){while(1){c=ea[H[H[a>>2]+20>>2]](a,l)|0;c=H[H[H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2]+8>>2]+(c<<2)>>2];mb(c,g);F[c+84|0]=1;H[c+72>>2]=H[c+68>>2];d=H[c+28>>2];if(d>>>0>9){break e}f:{g:{h:{e=1<>2],d,6,0,i,i>>31);c=jc(pa(96),e);H[f>>2]=c;F[c+84|0]=1;H[c+72>>2]=H[c+68>>2];mb(c,g);c=H[a+64>>2];if(c>>>0>=K[a+68>>2]){break h}d=H[f>>2];H[f>>2]=0;H[c>>2]=d;c=c+4|0;H[a+64>>2]=c;break g}j=0;if(!I[c+24|0]){break f}while(1){d=H[a+52>>2];i=H[a+56>>2];i:{if(d>>>0>>0){H[d>>2]=0;H[a+52>>2]=d+4;break i}e=d;d=H[a+48>>2];m=e-d|0;k=m>>2;e=k+1|0;if(e>>>0>=1073741824){break b}o=k<<2;i=i-d|0;k=i>>>1|0;e=i>>>0>=2147483644?1073741823:e>>>0>>0?k:e;if(e){if(e>>>0>=1073741824){break a}i=pa(e<<2)}else{i=0}k=o+i|0;H[k>>2]=0;o=e<<2;e=va(i,d,m);H[a+56>>2]=o+e;H[a+52>>2]=k+4;H[a+48>>2]=e;if(!d){break i}oa(d)}j=j+1|0;if(j>>>0>2];i=H[a+64>>2]-e>>2;d=i+1|0;if(d>>>0<1073741824){e=H[a+68>>2]-e|0;j=e>>>1|0;e=e>>>0>=2147483644?1073741823:d>>>0>>0?j:d;if(e){if(e>>>0>=1073741824){break l}c=pa(e<<2)}j=H[f>>2];H[f>>2]=0;d=(i<<2)+c|0;H[d>>2]=j;e=(e<<2)+c|0;i=d+4|0;c=H[a+64>>2];j=H[a+60>>2];if((c|0)==(j|0)){break k}while(1){c=c-4|0;m=H[c>>2];H[c>>2]=0;d=d-4|0;H[d>>2]=m;if((c|0)!=(j|0)){continue}break}H[a+68>>2]=e;e=H[a+64>>2];H[a+64>>2]=i;c=H[a+60>>2];H[a+60>>2]=d;if((c|0)==(e|0)){break j}while(1){e=e-4|0;d=H[e>>2];H[e>>2]=0;if(d){Ga(d)}if((c|0)!=(e|0)){continue}break}break j}sa();v()}wa();v()}H[a+68>>2]=e;H[a+64>>2]=i;H[a+60>>2]=d}if(c){oa(c)}c=H[a+64>>2]}c=H[c-4>>2];d=H[f>>2];H[f>>2]=0;if(!d){break f}Ga(d)}i=H[c+28>>2];d=i-1|0;if(d>>>0<=10){e=H[(d<<2)+13584>>2]}else{e=-1}d=H[f+32>>2]+N(l,20)|0;j=I[c+24|0];H[d+16>>2]=j;H[d+12>>2]=(e|0)>0?e:0;H[d+8>>2]=i;H[d+4>>2]=h;H[d>>2]=c;h=h+j|0;l=l+1|0;if((ea[H[H[a>>2]+24>>2]](a)|0)>(l|0)){continue}break}}a=Ac(f,f+32|0);m:{n:{o:{switch(p|0){case 0:c=wb(f+48|0,h);b=Bd(c,b,a,g);h=H[c+8>>2];xb(c);if(!b){break m}if((h|0)==(g|0)){break n}break m;case 1:c=wb(f+48|0,h);b=zd(c,b,a,g);h=H[c+8>>2];xb(c);if(!b){break m}if((h|0)==(g|0)){break n}break m;case 2:c=ub(f+48|0,h);b=yd(c,b,a,g);h=H[c+8>>2];vb(c);if(!b){break m}if((h|0)==(g|0)){break n}break m;case 3:c=ub(f+48|0,h);b=xd(c,b,a,g);h=H[c+8>>2];vb(c);if(!b){break m}if((h|0)==(g|0)){break n}break m;case 4:c=$a(f+48|0,h);b=wd(c,b,a,g);h=H[c+8>>2];ab(c);if(!b){break m}if((h|0)==(g|0)){break n}break m;case 5:c=$a(f+48|0,h);b=vd(c,b,a,g);h=H[c+8>>2];ab(c);if(!b){break m}if((h|0)==(g|0)){break n}break m;case 6:break o;default:break m}}c=$a(f+48|0,h);b=ud(c,b,a,g);h=H[c+8>>2];ab(c);if(!b|(h|0)!=(g|0)){break m}}n=1}b=H[a+16>>2];if(b){H[a+20>>2]=b;oa(b)}b=H[a>>2];if(!b){break e}H[a+4>>2]=b;oa(b)}a=H[f+32>>2];if(!a){break d}H[f+36>>2]=a;oa(a)}ca=f+704|0;return n|0}sa();v()}sa();v()}wa();v()}function Zi(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;e=ca-32|0;ca=e;a:{b:{switch(c-2|0){case 0:c=H[a+4>>2];f=H[a+12>>2];H[e+24>>2]=-1;H[e+16>>2]=-1;H[e+20>>2]=1065353216;H[e+8>>2]=-1;H[e+12>>2]=-1;if((b|0)==-2){break a}i=H[H[H[c+4>>2]+8>>2]+(f<<2)>>2];if((ea[H[H[c>>2]+8>>2]](c)|0)==1){h=H[H[H[c+4>>2]+8>>2]+(f<<2)>>2];c:{if((ea[H[H[c>>2]+8>>2]](c)|0)!=1|b-1>>>0>5){break c}g=ea[H[H[c>>2]+36>>2]](c)|0;a=ea[H[H[c>>2]+44>>2]](c,f)|0;if(!g|!a){break c}f=ea[H[H[c>>2]+40>>2]](c,f)|0;d:{if(f){if((b|0)!=6){break c}b=H[c+44>>2];d=pa(112);H[d+4>>2]=h;c=H[e+12>>2];H[d+8>>2]=H[e+8>>2];H[d+12>>2]=c;c=H[e+20>>2];H[d+16>>2]=H[e+16>>2];H[d+20>>2]=c;H[d+24>>2]=H[e+24>>2];H[d+40>>2]=a;c=a+12|0;H[d+36>>2]=c;H[d+32>>2]=f;H[d+28>>2]=b;H[d+68>>2]=a;H[d- -64>>2]=c;H[d+60>>2]=f;H[d+56>>2]=b;H[d+48>>2]=0;H[d+52>>2]=0;H[d>>2]=7144;H[d+88>>2]=1065353216;H[d+92>>2]=-1;H[d+80>>2]=-1;H[d+84>>2]=-1;H[d+72>>2]=1;H[d+76>>2]=-1;H[d+44>>2]=7668;a=d+96|0;break d}if((b|0)!=6){break c}b=H[c+44>>2];d=pa(112);H[d+4>>2]=h;c=H[e+12>>2];H[d+8>>2]=H[e+8>>2];H[d+12>>2]=c;c=H[e+20>>2];H[d+16>>2]=H[e+16>>2];H[d+20>>2]=c;H[d+24>>2]=H[e+24>>2];H[d+40>>2]=a;c=a+12|0;H[d+36>>2]=c;H[d+32>>2]=g;H[d+28>>2]=b;H[d+68>>2]=a;H[d- -64>>2]=c;H[d+60>>2]=g;H[d+56>>2]=b;H[d+48>>2]=0;H[d+52>>2]=0;H[d>>2]=8080;H[d+88>>2]=1065353216;H[d+92>>2]=-1;H[d+80>>2]=-1;H[d+84>>2]=-1;H[d+72>>2]=1;H[d+76>>2]=-1;H[d+44>>2]=8472;a=d+96|0}H[a>>2]=0;H[a+4>>2]=0;F[a+5|0]=0;F[a+6|0]=0;F[a+7|0]=0;F[a+8|0]=0;F[a+9|0]=0;F[a+10|0]=0;F[a+11|0]=0;F[a+12|0]=0}if(d){break a}}d=pa(28);H[d+4>>2]=i;a=H[e+12>>2];H[d+8>>2]=H[e+8>>2];H[d+12>>2]=a;a=H[e+20>>2];H[d+16>>2]=H[e+16>>2];H[d+20>>2]=a;H[d+24>>2]=H[e+24>>2];H[d>>2]=8860;break a;case 1:break b;default:break a}}c=H[a+4>>2];f=H[a+12>>2];H[e+24>>2]=-1;H[e+16>>2]=-1;H[e+20>>2]=1065353216;H[e+8>>2]=-1;H[e+12>>2]=-1;if((b|0)==-2){break a}i=H[H[H[c+4>>2]+8>>2]+(f<<2)>>2];if((ea[H[H[c>>2]+8>>2]](c)|0)==1){h=H[H[H[c+4>>2]+8>>2]+(f<<2)>>2];e:{if((ea[H[H[c>>2]+8>>2]](c)|0)!=1|b-1>>>0>5){break e}g=ea[H[H[c>>2]+36>>2]](c)|0;a=ea[H[H[c>>2]+44>>2]](c,f)|0;if(!g|!a){break e}f=ea[H[H[c>>2]+40>>2]](c,f)|0;f:{if(f){if((b|0)!=6){break e}b=H[c+44>>2];d=pa(112);H[d+4>>2]=h;c=H[e+12>>2];H[d+8>>2]=H[e+8>>2];H[d+12>>2]=c;c=H[e+20>>2];H[d+16>>2]=H[e+16>>2];H[d+20>>2]=c;H[d+24>>2]=H[e+24>>2];H[d+40>>2]=a;c=a+12|0;H[d+36>>2]=c;H[d+32>>2]=f;H[d+28>>2]=b;H[d+68>>2]=a;H[d- -64>>2]=c;H[d+60>>2]=f;H[d+56>>2]=b;H[d+48>>2]=0;H[d+52>>2]=0;H[d>>2]=9028;H[d+88>>2]=1065353216;H[d+92>>2]=-1;H[d+80>>2]=-1;H[d+84>>2]=-1;H[d+72>>2]=1;H[d+76>>2]=-1;H[d+44>>2]=9592;a=d+96|0;break f}if((b|0)!=6){break e}b=H[c+44>>2];d=pa(112);H[d+4>>2]=h;c=H[e+12>>2];H[d+8>>2]=H[e+8>>2];H[d+12>>2]=c;c=H[e+20>>2];H[d+16>>2]=H[e+16>>2];H[d+20>>2]=c;H[d+24>>2]=H[e+24>>2];H[d+40>>2]=a;c=a+12|0;H[d+36>>2]=c;H[d+32>>2]=g;H[d+28>>2]=b;H[d+68>>2]=a;H[d- -64>>2]=c;H[d+60>>2]=g;H[d+56>>2]=b;H[d+48>>2]=0;H[d+52>>2]=0;H[d>>2]=10032;H[d+88>>2]=1065353216;H[d+92>>2]=-1;H[d+80>>2]=-1;H[d+84>>2]=-1;H[d+72>>2]=1;H[d+76>>2]=-1;H[d+44>>2]=10452;a=d+96|0}H[a>>2]=0;H[a+4>>2]=0;F[a+5|0]=0;F[a+6|0]=0;F[a+7|0]=0;F[a+8|0]=0;F[a+9|0]=0;F[a+10|0]=0;F[a+11|0]=0;F[a+12|0]=0}if(d){break a}}d=pa(28);H[d+4>>2]=i;a=H[e+12>>2];H[d+8>>2]=H[e+8>>2];H[d+12>>2]=a;a=H[e+20>>2];H[d+16>>2]=H[e+16>>2];H[d+20>>2]=a;H[d+24>>2]=H[e+24>>2];H[d>>2]=10864}ca=e+32|0;return d|0}function Ki(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=O(0),f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=O(0),p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;if(H[c>>2]==H[c+4>>2]){m=H[d+80>>2];u=ca-16|0;ca=u;g=H[a+4>>2];k=I[b+24|0];h=H[d+48>>2];n=H[H[d>>2]>>2];c=u+8|0;H[c>>2]=1065353216;d=c;L[c>>2]=O(-1<>2];c=pa(k<<2);a:{if(!m|!k){break a}p=h+n|0;o=L[d>>2];n=H[a+8>>2];v=H[b>>2];d=H[b+48>>2];g=H[b+40>>2];w=H[b+44>>2];if(!I[b+84|0]){f=H[b+68>>2];s=k&254;t=k&1;a=0;while(1){b=H[v>>2];l=Rj(g,w,H[f+(i<<2)>>2],0)+d|0;h=qa(c,b+l|0,g);b=0;q=0;if((k|0)!=1){while(1){l=p+(a<<2)|0;j=b<<2;e=O(T(O(O(o*O(L[j+h>>2]-L[n+j>>2]))+O(.5))));b:{if(O(P(e))>2]=r;j=j|4;e=O(T(O(O(o*O(L[j+h>>2]-L[n+j>>2]))+O(.5))));c:{if(O(P(e))>2]=j;b=b+2|0;a=a+2|0;q=q+2|0;if((s|0)!=(q|0)){continue}break}}if(t){l=p+(a<<2)|0;b=b<<2;e=O(T(O(O(o*O(L[b+h>>2]-L[b+n>>2]))+O(.5))));d:{if(O(P(e))>2]=b;a=a+1|0}i=i+1|0;if((m|0)!=(i|0)){continue}break}break a}s=k&254;t=k&1;a=0;while(1){b=H[v>>2];h=Rj(g,w,i,l)+d|0;j=qa(c,b+h|0,g);b=0;q=0;if((k|0)!=1){while(1){h=p+(a<<2)|0;f=b<<2;e=O(T(O(O(o*O(L[f+j>>2]-L[f+n>>2]))+O(.5))));e:{if(O(P(e))>2]=r;f=f|4;e=O(T(O(O(o*O(L[f+j>>2]-L[f+n>>2]))+O(.5))));f:{if(O(P(e))>2]=f;b=b+2|0;a=a+2|0;q=q+2|0;if((s|0)!=(q|0)){continue}break}}if(t){h=p+(a<<2)|0;b=b<<2;e=O(T(O(O(o*O(L[b+j>>2]-L[b+n>>2]))+O(.5))));g:{if(O(P(e))>2]=b;a=a+1|0}b=l;i=i+1|0;b=i?b:b+1|0;l=b;if((i|0)!=(m|0)|b){continue}break}}oa(c);ca=u+16|0;return 1}j=ca-16|0;ca=j;m=H[a+4>>2];i=I[b+24|0];g=H[d+48>>2];h=H[H[d>>2]>>2];d=j+8|0;H[d>>2]=1065353216;l=d;L[d>>2]=O(-1<>2];d=pa(i<<2);m=H[c+4>>2];q=H[c>>2];h:{if(!i|(m|0)==(q|0)){break h}n=h+g|0;c=m-q>>2;u=c>>>0<=1?1:c;o=L[l>>2];h=H[a+8>>2];v=H[b>>2];l=H[b+48>>2];m=H[b+40>>2];w=H[b+44>>2];if(I[b+84|0]){s=i&254;t=i&1;a=0;c=0;while(1){b=H[v>>2];g=Rj(m,w,H[q+(c<<2)>>2],0)+l|0;p=qa(d,b+g|0,m);b=0;k=0;if((i|0)!=1){while(1){g=n+(a<<2)|0;f=b<<2;e=O(T(O(O(o*O(L[f+p>>2]-L[h+f>>2]))+O(.5))));i:{if(O(P(e))>2]=r;f=f|4;e=O(T(O(O(o*O(L[f+p>>2]-L[h+f>>2]))+O(.5))));j:{if(O(P(e))>2]=f;b=b+2|0;a=a+2|0;k=k+2|0;if((s|0)!=(k|0)){continue}break}}if(t){g=n+(a<<2)|0;b=b<<2;e=O(T(O(O(o*O(L[b+p>>2]-L[b+h>>2]))+O(.5))));k:{if(O(P(e))>2]=b;a=a+1|0}c=c+1|0;if((u|0)!=(c|0)){continue}break}break h}s=H[b+68>>2];t=i&254;x=i&1;a=0;c=0;while(1){b=H[v>>2];g=Rj(m,w,H[s+(H[q+(c<<2)>>2]<<2)>>2],0)+l|0;p=qa(d,b+g|0,m);b=0;k=0;if((i|0)!=1){while(1){g=n+(a<<2)|0;f=b<<2;e=O(T(O(O(o*O(L[f+p>>2]-L[h+f>>2]))+O(.5))));l:{if(O(P(e))>2]=r;f=f|4;e=O(T(O(O(o*O(L[f+p>>2]-L[h+f>>2]))+O(.5))));m:{if(O(P(e))>2]=f;b=b+2|0;a=a+2|0;k=k+2|0;if((t|0)!=(k|0)){continue}break}}if(x){g=n+(a<<2)|0;b=b<<2;e=O(T(O(O(o*O(L[b+p>>2]-L[b+h>>2]))+O(.5))));n:{if(O(P(e))>2]=b;a=a+1|0}c=c+1|0;if((u|0)!=(c|0)){continue}break}}oa(d);ca=j+16|0;return 1}function dd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;c=H[a+4>>2];e=H[a>>2];f=(c-e|0)/144|0;if(f>>>0>>0){e=a;b=b-f|0;h=H[a+8>>2];c=H[a+4>>2];a:{if(b>>>0<=(h-c|0)/144>>>0){b:{if(!b){break b}a=c;f=b&7;if(f){while(1){Ia(a);a=a+144|0;d=d+1|0;if((f|0)!=(d|0)){continue}break}}c=N(b,144)+c|0;if((b-1&268435455)>>>0<7){break b}while(1){Ia(a);Ia(a+144|0);Ia(a+288|0);Ia(a+432|0);Ia(a+576|0);Ia(a+720|0);Ia(a+864|0);Ia(a+1008|0);a=a+1152|0;if((c|0)!=(a|0)){continue}break}}H[e+4>>2]=c;break a}c:{d:{e:{a=c;c=H[e>>2];i=(a-c|0)/144|0;a=i+b|0;if(a>>>0<29826162){c=(h-c|0)/144|0;f=c<<1;f=c>>>0>=14913080?29826161:a>>>0>>0?f:a;if(f){if(f>>>0>=29826162){break e}g=pa(N(f,144))}c=N(i,144)+g|0;a=c;h=b&7;if(h){while(1){Ia(a);a=a+144|0;d=d+1|0;if((h|0)!=(d|0)){continue}break}}h=N(b,144)+c|0;if((b-1&268435455)>>>0>=7){while(1){Ia(a);Ia(a+144|0);Ia(a+288|0);Ia(a+432|0);Ia(a+576|0);Ia(a+720|0);Ia(a+864|0);Ia(a+1008|0);a=a+1152|0;if((h|0)!=(a|0)){continue}break}}b=N(f,144)+g|0;d=H[e+4>>2];f=H[e>>2];if((d|0)==(f|0)){break d}while(1){c=c-144|0;d=d-144|0;a=d;H[c>>2]=H[a>>2];H[c+4>>2]=H[a+4>>2];H[c+8>>2]=H[a+8>>2];H[c+12>>2]=H[a+12>>2];H[a+12>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[c+16>>2]=H[a+16>>2];H[c+20>>2]=H[a+20>>2];H[c+24>>2]=H[a+24>>2];H[a+24>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;g=I[a+28|0];H[c+40>>2]=0;H[c+32>>2]=0;H[c+36>>2]=0;F[c+28|0]=g;H[c+32>>2]=H[a+32>>2];H[c+36>>2]=H[a+36>>2];H[c+40>>2]=H[a+40>>2];H[a+40>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;H[c+52>>2]=0;H[c+44>>2]=0;H[c+48>>2]=0;H[c+44>>2]=H[a+44>>2];H[c+48>>2]=H[a+48>>2];H[c+52>>2]=H[a+52>>2];H[a+52>>2]=0;H[a+44>>2]=0;H[a+48>>2]=0;g=c- -64|0;H[g>>2]=0;H[c+56>>2]=0;H[c+60>>2]=0;H[c+56>>2]=H[a+56>>2];H[c+60>>2]=H[a+60>>2];i=g;g=a- -64|0;H[i>>2]=H[g>>2];H[g>>2]=0;H[a+56>>2]=0;H[a+60>>2]=0;H[c+68>>2]=H[a+68>>2];g=H[a+72>>2];H[c+84>>2]=0;H[c+76>>2]=0;H[c+80>>2]=0;H[c+72>>2]=g;H[c+76>>2]=H[a+76>>2];H[c+80>>2]=H[a+80>>2];H[c+84>>2]=H[a+84>>2];H[a+84>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[c+96>>2]=0;H[c+88>>2]=0;H[c+92>>2]=0;H[c+88>>2]=H[a+88>>2];H[c+92>>2]=H[a+92>>2];H[c+96>>2]=H[a+96>>2];H[a+96>>2]=0;H[a+88>>2]=0;H[a+92>>2]=0;g=I[a+100|0];H[c+112>>2]=0;H[c+104>>2]=0;H[c+108>>2]=0;F[c+100|0]=g;H[c+104>>2]=H[a+104>>2];H[c+108>>2]=H[a+108>>2];H[c+112>>2]=H[a+112>>2];H[a+112>>2]=0;H[a+104>>2]=0;H[a+108>>2]=0;H[c+124>>2]=0;H[c+116>>2]=0;H[c+120>>2]=0;H[c+116>>2]=H[a+116>>2];H[c+120>>2]=H[a+120>>2];H[c+124>>2]=H[a+124>>2];H[a+124>>2]=0;H[a+116>>2]=0;H[a+120>>2]=0;g=H[a+128>>2];H[c+140>>2]=0;H[c+132>>2]=0;H[c+136>>2]=0;H[c+128>>2]=g;H[c+132>>2]=H[a+132>>2];H[c+136>>2]=H[a+136>>2];H[c+140>>2]=H[a+140>>2];H[a+140>>2]=0;H[a+132>>2]=0;H[a+136>>2]=0;if((a|0)!=(f|0)){continue}break}H[e+8>>2]=b;a=H[e+4>>2];H[e+4>>2]=h;d=H[e>>2];H[e>>2]=c;if((a|0)==(d|0)){break c}while(1){b=a-144|0;c=H[b+132>>2];if(c){H[a-8>>2]=c;oa(c)}c=H[a-28>>2];if(c){H[a-24>>2]=c;oa(c)}c=H[a-40>>2];if(c){H[a-36>>2]=c;oa(c)}oc(a-140|0);a=b;if((d|0)!=(a|0)){continue}break}break c}sa();v()}wa();v()}H[e+8>>2]=b;H[e+4>>2]=h;H[e>>2]=c}if(d){oa(d)}}return}if(b>>>0>>0){e=e+N(b,144)|0;if((e|0)!=(c|0)){while(1){b=c-144|0;d=H[b+132>>2];if(d){H[c-8>>2]=d;oa(d)}d=H[c-28>>2];if(d){H[c-24>>2]=d;oa(d)}d=H[c-40>>2];if(d){H[c-36>>2]=d;oa(d)}oc(c-140|0);c=b;if((e|0)!=(c|0)){continue}break}}H[a+4>>2]=e}}function Pe(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;f=ca-80|0;ca=f;e=H[c+36>>2];H[f+72>>2]=H[c+32>>2];H[f+76>>2]=e;g=H[c+28>>2];e=f- -64|0;H[e>>2]=H[c+24>>2];H[e+4>>2]=g;e=H[c+20>>2];H[f+56>>2]=H[c+16>>2];H[f+60>>2]=e;e=H[c+12>>2];H[f+48>>2]=H[c+8>>2];H[f+52>>2]=e;e=H[c+4>>2];H[f+40>>2]=H[c>>2];H[f+44>>2]=e;nc(a,f+40|0,f+24|0);a:{if(H[a>>2]){break a}if(F[a+15|0]<0){oa(H[a+4>>2])}if(I[f+31|0]){b=pa(32);F[b+27|0]=0;c=I[1521]|I[1522]<<8|(I[1523]<<16|I[1524]<<24);F[b+23|0]=c;F[b+24|0]=c>>>8;F[b+25|0]=c>>>16;F[b+26|0]=c>>>24;c=I[1518]|I[1519]<<8|(I[1520]<<16|I[1521]<<24);d=I[1514]|I[1515]<<8|(I[1516]<<16|I[1517]<<24);F[b+16|0]=d;F[b+17|0]=d>>>8;F[b+18|0]=d>>>16;F[b+19|0]=d>>>24;F[b+20|0]=c;F[b+21|0]=c>>>8;F[b+22|0]=c>>>16;F[b+23|0]=c>>>24;c=I[1510]|I[1511]<<8|(I[1512]<<16|I[1513]<<24);d=I[1506]|I[1507]<<8|(I[1508]<<16|I[1509]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1502]|I[1503]<<8|(I[1504]<<16|I[1505]<<24);d=I[1498]|I[1499]<<8|(I[1500]<<16|I[1501]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;H[a>>2]=-1;za(a+4|0,b,27);oa(b);break a}i=ca-16|0;ca=i;b:{c:{switch(F[f+32|0]){case 0:e=pa(44);H[e>>2]=0;H[e+4>>2]=0;H[e+40>>2]=0;H[e+32>>2]=0;H[e+36>>2]=0;H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;e=Vc(e);H[e>>2]=13496;H[f+8>>2]=0;H[f+12>>2]=0;H[f>>2]=0;H[f+4>>2]=0;H[f+16>>2]=e;break b;case 1:e=pa(44);H[e>>2]=0;H[e+4>>2]=0;H[e+40>>2]=0;H[e+32>>2]=0;H[e+36>>2]=0;H[e+24>>2]=0;H[e+28>>2]=0;H[e+16>>2]=0;H[e+20>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;e=Vc(e);H[e>>2]=13404;H[f+8>>2]=0;H[f+12>>2]=0;H[f>>2]=0;H[f+4>>2]=0;H[f+16>>2]=e;break b;default:break c}}g=pa(32);F[g+28|0]=0;e=I[1550]|I[1551]<<8|(I[1552]<<16|I[1553]<<24);F[g+24|0]=e;F[g+25|0]=e>>>8;F[g+26|0]=e>>>16;F[g+27|0]=e>>>24;e=I[1546]|I[1547]<<8|(I[1548]<<16|I[1549]<<24);h=I[1542]|I[1543]<<8|(I[1544]<<16|I[1545]<<24);F[g+16|0]=h;F[g+17|0]=h>>>8;F[g+18|0]=h>>>16;F[g+19|0]=h>>>24;F[g+20|0]=e;F[g+21|0]=e>>>8;F[g+22|0]=e>>>16;F[g+23|0]=e>>>24;e=I[1538]|I[1539]<<8|(I[1540]<<16|I[1541]<<24);h=I[1534]|I[1535]<<8|(I[1536]<<16|I[1537]<<24);F[g+8|0]=h;F[g+9|0]=h>>>8;F[g+10|0]=h>>>16;F[g+11|0]=h>>>24;F[g+12|0]=e;F[g+13|0]=e>>>8;F[g+14|0]=e>>>16;F[g+15|0]=e>>>24;e=I[1530]|I[1531]<<8|(I[1532]<<16|I[1533]<<24);h=I[1526]|I[1527]<<8|(I[1528]<<16|I[1529]<<24);F[g|0]=h;F[g+1|0]=h>>>8;F[g+2|0]=h>>>16;F[g+3|0]=h>>>24;F[g+4|0]=e;F[g+5|0]=e>>>8;F[g+6|0]=e>>>16;F[g+7|0]=e>>>24;H[i>>2]=-1;e=i|4;za(e,g,28);j=F[i+15|0];H[f>>2]=H[i>>2];h=f+4|0;d:{if((j|0)>=0){j=H[e+4>>2];H[h>>2]=H[e>>2];H[h+4>>2]=j;H[h+8>>2]=H[e+8>>2];H[f+16>>2]=0;break d}za(h,H[i+4>>2],H[i+8>>2]);e=F[i+15|0];H[f+16>>2]=0;if((e|0)>=0){break d}oa(H[i+4>>2])}oa(g)}ca=i+16|0;e=H[f>>2];e:{if(e){H[a>>2]=e;a=a+4|0;if(F[f+15|0]>=0){b=f|4;c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c;H[a+8>>2]=H[b+8>>2];break e}za(a,H[f+4>>2],H[f+8>>2]);break e}e=H[f+16>>2];H[f+16>>2]=0;te(a,e,b,c,d);if(!H[a>>2]){if(F[a+15|0]<0){oa(H[a+4>>2])}H[a>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0}ea[H[H[e>>2]+4>>2]](e)}a=H[f+16>>2];H[f+16>>2]=0;if(a){ea[H[H[a>>2]+4>>2]](a)}if(F[f+15|0]>=0){break a}oa(H[f+4>>2])}ca=f+80|0}function Ic(a){var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;H[a+56>>2]=H[a+52>>2];H[a+44>>2]=H[a+40>>2];b=H[a+64>>2];c=H[b+24>>2];if((c|0)==H[b+28>>2]){return 1}a:{b:{c:{while(1){g=i;i=H[(k<<2)+c>>2];d:{if((i|0)==-1){i=g;break d}b=H[a+56>>2];e:{if((b|0)!=H[a+60>>2]){H[b>>2]=g;H[a+56>>2]=b+4;break e}d=H[a+52>>2];e=b-d|0;h=e>>2;c=h+1|0;if(c>>>0>=1073741824){break c}f=e>>>1|0;f=e>>>0>=2147483644?1073741823:c>>>0>>0?f:c;if(f){if(f>>>0>=1073741824){break b}e=pa(f<<2)}else{e=0}c=e+(h<<2)|0;H[c>>2]=g;h=c+4|0;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[a+60>>2]=e+(f<<2);H[a+56>>2]=h;H[a+52>>2]=c;if(!d){break e}oa(d)}f:{g:{if(!(H[H[a+12>>2]+(k>>>3&536870908)>>2]>>>k&1)){break g}e=i+1|0;e=(e>>>0)%3|0?e:i-2|0;if((e|0)==-1|H[H[a>>2]+(e>>>3&536870908)>>2]>>>e&1){break g}e=H[H[H[a+64>>2]+12>>2]+(e<<2)>>2];if((e|0)==-1){break g}b=e+1|0;b=(b>>>0)%3|0?b:e-2|0;if((b|0)==-1){break g}c=H[a+64>>2];f=H[a>>2];while(1){e=b;b=-1;d=e+1|0;d=(d>>>0)%3|0?d:e-2|0;h:{if((d|0)==-1|H[f+(d>>>3&536870908)>>2]>>>d&1){break h}d=H[H[c+12>>2]+(d<<2)>>2];if((d|0)==-1){break h}b=d+1|0;b=(b>>>0)%3|0?b:d-2|0}if((b|0)!=(i|0)){if((b|0)==-1){break f}continue}break}return 0}e=i}H[H[a+28>>2]+(e<<2)>>2]=g;b=H[a+44>>2];i:{if((b|0)!=H[a+48>>2]){H[b>>2]=e;H[a+44>>2]=b+4;break i}d=H[a+40>>2];i=b-d|0;h=i>>2;c=h+1|0;if(c>>>0>=1073741824){break a}f=i>>>1|0;f=i>>>0>=2147483644?1073741823:c>>>0>>0?f:c;if(f){if(f>>>0>=1073741824){break b}i=pa(f<<2)}else{i=0}c=i+(h<<2)|0;H[c>>2]=e;h=c+4|0;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[a+48>>2]=i+(f<<2);H[a+44>>2]=h;H[a+40>>2]=c;if(!d){break i}oa(d)}i=g+1|0;b=H[a+64>>2];if((e|0)==-1){break d}j:{if((e>>>0)%3|0){c=e-1|0;break j}c=e+2|0;if((c|0)==-1){break d}}d=H[H[b+12>>2]+(c<<2)>>2];if((d|0)==-1){break d}f=d+((d>>>0)%3|0?-1:2)|0;if((f|0)==-1|(e|0)==(f|0)){break d}while(1){b=f+1|0;b=(b>>>0)%3|0?b:f-2|0;if(H[H[a>>2]+(b>>>3&536870908)>>2]>>>b&1){b=H[a+56>>2];k:{if((b|0)!=H[a+60>>2]){H[b>>2]=i;H[a+56>>2]=b+4;break k}d=H[a+52>>2];g=b-d|0;j=g>>2;c=j+1|0;if(c>>>0>=1073741824){break c}h=g>>>1|0;h=g>>>0>=2147483644?1073741823:c>>>0>>0?h:c;if(h){if(h>>>0>=1073741824){break b}g=pa(h<<2)}else{g=0}c=g+(j<<2)|0;H[c>>2]=i;j=c+4|0;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[a+60>>2]=g+(h<<2);H[a+56>>2]=j;H[a+52>>2]=c;if(!d){break k}oa(d)}d=i+1|0;b=H[a+44>>2];l:{if((b|0)!=H[a+48>>2]){H[b>>2]=f;H[a+44>>2]=b+4;break l}h=H[a+40>>2];g=b-h|0;l=g>>2;c=l+1|0;if(c>>>0>=1073741824){break a}j=g>>>1|0;j=g>>>0>=2147483644?1073741823:c>>>0>>0?j:c;if(j){if(j>>>0>=1073741824){break b}g=pa(j<<2)}else{g=0}c=g+(l<<2)|0;H[c>>2]=f;l=c+4|0;if((b|0)!=(h|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(h|0)){continue}break}}H[a+48>>2]=g+(j<<2);H[a+44>>2]=l;H[a+40>>2]=c;if(!h){break l}oa(h)}g=i;i=d}H[H[a+28>>2]+(f<<2)>>2]=g;b=H[a+64>>2];m:{if((f>>>0)%3|0){c=f-1|0;break m}c=f+2|0;if((c|0)==-1){break d}}d=H[H[b+12>>2]+(c<<2)>>2];if((d|0)==-1){break d}f=d+((d>>>0)%3|0?-1:2)|0;if((f|0)==-1){break d}if((e|0)!=(f|0)){continue}break}}k=k+1|0;c=H[b+24>>2];if(k>>>0>2]-c>>2>>>0){continue}break}return 1}sa();v()}wa();v()}sa();v()}function ti(a){a=a|0;var b=0,c=0,d=0,e=0;c=H[a+32>>2];d=H[c+16>>2];e=H[c+12>>2];b=H[c+20>>2];if(K[c+8>>2]>d>>>0&(e|0)>=(b|0)|(b|0)<(e|0)){e=I[H[c>>2]+d|0];d=d+1|0;b=d?b:b+1|0;H[c+16>>2]=d;H[c+20>>2]=b;b=H[a+48>>2];H[a+48>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}a:{b:{c:{d:{switch(e|0){case 0:b=pa(384);H[b>>2]=11384;ra(b+4|0,0,80);H[b+96>>2]=0;H[b+100>>2]=0;H[b+92>>2]=-1;H[b+84>>2]=-1;H[b+88>>2]=-1;H[b+104>>2]=0;H[b+108>>2]=0;H[b+112>>2]=0;H[b+116>>2]=0;H[b+120>>2]=0;H[b+124>>2]=0;H[b+128>>2]=0;H[b+132>>2]=0;H[b+136>>2]=0;H[b+140>>2]=0;H[b+144>>2]=0;H[b+148>>2]=0;H[b+156>>2]=0;H[b+160>>2]=0;H[b+152>>2]=1065353216;H[b+164>>2]=0;H[b+168>>2]=0;H[b+172>>2]=0;H[b+176>>2]=0;H[b+180>>2]=0;H[b+184>>2]=0;H[b+188>>2]=0;H[b+192>>2]=0;H[b+196>>2]=0;H[b+200>>2]=0;H[b+204>>2]=0;H[b+208>>2]=0;H[b+212>>2]=-1;H[b+216>>2]=0;H[b+220>>2]=0;H[b+224>>2]=0;Ha(b+232|0);Ha(b+272|0);c=b+312|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;Ha(b+328|0);H[b+376>>2]=0;H[b+368>>2]=0;H[b+372>>2]=0;break c;case 1:b=pa(424);H[b>>2]=11436;ra(b+4|0,0,80);H[b+96>>2]=0;H[b+100>>2]=0;H[b+92>>2]=-1;H[b+84>>2]=-1;H[b+88>>2]=-1;H[b+104>>2]=0;H[b+108>>2]=0;H[b+112>>2]=0;H[b+116>>2]=0;H[b+120>>2]=0;H[b+124>>2]=0;H[b+128>>2]=0;H[b+132>>2]=0;H[b+136>>2]=0;H[b+140>>2]=0;H[b+144>>2]=0;H[b+148>>2]=0;H[b+156>>2]=0;H[b+160>>2]=0;H[b+152>>2]=1065353216;H[b+164>>2]=0;H[b+168>>2]=0;H[b+172>>2]=0;H[b+176>>2]=0;H[b+180>>2]=0;H[b+184>>2]=0;H[b+188>>2]=0;H[b+192>>2]=0;H[b+196>>2]=0;H[b+200>>2]=0;H[b+204>>2]=0;H[b+208>>2]=0;H[b+212>>2]=-1;H[b+216>>2]=0;H[b+220>>2]=0;H[b+224>>2]=0;Ha(b+232|0);Ha(b+272|0);c=b+312|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;Ha(b+328|0);H[b+392>>2]=0;H[b+396>>2]=0;H[b+384>>2]=0;H[b+388>>2]=0;H[b+376>>2]=0;H[b+380>>2]=0;H[b+368>>2]=0;H[b+372>>2]=0;c=b+400|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;H[b+416>>2]=-1;H[b+420>>2]=-1;break c;case 2:break d;default:break b}}b=pa(440);H[b>>2]=11484;ra(b+4|0,0,80);H[b+96>>2]=0;H[b+100>>2]=0;H[b+92>>2]=-1;H[b+84>>2]=-1;H[b+88>>2]=-1;H[b+104>>2]=0;H[b+108>>2]=0;H[b+112>>2]=0;H[b+116>>2]=0;H[b+120>>2]=0;H[b+124>>2]=0;H[b+128>>2]=0;H[b+132>>2]=0;H[b+136>>2]=0;H[b+140>>2]=0;H[b+144>>2]=0;H[b+148>>2]=0;H[b+156>>2]=0;H[b+160>>2]=0;H[b+152>>2]=1065353216;H[b+164>>2]=0;H[b+168>>2]=0;H[b+172>>2]=0;H[b+176>>2]=0;H[b+180>>2]=0;H[b+184>>2]=0;H[b+188>>2]=0;H[b+192>>2]=0;H[b+196>>2]=0;H[b+200>>2]=0;H[b+204>>2]=0;H[b+208>>2]=0;H[b+212>>2]=-1;H[b+216>>2]=0;H[b+220>>2]=0;H[b+224>>2]=0;Ha(b+232|0);Ha(b+272|0);c=b+312|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;Ha(b+328|0);H[b+392>>2]=0;H[b+396>>2]=0;H[b+384>>2]=0;H[b+388>>2]=0;H[b+376>>2]=0;H[b+380>>2]=0;H[b+368>>2]=0;H[b+372>>2]=0;H[b+416>>2]=0;H[b+420>>2]=0;H[b+408>>2]=2;H[b+412>>2]=7;H[b+400>>2]=-1;H[b+404>>2]=-1;H[b+424>>2]=0;H[b+428>>2]=0;H[b+432>>2]=0;H[b+436>>2]=0}c=H[a+48>>2];H[a+48>>2]=b;if(!c){break a}ea[H[H[c>>2]+4>>2]](c)}b=H[a+48>>2];if(b){break a}return 0}a=ea[H[H[b>>2]+8>>2]](b,a)|0}else{a=0}return a|0}function Lb(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0;f=ca-96|0;ca=f;e=H[a+16>>2];F[f+92|0]=1;H[f+88>>2]=b;H[f+84>>2]=b;H[f+80>>2]=e;a:{if((b|0)==-1){break a}j=H[a+20>>2];d=H[j>>2];e=H[H[e>>2]+(b<<2)>>2];if(e>>>0>=H[j+4>>2]-d>>2>>>0){break a}e=H[H[a+8>>2]+(H[d+(e<<2)>>2]<<2)>>2];d=H[a+4>>2];if(!I[d+84|0]){e=H[H[d+68>>2]+(e<<2)>>2]}H[f+72>>2]=0;H[f+76>>2]=0;j=f- -64|0;H[j>>2]=0;H[j+4>>2]=0;H[f+56>>2]=0;H[f+60>>2]=0;Sa(d,e,F[d+24|0],f+56|0);e=b+1|0;j=(e>>>0)%3|0?e:b-2|0;n=((b>>>0)%3|0?-1:2)+b|0;b:{c:{while(1){d=j;e=n;d:{if(!H[a+28>>2]){break d}e=b+1|0;d=(e>>>0)%3|0?e:b-2|0;e=b-1|0;if((b>>>0)%3|0){break d}e=b+2|0}if((d|0)==-1){break b}m=H[a+20>>2];b=H[m>>2];d=H[H[H[a+16>>2]>>2]+(d<<2)>>2];if(d>>>0>=H[m+4>>2]-b>>2>>>0){break b}d=H[H[a+8>>2]+(H[(d<<2)+b>>2]<<2)>>2];b=H[a+4>>2];if(!I[b+84|0]){d=H[H[b+68>>2]+(d<<2)>>2]}H[f+48>>2]=0;H[f+52>>2]=0;H[f+40>>2]=0;H[f+44>>2]=0;H[f+32>>2]=0;H[f+36>>2]=0;Sa(b,d,F[b+24|0],f+32|0);if((e|0)==-1){break c}d=H[a+20>>2];b=H[d>>2];e=H[H[H[a+16>>2]>>2]+(e<<2)>>2];if(e>>>0>=H[d+4>>2]-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)|0;i=m;k=j^-1;g=i^2147483647;m=h;e:{f:{if(!H[a+28>>2]){if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break e}b=b+i|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;e=a;g=h;a=g>>31;d=a;n=d^o;a=n-d|0;h=a;d=(d^g)-((d>>>0>n>>>0)+d|0)|0;a=a+e|0;d=d^2147483647;h=(d|0)==(b|0)&(h^-1)>>>0>>0|b>>>0>d>>>0;a=h?-1:a;if(!(h&0)&(a|0)<=536870912|(a|0)<536870912){break e}b=0;a=a>>>29|0;break f}g:{if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break g}b=b+i|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;k=h;h=h>>31;g=h;i=g^o;h=i-g|0;j=(g^k)-((g>>>0>i>>>0)+g|0)|0;g=j^2147483647;d=a;a=h;if((g|0)==(b|0)&d>>>0>(a^-1)>>>0|b>>>0>g>>>0){break g}b=b+j|0;n=a+d|0;b=n>>>0>>0?b+1|0:b;e=b;if(!b&n>>>0<536870913){break e}}b=e>>>29|0;a=(e&536870911)<<3|n>>>29}o=Sj(o,m,a,b);l=Sj(l,q,a,b);r=Sj(r,s,a,b)}H[c+8>>2]=o;H[c+4>>2]=l;H[c>>2]=r;ca=f+96|0;return}Ca();v()}Ca();v()}Ca();v()}function Wd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;a:{if((b|0)<0){break a}c=H[a+12>>2];d=H[a+8>>2];if(c-d>>2>>>0<=b>>>0){break a}d=d+(b<<2)|0;e=H[d>>2];i=H[e+60>>2];f=H[e+56>>2];e=d+4|0;if((e|0)!=(c|0)){while(1){h=H[e>>2];H[e>>2]=0;g=H[d>>2];H[d>>2]=h;if(g){Ga(g)}d=d+4|0;e=e+4|0;if((e|0)!=(c|0)){continue}break}c=H[a+12>>2]}if((c|0)!=(d|0)){while(1){c=c-4|0;e=H[c>>2];H[c>>2]=0;if(e){Ga(e)}if((c|0)!=(d|0)){continue}break}}H[a+12>>2]=d;g=H[a+4>>2];b:{if(!g|(i|0)<0){break b}c=H[g+24>>2];d=H[g+28>>2];if((c|0)==(d|0)){break b}while(1){if((i|0)==H[H[c>>2]+24>>2]){d=c+4|0;i=H[g+28>>2];if((d|0)!=(i|0)){while(1){h=H[d>>2];H[d>>2]=0;e=H[c>>2];H[c>>2]=h;if(e){Ra(e+12|0,H[e+16>>2]);Qa(e,H[e+4>>2]);oa(e)}c=c+4|0;d=d+4|0;if((i|0)!=(d|0)){continue}break}d=H[g+28>>2]}if((c|0)!=(d|0)){while(1){d=d-4|0;e=H[d>>2];H[d>>2]=0;if(e){Ra(e+12|0,H[e+16>>2]);Qa(e,H[e+4>>2]);oa(e)}if((c|0)!=(d|0)){continue}break}}H[g+28>>2]=c;break b}c=c+4|0;if((d|0)!=(c|0)){continue}break}}c:{if((f|0)>4){break c}d:{e=N(f,12)+a|0;c=H[e+20>>2];d=H[e+24>>2];if((c|0)==(d|0)){break d}while(1){if(H[c>>2]==(b|0)){break d}c=c+4|0;if((d|0)!=(c|0)){continue}break}break c}if((c|0)==(d|0)){break c}f=c;c=c+4|0;va(f,c,d-c|0);H[e+24>>2]=d-4}c=H[a+24>>2];d=H[a+20>>2];e:{if((c|0)==(d|0)){break e}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=H[h>>2];if((j|0)>(b|0)){H[h>>2]=j-1}f=d+(f|4)|0;h=H[f>>2];if((h|0)>(b|0)){H[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break e}c=d+(c<<2)|0;d=H[c>>2];if((d|0)<=(b|0)){break e}H[c>>2]=d-1}c=H[a+36>>2];d=H[a+32>>2];f:{if((c|0)==(d|0)){break f}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=H[h>>2];if((j|0)>(b|0)){H[h>>2]=j-1}f=d+(f|4)|0;h=H[f>>2];if((h|0)>(b|0)){H[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break f}c=d+(c<<2)|0;d=H[c>>2];if((d|0)<=(b|0)){break f}H[c>>2]=d-1}c=H[a+48>>2];d=H[a+44>>2];g:{if((c|0)==(d|0)){break g}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=H[h>>2];if((j|0)>(b|0)){H[h>>2]=j-1}f=d+(f|4)|0;h=H[f>>2];if((h|0)>(b|0)){H[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break g}c=d+(c<<2)|0;d=H[c>>2];if((d|0)<=(b|0)){break g}H[c>>2]=d-1}c=H[a+60>>2];d=H[a+56>>2];h:{if((c|0)==(d|0)){break h}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=H[h>>2];if((j|0)>(b|0)){H[h>>2]=j-1}f=d+(f|4)|0;h=H[f>>2];if((h|0)>(b|0)){H[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break h}c=d+(c<<2)|0;d=H[c>>2];if((d|0)<=(b|0)){break h}H[c>>2]=d-1}c=H[a+72>>2];a=H[a+68>>2];if((c|0)==(a|0)){break a}d=c-a|0;c=d>>2;e=c>>>0<=1?1:c;g=e&1;c=0;if(d>>>0>=8){d=e&-2;e=0;while(1){i=c<<2;f=i+a|0;h=H[f>>2];if((h|0)>(b|0)){H[f>>2]=h-1}i=a+(i|4)|0;f=H[i>>2];if((f|0)>(b|0)){H[i>>2]=f-1}c=c+2|0;e=e+2|0;if((d|0)!=(e|0)){continue}break}}if(!g){break a}f=b;a=a+(c<<2)|0;b=H[a>>2];if((f|0)>=(b|0)){break a}H[a>>2]=b-1}}function oa(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;a:{if(!a){break a}d=a-8|0;b=H[a-4>>2];a=b&-8;f=d+a|0;b:{if(b&1){break b}if(!(b&3)){break a}b=H[d>>2];d=d-b|0;if(d>>>0>>0<=255){e=H[d+8>>2];b=b>>>3|0;c=H[d+12>>2];if((c|0)==(e|0)){i=17192,j=H[4298]&Vj(b),H[i>>2]=j;break b}H[e+12>>2]=c;H[c+8>>2]=e;break b}h=H[d+24>>2];b=H[d+12>>2];c:{if((d|0)!=(b|0)){c=H[d+8>>2];H[c+12>>2]=b;H[b+8>>2]=c;break c}d:{e=d+20|0;c=H[e>>2];if(c){break d}e=d+16|0;c=H[e>>2];if(c){break d}b=0;break c}while(1){g=e;b=c;e=b+20|0;c=H[e>>2];if(c){continue}e=b+16|0;c=H[b+16>>2];if(c){continue}break}H[g>>2]=0}if(!h){break b}e=H[d+28>>2];c=(e<<2)+17496|0;e:{if(H[c>>2]==(d|0)){H[c>>2]=b;if(b){break e}i=17196,j=H[4299]&Vj(e),H[i>>2]=j;break b}H[h+(H[h+16>>2]==(d|0)?16:20)>>2]=b;if(!b){break b}}H[b+24>>2]=h;c=H[d+16>>2];if(c){H[b+16>>2]=c;H[c+24>>2]=b}c=H[d+20>>2];if(!c){break b}H[b+20>>2]=c;H[c+24>>2]=b;break b}b=H[f+4>>2];if((b&3)!=3){break b}H[4300]=a;H[f+4>>2]=b&-2;H[d+4>>2]=a|1;H[a+d>>2]=a;return}if(d>>>0>=f>>>0){break a}b=H[f+4>>2];if(!(b&1)){break a}f:{if(!(b&2)){if(H[4304]==(f|0)){H[4304]=d;a=H[4301]+a|0;H[4301]=a;H[d+4>>2]=a|1;if(H[4303]!=(d|0)){break a}H[4300]=0;H[4303]=0;return}if(H[4303]==(f|0)){H[4303]=d;a=H[4300]+a|0;H[4300]=a;H[d+4>>2]=a|1;H[a+d>>2]=a;return}a=(b&-8)+a|0;g:{if(b>>>0<=255){e=H[f+8>>2];b=b>>>3|0;c=H[f+12>>2];if((c|0)==(e|0)){i=17192,j=H[4298]&Vj(b),H[i>>2]=j;break g}H[e+12>>2]=c;H[c+8>>2]=e;break g}h=H[f+24>>2];b=H[f+12>>2];h:{if((f|0)!=(b|0)){c=H[f+8>>2];H[c+12>>2]=b;H[b+8>>2]=c;break h}i:{e=f+20|0;c=H[e>>2];if(c){break i}e=f+16|0;c=H[e>>2];if(c){break i}b=0;break h}while(1){g=e;b=c;e=b+20|0;c=H[e>>2];if(c){continue}e=b+16|0;c=H[b+16>>2];if(c){continue}break}H[g>>2]=0}if(!h){break g}e=H[f+28>>2];c=(e<<2)+17496|0;j:{if(H[c>>2]==(f|0)){H[c>>2]=b;if(b){break j}i=17196,j=H[4299]&Vj(e),H[i>>2]=j;break g}H[h+(H[h+16>>2]==(f|0)?16:20)>>2]=b;if(!b){break g}}H[b+24>>2]=h;c=H[f+16>>2];if(c){H[b+16>>2]=c;H[c+24>>2]=b}c=H[f+20>>2];if(!c){break g}H[b+20>>2]=c;H[c+24>>2]=b}H[d+4>>2]=a|1;H[a+d>>2]=a;if(H[4303]!=(d|0)){break f}H[4300]=a;return}H[f+4>>2]=b&-2;H[d+4>>2]=a|1;H[a+d>>2]=a}if(a>>>0<=255){b=(a&-8)+17232|0;c=H[4298];a=1<<(a>>>3);k:{if(!(c&a)){H[4298]=a|c;a=b;break k}a=H[b+8>>2]}H[b+8>>2]=d;H[a+12>>2]=d;H[d+12>>2]=b;H[d+8>>2]=a;return}e=31;if(a>>>0<=16777215){b=Q(a>>>8|0);e=((a>>>38-b&1)-(b<<1)|0)+62|0}H[d+28>>2]=e;H[d+16>>2]=0;H[d+20>>2]=0;g=(e<<2)+17496|0;l:{m:{c=H[4299];b=1<>2]=d;H[d+24>>2]=g;break n}e=a<<((e|0)!=31?25-(e>>>1|0)|0:0);b=H[g>>2];while(1){c=b;if((H[b+4>>2]&-8)==(a|0)){break m}b=e>>>29|0;e=e<<1;g=c+(b&4)|0;b=H[g+16>>2];if(b){continue}break}H[g+16>>2]=d;H[d+24>>2]=c}H[d+12>>2]=d;H[d+8>>2]=d;break l}a=H[c+8>>2];H[a+12>>2]=d;H[c+8>>2]=d;H[d+24>>2]=0;H[d+12>>2]=c;H[d+8>>2]=a}a=H[4306]-1|0;H[4306]=a?a:-1}}function tj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;H[a+8>>2]=e;n=a+32|0;h=H[n>>2];f=H[a+36>>2]-h>>2;a:{if(f>>>0>>0){ya(n,e-f|0);d=H[a+8>>2];break a}d=e;if(d>>>0>=f>>>0){break a}H[a+36>>2]=h+(e<<2);d=e}s=H[a+52>>2];p=H[a+48>>2];f=0;h=e>>>0>1073741823?-1:e<<2;m=ra(pa(h),0,h);b:{if((d|0)<=0){break b}g=H[a+32>>2];while(1){d=f<<2;h=H[d+m>>2];j=H[a+16>>2];c:{if((h|0)>(j|0)){H[d+g>>2]=j;break c}d=d+g|0;j=H[a+12>>2];if((j|0)>(h|0)){H[d>>2]=j;break c}H[d>>2]=h}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}if((d|0)<=0){break b}f=0;while(1){h=f<<2;d=h+c|0;h=H[b+h>>2]+H[g+h>>2]|0;H[d>>2]=h;d:{if((h|0)>H[a+16>>2]){i=h-H[a+20>>2]|0}else{if((h|0)>=H[a+12>>2]){break d}i=h+H[a+20>>2]|0}H[d>>2]=i}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}f=H[a+56>>2];q=H[f>>2];f=H[f+4>>2]-q|0;if((f|0)>=5){o=f>>>2|0;t=o>>>0<=2?2:o;u=e&-2;w=e&1;h=1;while(1){e:{f:{if((h|0)!=(o|0)){r=N(e,h);f=H[(h<<2)+q>>2];if((f|0)==-1){break f}f=H[H[p+12>>2]+(f<<2)>>2];if((f|0)==-1){break f}j=H[s>>2];g=H[p>>2];k=H[j+(H[g+(f<<2)>>2]<<2)>>2];i=f+1|0;i=(i>>>0)%3|0?i:f-2|0;if((i|0)!=-1){i=H[g+(i<<2)>>2]}else{i=-1}g:{h:{if((f>>>0)%3|0){f=f-1|0;break h}f=f+2|0;l=-1;if((f|0)==-1){break g}}l=H[g+(f<<2)>>2]}if((h|0)<=(k|0)){break f}f=H[(i<<2)+j>>2];if((f|0)>=(h|0)){break f}g=H[j+(l<<2)>>2];if((g|0)>=(h|0)){break f}i:{if((e|0)<=0){break i}g=N(e,g);j=N(e,f);k=N(e,k);f=0;l=0;if((e|0)!=1){while(1){H[(f<<2)+m>>2]=(H[(f+g<<2)+c>>2]+H[(f+j<<2)+c>>2]|0)-H[(f+k<<2)+c>>2];i=f|1;H[(i<<2)+m>>2]=(H[(g+i<<2)+c>>2]+H[(j+i<<2)+c>>2]|0)-H[(i+k<<2)+c>>2];f=f+2|0;l=l+2|0;if((u|0)!=(l|0)){continue}break}}if(!w){break i}H[(f<<2)+m>>2]=(H[(f+g<<2)+c>>2]+H[(f+j<<2)+c>>2]|0)-H[(f+k<<2)+c>>2]}if((d|0)<=0){break e}j=H[n>>2];f=0;while(1){d=f<<2;g=H[d+m>>2];k=H[a+16>>2];j:{if((g|0)>(k|0)){H[d+j>>2]=k;break j}d=d+j|0;k=H[a+12>>2];if((k|0)>(g|0)){H[d>>2]=k;break j}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;i=b+d|0;while(1){g=f<<2;d=g+k|0;g=H[g+i>>2]+H[g+j>>2]|0;H[d>>2]=g;k:{if((g|0)>H[a+16>>2]){l=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break k}l=g+H[a+20>>2]|0}H[d>>2]=l}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}break e}Ca();v()}if((d|0)<=0){break e}k=(N(h-1|0,e)<<2)+c|0;j=H[n>>2];f=0;while(1){d=f<<2;g=H[d+k>>2];i=H[a+16>>2];l:{if((g|0)>(i|0)){H[d+j>>2]=i;break l}d=d+j|0;i=H[a+12>>2];if((i|0)>(g|0)){H[d>>2]=i;break l}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;i=b+d|0;while(1){g=f<<2;d=g+k|0;g=H[g+i>>2]+H[g+j>>2]|0;H[d>>2]=g;m:{if((g|0)>H[a+16>>2]){l=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break m}l=g+H[a+20>>2]|0}H[d>>2]=l}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}h=h+1|0;if((t|0)!=(h|0)){continue}break}}oa(m);return 1}function we(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;if((b|0)==-1){return 1}g=(b>>>0)/3|0;if(!(H[H[a+24>>2]+(g>>>3&268435452)>>2]>>>g&1)){e=H[a+48>>2];H[a+52>>2]=e;a:{if((e|0)!=H[a+56>>2]){H[e>>2]=b;H[a+52>>2]=e+4;break a}d=pa(4);H[d>>2]=b;c=d+4|0;H[a+56>>2]=c;H[a+52>>2]=c;H[a+48>>2]=d;if(!e){break a}oa(e)}c=b+1|0;i=(c>>>0)%3|0?c:b-2|0;c=H[H[a+4>>2]+28>>2];k=H[(i<<2)+c>>2];if((k|0)==-1){return 0}e=(b-N(g,3)|0?-1:2)+b|0;j=H[c+(e<<2)>>2];if((j|0)==-1){return 0}b=H[a+36>>2];g=b+(k>>>3&536870908)|0;d=H[g>>2];c=1<>2]=c|d;Ua(a+8|0,k,i);b=H[a+36>>2]}d=(j>>>3&536870908)+b|0;c=H[d>>2];b=1<>2]=b|c;Ua(a+8|0,j,e)}f=H[a+52>>2];if((f|0)==H[a+48>>2]){return 1}k=a+8|0;while(1){b:{c:{f=f-4|0;b=H[f>>2];if((b|0)==-1){break c}c=(b>>>0)/3|0;g=H[a+24>>2]+(c>>>3&268435452)|0;d=H[g>>2];c=1<>2]=c|d;h=H[a+4>>2];c=H[H[h+28>>2]+(b<<2)>>2];if((c|0)==-1){return 0}while(1){d=b;d:{e:{j=H[a+36>>2]+(c>>>3&536870908)|0;i=H[j>>2];e=1<>2]+(c<<2)>>2];g:{if((g|0)==-1){break g}b=g+1|0;b=(b>>>0)%3|0?b:g-2|0;if((b|0)==-1|H[H[h>>2]+(b>>>3&536870908)>>2]>>>b&1){break g}g=H[H[H[h+64>>2]+12>>2]+(b<<2)>>2];if((g|0)!=-1){break f}}H[j>>2]=e|i;Ua(k,c,d);h=H[a+4>>2];break e}H[j>>2]=e|i;Ua(k,c,d);h=H[a+4>>2];b=g+1|0;if((((b>>>0)%3|0?b:g-2|0)|0)==-1){break e}b=-1;h:{if((d|0)==-1){break h}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1|H[H[h>>2]+(c>>>3&536870908)>>2]>>>c&1){break h}b=H[H[H[h+64>>2]+12>>2]+(c<<2)>>2]}c=(b>>>0)/3|0;d=1<>2];e=c>>>5|0;j=H[f+(e<<2)>>2];break d}i:{j:{if((d|0)==-1){break j}c=-1;b=d+1|0;b=(b>>>0)%3|0?b:d-2|0;if(!((b|0)==-1|H[H[h>>2]+(b>>>3&536870908)>>2]>>>b&1)){c=H[H[H[h+64>>2]+12>>2]+(b<<2)>>2]}k:{l:{if((d>>>0)%3|0){f=d-1|0;break l}f=d+2|0;b=-1;if((f|0)==-1){break k}}b=-1;if(H[H[h>>2]+(f>>>3&536870908)>>2]>>>f&1){break k}b=H[H[H[h+64>>2]+12>>2]+(f<<2)>>2]}g=(b|0)==-1;i=g?-1:(b>>>0)/3|0;if((c|0)!=-1){f=H[a+24>>2];d=(c>>>0)/3|0;e=d>>>5|0;j=H[f+(e<<2)>>2];d=1<>2];e=i>>>5|0;j=H[f+(e<<2)>>2];if(!(d&j)){break d}}f=H[a+52>>2]-4|0;H[a+52>>2]=f;break b}if(g){b=c;break d}if(H[(i>>>3&536870908)+f>>2]>>>i&1){b=c;break d}h=H[a+52>>2];H[h-4>>2]=b;if(H[a+56>>2]!=(h|0)){H[h>>2]=c;f=h+4|0;break c}m:{i=H[a+48>>2];e=h-i|0;g=e>>2;d=g+1|0;if(d>>>0<1073741824){b=e>>>1|0;e=e>>>0>=2147483644?1073741823:b>>>0>d>>>0?b:d;if(e){if(e>>>0>=1073741824){break m}d=pa(e<<2)}else{d=0}b=d+(g<<2)|0;H[b>>2]=c;f=b+4|0;if((h|0)!=(i|0)){while(1){b=b-4|0;h=h-4|0;H[b>>2]=H[h>>2];if((h|0)!=(i|0)){continue}break}}H[a+56>>2]=d+(e<<2);H[a+52>>2]=f;H[a+48>>2]=b;if(!i){break b}oa(i);f=H[a+52>>2];break b}sa();v()}wa();v()}H[(e<<2)+f>>2]=d|j;c=H[H[h+28>>2]+(b<<2)>>2];if((c|0)!=-1){continue}break}return 0}H[a+52>>2]=f}if(H[a+48>>2]!=(f|0)){continue}break}}return 1}function Lj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;H[a+8>>2]=e;m=a+32|0;h=H[m>>2];f=H[a+36>>2]-h>>2;a:{if(f>>>0>>0){ya(m,e-f|0);d=H[a+8>>2];break a}d=e;if(d>>>0>=f>>>0){break a}H[a+36>>2]=h+(e<<2);d=e}s=H[a+52>>2];n=H[a+48>>2];f=0;h=e>>>0>1073741823?-1:e<<2;l=ra(pa(h),0,h);b:{if((d|0)<=0){break b}g=H[a+32>>2];while(1){d=f<<2;h=H[d+l>>2];i=H[a+16>>2];c:{if((h|0)>(i|0)){H[d+g>>2]=i;break c}d=d+g|0;i=H[a+12>>2];if((i|0)>(h|0)){H[d>>2]=i;break c}H[d>>2]=h}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}if((d|0)<=0){break b}f=0;while(1){h=f<<2;d=h+c|0;h=H[b+h>>2]+H[g+h>>2]|0;H[d>>2]=h;d:{if((h|0)>H[a+16>>2]){h=h-H[a+20>>2]|0}else{if((h|0)>=H[a+12>>2]){break d}h=h+H[a+20>>2]|0}H[d>>2]=h}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}f=H[a+56>>2];q=H[f>>2];f=H[f+4>>2]-q|0;if((f|0)>=5){o=f>>>2|0;t=o>>>0<=2?2:o;u=e&-2;w=e&1;h=1;while(1){e:{f:{if((h|0)!=(o|0)){r=N(e,h);f=H[(h<<2)+q>>2];if((f|0)==-1|H[H[n>>2]+(f>>>3&536870908)>>2]>>>f&1){break f}f=H[H[H[n+64>>2]+12>>2]+(f<<2)>>2];if((f|0)==-1){break f}i=H[s>>2];g=H[n+28>>2];k=H[i+(H[g+(f<<2)>>2]<<2)>>2];if((k|0)>=(h|0)){break f}j=f+1|0;j=H[i+(H[g+(((j>>>0)%3|0?j:f-2|0)<<2)>>2]<<2)>>2];if((j|0)>=(h|0)){break f}f=H[i+(H[g+(f+((f>>>0)%3|0?-1:2)<<2)>>2]<<2)>>2];if((f|0)>=(h|0)){break f}g:{if((e|0)<=0){break g}g=N(e,f);i=N(e,j);k=N(e,k);f=0;p=0;if((e|0)!=1){while(1){H[(f<<2)+l>>2]=(H[(f+g<<2)+c>>2]+H[(f+i<<2)+c>>2]|0)-H[(f+k<<2)+c>>2];j=f|1;H[(j<<2)+l>>2]=(H[(g+j<<2)+c>>2]+H[(i+j<<2)+c>>2]|0)-H[(k+j<<2)+c>>2];f=f+2|0;p=p+2|0;if((u|0)!=(p|0)){continue}break}}if(!w){break g}H[(f<<2)+l>>2]=(H[(f+g<<2)+c>>2]+H[(f+i<<2)+c>>2]|0)-H[(f+k<<2)+c>>2]}if((d|0)<=0){break e}i=H[m>>2];f=0;while(1){d=f<<2;g=H[d+l>>2];k=H[a+16>>2];h:{if((g|0)>(k|0)){H[d+i>>2]=k;break h}d=d+i|0;k=H[a+12>>2];if((k|0)>(g|0)){H[d>>2]=k;break h}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;j=b+d|0;while(1){g=f<<2;d=g+k|0;g=H[g+j>>2]+H[g+i>>2]|0;H[d>>2]=g;i:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break i}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}break e}Ca();v()}if((d|0)<=0){break e}k=(N(h-1|0,e)<<2)+c|0;i=H[m>>2];f=0;while(1){d=f<<2;g=H[d+k>>2];j=H[a+16>>2];j:{if((g|0)>(j|0)){H[d+i>>2]=j;break j}d=d+i|0;j=H[a+12>>2];if((j|0)>(g|0)){H[d>>2]=j;break j}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;j=b+d|0;while(1){g=f<<2;d=g+k|0;g=H[g+j>>2]+H[g+i>>2]|0;H[d>>2]=g;k:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break k}g=g+H[a+20>>2]|0}H[d>>2]=g}d=H[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}h=h+1|0;if((t|0)!=(h|0)){continue}break}}oa(l);return 1}function Gb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=O(0),k=0,l=0,m=O(0);i=H[c>>2];a:{b:{f=H[b+4>>2];if(!f){break b}g=Uj(f);c:{if(g>>>0>=2){e=i;if(f>>>0<=e>>>0){e=(i>>>0)%(f>>>0)|0}c=H[H[b>>2]+(e<<2)>>2];if(!c){break b}if(g>>>0<=1){break c}while(1){c=H[c>>2];if(!c){break b}g=H[c+4>>2];if((g|0)!=(i|0)){if(f>>>0<=g>>>0){g=(g>>>0)%(f>>>0)|0}if((e|0)!=(g|0)){break b}}if(H[c+8>>2]!=(i|0)){continue}break}b=0;break a}e=f-1&i;c=H[H[b>>2]+(e<<2)>>2];if(!c){break b}}h=f-1|0;while(1){c=H[c>>2];if(!c){break b}g=H[c+4>>2];if((g|0)!=(i|0)&(g&h)!=(e|0)){break b}if(H[c+8>>2]!=(i|0)){continue}break}b=0;break a}c=pa(16);d=H[H[d>>2]>>2];H[c+12>>2]=0;H[c+8>>2]=d;H[c+4>>2]=i;H[c>>2]=0;m=O(H[b+12>>2]+1>>>0);j=L[b+16>>2];d:{if(m>O(j*O(f>>>0))?0:f){break d}e=2;d=(f-1&f)!=0|f>>>0<3|f<<1;j=O(U(O(m/j)));e:{if(j=O(0)){g=~~j>>>0;break e}g=0}d=d>>>0>g>>>0?d:g;f:{if((d|0)==1){break f}if(!(d&d-1)){e=d;break f}e=Kd(d);f=H[b+4>>2]}g:{if(e>>>0<=f>>>0){if(e>>>0>=f>>>0){break g}g=f>>>0<3;j=O(U(O(O(K[b+12>>2])/L[b+16>>2])));h:{if(j=O(0)){d=~~j>>>0;break h}d=0}i:{j:{if(g){break j}if(Uj(f)>>>0>1){break j}d=d>>>0<2?d:1<<32-Q(d-1|0);break i}d=Kd(d)}e=d>>>0>>0?e:d;if(f>>>0<=e>>>0){break g}}f=0;g=0;h=e;k:{l:{m:{n:{if(e){if(h>>>0>=1073741824){break n}d=pa(h<<2);e=H[b>>2];H[b>>2]=d;if(e){oa(e)}H[b+4>>2]=h;d=0;if(h>>>0>=4){e=h&-4;while(1){k=d<<2;H[k+H[b>>2]>>2]=0;H[H[b>>2]+(k|4)>>2]=0;H[H[b>>2]+(k|8)>>2]=0;H[H[b>>2]+(k|12)>>2]=0;d=d+4|0;g=g+4|0;if((e|0)!=(g|0)){continue}break}}e=h&3;if(e){while(1){H[H[b>>2]+(d<<2)>>2]=0;d=d+1|0;f=f+1|0;if((e|0)!=(f|0)){continue}break}}e=H[b+8>>2];if(!e){break k}d=b+8|0;f=H[e+4>>2];g=Uj(h);if(g>>>0<2){break m}f=f>>>0>=h>>>0?(f>>>0)%(h>>>0)|0:f;H[H[b>>2]+(f<<2)>>2]=d;d=H[e>>2];if(!d){break k}if(g>>>0<=1){break l}while(1){g=H[d+4>>2];if(h>>>0<=g>>>0){g=(g>>>0)%(h>>>0)|0}o:{if((f|0)==(g|0)){e=d;break o}l=g<<2;k=l+H[b>>2]|0;if(!H[k>>2]){H[k>>2]=e;e=d;f=g;break o}H[e>>2]=H[d>>2];H[d>>2]=H[H[l+H[b>>2]>>2]>>2];H[H[l+H[b>>2]>>2]>>2]=d}d=H[e>>2];if(d){continue}break}break k}d=H[b>>2];H[b>>2]=0;if(d){oa(d)}H[b+4>>2]=0;break k}wa();v()}f=h-1&f;H[H[b>>2]+(f<<2)>>2]=d;d=H[e>>2];if(!d){break k}}k=h-1|0;while(1){g=k&H[d+4>>2];p:{if((g|0)==(f|0)){e=d;break p}l=g<<2;h=l+H[b>>2]|0;if(H[h>>2]){H[e>>2]=H[d>>2];H[d>>2]=H[H[l+H[b>>2]>>2]>>2];H[H[l+H[b>>2]>>2]>>2]=d;break p}H[h>>2]=e;e=d;f=g}d=H[e>>2];if(d){continue}break}}}f=H[b+4>>2];d=f-1|0;if(!(d&f)){e=d&i;break d}if(f>>>0>i>>>0){e=i;break d}e=(i>>>0)%(f>>>0)|0}e=H[b>>2]+(e<<2)|0;d=H[e>>2];q:{r:{if(!d){d=b+8|0;H[c>>2]=H[d>>2];H[b+8>>2]=c;H[e>>2]=d;d=H[c>>2];if(!d){break q}d=H[d+4>>2];e=f-1|0;s:{if(!(e&f)){d=d&e;break s}if(d>>>0>>0){break s}d=(d>>>0)%(f>>>0)|0}d=H[b>>2]+(d<<2)|0;break r}H[c>>2]=H[d>>2]}H[d>>2]=c}H[b+12>>2]=H[b+12>>2]+1;b=1}F[a+4|0]=b;H[a>>2]=c}function Oe(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;f=ca-80|0;ca=f;e=H[c+36>>2];H[f+72>>2]=H[c+32>>2];H[f+76>>2]=e;g=H[c+28>>2];e=f- -64|0;H[e>>2]=H[c+24>>2];H[e+4>>2]=g;e=H[c+20>>2];H[f+56>>2]=H[c+16>>2];H[f+60>>2]=e;e=H[c+12>>2];H[f+48>>2]=H[c+8>>2];H[f+52>>2]=e;e=H[c+4>>2];H[f+40>>2]=H[c>>2];H[f+44>>2]=e;nc(a,f+40|0,f+24|0);a:{if(H[a>>2]){break a}if(F[a+15|0]<0){oa(H[a+4>>2])}if(I[f+31|0]!=1){b=pa(32);F[b+20|0]=0;c=I[1448]|I[1449]<<8|(I[1450]<<16|I[1451]<<24);F[b+16|0]=c;F[b+17|0]=c>>>8;F[b+18|0]=c>>>16;F[b+19|0]=c>>>24;c=I[1444]|I[1445]<<8|(I[1446]<<16|I[1447]<<24);d=I[1440]|I[1441]<<8|(I[1442]<<16|I[1443]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1436]|I[1437]<<8|(I[1438]<<16|I[1439]<<24);d=I[1432]|I[1433]<<8|(I[1434]<<16|I[1435]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;H[a>>2]=-1;za(a+4|0,b,20);oa(b);break a}i=ca-16|0;ca=i;b:{c:{switch(I[f+32|0]){case 0:e=Ke(pa(48));H[e>>2]=13112;H[f+8>>2]=0;H[f+12>>2]=0;H[f>>2]=0;H[f+4>>2]=0;H[f+16>>2]=e;break b;case 1:e=Ke(pa(52));H[e+48>>2]=0;H[e>>2]=11276;H[f+8>>2]=0;H[f+12>>2]=0;H[f>>2]=0;H[f+4>>2]=0;H[f+16>>2]=e;break b;default:break c}}g=pa(32);F[g+28|0]=0;e=I[1550]|I[1551]<<8|(I[1552]<<16|I[1553]<<24);F[g+24|0]=e;F[g+25|0]=e>>>8;F[g+26|0]=e>>>16;F[g+27|0]=e>>>24;e=I[1546]|I[1547]<<8|(I[1548]<<16|I[1549]<<24);h=I[1542]|I[1543]<<8|(I[1544]<<16|I[1545]<<24);F[g+16|0]=h;F[g+17|0]=h>>>8;F[g+18|0]=h>>>16;F[g+19|0]=h>>>24;F[g+20|0]=e;F[g+21|0]=e>>>8;F[g+22|0]=e>>>16;F[g+23|0]=e>>>24;e=I[1538]|I[1539]<<8|(I[1540]<<16|I[1541]<<24);h=I[1534]|I[1535]<<8|(I[1536]<<16|I[1537]<<24);F[g+8|0]=h;F[g+9|0]=h>>>8;F[g+10|0]=h>>>16;F[g+11|0]=h>>>24;F[g+12|0]=e;F[g+13|0]=e>>>8;F[g+14|0]=e>>>16;F[g+15|0]=e>>>24;e=I[1530]|I[1531]<<8|(I[1532]<<16|I[1533]<<24);h=I[1526]|I[1527]<<8|(I[1528]<<16|I[1529]<<24);F[g|0]=h;F[g+1|0]=h>>>8;F[g+2|0]=h>>>16;F[g+3|0]=h>>>24;F[g+4|0]=e;F[g+5|0]=e>>>8;F[g+6|0]=e>>>16;F[g+7|0]=e>>>24;H[i>>2]=-1;e=i|4;za(e,g,28);j=F[i+15|0];H[f>>2]=H[i>>2];h=f+4|0;d:{if((j|0)>=0){j=H[e+4>>2];H[h>>2]=H[e>>2];H[h+4>>2]=j;H[h+8>>2]=H[e+8>>2];H[f+16>>2]=0;break d}za(h,H[i+4>>2],H[i+8>>2]);e=F[i+15|0];H[f+16>>2]=0;if((e|0)>=0){break d}oa(H[i+4>>2])}oa(g)}ca=i+16|0;e=H[f>>2];e:{if(e){H[a>>2]=e;a=a+4|0;if(F[f+15|0]>=0){b=f|4;c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c;H[a+8>>2]=H[b+8>>2];break e}za(a,H[f+4>>2],H[f+8>>2]);break e}e=H[f+16>>2];H[f+16>>2]=0;H[e+44>>2]=d;te(a,e,b,c,d);if(!H[a>>2]){if(F[a+15|0]<0){oa(H[a+4>>2])}H[a>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0}ea[H[H[e>>2]+4>>2]](e)}a=H[f+16>>2];H[f+16>>2]=0;if(a){ea[H[H[a>>2]+4>>2]](a)}if(F[f+15|0]>=0){break a}oa(H[f+4>>2])}ca=f+80|0}function Gc(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;j=N(b,12)+a|0;H[j+12>>2]=H[j+8>>2];m=(c|0)==-1?-1:(c>>>0)/3|0;d=1;k=c;a:{b:{c:{while(1){d:{l=d;if(!d){if((k|0)==-1){break d}if((de(a,((k>>>0)%3|0?-1:2)+k|0)|0)==-1){break a}c=k+1|0;d=(c>>>0)%3|0?c:k-2|0;if((d|0)==-1){break a}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1){break a}d=H[H[H[a+4>>2]+12>>2]+(c<<2)>>2];if((d|0)==-1){break a}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1){break a}m=(c>>>0)/3|0}e:{d=H[a+56>>2]+(m>>>3&536870908)|0;h=H[d>>2];e=1<>2]=e|h;d=H[j+12>>2];f:{if((d|0)!=H[j+16>>2]){H[d>>2]=m;H[j+12>>2]=d+4;break f}n=H[j+8>>2];h=d-n|0;e=h>>2;i=e+1|0;if(i>>>0>=1073741824){break c}g=h>>>1|0;i=h>>>0>=2147483644?1073741823:i>>>0>>0?g:i;if(i){if(i>>>0>=1073741824){break b}g=pa(i<<2)}else{g=0}h=g+(e<<2)|0;H[h>>2]=m;e=h+4|0;if((d|0)!=(n|0)){while(1){h=h-4|0;d=d-4|0;H[h>>2]=H[d>>2];if((d|0)!=(n|0)){continue}break}}H[j+8>>2]=h;H[j+12>>2]=e;H[j+16>>2]=g+(i<<2);if(!n){break f}oa(n)}g=f+1|0;g:{h:{i:{if(!f){break i}if(g&1){if((c|0)==-1){c=-1;break g}d=c+1|0;c=(d>>>0)%3|0?d:c-2|0;break i}k=l?k:c;if((c|0)==-1){c=-1;break g}if((c>>>0)%3|0){d=c-1|0;break h}c=c+2|0}d=c;c=-1;if((d|0)==-1){break g}}c=H[H[H[a+4>>2]+12>>2]+(d<<2)>>2];h=-1;f=-1;e=d+1|0;e=(e>>>0)%3|0?e:d-2|0;if((e|0)>=0){f=(e>>>0)/3|0;f=H[(H[H[a>>2]+96>>2]+N(f,12)|0)+(e-N(f,3)<<2)>>2]}j:{if((c|0)==-1){break j}i=((c>>>0)%3|0?-1:2)+c|0;if((i|0)<0){break j}e=(i>>>0)/3|0;h=H[(H[H[a>>2]+96>>2]+N(e,12)|0)+(i-N(e,3)<<2)>>2]}if((f|0)!=(h|0)){c=-1;break g}k:{l:{f=((d>>>0)%3|0?-1:2)+d|0;if((f|0)>=0){d=(f>>>0)/3|0;if((c|0)!=-1){break l}c=-1;break g}d=-1;if((c|0)!=-1){break k}c=-1;break g}d=H[(H[H[a>>2]+96>>2]+N(d,12)|0)+(f-N(d,3)<<2)>>2]}f=c+1|0;e=(f>>>0)%3|0?f:c-2|0;if((e|0)>=0){f=(e>>>0)/3|0;f=H[(H[H[a>>2]+96>>2]+N(f,12)|0)+(e-N(f,3)<<2)>>2]}else{f=-1}if((f|0)!=(d|0)){c=-1;break g}f=g;m=(c>>>0)/3|0;d=H[a+56>>2]+(m>>>3&268435452)|0;h=H[d>>2];e=1<>2]-4|0;g=H[l>>2];d=H[a+56>>2]+(g>>>3&536870908)|0;c=H[d>>2];o=d,p=Vj(g)&c,H[o>>2]=p;H[j+12>>2]=l;break a}d=0;if(l){continue}break a}break}k=-1;de(a,-1);break a}sa();v()}wa();v()}H[((b<<2)+a|0)+44>>2]=k;b=H[j+12>>2];i=H[j+8>>2];m:{if((b|0)==(i|0)){break m}c=b-i|0;b=c>>2;b=b>>>0<=1?1:b;k=b&1;e=H[a+56>>2];d=0;if(c>>>0>=8){f=b&-2;c=0;while(1){l=d<<2;g=H[l+i>>2];b=e+(g>>>3&536870908)|0;a=H[b>>2];o=b,p=Vj(g)&a,H[o>>2]=p;g=H[i+(l|4)>>2];b=e+(g>>>3&536870908)|0;a=H[b>>2];o=b,p=Vj(g)&a,H[o>>2]=p;d=d+2|0;c=c+2|0;if((f|0)!=(c|0)){continue}break}}if(!k){break m}c=H[i+(d<<2)>>2];b=e+(c>>>3&536870908)|0;a=H[b>>2];o=b,p=Vj(c)&a,H[o>>2]=p}}function Gj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=ca-32|0;ca=h;a:{if(J[b+38>>1]<=513){c=H[b+20>>2];f=H[b+12>>2];d=H[b+16>>2];if((c|0)>=(f|0)&d>>>0>=K[b+8>>2]|(c|0)>(f|0)){break a}f=I[d+H[b>>2]|0];d=d+1|0;c=d?c:c+1|0;H[b+16>>2]=d;H[b+20>>2]=c;if(f){break a}}b:{if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[H[a+48>>2]+64>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}c:{if(d){Wa(a+60|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[H[a+48>>2]+64>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}if(d){e=0;Wa(a+72|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[H[a+48>>2]+64>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}if(d){e=0;Wa(a+84|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[H[a+48>>2]+64>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}if(d){e=0;Wa(a+96|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}e=0;c=H[b+8>>2];f=H[b+12>>2];d=c;c=H[b+20>>2];i=c;g=H[b+16>>2];j=g+4|0;c=j>>>0<4?c+1|0:c;if(d>>>0>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break a}m=H[b>>2];k=m+g|0;l=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);H[b+16>>2]=j;H[b+20>>2]=c;k=d;d=f;c=i;f=g+8|0;c=f>>>0<8?c+1|0:c;if(f>>>0>k>>>0&(c|0)>=(d|0)|(c|0)>(d|0)){break a}d=j+m|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=c;if((d|0)<(l|0)){break a}H[a+16>>2]=d;H[a+12>>2]=l;c=(d>>31)-((l>>31)+(d>>>0>>0)|0)|0;b=d-l|0;if(!c&b>>>0>2147483646|c){break a}e=1;b=b+1|0;H[a+20>>2]=b;c=b>>>1|0;H[a+24>>2]=c;H[a+28>>2]=0-c;if(b&1){break a}H[a+24>>2]=c-1;break a}}e=0}ca=h+32|0;return e|0}function pj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=ca-32|0;ca=h;a:{if(J[b+38>>1]<=513){c=H[b+20>>2];f=H[b+12>>2];d=H[b+16>>2];if((c|0)>=(f|0)&d>>>0>=K[b+8>>2]|(c|0)>(f|0)){break a}f=I[d+H[b>>2]|0];d=d+1|0;c=d?c:c+1|0;H[b+16>>2]=d;H[b+20>>2]=c;if(f){break a}}b:{if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[a+48>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}c:{if(d){Wa(a+60|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[a+48>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}if(d){e=0;Wa(a+72|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[a+48>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}if(d){e=0;Wa(a+84|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Xa(1,h+28|0,b)){break b}d=H[h+28>>2];c=H[a+48>>2];if(d>>>0>H[c+4>>2]-H[c>>2]>>2>>>0){break b}if(d){e=0;Wa(a+96|0,d);c=h+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;if(!ta(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|H[g>>2]}else{i=H[g>>2]&(f^-1)}H[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}e=0;c=H[b+8>>2];f=H[b+12>>2];d=c;c=H[b+20>>2];i=c;g=H[b+16>>2];j=g+4|0;c=j>>>0<4?c+1|0:c;if(d>>>0>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break a}m=H[b>>2];k=m+g|0;l=I[k|0]|I[k+1|0]<<8|(I[k+2|0]<<16|I[k+3|0]<<24);H[b+16>>2]=j;H[b+20>>2]=c;k=d;d=f;c=i;f=g+8|0;c=f>>>0<8?c+1|0:c;if(f>>>0>k>>>0&(c|0)>=(d|0)|(c|0)>(d|0)){break a}d=j+m|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=c;if((d|0)<(l|0)){break a}H[a+16>>2]=d;H[a+12>>2]=l;c=(d>>31)-((l>>31)+(d>>>0>>0)|0)|0;b=d-l|0;if(!c&b>>>0>2147483646|c){break a}e=1;b=b+1|0;H[a+20>>2]=b;c=b>>>1|0;H[a+24>>2]=c;H[a+28>>2]=0-c;if(b&1){break a}H[a+24>>2]=c-1;break a}}e=0}ca=h+32|0;return e|0}function xe(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;if((b|0)==-1){return 1}g=(b>>>0)/3|0;if(!(H[H[a+24>>2]+(g>>>3&268435452)>>2]>>>g&1)){f=H[a+48>>2];H[a+52>>2]=f;a:{if((f|0)!=H[a+56>>2]){H[f>>2]=b;H[a+52>>2]=f+4;break a}d=pa(4);H[d>>2]=b;c=d+4|0;H[a+56>>2]=c;H[a+52>>2]=c;H[a+48>>2]=d;if(!f){break a}oa(f)}e=-1;d=H[a+4>>2];c=b+1|0;i=(c>>>0)%3|0?c:b-2|0;if((i|0)!=-1){e=H[H[d>>2]+(i<<2)>>2]}b:{h=b-N(g,3)|0;if(h){c=b-1|0;break b}c=b+2|0;if((c|0)!=-1){break b}return 0}if((e|0)==-1){return 0}j=H[H[d>>2]+(c<<2)>>2];if((j|0)==-1){return 0}c=H[a+36>>2];f=c+(e>>>3&536870908)|0;g=H[f>>2];d=1<>2]=d|g;Ua(a+8|0,e,i);c=H[a+36>>2]}g=(j>>>3&536870908)+c|0;d=H[g>>2];c=1<>2]=c|d;Ua(a+8|0,j,(h?-1:2)+b|0)}c=H[a+52>>2];if((c|0)==H[a+48>>2]){return 1}j=a+8|0;while(1){c:{d:{c=c-4|0;b=H[c>>2];if((b|0)==-1){break d}d=(b>>>0)/3|0;f=H[a+24>>2]+(d>>>3&268435452)|0;g=H[f>>2];d=1<>2]=d|g;while(1){i=H[a+4>>2];e=H[H[i>>2]+(b<<2)>>2];if((e|0)==-1){return 0}e:{f:{h=H[a+36>>2]+(e>>>3&536870908)|0;f=H[h>>2];g=1<>2]+(e<<2)>>2];h:{if((d|0)==-1){break h}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1){break h}d=H[H[i+12>>2]+(c<<2)>>2];if((d|0)!=-1){break g}}H[h>>2]=f|g;Ua(j,e,b);break f}H[h>>2]=f|g;Ua(j,e,b);c=d+1|0;if((((c>>>0)%3|0?c:d-2|0)|0)==-1){break f}c=b-2|0;d=b+1|0;b=-1;c=(d>>>0)%3|0?d:c;if((c|0)!=-1){b=H[H[H[a+4>>2]+12>>2]+(c<<2)>>2]}c=(b>>>0)/3|0;d=1<>2];f=c>>>5|0;i=H[e+(f<<2)>>2];break e}c=-1;g=H[a+4>>2];d=b+1|0;d=(d>>>0)%3|0?d:b-2|0;if((d|0)!=-1){c=H[H[g+12>>2]+(d<<2)>>2]}i:{j:{if((b>>>0)%3|0){e=b-1|0;break j}e=b+2|0;b=-1;if((e|0)==-1){break i}}b=H[H[g+12>>2]+(e<<2)>>2]}g=(b|0)==-1;h=g?-1:(b>>>0)/3|0;k:{if((c|0)!=-1){e=H[a+24>>2];d=(c>>>0)/3|0;f=d>>>5|0;i=H[e+(f<<2)>>2];d=1<>2];f=h>>>5|0;i=H[e+(f<<2)>>2];if(!(d&i)){break e}}c=H[a+52>>2]-4|0;H[a+52>>2]=c;break c}if(g){b=c;break e}if(H[(h>>>3&536870908)+e>>2]>>>h&1){b=c;break e}e=H[a+52>>2];H[e-4>>2]=b;if(H[a+56>>2]!=(e|0)){H[e>>2]=c;c=e+4|0;break d}l:{h=H[a+48>>2];f=e-h|0;g=f>>2;d=g+1|0;if(d>>>0<1073741824){b=f>>>1|0;f=f>>>0>=2147483644?1073741823:b>>>0>d>>>0?b:d;if(f){if(f>>>0>=1073741824){break l}d=pa(f<<2)}else{d=0}b=d+(g<<2)|0;H[b>>2]=c;c=b+4|0;if((e|0)!=(h|0)){while(1){b=b-4|0;e=e-4|0;H[b>>2]=H[e>>2];if((e|0)!=(h|0)){continue}break}}H[a+56>>2]=d+(f<<2);H[a+52>>2]=c;H[a+48>>2]=b;if(!h){break c}oa(h);c=H[a+52>>2];break c}sa();v()}wa();v()}H[(f<<2)+e>>2]=d|i;if((b|0)!=-1){continue}break}return 0}H[a+52>>2]=c}if(H[a+48>>2]!=(c|0)){continue}break}}return 1}function uj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;g=ca-32|0;ca=g;H[a+68>>2]=f;d=H[a+56>>2];e=H[d>>2];d=H[d+4>>2];H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+60|0;d=d>>>2|0;n=d>>>0<=1?1:d;o=a+112|0;while(1){e=H[a+56>>2];d=H[e>>2];if(H[e+4>>2]-d>>2>>>0<=j>>>0){break a}Nb(m,H[d+(j<<2)>>2],g+16|0);i=H[g+20>>2];d=i>>31;h=H[g+16>>2];e=h>>31;f=(d^i)-d+((e^h)-e)|0;k=H[g+24>>2];d=k>>31;e=(d^k)-d|0;d=0;l=e;e=e+f|0;d=l>>>0>e>>>0?1:d;b:{if(!(d|e)){H[g+16>>2]=H[a+108>>2];break b}f=H[a+108>>2];l=f>>31;h=Sj(Rj(f,l,h,h>>31),da,e,d);H[g+16>>2]=h;d=Sj(Rj(f,l,i,i>>31),da,e,d);H[g+20>>2]=d;e=d;d=d>>31;e=(e^d)-d|0;d=h>>31;d=e+((d^h)-d|0)|0;if((k|0)>=0){H[g+24>>2]=f-d;break b}H[g+24>>2]=d-f}d=Ba(o);f=H[g+16>>2];c:{if(d){H[g+24>>2]=0-H[g+24>>2];e=0-H[g+20>>2]|0;H[g+20>>2]=e;f=0-f|0;H[g+16>>2]=f;break c}e=H[g+20>>2]}d:{if((f|0)>=0){f=H[a+108>>2];d=f+H[g+24>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=H[g+24>>2];f=d>>31;f=(d^f)-f|0;break e}d=H[g+24>>2];f=d>>31;f=H[a+100>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=H[a+100>>2]+(d-(d^e)|0)|0}e=H[a+100>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}i=H[a+108>>2];if((i|0)>=(d|0)){break g}d=(i<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}i=H[a+108>>2];if((i|0)<=(d|0)){break h}d=(i<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=H[a+108>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=H[a+108>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}H[g+12>>2]=d;H[g+8>>2]=f;j:{if(H[a+8>>2]<=0){break j}i=H[a+32>>2];f=0;while(1){d=f<<2;e=H[d+(g+8|0)>>2];h=H[a+16>>2];k:{if((e|0)>(h|0)){H[d+i>>2]=h;break k}d=d+i|0;h=H[a+12>>2];if((h|0)>(e|0)){H[d>>2]=h;break k}H[d>>2]=e}f=f+1|0;e=H[a+8>>2];if((f|0)<(e|0)){continue}break}d=0;if((e|0)<=0){break j}e=j<<3;h=e+c|0;k=b+e|0;while(1){f=d<<2;e=f+h|0;f=H[f+k>>2]+H[f+i>>2]|0;H[e>>2]=f;l:{if((f|0)>H[a+16>>2]){f=f-H[a+20>>2]|0}else{if((f|0)>=H[a+12>>2]){break l}f=f+H[a+20>>2]|0}H[e>>2]=f}d=d+1|0;if((d|0)>2]){continue}break}}j=j+1|0;if((n|0)!=(j|0)){continue}break}}ca=g+32|0;return 1}Ca();v()}function dj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;g=ca-32|0;ca=g;H[a+68>>2]=f;d=H[a+56>>2];e=H[d>>2];d=H[d+4>>2];H[g+24>>2]=0;H[g+16>>2]=0;H[g+20>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+60|0;d=d>>>2|0;n=d>>>0<=1?1:d;o=a+112|0;while(1){e=H[a+56>>2];d=H[e>>2];if(H[e+4>>2]-d>>2>>>0<=j>>>0){break a}Lb(m,H[d+(j<<2)>>2],g+16|0);i=H[g+20>>2];d=i>>31;h=H[g+16>>2];e=h>>31;f=(d^i)-d+((e^h)-e)|0;k=H[g+24>>2];d=k>>31;e=(d^k)-d|0;d=0;l=e;e=e+f|0;d=l>>>0>e>>>0?1:d;b:{if(!(d|e)){H[g+16>>2]=H[a+108>>2];break b}f=H[a+108>>2];l=f>>31;h=Sj(Rj(f,l,h,h>>31),da,e,d);H[g+16>>2]=h;d=Sj(Rj(f,l,i,i>>31),da,e,d);H[g+20>>2]=d;e=d;d=d>>31;e=(e^d)-d|0;d=h>>31;d=e+((d^h)-d|0)|0;if((k|0)>=0){H[g+24>>2]=f-d;break b}H[g+24>>2]=d-f}d=Ba(o);f=H[g+16>>2];c:{if(d){H[g+24>>2]=0-H[g+24>>2];e=0-H[g+20>>2]|0;H[g+20>>2]=e;f=0-f|0;H[g+16>>2]=f;break c}e=H[g+20>>2]}d:{if((f|0)>=0){f=H[a+108>>2];d=f+H[g+24>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=H[g+24>>2];f=d>>31;f=(d^f)-f|0;break e}d=H[g+24>>2];f=d>>31;f=H[a+100>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=H[a+100>>2]+(d-(d^e)|0)|0}e=H[a+100>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}i=H[a+108>>2];if((i|0)>=(d|0)){break g}d=(i<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}i=H[a+108>>2];if((i|0)<=(d|0)){break h}d=(i<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=H[a+108>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=H[a+108>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}H[g+12>>2]=d;H[g+8>>2]=f;j:{if(H[a+8>>2]<=0){break j}i=H[a+32>>2];f=0;while(1){d=f<<2;e=H[d+(g+8|0)>>2];h=H[a+16>>2];k:{if((e|0)>(h|0)){H[d+i>>2]=h;break k}d=d+i|0;h=H[a+12>>2];if((h|0)>(e|0)){H[d>>2]=h;break k}H[d>>2]=e}f=f+1|0;e=H[a+8>>2];if((f|0)<(e|0)){continue}break}d=0;if((e|0)<=0){break j}e=j<<3;h=e+c|0;k=b+e|0;while(1){f=d<<2;e=f+h|0;f=H[f+k>>2]+H[f+i>>2]|0;H[e>>2]=f;l:{if((f|0)>H[a+16>>2]){f=f-H[a+20>>2]|0}else{if((f|0)>=H[a+12>>2]){break l}f=f+H[a+20>>2]|0}H[e>>2]=f}d=d+1|0;if((d|0)>2]){continue}break}}j=j+1|0;if((n|0)!=(j|0)){continue}break}}ca=g+32|0;return 1}Ca();v()}function ke(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;h=ca-80|0;ca=h;a:{b:{if(I[H[a+28>>2]+36|0]<=1){d=H[b+20>>2];f=H[b+16>>2];c=f+4|0;d=c>>>0<4?d+1|0:d;g=H[b+12>>2];if(K[b+8>>2]>>0&(g|0)<=(d|0)|(d|0)>(g|0)){break a}f=f+H[b>>2]|0;j=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=c;H[b+20>>2]=d;break b}if(!Pc(1,h+76|0,b)){break a}j=H[h+76>>2]}if(!j){break a}d=H[b+8>>2];c=H[b+16>>2];d=Rj(d-c|0,H[b+12>>2]-(H[b+20>>2]+(c>>>0>d>>>0)|0)|0,5,0);c=da;if(d>>>0>>0&(c|0)<=0|(c|0)<0){break a}c=H[a+4>>2];d=H[a+8>>2]-c>>2;c:{if(d>>>0>>0){ya(a+4|0,j-d|0);break c}if(d>>>0<=j>>>0){break c}H[a+8>>2]=c+(j<<2)}p=a+16|0;l=H[a+32>>2];while(1){i=H[b+12>>2];c=i;d=H[b+20>>2];e=H[b+8>>2];f=H[b+16>>2];if((c|0)<=(d|0)&e>>>0<=f>>>0|(c|0)<(d|0)){e=0;break a}n=H[b>>2];q=I[n+f|0];c=d;g=f+1|0;c=g?c:c+1|0;H[b+16>>2]=g;H[b+20>>2]=c;if(e>>>0<=g>>>0&(c|0)>=(i|0)|(c|0)>(i|0)){e=0;break a}g=I[g+n|0];c=d;k=f+2|0;c=k>>>0<2?c+1|0:c;H[b+16>>2]=k;H[b+20>>2]=c;if(e>>>0<=k>>>0&(c|0)>=(i|0)|(c|0)>(i|0)){e=0;break a}k=I[k+n|0];c=d;m=f+3|0;c=m>>>0<3?c+1|0:c;H[b+16>>2]=m;H[b+20>>2]=c;if(e>>>0<=m>>>0&(c|0)>=(i|0)|(c|0)>(i|0)){e=0;break a}e=I[m+n|0];c=d;d=f+4|0;c=d>>>0<4?c+1|0:c;H[b+16>>2]=d;H[b+20>>2]=c;if(q>>>0>4){e=0;break a}if((g-12&255)>>>0<245){e=0;break a}if(!k){e=0;break a}m=Eb(h+8|0);i=(e|0)!=0;d=g-1|0;if(d>>>0<=10){c=H[(d<<2)+13584>>2]}else{c=-1}d=N(c,k);lc(m,q,k,g,i,d,d>>31);d:{d=J[H[a+28>>2]+36>>1];e:{if(((d<<8|d>>>8)&65535)>>>0<=258){c=H[b+20>>2];f=H[b+16>>2];d=f+2|0;c=d>>>0<2?c+1|0:c;e=H[b+12>>2];if(K[b+8>>2]>>0&(e|0)<=(c|0)|(c|0)>(e|0)){break d}f=f+H[b>>2]|0;e=I[f|0]|I[f+1|0]<<8;H[b+16>>2]=d;H[b+20>>2]=c;break e}if(!Pc(1,h+4|0,b)){break d}e=H[h+4>>2]}H[h+68>>2]=e;d=jc(pa(96),m);ea[H[H[l>>2]+8>>2]](l,H[l+12>>2]-H[l+8>>2]>>2,d);d=(H[l+12>>2]-H[l+8>>2]>>2)-1|0;f=d<<2;H[H[f+H[l+8>>2]>>2]+60>>2]=e;H[H[a+4>>2]+(o<<2)>>2]=d;e=H[a+16>>2];c=H[a+20>>2]-e>>2;f:{if((c|0)>(d|0)){break f}H[h>>2]=-1;d=d+1|0;if(d>>>0>c>>>0){Pa(p,d-c|0,h);e=H[p>>2];break f}if(c>>>0<=d>>>0){break f}H[a+20>>2]=(d<<2)+e}H[e+f>>2]=o;e=1;o=o+1|0;if((o|0)!=(j|0)){continue}break a}break}e=0}ca=h+80|0;return e|0}function nd(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;n=ea[H[H[a>>2]+44>>2]](a)|0;a:{if((n|0)<=0){break a}i=H[b+4>>2]-H[b>>2]>>2;e=ca+-64|0;ca=e;f=Eb(e);d=N(H[3400],n);lc(f,H[H[a+8>>2]+56>>2],n&255,5,0,d,d>>31);f=jc(pa(96),f);F[f+84|0]=1;H[f+72>>2]=H[f+68>>2];mb(f,i);H[f+60>>2]=H[H[a+8>>2]+60>>2];d=H[a+16>>2];H[a+16>>2]=f;if(d){Ga(d)}ca=e- -64|0;h=H[a+16>>2];if(!H[h+80>>2]){break a}j=H[H[h>>2]>>2];if(!j){break a}m=H[c+12>>2];e=m;d=H[c+20>>2];g=H[c+8>>2];k=H[c+16>>2];if((e|0)<=(d|0)&g>>>0<=k>>>0|(d|0)>(e|0)){break a}l=N(i,n);i=j+H[h+48>>2]|0;h=H[c>>2];j=I[h+k|0];e=k+1|0;f=e?d:d+1|0;H[c+16>>2]=e;H[c+20>>2]=f;b:{c:{if(j){if(kd(l,n,c,i)){break c}break a}if((f|0)>=(m|0)&e>>>0>=g>>>0|(f|0)>(m|0)){break a}g=I[e+h|0];f=k+2|0;d=f>>>0<2?d+1|0:d;H[c+16>>2]=f;H[c+20>>2]=d;d=H[H[a+16>>2]+64>>2];d=H[d+4>>2]-H[d>>2]|0;if((g|0)==H[3400]){e=l<<2;if(e>>>0>d>>>0){break a}g=H[c+8>>2];k=H[c+12>>2];j=H[c+20>>2];d=H[c+16>>2];f=e+d|0;j=f>>>0>>0?j+1|0:j;if(f>>>0>g>>>0&(j|0)>=(k|0)|(j|0)>(k|0)){break a}qa(i,d+H[c>>2]|0,e);f=H[c+20>>2];d=e+H[c+16>>2]|0;f=d>>>0>>0?f+1|0:f;H[c+16>>2]=d;H[c+20>>2]=f;break c}if(d>>>0>>0){break a}d=H[c+8>>2];f=H[c+16>>2];e=d-f|0;m=d>>>0>>0;d=H[c+20>>2];k=H[c+12>>2]-(m+d|0)|0;m=Rj(g,0,l,0)>>>0>e>>>0;e=da;if(m&(e|0)>=(k|0)|(e|0)>(k|0)){break a}e=1;if(!l){break b}h=0;while(1){k=H[c+8>>2];j=H[c+12>>2];e=f+g|0;d=e>>>0>>0?d+1|0:d;if(e>>>0>k>>>0&(d|0)>=(j|0)|(d|0)>(j|0)){return 0}qa(i+(h<<2)|0,H[c>>2]+f|0,g);d=H[c+20>>2];f=g+H[c+16>>2]|0;d=f>>>0>>0?d+1|0:d;H[c+16>>2]=f;H[c+20>>2]=d;h=h+1|0;if((l|0)!=(h|0)){continue}break}}e=1;if(!l){break b}d=H[a+20>>2];if(d){e=0;if(ea[H[H[d>>2]+32>>2]](d)|0){break b}}g=0;h=0;d:{if((l|0)<=0){break d}if((l|0)!=1){f=l&-2;while(1){e=g<<2;d=H[e+i>>2];H[e+i>>2]=0-(d&1)^d>>>1;d=e|4;e=H[d+i>>2];H[d+i>>2]=0-(e&1)^e>>>1;g=g+2|0;h=h+2|0;if((f|0)!=(h|0)){continue}break}}if(!(l&1)){break d}d=g<<2;f=H[d+i>>2];H[d+i>>2]=0-(f&1)^f>>>1}e=0}d=e;f=H[a+20>>2];e:{if(!f){break e}if(!(ea[H[H[f>>2]+40>>2]](f,c)|0)){break a}if(d){break e}a=H[a+20>>2];if(!(ea[H[H[a>>2]+44>>2]](a,i,i,l,n,H[b>>2])|0)){break a}}o=1}return o|0}function pb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=ca-32|0;ca=h;a:{b:{if(H[a+8>>2]<<5>>>0>=b>>>0){break b}if((b|0)<0){break a}b=(b-1>>>5|0)+1|0;c=pa(b<<2);H[h+24>>2]=b;H[h+20>>2]=0;H[h+16>>2]=c;b=H[a>>2];H[h+12>>2]=0;H[h+8>>2]=b;c=H[a+4>>2];H[h+4>>2]=c&31;H[h>>2]=b+(c>>>3&536870908);e=ca-32|0;ca=e;i=H[h+4>>2];g=H[h+12>>2];j=H[h>>2];d=H[h+8>>2];b=(i-g|0)+(j-d<<3)|0;f=H[h+20>>2];c=b+f|0;H[h+20>>2]=c;if(!((c-1^f-1)>>>0<32?f:0)){H[H[h+16>>2]+((c>>>0>=33?c-1>>>5|0:0)<<2)>>2]=0}c=H[h+16>>2]+(f>>>3&536870908)|0;f=f&31;c:{if((f|0)==(g|0)){if((b|0)<=0){break c}if(g){i=32-g|0;f=(b|0)<(i|0)?b:i;i=-1<>>i-f;H[c>>2]=H[c>>2]&(i^-1)|i&H[d>>2];d=d+4|0;c=(g+f>>>3&536870908)+c|0;b=b-f|0}g=(b|0)/32|0;if(b+31>>>0>=63){va(c,d,g<<2)}b=b-(g<<5)|0;if((b|0)<=0){break c}f=c;c=g<<2;g=f+c|0;b=-1>>>32-b|0;H[g>>2]=H[g>>2]&(b^-1)|b&H[c+d>>2];break c}H[e+28>>2]=g;H[e+24>>2]=d;H[e+20>>2]=i;H[e+16>>2]=j;H[e+12>>2]=f;H[e+8>>2]=c;b=H[e+28>>2];c=H[e+24>>2];g=(H[e+20>>2]-b|0)+(H[e+16>>2]-c<<3)|0;d:{if((g|0)<=0){b=H[e+12>>2];d=H[e+8>>2];break d}e:{if(!b){b=H[e+12>>2];break e}d=H[e+12>>2];j=32-d|0;k=32-b|0;f=(g|0)<(k|0)?g:k;i=f>>>0>j>>>0?j:f;l=H[e+8>>2];m=H[l>>2]&(-1<>>j-i^-1);j=H[c>>2]&(-1<>>k-f);H[l>>2]=m|(b>>>0>>0?j<>>b-d|0);c=d+i|0;b=c&31;H[e+12>>2]=b;d=l+(c>>>3&536870908)|0;H[e+8>>2]=d;c=f-i|0;if((c|0)>0){H[d>>2]=H[d>>2]&(-1>>>32-c^-1)|j>>>i+H[e+28>>2];H[e+12>>2]=c;b=c}g=g-f|0;c=H[e+24>>2]+4|0;H[e+24>>2]=c}i=-1<=32){j=i^-1;while(1){d=H[e+8>>2];c=H[c>>2];H[d>>2]=j&H[d>>2]|c<>2]=d+4;H[d+4>>2]=i&H[d+4>>2]|c>>>f;c=H[e+24>>2]+4|0;H[e+24>>2]=c;d=g>>>0>63;g=g-32|0;if(d){continue}break}}d=H[e+8>>2];if((g|0)<=0){break d}j=f;f=(g|0)>(f|0)?f:g;j=H[d>>2]&(i&-1>>>j-f^-1);i=H[c>>2]&-1>>>32-g;H[d>>2]=j|i<>2]=c;d=(b>>>3&536870908)+d|0;H[e+8>>2]=d;b=g-f|0;if((b|0)<=0){b=c;break d}H[d>>2]=H[d>>2]&(-1>>>32-b^-1)|i>>>f;H[e+12>>2]=b}H[e+4>>2]=b;H[e>>2]=d}ca=e+32|0;b=H[a>>2];H[a>>2]=H[h+16>>2];H[h+16>>2]=b;c=H[a+4>>2];H[a+4>>2]=H[h+20>>2];H[h+20>>2]=c;c=H[a+8>>2];H[a+8>>2]=H[h+24>>2];H[h+24>>2]=c;if(!b){break b}oa(b)}ca=h+32|0;return}sa();v()}function Ne(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;c=J[b+38>>1];a:{if(!c){break a}b:{if(c>>>0<=511){g=H[b+8>>2];e=H[b+12>>2];d=H[b+20>>2];c=H[b+16>>2];i=c+4|0;d=i>>>0<4?d+1|0:d;if(g>>>0>>0&(d|0)>=(e|0)|(d|0)>(e|0)){break a}c=c+H[b>>2]|0;f=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[a+12>>2]=f;d=H[b+20>>2];c=H[b+16>>2]+4|0;d=c>>>0<4?d+1|0:d;H[b+16>>2]=c;H[b+20>>2]=d;break b}if(!hb(1,a+12|0,b)){break a}c=H[b+16>>2];d=H[b+20>>2];f=H[a+12>>2]}e=H[b+8>>2];i=e-c|0;c=H[b+12>>2]-(d+(c>>>0>e>>>0)|0)|0;if(i>>>0>>6>>>0&(c|0)<=0|(c|0)<0){break a}d=H[a>>2];c=H[a+4>>2]-d>>2;c:{if(c>>>0>>0){ya(a,f-c|0);f=H[a+12>>2];break c}if(c>>>0<=f>>>0){break c}H[a+4>>2]=d+(f<<2)}if(!f){return 1}c=H[b+16>>2];d=H[b+20>>2];l=H[a>>2];i=H[b+8>>2];j=H[b+12>>2];g=0;while(1){if((d|0)>=(j|0)&c>>>0>=i>>>0|(d|0)>(j|0)){return 0}m=H[b>>2];k=I[m+c|0];c=c+1|0;d=c?d:d+1|0;H[b+16>>2]=c;H[b+20>>2]=d;e=k>>>2|0;h=0;d:{e:{f:{g:{n=k&3;switch(n|0){case 0:break e;case 3:break g;default:break f}}e=e+g|0;if(e>>>0>=f>>>0){return 0}ra(l+(g<<2)|0,0,(k&252)+4|0);g=e;break d}while(1){if((c|0)==(i|0)&(d|0)==(j|0)){break a}f=I[c+m|0];c=c+1|0;d=c?d:d+1|0;H[b+16>>2]=c;H[b+20>>2]=d;e=f<<(h<<3|6)|e;h=h+1|0;if((n|0)!=(h|0)){continue}break}}H[l+(g<<2)>>2]=e}f=H[a+12>>2];g=g+1|0;if(f>>>0>g>>>0){continue}break}b=a+16|0;i=H[a>>2];d=H[a+16>>2];c=H[a+20>>2]-d|0;h:{if(c>>>0<=16383){ya(b,4096-(c>>>2|0)|0);break h}if((c|0)==16384){break h}H[a+20>>2]=d+16384}c=a+28|0;g=H[c>>2];d=H[a+32>>2]-g>>3;i:{if(d>>>0>>0){ob(c,f-d|0);g=H[c>>2];break i}if(d>>>0>f>>>0){H[a+32>>2]=(f<<3)+g}if(!f){break a}}d=H[b>>2];b=0;a=0;while(1){c=i+(b<<2)|0;h=H[c>>2];e=a;j=(b<<3)+g|0;H[j+4>>2]=a;H[j>>2]=h;c=H[c>>2];a=c+a|0;if(a>>>0>4096){break a}j:{if(a>>>0<=e>>>0){break j}h=0;j=c&7;if(j){while(1){H[d+(e<<2)>>2]=b;e=e+1|0;h=h+1|0;if((j|0)!=(h|0)){continue}break}}if(c-1>>>0<=6){break j}while(1){c=d+(e<<2)|0;H[c>>2]=b;H[c+28>>2]=b;H[c+24>>2]=b;H[c+20>>2]=b;H[c+16>>2]=b;H[c+12>>2]=b;H[c+8>>2]=b;H[c+4>>2]=b;e=e+8|0;if((e|0)!=(a|0)){continue}break}}b=b+1|0;if((f|0)!=(b|0)){continue}break}o=(a|0)==4096}return o}function Ni(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=ca-48|0;ca=g;d=H[a+8>>2];if(d-2>>>0<=28){H[a+76>>2]=d;e=-1<>2]=d;H[a+80>>2]=e^-1;H[a+92>>2]=(d|0)/2;L[a+88>>2]=O(2)/O(d|0)}H[a+52>>2]=f;d=H[a+40>>2];e=H[d>>2];d=H[d+4>>2];H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+8|0;n=a+44|0;d=d>>>2|0;o=d>>>0<=1?1:d;p=a+96|0;while(1){e=H[a+40>>2];d=H[e>>2];if(H[e+4>>2]-d>>2>>>0<=j>>>0){break a}Nb(n,H[d+(j<<2)>>2],g+8|0);h=H[g+12>>2];d=h>>31;i=H[g+8>>2];e=i>>31;f=(d^h)-d+((e^i)-e)|0;l=H[g+16>>2];d=l>>31;e=(d^l)-d|0;d=0;k=e;e=e+f|0;d=k>>>0>e>>>0?1:d;b:{if(!(d|e)){H[g+8>>2]=H[a+92>>2];break b}f=H[a+92>>2];k=f>>31;i=Sj(Rj(f,k,i,i>>31),da,e,d);H[g+8>>2]=i;d=Sj(Rj(f,k,h,h>>31),da,e,d);H[g+12>>2]=d;e=d>>31;e=(d^e)-e|0;d=i>>31;d=e+((d^i)-d|0)|0;if((l|0)>=0){H[g+16>>2]=f-d;break b}H[g+16>>2]=d-f}d=Ba(p);f=H[g+8>>2];c:{if(d){H[g+16>>2]=0-H[g+16>>2];e=0-H[g+12>>2]|0;H[g+12>>2]=e;f=0-f|0;H[g+8>>2]=f;break c}e=H[g+12>>2]}d:{if((f|0)>=0){f=H[a+92>>2];d=f+H[g+16>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=H[g+16>>2];f=d>>31;f=(d^f)-f|0;break e}d=H[g+16>>2];f=d>>31;f=H[a+84>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=H[a+84>>2]+(d-(d^e)|0)|0}e=H[a+84>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}h=H[a+92>>2];if((h|0)>=(d|0)){break g}d=(h<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}h=H[a+92>>2];if((h|0)<=(d|0)){break h}d=(h<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=H[a+92>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=H[a+92>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}e=j<<3;h=e+b|0;i=H[h>>2];h=H[h+4>>2];H[g+36>>2]=d;H[g+32>>2]=f;H[g+24>>2]=i;H[g+28>>2]=h;qc(g+40|0,m,g+32|0,g+24|0);d=c+e|0;H[d>>2]=H[g+40>>2];H[d+4>>2]=H[g+44>>2];j=j+1|0;if((o|0)!=(j|0)){continue}break}}ca=g+48|0;return 1}Ca();v()}function Ii(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=ca-48|0;ca=g;d=H[a+8>>2];if(d-2>>>0<=28){H[a+76>>2]=d;e=-1<>2]=d;H[a+80>>2]=e^-1;H[a+92>>2]=(d|0)/2;L[a+88>>2]=O(2)/O(d|0)}H[a+52>>2]=f;d=H[a+40>>2];e=H[d>>2];d=H[d+4>>2];H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+8|0;n=a+44|0;d=d>>>2|0;o=d>>>0<=1?1:d;p=a+96|0;while(1){e=H[a+40>>2];d=H[e>>2];if(H[e+4>>2]-d>>2>>>0<=j>>>0){break a}Lb(n,H[d+(j<<2)>>2],g+8|0);h=H[g+12>>2];d=h>>31;i=H[g+8>>2];e=i>>31;f=(d^h)-d+((e^i)-e)|0;l=H[g+16>>2];d=l>>31;e=(d^l)-d|0;d=0;k=e;e=e+f|0;d=k>>>0>e>>>0?1:d;b:{if(!(d|e)){H[g+8>>2]=H[a+92>>2];break b}f=H[a+92>>2];k=f>>31;i=Sj(Rj(f,k,i,i>>31),da,e,d);H[g+8>>2]=i;d=Sj(Rj(f,k,h,h>>31),da,e,d);H[g+12>>2]=d;e=d>>31;e=(d^e)-e|0;d=i>>31;d=e+((d^i)-d|0)|0;if((l|0)>=0){H[g+16>>2]=f-d;break b}H[g+16>>2]=d-f}d=Ba(p);f=H[g+8>>2];c:{if(d){H[g+16>>2]=0-H[g+16>>2];e=0-H[g+12>>2]|0;H[g+12>>2]=e;f=0-f|0;H[g+8>>2]=f;break c}e=H[g+12>>2]}d:{if((f|0)>=0){f=H[a+92>>2];d=f+H[g+16>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=H[g+16>>2];f=d>>31;f=(d^f)-f|0;break e}d=H[g+16>>2];f=d>>31;f=H[a+84>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=H[a+84>>2]+(d-(d^e)|0)|0}e=H[a+84>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}h=H[a+92>>2];if((h|0)>=(d|0)){break g}d=(h<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}h=H[a+92>>2];if((h|0)<=(d|0)){break h}d=(h<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=H[a+92>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=H[a+92>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}e=j<<3;h=e+b|0;i=H[h>>2];h=H[h+4>>2];H[g+36>>2]=d;H[g+32>>2]=f;H[g+24>>2]=i;H[g+28>>2]=h;qc(g+40|0,m,g+32|0,g+24|0);d=c+e|0;H[d>>2]=H[g+40>>2];H[d+4>>2]=H[g+44>>2];j=j+1|0;if((o|0)!=(j|0)){continue}break}}ca=g+48|0;return 1}Ca();v()}function Wi(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=ca-48|0;ca=g;d=H[a+8>>2];if(d-2>>>0<=28){H[a+76>>2]=d;e=-1<>2]=d;H[a+80>>2]=e^-1;H[a+92>>2]=(d|0)/2;L[a+88>>2]=O(2)/O(d|0)}H[a+52>>2]=f;d=H[a+40>>2];e=H[d>>2];d=H[d+4>>2];H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+8|0;n=a+44|0;d=d>>>2|0;o=d>>>0<=1?1:d;p=a+96|0;while(1){e=H[a+40>>2];d=H[e>>2];if(H[e+4>>2]-d>>2>>>0<=j>>>0){break a}Nb(n,H[d+(j<<2)>>2],g+8|0);h=H[g+12>>2];d=h>>31;i=H[g+8>>2];e=i>>31;f=(d^h)-d+((e^i)-e)|0;l=H[g+16>>2];d=l>>31;e=(d^l)-d|0;d=0;k=e;e=e+f|0;d=k>>>0>e>>>0?1:d;b:{if(!(d|e)){H[g+8>>2]=H[a+92>>2];break b}f=H[a+92>>2];k=f>>31;i=Sj(Rj(f,k,i,i>>31),da,e,d);H[g+8>>2]=i;d=Sj(Rj(f,k,h,h>>31),da,e,d);H[g+12>>2]=d;e=d>>31;e=(d^e)-e|0;d=i>>31;d=e+((d^i)-d|0)|0;if((l|0)>=0){H[g+16>>2]=f-d;break b}H[g+16>>2]=d-f}d=Ba(p);f=H[g+8>>2];c:{if(d){H[g+16>>2]=0-H[g+16>>2];e=0-H[g+12>>2]|0;H[g+12>>2]=e;f=0-f|0;H[g+8>>2]=f;break c}e=H[g+12>>2]}d:{if((f|0)>=0){f=H[a+92>>2];d=f+H[g+16>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=H[g+16>>2];f=d>>31;f=(d^f)-f|0;break e}d=H[g+16>>2];f=d>>31;f=H[a+84>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=H[a+84>>2]+(d-(d^e)|0)|0}e=H[a+84>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}h=H[a+92>>2];if((h|0)>=(d|0)){break g}d=(h<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}h=H[a+92>>2];if((h|0)<=(d|0)){break h}d=(h<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=H[a+92>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=H[a+92>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}e=j<<3;h=e+b|0;i=H[h+4>>2];H[g+40>>2]=H[h>>2];H[g+44>>2]=i;H[g+28>>2]=d;H[g+24>>2]=f;rc(g+32|0,m,g+24|0,g+40|0);d=c+e|0;H[d>>2]=H[g+32>>2];H[d+4>>2]=H[g+36>>2];j=j+1|0;if((o|0)!=(j|0)){continue}break}}ca=g+48|0;return 1}Ca();v()}function Ri(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=ca-48|0;ca=g;d=H[a+8>>2];if(d-2>>>0<=28){H[a+76>>2]=d;e=-1<>2]=d;H[a+80>>2]=e^-1;H[a+92>>2]=(d|0)/2;L[a+88>>2]=O(2)/O(d|0)}H[a+52>>2]=f;d=H[a+40>>2];e=H[d>>2];d=H[d+4>>2];H[g+16>>2]=0;H[g+8>>2]=0;H[g+12>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+8|0;n=a+44|0;d=d>>>2|0;o=d>>>0<=1?1:d;p=a+96|0;while(1){e=H[a+40>>2];d=H[e>>2];if(H[e+4>>2]-d>>2>>>0<=j>>>0){break a}Lb(n,H[d+(j<<2)>>2],g+8|0);h=H[g+12>>2];d=h>>31;i=H[g+8>>2];e=i>>31;f=(d^h)-d+((e^i)-e)|0;l=H[g+16>>2];d=l>>31;e=(d^l)-d|0;d=0;k=e;e=e+f|0;d=k>>>0>e>>>0?1:d;b:{if(!(d|e)){H[g+8>>2]=H[a+92>>2];break b}f=H[a+92>>2];k=f>>31;i=Sj(Rj(f,k,i,i>>31),da,e,d);H[g+8>>2]=i;d=Sj(Rj(f,k,h,h>>31),da,e,d);H[g+12>>2]=d;e=d>>31;e=(d^e)-e|0;d=i>>31;d=e+((d^i)-d|0)|0;if((l|0)>=0){H[g+16>>2]=f-d;break b}H[g+16>>2]=d-f}d=Ba(p);f=H[g+8>>2];c:{if(d){H[g+16>>2]=0-H[g+16>>2];e=0-H[g+12>>2]|0;H[g+12>>2]=e;f=0-f|0;H[g+8>>2]=f;break c}e=H[g+12>>2]}d:{if((f|0)>=0){f=H[a+92>>2];d=f+H[g+16>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=H[g+16>>2];f=d>>31;f=(d^f)-f|0;break e}d=H[g+16>>2];f=d>>31;f=H[a+84>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=H[a+84>>2]+(d-(d^e)|0)|0}e=H[a+84>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}h=H[a+92>>2];if((h|0)>=(d|0)){break g}d=(h<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}h=H[a+92>>2];if((h|0)<=(d|0)){break h}d=(h<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=H[a+92>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=H[a+92>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}e=j<<3;h=e+b|0;i=H[h+4>>2];H[g+40>>2]=H[h>>2];H[g+44>>2]=i;H[g+28>>2]=d;H[g+24>>2]=f;rc(g+32|0,m,g+24|0,g+40|0);d=c+e|0;H[d>>2]=H[g+32>>2];H[d+4>>2]=H[g+36>>2];j=j+1|0;if((o|0)!=(j|0)){continue}break}}ca=g+48|0;return 1}Ca();v()}function Ge(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;f=ca-16|0;ca=f;c=H[a+4>>2];H[a+40>>2]=H[a>>2];H[a+44>>2]=c;c=H[a+36>>2];H[a+72>>2]=H[a+32>>2];H[a+76>>2]=c;d=H[a+28>>2];c=a- -64|0;H[c>>2]=H[a+24>>2];H[c+4>>2]=d;c=H[a+20>>2];H[a+56>>2]=H[a+16>>2];H[a+60>>2]=c;c=H[a+12>>2];H[a+48>>2]=H[a+8>>2];H[a+52>>2]=c;a:{b:{if(Db(a+40|0,1,f+8|0)){c=H[a+44>>2];H[a>>2]=H[a+40>>2];H[a+4>>2]=c;c=H[a+76>>2];H[a+32>>2]=H[a+72>>2];H[a+36>>2]=c;c=H[a+68>>2];H[a+24>>2]=H[a+64>>2];H[a+28>>2]=c;d=H[a+60>>2];h=d;c=H[a+56>>2];H[a+16>>2]=c;H[a+20>>2]=d;e=H[a+52>>2];d=H[a+48>>2];H[a+8>>2]=d;H[a+12>>2]=e;i=d-c|0;g=H[f+12>>2];e=e-((c>>>0>d>>>0)+h|0)|0;d=H[f+8>>2];if((g|0)==(e|0)&i>>>0>=d>>>0|e>>>0>g>>>0){break b}}c=0;break a}e=h+g|0;c=c+d|0;e=c>>>0>>0?e+1|0:e;H[a+16>>2]=c;H[a+20>>2]=e;c:{if(J[a+38>>1]<=513){c=H[a+4>>2];H[a+96>>2]=H[a>>2];H[a+100>>2]=c;c=H[a+36>>2];H[a+128>>2]=H[a+32>>2];H[a+132>>2]=c;c=H[a+28>>2];H[a+120>>2]=H[a+24>>2];H[a+124>>2]=c;c=H[a+20>>2];H[a+112>>2]=H[a+16>>2];H[a+116>>2]=c;c=H[a+12>>2];H[a+104>>2]=H[a+8>>2];H[a+108>>2]=c;d:{if(Db(a+96|0,1,f+8|0)){c=H[a+100>>2];H[a>>2]=H[a+96>>2];H[a+4>>2]=c;c=H[a+132>>2];H[a+32>>2]=H[a+128>>2];H[a+36>>2]=c;c=H[a+124>>2];H[a+24>>2]=H[a+120>>2];H[a+28>>2]=c;d=H[a+116>>2];h=d;c=H[a+112>>2];H[a+16>>2]=c;H[a+20>>2]=d;e=H[a+108>>2];d=H[a+104>>2];H[a+8>>2]=d;H[a+12>>2]=e;i=d-c|0;g=H[f+12>>2];e=e-((c>>>0>d>>>0)+h|0)|0;d=H[f+8>>2];if((g|0)==(e|0)&i>>>0>=d>>>0|e>>>0>g>>>0){break d}}c=0;break a}e=h+g|0;c=c+d|0;e=c>>>0>>0?e+1|0:e;H[a+16>>2]=c;H[a+20>>2]=e;break c}c=0;if(!ta(a+80|0,a)){break a}}c=0;if(!Fe(a)){break a}c=H[a+4>>2];H[b>>2]=H[a>>2];H[b+4>>2]=c;c=H[a+36>>2];H[b+32>>2]=H[a+32>>2];H[b+36>>2]=c;c=H[a+28>>2];H[b+24>>2]=H[a+24>>2];H[b+28>>2]=c;c=H[a+20>>2];H[b+16>>2]=H[a+16>>2];H[b+20>>2]=c;c=H[a+12>>2];H[b+8>>2]=H[a+8>>2];H[b+12>>2]=c;c=1}ca=f+16|0;return c}function oe(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;if(!H[a+64>>2]){c=pa(32);H[c+16>>2]=0;H[c+20>>2]=0;H[c+8>>2]=0;H[c>>2]=0;H[c+4>>2]=0;H[c+24>>2]=0;H[c+28>>2]=0;d=H[a+64>>2];H[a+64>>2]=c;if(d){c=H[d>>2];if(c){H[d+4>>2]=c;oa(c)}oa(d);c=H[a+64>>2]}H[a>>2]=c;d=H[c+20>>2];H[a+8>>2]=H[c+16>>2];H[a+12>>2]=d;d=H[c+24>>2];c=H[c+28>>2];H[a+48>>2]=0;H[a+52>>2]=0;H[a+40>>2]=0;H[a+44>>2]=0;H[a+16>>2]=d;H[a+20>>2]=c}a:{F[a+24|0]=I[b+24|0];H[a+28>>2]=H[b+28>>2];F[a+32|0]=I[b+32|0];c=H[b+44>>2];H[a+40>>2]=H[b+40>>2];H[a+44>>2]=c;c=H[b+52>>2];H[a+48>>2]=H[b+48>>2];H[a+52>>2]=c;H[a+56>>2]=H[b+56>>2];c=H[b+12>>2];H[a+8>>2]=H[b+8>>2];H[a+12>>2]=c;c=H[b+20>>2];H[a+16>>2]=H[b+16>>2];H[a+20>>2]=c;H[a+60>>2]=H[b+60>>2];c=H[b>>2];b:{if(!c){H[a>>2]=0;d=1;break b}g=H[a>>2];d=0;if(!g){break b}d=H[c>>2];c=H[c+4>>2]-d|0;se(g,d,c,0);d=1}c:{if(!d){break c}F[a+84|0]=I[b+84|0];H[a+80>>2]=H[b+80>>2];if((a|0)!=(b|0)){Cb(a+68|0,H[b+68>>2],H[b+72>>2])}f=H[b+88>>2];d:{if(f){e=pa(40);b=H[f>>2];H[e+16>>2]=0;H[e+8>>2]=0;H[e+12>>2]=0;H[e>>2]=b;c=H[f+12>>2];b=H[f+8>>2];if((c|0)!=(b|0)){c=c-b|0;if((c|0)<0){break a}b=pa(c);H[e+12>>2]=b;H[e+8>>2]=b;H[e+16>>2]=b+c;c=H[f+8>>2];h=H[f+12>>2];e:{if((c|0)==(h|0)){break e}g=(c^-1)+h|0;d=h-c&7;if(d){while(1){F[b|0]=I[c|0];b=b+1|0;c=c+1|0;i=i+1|0;if((d|0)!=(i|0)){continue}break}}if(g>>>0<7){break e}while(1){F[b|0]=I[c|0];F[b+1|0]=I[c+1|0];F[b+2|0]=I[c+2|0];F[b+3|0]=I[c+3|0];F[b+4|0]=I[c+4|0];F[b+5|0]=I[c+5|0];F[b+6|0]=I[c+6|0];F[b+7|0]=I[c+7|0];b=b+8|0;c=c+8|0;if((h|0)!=(c|0)){continue}break}}H[e+12>>2]=b}b=H[f+36>>2];H[e+32>>2]=H[f+32>>2];H[e+36>>2]=b;b=H[f+28>>2];H[e+24>>2]=H[f+24>>2];H[e+28>>2]=b;b=H[a+88>>2];H[a+88>>2]=e;if(b){break d}break c}b=H[a+88>>2];H[a+88>>2]=0;if(!b){break c}}a=H[b+8>>2];if(a){H[b+12>>2]=a;oa(a)}oa(b)}return}sa();v()}function og(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;f=ca-32|0;ca=f;e=f+8|0;c=ca-80|0;ca=c;a=H[b+36>>2];H[c+72>>2]=H[b+32>>2];H[c+76>>2]=a;d=H[b+28>>2];a=c- -64|0;H[a>>2]=H[b+24>>2];H[a+4>>2]=d;a=H[b+20>>2];H[c+56>>2]=H[b+16>>2];H[c+60>>2]=a;a=H[b+12>>2];H[c+48>>2]=H[b+8>>2];H[c+52>>2]=a;a=H[b+4>>2];H[c+40>>2]=H[b>>2];H[c+44>>2]=a;nc(c+8|0,c+40|0,c+24|0);a=H[c+8>>2];a:{if(a){H[e>>2]=a;a=e+4|0;if(F[c+23|0]>=0){b=c+8|4;e=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=e;H[a+8>>2]=H[b+8>>2];break a}za(a,H[c+12>>2],H[c+16>>2]);if(F[c+23|0]>=0){break a}oa(H[c+12>>2]);break a}if(F[c+23|0]<0){oa(H[c+12>>2])}a=I[c+31|0];if(a>>>0>=2){b=pa(32);F[b+26|0]=0;a=I[1477]|I[1478]<<8;F[b+24|0]=a;F[b+25|0]=a>>>8;a=I[1473]|I[1474]<<8|(I[1475]<<16|I[1476]<<24);d=I[1469]|I[1470]<<8|(I[1471]<<16|I[1472]<<24);F[b+16|0]=d;F[b+17|0]=d>>>8;F[b+18|0]=d>>>16;F[b+19|0]=d>>>24;F[b+20|0]=a;F[b+21|0]=a>>>8;F[b+22|0]=a>>>16;F[b+23|0]=a>>>24;a=I[1465]|I[1466]<<8|(I[1467]<<16|I[1468]<<24);d=I[1461]|I[1462]<<8|(I[1463]<<16|I[1464]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=a;F[b+13|0]=a>>>8;F[b+14|0]=a>>>16;F[b+15|0]=a>>>24;a=I[1457]|I[1458]<<8|(I[1459]<<16|I[1460]<<24);d=I[1453]|I[1454]<<8|(I[1455]<<16|I[1456]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=a;F[b+5|0]=a>>>8;F[b+6|0]=a>>>16;F[b+7|0]=a>>>24;H[c+8>>2]=-1;a=c+8|4;za(a,b,26);d=F[c+23|0];H[e>>2]=H[c+8>>2];e=e+4|0;if((d|0)>=0){d=H[a+4>>2];H[e>>2]=H[a>>2];H[e+4>>2]=d;H[e+8>>2]=H[a+8>>2];oa(b);break a}za(e,H[c+12>>2],H[c+16>>2]);if(F[c+23|0]<0){oa(H[c+12>>2])}oa(b);break a}H[e>>2]=0;H[e+4>>2]=0;H[e+16>>2]=a;H[e+8>>2]=0;H[e+12>>2]=0}ca=c+80|0;a=H[f+24>>2];if(F[f+23|0]<0){oa(H[f+12>>2])}ca=f+32|0;return a|0}function Xd(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;k=ca-16|0;ca=k;H[k+8>>2]=c;h=H[a+12>>2];d=H[a+8>>2];g=h-d>>2;a:{if((g|0)>(b|0)){break a}e=b+1|0;if(e>>>0>g>>>0){l=e-g|0;f=H[a+16>>2];d=H[a+12>>2];if(l>>>0<=f-d>>2>>>0){if(l){e=d;d=l<<2;d=ra(e,0,d)+d|0}H[a+12>>2]=d;break a}b:{c:{d:{m=H[a+8>>2];g=d-m>>2;i=g+l|0;if(i>>>0<1073741824){e=f-m|0;f=e>>>1|0;e=e>>>0>=2147483644?1073741823:f>>>0>i>>>0?f:i;if(e){if(e>>>0>=1073741824){break d}j=pa(e<<2)}h=(g<<2)+j|0;f=l<<2;i=ra(h,0,f);g=f+i|0;e=(e<<2)+j|0;if((d|0)==(m|0)){break c}while(1){d=d-4|0;f=H[d>>2];H[d>>2]=0;h=h-4|0;H[h>>2]=f;if((d|0)!=(m|0)){continue}break}H[a+16>>2]=e;e=H[a+12>>2];H[a+12>>2]=g;d=H[a+8>>2];H[a+8>>2]=h;if((d|0)==(e|0)){break b}while(1){e=e-4|0;f=H[e>>2];H[e>>2]=0;if(f){Ga(f)}if((d|0)!=(e|0)){continue}break}break b}sa();v()}wa();v()}H[a+16>>2]=e;H[a+12>>2]=g;H[a+8>>2]=i}if(d){oa(d)}break a}if(e>>>0>=g>>>0){break a}d=d+(e<<2)|0;if((d|0)!=(h|0)){while(1){h=h-4|0;c=H[h>>2];H[h>>2]=0;if(c){Ga(c)}if((d|0)!=(h|0)){continue}break}c=H[k+8>>2]}H[a+12>>2]=d}e:{f:{d=H[c+56>>2];g:{if((d|0)>4){break g}j=N(d,12)+a|0;d=H[j+24>>2];if((d|0)!=H[j+28>>2]){H[d>>2]=b;H[j+24>>2]=d+4;break g}i=H[j+20>>2];g=d-i|0;f=g>>2;e=f+1|0;if(e>>>0>=1073741824){break f}d=g>>>1|0;e=g>>>0>=2147483644?1073741823:d>>>0>e>>>0?d:e;if(e){if(e>>>0>=1073741824){break e}d=pa(e<<2)}else{d=0}f=d+(f<<2)|0;H[f>>2]=b;d=va(d,i,g);H[j+20>>2]=d;H[j+24>>2]=f+4;H[j+28>>2]=d+(e<<2);if(!i){break g}oa(i)}H[c+60>>2]=b;a=H[a+8>>2];H[k+8>>2]=0;a=a+(b<<2)|0;b=H[a>>2];H[a>>2]=c;if(b){Ga(b)}a=H[k+8>>2];H[k+8>>2]=0;if(a){Ga(a)}ca=k+16|0;return}sa();v()}wa();v()}function Og(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;i=c;d=a;a:{if(H[a+12>>2]==(b|0)){break a}a=b;b=H[d+4>>2];e=H[d>>2];if((b|0)!=(e|0)){while(1){c=b-12|0;if(F[b-1|0]<0){oa(H[c>>2])}b=c;if((e|0)!=(b|0)){continue}break}}H[d+12>>2]=a;H[d+4>>2]=e;c=H[a>>2];j=a+4|0;if((c|0)==(j|0)){break a}while(1){a=H[d+4>>2];b:{if((a|0)!=H[d+8>>2]){c:{if(F[c+27|0]>=0){b=H[c+20>>2];H[a>>2]=H[c+16>>2];H[a+4>>2]=b;H[a+8>>2]=H[c+24>>2];break c}za(a,H[c+16>>2],H[c+20>>2])}H[d+4>>2]=a+12;break b}g=0;d:{e:{f:{a=H[d+4>>2];e=H[d>>2];f=(a-e|0)/12|0;b=f+1|0;if(b>>>0<357913942){h=(H[d+8>>2]-e|0)/12|0;k=h<<1;b=h>>>0>=178956970?357913941:b>>>0>>0?k:b;if(b){if(b>>>0>=357913942){break f}g=pa(N(b,12))}h=N(b,12);b=N(f,12)+g|0;g:{if(F[c+27|0]>=0){f=H[c+20>>2];H[b>>2]=H[c+16>>2];H[b+4>>2]=f;H[b+8>>2]=H[c+24>>2];break g}za(b,H[c+16>>2],H[c+20>>2]);e=H[d>>2];a=H[d+4>>2]}g=g+h|0;f=b+12|0;if((a|0)==(e|0)){break e}while(1){a=a-12|0;h=H[a+4>>2];b=b-12|0;H[b>>2]=H[a>>2];H[b+4>>2]=h;H[b+8>>2]=H[a+8>>2];H[a>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;if((a|0)!=(e|0)){continue}break}H[d+8>>2]=g;a=H[d+4>>2];H[d+4>>2]=f;e=H[d>>2];H[d>>2]=b;if((a|0)==(e|0)){break d}while(1){b=a-12|0;if(F[a-1|0]<0){oa(H[b>>2])}a=b;if((e|0)!=(b|0)){continue}break}break d}sa();v()}wa();v()}H[d+8>>2]=g;H[d+4>>2]=f;H[d>>2]=b}if(e){oa(e)}}b=H[c+4>>2];h:{if(b){while(1){a=b;b=H[b>>2];if(b){continue}break h}}while(1){a=H[c+8>>2];b=H[a>>2]!=(c|0);c=a;if(b){continue}break}}c=a;if((j|0)!=(a|0)){continue}break}}a=0;i:{if((i|0)<0){break i}b=H[d>>2];if((H[d+4>>2]-b|0)/12>>>0<=i>>>0){break i}a=b+N(i,12)|0;a=F[a+11|0]<0?H[a>>2]:a}return a|0}function bd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;i=ca-16|0;ca=i;H[i>>2]=b;f=-1;a:{if((b|0)==-1){H[i+4>>2]=-1;break a}f=b+1|0;H[i+4>>2]=(f>>>0)%3|0?f:b-2|0;if((b>>>0)%3|0){f=b-1|0;break a}f=b+2|0}H[i+8>>2]=f;n=(b>>>0)/3|0;b:{c:{d:{while(1){e:{f:{j=H[(l<<2)+i>>2];if((j|0)!=-1){f=H[H[H[a+8>>2]+12>>2]+(j<<2)>>2];if((f|0)!=-1){break f}}f=0;g=H[a+216>>2];if((g|0)==H[a+220>>2]){break e}while(1){g=N(f,144)+g|0;d=H[g+136>>2];c=H[g+140>>2];g:{if(d>>>0>>0){H[d>>2]=j;H[g+136>>2]=d+4;break g}e=d;d=H[g+132>>2];k=e-d|0;e=k>>2;h=e+1|0;if(h>>>0>=1073741824){break d}m=e<<2;c=c-d|0;e=c>>>1|0;h=c>>>0>=2147483644?1073741823:h>>>0>>0?e:h;if(h){if(h>>>0>=1073741824){break c}c=pa(h<<2)}else{c=0}e=m+c|0;H[e>>2]=j;c=va(c,d,k);H[g+132>>2]=c;H[g+136>>2]=e+4;H[g+140>>2]=c+(h<<2);if(!d){break g}oa(d)}f=f+1|0;g=H[a+216>>2];if(f>>>0<(H[a+220>>2]-g|0)/144>>>0){continue}break}break e}if((b|0)==-1|(f>>>0)/3>>>0>>0){break e}f=0;if(H[a+220>>2]==H[a+216>>2]){break e}while(1){h:{if(!Ba(H[a+368>>2]+(f<<4)|0)){break h}g=H[a+216>>2]+N(f,144)|0;d=H[g+136>>2];c=H[g+140>>2];if(d>>>0>>0){H[d>>2]=j;H[g+136>>2]=d+4;break h}e=d;d=H[g+132>>2];k=e-d|0;e=k>>2;h=e+1|0;if(h>>>0>=1073741824){break b}m=e<<2;c=c-d|0;e=c>>>1|0;h=c>>>0>=2147483644?1073741823:h>>>0>>0?e:h;if(h){if(h>>>0>=1073741824){break c}c=pa(h<<2)}else{c=0}e=m+c|0;H[e>>2]=j;c=va(c,d,k);H[g+132>>2]=c;H[g+136>>2]=e+4;H[g+140>>2]=c+(h<<2);if(!d){break h}oa(d)}f=f+1|0;if(f>>>0<(H[a+220>>2]-H[a+216>>2]|0)/144>>>0){continue}break}}l=l+1|0;if((l|0)!=3){continue}break}ca=i+16|0;return 1}sa();v()}wa();v()}sa();v()}function cd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;h=ca-16|0;ca=h;H[h>>2]=b;c=-1;a:{if((b|0)==-1){H[h+4>>2]=-1;break a}c=b+1|0;H[h+4>>2]=(c>>>0)%3|0?c:b-2|0;if((b>>>0)%3|0){c=b-1|0;break a}c=b+2|0}H[h+8>>2]=c;b:{c:{while(1){i=H[(k<<2)+h>>2];d:{if(!((i|0)==-1|H[H[H[a+8>>2]+12>>2]+(i<<2)>>2]==-1)){b=0;if(H[a+220>>2]==H[a+216>>2]){break d}while(1){e:{f:{if(!Ba(H[a+368>>2]+(b<<4)|0)){break f}c=H[a+216>>2]+N(b,144)|0;e=H[c+136>>2];d=H[c+140>>2];if(e>>>0>>0){H[e>>2]=i;H[c+136>>2]=e+4;break f}f=e;e=H[c+132>>2];j=f-e|0;f=j>>2;g=f+1|0;if(g>>>0>=1073741824){break e}l=f<<2;d=d-e|0;f=d>>>1|0;g=d>>>0>=2147483644?1073741823:g>>>0>>0?f:g;if(g){if(g>>>0>=1073741824){break b}d=pa(g<<2)}else{d=0}f=l+d|0;H[f>>2]=i;d=va(d,e,j);H[c+132>>2]=d;H[c+136>>2]=f+4;H[c+140>>2]=d+(g<<2);if(!e){break f}oa(e)}b=b+1|0;if(b>>>0<(H[a+220>>2]-H[a+216>>2]|0)/144>>>0){continue}break d}break}sa();v()}b=0;c=H[a+216>>2];if((c|0)==H[a+220>>2]){break d}while(1){c=N(b,144)+c|0;e=H[c+136>>2];d=H[c+140>>2];g:{if(e>>>0>>0){H[e>>2]=i;H[c+136>>2]=e+4;break g}f=e;e=H[c+132>>2];j=f-e|0;f=j>>2;g=f+1|0;if(g>>>0>=1073741824){break c}l=f<<2;d=d-e|0;f=d>>>1|0;g=d>>>0>=2147483644?1073741823:g>>>0>>0?f:g;if(g){if(g>>>0>=1073741824){break b}d=pa(g<<2)}else{d=0}f=l+d|0;H[f>>2]=i;d=va(d,e,j);H[c+132>>2]=d;H[c+136>>2]=f+4;H[c+140>>2]=d+(g<<2);if(!e){break g}oa(e)}b=b+1|0;c=H[a+216>>2];if(b>>>0<(H[a+220>>2]-c|0)/144>>>0){continue}break}}k=k+1|0;if((k|0)!=3){continue}break}ca=h+16|0;return 1}sa();v()}wa();v()}function vg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;m=ca-16|0;ca=m;l=H[b+80>>2];e=I[c+24|0];a=N(l,e);a:{b:{c:{d:{b=H[c+28>>2];if(!(!I[c+84|0]|(b|0)!=1&(b|0)!=2)){b=H[c+48>>2];c=H[H[c>>2]>>2];H[m+8>>2]=0;H[m>>2]=0;H[m+4>>2]=0;if(a){if((a|0)<0){break d}f=pa(a);h=qa(f,b+c|0,a)+a|0}a=H[d>>2];if(a){H[d+4>>2]=a;oa(a)}H[d+8>>2]=h;H[d+4>>2]=h;H[d>>2]=f;b=1;break a}if(e){f=pa(e);ra(f,0,e)}e:{i=H[d+4>>2];b=H[d>>2];g=i-b|0;f:{if(g>>>0>>0){k=a-g|0;j=H[d+8>>2];if(k>>>0<=j-i>>>0){n=d,o=ra(i,0,k)+k|0,H[n+4>>2]=o;break f}if((a|0)<0){break e}i=j-b|0;j=i<<1;i=i>>>0>=1073741823?2147483647:a>>>0>>0?j:a;j=pa(i);ra(j+g|0,0,k);g=va(j,b,g);H[d+8>>2]=g+i;H[d+4>>2]=a+g;H[d>>2]=g;if(!b){break f}oa(b);break f}if(a>>>0>=g>>>0){break f}H[d+4>>2]=a+b}if(!l){b=1;break c}if(!e){b=0;a=0;while(1){if(!ic(c,I[c+84|0]?a:H[H[c+68>>2]+(a<<2)>>2],F[c+24|0],f)){break c}a=a+1|0;b=l>>>0<=a>>>0;if((a|0)!=(l|0)){continue}break}break c}i=e&252;g=e&3;b=0;j=e>>>0<4;e=0;while(1){if(!ic(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],f)){break c}b=0;a=0;k=0;if(!j){while(1){F[H[d>>2]+h|0]=I[a+f|0];F[(H[d>>2]+h|0)+1|0]=I[(a|1)+f|0];F[(H[d>>2]+h|0)+2|0]=I[(a|2)+f|0];F[(H[d>>2]+h|0)+3|0]=I[(a|3)+f|0];a=a+4|0;h=h+4|0;k=k+4|0;if((i|0)!=(k|0)){continue}break}}if(g){while(1){F[H[d>>2]+h|0]=I[a+f|0];a=a+1|0;h=h+1|0;b=b+1|0;if((g|0)!=(b|0)){continue}break}}e=e+1|0;b=l>>>0<=e>>>0;if((e|0)!=(l|0)){continue}break}break b}sa();v()}sa();v()}if(!f){break a}}oa(f)}ca=m+16|0;return b&1}function ug(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;m=ca-16|0;ca=m;l=H[b+80>>2];e=I[c+24|0];a=N(l,e);a:{b:{c:{d:{b=H[c+28>>2];if(!(!I[c+84|0]|(b|0)!=1&(b|0)!=2)){b=H[c+48>>2];c=H[H[c>>2]>>2];H[m+8>>2]=0;H[m>>2]=0;H[m+4>>2]=0;if(a){if((a|0)<0){break d}f=pa(a);h=qa(f,b+c|0,a)+a|0}a=H[d>>2];if(a){H[d+4>>2]=a;oa(a)}H[d+8>>2]=h;H[d+4>>2]=h;H[d>>2]=f;b=1;break a}if(e){f=pa(e);ra(f,0,e)}e:{i=H[d+4>>2];b=H[d>>2];g=i-b|0;f:{if(g>>>0>>0){k=a-g|0;j=H[d+8>>2];if(k>>>0<=j-i>>>0){n=d,o=ra(i,0,k)+k|0,H[n+4>>2]=o;break f}if((a|0)<0){break e}i=j-b|0;j=i<<1;i=i>>>0>=1073741823?2147483647:a>>>0>>0?j:a;j=pa(i);ra(j+g|0,0,k);g=va(j,b,g);H[d+8>>2]=g+i;H[d+4>>2]=a+g;H[d>>2]=g;if(!b){break f}oa(b);break f}if(a>>>0>=g>>>0){break f}H[d+4>>2]=a+b}if(!l){b=1;break c}if(!e){b=0;a=0;while(1){if(!hc(c,I[c+84|0]?a:H[H[c+68>>2]+(a<<2)>>2],F[c+24|0],f)){break c}a=a+1|0;b=l>>>0<=a>>>0;if((a|0)!=(l|0)){continue}break}break c}i=e&252;g=e&3;b=0;j=e>>>0<4;e=0;while(1){if(!hc(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],f)){break c}b=0;a=0;k=0;if(!j){while(1){F[H[d>>2]+h|0]=I[a+f|0];F[(H[d>>2]+h|0)+1|0]=I[(a|1)+f|0];F[(H[d>>2]+h|0)+2|0]=I[(a|2)+f|0];F[(H[d>>2]+h|0)+3|0]=I[(a|3)+f|0];a=a+4|0;h=h+4|0;k=k+4|0;if((i|0)!=(k|0)){continue}break}}if(g){while(1){F[H[d>>2]+h|0]=I[a+f|0];a=a+1|0;h=h+1|0;b=b+1|0;if((g|0)!=(b|0)){continue}break}}e=e+1|0;b=l>>>0<=e>>>0;if((e|0)!=(l|0)){continue}break}break b}sa();v()}sa();v()}if(!f){break a}}oa(f)}ca=m+16|0;return b&1}function qc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;k=H[b+16>>2];h=H[c+4>>2]-k|0;e=H[c>>2]-k|0;H[c>>2]=e;f=h;H[c+4>>2]=f;l=H[b+16>>2];f=f>>31;g=(h^f)-f|0;f=e>>31;m=l>>>0>=g+((f^e)-f|0)>>>0;a:{if(m){f=h;break a}b:{c:{if((e|0)>=0){g=1;j=1;if((h|0)>=0){break b}i=1;g=-1;j=-1;if(e){break c}break b}i=-1;g=-1;j=-1;if((h|0)<=0){break b}}g=(h|0)<=0?-1:1;j=i}n=N(j,l);f=(e<<1)-n|0;i=(N(g,j)|0)>=0;e=N(g,l);f=((i?0-f|0:f)+e|0)/2|0;H[c+4>>2]=f;e=(h<<1)-e|0;e=((i?0-e|0:e)+n|0)/2|0;H[c>>2]=e}d:{e:{f:{g:{h:{i:{j:{if(e){if((e|0)<0){break j}if((f|0)>=0){break i}break f}if(f){break h}j=1;g=0;f=0;i=0;break d}j=1;if((f|0)>0){break g}i=(f|0)>0?3:0;g=f;f=e;break d}g=0-f|0;f=0-e|0;i=2;break e}if((f|0)<=0){break f}}f=0-f|0;g=e;i=3;break e}g=0-e|0;i=1}H[c>>2]=f;H[c+4>>2]=g;j=0}e=H[d>>2]+f|0;h=H[b+16>>2];k:{if((e|0)>(h|0)){e=e-H[b+4>>2]|0;break k}if((0-h|0)<=(e|0)){break k}e=H[b+4>>2]+e|0}c=H[d+4>>2]+g|0;l:{if((h|0)<(c|0)){c=c-H[b+4>>2]|0;break l}if((0-h|0)<=(c|0)){break l}c=H[b+4>>2]+c|0}m:{if(j){b=c;break m}b=c;n:{o:{p:{d=4-i|0;switch((d>>>0<4?d:0-i|0)-1|0){case 2:break n;case 1:break o;case 0:break p;default:break m}}b=0-e|0;e=c;break m}b=0-c|0;e=0-e|0;break m}b=e;e=0-c|0}q:{if(m){c=b;break q}r:{s:{if((e|0)>=0){c=1;f=1;if((b|0)>=0){break r}d=1;c=-1;f=-1;if(e){break s}break r}d=-1;c=-1;f=-1;if((b|0)<=0){break r}}c=(b|0)<=0?-1:1;f=d}d=e<<1;e=N(f,h);d=d-e|0;f=(N(c,f)|0)>=0;g=f?0-d|0:d;d=N(c,h);c=(g+d|0)/2|0;b=(b<<1)-d|0;e=(e+(f?0-b|0:b)|0)/2|0}b=a;H[b>>2]=e+k;H[b+4>>2]=c+k}function Cj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;j=ca-32|0;ca=j;H[j+28>>2]=0;a:{b:{if(J[b+38>>1]<=513){c=H[b+20>>2];d=H[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;h=H[b+12>>2];if(K[b+8>>2]>>0&(h|0)<=(c|0)|(c|0)>(h|0)){break a}d=d+H[b>>2]|0;f=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;break b}if(!Xa(1,j+28|0,b)){break a}f=H[j+28>>2]}if(!f){break a}c=H[H[a+48>>2]+64>>2];if(H[c+4>>2]-H[c>>2]>>2>>>0>>0){break a}Wa(a+76|0,f);c=j+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;c:{if(!ta(c,b)){break c}h=1;while(1){d=1<>2]+(i>>>3&536870908)|0;e=e^h;if(e&1){d=H[g>>2]&(d^-1)}else{d=d|H[g>>2]}h=e^1;H[g>>2]=d;i=i+1|0;if((f|0)!=(i|0)){continue}break}c=H[b+8>>2];e=H[b+12>>2];g=e;e=H[b+20>>2];h=e;f=H[b+16>>2];d=f+4|0;e=d>>>0<4?e+1|0:e;i=d;if(d>>>0>c>>>0&(e|0)>=(g|0)|(e|0)>(g|0)){break c}l=H[b>>2];d=l+f|0;k=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=i;H[b+20>>2]=e;d=c;c=h;e=f+8|0;c=e>>>0<8?c+1|0:c;if(d>>>0>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break c}d=i+l|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;if((d|0)<(k|0)){break c}H[a+16>>2]=d;H[a+12>>2]=k;c=(d>>31)-((k>>31)+(d>>>0>>0)|0)|0;b=d-k|0;if(!c&b>>>0>2147483646|c){break c}m=1;c=b+1|0;H[a+20>>2]=c;b=c>>>1|0;H[a+24>>2]=b;H[a+28>>2]=0-b;if(c&1){break c}H[a+24>>2]=b-1}}ca=j+32|0;return m|0}function lj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;j=ca-32|0;ca=j;H[j+28>>2]=0;a:{b:{if(J[b+38>>1]<=513){c=H[b+20>>2];d=H[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;h=H[b+12>>2];if(K[b+8>>2]>>0&(h|0)<=(c|0)|(c|0)>(h|0)){break a}d=d+H[b>>2]|0;f=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;break b}if(!Xa(1,j+28|0,b)){break a}f=H[j+28>>2]}if(!f){break a}c=H[a+48>>2];if(H[c+4>>2]-H[c>>2]>>2>>>0>>0){break a}Wa(a+76|0,f);c=j+8|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;c:{if(!ta(c,b)){break c}h=1;while(1){d=1<>2]+(i>>>3&536870908)|0;e=e^h;if(e&1){d=H[g>>2]&(d^-1)}else{d=d|H[g>>2]}h=e^1;H[g>>2]=d;i=i+1|0;if((f|0)!=(i|0)){continue}break}c=H[b+8>>2];e=H[b+12>>2];g=e;e=H[b+20>>2];h=e;f=H[b+16>>2];d=f+4|0;e=d>>>0<4?e+1|0:e;i=d;if(d>>>0>c>>>0&(e|0)>=(g|0)|(e|0)>(g|0)){break c}l=H[b>>2];d=l+f|0;k=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=i;H[b+20>>2]=e;d=c;c=h;e=f+8|0;c=e>>>0<8?c+1|0:c;if(d>>>0>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break c}d=i+l|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;if((d|0)<(k|0)){break c}H[a+16>>2]=d;H[a+12>>2]=k;c=(d>>31)-((k>>31)+(d>>>0>>0)|0)|0;b=d-k|0;if(!c&b>>>0>2147483646|c){break c}m=1;c=b+1|0;H[a+20>>2]=c;b=c>>>1|0;H[a+24>>2]=b;H[a+28>>2]=0-b;if(c&1){break c}H[a+24>>2]=b-1}}ca=j+32|0;return m|0}function cj(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;H[a+8>>2]=e;m=a+32|0;h=H[m>>2];g=H[a+36>>2]-h>>2;a:{if(g>>>0>>0){ya(m,e-g|0);f=H[a+8>>2];break a}f=e;if(f>>>0>=g>>>0){break a}H[a+36>>2]=h+(e<<2);f=e}g=e>>>0>1073741823?-1:e<<2;n=ra(pa(g),0,g);b:{if((f|0)<=0){break b}h=H[a+32>>2];while(1){f=i<<2;g=H[f+n>>2];j=H[a+16>>2];c:{if((g|0)>(j|0)){H[f+h>>2]=j;break c}f=f+h|0;j=H[a+12>>2];if((j|0)>(g|0)){H[f>>2]=j;break c}H[f>>2]=g}f=H[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}if((f|0)<=0){break b}i=0;while(1){g=i<<2;f=g+c|0;g=H[b+g>>2]+H[g+h>>2]|0;H[f>>2]=g;d:{if((g|0)>H[a+16>>2]){g=g-H[a+20>>2]|0}else{if((g|0)>=H[a+12>>2]){break d}g=g+H[a+20>>2]|0}H[f>>2]=g}f=H[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}}if(!((d|0)<=(e|0)|(f|0)<=0)){p=0-e<<2;g=e;while(1){e:{if((f|0)<=0){break e}l=g<<2;o=l+c|0;q=o+p|0;j=H[m>>2];i=0;while(1){f=i<<2;h=H[f+q>>2];k=H[a+16>>2];f:{if((h|0)>(k|0)){H[f+j>>2]=k;break f}f=f+j|0;k=H[a+12>>2];if((k|0)>(h|0)){H[f>>2]=k;break f}H[f>>2]=h}f=H[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}i=0;if((f|0)<=0){break e}l=b+l|0;while(1){h=i<<2;f=h+o|0;h=H[h+l>>2]+H[h+j>>2]|0;H[f>>2]=h;g:{if((h|0)>H[a+16>>2]){h=h-H[a+20>>2]|0}else{if((h|0)>=H[a+12>>2]){break g}h=h+H[a+20>>2]|0}H[f>>2]=h}f=H[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}}g=e+g|0;if((g|0)<(d|0)){continue}break}}oa(n);return 1}function De(a,b){var c=0,d=0,e=0,f=0,g=0;d=-1;f=-1;a:{if((b|0)==-1){break a}c=b+1|0;d=(c>>>0)%3|0?c:b-2|0;f=b-1|0;if((b>>>0)%3|0){break a}f=b+2|0}b:{c:{d:{e:{f:{g:{e=H[a+184>>2];switch(e|0){case 7:break d;case 3:break e;case 5:break f;case 0:case 1:break g;default:break b}}g=H[a+148>>2];c=-1;e=1;d=((d|0)!=-1?H[H[g>>2]+(d<<2)>>2]:c)<<2;c=H[a+156>>2];d=d+c|0;H[d>>2]=H[d>>2]+1;c=(((f|0)==-1?-1:H[H[g>>2]+(f<<2)>>2])<<2)+c|0;break c}g=H[a+148>>2];c=H[a+156>>2];e=c+(((b|0)==-1?-1:H[H[g>>2]+(b<<2)>>2])<<2)|0;H[e>>2]=H[e>>2]+1;d=(((d|0)==-1?-1:H[H[g>>2]+(d<<2)>>2])<<2)+c|0;H[d>>2]=H[d>>2]+1;e=2;c=(((f|0)==-1?-1:H[H[g>>2]+(f<<2)>>2])<<2)+c|0;break c}g=H[a+148>>2];c=H[a+156>>2];e=c+(((b|0)==-1?-1:H[H[g>>2]+(b<<2)>>2])<<2)|0;H[e>>2]=H[e>>2]+1;d=(((d|0)==-1?-1:H[H[g>>2]+(d<<2)>>2])<<2)+c|0;H[d>>2]=H[d>>2]+2;e=1;c=(((f|0)==-1?-1:H[H[g>>2]+(f<<2)>>2])<<2)+c|0;break c}g=H[a+148>>2];c=H[a+156>>2];e=c+(((b|0)==-1?-1:H[H[g>>2]+(b<<2)>>2])<<2)|0;H[e>>2]=H[e>>2]+2;d=(((d|0)==-1?-1:H[H[g>>2]+(d<<2)>>2])<<2)+c|0;H[d>>2]=H[d>>2]+2;e=2;c=(((f|0)==-1?-1:H[H[g>>2]+(f<<2)>>2])<<2)+c|0}H[c>>2]=H[c>>2]+e;e=H[a+184>>2]}h:{switch(e|0){case 0:case 5:f=H[a+156>>2];c=-1;i:{if((b|0)==-1){break i}d=b+1|0;b=(d>>>0)%3|0?d:b-2|0;c=-1;if((b|0)==-1){break i}c=H[H[H[a+148>>2]>>2]+(b<<2)>>2]}if(H[f+(c<<2)>>2]<=5){H[a+188>>2]=5;return}H[a+188>>2]=0;return;default:break h}}H[a+188>>2]=-1}function xg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;j=H[b+80>>2];b=I[c+24|0];g=N(j,b);a:{if(!b){break a}h=b<<2;f=pa(h);a=f;k=b&7;if(k){while(1){H[a>>2]=-1073741824;a=a+4|0;e=e+1|0;if((k|0)!=(e|0)){continue}break}}if((b-1&1073741823)>>>0<7){break a}e=f+h|0;while(1){H[a+24>>2]=-1073741824;H[a+28>>2]=-1073741824;H[a+16>>2]=-1073741824;H[a+20>>2]=-1073741824;H[a+8>>2]=-1073741824;H[a+12>>2]=-1073741824;H[a>>2]=-1073741824;H[a+4>>2]=-1073741824;a=a+32|0;if((e|0)!=(a|0)){continue}break}}e=H[d>>2];a=H[d+4>>2]-e>>2;b:{if(a>>>0>>0){ya(d,g-a|0);break b}if(a>>>0<=g>>>0){break b}H[d+4>>2]=e+(g<<2)}c:{d:{e:{if(!j){i=1;break e}if(!b){a=0;while(1){if(!Va(c,I[c+84|0]?a:H[H[c+68>>2]+(a<<2)>>2],F[c+24|0],f)){break e}a=a+1|0;i=j>>>0<=a>>>0;if((a|0)!=(j|0)){continue}break}break e}n=b&252;k=b&3;o=b>>>0<4;e=0;b=0;while(1){if(!Va(c,I[c+84|0]?b:H[H[c+68>>2]+(b<<2)>>2],F[c+24|0],f)){break e}m=H[d>>2];i=0;a=0;l=0;if(!o){while(1){g=(e<<2)+m|0;h=a<<2;L[g>>2]=L[h+f>>2];L[g+4>>2]=L[(h|4)+f>>2];L[g+8>>2]=L[(h|8)+f>>2];L[g+12>>2]=L[(h|12)+f>>2];a=a+4|0;e=e+4|0;l=l+4|0;if((n|0)!=(l|0)){continue}break}}if(k){while(1){L[(e<<2)+m>>2]=L[(a<<2)+f>>2];a=a+1|0;e=e+1|0;i=i+1|0;if((k|0)!=(i|0)){continue}break}}b=b+1|0;i=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break d}if(!f){break c}}oa(f)}return i|0}function mf(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;e=ca-16|0;ca=e;h=1;i=ea[H[H[a>>2]+24>>2]](a)|0;a:{if((i|0)<=0){break a}l=a+48|0;h=0;while(1){b:{c:{if(!H[(ea[H[H[a>>2]+28>>2]](a)|0)+40>>2]){break c}j=f<<2;g=H[j+H[a+36>>2]>>2];b=H[g+8>>2];k=rb(g);if(!k){break c}g=H[(ea[H[H[a>>2]+28>>2]](a)|0)+40>>2];H[e+12>>2]=H[b+56>>2];b=pa(32);H[e>>2]=b;H[e+4>>2]=24;H[e+8>>2]=-2147483616;c=I[1206]|I[1207]<<8|(I[1208]<<16|I[1209]<<24);d=I[1202]|I[1203]<<8|(I[1204]<<16|I[1205]<<24);F[b+16|0]=d;F[b+17|0]=d>>>8;F[b+18|0]=d>>>16;F[b+19|0]=d>>>24;F[b+20|0]=c;F[b+21|0]=c>>>8;F[b+22|0]=c>>>16;F[b+23|0]=c>>>24;c=I[1198]|I[1199]<<8|(I[1200]<<16|I[1201]<<24);d=I[1194]|I[1195]<<8|(I[1196]<<16|I[1197]<<24);F[b+8|0]=d;F[b+9|0]=d>>>8;F[b+10|0]=d>>>16;F[b+11|0]=d>>>24;F[b+12|0]=c;F[b+13|0]=c>>>8;F[b+14|0]=c>>>16;F[b+15|0]=c>>>24;c=I[1190]|I[1191]<<8|(I[1192]<<16|I[1193]<<24);d=I[1186]|I[1187]<<8|(I[1188]<<16|I[1189]<<24);F[b|0]=d;F[b+1|0]=d>>>8;F[b+2|0]=d>>>16;F[b+3|0]=d>>>24;F[b+4|0]=c;F[b+5|0]=c>>>8;F[b+6|0]=c>>>16;F[b+7|0]=c>>>24;F[b+24|0]=0;b=sd(g,e+12|0,e);if(F[e+11|0]<0){oa(H[e>>2])}if(!b){break c}oe(H[H[H[a+36>>2]+j>>2]+8>>2],k);break b}b=H[H[a+36>>2]+(f<<2)>>2];if(!(ea[H[H[b>>2]+24>>2]](b,l)|0)){break a}}f=f+1|0;h=(i|0)<=(f|0);if((f|0)!=(i|0)){continue}break}}ca=e+16|0;return h|0}function Ye(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;k=ca-16|0;ca=k;c=H[b+20>>2];d=H[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;g=H[b+12>>2];a:{if(K[b+8>>2]>>0&(g|0)<=(c|0)|(c|0)>(g|0)){break a}d=d+H[b>>2]|0;h=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;if((h|0)<0){break a}Wa(a+76|0,h);c=k;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;b:{if(!ta(c,b)){break b}if(h){g=1;while(1){d=1<>2]+(i>>>3&536870908)|0;e=e^g;if(e&1){d=H[f>>2]&(d^-1)}else{d=d|H[f>>2]}g=e^1;H[f>>2]=d;i=i+1|0;if((h|0)!=(i|0)){continue}break}}i=0;c=H[b+8>>2];e=H[b+12>>2];f=e;e=H[b+20>>2];g=e;l=H[b+16>>2];d=l+4|0;e=d>>>0<4?e+1|0:e;h=d;if(d>>>0>c>>>0&(e|0)>=(f|0)|(e|0)>(f|0)){break b}m=H[b>>2];d=m+l|0;j=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=h;H[b+20>>2]=e;d=c;c=g;e=l+8|0;c=e>>>0<8?c+1|0:c;if(d>>>0>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break b}d=h+m|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;if((d|0)<(j|0)){break b}H[a+16>>2]=d;H[a+12>>2]=j;c=(d>>31)-((j>>31)+(d>>>0>>0)|0)|0;b=d-j|0;if(!c&b>>>0>2147483646|c){break b}i=1;c=b+1|0;H[a+20>>2]=c;b=c>>>1|0;H[a+24>>2]=b;H[a+28>>2]=0-b;if(c&1){break b}H[a+24>>2]=b-1}}ca=k+16|0;return i|0}function rg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=ca-16|0;ca=k;j=H[b+80>>2];e=I[c+24|0];b=N(j,e);a:{b:{c:{d:{f=H[c+28>>2];if(!(!I[c+84|0]|(f|0)!=5&(f|0)!=6)){e=H[c+48>>2];c=H[H[c>>2]>>2];H[k+8>>2]=0;H[k>>2]=0;H[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<2;a=pa(b);g=qa(a,c+e|0,b)+b|0}b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}H[d+8>>2]=g;H[d+4>>2]=g;H[d>>2]=a;h=1;break a}if(e){f=e<<2;a=pa(f);ra(a,0,f)}i=H[d>>2];f=H[d+4>>2]-i>>2;e:{if(f>>>0>>0){ya(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}H[d+4>>2]=i+(b<<2)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!dc(c,I[c+84|0]?b:H[H[c+68>>2]+(b<<2)>>2],F[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!dc(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],a)){break c}n=H[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<2)+n|0;i=b<<2;H[f>>2]=H[i+a>>2];H[f+4>>2]=H[(i|4)+a>>2];H[f+8>>2]=H[(i|8)+a>>2];H[f+12>>2]=H[(i|12)+a>>2];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){H[(g<<2)+n>>2]=H[(b<<2)+a>>2];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}sa();v()}if(!a){break a}}oa(a)}ca=k+16|0;return h|0}function ge(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=ca-16|0;ca=k;j=H[b+80>>2];e=I[c+24|0];b=N(j,e);a:{b:{c:{d:{f=H[c+28>>2];if(!(!I[c+84|0]|(f|0)!=5&(f|0)!=6)){e=H[c+48>>2];c=H[H[c>>2]>>2];H[k+8>>2]=0;H[k>>2]=0;H[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<2;a=pa(b);g=qa(a,c+e|0,b)+b|0}b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}H[d+8>>2]=g;H[d+4>>2]=g;H[d>>2]=a;h=1;break a}if(e){f=e<<2;a=pa(f);ra(a,0,f)}i=H[d>>2];f=H[d+4>>2]-i>>2;e:{if(f>>>0>>0){ya(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}H[d+4>>2]=i+(b<<2)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!ec(c,I[c+84|0]?b:H[H[c+68>>2]+(b<<2)>>2],F[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!ec(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],a)){break c}n=H[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<2)+n|0;i=b<<2;H[f>>2]=H[i+a>>2];H[f+4>>2]=H[(i|4)+a>>2];H[f+8>>2]=H[(i|8)+a>>2];H[f+12>>2]=H[(i|12)+a>>2];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){H[(g<<2)+n>>2]=H[(b<<2)+a>>2];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}sa();v()}if(!a){break a}}oa(a)}ca=k+16|0;return h|0}function tg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=ca-16|0;ca=k;j=H[b+80>>2];e=I[c+24|0];b=N(j,e);a:{b:{c:{d:{f=H[c+28>>2];if(!(!I[c+84|0]|(f|0)!=3&(f|0)!=4)){e=H[c+48>>2];c=H[H[c>>2]>>2];H[k+8>>2]=0;H[k>>2]=0;H[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<1;a=pa(b);g=qa(a,c+e|0,b)+b|0}b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}H[d+8>>2]=g;H[d+4>>2]=g;H[d>>2]=a;h=1;break a}if(e){f=e<<1;a=pa(f);ra(a,0,f)}i=H[d>>2];f=H[d+4>>2]-i>>1;e:{if(f>>>0>>0){qe(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}H[d+4>>2]=i+(b<<1)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!gc(c,I[c+84|0]?b:H[H[c+68>>2]+(b<<2)>>2],F[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!gc(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],a)){break c}n=H[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<1)+n|0;i=b<<1;G[f>>1]=J[i+a>>1];G[f+2>>1]=J[(i|2)+a>>1];G[f+4>>1]=J[(i|4)+a>>1];G[f+6>>1]=J[(i|6)+a>>1];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){G[(g<<1)+n>>1]=J[(b<<1)+a>>1];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}sa();v()}if(!a){break a}}oa(a)}ca=k+16|0;return h|0}function sg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=ca-16|0;ca=k;j=H[b+80>>2];e=I[c+24|0];b=N(j,e);a:{b:{c:{d:{f=H[c+28>>2];if(!(!I[c+84|0]|(f|0)!=3&(f|0)!=4)){e=H[c+48>>2];c=H[H[c>>2]>>2];H[k+8>>2]=0;H[k>>2]=0;H[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<1;a=pa(b);g=qa(a,c+e|0,b)+b|0}b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}H[d+8>>2]=g;H[d+4>>2]=g;H[d>>2]=a;h=1;break a}if(e){f=e<<1;a=pa(f);ra(a,0,f)}i=H[d>>2];f=H[d+4>>2]-i>>1;e:{if(f>>>0>>0){qe(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}H[d+4>>2]=i+(b<<1)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!fc(c,I[c+84|0]?b:H[H[c+68>>2]+(b<<2)>>2],F[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!fc(c,I[c+84|0]?e:H[H[c+68>>2]+(e<<2)>>2],F[c+24|0],a)){break c}n=H[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<1)+n|0;i=b<<1;G[f>>1]=J[i+a>>1];G[f+2>>1]=J[(i|2)+a>>1];G[f+4>>1]=J[(i|4)+a>>1];G[f+6>>1]=J[(i|6)+a>>1];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){G[(g<<1)+n>>1]=J[(b<<1)+a>>1];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}sa();v()}if(!a){break a}}oa(a)}ca=k+16|0;return h|0}function Ce(a,b){var c=0,d=0,e=0,f=0,g=0;f=-1;d=-1;a:{if((b|0)==-1){break a}d=b+1|0;f=(d>>>0)%3|0?d:b-2|0;d=b-1|0;if((b>>>0)%3|0){break a}d=b+2|0}b:{c:{d:{switch(H[a+168>>2]){case 0:case 1:e=H[a+148>>2];c=1;b=H[a+156>>2];g=b+(((f|0)==-1?-1:H[H[e>>2]+(f<<2)>>2])<<2)|0;H[g>>2]=H[g>>2]+1;b=(((d|0)==-1?-1:H[H[e>>2]+(d<<2)>>2])<<2)+b|0;break c;case 5:e=H[a+148>>2];c=-1;c=((b|0)!=-1?H[H[e>>2]+(b<<2)>>2]:c)<<2;b=H[a+156>>2];c=c+b|0;H[c>>2]=H[c>>2]+1;c=(((f|0)==-1?-1:H[H[e>>2]+(f<<2)>>2])<<2)+b|0;H[c>>2]=H[c>>2]+1;c=2;b=(((d|0)==-1?-1:H[H[e>>2]+(d<<2)>>2])<<2)+b|0;break c;case 3:e=H[a+148>>2];c=-1;c=((b|0)!=-1?H[H[e>>2]+(b<<2)>>2]:c)<<2;b=H[a+156>>2];c=c+b|0;H[c>>2]=H[c>>2]+1;c=(((f|0)==-1?-1:H[H[e>>2]+(f<<2)>>2])<<2)+b|0;H[c>>2]=H[c>>2]+2;c=1;b=(((d|0)==-1?-1:H[H[e>>2]+(d<<2)>>2])<<2)+b|0;break c;case 7:break d;default:break b}}e=H[a+148>>2];c=-1;c=((b|0)!=-1?H[H[e>>2]+(b<<2)>>2]:c)<<2;b=H[a+156>>2];c=c+b|0;H[c>>2]=H[c>>2]+2;c=(((f|0)==-1?-1:H[H[e>>2]+(f<<2)>>2])<<2)+b|0;H[c>>2]=H[c>>2]+2;c=2;b=(((d|0)==-1?-1:H[H[e>>2]+(d<<2)>>2])<<2)+b|0}H[b>>2]=H[b>>2]+c}c=a;b=H[H[a+156>>2]+(((f|0)==-1?-1:H[H[H[a+148>>2]>>2]+(f<<2)>>2])<<2)>>2];d=H[a+180>>2];a=H[a+176>>2];H[c+172>>2]=(a|0)<=(b|0)?((b|0)<(d|0)?b:d)-a|0:0}function Ac(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;H[a+24>>2]=0;f=H[b+4>>2];g=H[b>>2];e=f-g|0;c=(e|0)/20|0;a:{if((f|0)==(g|0)){break a}b:{if(c>>>0<214748365){f=pa(e);H[a+20>>2]=f;H[a+16>>2]=f;H[a+24>>2]=f+N(c,20);c=H[b>>2];g=H[b+4>>2];if((c|0)==(g|0)){break a}b=f;while(1){e=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=e;H[b+16>>2]=H[c+16>>2];e=H[c+12>>2];H[b+8>>2]=H[c+8>>2];H[b+12>>2]=e;b=b+20|0;c=c+20|0;if((g|0)!=(c|0)){continue}break}g=0;H[a+28>>2]=0;H[a+20>>2]=b;if((b|0)!=(f|0)){b=(b-f|0)/20|0;e=b>>>0<=1?1:b;h=e&3;b=0;c=0;if(e-1>>>0>=3){i=e&-4;e=0;while(1){d=f+N(b,20)|0;d=N(H[d+16>>2],H[d+12>>2]);c=c>>>0>d>>>0?c:d;d=f+N(b|1,20)|0;d=N(H[d+16>>2],H[d+12>>2]);c=c>>>0>d>>>0?c:d;d=f+N(b|2,20)|0;d=N(H[d+16>>2],H[d+12>>2]);c=c>>>0>d>>>0?c:d;d=f+N(b|3,20)|0;d=N(H[d+16>>2],H[d+12>>2]);c=c>>>0>d>>>0?c:d;b=b+4|0;e=e+4|0;if((i|0)!=(e|0)){continue}break}}if(h){while(1){e=f+N(b,20)|0;e=N(H[e+16>>2],H[e+12>>2]);c=c>>>0>e>>>0?c:e;b=b+1|0;g=g+1|0;if((h|0)!=(g|0)){continue}break}}if(!c){H[a+12>>2]=0;return a}if((c|0)<0){break b}g=pa(c);b=ra(g,0,c);f=b+c|0;H[a+8>>2]=f;H[a+4>>2]=f;H[a>>2]=b}H[a+12>>2]=g;return a}sa();v()}sa();v()}H[a+28>>2]=0;H[a+12>>2]=0;return a}function Dh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;a:{b=H[a+32>>2];f=H[b+8>>2];h=H[b+12>>2];g=H[b+20>>2];c=H[b+16>>2];e=0;b:{if((h|0)<=(g|0)&c>>>0>=f>>>0|(g|0)>(h|0)){break b}f=I[H[b>>2]+c|0];e=b;b=g;c=c+1|0;b=c?b:b+1|0;H[e+16>>2]=c;H[e+20>>2]=b;c:{if(!f){break c}while(1){if(ea[H[H[a>>2]+16>>2]](a,d)|0){d=d+1|0;if((f|0)!=(d|0)){continue}break c}break}return 0}d=H[a+8>>2];b=H[a+12>>2];if((d|0)!=(b|0)){while(1){c=H[d>>2];if(!(ea[H[H[c>>2]+8>>2]](c,a,H[a+4>>2])|0)){break a}d=d+4|0;if((b|0)!=(d|0)){continue}break}}d:{if(!f){break d}d=0;while(1){b=H[H[a+8>>2]+(d<<2)>>2];if(!(ea[H[H[b>>2]+12>>2]](b,H[a+32>>2])|0)){break a}d=d+1|0;if((f|0)!=(d|0)){continue}break}if(!f){break d}i=a+20|0;b=0;while(1){d=0;j=b<<2;c=H[j+H[a+8>>2]>>2];k=ea[H[H[c>>2]+24>>2]](c)|0;if((k|0)>0){while(1){c=H[H[a+8>>2]+j>>2];c=ea[H[H[c>>2]+20>>2]](c,d)|0;e=H[a+20>>2];g=H[a+24>>2]-e>>2;e:{if(c>>>0>>0){break e}h=c+1|0;if(h>>>0>g>>>0){ya(i,h-g|0);e=H[i>>2];break e}if(g>>>0<=h>>>0){break e}H[a+24>>2]=(h<<2)+e}H[(c<<2)+e>>2]=b;d=d+1|0;if((k|0)!=(d|0)){continue}break}}b=b+1|0;if((f|0)!=(b|0)){continue}break}}e=0;if(!(ea[H[H[a>>2]+28>>2]](a)|0)){break b}e=ea[H[H[a>>2]+32>>2]](a)|0}return e|0}return 0}function ta(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;i=ca-16|0;ca=i;f=H[b+20>>2];d=H[b+12>>2];c=H[b+16>>2];a:{if((f|0)>=(d|0)&c>>>0>=K[b+8>>2]|(d|0)<(f|0)){break a}F[a+12|0]=I[c+H[b>>2]|0];c=H[b+20>>2];g=c;f=H[b+16>>2];e=f+1|0;c=e?c:c+1|0;H[b+16>>2]=e;H[b+20>>2]=c;b:{if(J[b+38>>1]<=513){d=H[b+8>>2];c=H[b+12>>2];h=c;c=g;f=f+5|0;c=f>>>0<5?c+1|0:c;if(d>>>0>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break a}e=e+H[b>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=c;break b}if(!Qe(1,i+12|0,b)){break a}f=H[b+16>>2];c=H[b+20>>2];d=H[b+8>>2];h=H[b+12>>2];e=H[i+12>>2]}g=d-f|0;d=h-(c+(d>>>0>>0)|0)|0;if((d|0)<=0&e>>>0>g>>>0|(d|0)<0|(e|0)<=0){break a}j=H[b>>2]+f|0;H[a>>2]=j;c:{d:{h=e-1|0;g=h+j|0;d=I[g|0];e:{if(d>>>0<=63){H[a+4>>2]=h;g=I[g|0]&63;break e}f:{switch((d>>>6|0)-1|0){case 1:break d;case 0:break f;default:break a}}if(e>>>0<2){break a}d=e-2|0;H[a+4>>2]=d;d=d+j|0;g=I[d+1|0]<<8&16128|I[d|0]}H[a+8>>2]=g+4096;break c}if(e>>>0<3){break a}d=e-3|0;H[a+4>>2]=d;g=a;a=d+j|0;a=I[a+1|0]<<8|I[a+2|0]<<16&4128768|I[a|0];H[g+8>>2]=a+4096;if(a>>>0>1044479){break a}}a=e+f|0;c=a>>>0>>0?c+1|0:c;H[b+16>>2]=a;H[b+20>>2]=c;k=1}ca=i+16|0;return k}function Wf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;Xd(a,b,c);c=H[a+84>>2];d=H[a+88>>2]-c>>2;a:{if((d|0)>(b|0)){break a}b=b+1|0;if(b>>>0>d>>>0){b:{d=b-d|0;e=H[a+92>>2];c=H[a+88>>2];if(d>>>0<=e-c>>2>>>0){c:{if(!d){break c}b=c;e=d&7;if(e){while(1){H[b>>2]=1;b=b+4|0;f=f+1|0;if((e|0)!=(f|0)){continue}break}}c=(d<<2)+c|0;if((d-1&1073741823)>>>0<7){break c}while(1){H[b+24>>2]=1;H[b+28>>2]=1;H[b+16>>2]=1;H[b+20>>2]=1;H[b+8>>2]=1;H[b+12>>2]=1;H[b>>2]=1;H[b+4>>2]=1;b=b+32|0;if((c|0)!=(b|0)){continue}break}}H[a+88>>2]=c;break b}d:{b=c;c=H[a+84>>2];i=b-c|0;g=i>>2;b=g+d|0;if(b>>>0<1073741824){e=e-c|0;h=e>>>1|0;e=e>>>0>=2147483644?1073741823:b>>>0>>0?h:b;if(e){if(e>>>0>=1073741824){break d}j=pa(e<<2)}g=(g<<2)+j|0;b=g;h=d&7;if(h){while(1){H[b>>2]=1;b=b+4|0;f=f+1|0;if((h|0)!=(f|0)){continue}break}}f=g+(d<<2)|0;if((d-1&1073741823)>>>0>=7){while(1){H[b+24>>2]=1;H[b+28>>2]=1;H[b+16>>2]=1;H[b+20>>2]=1;H[b+8>>2]=1;H[b+12>>2]=1;H[b>>2]=1;H[b+4>>2]=1;b=b+32|0;if((f|0)!=(b|0)){continue}break}}b=va(j,c,i);H[a+88>>2]=f;H[a+84>>2]=b;H[a+92>>2]=b+(e<<2);if(c){oa(c)}break b}sa();v()}wa();v()}return}if(b>>>0>=d>>>0){break a}H[a+88>>2]=c+(b<<2)}}function qb(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=H[a+8>>2];e=H[a+4>>2];if(d-e>>2>>>0>=b>>>0){a:{if(!b){break a}d=e;g=b&7;if(g){while(1){H[d>>2]=H[c>>2];d=d+4|0;f=f+1|0;if((g|0)!=(f|0)){continue}break}}e=(b<<2)+e|0;if((b-1&1073741823)>>>0<7){break a}while(1){H[d>>2]=H[c>>2];H[d+4>>2]=H[c>>2];H[d+8>>2]=H[c>>2];H[d+12>>2]=H[c>>2];H[d+16>>2]=H[c>>2];H[d+20>>2]=H[c>>2];H[d+24>>2]=H[c>>2];H[d+28>>2]=H[c>>2];d=d+32|0;if((e|0)!=(d|0)){continue}break}}H[a+4>>2]=e;return}b:{i=H[a>>2];f=e-i>>2;h=f+b|0;if(h>>>0<1073741824){j=d-i|0;d=j>>>1|0;h=j>>>0>=2147483644?1073741823:d>>>0>h>>>0?d:h;if(h){if(h>>>0>=1073741824){break b}k=pa(h<<2)}f=(f<<2)+k|0;d=f;j=b&7;if(j){while(1){H[d>>2]=H[c>>2];d=d+4|0;g=g+1|0;if((j|0)!=(g|0)){continue}break}}g=(b<<2)+f|0;if((b-1&1073741823)>>>0>=7){while(1){H[d>>2]=H[c>>2];H[d+4>>2]=H[c>>2];H[d+8>>2]=H[c>>2];H[d+12>>2]=H[c>>2];H[d+16>>2]=H[c>>2];H[d+20>>2]=H[c>>2];H[d+24>>2]=H[c>>2];H[d+28>>2]=H[c>>2];d=d+32|0;if((g|0)!=(d|0)){continue}break}}if((e|0)!=(i|0)){while(1){f=f-4|0;e=e-4|0;H[f>>2]=H[e>>2];if((e|0)!=(i|0)){continue}break}}H[a+8>>2]=(h<<2)+k;H[a+4>>2]=g;H[a>>2]=f;if(i){oa(i)}return}sa();v()}wa();v()}function Kc(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=H[a+8>>2];e=H[a>>2];if(d-e>>2>>>0>=b>>>0){f=H[a+4>>2];h=f-e>>2;i=b>>>0>h>>>0?h:b;a:{if(!i){break a}d=e;g=i;j=g&7;if(j){while(1){H[d>>2]=H[c>>2];g=g-1|0;d=d+4|0;k=k+1|0;if((k|0)!=(j|0)){continue}break}}if(i>>>0<8){break a}while(1){H[d>>2]=H[c>>2];H[d+4>>2]=H[c>>2];H[d+8>>2]=H[c>>2];H[d+12>>2]=H[c>>2];H[d+16>>2]=H[c>>2];H[d+20>>2]=H[c>>2];H[d+24>>2]=H[c>>2];H[d+28>>2]=H[c>>2];d=d+32|0;g=g-8|0;if(g){continue}break}}if(b>>>0>h>>>0){b=(b-h<<2)+f|0;while(1){H[f>>2]=H[c>>2];f=f+4|0;if((b|0)!=(f|0)){continue}break}H[a+4>>2]=b;return}H[a+4>>2]=e+(b<<2);return}if(e){H[a+4>>2]=e;oa(e);H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;d=0}b:{if(b>>>0>=1073741824){break b}e=d>>>1|0;d=d>>>0>=2147483644?1073741823:b>>>0>>0?e:b;if(d>>>0>=1073741824){break b}d=d<<2;e=pa(d);H[a>>2]=e;H[a+8>>2]=d+e;c=H[c>>2];d=e;g=b&7;if(g){while(1){H[d>>2]=c;d=d+4|0;f=f+1|0;if((g|0)!=(f|0)){continue}break}}e=e+(b<<2)|0;if((b-1&1073741823)>>>0>=7){while(1){H[d+28>>2]=c;H[d+24>>2]=c;H[d+20>>2]=c;H[d+16>>2]=c;H[d+12>>2]=c;H[d+8>>2]=c;H[d+4>>2]=c;H[d>>2]=c;d=d+32|0;if((e|0)!=(d|0)){continue}break}}H[a+4>>2]=e;return}sa();v()}function Me(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;h=ca-16|0;ca=h;a:{b:{if(J[b+38>>1]<=511){e=H[b+8>>2];c=H[b+12>>2];i=c;f=H[b+20>>2];d=H[b+16>>2];g=d+8|0;f=g>>>0<8?f+1|0:f;if(e>>>0>>0&(c|0)<=(f|0)|(c|0)<(f|0)){break a}d=d+H[b>>2]|0;c=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=I[d+4|0]|I[d+5|0]<<8|(I[d+6|0]<<16|I[d+7|0]<<24);H[b+16>>2]=g;H[b+20>>2]=f;break b}if(!gb(1,h+8|0,b)){break a}g=H[b+16>>2];f=H[b+20>>2];e=H[b+8>>2];i=H[b+12>>2];c=H[h+8>>2];d=H[h+12>>2]}j=e-g|0;e=i-(f+(e>>>0>>0)|0)|0;if((e|0)==(d|0)&c>>>0>j>>>0|d>>>0>e>>>0){break a}e=d+f|0;f=c+g|0;e=f>>>0>>0?e+1|0:e;H[b+16>>2]=f;H[b+20>>2]=e;if((c|0)<=0){break a}b=H[b>>2]+g|0;H[a+40>>2]=b;g=c-1|0;e=b+g|0;f=I[e|0];c:{if(f>>>0<=63){H[a+44>>2]=g;b=I[e|0]&63;break c}d:{switch((f>>>6|0)-1|0){case 0:if(c>>>0<2){break a}c=c-2|0;H[a+44>>2]=c;b=b+c|0;b=I[b+1|0]<<8&16128|I[b|0];break c;case 1:if(c>>>0<3){break a}c=c-3|0;H[a+44>>2]=c;b=b+c|0;b=I[b+1|0]<<8|I[b+2|0]<<16&4128768|I[b|0];break c;default:break d}}c=c-4|0;H[a+44>>2]=c;b=b+c|0;b=(I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24))&1073741823}H[a+48>>2]=b+16384;k=b>>>0<4177920}ca=h+16|0;return k}function Ua(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;f=(c>>>0)/3|0;j=H[(H[H[a+8>>2]+96>>2]+N(f,12)|0)+(c-N(f,3)<<2)>>2];a:{h=H[H[a+12>>2]+4>>2];e=H[h+4>>2];if((e|0)!=H[h+8>>2]){H[e>>2]=j;H[h+4>>2]=e+4;break a}b:{i=H[h>>2];f=e-i|0;g=f>>2;d=g+1|0;if(d>>>0<1073741824){k=g<<2;g=f>>>1|0;g=f>>>0>=2147483644?1073741823:d>>>0>>0?g:d;if(g){if(g>>>0>=1073741824){break b}f=pa(g<<2)}else{f=0}d=k+f|0;H[d>>2]=j;j=d+4|0;if((e|0)!=(i|0)){while(1){d=d-4|0;e=e-4|0;H[d>>2]=H[e>>2];if((e|0)!=(i|0)){continue}break}}H[h+8>>2]=f+(g<<2);H[h+4>>2]=j;H[h>>2]=d;if(i){oa(i)}break a}sa();v()}wa();v()}c:{d:{h=H[a+4>>2];e=H[h+4>>2];e:{if((e|0)!=H[h+8>>2]){H[e>>2]=c;H[h+4>>2]=e+4;break e}i=H[h>>2];f=e-i|0;j=f>>2;d=j+1|0;if(d>>>0>=1073741824){break d}g=f>>>1|0;g=f>>>0>=2147483644?1073741823:d>>>0>>0?g:d;if(g){if(g>>>0>=1073741824){break c}f=pa(g<<2)}else{f=0}d=f+(j<<2)|0;H[d>>2]=c;c=d+4|0;if((e|0)!=(i|0)){while(1){d=d-4|0;e=e-4|0;H[d>>2]=H[e>>2];if((e|0)!=(i|0)){continue}break}}H[h+8>>2]=f+(g<<2);H[h+4>>2]=c;H[h>>2]=d;if(!i){break e}oa(i)}a=H[a+4>>2];H[H[a+12>>2]+(b<<2)>>2]=H[a+24>>2];H[a+24>>2]=H[a+24>>2]+1;return}sa();v()}wa();v()}function Wb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0;h=d-c|0;if((h|0)<=0){return}a:{e=H[a+8>>2];i=H[a+4>>2];if((e-i|0)>=(h|0)){j=i-b|0;if((j|0)>=(h|0)){f=i;g=d;break a}f=i;g=c+j|0;if((g|0)!=(d|0)){e=g;while(1){F[f|0]=I[e|0];f=f+1|0;e=e+1|0;if((e|0)!=(d|0)){continue}break}}H[a+4>>2]=f;if((j|0)>0){break a}return}k=H[a>>2];g=(i-k|0)+h|0;if((g|0)>=0){j=b-k|0;f=e-k|0;e=f<<1;f=f>>>0>=1073741823?2147483647:e>>>0>g>>>0?e:g;if(f){e=pa(f)}else{e=0}g=j+e|0;if((c|0)!=(d|0)){g=qa(g,c,h)+h|0}d=va(e,k,j);c=i-b|0;b=va(g,b,c);H[a+8>>2]=e+f;H[a+4>>2]=b+c;H[a>>2]=d;if(k){oa(k)}return}sa();v()}e=f;d=e-h|0;if(i>>>0>d>>>0){while(1){F[e|0]=I[d|0];e=e+1|0;d=d+1|0;if(i>>>0>d>>>0){continue}break}}H[a+4>>2]=e;a=b+h|0;if((a|0)!=(f|0)){a=f-a|0;va(f-a|0,b,a)}if((c|0)==(g|0)){return}f=(c^-1)+g|0;a=g-c&7;b:{if(!a){e=b;break b}d=0;e=b;while(1){F[e|0]=I[c|0];e=e+1|0;c=c+1|0;d=d+1|0;if((a|0)!=(d|0)){continue}break}}if(f>>>0<7){return}while(1){F[e|0]=I[c|0];F[e+1|0]=I[c+1|0];F[e+2|0]=I[c+2|0];F[e+3|0]=I[c+3|0];F[e+4|0]=I[c+4|0];F[e+5|0]=I[c+5|0];F[e+6|0]=I[c+6|0];F[e+7|0]=I[c+7|0];e=e+8|0;c=c+8|0;if((g|0)!=(c|0)){continue}break}}function qa(a,b,c){var d=0,e=0,f=0;if(c>>>0>=512){ba(a|0,b|0,c|0);return a}e=a+c|0;a:{if(!((a^b)&3)){b:{if(!(a&3)){c=a;break b}if(!c){c=a;break b}c=a;while(1){F[c|0]=I[b|0];b=b+1|0;c=c+1|0;if(!(c&3)){break b}if(c>>>0>>0){continue}break}}d=e&-4;c:{if(d>>>0<64){break c}f=d+-64|0;if(f>>>0>>0){break c}while(1){H[c>>2]=H[b>>2];H[c+4>>2]=H[b+4>>2];H[c+8>>2]=H[b+8>>2];H[c+12>>2]=H[b+12>>2];H[c+16>>2]=H[b+16>>2];H[c+20>>2]=H[b+20>>2];H[c+24>>2]=H[b+24>>2];H[c+28>>2]=H[b+28>>2];H[c+32>>2]=H[b+32>>2];H[c+36>>2]=H[b+36>>2];H[c+40>>2]=H[b+40>>2];H[c+44>>2]=H[b+44>>2];H[c+48>>2]=H[b+48>>2];H[c+52>>2]=H[b+52>>2];H[c+56>>2]=H[b+56>>2];H[c+60>>2]=H[b+60>>2];b=b- -64|0;c=c- -64|0;if(f>>>0>=c>>>0){continue}break}}if(c>>>0>=d>>>0){break a}while(1){H[c>>2]=H[b>>2];b=b+4|0;c=c+4|0;if(d>>>0>c>>>0){continue}break}break a}if(e>>>0<4){c=a;break a}d=e-4|0;if(d>>>0>>0){c=a;break a}c=a;while(1){F[c|0]=I[b|0];F[c+1|0]=I[b+1|0];F[c+2|0]=I[b+2|0];F[c+3|0]=I[b+3|0];b=b+4|0;c=c+4|0;if(d>>>0>=c>>>0){continue}break}}if(c>>>0>>0){while(1){F[c|0]=I[b|0];b=b+1|0;c=c+1|0;if((e|0)!=(c|0)){continue}break}}return a}function ub(a,b){var c=0,d=0,e=0,f=0,g=0;d=ca-16|0;ca=d;H[a+12>>2]=b;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;c=a+16|0;H[c>>2]=0;H[c+4>>2]=0;F[c+5|0]=0;F[c+6|0]=0;F[c+7|0]=0;F[c+8|0]=0;F[c+9|0]=0;F[c+10|0]=0;F[c+11|0]=0;F[c+12|0]=0;H[a+32>>2]=0;H[a+36>>2]=0;H[a+48>>2]=0;H[a+40>>2]=0;H[a+44>>2]=0;H[a+52>>2]=0;H[a+56>>2]=0;H[a+68>>2]=0;H[a+60>>2]=0;H[a+64>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;H[a+88>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+100>>2]=0;H[a+92>>2]=0;H[a+96>>2]=0;g=a+116|0;a:{b:{if(b){if(b>>>0<1073741824){break b}sa();v()}H[a+104>>2]=0;H[a+108>>2]=0;H[a+112>>2]=0;H[d+8>>2]=0;H[d>>2]=0;H[d+4>>2]=0;c=1;break a}c=b<<2;e=pa(c);H[a+92>>2]=e;f=c+e|0;H[a+100>>2]=f;ra(e,0,c);H[a+112>>2]=0;H[a+104>>2]=0;H[a+108>>2]=0;H[a+96>>2]=f;e=pa(c);H[a+104>>2]=e;f=c+e|0;H[a+112>>2]=f;ra(e,0,c);H[a+108>>2]=f;e=pa(c);H[d>>2]=e;f=c+e|0;H[d+8>>2]=f;ra(e,0,c);H[d+4>>2]=f;c=b<<5|1}tb(g,c,d);e=H[d>>2];if(e){H[d+4>>2]=e;oa(e)}H[d+8>>2]=0;H[d>>2]=0;H[d+4>>2]=0;if(b){b=b<<2;e=pa(b);H[d>>2]=e;f=b+e|0;H[d+8>>2]=f;ra(e,0,b);H[d+4>>2]=f}tb(a+128|0,c,d);b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}ca=d+16|0;return a}function ze(a){a=a|0;var b=0,c=0,d=0,e=0,f=0;H[a>>2]=11484;d=a+232|0;b=H[d+196>>2];if(b){H[d+200>>2]=b;oa(b)}c=H[d+184>>2];if(c){b=c;e=H[d+188>>2];if((b|0)!=(e|0)){while(1){b=e-12|0;f=H[b>>2];if(f){H[e-8>>2]=f;oa(f)}e=b;if((b|0)!=(c|0)){continue}break}b=H[d+184>>2]}H[d+188>>2]=c;oa(b)}b=H[d+156>>2];if(b){H[d+160>>2]=b;oa(b)}c=H[d+136>>2];H[d+136>>2]=0;if(c){e=c-4|0;b=H[e>>2];if(b){b=c+(b<<4)|0;while(1){b=b-16|0;if((c|0)!=(b|0)){continue}break}}oa(e)}Yc(a+216|0);b=H[a+196>>2];if(b){H[a+200>>2]=b;oa(b)}b=H[a+184>>2];if(b){H[a+188>>2]=b;oa(b)}b=H[a+172>>2];if(b){H[a+176>>2]=b;oa(b)}b=H[a+160>>2];if(b){H[a+164>>2]=b;oa(b)}b=H[a+144>>2];if(b){while(1){c=H[b>>2];oa(b);b=c;if(b){continue}break}}b=H[a+136>>2];H[a+136>>2]=0;if(b){oa(b)}b=H[a+120>>2];if(b){oa(b)}b=H[a+108>>2];if(b){oa(b)}b=H[a+96>>2];if(b){oa(b)}b=H[a+72>>2];if(b){H[a+76>>2]=b;oa(b)}b=H[a+60>>2];if(b){oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}b=H[a+36>>2];if(b){H[a+40>>2]=b;oa(b)}b=H[a+24>>2];if(b){H[a+28>>2]=b;oa(b)}b=H[a+12>>2];if(b){H[a+16>>2]=b;oa(b)}b=H[a+8>>2];H[a+8>>2]=0;if(b){cb(b)}return a|0}function Pa(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=H[a+8>>2];e=H[a+4>>2];if(d-e>>2>>>0>=b>>>0){a:{if(!b){break a}d=e;f=b&7;if(f){while(1){H[d>>2]=H[c>>2];d=d+4|0;h=h+1|0;if((f|0)!=(h|0)){continue}break}}e=(b<<2)+e|0;if((b-1&1073741823)>>>0<7){break a}while(1){H[d>>2]=H[c>>2];H[d+4>>2]=H[c>>2];H[d+8>>2]=H[c>>2];H[d+12>>2]=H[c>>2];H[d+16>>2]=H[c>>2];H[d+20>>2]=H[c>>2];H[d+24>>2]=H[c>>2];H[d+28>>2]=H[c>>2];d=d+32|0;if((e|0)!=(d|0)){continue}break}}H[a+4>>2]=e;return}b:{i=H[a>>2];j=e-i|0;f=j>>2;g=f+b|0;if(g>>>0<1073741824){d=d-i|0;e=d>>>1|0;g=d>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(g){if(g>>>0>=1073741824){break b}k=pa(g<<2)}f=(f<<2)+k|0;d=f;e=b&7;if(e){while(1){H[d>>2]=H[c>>2];d=d+4|0;h=h+1|0;if((e|0)!=(h|0)){continue}break}}e=f+(b<<2)|0;if((b-1&1073741823)>>>0>=7){while(1){H[d>>2]=H[c>>2];H[d+4>>2]=H[c>>2];H[d+8>>2]=H[c>>2];H[d+12>>2]=H[c>>2];H[d+16>>2]=H[c>>2];H[d+20>>2]=H[c>>2];H[d+24>>2]=H[c>>2];H[d+28>>2]=H[c>>2];d=d+32|0;if((e|0)!=(d|0)){continue}break}}b=va(k,i,j);H[a+4>>2]=e;H[a>>2]=b;H[a+8>>2]=b+(g<<2);if(i){oa(i)}return}sa();v()}wa();v()}function Cc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;if(I[a+11|0]>>>7|0){d=H[a+4>>2]}else{d=I[a+11|0]&127}if(d>>>0>>0){h=ca-16|0;ca=h;b=b-d|0;if(b){g=I[a+11|0]>>>7|0?(H[a+8>>2]&2147483647)-1|0:10;if(I[a+11|0]>>>7|0){d=H[a+4>>2]}else{d=I[a+11|0]&127}i=d+b|0;if(g-d>>>0>>0){a:{e=ca-16|0;ca=e;c=i-g|0;if(c>>>0<=2147483631-g>>>0){if(I[a+11|0]>>>7|0){f=H[a>>2]}else{f=a}if(g>>>0<1073741799){H[e+12>>2]=g<<1;H[e>>2]=c+g;c=ca-16|0;ca=c;ca=c+16|0;c=e+12|0;c=H[(K[e>>2]>2]?c:e)>>2];if(c>>>0>=11){j=c+16&-16;c=j-1|0;c=(c|0)==11?j:c}else{c=10}c=c+1|0}else{c=2147483631}Zb(e,c);c=H[e>>2];if(d){yb(c,f,d)}if((g|0)!=10){oa(f)}H[a>>2]=c;H[a+8>>2]=H[a+8>>2]&-2147483648|H[e+4>>2]&2147483647;H[a+8>>2]=H[a+8>>2]|-2147483648;ca=e+16|0;break a}Na();v()}}f=d;if(I[a+11|0]>>>7|0){d=H[a>>2]}else{d=a}f=f+d|0;e=ca-16|0;ca=e;F[e+15|0]=0;while(1){if(b){F[f|0]=I[e+15|0];b=b-1|0;f=f+1|0;continue}break}ca=e+16|0;Id(a,i);F[h+15|0]=0;F[d+i|0]=I[h+15|0]}ca=h+16|0;return}if(I[a+11|0]>>>7|0){d=H[a>>2]}else{d=a}f=ca-16|0;ca=f;Id(a,b);F[f+15|0]=0;F[b+d|0]=I[f+15|0];ca=f+16|0}function Jc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;g=ca-16|0;ca=g;a:{b:{if(b){H[a+88>>2]=0;H[a+92>>2]=0;d=H[a+84>>2];H[a+84>>2]=0;if(d){oa(d)}H[a+76>>2]=0;H[a+80>>2]=0;d=H[a+72>>2];H[a+72>>2]=0;if(d){oa(d)}d=H[b>>2];c=H[b+4>>2];F[g+15|0]=0;Oa(a,c-d>>2,g+15|0);d=H[b+28>>2];c=H[b+24>>2];F[g+14|0]=0;Oa(a+12|0,d-c>>2,g+14|0);Kc(a+28|0,H[b+4>>2]-H[b>>2]>>2,13708);c=H[b+28>>2]-H[b+24>>2]|0;f=c>>2;e=H[a+52>>2];c:{if(f>>>0<=H[a+60>>2]-e>>2>>>0){break c}if((c|0)<0){break b}d=H[a+56>>2];c=pa(c);f=c+(f<<2)|0;h=c+(d-e&-4)|0;c=h;if((d|0)!=(e|0)){while(1){c=c-4|0;d=d-4|0;H[c>>2]=H[d>>2];if((d|0)!=(e|0)){continue}break}}H[a+60>>2]=f;H[a+56>>2]=h;H[a+52>>2]=c;if(!e){break c}oa(e)}c=H[b+28>>2]-H[b+24>>2]|0;f=c>>2;e=H[a+40>>2];d:{if(f>>>0<=H[a+48>>2]-e>>2>>>0){break d}if((c|0)<0){break a}d=H[a+44>>2];c=pa(c);f=c+(f<<2)|0;h=c+(d-e&-4)|0;c=h;if((d|0)!=(e|0)){while(1){c=c-4|0;d=d-4|0;H[c>>2]=H[d>>2];if((d|0)!=(e|0)){continue}break}}H[a+48>>2]=f;H[a+44>>2]=h;H[a+40>>2]=c;if(!e){break d}oa(e)}F[a+24|0]=1;H[a+64>>2]=b}ca=g+16|0;return}sa();v()}sa();v()}function wb(a,b){var c=0,d=0,e=0,f=0,g=0;c=ca-16|0;ca=c;H[a+12>>2]=b;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+32>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;H[a+36>>2]=0;H[a+40>>2]=0;H[a+52>>2]=0;H[a+44>>2]=0;H[a+48>>2]=0;H[a+56>>2]=0;H[a+60>>2]=0;H[a+72>>2]=0;H[a+64>>2]=0;H[a+68>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+92>>2]=0;H[a+84>>2]=0;H[a+88>>2]=0;H[a+104>>2]=0;H[a+96>>2]=0;H[a+100>>2]=0;g=a+120|0;a:{b:{if(b){if(b>>>0<1073741824){break b}sa();v()}H[a+108>>2]=0;H[a+112>>2]=0;H[a+116>>2]=0;H[c+8>>2]=0;H[c>>2]=0;H[c+4>>2]=0;e=1;break a}e=b<<2;d=pa(e);H[a+96>>2]=d;f=d+e|0;H[a+104>>2]=f;ra(d,0,e);H[a+116>>2]=0;H[a+108>>2]=0;H[a+112>>2]=0;H[a+100>>2]=f;d=pa(e);H[a+108>>2]=d;f=d+e|0;H[a+116>>2]=f;ra(d,0,e);H[a+112>>2]=f;d=pa(e);H[c>>2]=d;f=d+e|0;H[c+8>>2]=f;ra(d,0,e);H[c+4>>2]=f;e=b<<5|1}tb(g,e,c);d=H[c>>2];if(d){H[c+4>>2]=d;oa(d)}H[c+8>>2]=0;H[c>>2]=0;H[c+4>>2]=0;if(b){b=b<<2;d=pa(b);H[c>>2]=d;f=b+d|0;H[c+8>>2]=f;ra(d,0,b);H[c+4>>2]=f}tb(a+132|0,e,c);b=H[c>>2];if(b){H[c+4>>2]=b;oa(b)}ca=c+16|0;return a}function Sb(a,b){var c=0,d=0,e=0;c=(a|0)==(b|0);F[b+12|0]=c;a:{if(c){break a}while(1){d=H[b+8>>2];if(I[d+12|0]){break a}b:{c=H[d+8>>2];e=H[c>>2];if((e|0)==(d|0)){e=H[c+4>>2];if(!(!e|I[e+12|0])){break b}c:{if(H[d>>2]==(b|0)){b=d;break c}b=H[d+4>>2];a=H[b>>2];H[d+4>>2]=a;if(a){H[a+8>>2]=d;c=H[d+8>>2]}H[b+8>>2]=c;a=H[d+8>>2];H[((H[a>>2]!=(d|0))<<2)+a>>2]=b;H[b>>2]=d;H[d+8>>2]=b;c=H[b+8>>2];d=H[c>>2]}F[b+12|0]=1;F[c+12|0]=0;a=H[d+4>>2];H[c>>2]=a;if(a){H[a+8>>2]=c}H[d+8>>2]=H[c+8>>2];a=H[c+8>>2];H[((H[a>>2]!=(c|0))<<2)+a>>2]=d;H[d+4>>2]=c;H[c+8>>2]=d;return}if(!(I[e+12|0]|!e)){break b}d:{if(H[d>>2]!=(b|0)){b=d;break d}a=H[b+4>>2];H[d>>2]=a;if(a){H[a+8>>2]=d;c=H[d+8>>2]}H[b+8>>2]=c;a=H[d+8>>2];H[((H[a>>2]!=(d|0))<<2)+a>>2]=b;H[b+4>>2]=d;H[d+8>>2]=b;c=H[b+8>>2]}F[b+12|0]=1;F[c+12|0]=0;a=H[c+4>>2];b=H[a>>2];H[c+4>>2]=b;if(b){H[b+8>>2]=c}H[a+8>>2]=H[c+8>>2];b=H[c+8>>2];H[((H[b>>2]!=(c|0))<<2)+b>>2]=a;H[a>>2]=c;H[c+8>>2]=a;break a}F[d+12|0]=1;F[c+12|0]=(a|0)==(c|0);F[e+12|0]=1;b=c;if((c|0)!=(a|0)){continue}break}}}function Tj(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{if(b){if(!c){break k}if(!d){break j}e=Q(d)-Q(b)|0;if(e>>>0<=31){break i}break c}if((d|0)==1|d>>>0>1){break c}da=0;a=(a>>>0)/(c>>>0)|0;break a}if(!a){break h}if(!d|d-1&d){break g}a=b>>>Qj(d)|0;da=0;break a}if(!(c-1&c)){break f}h=(Q(c)+33|0)-Q(b)|0;g=0-h|0;break d}h=e+1|0;g=63-e|0;break d}da=0;a=(b>>>0)/(d>>>0)|0;break a}e=Q(d)-Q(b)|0;if(e>>>0<31){break e}break c}if((c|0)==1){break b}d=Qj(c);c=d&31;if((d&63)>>>0>=32){a=b>>>c|0}else{e=b>>>c|0;a=((1<>>c}da=e;break a}h=e+1|0;g=63-e|0}e=h&63;f=e&31;if(e>>>0>=32){e=0;i=b>>>f|0}else{e=b>>>f|0;i=((1<>>f}g=g&63;f=g&31;if(g>>>0>=32){b=a<>>32-f|b<>>31;e=i<<1|b>>>31;f=m-(j+(e>>>0>g>>>0)|0)>>31;k=c&f;i=e-k|0;e=j-((d&f)+(e>>>0>>0)|0)|0;b=b<<1|a>>>31;a=l|a<<1;l=f&1;h=h-1|0;if(h){continue}break}}da=b<<1|a>>>31;a=l|a<<1;break a}a=0;b=0}da=b}return a}function rc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;k=H[b+16>>2];h=H[c+4>>2]-k|0;e=H[c>>2]-k|0;H[c>>2]=e;H[c+4>>2]=h;g=H[b+16>>2];f=h>>31;i=(f^h)-f|0;f=e>>31;l=g>>>0>=i+((f^e)-f|0)>>>0;a:{if(l){f=h;break a}b:{c:{if((e|0)>=0){f=1;i=1;if((h|0)>=0){break b}j=1;f=-1;i=-1;if(e){break c}break b}j=-1;f=-1;i=-1;if((h|0)<=0){break b}}f=(h|0)<=0?-1:1;i=j}j=N(g,i);e=(e<<1)-j|0;i=(N(f,i)|0)>=0;g=N(f,g);f=((i?0-e|0:e)+g|0)/2|0;H[c+4>>2]=f;m=c;c=(h<<1)-g|0;e=(j+(i?0-c|0:c)|0)/2|0;H[m>>2]=e;g=H[b+16>>2]}c=H[d+4>>2]+f|0;e=H[d>>2]+e|0;d:{if((g|0)<(e|0)){e=e-H[b+4>>2]|0;break d}if((0-g|0)<=(e|0)){break d}e=H[b+4>>2]+e|0}e:{if((c|0)>(g|0)){c=c-H[b+4>>2]|0;break e}if((0-g|0)<=(c|0)){break e}c=H[b+4>>2]+c|0}f:{if(l){g=c;break f}g:{h:{if((e|0)>=0){b=1;f=1;if((c|0)>=0){break g}d=1;b=-1;f=-1;if(e){break h}break g}d=-1;b=-1;f=-1;if((c|0)<=0){break g}}b=(c|0)<=0?-1:1;f=d}d=N(f,g);h=(e<<1)-d|0;f=(N(b,f)|0)>=0;b=N(b,g);g=((f?0-h|0:h)+b|0)/2|0;b=(c<<1)-b|0;e=(d+(f?0-b|0:b)|0)/2|0}c=a;H[c>>2]=e+k;H[c+4>>2]=g+k}function Wh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0;g=ca-16|0;ca=g;e=H[a+4>>2];d=H[e>>2];a:{b=H[a+12>>2];c=H[b+28>>2]-H[b+24>>2]|0;f=c>>2;b:{if(f>>>0<=H[e+8>>2]-d>>2>>>0){break b}if((c|0)<0){break a}b=H[e+4>>2];c=pa(c);f=c+(f<<2)|0;h=c+(b-d&-4)|0;c=h;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[e+8>>2]=f;H[e+4>>2]=h;H[e>>2]=c;if(!d){break b}oa(d)}b=H[a+12>>2];c=H[b+28>>2];b=H[b+24>>2];H[g+12>>2]=0;b=c-b>>2;d=a+96|0;e=H[d>>2];c=H[a+100>>2]-e>>2;c:{if(b>>>0>c>>>0){Pa(d,b-c|0,g+12|0);break c}if(b>>>0>=c>>>0){break c}H[a+100>>2]=e+(b<<2)}e=a+8|0;b=H[a+116>>2];d:{if(b){d=H[b>>2];if((d|0)==H[b+4>>2]){c=1;break d}b=0;while(1){c=ye(e,H[(b<<2)+d>>2]);if(!c){break d}f=H[a+116>>2];d=H[f>>2];b=b+1|0;if(b>>>0>2]-d>>2>>>0){continue}break}break d}c=1;a=H[a+12>>2];a=H[a+4>>2]-H[a>>2]|0;if(a>>>0<12){break d}a=(a>>2>>>0)/3|0;b=0;while(1){c=ye(e,N(b,3));if(!c){break d}b=b+1|0;if((a|0)!=(b|0)){continue}break}}ca=g+16|0;return c|0}sa();v()}function gj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;c=H[b+88>>2];if(!(!c|H[c>>2]!=1)){e=H[c+8>>2];H[a+4>>2]=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);f=a+8|0;d=I[b+24|0];h=H[a+8>>2];g=H[a+12>>2]-h>>2;a:{if(d>>>0>g>>>0){ya(f,d-g|0);d=I[b+24|0];e=H[c+8>>2];break a}if(d>>>0>=g>>>0){break a}H[a+12>>2]=h+(d<<2)}b:{if(!d){b=4;break b}h=d&3;f=H[f>>2];c:{if(d-1>>>0<3){b=4;d=0;break c}k=d&252;d=0;b=4;while(1){g=d<<2;c=b+e|0;H[g+f>>2]=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[f+(g|4)>>2]=I[c+4|0]|I[c+5|0]<<8|(I[c+6|0]<<16|I[c+7|0]<<24);H[f+(g|8)>>2]=I[c+8|0]|I[c+9|0]<<8|(I[c+10|0]<<16|I[c+11|0]<<24);H[f+(g|12)>>2]=I[c+12|0]|I[c+13|0]<<8|(I[c+14|0]<<16|I[c+15|0]<<24);d=d+4|0;b=b+16|0;i=i+4|0;if((k|0)!=(i|0)){continue}break}}if(!h){break b}while(1){c=b+e|0;H[f+(d<<2)>>2]=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);d=d+1|0;b=b+4|0;j=j+1|0;if((h|0)!=(j|0)){continue}break}}d=a;a=b+e|0;H[d+20>>2]=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);d=1}return d|0}function se(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;a:{b:{c:{if(!b){if((d|0)<0){break a}f=H[a+4>>2];b=H[a>>2];d=f-b|0;if(c>>>0>d>>>0){g=c-d|0;e=H[a+8>>2];if(g>>>0<=e-f>>>0){i=a,j=ra(f,0,g)+g|0,H[i+4>>2]=j;break c}if((c|0)<0){break b}f=e-b|0;e=f<<1;f=f>>>0>=1073741823?2147483647:c>>>0>>0?e:c;e=pa(f);ra(e+d|0,0,g);d=va(e,b,d);H[a+8>>2]=d+f;H[a+4>>2]=c+d;H[a>>2]=d;if(!b){break c}oa(b);break c}if(c>>>0>=d>>>0){break c}H[a+4>>2]=b+c;break c}if((d|0)<0){break a}e=H[a+4>>2];f=H[a>>2];g=e-f|0;d:{if((d|0)<=0&c>>>0<=g>>>0|(d|0)<0){break d}if(c>>>0>g>>>0){d=c-g|0;h=H[a+8>>2];if(d>>>0<=h-e>>>0){i=a,j=ra(e,0,d)+d|0,H[i+4>>2]=j;break d}if((c|0)<0){break b}e=h-f|0;h=e<<1;e=e>>>0>=1073741823?2147483647:c>>>0>>0?h:c;h=pa(e);ra(h+g|0,0,d);d=va(h,f,g);H[a+8>>2]=d+e;H[a+4>>2]=c+d;H[a>>2]=d;if(!f){break d}oa(f);break d}if(c>>>0>=g>>>0){break d}H[a+4>>2]=c+f}if(!c){break c}va(H[a>>2],b,c)}b=H[a+28>>2];c=H[a+24>>2]+1|0;b=c?b:b+1|0;H[a+24>>2]=c;H[a+28>>2]=b;g=1;break a}sa();v()}return g}function Jh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;k=H[a+12>>2];c=H[a+68>>2];d=H[c+80>>2];F[b+84|0]=0;n=b+68|0;i=H[b+68>>2];e=H[b+72>>2]-i>>2;a:{if(e>>>0>>0){qb(n,d-e|0,12372);c=H[a+68>>2];d=H[c+80>>2];break a}if(d>>>0>=e>>>0){break a}H[b+72>>2]=i+(d<<2)}b=H[c+100>>2];e=H[c+96>>2];i=(b-e|0)/12|0;m=1;b:{if((b|0)==(e|0)){break b}k=H[k+28>>2];f=H[k>>2];if((f|0)==-1){return 0}o=i>>>0<=1?1:i;c=e;b=0;m=0;while(1){g=H[c>>2];if(g>>>0>=d>>>0){break b}j=H[H[a+72>>2]+12>>2];h=H[j+(f<<2)>>2];if(h>>>0>=d>>>0){break b}f=H[n>>2];H[f+(g<<2)>>2]=h;g=k+(l<<2)|0;h=H[g+4>>2];if((h|0)==-1){break b}l=H[c+4>>2];if(l>>>0>=d>>>0){break b}h=H[(h<<2)+j>>2];if(h>>>0>=d>>>0){break b}H[f+(l<<2)>>2]=h;g=H[g+8>>2];if((g|0)==-1){break b}c=H[c+8>>2];if(c>>>0>=d>>>0){break b}j=H[(g<<2)+j>>2];if(j>>>0>=d>>>0){break b}H[f+(c<<2)>>2]=j;b=b+1|0;m=i>>>0<=b>>>0;if((b|0)==(o|0)){break b}c=e+N(b,12)|0;l=N(b,3);f=H[k+(l<<2)>>2];if((f|0)!=-1){continue}break}}return m|0}function Gh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=H[d+80>>2];e=ca-48|0;ca=e;a=H[a+4>>2];m=a-2|0;a:{if(m>>>0>28){break a}j=H[H[d>>2]>>2]+H[d+48>>2]|0;H[e+16>>2]=a;a=-1<>2]=a^-1;a=-2-a|0;H[e+24>>2]=a;H[e+32>>2]=(a|0)/2;L[e+28>>2]=O(2)/O(a|0);f=H[c>>2];if((f|0)!=H[c+4>>2]){a=0;d=0;while(1){g=H[(d<<2)+f>>2];h=e+36|0;k=H[H[b>>2]>>2];l=H[b+48>>2];f=H[b+40>>2];i=H[b+44>>2];if(!I[b+84|0]){g=H[H[b+68>>2]+(g<<2)>>2]}g=Rj(f,i,g,0);i=g;g=g+l|0;qa(h,g+k|0,f);he(e+16|0,h,e+12|0,e+8|0);f=a<<2;H[f+j>>2]=H[e+12>>2];H[(f|4)+j>>2]=H[e+8>>2];a=a+2|0;d=d+1|0;f=H[c>>2];if(d>>>0>2]-f>>2>>>0){continue}break}break a}if(!h){break a}d=0;a=0;while(1){k=e+36|0;l=H[H[b>>2]>>2];i=H[b+48>>2];c=H[b+40>>2];f=Rj(c,H[b+44>>2],I[b+84|0]?a:H[H[b+68>>2]+(a<<2)>>2],0);g=f;f=f+i|0;qa(k,f+l|0,c);he(e+16|0,k,e+12|0,e+8|0);c=d<<2;H[c+j>>2]=H[e+12>>2];H[(c|4)+j>>2]=H[e+8>>2];d=d+2|0;a=a+1|0;if((h|0)!=(a|0)){continue}break}}ca=e+48|0;return m>>>0<29|0}function Re(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=O(0),j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0;k=ca-16|0;ca=k;if(H[c+28>>2]==9){d=H[a+4>>2];h=I[c+24|0];e=h<<2;f=pa(e);l=k+8|0;H[l>>2]=1065353216;i=L[a+20>>2];d=-1<0){L[l>>2]=i/O(d|0)}o=(d|0)>0;a:{if(!o){break a}j=H[c+80>>2];if(!j){break a}if(h){p=H[H[b>>2]>>2]+H[b+48>>2]|0;t=h&254;u=h&1;b=0;while(1){m=H[a+8>>2];i=L[l>>2];d=0;n=0;if((h|0)!=1){while(1){g=d<<2;q=(b<<2)+p|0;L[g+f>>2]=O(i*O(H[q>>2]))+L[g+m>>2];g=g|4;L[g+f>>2]=O(i*O(H[q+4>>2]))+L[g+m>>2];d=d+2|0;b=b+2|0;n=n+2|0;if((t|0)!=(n|0)){continue}break}}if(u){d=d<<2;L[d+f>>2]=O(i*O(H[(b<<2)+p>>2]))+L[d+m>>2];b=b+1|0}qa(H[H[c+64>>2]>>2]+r|0,f,e);r=e+r|0;s=s+1|0;if((s|0)!=(j|0)){continue}break}break a}b=0;if((j|0)!=1){a=j&-2;d=0;while(1){qa(H[H[c+64>>2]>>2]+b|0,f,e);b=b+e|0;qa(b+H[H[c+64>>2]>>2]|0,f,e);b=b+e|0;d=d+2|0;if((a|0)!=(d|0)){continue}break}}if(!(j&1)){break a}qa(H[H[c+64>>2]>>2]+b|0,f,e)}oa(f)}ca=k+16|0;return o|0}function Xh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;c=H[a+12>>2];d=H[a+108>>2];e=H[d+80>>2];F[b+84|0]=0;m=b+68|0;h=H[b+68>>2];f=H[b+72>>2]-h>>2;a:{if(f>>>0>>0){qb(m,e-f|0,12372);d=H[a+108>>2];e=H[d+80>>2];break a}if(e>>>0>=f>>>0){break a}H[b+72>>2]=h+(e<<2)}b=H[d+100>>2];f=H[d+96>>2];h=(b-f|0)/12|0;k=1;b:{if((b|0)==(f|0)){break b}n=h>>>0<=1?1:h;o=H[c>>2];c=0;d=f;b=0;k=0;while(1){c=(c<<2)+o|0;i=H[c>>2];if((i|0)==-1){break b}g=H[d>>2];if(g>>>0>=e>>>0){break b}l=H[H[a+112>>2]+12>>2];j=H[l+(i<<2)>>2];if(j>>>0>=e>>>0){break b}i=H[m>>2];H[i+(g<<2)>>2]=j;g=H[c+4>>2];if((g|0)==-1){break b}j=H[d+4>>2];if(j>>>0>=e>>>0){break b}g=H[(g<<2)+l>>2];if(g>>>0>=e>>>0){break b}H[i+(j<<2)>>2]=g;c=H[c+8>>2];if((c|0)==-1){break b}d=H[d+8>>2];if(d>>>0>=e>>>0){break b}c=H[(c<<2)+l>>2];if(c>>>0>=e>>>0){break b}H[i+(d<<2)>>2]=c;b=b+1|0;k=h>>>0<=b>>>0;if((b|0)==(n|0)){break b}c=N(b,3);d=f+N(b,12)|0;if((b|0)!=1431655765){continue}break}}return k|0}function Ph(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;c=H[a+12>>2];d=H[a+68>>2];e=H[d+80>>2];F[b+84|0]=0;m=b+68|0;h=H[b+68>>2];f=H[b+72>>2]-h>>2;a:{if(f>>>0>>0){qb(m,e-f|0,12372);d=H[a+68>>2];e=H[d+80>>2];break a}if(e>>>0>=f>>>0){break a}H[b+72>>2]=h+(e<<2)}b=H[d+100>>2];f=H[d+96>>2];h=(b-f|0)/12|0;k=1;b:{if((b|0)==(f|0)){break b}n=h>>>0<=1?1:h;o=H[c>>2];c=0;d=f;b=0;k=0;while(1){c=(c<<2)+o|0;i=H[c>>2];if((i|0)==-1){break b}g=H[d>>2];if(g>>>0>=e>>>0){break b}l=H[H[a+72>>2]+12>>2];j=H[l+(i<<2)>>2];if(j>>>0>=e>>>0){break b}i=H[m>>2];H[i+(g<<2)>>2]=j;g=H[c+4>>2];if((g|0)==-1){break b}j=H[d+4>>2];if(j>>>0>=e>>>0){break b}g=H[(g<<2)+l>>2];if(g>>>0>=e>>>0){break b}H[i+(j<<2)>>2]=g;c=H[c+8>>2];if((c|0)==-1){break b}d=H[d+8>>2];if(d>>>0>=e>>>0){break b}c=H[(c<<2)+l>>2];if(c>>>0>=e>>>0){break b}H[i+(d<<2)>>2]=c;b=b+1|0;k=h>>>0<=b>>>0;if((b|0)==(n|0)){break b}c=N(b,3);d=f+N(b,12)|0;if((b|0)!=1431655765){continue}break}}return k|0}function Wa(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;d=ca-16|0;ca=d;a:{f=H[a+4>>2];b:{if(f>>>0>>0){e=b-f|0;c=H[a+8>>2];g=c<<5;c:{if(!(e>>>0>g>>>0|f>>>0>g-e>>>0)){H[a+4>>2]=b;h=f&31;b=H[a>>2]+(f>>>3&536870908)|0;break c}H[d+8>>2]=0;H[d>>2]=0;H[d+4>>2]=0;if((b|0)<0){break a}if(g>>>0<=1073741822){c=c<<6;b=b+31&-32;b=b>>>0>>0?c:b}else{b=2147483647}pb(d,b);f=H[a+4>>2];H[d+4>>2]=f+e;i=H[a>>2];b=H[d>>2];d:{if((f|0)<=0){break d}c=f>>>5|0;if(f>>>0>=32){va(b,i,c<<2)}g=c<<2;b=g+b|0;h=f&31;if(h){c=-1>>>32-h|0;H[b>>2]=H[b>>2]&(c^-1)|H[i+g>>2]&c}i=H[a>>2]}H[a>>2]=H[d>>2];H[d>>2]=i;c=H[a+4>>2];H[a+4>>2]=H[d+4>>2];H[d+4>>2]=c;c=H[a+8>>2];H[a+8>>2]=H[d+8>>2];H[d+8>>2]=c;if(!i){break c}oa(i)}if(!e){break b}if(h){c=32-h|0;a=c>>>0>>0?c:e;H[b>>2]=H[b>>2]&(-1<>>c-a^-1);e=e-a|0;b=b+4|0}a=e>>>5|0;if(e>>>0>=32){ra(b,0,a<<2)}if((e&-32)==(e|0)){break b}a=(a<<2)+b|0;H[a>>2]=H[a>>2]&(-1>>>32-(e&31)^-1);break b}H[a+4>>2]=b}ca=d+16|0;return}sa();v()}function Je(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;e=H[a+12>>2];i=H[a+8>>2];d=e-i>>2;b=I[b+24|0];a:{if(d>>>0>>0){ya(a+8|0,b-d|0);i=H[a+8>>2];e=H[a+12>>2];break a}if(b>>>0>=d>>>0){break a}e=(b<<2)+i|0;H[a+12>>2]=e}b=0;f=H[c+8>>2];h=H[c+12>>2];j=H[c+20>>2];e=e-i|0;d=H[c+16>>2];g=e+d|0;j=e>>>0>g>>>0?j+1|0:j;b:{if(f>>>0>>0&(h|0)<=(j|0)|(h|0)<(j|0)){break b}qa(i,d+H[c>>2]|0,e);d=H[c+20>>2];g=e;e=e+H[c+16>>2]|0;d=g>>>0>e>>>0?d+1|0:d;H[c+16>>2]=e;H[c+20>>2]=d;f=H[c+8>>2];h=H[c+12>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;if(f>>>0>>0&(d|0)>=(h|0)|(d|0)>(h|0)){break b}d=e+H[c>>2]|0;H[a+20>>2]=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);d=H[c+20>>2];g=d;f=d;e=H[c+16>>2];d=e+4|0;f=d>>>0<4?f+1|0:f;H[c+16>>2]=d;H[c+20>>2]=f;h=H[c+12>>2];if((f|0)>=(h|0)&d>>>0>=K[c+8>>2]|(f|0)>(h|0)){break b}f=I[d+H[c>>2]|0];d=g;e=e+5|0;d=e>>>0<5?d+1|0:d;H[c+16>>2]=e;H[c+20>>2]=d;if(f-1>>>0>29){break b}H[a+4>>2]=f;b=1}return b|0}function qd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;a:{f=H[a+4>>2];b:{if((f|0)!=H[a>>2]){c=f;break b}g=H[a+8>>2];c=H[a+12>>2];if(g>>>0>>0){e=((c-g>>2)+1|0)/2<<2;c=e+g|0;if((f|0)!=(g|0)){d=g-f|0;c=c-d|0;va(c,f,d);f=H[a+8>>2]}H[a+4>>2]=c;H[a+8>>2]=e+f;break b}d=(c|0)==(f|0)?1:c-f>>1;if(d>>>0>=1073741824){break a}c=d<<2;i=pa(c);k=i+c|0;c=(d+3&-4)+i|0;h=c;c:{if((f|0)==(g|0)){break c}g=g-f|0;l=g&-4;e=c;d=f;j=g-4|0;g=(j>>>2|0)+1&7;if(g){h=0;while(1){H[e>>2]=H[d>>2];d=d+4|0;e=e+4|0;h=h+1|0;if((g|0)!=(h|0)){continue}break}}h=c+l|0;if(j>>>0<28){break c}while(1){H[e>>2]=H[d>>2];H[e+4>>2]=H[d+4>>2];H[e+8>>2]=H[d+8>>2];H[e+12>>2]=H[d+12>>2];H[e+16>>2]=H[d+16>>2];H[e+20>>2]=H[d+20>>2];H[e+24>>2]=H[d+24>>2];H[e+28>>2]=H[d+28>>2];d=d+32|0;e=e+32|0;if((h|0)!=(e|0)){continue}break}}H[a+12>>2]=k;H[a+8>>2]=h;H[a+4>>2]=c;H[a>>2]=i;if(!f){break b}oa(f);c=H[a+4>>2]}H[c-4>>2]=H[b>>2];H[a+4>>2]=H[a+4>>2]-4;return}wa();v()}function sb(a,b){var c=0;a:{if(!ta(a,b)){break a}if(!ta(a+16|0,b)){break a}if(!ta(a+32|0,b)){break a}if(!ta(a+48|0,b)){break a}if(!ta(a- -64|0,b)){break a}if(!ta(a+80|0,b)){break a}if(!ta(a+96|0,b)){break a}if(!ta(a+112|0,b)){break a}if(!ta(a+128|0,b)){break a}if(!ta(a+144|0,b)){break a}if(!ta(a+160|0,b)){break a}if(!ta(a+176|0,b)){break a}if(!ta(a+192|0,b)){break a}if(!ta(a+208|0,b)){break a}if(!ta(a+224|0,b)){break a}if(!ta(a+240|0,b)){break a}if(!ta(a+256|0,b)){break a}if(!ta(a+272|0,b)){break a}if(!ta(a+288|0,b)){break a}if(!ta(a+304|0,b)){break a}if(!ta(a+320|0,b)){break a}if(!ta(a+336|0,b)){break a}if(!ta(a+352|0,b)){break a}if(!ta(a+368|0,b)){break a}if(!ta(a+384|0,b)){break a}if(!ta(a+400|0,b)){break a}if(!ta(a+416|0,b)){break a}if(!ta(a+432|0,b)){break a}if(!ta(a+448|0,b)){break a}if(!ta(a+464|0,b)){break a}if(!ta(a+480|0,b)){break a}if(!ta(a+496|0,b)){break a}c=ta(a+512|0,b)}return c}function qf(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;a:{if(!ke(a,b)){break a}h=a+36|0;g=ea[H[H[a>>2]+24>>2]](a)|0;e=H[a+40>>2];d=H[a+36>>2];c=e-d>>2;b:{if(g>>>0>c>>>0){Vb(h,g-c|0);break b}if(c>>>0<=g>>>0){break b}d=d+(g<<2)|0;if((d|0)!=(e|0)){while(1){e=e-4|0;c=H[e>>2];H[e>>2]=0;if(c){ea[H[H[c>>2]+4>>2]](c)}if((d|0)!=(e|0)){continue}break}}H[a+40>>2]=d}c=1;if((g|0)<=0){break a}e=0;while(1){c:{c=H[b+20>>2];f=H[b+12>>2];d=H[b+16>>2];if((c|0)>=(f|0)&d>>>0>=K[b+8>>2]|(c|0)>(f|0)){break c}f=I[H[b>>2]+d|0];d=d+1|0;c=d?c:c+1|0;H[b+16>>2]=d;H[b+20>>2]=c;d=ea[H[H[a>>2]+48>>2]](a,f)|0;f=e<<2;i=f+H[a+36>>2]|0;c=H[i>>2];H[i>>2]=d;if(c){ea[H[H[c>>2]+4>>2]](c)}c=H[H[h>>2]+f>>2];if(!c){break c}if(!(k=c,l=ea[H[H[a>>2]+28>>2]](a)|0,m=ea[H[H[a>>2]+20>>2]](a,e)|0,j=H[H[c>>2]+8>>2],ea[j](k|0,l|0,m|0)|0)){break c}c=1;e=e+1|0;if((g|0)!=(e|0)){continue}break a}break}c=0}return c|0}function he(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;j=+L[b>>2];k=+L[b+4>>2];l=+L[b+8>>2];g=P(j)+P(k)+P(l);a:{if(!(g>1e-6)){j=1;k=0;e=0;break a}g=1/g;k=g*k;j=g*j;e=g*l<0}h=H[a+16>>2];l=+(h|0);g=T(j*l+.5);b:{if(P(g)<2147483648){m=~~g;break b}m=-2147483648}f=m>>31;i=(f^m)-f|0;g=T(k*l+.5);c:{if(P(g)<2147483648){f=~~g;break c}f=-2147483648}b=f>>31;b=h-(i+((f^b)-b|0)|0)|0;i=(b|0)>0?b:0;e=e?0-i|0:i;f=f+(b>>31&((f|0)>0?b:0-b|0))|0;d:{if((m|0)>=0){b=e+h|0;a=H[a+8>>2];e=h+f|0;break d}b=f>>31;b=(b^f)-b|0;a=H[a+8>>2];b=(e|0)<0?b:a-b|0;e=(f|0)<0?i:a-i|0}e:{if(!(b|e)){b=a;break e}if(!((a|0)!=(b|0)|e)){b=a;break e}if(!((a|0)!=(e|0)|b)){b=a;break e}if(!((b|0)<=(h|0)|e)){b=(h<<1)-b|0;a=0;break e}if(!((a|0)!=(e|0)|(b|0)>=(h|0))){b=(h<<1)-b|0;break e}if(!((a|0)!=(b|0)|(e|0)>=(h|0))){b=a;a=(h<<1)-e|0;break e}if(b){a=e;break e}b=0;if((e|0)<=(h|0)){a=e;break e}a=(h<<1)-e|0}H[c>>2]=a;H[d>>2]=b}function Ve(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;g=H[b+8>>2];h=H[b+12>>2];c=H[b+20>>2];i=c;k=H[b+16>>2];d=k+4|0;c=d>>>0<4?c+1|0:c;a:{if(d>>>0>g>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break a}l=H[b>>2];f=k+l|0;e=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=d;H[b+20>>2]=c;c=i;f=k+8|0;c=f>>>0<8?c+1|0:c;if(f>>>0>g>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break a}d=d+l|0;j=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=c;if((e|0)>(j|0)){break a}H[a+16>>2]=j;H[a+12>>2]=e;d=j-e|0;e=(j>>31)-((e>>31)+(e>>>0>j>>>0)|0)|0;if(!e&d>>>0>2147483646|e){break a}d=d+1|0;H[a+20>>2]=d;e=d>>>1|0;H[a+24>>2]=e;H[a+28>>2]=0-e;if(!(d&1)){H[a+24>>2]=e-1}if(J[b+38>>1]<=513){if((c|0)>=(h|0)&f>>>0>=g>>>0|(c|0)>(h|0)){break a}g=I[f+l|0];c=i;i=k+9|0;c=i>>>0<9?c+1|0:c;H[b+16>>2]=i;H[b+20>>2]=c;if(g>>>0>1){break a}H[a+88>>2]=g}m=ta(a+112|0,b)}return m|0}function Hc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;g=H[a>>2];c=g+(b>>>3&536870908)|0;H[c>>2]=H[c>>2]|1<>2];e=(b|0)==-1;d=-1;a:{if(e){break a}c=b+1|0;c=(c>>>0)%3|0?c:b-2|0;d=-1;if((c|0)==-1){break a}d=H[H[f>>2]+(c<<2)>>2]}c=H[a+12>>2];h=(d>>>3&536870908)+c|0;H[h>>2]=H[h>>2]|1<>>0)%3|0){e=b-1|0;break e}e=b+2|0;d=-1;if((e|0)==-1){break d}}d=H[H[f>>2]+(e<<2)>>2]}e=(d>>>3&536870908)+c|0;H[e>>2]=H[e>>2]|1<>2]+(b<<2)>>2];if((b|0)==-1){break b}F[a+24|0]=0;a=(b>>>3&536870908)+g|0;H[a>>2]=H[a>>2]|1<>>0)%3|0?a:b-2|0;if((a|0)!=-1){d=H[H[f>>2]+(a<<2)>>2]}a=c+(d>>>3&536870908)|0;H[a>>2]=H[a>>2]|1<>>0)%3|0){b=b-1|0;break g}b=b+2|0;a=-1;if((b|0)==-1){break f}}a=H[H[f>>2]+(b<<2)>>2]}b=1<>>3&536870908)|0;c=H[a>>2];break c}a=c+536870908|0;b=H[c+536870908>>2];c=-2147483648}H[a>>2]=b|c}}function Fd(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=O(0),f=O(0),g=O(0),h=O(0),i=O(0),j=0,k=O(0),l=O(0),m=O(0),n=O(0),o=0;a:{if(H[c+28>>2]!=9|I[c+24|0]!=3){break a}a=H[a+4>>2];if(a-2>>>0>28){break a}o=1;j=H[c+80>>2];if(!j){break a}k=O(O(2)/O((1<>2]>>2]+H[c+48>>2]|0;a=H[H[b>>2]>>2]+H[b+48>>2]|0;b=0;while(1){g=O(0);l=O(0);m=O(0);e=O(O(O(H[a>>2])*k)+O(-1));f=O(O(O(H[a+4>>2])*k)+O(-1));i=O(O(O(1)-O(P(e)))-O(P(f)));h=O(S(O(-i),O(0)));n=O(-h);f=O(f+(f>>8;F[c+10|0]=d>>>16;F[c+11|0]=d>>>24;d=(w(l),y(2));F[c+4|0]=d;F[c+5|0]=d>>>8;F[c+6|0]=d>>>16;F[c+7|0]=d>>>24;d=(w(g),y(2));F[c|0]=d;F[c+1|0]=d>>>8;F[c+2|0]=d>>>16;F[c+3|0]=d>>>24;c=c+12|0;b=b+1|0;if((j|0)!=(b|0)){continue}break}}return o|0}function Vd(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0;a:{if(b>>>0<=63){b=0;a=H[a+12>>2];if(a>>>0<2){break a}b=a-1|0;e=b&3;d=H[c>>2];c=0;b:{if(a-2>>>0<3){a=1;b=0;break b}f=b&-4;b=0;a=1;while(1){g=a+3|0;h=a+2|0;i=a+1|0;b=K[d+(b<<2)>>2]>K[d+(a<<2)>>2]?a:b;b=K[d+(b<<2)>>2]>K[d+(i<<2)>>2]?i:b;b=K[d+(b<<2)>>2]>K[d+(h<<2)>>2]?h:b;b=K[d+(b<<2)>>2]>K[d+(g<<2)>>2]?g:b;a=a+4|0;j=j+4|0;if((f|0)!=(j|0)){continue}break}}if(!e){break a}while(1){b=K[d+(b<<2)>>2]>K[d+(a<<2)>>2]?a:b;a=a+1|0;c=c+1|0;if((e|0)!=(c|0)){continue}break}break a}b=H[a+580>>2];d=32-b|0;if((d|0)>=4){c=H[a+576>>2];if((c|0)==H[a+568>>2]){return 0}d=H[c>>2];e=b+4|0;H[a+580>>2]=e;b=d<>>28|0;if((e|0)!=32){break a}H[a+580>>2]=0;H[a+576>>2]=c+4;return b}c=H[a+576>>2];e=c+4|0;if((e|0)==H[a+568>>2]){return 0}f=H[c>>2];H[a+576>>2]=e;H[a+580>>2]=b-28;a=60-b|0;b=H[c+4>>2]>>>a|f<>>a-d}return b}function Ae(a){a=a|0;var b=0,c=0,d=0,e=0;H[a>>2]=11436;b=H[a+388>>2];if(b){H[a+392>>2]=b;oa(b)}d=H[a+368>>2];H[a+368>>2]=0;if(d){e=d-4|0;b=H[e>>2];if(b){c=(b<<4)+d|0;while(1){c=c-16|0;if((d|0)!=(c|0)){continue}break}}oa(e)}Yc(a+216|0);b=H[a+196>>2];if(b){H[a+200>>2]=b;oa(b)}b=H[a+184>>2];if(b){H[a+188>>2]=b;oa(b)}b=H[a+172>>2];if(b){H[a+176>>2]=b;oa(b)}b=H[a+160>>2];if(b){H[a+164>>2]=b;oa(b)}c=H[a+144>>2];if(c){while(1){b=H[c>>2];oa(c);c=b;if(b){continue}break}}b=H[a+136>>2];H[a+136>>2]=0;if(b){oa(b)}b=H[a+120>>2];if(b){oa(b)}b=H[a+108>>2];if(b){oa(b)}b=H[a+96>>2];if(b){oa(b)}b=H[a+72>>2];if(b){H[a+76>>2]=b;oa(b)}b=H[a+60>>2];if(b){oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}b=H[a+36>>2];if(b){H[a+40>>2]=b;oa(b)}b=H[a+24>>2];if(b){H[a+28>>2]=b;oa(b)}b=H[a+12>>2];if(b){H[a+16>>2]=b;oa(b)}b=H[a+8>>2];H[a+8>>2]=0;if(b){cb(b)}return a|0}function Sg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;a:{a=ca-32|0;ca=a;e=Ma(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){g=(e|15)+1|0;f=pa(g);H[a+24>>2]=g|-2147483648;H[a+16>>2]=f;H[a+20>>2]=e;g=e+f|0;break c}F[a+27|0]=e;f=a+16|0;g=e+f|0;if(!e){break b}}qa(f,c,e)}F[g|0]=0;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;d:{c=nb(b,a+16|0);if((c|0)==(b+4|0)){break d}b=H[c+28>>2];e=H[c+32>>2];if((b|0)==(e|0)){break d}b=e-b|0;if(b&3){break d}e=b>>>2|0;f=H[a+4>>2];b=H[a>>2];g=f-b>>2;e:{if(e>>>0>g>>>0){ya(a,e-g|0);b=H[a>>2];f=H[a+4>>2];break e}if(e>>>0>=g>>>0){break e}f=(e<<2)+b|0;H[a+4>>2]=f}if((b|0)!=(f|0)){e=b;b=H[c+28>>2];qa(e,b,H[c+32>>2]-b|0);break d}Ca();v()}b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}H[d>>2]=H[a>>2];H[d+4>>2]=H[a+4>>2];H[d+8>>2]=H[a+8>>2];if(F[a+27|0]<0){oa(H[a+16>>2])}ca=a+32|0;break a}Na();v()}}function Be(a){a=a|0;var b=0,c=0,d=0,e=0;H[a>>2]=11384;d=H[a+368>>2];H[a+368>>2]=0;if(d){e=d-4|0;b=H[e>>2];if(b){c=(b<<4)+d|0;while(1){c=c-16|0;if((d|0)!=(c|0)){continue}break}}oa(e)}Yc(a+216|0);b=H[a+196>>2];if(b){H[a+200>>2]=b;oa(b)}b=H[a+184>>2];if(b){H[a+188>>2]=b;oa(b)}b=H[a+172>>2];if(b){H[a+176>>2]=b;oa(b)}b=H[a+160>>2];if(b){H[a+164>>2]=b;oa(b)}c=H[a+144>>2];if(c){while(1){b=H[c>>2];oa(c);c=b;if(b){continue}break}}b=H[a+136>>2];H[a+136>>2]=0;if(b){oa(b)}b=H[a+120>>2];if(b){oa(b)}b=H[a+108>>2];if(b){oa(b)}b=H[a+96>>2];if(b){oa(b)}b=H[a+72>>2];if(b){H[a+76>>2]=b;oa(b)}b=H[a+60>>2];if(b){oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}b=H[a+36>>2];if(b){H[a+40>>2]=b;oa(b)}b=H[a+24>>2];if(b){H[a+28>>2]=b;oa(b)}b=H[a+12>>2];if(b){H[a+16>>2]=b;oa(b)}b=H[a+8>>2];H[a+8>>2]=0;if(b){cb(b)}return a|0}function Ug(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;d=ca-16|0;ca=d;a:{e=Ma(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){f=(e|15)+1|0;a=pa(f);H[d+8>>2]=f|-2147483648;H[d>>2]=a;H[d+4>>2]=e;f=a+e|0;break c}F[d+11|0]=e;f=d+e|0;a=d;if(!e){break b}}qa(a,c,e)}F[f|0]=0;c=I[d+11|0];e=c<<24>>24;b=H[b+4>>2];a=0;d:{if(!b){break d}a=c;c=(e|0)<0;a=c?H[d+4>>2]:a;f=c?H[d>>2]:d;while(1){c=I[b+27|0];g=c<<24>>24<0;c=g?H[b+20>>2]:c;i=c>>>0>>0;e:{f:{g:{h:{i:{j:{h=i?c:a;if(h){g=g?H[b+16>>2]:b+16|0;j=Fa(f,g,h);if(j){break j}if(a>>>0>=c>>>0){break i}break e}if(a>>>0>=c>>>0){break h}break e}if((j|0)<0){break e}}c=Fa(g,f,h);if(c){break g}}if(i){break f}a=1;break d}if((c|0)<0){break f}a=1;break d}b=b+4|0}b=H[b>>2];if(b){continue}break}a=0}if((e|0)<0){oa(H[d>>2])}ca=d+16|0;break a}Na();v()}return a|0}function fd(a,b){var c=0,d=0;c=H[b+8>>2];H[a+4>>2]=H[b+4>>2];H[a+8>>2]=c;H[a+20>>2]=H[b+20>>2];c=H[b+16>>2];H[a+12>>2]=H[b+12>>2];H[a+16>>2]=c;a:{b:{if((a|0)!=(b|0)){c=H[b+28>>2];if(c){d=H[a+24>>2];if(H[a+32>>2]<<5>>>0>>0){if(d){oa(d);H[a+32>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;c=H[b+28>>2]}if((c|0)<0){break b}c=(c-1>>>5|0)+1|0;d=pa(c<<2);H[a+32>>2]=c;H[a+28>>2]=0;H[a+24>>2]=d;c=H[b+28>>2]}va(d,H[b+24>>2],(c-1>>>3&536870908)+4|0);c=H[b+28>>2]}else{c=0}H[a+28>>2]=c;c=H[b+40>>2];if(c){d=H[a+36>>2];if(H[a+44>>2]<<5>>>0>>0){if(d){oa(d);H[a+44>>2]=0;H[a+36>>2]=0;H[a+40>>2]=0;c=H[b+40>>2]}if((c|0)<0){break a}c=(c-1>>>5|0)+1|0;d=pa(c<<2);H[a+44>>2]=c;H[a+40>>2]=0;H[a+36>>2]=d;c=H[b+40>>2]}va(d,H[b+36>>2],(c-1>>>3&536870908)+4|0);b=H[b+40>>2]}else{b=0}H[a+40>>2]=b}return}sa();v()}sa();v()}function uc(a){var b=0,c=0,d=0;b=H[a+8>>2];d=H[a>>2];a:{if(I[a+12|0]){b:{c:{d:{e:{if((b|0)==-1){break e}c=b+1|0;b=(c>>>0)%3|0?c:b-2|0;if((b|0)==-1){break e}b=H[H[d+12>>2]+(b<<2)>>2];if((b|0)!=-1){break d}}H[a+8>>2]=-1;break c}c=b+1|0;b=(c>>>0)%3|0?c:b-2|0;H[a+8>>2]=b;if((b|0)!=-1){break b}}c=H[a+4>>2];b=-1;f:{if((c|0)==-1){break f}g:{if((c>>>0)%3|0){c=c-1|0;break g}c=c+2|0;b=-1;if((c|0)==-1){break f}}c=H[H[d+12>>2]+(c<<2)>>2];b=-1;if((c|0)==-1){break f}b=c-1|0;if((c>>>0)%3|0){break f}b=c+2|0}F[a+12|0]=0;H[a+8>>2]=b;return}if((b|0)!=H[a+4>>2]){break a}H[a+8>>2]=-1;return}c=-1;h:{if((b|0)==-1){break h}i:{if((b>>>0)%3|0){b=b-1|0;break i}b=b+2|0;c=-1;if((b|0)==-1){break h}}b=H[H[d+12>>2]+(b<<2)>>2];c=-1;if((b|0)==-1){break h}c=b-1|0;if((b>>>0)%3|0){break h}c=b+2|0}H[a+8>>2]=c}}function Rf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;f=ca-32|0;ca=f;d=H[a+28>>2];H[f+16>>2]=d;g=H[a+20>>2];H[f+28>>2]=c;H[f+24>>2]=b;b=g-d|0;H[f+20>>2]=b;g=b+c|0;i=2;a:{b:{b=f+16|0;d=Z(H[a+60>>2],b|0,2,f+12|0)|0;if(d){H[3992]=d;d=-1}else{d=0}c:{d:{if(d){d=b;break d}while(1){e=H[f+12>>2];if((e|0)==(g|0)){break c}if((e|0)<0){d=b;break b}h=H[b+4>>2];j=h>>>0>>0;d=(j<<3)+b|0;h=e-(j?h:0)|0;H[d>>2]=h+H[d>>2];b=(j?12:4)+b|0;H[b>>2]=H[b>>2]-h;g=g-e|0;b=d;i=i-j|0;e=Z(H[a+60>>2],b|0,i|0,f+12|0)|0;if(e){H[3992]=e;e=-1}else{e=0}if(!e){continue}break}}if((g|0)!=-1){break b}}b=H[a+44>>2];H[a+28>>2]=b;H[a+20>>2]=b;H[a+16>>2]=b+H[a+48>>2];a=c;break a}H[a+28>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a>>2]=H[a>>2]|32;a=0;if((i|0)==2){break a}a=c-H[d+4>>2]|0}ca=f+32|0;return a|0}function Ih(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0;e=H[a+4>>2];d=H[e>>2];a:{b=H[a+12>>2];c=H[b+56>>2]-H[b+52>>2]|0;f=c>>2;b:{if(f>>>0<=H[e+8>>2]-d>>2>>>0){break b}if((c|0)<0){break a}b=H[e+4>>2];c=pa(c);f=c+(f<<2)|0;g=c+(b-d&-4)|0;c=g;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[e+8>>2]=f;H[e+4>>2]=g;H[e>>2]=c;if(!d){break b}oa(d)}e=a+8|0;b=H[a+76>>2];c:{if(b){d=H[b>>2];if((d|0)==H[b+4>>2]){return 1}b=0;while(1){c=we(e,H[(b<<2)+d>>2]);if(!c){break c}f=H[a+76>>2];d=H[f>>2];b=b+1|0;if(b>>>0>2]-d>>2>>>0){continue}break}break c}c=1;a=H[H[a+12>>2]+64>>2];a=H[a+4>>2]-H[a>>2]|0;if(a>>>0<12){break c}a=(a>>2>>>0)/3|0;b=0;while(1){c=we(e,N(b,3));if(!c){break c}b=b+1|0;if((a|0)!=(b|0)){continue}break}}return c|0}sa();v()}function Oh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0;e=H[a+4>>2];d=H[e>>2];a:{b=H[a+12>>2];c=H[b+28>>2]-H[b+24>>2]|0;f=c>>2;b:{if(f>>>0<=H[e+8>>2]-d>>2>>>0){break b}if((c|0)<0){break a}b=H[e+4>>2];c=pa(c);f=c+(f<<2)|0;g=c+(b-d&-4)|0;c=g;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[e+8>>2]=f;H[e+4>>2]=g;H[e>>2]=c;if(!d){break b}oa(d)}e=a+8|0;b=H[a+76>>2];c:{if(b){d=H[b>>2];if((d|0)==H[b+4>>2]){return 1}b=0;while(1){c=xe(e,H[(b<<2)+d>>2]);if(!c){break c}f=H[a+76>>2];d=H[f>>2];b=b+1|0;if(b>>>0>2]-d>>2>>>0){continue}break}break c}c=1;a=H[a+12>>2];a=H[a+4>>2]-H[a>>2]|0;if(a>>>0<12){break c}a=(a>>2>>>0)/3|0;b=0;while(1){c=xe(e,N(b,3));if(!c){break c}b=b+1|0;if((a|0)!=(b|0)){continue}break}}return c|0}sa();v()}function Te(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;g=H[b+8>>2];h=H[b+12>>2];c=H[b+20>>2];i=c;e=H[b+16>>2];d=e+4|0;c=d>>>0<4?c+1|0:c;a:{if(d>>>0>g>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break a}j=H[b>>2];f=e+j|0;f=I[f|0]|I[f+1|0]<<8|(I[f+2|0]<<16|I[f+3|0]<<24);H[b+16>>2]=d;H[b+20>>2]=c;k=J[b+38>>1];if(k>>>0<=513){c=i;d=e+8|0;c=d>>>0<8?c+1|0:c;if(d>>>0>g>>>0&(c|0)>=(h|0)|(c|0)>(h|0)){break a}H[b+16>>2]=d;H[b+20>>2]=c}if(!(f&1)){break a}e=Q(f)^31;if(e-1>>>0>28){break a}H[a+8>>2]=e+1;i=-2<>2]=e;H[a+12>>2]=i^-1;H[a+24>>2]=e>>1;L[a+20>>2]=O(2)/O(e|0);if(k>>>0<=513){if((c|0)>=(h|0)&d>>>0>=g>>>0|(c|0)>(h|0)){break a}g=I[d+j|0];d=d+1|0;c=d?c:c+1|0;H[b+16>>2]=d;H[b+20>>2]=c;if(g>>>0>1){break a}H[a+72>>2]=g}l=ta(a+96|0,b)}return l|0}function Se(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;f=H[b+8>>2];g=H[b+12>>2];c=H[b+20>>2];h=c;i=H[b+16>>2];e=i+4|0;c=e>>>0<4?c+1|0:c;a:{if(e>>>0>f>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break a}j=H[b>>2];d=i+j|0;d=I[d|0]|I[d+1|0]<<8|(I[d+2|0]<<16|I[d+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=c;c=h;e=i+8|0;c=e>>>0<8?c+1|0:c;if(e>>>0>f>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break a}H[b+16>>2]=e;H[b+20>>2]=c;if(!(d&1)){break a}d=Q(d)^31;if(d-1>>>0>28){break a}H[a+8>>2]=d+1;k=-2<>2]=d;H[a+12>>2]=k^-1;H[a+24>>2]=d>>1;L[a+20>>2]=O(2)/O(d|0);if(J[b+38>>1]<=513){if((c|0)>=(g|0)&e>>>0>=f>>>0|(c|0)>(g|0)){break a}c=I[e+j|0];f=i+9|0;h=f>>>0<9?h+1|0:h;H[b+16>>2]=f;H[b+20>>2]=h;if(c>>>0>1){break a}H[a+72>>2]=c}l=ta(a+96|0,b)}return l|0} +function va(a,b,c){var d=0,e=0;a:{if((a|0)==(b|0)){break a}e=a+c|0;if(b-e>>>0<=0-(c<<1)>>>0){return qa(a,b,c)}d=(a^b)&3;b:{c:{if(a>>>0>>0){if(d){d=a;break b}if(!(a&3)){d=a;break c}d=a;while(1){if(!c){break a}F[d|0]=I[b|0];b=b+1|0;c=c-1|0;d=d+1|0;if(d&3){continue}break}break c}d:{if(d){break d}if(e&3){while(1){if(!c){break a}c=c-1|0;d=c+a|0;F[d|0]=I[b+c|0];if(d&3){continue}break}}if(c>>>0<=3){break d}while(1){c=c-4|0;H[c+a>>2]=H[b+c>>2];if(c>>>0>3){continue}break}}if(!c){break a}while(1){c=c-1|0;F[c+a|0]=I[b+c|0];if(c){continue}break}break a}if(c>>>0<=3){break b}while(1){H[d>>2]=H[b>>2];b=b+4|0;d=d+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}while(1){F[d|0]=I[b|0];d=d+1|0;b=b+1|0;c=c-1|0;if(c){continue}break}}return a}function ff(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;h=H[c+12>>2];f=h;e=H[c+20>>2];i=H[c+8>>2];g=H[c+16>>2];a:{if((f|0)<=(e|0)&i>>>0<=g>>>0|(e|0)>(f|0)){break a}j=H[c>>2];k=F[j+g|0];d=e;f=g+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;b:{if((k|0)==-2){break b}if((d|0)>=(h|0)&f>>>0>=i>>>0|(d|0)>(h|0)){break a}d=F[f+j|0];g=g+2|0;e=g>>>0<2?e+1|0:e;H[c+16>>2]=g;H[c+20>>2]=e;if((d-4&255)>>>0<251){break a}e=ea[H[H[a>>2]+40>>2]](a,k,d)|0;d=H[a+20>>2];H[a+20>>2]=e;if(!d){break b}ea[H[H[d>>2]+4>>2]](d)}d=H[a+20>>2];if(d){if(!(ea[H[H[a>>2]+28>>2]](a,d)|0)){break a}}if(!(ea[H[H[a>>2]+36>>2]](a,b,c)|0)){break a}c=H[a+4>>2];if(!(!c|I[c+36|0]>1)){if(!(ea[H[H[a>>2]+48>>2]](a,H[b+4>>2]-H[b>>2]>>2)|0)){break a}}l=1}return l|0}function Vb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;d=H[a+8>>2];c=H[a+4>>2];if(d-c>>2>>>0>=b>>>0){if(b){b=b<<2;c=ra(c,0,b)+b|0}H[a+4>>2]=c;return}a:{b:{c:{g=H[a>>2];f=c-g>>2;e=f+b|0;if(e>>>0<1073741824){d=d-g|0;h=d>>>1|0;e=d>>>0>=2147483644?1073741823:e>>>0>>0?h:e;if(e){if(e>>>0>=1073741824){break c}i=pa(e<<2)}d=(f<<2)+i|0;f=b<<2;b=ra(d,0,f);f=b+f|0;e=(e<<2)+i|0;if((c|0)==(g|0)){break b}while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;d=d-4|0;H[d>>2]=b;if((c|0)!=(g|0)){continue}break}H[a+8>>2]=e;b=H[a+4>>2];H[a+4>>2]=f;c=H[a>>2];H[a>>2]=d;if((b|0)==(c|0)){break a}while(1){b=b-4|0;a=H[b>>2];H[b>>2]=0;if(a){ea[H[H[a>>2]+4>>2]](a)}if((b|0)!=(c|0)){continue}break}break a}sa();v()}wa();v()}H[a+8>>2]=e;H[a+4>>2]=f;H[a>>2]=b}if(c){oa(c)}}function Md(a,b,c){a:{switch(b-9|0){case 0:b=H[c>>2];H[c>>2]=b+4;H[a>>2]=H[b>>2];return;case 6:b=H[c>>2];H[c>>2]=b+4;b=G[b>>1];H[a>>2]=b;H[a+4>>2]=b>>31;return;case 7:b=H[c>>2];H[c>>2]=b+4;H[a>>2]=J[b>>1];H[a+4>>2]=0;return;case 8:b=H[c>>2];H[c>>2]=b+4;b=F[b|0];H[a>>2]=b;H[a+4>>2]=b>>31;return;case 9:b=H[c>>2];H[c>>2]=b+4;H[a>>2]=I[b|0];H[a+4>>2]=0;return;case 16:b=H[c>>2]+7&-8;H[c>>2]=b+8;M[a>>3]=M[b>>3];return;case 17:v();default:return;case 1:case 4:case 14:b=H[c>>2];H[c>>2]=b+4;b=H[b>>2];H[a>>2]=b;H[a+4>>2]=b>>31;return;case 2:case 5:case 11:case 15:b=H[c>>2];H[c>>2]=b+4;H[a>>2]=H[b>>2];H[a+4>>2]=0;return;case 3:case 10:case 12:case 13:break a}}b=H[c>>2]+7&-8;H[c>>2]=b+8;c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c}function Ed(a,b){var c=0,d=0,e=0;c=ca+-64|0;ca=c;d=H[a>>2];e=H[d-4>>2];d=H[d-8>>2];H[c+32>>2]=0;H[c+36>>2]=0;H[c+40>>2]=0;H[c+44>>2]=0;H[c+48>>2]=0;H[c+52>>2]=0;F[c+55|0]=0;F[c+56|0]=0;F[c+57|0]=0;F[c+58|0]=0;F[c+59|0]=0;F[c+60|0]=0;F[c+61|0]=0;F[c+62|0]=0;H[c+24>>2]=0;H[c+28>>2]=0;H[c+20>>2]=0;H[c+16>>2]=14924;H[c+12>>2]=a;H[c+8>>2]=b;a=a+d|0;d=0;a:{if(Ya(e,b,0)){H[c+56>>2]=1;ea[H[H[e>>2]+20>>2]](e,c+8|0,a,a,1,0);d=H[c+32>>2]==1?a:0;break a}ea[H[H[e>>2]+24>>2]](e,c+8|0,a,1,0);b:{switch(H[c+44>>2]){case 0:d=H[c+48>>2]==1?H[c+36>>2]==1?H[c+40>>2]==1?H[c+28>>2]:0:0:0;break a;case 1:break b;default:break a}}if(H[c+32>>2]!=1){if(H[c+48>>2]|H[c+36>>2]!=1|H[c+40>>2]!=1){break a}}d=H[c+24>>2]}ca=c- -64|0;return d}function ua(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;H[a+16>>2]=0;e=H[a>>2];H[a+4>>2]=e;H[a+12>>2]=e;e=H[b+8>>2];c=H[b+12>>2];h=c;d=H[b+20>>2];f=H[b+16>>2];g=f+4|0;d=g>>>0<4?d+1|0:d;a:{if(e>>>0>>0&(d|0)>=(c|0)|(d|0)>(c|0)){break a}c=f+H[b>>2]|0;c=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[b+16>>2]=g;H[b+20>>2]=d;if(!c|c&3){break a}f=h-(d+(e>>>0>>0)|0)|0;if(e-g>>>0>>0&(f|0)<=0|(f|0)<0){break a}if(c>>>0>=4){ya(a,c>>>2|0);h=H[b+12>>2];g=H[b+16>>2];d=H[b+20>>2];e=H[b+8>>2]}f=c+g|0;d=f>>>0>>0?d+1|0:d;if(e>>>0>>0&(d|0)>=(h|0)|(d|0)>(h|0)){break a}qa(H[a>>2],H[b>>2]+g|0,c);d=H[b+20>>2];e=c+H[b+16>>2]|0;d=e>>>0>>0?d+1|0:d;H[b+16>>2]=e;H[b+20>>2]=d;H[a+16>>2]=0;H[a+12>>2]=H[a>>2];i=1}return i}function de(a,b){var c=0,d=0,e=0,f=0;d=-1;e=-1;f=-1;a:{b:{if((b|0)==-1){break b}e=H[H[H[a+4>>2]+12>>2]+(b<<2)>>2];c=b+1|0;c=(c>>>0)%3|0?c:b-2|0;if((c|0)>=0){f=(c>>>0)/3|0;f=H[(H[H[a>>2]+96>>2]+N(f,12)|0)+(c-N(f,3)<<2)>>2]}c:{if((e|0)==-1){break c}c=((e>>>0)%3|0?-1:2)+e|0;if((c|0)<0){break c}d=(c>>>0)/3|0;d=H[(H[H[a>>2]+96>>2]+N(d,12)|0)+(c-N(d,3)<<2)>>2]}c=-1;if((d|0)!=(f|0)){break a}f=-1;d:{b=((b>>>0)%3|0?-1:2)+b|0;if((b|0)>=0){d=(b>>>0)/3|0;d=H[(H[H[a>>2]+96>>2]+N(d,12)|0)+(b-N(d,3)<<2)>>2];if((e|0)==-1){break b}break d}d=-1;if((e|0)!=-1){break d}break b}b=e+1|0;b=(b>>>0)%3|0?b:e-2|0;if((b|0)<0){break b}c=H[H[a>>2]+96>>2];a=(b>>>0)/3|0;f=H[(c+N(a,12)|0)+(b-N(a,3)<<2)>>2]}c=(d|0)!=(f|0)?-1:e}return c}function Ah(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;c=pa(72);H[c+4>>2]=0;H[c+8>>2]=0;H[c>>2]=1984;H[c+12>>2]=0;H[c+16>>2]=0;H[c+20>>2]=0;H[c+24>>2]=0;H[c+28>>2]=0;H[c+32>>2]=0;H[c+36>>2]=0;H[c+40>>2]=0;H[c>>2]=2128;H[c+44>>2]=0;H[c+48>>2]=0;H[c+52>>2]=0;H[c+56>>2]=0;H[c+60>>2]=0;H[c+64>>2]=0;H[c+68>>2]=0;h=c;a:{if((b|0)>=0){g=a+8|0;c=H[a+12>>2];e=H[a+8>>2];f=c-e>>2;b:{if((f|0)>(b|0)){break b}d=b+1|0;if(b>>>0>=f>>>0){Vb(g,d-f|0);break b}if(d>>>0>=f>>>0){break b}e=(d<<2)+e|0;if((e|0)!=(c|0)){while(1){c=c-4|0;d=H[c>>2];H[c>>2]=0;if(d){ea[H[H[d>>2]+4>>2]](d)}if((c|0)!=(e|0)){continue}break}}H[a+12>>2]=e}a=H[g>>2]+(b<<2)|0;c=H[a>>2];H[a>>2]=h;if(!c){break a}}ea[H[H[c>>2]+4>>2]](c)}return(b^-1)>>>31|0}function ra(a,b,c){var d=0,e=0,f=0,g=0;a:{if(!c){break a}F[a|0]=b;d=a+c|0;F[d-1|0]=b;if(c>>>0<3){break a}F[a+2|0]=b;F[a+1|0]=b;F[d-3|0]=b;F[d-2|0]=b;if(c>>>0<7){break a}F[a+3|0]=b;F[d-4|0]=b;if(c>>>0<9){break a}d=0-a&3;e=d+a|0;b=N(b&255,16843009);H[e>>2]=b;d=c-d&-4;c=d+e|0;H[c-4>>2]=b;if(d>>>0<9){break a}H[e+8>>2]=b;H[e+4>>2]=b;H[c-8>>2]=b;H[c-12>>2]=b;if(d>>>0<25){break a}H[e+24>>2]=b;H[e+20>>2]=b;H[e+16>>2]=b;H[e+12>>2]=b;H[c-16>>2]=b;H[c-20>>2]=b;H[c-24>>2]=b;H[c-28>>2]=b;g=e&4|24;c=d-g|0;if(c>>>0<32){break a}d=Rj(b,0,1,1);f=da;b=e+g|0;while(1){H[b+24>>2]=d;H[b+28>>2]=f;H[b+16>>2]=d;H[b+20>>2]=f;H[b+8>>2]=d;H[b+12>>2]=f;H[b>>2]=d;H[b+4>>2]=f;b=b+32|0;c=c-32|0;if(c>>>0>31){continue}break}}return a}function Mj(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;d=H[b+8>>2];e=H[b+12>>2];g=e;e=H[b+20>>2];k=e;h=H[b+16>>2];c=h+4|0;e=c>>>0<4?e+1|0:e;i=c;a:{if(c>>>0>d>>>0&(e|0)>=(g|0)|(e|0)>(g|0)){break a}j=H[b>>2];c=j+h|0;f=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[b+16>>2]=i;H[b+20>>2]=e;c=d;d=k;e=h+8|0;d=e>>>0<8?d+1|0:d;if(c>>>0>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}c=i+j|0;c=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[b+16>>2]=e;H[b+20>>2]=d;if((c|0)<(f|0)){break a}H[a+16>>2]=c;H[a+12>>2]=f;d=(c>>31)-((f>>31)+(c>>>0>>0)|0)|0;b=c-f|0;if(!d&b>>>0>2147483646|d){break a}l=1;d=b+1|0;H[a+20>>2]=d;b=d>>>1|0;H[a+24>>2]=b;H[a+28>>2]=0-b;if(d&1){break a}H[a+24>>2]=b-1}return l|0}function sd(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;e=a+16|0;d=H[e>>2];a:{if(!d){break a}f=H[b>>2];b=e;while(1){g=(f|0)>H[d+16>>2];b=g?b:d;d=H[(g?d+4|0:d)>>2];if(d){continue}break}if((b|0)==(e|0)|(f|0)>2]){break a}d=H[b+24>>2];if(!d){break a}f=b+20|0;b=I[c+11|0];e=b<<24>>24<0;g=e?H[c>>2]:c;b=e?H[c+4>>2]:b;while(1){e=I[d+27|0];h=e<<24>>24<0;e=h?H[d+20>>2]:e;j=e>>>0>>0;b:{c:{d:{e:{f:{g:{i=j?e:b;if(i){h=h?H[d+16>>2]:d+16|0;k=Fa(g,h,i);if(k){break g}if(b>>>0>=e>>>0){break f}break b}if(b>>>0>=e>>>0){break e}break b}if((k|0)<0){break b}}e=Fa(h,g,i);if(e){break d}}if(j){break c}return Tc(f,c)}if((e|0)<0){break c}return Tc(f,c)}d=d+4|0}d=H[d>>2];if(d){continue}break}}return Tc(a,c)}function be(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;d=ca-16|0;ca=d;f=H[a+24>>2];k=H[a+28>>2];a:{if((f|0)!=(k|0)){while(1){H[d+8>>2]=0;H[d>>2]=0;H[d+4>>2]=0;a=$d(H[f>>2],b,d);g=I[d+11|0];h=g<<24>>24;i=3;b:{c:{d:{if(!a){break d}i=0;a=I[c+11|0];e=a<<24>>24;j=(h|0)<0?H[d+4>>2]:g;if((j|0)!=(((e|0)<0?H[c+4>>2]:a)|0)){break d}a=(e|0)<0?H[c>>2]:c;e=(h|0)<0;e:{if(!e){e=d;if(!h){break e}while(1){if(I[e|0]!=I[a|0]){break d}a=a+1|0;e=e+1|0;g=g-1|0;if(g){continue}break}break e}if(!j){break e}if(Fa(e?H[d>>2]:d,a,j)){break c}}l=H[f>>2];i=1}if((h|0)>=0){break b}}oa(H[d>>2])}f:{switch(i|0){case 0:case 3:break f;default:break a}}f=f+4|0;if((k|0)!=(f|0)){continue}break}}l=0}ca=d+16|0;return l}function Cb(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;f=c-b|0;h=f>>2;d=H[a+8>>2];e=H[a>>2];if(h>>>0<=d-e>>2>>>0){d=H[a+4>>2];g=d-e|0;f=g+b|0;i=g>>2;g=i>>>0>>0?f:c;if((g|0)!=(b|0)){while(1){H[e>>2]=H[b>>2];e=e+4|0;b=b+4|0;if((g|0)!=(b|0)){continue}break}}if(h>>>0>i>>>0){if((c|0)!=(g|0)){while(1){H[d>>2]=H[f>>2];d=d+4|0;f=f+4|0;if((f|0)!=(c|0)){continue}break}}H[a+4>>2]=d;return}H[a+4>>2]=e;return}if(e){H[a+4>>2]=e;oa(e);H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;d=0}a:{if((f|0)<0){break a}e=d>>>1|0;d=d>>>0>=2147483644?1073741823:e>>>0>h>>>0?e:h;if(d>>>0>=1073741824){break a}e=d<<2;d=pa(e);H[a>>2]=d;H[a+8>>2]=d+e;if((b|0)!=(c|0)){c=b;b=(f-4&-4)+4|0;d=qa(d,c,b)+b|0}H[a+4>>2]=d;return}sa();v()}function Oa(a,b,c){var d=0,e=0,f=0;e=ca-16|0;ca=e;H[a+4>>2]=0;a:{b:{if(!b){break b}f=H[a+8>>2];d=f<<5;c:{if(d>>>0>=b>>>0){H[a+4>>2]=b;break c}H[e+8>>2]=0;H[e>>2]=0;H[e+4>>2]=0;if((b|0)<0){break a}if(d>>>0<=1073741822){f=f<<6;d=b+31&-32;d=d>>>0>>0?f:d}else{d=2147483647}pb(e,d);f=H[a>>2];H[a>>2]=H[e>>2];H[e>>2]=f;d=H[a+4>>2];H[a+4>>2]=b;H[e+4>>2]=d;d=H[a+8>>2];H[a+8>>2]=H[e+8>>2];H[e+8>>2]=d;if(!f){break c}oa(f)}d=b>>>5|0;a=H[a>>2];if(I[c|0]){if(b>>>0>=32){ra(a,255,d<<2)}if((b&-32)==(b|0)){break b}a=a+(d<<2)|0;H[a>>2]=H[a>>2]|-1>>>32-(b&31);break b}if(b>>>0>=32){ra(a,0,d<<2)}if((b&-32)==(b|0)){break b}a=a+(d<<2)|0;H[a>>2]=H[a>>2]&(-1>>>32-(b&31)^-1)}ca=e+16|0;return}sa();v()}function Hg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=ca-32|0;ca=e;a:{b:{f=Ma(c);if(f>>>0<2147483632){c:{d:{if(f>>>0>=11){a=(f|15)+1|0;g=pa(a);H[e+24>>2]=a|-2147483648;H[e+16>>2]=g;H[e+20>>2]=f;a=f+g|0;break d}F[e+27|0]=f;g=e+16|0;a=f+g|0;if(!f){break c}}qa(g,c,f)}F[a|0]=0;c=Ma(d);if(c>>>0>=2147483632){break b}e:{f:{if(c>>>0>=11){f=(c|15)+1|0;a=pa(f);H[e+8>>2]=f|-2147483648;H[e>>2]=a;H[e+4>>2]=c;g=a+c|0;break f}F[e+11|0]=c;g=c+e|0;a=e;if(!c){break e}}qa(a,d,c)}F[g|0]=0;c=H[b+4>>2];a=-1;g:{if(!c){break g}c=be(c,e+16|0,e);a=-1;if(!c){break g}a=Yd(b,H[c+24>>2])}if(F[e+11|0]<0){oa(H[e>>2])}if(F[e+27|0]<0){oa(H[e+16>>2])}ca=e+32|0;break a}Na();v()}Na();v()}return a|0}function jb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;b=H[b>>2];h=H[b+8>>2];i=H[b+4>>2];j=H[b>>2];d=H[a>>2];b=H[d+4>>2];a=H[d+8>>2];if(b>>>0>>0){H[b+8>>2]=h;H[b+4>>2]=i;H[b>>2]=j;H[d+4>>2]=b+12;return}a:{e=H[d>>2];g=(b-e|0)/12|0;c=g+1|0;if(c>>>0<357913942){f=(a-e|0)/12|0;a=f<<1;c=f>>>0>=178956970?357913941:a>>>0>c>>>0?a:c;if(c){if(c>>>0>=357913942){break a}f=pa(N(c,12))}else{f=0}a=f+N(g,12)|0;H[a+8>>2]=h;H[a+4>>2]=i;H[a>>2]=j;g=a+12|0;if((b|0)!=(e|0)){while(1){a=a-12|0;b=b-12|0;H[a>>2]=H[b>>2];H[a+4>>2]=H[b+4>>2];H[a+8>>2]=H[b+8>>2];if((b|0)!=(e|0)){continue}break}}H[d+8>>2]=f+N(c,12);H[d+4>>2]=g;H[d>>2]=a;if(e){oa(e)}return}sa();v()}wa();v()}function lf(a,b){a=a|0;b=b|0;a=0;a:{switch(b|0){case 0:a=pa(20);H[a+12>>2]=-1;H[a+16>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=2232;return a|0;case 1:a=pa(24);H[a+12>>2]=-1;H[a+16>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=2232;H[a+20>>2]=0;H[a>>2]=2448;return a|0;case 2:a=pa(48);H[a+12>>2]=-1;H[a+16>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=2232;H[a+20>>2]=0;H[a>>2]=2448;H[a+24>>2]=1832;H[a>>2]=11048;H[a+32>>2]=0;H[a+36>>2]=0;H[a+28>>2]=-1;H[a+40>>2]=0;H[a+44>>2]=0;return a|0;case 3:a=pa(32);H[a+12>>2]=-1;H[a+16>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=2232;H[a+20>>2]=0;H[a>>2]=2448;H[a+24>>2]=1032;H[a>>2]=7028;H[a+28>>2]=-1;break;default:break a}}return a|0}function tf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;f=H[b>>2];b=H[b+4>>2];d=H[H[a+8>>2]+40>>2];j=d;m=pa((d|0)<0?-1:d);i=b-f|0;e=1;a:{if((i|0)<4){break a}b=0;g=H[c+16>>2];k=d;f=g+d|0;d=0+H[c+20>>2]|0;d=f>>>0>>0?d+1|0:d;h=H[c+12>>2];e=0;if(K[c+8>>2]>>0&(d|0)>=(h|0)|(d|0)>(h|0)){break a}e=i>>2;i=(e|0)<=1?1:e;while(1){b:{g=qa(m,H[c>>2]+g|0,j);H[c+16>>2]=f;H[c+20>>2]=d;qa(H[H[H[a+8>>2]+64>>2]>>2]+b|0,g,j);l=l+1|0;if((i|0)==(l|0)){break b}b=b+j|0;d=n+H[c+20>>2]|0;g=H[c+16>>2];f=k+g|0;d=f>>>0>>0?d+1|0:d;h=H[c+12>>2];if((d|0)<=(h|0)&K[c+8>>2]>=f>>>0|(d|0)<(h|0)){continue}}break}e=(e|0)<=(l|0)}oa(m);return e|0}function Ti(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;H[b>>2]=1;f=b+8|0;c=H[b+8>>2];d=H[b+12>>2]-c|0;if(d>>>0<=4294967291){kc(f,d+4|0);c=H[f>>2]}c=c+d|0;d=H[a+4>>2];F[c|0]=d;F[c+1|0]=d>>>8;F[c+2|0]=d>>>16;F[c+3|0]=d>>>24;c=H[a+8>>2];if((c|0)!=H[a+12>>2]){d=0;while(1){g=(d<<2)+c|0;c=H[b+8>>2];e=H[b+12>>2]-c|0;if(e>>>0<=4294967291){kc(f,e+4|0);c=H[f>>2]}c=c+e|0;e=H[g>>2];F[c|0]=e;F[c+1|0]=e>>>8;F[c+2|0]=e>>>16;F[c+3|0]=e>>>24;d=d+1|0;c=H[a+8>>2];if(d>>>0>2]-c>>2>>>0){continue}break}}c=H[b+12>>2];b=H[b+8>>2];c=c-b|0;if(c>>>0<=4294967291){kc(f,c+4|0);b=H[f>>2]}b=b+c|0;a=H[a+20>>2];F[b|0]=a;F[b+1|0]=a>>>8;F[b+2|0]=a>>>16;F[b+3|0]=a>>>24}function Aa(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;f=c-b|0;g=f>>2;d=H[a+8>>2];e=H[a>>2];if(g>>>0<=d-e>>2>>>0){f=H[a+4>>2]-e|0;d=f+b|0;h=f>>2;f=h>>>0>>0?d:c;i=f-b|0;if((b|0)!=(f|0)){va(e,b,i)}if(g>>>0>h>>>0){b=H[a+4>>2];if((c|0)!=(f|0)){while(1){H[b>>2]=H[d>>2];b=b+4|0;d=d+4|0;if((d|0)!=(c|0)){continue}break}}H[a+4>>2]=b;return}H[a+4>>2]=e+i;return}if(e){H[a+4>>2]=e;oa(e);H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;d=0}a:{if((f|0)<0){break a}e=d>>>1|0;d=d>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(d>>>0>=1073741824){break a}e=d<<2;d=pa(e);H[a>>2]=d;H[a+8>>2]=d+e;if((b|0)!=(c|0)){c=b;b=(f-4&-4)+4|0;d=qa(d,c,b)+b|0}H[a+4>>2]=d;return}sa();v()}function Rb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;c=H[a+4>>2];if((c|0)!=H[a+8>>2]){e=H[b+4>>2];H[c>>2]=H[b>>2];H[c+4>>2]=e;H[c+8>>2]=H[b+8>>2];H[a+4>>2]=c+12;return}a:{g=H[a>>2];d=(c-g|0)/12|0;e=d+1|0;if(e>>>0<357913942){f=d<<1;f=d>>>0>=178956970?357913941:e>>>0>>0?f:e;if(f){if(f>>>0>=357913942){break a}e=pa(N(f,12))}else{e=0}d=e+N(d,12)|0;h=H[b+4>>2];H[d>>2]=H[b>>2];H[d+4>>2]=h;H[d+8>>2]=H[b+8>>2];b=d+12|0;if((c|0)!=(g|0)){while(1){c=c-12|0;h=H[c+4>>2];d=d-12|0;H[d>>2]=H[c>>2];H[d+4>>2]=h;H[d+8>>2]=H[c+8>>2];if((c|0)!=(g|0)){continue}break}c=H[a>>2]}H[a+8>>2]=e+N(f,12);H[a+4>>2]=b;H[a>>2]=d;if(c){oa(c)}return}sa();v()}wa();v()}function Qi(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;f=ca-32|0;ca=f;g=e>>>0>1073741823?-1:e<<2;l=ra(pa(g),0,g);g=l;i=H[g>>2];g=H[g+4>>2];k=H[b+4>>2];H[f+24>>2]=H[b>>2];H[f+28>>2]=k;H[f+8>>2]=i;H[f+12>>2]=g;i=a+8|0;rc(f+16|0,i,f+8|0,f+24|0);H[c>>2]=H[f+16>>2];H[c+4>>2]=H[f+20>>2];if((d|0)>(e|0)){k=0-e<<2;a=e;while(1){h=a<<2;g=h+c|0;j=g+k|0;m=H[j>>2];j=H[j+4>>2];h=b+h|0;n=H[h+4>>2];H[f+24>>2]=H[h>>2];H[f+28>>2]=n;H[f+8>>2]=m;H[f+12>>2]=j;rc(f+16|0,i,f+8|0,f+24|0);H[g>>2]=H[f+16>>2];H[g+4>>2]=H[f+20>>2];a=a+e|0;if((d|0)>(a|0)){continue}break}}oa(l);ca=f+32|0;return 1}function Hi(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;f=ca-32|0;ca=f;h=e>>>0>1073741823?-1:e<<2;h=ra(pa(h),0,h);g=H[b>>2];i=H[b+4>>2];k=H[h+4>>2];H[f+16>>2]=H[h>>2];H[f+20>>2]=k;H[f+8>>2]=g;H[f+12>>2]=i;i=a+8|0;qc(f+24|0,i,f+16|0,f+8|0);H[c>>2]=H[f+24>>2];H[c+4>>2]=H[f+28>>2];if((d|0)>(e|0)){k=0-e<<2;a=e;while(1){g=a<<2;j=g+b|0;m=H[j>>2];j=H[j+4>>2];g=c+g|0;l=g+k|0;n=H[l+4>>2];H[f+16>>2]=H[l>>2];H[f+20>>2]=n;H[f+8>>2]=m;H[f+12>>2]=j;qc(f+24|0,i,f+16|0,f+8|0);H[g>>2]=H[f+24>>2];H[g+4>>2]=H[f+28>>2];a=a+e|0;if((d|0)>(a|0)){continue}break}}oa(h);ca=f+32|0;return 1}function Ag(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;a:{if(K[b+80>>2]>65535){break a}a=H[b+100>>2];b=H[b+96>>2];e=(a-b|0)/12|0;f=N(e,6);g=(f|0)==(c|0);if((a|0)==(b|0)|(c|0)!=(f|0)){break a}g=1;c=e>>>0<=1?1:e;i=c&1;a=0;if(e>>>0>=2){j=c&-2;c=0;while(1){f=N(a,6);h=f+d|0;e=b+N(a,12)|0;G[h>>1]=H[e>>2];G[(f|2)+d>>1]=H[e+4>>2];G[h+4>>1]=H[e+8>>2];f=a|1;e=N(f,6)+d|0;f=b+N(f,12)|0;G[e>>1]=H[f>>2];G[e+2>>1]=H[f+4>>2];G[e+4>>1]=H[f+8>>2];a=a+2|0;c=c+2|0;if((j|0)!=(c|0)){continue}break}}if(!i){break a}c=N(a,6)+d|0;a=b+N(a,12)|0;G[c>>1]=H[a>>2];G[c+2>>1]=H[a+4>>2];G[c+4>>1]=H[a+8>>2]}return g|0}function Gd(a,b,c,d,e,f,g){var h=0,i=0,j=0;h=ca-16|0;ca=h;if((b^-1)+2147483631>>>0>=c>>>0){if(I[a+11|0]>>>7|0){i=H[a>>2]}else{i=a}if(b>>>0<1073741799){H[h+12>>2]=b<<1;H[h>>2]=b+c;c=ca-16|0;ca=c;ca=c+16|0;c=h+12|0;c=H[(K[h>>2]>2]?c:h)>>2];if(c>>>0>=11){j=c+16&-16;c=j-1|0;c=(c|0)==11?j:c}else{c=10}c=c+1|0}else{c=2147483631}Zb(h,c);c=H[h>>2];if(f){yb(c,g,f)}g=d-e|0;if((d|0)!=(e|0)){yb(c+f|0,e+i|0,g)}if((b|0)!=10){oa(i)}H[a>>2]=c;H[a+8>>2]=H[a+8>>2]&-2147483648|H[h+4>>2]&2147483647;H[a+8>>2]=H[a+8>>2]|-2147483648;b=a;a=f+g|0;H[b+4>>2]=a;F[h+12|0]=0;F[a+c|0]=I[h+12|0];ca=h+16|0;return}Na();v()}function Rg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;a=ca-32|0;ca=a;H[a+24>>2]=0;H[a+28>>2]=0;a:{d=Ma(c);if(d>>>0<2147483632){b:{c:{if(d>>>0>=11){e=(d|15)+1|0;f=pa(e);H[a+16>>2]=e|-2147483648;H[a+8>>2]=f;H[a+12>>2]=d;e=d+f|0;break c}F[a+19|0]=d;f=a+8|0;e=f+d|0;if(!d){break b}}qa(f,c,d)}F[e|0]=0;c=b+4|0;b=nb(b,a+8|0);d:{if((c|0)==(b|0)){break d}c=H[b+32>>2];b=H[b+28>>2];if((c-b|0)!=8){break d}c=I[b+4|0]|I[b+5|0]<<8|(I[b+6|0]<<16|I[b+7|0]<<24);H[a+24>>2]=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[a+28>>2]=c}g=M[a+24>>3];if(F[a+19|0]<0){oa(H[a+8>>2])}ca=a+32|0;break a}Na();v()}return+g}function uf(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;f=1;a:{if((ea[H[H[b>>2]+20>>2]](b)|0)<=0){break a}while(1){f=0;c=Zd(H[H[a+4>>2]+4>>2],ea[H[H[b>>2]+24>>2]](b,g)|0);if((c|0)==-1){break a}e=H[a+4>>2];b:{if(I[e+36|0]<=1){if(ea[H[H[b>>2]+28>>2]](b,H[H[H[e+4>>2]+8>>2]+(c<<2)>>2])|0){break b}break a}d=0;c:{if((c|0)<0){break c}h=H[e+4>>2];if(H[h+12>>2]-H[h+8>>2]>>2<=(c|0)){break c}d=H[H[e+8>>2]+(H[H[e+20>>2]+(c<<2)>>2]<<2)>>2];d=ea[H[H[d>>2]+32>>2]](d,c)|0}if(!d){break a}if(!(ea[H[H[b>>2]+28>>2]](b,d)|0)){break a}}f=1;g=g+1|0;if((ea[H[H[b>>2]+20>>2]](b)|0)>(g|0)){continue}break}}return f|0}function tb(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;a:{b:{if(b){if(b>>>0>=357913942){break b}b=N(b,12);d=pa(b);H[a+4>>2]=d;H[a>>2]=d;e=b+d|0;H[a+8>>2]=e;f=H[c+4>>2];g=H[c>>2];c:{if((f|0)==(g|0)){b=b-12|0;ra(d,0,(b-((b>>>0)%12|0)|0)+12|0);break c}h=f-g|0;if((h|0)<0){break a}i=h&-4;while(1){H[d+8>>2]=0;H[d>>2]=0;H[d+4>>2]=0;b=pa(h);H[d>>2]=b;H[d+8>>2]=b+i;c=g;while(1){H[b>>2]=H[c>>2];b=b+4|0;c=c+4|0;if((f|0)!=(c|0)){continue}break}H[d+4>>2]=b;d=d+12|0;if((e|0)!=(d|0)){continue}break}}H[a+4>>2]=e}return}sa();v()}H[d+8>>2]=0;H[d>>2]=0;H[d+4>>2]=0;sa();v()}function Vi(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;c=H[b+8>>2];d=H[b+12>>2];g=d;d=H[b+20>>2];i=d;h=H[b+16>>2];f=h+4|0;d=f>>>0<4?d+1|0:d;a:{if(c>>>0>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}e=h+H[b>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=d;if(J[b+38>>1]<=513){f=c;c=i;d=h+8|0;c=d>>>0<8?c+1|0:c;if(d>>>0>f>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break a}H[b+16>>2]=d;H[b+20>>2]=c}if(!(e&1)){break a}b=Q(e)^31;if(b-1>>>0>28){break a}j=1;H[a+8>>2]=b+1;b=-2<>2]=c;H[a+12>>2]=b^-1;H[a+24>>2]=c>>1;L[a+20>>2]=O(2)/O(c|0)}return j|0}function Lc(a,b,c){var d=0,e=0,f=0,g=0;a:{f=b>>>0<1431655766&(b|c)>=0;b:{if(!f){break b}b=N(b,3);Kc(a,b,13648);Kc(a+12|0,b,13652);d=H[a+24>>2];c:{if(H[a+32>>2]-d>>2>>>0>=c>>>0){break c}if(c>>>0>=1073741824){break a}b=H[a+28>>2];e=c<<2;c=pa(e);e=c+e|0;g=c+(b-d&-4)|0;c=g;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;H[c>>2]=H[b>>2];if((b|0)!=(d|0)){continue}break}}H[a+32>>2]=e;H[a+28>>2]=g;H[a+24>>2]=c;if(!d){break c}oa(d)}H[a+80>>2]=0;H[a+84>>2]=0;b=H[a+76>>2];H[a+76>>2]=0;if(b){oa(b)}H[a+68>>2]=0;H[a+72>>2]=0;b=a- -64|0;a=H[b>>2];H[b>>2]=0;if(!a){break b}oa(a)}return f}sa();v()}function Fe(a){var b=0,c=0,d=0,e=0,f=0;f=1;c=H[a+140>>2];a:{if((c|0)<=0){break a}b=c<<4;d=pa(c>>>0>268435455?-1:b|4);H[d>>2]=c;d=d+4|0;c=d+b|0;b=d;while(1){H[b>>2]=0;H[b+4>>2]=0;F[b+5|0]=0;F[b+6|0]=0;F[b+7|0]=0;F[b+8|0]=0;F[b+9|0]=0;F[b+10|0]=0;F[b+11|0]=0;F[b+12|0]=0;b=b+16|0;if((c|0)!=(b|0)){continue}break}e=H[a+136>>2];H[a+136>>2]=d;if(e){c=e-4|0;d=H[c>>2];if(d){b=(d<<4)+e|0;while(1){b=b-16|0;if((e|0)!=(b|0)){continue}break}}oa(c)}b=0;if(H[a+140>>2]<=0){break a}while(1){f=ta(H[a+136>>2]+(b<<4)|0,a);if(!f){break a}b=b+1|0;if((b|0)>2]){continue}break}}return f}function mb(a,b){var c=0,d=0,e=0,f=0,g=0;a:{if(H[a+64>>2]){break a}c=pa(32);H[c+16>>2]=0;H[c+20>>2]=0;H[c+8>>2]=0;H[c>>2]=0;H[c+4>>2]=0;H[c+24>>2]=0;H[c+28>>2]=0;d=H[a+64>>2];H[a+64>>2]=c;if(!d){break a}c=H[d>>2];if(c){H[d+4>>2]=c;oa(c)}oa(d)}d=H[a+64>>2];c=H[a+28>>2]-1|0;if(c>>>0<=10){c=H[(c<<2)+13584>>2]}else{c=-1}c=N(c,I[a+24|0]);f=c>>31;g=se(d,0,Rj(c,f,b,0),da);if(g){d=H[a+64>>2];H[a>>2]=d;e=H[d+20>>2];H[a+8>>2]=H[d+16>>2];H[a+12>>2]=e;e=H[d+24>>2];d=H[d+28>>2];H[a+48>>2]=0;H[a+52>>2]=0;H[a+40>>2]=c;H[a+44>>2]=f;H[a+16>>2]=e;H[a+20>>2]=d;H[a+80>>2]=b}return g}function jc(a,b){var c=0;c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c;c=H[b+60>>2];H[a+56>>2]=H[b+56>>2];H[a+60>>2]=c;c=H[b+52>>2];H[a+48>>2]=H[b+48>>2];H[a+52>>2]=c;c=H[b+44>>2];H[a+40>>2]=H[b+40>>2];H[a+44>>2]=c;c=H[b+36>>2];H[a+32>>2]=H[b+32>>2];H[a+36>>2]=c;c=H[b+28>>2];H[a+24>>2]=H[b+24>>2];H[a+28>>2]=c;c=H[b+20>>2];H[a+16>>2]=H[b+16>>2];H[a+20>>2]=c;c=H[b+12>>2];H[a+8>>2]=H[b+8>>2];H[a+12>>2]=c;H[a+88>>2]=0;H[a+64>>2]=0;H[a+68>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;F[a+77|0]=0;F[a+78|0]=0;F[a+79|0]=0;F[a+80|0]=0;F[a+81|0]=0;F[a+82|0]=0;F[a+83|0]=0;F[a+84|0]=0;return a}function zg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0;a=H[b+100>>2];b=H[b+96>>2];h=a-b|0;a:{if((h|0)!=(c|0)|(a|0)==(b|0)){break a}g=(c|0)/12|0;e=g>>>0<=1?1:g;j=e&1;a=0;if(g>>>0>=2){k=e&-2;g=0;while(1){e=N(a,12);i=e+d|0;f=b+e|0;H[i>>2]=H[f>>2];H[(e|4)+d>>2]=H[f+4>>2];H[i+8>>2]=H[f+8>>2];f=N(a|1,12);e=f+d|0;f=b+f|0;H[e>>2]=H[f>>2];H[e+4>>2]=H[f+4>>2];H[e+8>>2]=H[f+8>>2];a=a+2|0;g=g+2|0;if((k|0)!=(g|0)){continue}break}}if(!j){break a}e=d;d=N(a,12);a=e+d|0;b=b+d|0;H[a>>2]=H[b>>2];H[a+4>>2]=H[b+4>>2];H[a+8>>2]=H[b+8>>2]}return(c|0)==(h|0)|0}function Mi(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;c=H[b+8>>2];d=H[b+12>>2];g=d;d=H[b+20>>2];i=d;h=H[b+16>>2];f=h+4|0;d=f>>>0<4?d+1|0:d;a:{if(c>>>0>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}e=h+H[b>>2]|0;e=I[e|0]|I[e+1|0]<<8|(I[e+2|0]<<16|I[e+3|0]<<24);H[b+16>>2]=f;H[b+20>>2]=d;f=c;c=i;d=h+8|0;c=d>>>0<8?c+1|0:c;if(d>>>0>f>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break a}H[b+16>>2]=d;H[b+20>>2]=c;if(!(e&1)){break a}b=Q(e)^31;if(b-1>>>0>28){break a}j=1;H[a+8>>2]=b+1;b=-2<>2]=c;H[a+12>>2]=b^-1;H[a+24>>2]=c>>1;L[a+20>>2]=O(2)/O(c|0)}return j|0}function nb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;f=a+4|0;a=H[a+4>>2];a:{b:{if(!a){break b}d=I[b+11|0];c=d<<24>>24<0;g=c?H[b>>2]:b;d=c?H[b+4>>2]:d;b=f;while(1){e=I[a+27|0];c=e<<24>>24<0;e=c?H[a+20>>2]:e;h=e>>>0>d>>>0;i=h?d:e;c:{if(i){c=Fa(c?H[a+16>>2]:a+16|0,g,i);if(c){break c}}c=d>>>0>e>>>0?-1:h}c=(c|0)<0;b=c?b:a;a=H[(c?a+4|0:a)>>2];if(a){continue}break}if((b|0)==(f|0)){break b}c=I[b+27|0];a=c<<24>>24<0;d:{c=a?H[b+20>>2]:c;e=c>>>0>>0?c:d;if(e){a=Fa(g,a?H[b+16>>2]:b+16|0,e);if(a){break d}}if(c>>>0>d>>>0){break b}break a}if((a|0)>=0){break a}}b=f}return b}function Jf(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;if(Ya(a,H[b+8>>2],e)){if(!(H[b+28>>2]==1|H[b+4>>2]!=(c|0))){H[b+28>>2]=d}return}a:{if(Ya(a,H[b>>2],e)){if(!(H[b+16>>2]!=(c|0)&H[b+20>>2]!=(c|0))){if((d|0)!=1){break a}H[b+32>>2]=1;return}H[b+32>>2]=d;b:{if(H[b+44>>2]==4){break b}G[b+52>>1]=0;a=H[a+8>>2];ea[H[H[a>>2]+20>>2]](a,b,c,c,1,e);if(I[b+53|0]){H[b+44>>2]=3;if(!I[b+52|0]){break b}break a}H[b+44>>2]=4}H[b+20>>2]=c;H[b+40>>2]=H[b+40>>2]+1;if(H[b+36>>2]!=1|H[b+24>>2]!=2){break a}F[b+54|0]=1;return}a=H[a+8>>2];ea[H[H[a>>2]+24>>2]](a,b,c,d,e)}}function Db(a,b,c){var d=0,e=0,f=0,g=0;a:{b:{if(!b){break b}if(J[a+38>>1]<=513){f=H[a+12>>2];d=H[a+20>>2];b=H[a+16>>2];g=b+8|0;d=g>>>0<8?d+1|0:d;e=0;if(K[a+8>>2]>>0&(d|0)>=(f|0)|(d|0)>(f|0)){break a}b=b+H[a>>2]|0;d=I[b+4|0]|I[b+5|0]<<8|(I[b+6|0]<<16|I[b+7|0]<<24);H[c>>2]=I[b|0]|I[b+1|0]<<8|(I[b+2|0]<<16|I[b+3|0]<<24);H[c+4>>2]=d;b=H[a+20>>2];c=H[a+16>>2]+8|0;b=c>>>0<8?b+1|0:b;H[a+16>>2]=c;H[a+20>>2]=b;break b}e=0;if(!re(1,c,a)){break a}}F[a+36|0]=1;H[a+32>>2]=0;b=H[a+16>>2];c=b+H[a>>2]|0;H[a+24>>2]=c;H[a+28>>2]=(H[a+8>>2]-b|0)+c;e=1}return e}function ve(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;f=pa(64);c=pa(12);H[c+8>>2]=H[H[a+4>>2]+80>>2];H[c>>2]=13216;H[c+4>>2]=0;f=od(f,c);a:{b:{if((b|0)<0){c=f;break b}h=a+8|0;c=H[a+12>>2];e=H[a+8>>2];g=c-e>>2;c:{if((g|0)>(b|0)){break c}d=b+1|0;if(b>>>0>=g>>>0){Vb(h,d-g|0);break c}if(d>>>0>=g>>>0){break c}e=e+(d<<2)|0;if((e|0)!=(c|0)){while(1){c=c-4|0;d=H[c>>2];H[c>>2]=0;if(d){ea[H[H[d>>2]+4>>2]](d)}if((c|0)!=(e|0)){continue}break}}H[a+12>>2]=e}a=H[h>>2]+(b<<2)|0;c=H[a>>2];H[a>>2]=f;if(!c){break a}}ea[H[H[c>>2]+4>>2]](c)}return(b^-1)>>>31|0}function Qd(a,b){var c=0,d=0,e=0,f=0;d=ca-16|0;ca=d;H[d+12>>2]=b;c=ca-208|0;ca=c;H[c+204>>2]=b;b=c+160|0;ra(b,0,40);H[c+200>>2]=H[c+204>>2];a:{if((Od(0,a,c+200|0,c+80|0,b)|0)<0){break a}f=H[3941]>=0;b=H[3922];if(H[3940]<=0){H[3922]=b&-33}b:{c:{d:{if(!H[3934]){H[3934]=80;H[3929]=0;H[3926]=0;H[3927]=0;e=H[3933];H[3933]=c;break d}if(H[3926]){break c}}if(Sd(15688)){break b}}Od(15688,a,c+200|0,c+80|0,c+160|0)}if(e){ea[H[3931]](15688,0,0)|0;H[3934]=0;H[3933]=e;H[3929]=0;H[3926]=0;H[3927]=0}H[3922]=H[3922]|b&32;if(!f){break a}}ca=c+208|0;ca=d+16|0}function pf(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;c=H[a+60>>2];a:{if(!c){break a}H[c+4>>2]=a+48;if(!(ea[H[H[c>>2]+12>>2]](c)|0)){break a}b:{c=ea[H[H[a>>2]+24>>2]](a)|0;if((c|0)<=0){break b}while(1){c:{f=H[(ea[H[H[a>>2]+28>>2]](a)|0)+4>>2];g=ea[H[H[a>>2]+20>>2]](a,d)|0;e=H[a+60>>2];if(!(ea[H[H[e>>2]+8>>2]](e,H[H[f+8>>2]+(g<<2)>>2])|0)){break c}d=d+1|0;if((c|0)!=(d|0)){continue}break b}break}return 0}d=0;if(!(ea[H[H[a>>2]+36>>2]](a,b)|0)){break a}if(!(ea[H[H[a>>2]+40>>2]](a,b)|0)){break a}d=ea[H[H[a>>2]+44>>2]](a)|0}return d|0}function id(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;c=H[a+216>>2];if((c|0)!=H[a+220>>2]){while(1){a:{c=H[N(e,144)+c>>2];if((c|0)<0){break a}d=H[a+4>>2];f=H[d+8>>2];if((c|0)>=H[d+12>>2]-f>>2){break a}d=0;c=H[(c<<2)+f>>2];if((ea[H[H[c>>2]+24>>2]](c)|0)<=0){break a}while(1){if((ea[H[H[c>>2]+20>>2]](c,d)|0)!=(b|0)){d=d+1|0;if((ea[H[H[c>>2]+24>>2]](c)|0)>(d|0)){continue}break a}break}a=H[a+216>>2]+N(e,144)|0;return(I[a+100|0]?a+4|0:0)|0}e=e+1|0;c=H[a+216>>2];if(e>>>0<(H[a+220>>2]-c|0)/144>>>0){continue}break}}return 0}function xb(a){var b=0,c=0,d=0,e=0;c=H[a+132>>2];if(c){d=c;b=H[a+136>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;e=H[d>>2];if(e){H[b-8>>2]=e;oa(e)}b=d;if((c|0)!=(b|0)){continue}break}d=H[a+132>>2]}H[a+136>>2]=c;oa(d)}c=H[a+120>>2];if(c){d=c;b=H[a+124>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;e=H[d>>2];if(e){H[b-8>>2]=e;oa(e)}b=d;if((c|0)!=(b|0)){continue}break}d=H[a+120>>2]}H[a+124>>2]=c;oa(d)}b=H[a+108>>2];if(b){H[a+112>>2]=b;oa(b)}b=H[a+96>>2];if(b){H[a+100>>2]=b;oa(b)}Za(a+76|0);Za(a+56|0);Za(a+36|0);Za(a+16|0)}function rd(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=2128;d=H[a+60>>2];if(d){b=d;c=H[a- -64>>2];if((b|0)!=(c|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){Ga(b)}if((c|0)!=(d|0)){continue}break}b=H[a+60>>2]}H[a+64>>2]=d;oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}d=H[a+36>>2];if(d){b=d;c=H[a+40>>2];if((b|0)!=(c|0)){while(1){c=c-24|0;ea[H[H[c>>2]>>2]](c)|0;if((c|0)!=(d|0)){continue}break}b=H[a+36>>2]}H[a+40>>2]=d;oa(b)}H[a>>2]=1984;b=H[a+16>>2];if(b){H[a+20>>2]=b;oa(b)}b=H[a+4>>2];if(b){H[a+8>>2]=b;oa(b)}return a|0}function ue(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;c=H[a+8>>2];d=H[a+4>>2];if(c-d>>2>>>0>=b>>>0){if(b){b=b<<2;d=ra(d,0,b)+b|0}H[a+4>>2]=d;return}a:{f=H[a>>2];g=d-f>>2;e=g+b|0;if(e>>>0<1073741824){c=c-f|0;h=c>>>1|0;e=c>>>0>=2147483644?1073741823:e>>>0>>0?h:e;if(e){if(e>>>0>=1073741824){break a}i=pa(e<<2)}c=(g<<2)+i|0;b=b<<2;b=ra(c,0,b)+b|0;if((d|0)!=(f|0)){while(1){c=c-4|0;d=d-4|0;H[c>>2]=H[d>>2];if((d|0)!=(f|0)){continue}break}}H[a+8>>2]=(e<<2)+i;H[a+4>>2]=b;H[a>>2]=c;if(f){oa(f)}return}sa();v()}wa();v()}function rb(a){var b=0,c=0,d=0,e=0,f=0;d=H[a+8>>2];a:{if(I[d+84|0]){break a}b=H[a+16>>2];if(!b|!I[b+84|0]){break a}c=H[d+72>>2];e=H[d+68>>2];F[b+84|0]=0;c=c-e>>2;f=H[b+68>>2];e=H[b+72>>2]-f>>2;b:{if(c>>>0>e>>>0){qb(b+68|0,c-e|0,2316);d=H[a+8>>2];break b}if(c>>>0>=e>>>0){break b}H[b+72>>2]=f+(c<<2)}if(I[d+84|0]){break a}c=H[d+68>>2];if((c|0)==H[d+72>>2]){break a}e=H[H[a+16>>2]+68>>2];b=0;while(1){f=b<<2;H[f+e>>2]=H[c+f>>2];b=b+1|0;c=H[d+68>>2];if(b>>>0>2]-c>>2>>>0){continue}break}}return H[a+16>>2]}function Lg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=ca+-64|0;ca=e;f=Ha(e+8|0);H[f+16>>2]=0;H[f+20>>2]=0;H[f>>2]=b;H[f+8>>2]=c;H[f+12>>2]=0;b=e+48|0;Pe(b,a,f,d);H[a+24>>2]=H[e+48>>2];f=a+24|0;a:{if((f|0)==(b|0)){break a}b=a+28|0;c=e+48|4;g=I[e+63|0];d=g<<24>>24;if(F[a+39|0]>=0){if((d|0)>=0){a=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=a;H[b+8>>2]=H[c+8>>2];break a}Xb(b,H[e+52>>2],H[e+56>>2]);break a}a=(d|0)<0;Yb(b,a?H[e+52>>2]:c,a?H[e+56>>2]:g)}if(F[e+63|0]<0){oa(H[e+52>>2])}ca=e- -64|0;return f|0}function Kg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=ca+-64|0;ca=e;f=Ha(e+8|0);H[f+16>>2]=0;H[f+20>>2]=0;H[f>>2]=b;H[f+8>>2]=c;H[f+12>>2]=0;b=e+48|0;Oe(b,a,f,d);H[a+24>>2]=H[e+48>>2];f=a+24|0;a:{if((f|0)==(b|0)){break a}b=a+28|0;c=e+48|4;g=I[e+63|0];d=g<<24>>24;if(F[a+39|0]>=0){if((d|0)>=0){a=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=a;H[b+8>>2]=H[c+8>>2];break a}Xb(b,H[e+52>>2],H[e+56>>2]);break a}a=(d|0)<0;Yb(b,a?H[e+52>>2]:c,a?H[e+56>>2]:g)}if(F[e+63|0]<0){oa(H[e+52>>2])}ca=e- -64|0;return f|0}function Ig(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;a=ca-32|0;ca=a;a:{d=Ma(c);if(d>>>0<2147483632){b:{c:{if(d>>>0>=11){e=(d|15)+1|0;f=pa(e);H[a+24>>2]=e|-2147483648;H[a+16>>2]=f;H[a+20>>2]=d;e=d+f|0;break c}F[a+27|0]=d;f=a+16|0;e=f+d|0;if(!d){break b}}qa(f,c,d)}F[e|0]=0;F[a+4|0]=0;H[a>>2]=1701667182;F[a+11|0]=4;d=H[b+4>>2];c=-1;d:{if(!d){break d}d=be(d,a,a+16|0);c=-1;if(!d){break d}c=Yd(b,H[d+24>>2])}b=c;if(F[a+11|0]<0){oa(H[a>>2])}if(F[a+27|0]<0){oa(H[a+16>>2])}ca=a+32|0;break a}Na();v()}return b|0}function hd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;c=H[a+216>>2];if((c|0)!=H[a+220>>2]){while(1){a:{c=H[N(e,144)+c>>2];if((c|0)<0){break a}d=H[a+4>>2];f=H[d+8>>2];if((c|0)>=H[d+12>>2]-f>>2){break a}d=0;c=H[(c<<2)+f>>2];if((ea[H[H[c>>2]+24>>2]](c)|0)<=0){break a}while(1){if((ea[H[H[c>>2]+20>>2]](c,d)|0)!=(b|0)){d=d+1|0;if((ea[H[H[c>>2]+24>>2]](c)|0)>(d|0)){continue}break a}break}return(H[a+216>>2]+N(e,144)|0)+104|0}e=e+1|0;c=H[a+216>>2];if(e>>>0<(H[a+220>>2]-c|0)/144>>>0){continue}break}}return a+184|0}function ab(a){var b=0,c=0,d=0,e=0;c=H[a+640>>2];if(c){d=c;b=H[a+644>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;e=H[d>>2];if(e){H[b-8>>2]=e;oa(e)}b=d;if((c|0)!=(b|0)){continue}break}d=H[a+640>>2]}H[a+644>>2]=c;oa(d)}c=H[a+628>>2];if(c){d=c;b=H[a+632>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;e=H[d>>2];if(e){H[b-8>>2]=e;oa(e)}b=d;if((c|0)!=(b|0)){continue}break}d=H[a+628>>2]}H[a+632>>2]=c;oa(d)}b=H[a+616>>2];if(b){H[a+620>>2]=b;oa(b)}b=H[a+604>>2];if(b){H[a+608>>2]=b;oa(b)}Za(a+584|0);Za(a+564|0);Za(a+544|0)}function Tg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;d=ca-16|0;ca=d;H[d+12>>2]=0;a:{e=Ma(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){f=(e|15)+1|0;a=pa(f);H[d+8>>2]=f|-2147483648;H[d>>2]=a;H[d+4>>2]=e;f=a+e|0;break c}F[d+11|0]=e;f=d+e|0;a=d;if(!e){break b}}qa(a,c,e)}F[f|0]=0;a=nb(b,d);d:{if((a|0)==(b+4|0)){break d}b=H[a+32>>2];a=H[a+28>>2];if((b-a|0)!=4){break d}H[d+12>>2]=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24)}a=H[d+12>>2];if(F[d+11|0]<0){oa(H[d>>2])}ca=d+16|0;break a}Na();v()}return a|0}function vb(a){var b=0,c=0,d=0,e=0;c=H[a+128>>2];if(c){d=c;b=H[a+132>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;e=H[d>>2];if(e){H[b-8>>2]=e;oa(e)}b=d;if((c|0)!=(b|0)){continue}break}d=H[a+128>>2]}H[a+132>>2]=c;oa(d)}c=H[a+116>>2];if(c){d=c;b=H[a+120>>2];if((c|0)!=(b|0)){while(1){d=b-12|0;e=H[d>>2];if(e){H[b-8>>2]=e;oa(e)}b=d;if((c|0)!=(b|0)){continue}break}d=H[a+116>>2]}H[a+120>>2]=c;oa(d)}b=H[a+104>>2];if(b){H[a+108>>2]=b;oa(b)}b=H[a+92>>2];if(b){H[a+96>>2]=b;oa(b)}Za(a+72|0);Za(a+52|0);Za(a+32|0)}function kc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;a:{c=H[a+4>>2];e=H[a>>2];d=c-e|0;b:{if(d>>>0>>0){g=b-d|0;f=H[a+8>>2];if(g>>>0<=f-c>>>0){h=a,i=ra(c,0,g)+g|0,H[h+4>>2]=i;break b}if((b|0)<0){break a}c=f-e|0;f=c<<1;c=c>>>0>=1073741823?2147483647:b>>>0>>0?f:b;f=pa(c);ra(f+d|0,0,g);d=va(f,e,d);H[a+8>>2]=d+c;H[a+4>>2]=b+d;H[a>>2]=d;if(!e){break b}oa(e);break b}if(b>>>0>=d>>>0){break b}H[a+4>>2]=b+e}b=H[a+28>>2];c=b;d=b+1|0;b=H[a+24>>2]+1|0;e=b?c:d;H[a+24>>2]=b;H[a+28>>2]=e;return}sa();v()}function Ka(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;e=H[a+4>>2];if((e|0)!=H[a+8>>2]){H[e>>2]=H[b>>2];H[a+4>>2]=e+4;return}a:{g=H[a>>2];f=e-g|0;c=f>>2;d=c+1|0;if(d>>>0<1073741824){h=c<<2;c=f>>>1|0;c=f>>>0>=2147483644?1073741823:c>>>0>d>>>0?c:d;if(c){if(c>>>0>=1073741824){break a}f=pa(c<<2)}else{f=0}d=h+f|0;H[d>>2]=H[b>>2];b=d+4|0;if((e|0)!=(g|0)){while(1){d=d-4|0;e=e-4|0;H[d>>2]=H[e>>2];if((e|0)!=(g|0)){continue}break}}H[a+8>>2]=f+(c<<2);H[a+4>>2]=b;H[a>>2]=d;if(g){oa(g)}return}sa();v()}wa();v()}function Ia(a){H[a>>2]=-1;H[a+4>>2]=0;H[a+8>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;F[a+28|0]=1;H[a+20>>2]=0;H[a+24>>2]=0;H[a+12>>2]=0;H[a+16>>2]=0;H[a+40>>2]=0;H[a+44>>2]=0;H[a+48>>2]=0;H[a+52>>2]=0;H[a+56>>2]=0;H[a+60>>2]=0;H[a+64>>2]=0;H[a+68>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+88>>2]=0;H[a+92>>2]=0;H[a+96>>2]=0;H[a+72>>2]=a+4;H[a+104>>2]=0;H[a+108>>2]=0;F[a+100|0]=1;H[a+112>>2]=0;H[a+116>>2]=0;H[a+120>>2]=0;H[a+124>>2]=0;H[a+128>>2]=0;H[a+132>>2]=0;H[a+136>>2]=0;H[a+140>>2]=0}function Ld(a,b){if(!a){return 0}a:{b:{if(a){if(b>>>0<=127){break b}c:{if(!H[H[4292]>>2]){if((b&-128)==57216){break b}break c}if(b>>>0<=2047){F[a+1|0]=b&63|128;F[a|0]=b>>>6|192;a=2;break a}if(!((b&-8192)!=57344&b>>>0>=55296)){F[a+2|0]=b&63|128;F[a|0]=b>>>12|224;F[a+1|0]=b>>>6&63|128;a=3;break a}if(b-65536>>>0<=1048575){F[a+3|0]=b&63|128;F[a|0]=b>>>18|240;F[a+2|0]=b>>>6&63|128;F[a+1|0]=b>>>12&63|128;a=4;break a}}H[3992]=25;a=-1}else{a=1}break a}F[a|0]=b;a=1}return a}function Hb(a,b){var c=0,d=0,e=0,f=0;d=H[a+12>>2];c=H[a+16>>2]-d>>2;a:{if(c>>>0>>0){ya(a+12|0,b-c|0);break a}if(b>>>0>=c>>>0){break a}H[a+16>>2]=d+(b<<2)}b:{c=H[a>>2];c:{if(H[a+8>>2]-c>>2>>>0>=b>>>0){break c}if(b>>>0>=1073741824){break b}d=H[a+4>>2];e=b<<2;b=pa(e);e=b+e|0;f=b+(d-c&-4)|0;b=f;if((c|0)!=(d|0)){while(1){b=b-4|0;d=d-4|0;H[b>>2]=H[d>>2];if((c|0)!=(d|0)){continue}break}}H[a+8>>2]=e;H[a+4>>2]=f;H[a>>2]=b;if(!c){break c}oa(c)}return}sa();v()}function _b(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=13724;b=H[a+68>>2];if(b){H[a+72>>2]=b;oa(b)}b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}b=H[a+44>>2];if(b){H[a+48>>2]=b;oa(b)}b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}b=H[a+20>>2];if(b){H[a+24>>2]=b;oa(b)}b=H[a+8>>2];if(b){d=b;c=H[a+12>>2];if((b|0)!=(c|0)){while(1){c=c-4|0;d=H[c>>2];H[c>>2]=0;if(d){Ga(d)}if((b|0)!=(c|0)){continue}break}d=H[a+8>>2]}H[a+12>>2]=b;oa(d)}b=H[a+4>>2];H[a+4>>2]=0;if(b){Uc(b)}return a|0}function yb(a,b,c){var d=0,e=0,f=0,g=0,h=0;f=ca-16|0;ca=f;d=ca-32|0;ca=d;e=ca-16|0;ca=e;H[e+12>>2]=b;H[e+8>>2]=b+c;H[d+24>>2]=H[e+12>>2];H[d+28>>2]=H[e+8>>2];ca=e+16|0;c=ca-16|0;ca=c;h=H[d+28>>2];e=H[d+24>>2];g=h-e|0;if((e|0)!=(h|0)){va(a,e,g)}H[c+12>>2]=e+g;H[c+8>>2]=a+g;H[d+16>>2]=H[c+12>>2];H[d+20>>2]=H[c+8>>2];ca=c+16|0;H[d+12>>2]=(H[d+16>>2]-b|0)+b;H[d+8>>2]=(H[d+20>>2]-a|0)+a;H[f+8>>2]=H[d+12>>2];H[f+12>>2]=H[d+8>>2];ca=d+32|0;ca=f+16|0}function ya(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;e=H[a+8>>2];c=H[a+4>>2];if(e-c>>2>>>0>=b>>>0){if(b){b=b<<2;c=ra(c,0,b)+b|0}H[a+4>>2]=c;return}a:{f=c;c=H[a>>2];g=f-c|0;h=g>>2;d=h+b|0;if(d>>>0<1073741824){e=e-c|0;f=e>>>1|0;d=e>>>0>=2147483644?1073741823:d>>>0>>0?f:d;if(d){if(d>>>0>=1073741824){break a}i=pa(d<<2)}b=b<<2;e=ra((h<<2)+i|0,0,b);f=d<<2;d=va(i,c,g);H[a+8>>2]=f+d;H[a+4>>2]=b+e;H[a>>2]=d;if(c){oa(c)}return}sa();v()}wa();v()}function Tc(a,b){var c=0,d=0,e=0,f=0;c=a+4|0;a=nb(a,b);a:{if((c|0)==(a|0)){break a}b=a+28|0;b=F[a+39|0]<0?H[b>>2]:b;while(1){a=b;b=a+1|0;c=F[a|0];if((c|0)==32|c-9>>>0<5){continue}break}b:{c:{d:{c=F[a|0];switch(c-43|0){case 0:break c;case 2:break d;default:break b}}e=1}c=F[b|0];a=b}if(c-48>>>0<10){while(1){d=(N(d,10)-F[a|0]|0)+48|0;b=F[a+1|0];a=a+1|0;if(b-48>>>0<10){continue}break}}a=e?d:0-d|0;if((a|0)==-1){break a}f=(a|0)!=0}return f}function bb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;a=H[a>>2];c=H[a+4>>2];e=H[a+8>>2];if(c>>>0>>0){H[c>>2]=H[b>>2];H[a+4>>2]=c+4;return}a:{d=c;c=H[a>>2];g=d-c|0;d=g>>2;f=d+1|0;if(f>>>0<1073741824){h=d<<2;e=e-c|0;d=e>>>1|0;f=e>>>0>=2147483644?1073741823:f>>>0>>0?d:f;if(f){if(f>>>0>=1073741824){break a}e=pa(f<<2)}else{e=0}d=h+e|0;H[d>>2]=H[b>>2];b=va(e,c,g);H[a+8>>2]=b+(f<<2);H[a+4>>2]=d+4;H[a>>2]=b;if(c){oa(c)}return}sa();v()}wa();v()}function ob(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;e=H[a+8>>2];c=H[a+4>>2];if(e-c>>3>>>0>=b>>>0){if(b){b=b<<3;c=ra(c,0,b)+b|0}H[a+4>>2]=c;return}a:{f=c;c=H[a>>2];g=f-c|0;h=g>>3;d=h+b|0;if(d>>>0<536870912){e=e-c|0;f=e>>>2|0;d=e>>>0>=2147483640?536870911:d>>>0>>0?f:d;if(d){if(d>>>0>=536870912){break a}i=pa(d<<3)}b=b<<3;e=ra((h<<3)+i|0,0,b);f=d<<3;d=va(i,c,g);H[a+8>>2]=f+d;H[a+4>>2]=b+e;H[a>>2]=d;if(c){oa(c)}return}sa();v()}wa();v()}function kf(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=2328;b=H[a+60>>2];H[a+60>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}d=H[a+36>>2];if(d){c=H[a+40>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=H[a+36>>2]}H[a+40>>2]=d;oa(b)}H[a>>2]=1984;b=H[a+16>>2];if(b){H[a+20>>2]=b;oa(b)}b=H[a+4>>2];if(b){H[a+8>>2]=b;oa(b)}return a|0}function jf(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=2328;b=H[a+60>>2];H[a+60>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}d=H[a+36>>2];if(d){c=H[a+40>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=H[a+36>>2]}H[a+40>>2]=d;oa(b)}H[a>>2]=1984;b=H[a+16>>2];if(b){H[a+20>>2]=b;oa(b)}b=H[a+4>>2];if(b){H[a+8>>2]=b;oa(b)}oa(a)}function xi(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;d=ca-16|0;ca=d;e=H[a+4>>2];a:{if((e|0)==-1){break a}c=H[b+20>>2];if(!!H[b+16>>2]&(c|0)>=0|(c|0)>0){break a}Wb(b,H[b+4>>2],H[a+8>>2],H[a+12>>2]);c=H[b+20>>2];if(!!H[b+16>>2]&(c|0)>=0|(c|0)>0){break a}Wb(b,H[b+4>>2],a+20|0,a+24|0);c=H[b+20>>2];f=H[b+16>>2];F[d+15|0]=H[a+4>>2];if(!!f&(c|0)>=0|(c|0)>0){break a}Wb(b,H[b+4>>2],d+15|0,d+16|0)}ca=d+16|0;return(e|0)!=-1|0}function Eh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0;a:{b=H[a+8>>2];b:{if((b|0)<0){break b}c=H[a+4>>2];e=H[c>>2];d=H[c+4>>2]-e>>2;c:{if(d>>>0>>0){ue(c,b-d|0);f=H[a+8>>2];break c}f=b;if(b>>>0>=d>>>0){break c}H[c+4>>2]=e+(b<<2);f=b}d=f;if((d|0)<=0){break b}a=H[a+4>>2];c=H[a>>2];e=H[a+4>>2]-c>>2;a=0;while(1){if((a|0)==(e|0)){break a}H[c+(a<<2)>>2]=a;a=a+1|0;if((d|0)!=(a|0)){continue}break}}return(b^-1)>>>31|0}Ca();v()}function qe(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;e=H[a+8>>2];c=H[a+4>>2];if(e-c>>1>>>0>=b>>>0){if(b){b=b<<1;c=ra(c,0,b)+b|0}H[a+4>>2]=c;return}a:{f=c;c=H[a>>2];g=f-c|0;f=g>>1;d=f+b|0;if((d|0)>=0){e=e-c|0;d=e>>>0>=2147483646?2147483647:d>>>0>>0?e:d;if(d){if((d|0)<0){break a}h=pa(d<<1)}b=b<<1;e=ra((f<<1)+h|0,0,b);f=d<<1;d=va(h,c,g);H[a+8>>2]=f+d;H[a+4>>2]=b+e;H[a>>2]=d;if(c){oa(c)}return}sa();v()}wa();v()}function ng(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;d=ca-16|0;ca=d;Pe(d,a,b,c);H[a+24>>2]=H[d>>2];e=a+24|0;a:{if((e|0)==(d|0)){break a}b=a+28|0;c=d|4;f=I[d+15|0];g=f<<24>>24;if(F[a+39|0]>=0){if((g|0)>=0){a=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=a;H[b+8>>2]=H[c+8>>2];break a}Xb(b,H[d+4>>2],H[d+8>>2]);break a}a=(g|0)<0;Yb(b,a?H[d+4>>2]:c,a?H[d+8>>2]:f)}if(F[d+15|0]<0){oa(H[d+4>>2])}ca=d+16|0;return e|0}function mg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;d=ca-16|0;ca=d;Oe(d,a,b,c);H[a+24>>2]=H[d>>2];e=a+24|0;a:{if((e|0)==(d|0)){break a}b=a+28|0;c=d|4;f=I[d+15|0];g=f<<24>>24;if(F[a+39|0]>=0){if((g|0)>=0){a=H[c+4>>2];H[b>>2]=H[c>>2];H[b+4>>2]=a;H[b+8>>2]=H[c+8>>2];break a}Xb(b,H[d+4>>2],H[d+8>>2]);break a}a=(g|0)<0;Yb(b,a?H[d+4>>2]:c,a?H[d+8>>2]:f)}if(F[d+15|0]<0){oa(H[d+4>>2])}ca=d+16|0;return e|0}function za(a,b,c){var d=0,e=0,f=0,g=0;e=ca-16|0;ca=e;a:{b:{if(c>>>0<11){d=a;F[a+11|0]=I[a+11|0]&128|c;F[a+11|0]=I[a+11|0]&127;break b}if(c>>>0>2147483631){break a}g=e+8|0;if(c>>>0>=11){f=c+16&-16;d=f-1|0;d=(d|0)==11?f:d}else{d=10}Zb(g,d+1|0);d=H[e+8>>2];H[a>>2]=d;H[a+8>>2]=H[a+8>>2]&-2147483648|H[e+12>>2]&2147483647;H[a+8>>2]=H[a+8>>2]|-2147483648;H[a+4>>2]=c}yb(d,b,c+1|0);ca=e+16|0;return}Na();v()}function Qg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;d=ca-16|0;ca=d;a:{e=Ma(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){g=(e|15)+1|0;f=pa(g);H[d+8>>2]=g|-2147483648;H[d>>2]=f;H[d+4>>2]=e;g=e+f|0;break c}F[d+11|0]=e;g=d+e|0;f=d;if(!e){break b}}qa(f,c,e)}F[g|0]=0;f=a+16|0;c=$d(b,d,f);b=H[a+16>>2];a=F[a+27|0];if(F[d+11|0]<0){oa(H[d>>2])}ca=d+16|0;a=c?(a|0)<0?b:f:0;break a}Na();v()}return a|0}function Mc(a,b){var c=0,d=0,e=0;c=H[a+4>>2];d=c+b|0;H[a+4>>2]=d;if(!((d-1^c-1)>>>0<32?c:0)){H[H[a>>2]+((d>>>0>=33?d-1>>>5|0:0)<<2)>>2]=0}a:{if(!b){break a}a=H[a>>2]+(c>>>3&536870908)|0;c=c&31;if(c){d=32-c|0;e=b>>>0>d>>>0?d:b;H[a>>2]=H[a>>2]&(-1<>>d-e^-1);b=b-e|0;a=a+4|0}c=b>>>5|0;if(b>>>0>=32){ra(a,0,c<<2)}if((b&-32)==(b|0)){break a}a=(c<<2)+a|0;H[a>>2]=H[a>>2]&(-1>>>32-(b&31)^-1)}}function Fc(a,b,c){var d=0,e=0,f=0;d=H[c+16>>2];a:{if(!d){if(Sd(c)){break a}d=H[c+16>>2]}f=H[c+20>>2];if(d-f>>>0>>0){return ea[H[c+36>>2]](c,a,b)|0}b:{if(H[c+80>>2]<0){d=0;break b}e=b;while(1){d=e;if(!d){d=0;break b}e=d-1|0;if(I[e+a|0]!=10){continue}break}e=ea[H[c+36>>2]](c,a,d)|0;if(e>>>0>>0){break a}a=a+d|0;b=b-d|0;f=H[c+20>>2]}qa(f,a,b);H[c+20>>2]=H[c+20>>2]+b;e=b+d|0}return e}function ad(a){var b=0,c=0,d=0,e=0;if(I[a+76|0]){F[a+76|0]=0;e=H[a+60>>2];c=H[a+72>>2]+7|0;b=c>>>0<7?1:b;d=b<<29|c>>>3;c=d+H[a+56>>2]|0;b=(b>>>3|0)+e|0;H[a+56>>2]=c;H[a+60>>2]=c>>>0>>0?b+1|0:b}if(J[a+38>>1]<=513){F[a+132|0]=0;e=H[a+116>>2];b=0;c=H[a+128>>2]+7|0;b=c>>>0<7?1:b;d=b<<29|c>>>3;c=d+H[a+112>>2]|0;b=(b>>>3|0)+e|0;H[a+112>>2]=c;H[a+116>>2]=c>>>0>>0?b+1|0:b}}function re(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>10){break a}d=H[c+20>>2];f=H[c+12>>2];e=H[c+16>>2];if((d|0)>=(f|0)&e>>>0>=K[c+8>>2]|(d|0)>(f|0)){break a}f=F[e+H[c>>2]|0];e=e+1|0;d=e?d:d+1|0;H[c+16>>2]=e;H[c+20>>2]=d;d=f;b:{if((d|0)<0){if(!re(a+1|0,b,c)){break a}a=H[b>>2];d=d&127|a<<7;a=H[b+4>>2]<<7|a>>>25;break b}d=d&255;a=0}H[b>>2]=d;H[b+4>>2]=a;g=1}return g}function gb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>10){break a}d=H[c+20>>2];f=H[c+12>>2];e=H[c+16>>2];if((d|0)>=(f|0)&e>>>0>=K[c+8>>2]|(d|0)>(f|0)){break a}f=F[e+H[c>>2]|0];e=e+1|0;d=e?d:d+1|0;H[c+16>>2]=e;H[c+20>>2]=d;d=f;b:{if((d|0)<0){if(!gb(a+1|0,b,c)){break a}a=H[b>>2];d=d&127|a<<7;a=H[b+4>>2]<<7|a>>>25;break b}d=d&255;a=0}H[b>>2]=d;H[b+4>>2]=a;g=1}return g}function Nh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;e=ca+-64|0;ca=e;d=ea[H[H[a>>2]+44>>2]](a,b)|0;a=ea[H[H[a>>2]+40>>2]](a,b)|0;f=Eb(e);g=H[b+56>>2];h=d&255;i=a;a=a-1|0;if(a>>>0<=10){a=H[(a<<2)+13584>>2]}else{a=-1}d=N(a,d);lc(f,g,h,i,0,d,d>>31);a=jc(pa(96),f);mb(a,c);F[a+84|0]=1;H[a+72>>2]=H[a+68>>2];H[a+60>>2]=H[b+60>>2];ca=e- -64|0;return a|0}function If(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;if(Ya(a,H[b+8>>2],e)){if(!(H[b+28>>2]==1|H[b+4>>2]!=(c|0))){H[b+28>>2]=d}return}a:{if(!Ya(a,H[b>>2],e)){break a}if(!(H[b+16>>2]!=(c|0)&H[b+20>>2]!=(c|0))){if((d|0)!=1){break a}H[b+32>>2]=1;return}H[b+20>>2]=c;H[b+32>>2]=d;H[b+40>>2]=H[b+40>>2]+1;if(!(H[b+36>>2]!=1|H[b+24>>2]!=2)){F[b+54|0]=1}H[b+44>>2]=4}}function Bh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0;e=H[a+32>>2];b=e;h=H[b+8>>2];g=H[b+12>>2];c=H[b+16>>2];b=H[b+20>>2];f=c+4|0;b=f>>>0<4?b+1|0:b;d=0;a:{if(f>>>0>h>>>0&(b|0)>=(g|0)|(b|0)>(g|0)){break a}c=H[e>>2]+c|0;c=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[e+16>>2]=f;H[e+20>>2]=b;d=0;if((c|0)<0){break a}H[H[a+4>>2]+80>>2]=c;d=1}return d|0}function qi(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=11276;b=H[a+48>>2];H[a+48>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}H[a>>2]=13280;b=H[a+20>>2];if(b){H[a+24>>2]=b;oa(b)}d=H[a+8>>2];if(d){c=H[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=H[a+8>>2]}H[a+12>>2]=d;oa(b)}return a|0}function Ee(a,b){var c=0,d=0,e=0,f=0;H[a+144>>2]=b;c=H[(ea[H[H[b>>2]+32>>2]](b)|0)+32>>2];c=H[c>>2]+H[c+16>>2]|0;d=H[(ea[H[H[b>>2]+32>>2]](b)|0)+32>>2];d=H[d+8>>2]-H[d+16>>2]|0;e=a,f=J[H[(ea[H[H[b>>2]+32>>2]](b)|0)+32>>2]+38>>1],G[e+38>>1]=f;H[a>>2]=c;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=d;H[a+12>>2]=0;e=a,f=ea[H[H[b>>2]+36>>2]](b)|0,H[e+148>>2]=f}function Cd(a,b,c,d){F[a+53|0]=1;a:{if(H[a+4>>2]!=(c|0)){break a}F[a+52|0]=1;c=H[a+16>>2];b:{if(!c){H[a+36>>2]=1;H[a+24>>2]=d;H[a+16>>2]=b;if((d|0)!=1){break a}if(H[a+48>>2]==1){break b}break a}if((b|0)==(c|0)){c=H[a+24>>2];if((c|0)==2){H[a+24>>2]=d;c=d}if(H[a+48>>2]!=1){break a}if((c|0)==1){break b}break a}H[a+36>>2]=H[a+36>>2]+1}F[a+54|0]=1}}function pi(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=11276;b=H[a+48>>2];H[a+48>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}H[a>>2]=13280;b=H[a+20>>2];if(b){H[a+24>>2]=b;oa(b)}d=H[a+8>>2];if(d){c=H[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=H[a+8>>2]}H[a+12>>2]=d;oa(b)}oa(a)}function zh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0;e=H[a+32>>2];b=e;g=H[b+8>>2];d=H[b+12>>2];c=H[b+16>>2];b=H[b+20>>2];f=d;d=c+4|0;b=d>>>0<4?b+1|0:b;if((f|0)>=(b|0)&d>>>0<=g>>>0|(b|0)<(f|0)){c=H[e>>2]+c|0;c=I[c|0]|I[c+1|0]<<8|(I[c+2|0]<<16|I[c+3|0]<<24);H[e+16>>2]=d;H[e+20>>2]=b;H[H[a+4>>2]+80>>2]=c}return(b|0)<=(f|0)&d>>>0<=g>>>0|(b|0)<(f|0)}function Mf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;e=ca+-64|0;ca=e;d=1;a:{if(Ya(a,b,0)){break a}d=0;if(!b){break a}b=Ed(b,14972);d=0;if(!b){break a}d=e+8|0;ra(d|4,0,52);H[e+56>>2]=1;H[e+20>>2]=-1;H[e+16>>2]=a;H[e+8>>2]=b;ea[H[H[b>>2]+28>>2]](b,d,H[c>>2],1);a=H[e+32>>2];if((a|0)==1){H[c>>2]=H[e+24>>2]}d=(a|0)==1}ca=e- -64|0;return d|0}function Ie(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=ca-16|0;ca=d;H[a+4>>2]=b;b=H[b+64>>2];e=H[b>>2];b=H[b+4>>2];F[d+15|0]=0;Oa(a+24|0,(b-e>>2>>>0)/3|0,d+15|0);b=H[a+4>>2];e=H[b+56>>2];b=H[b+52>>2];F[d+14|0]=0;Oa(a+36|0,e-b>>2,d+14|0);b=H[c+12>>2];H[a+16>>2]=H[c+8>>2];H[a+20>>2]=b;b=H[c+4>>2];H[a+8>>2]=H[c>>2];H[a+12>>2]=b;ca=d+16|0}function pc(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;if(!b){H[c>>2]=0;return}h=0-I[a+12|0]&255;e=H[a+4>>2];d=H[a+8>>2];i=H[a>>2];while(1){j=f<<1;if(!((e|0)<=0|d>>>0>4095)){e=e-1|0;H[a+4>>2]=e;d=I[e+i|0]|d<<8}g=d&255;f=g>>>0>>0;k=g;g=N(d>>>8|0,h);d=f?k+g|0:d-(h+g|0)|0;H[a+8>>2]=d;f=f|j;b=b-1|0;if(b){continue}break}H[c>>2]=f}function yg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;a=ca-16|0;ca=a;f=F[b+24|0];e=H[3411];H[a+8>>2]=H[3410];H[a+12>>2]=e;e=H[3409];H[a>>2]=H[3408];H[a+4>>2]=e;e=Va(b,c,f,a);if(e){b=0;if(f){c=(f&255)<<2;b=pa(c);g=qa(b,a,c)+c|0}c=H[d>>2];if(c){H[d+4>>2]=c;oa(c)}H[d+8>>2]=g;H[d+4>>2]=g;H[d>>2]=b}ca=a+16|0;return e|0}function of(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;f=ea[H[H[a>>2]+24>>2]](a)|0;c=1;a:{if((f|0)<=0){break a}d=H[H[a+36>>2]>>2];g=a+48|0;c=0;if(!(ea[H[H[d>>2]+16>>2]](d,g,b)|0)){break a}while(1){e=e+1|0;if((f|0)!=(e|0)){d=H[H[a+36>>2]+(e<<2)>>2];if(ea[H[H[d>>2]+16>>2]](d,g,b)|0){continue}}break}c=(e|0)>=(f|0)}return c|0}function nf(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;f=ea[H[H[a>>2]+24>>2]](a)|0;c=1;a:{if((f|0)<=0){break a}d=H[H[a+36>>2]>>2];g=a+48|0;c=0;if(!(ea[H[H[d>>2]+20>>2]](d,g,b)|0)){break a}while(1){e=e+1|0;if((f|0)!=(e|0)){d=H[H[a+36>>2]+(e<<2)>>2];if(ea[H[H[d>>2]+20>>2]](d,g,b)|0){continue}}break}c=(e|0)>=(f|0)}return c|0}function _c(a,b){var c=0,d=0;a:{c=H[a+4>>2];d=H[a+8>>2];if((c|0)==d<<5){if((c+1|0)<0){break a}if(c>>>0<=1073741822){d=d<<6;c=(c&-32)+32|0;c=c>>>0>>0?d:c}else{c=2147483647}pb(a,c);c=H[a+4>>2]}H[a+4>>2]=c+1;d=1<>2]+(c>>>3&536870908)|0;if(I[b|0]){H[a>>2]=d|H[a>>2];return}H[a>>2]=H[a>>2]&(d^-1);return}sa();v()}function $h(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=ca-16|0;ca=d;H[a+4>>2]=b;e=H[b>>2];b=H[b+4>>2];F[d+15|0]=0;Oa(a+24|0,(b-e>>2>>>0)/3|0,d+15|0);b=H[a+4>>2];e=H[b+28>>2];b=H[b+24>>2];F[d+14|0]=0;Oa(a+36|0,e-b>>2,d+14|0);b=H[c+12>>2];H[a+16>>2]=H[c+8>>2];H[a+20>>2]=b;b=H[c+4>>2];H[a+8>>2]=H[c>>2];H[a+12>>2]=b;ca=d+16|0}function $b(a){var b=0;H[a>>2]=0;H[a+4>>2]=0;H[a+56>>2]=0;H[a+48>>2]=0;H[a+52>>2]=0;H[a+40>>2]=0;H[a+44>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0;b=a- -64|0;H[b>>2]=0;H[b+4>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;H[a+80>>2]=0;H[a+84>>2]=0;H[a+60>>2]=a;return a}function td(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!td(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g} +function hb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!hb(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Xa(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Xa(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Qe(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Qe(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Pc(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Pc(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Fb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Fb(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Ea(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Ea(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Bb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=H[c+20>>2];e=H[c+12>>2];f=H[c+16>>2];if((d|0)>=(e|0)&f>>>0>=K[c+8>>2]|(d|0)>(e|0)){break a}e=I[H[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;H[c+16>>2]=f;H[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Bb(a+1|0,b,c)){break a}e=d&127|H[b>>2]<<7}H[b>>2]=e;g=1}return g}function Fa(a,b,c){var d=0,e=0;a:{b:{if(c>>>0>=4){if((a|b)&3){break b}while(1){if(H[a>>2]!=H[b>>2]){break b}b=b+4|0;a=a+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}}while(1){d=I[a|0];e=I[b|0];if((d|0)==(e|0)){b=b+1|0;a=a+1|0;c=c-1|0;if(c){continue}break a}break}return d-e|0}return 0}function Yc(a){var b=0,c=0,d=0,e=0;d=H[a>>2];if(d){e=d;c=H[a+4>>2];if((d|0)!=(c|0)){while(1){e=c-144|0;b=H[e+132>>2];if(b){H[c-8>>2]=b;oa(b)}b=H[c-28>>2];if(b){H[c-24>>2]=b;oa(b)}b=H[c-40>>2];if(b){H[c-36>>2]=b;oa(b)}oc(c-140|0);c=e;if((d|0)!=(c|0)){continue}break}e=H[a>>2]}H[a+4>>2]=d;oa(e)}}function Dg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=H[b+4>>2];a:{if(!d){break a}b=H[H[H[b+8>>2]+(c<<2)>>2]+60>>2];if((b|0)<0){break a}a=H[d+24>>2];c=H[d+28>>2];if((a|0)==(c|0)){break a}b:{while(1){e=H[a>>2];if((b|0)==H[e+24>>2]){break b}a=a+4|0;if((c|0)!=(a|0)){continue}break}e=0}}return e|0}function Zh(a){a=a|0;var b=0;H[a+8>>2]=12384;H[a>>2]=12172;b=H[a+96>>2];if(b){H[a+100>>2]=b;oa(b)}b=H[a+80>>2];if(b){H[a+84>>2]=b;oa(b)}b=H[a+68>>2];if(b){H[a+72>>2]=b;oa(b)}b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}H[a+8>>2]=12620;b=H[a+44>>2];if(b){oa(b)}b=H[a+32>>2];if(b){oa(b)}return a|0}function Uc(a){var b=0,c=0,d=0;if(a){d=H[a+24>>2];if(d){b=d;c=H[a+28>>2];if((b|0)!=(c|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){Ra(b+12|0,H[b+16>>2]);Qa(b,H[b+4>>2]);oa(b)}if((c|0)!=(d|0)){continue}break}b=H[a+24>>2]}H[a+28>>2]=d;oa(b)}Ra(a+12|0,H[a+16>>2]);Qa(a,H[a+4>>2]);oa(a)}}function Yh(a){a=a|0;var b=0;H[a+8>>2]=12384;H[a>>2]=12172;b=H[a+96>>2];if(b){H[a+100>>2]=b;oa(b)}b=H[a+80>>2];if(b){H[a+84>>2]=b;oa(b)}b=H[a+68>>2];if(b){H[a+72>>2]=b;oa(b)}b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}H[a+8>>2]=12620;b=H[a+44>>2];if(b){oa(b)}b=H[a+32>>2];if(b){oa(b)}oa(a)}function vi(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=13280;b=H[a+20>>2];if(b){H[a+24>>2]=b;oa(b)}d=H[a+8>>2];if(d){c=H[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=H[a+8>>2]}H[a+12>>2]=d;oa(b)}return a|0}function xc(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;h=H[c+8>>2];e=H[c+16>>2];g=H[c+12>>2];f=g;d=H[c+20>>2];if(h>>>0>e>>>0&(f|0)>=(d|0)|(d|0)<(f|0)){b=I[H[c>>2]+e|0];i=e+1|0;f=i?d:d+1|0;H[c+16>>2]=i;H[c+20>>2]=f;H[a+4>>2]=b}return e>>>0>>0&(d|0)<=(g|0)|(d|0)<(g|0)}function Wc(a){a=a|0;var b=0,c=0,d=0;H[a>>2]=13280;b=H[a+20>>2];if(b){H[a+24>>2]=b;oa(b)}d=H[a+8>>2];if(d){c=H[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=H[c>>2];H[c>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=H[a+8>>2]}H[a+12>>2]=d;oa(b)}oa(a)}function Ya(a,b,c){var d=0;if(!c){return H[a+4>>2]==H[b+4>>2]}if((a|0)==(b|0)){return 1}d=H[a+4>>2];a=I[d|0];c=H[b+4>>2];b=I[c|0];a:{if(!a|(b|0)!=(a|0)){break a}while(1){b=I[c+1|0];a=I[d+1|0];if(!a){break a}c=c+1|0;d=d+1|0;if((a|0)==(b|0)){continue}break}}return(a|0)==(b|0)}function _h(a){a=a|0;var b=0;H[a>>2]=12384;b=H[a+88>>2];if(b){H[a+92>>2]=b;oa(b)}b=H[a+72>>2];if(b){H[a+76>>2]=b;oa(b)}b=H[a+60>>2];if(b){H[a- -64>>2]=b;oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}H[a>>2]=12620;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}return a|0}function Fg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=H[b+12>>2];b=H[b+8>>2];a=0;a:{if((d|0)==(b|0)){break a}a=d-b>>2;d=a>>>0<=1?1:a;a=0;b:{while(1){e=H[b+(a<<2)>>2];if(H[e+60>>2]==(c|0)){break b}a=a+1|0;if((d|0)!=(a|0)){continue}break}a=0;break a}a=(a|0)!=-1?e:0}return a|0}function ae(a,b){var c=0,d=0,e=0;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;a:{c=H[b+4>>2];d=H[b>>2];b:{if((c|0)==(d|0)){a=c;break b}c=c-d|0;if((c|0)<0){break a}d=c;e=pa(c);c=ra(e,0,c);d=d+c|0;H[a+8>>2]=d;H[a+4>>2]=d;H[a>>2]=c;c=H[b>>2];a=H[b+4>>2]}qa(e,c,a-c|0);return}sa();v()}function ed(a){var b=0,c=0,d=0,e=0;c=H[a+4>>2];d=H[a>>2];if((c|0)!=(d|0)){while(1){e=c-144|0;b=H[e+132>>2];if(b){H[c-8>>2]=b;oa(b)}b=H[c-28>>2];if(b){H[c-24>>2]=b;oa(b)}b=H[c-40>>2];if(b){H[c-36>>2]=b;oa(b)}oc(c-140|0);c=e;if((d|0)!=(c|0)){continue}break}}H[a+4>>2]=d}function Vh(a){a=a|0;var b=0;H[a>>2]=12384;b=H[a+88>>2];if(b){H[a+92>>2]=b;oa(b)}b=H[a+72>>2];if(b){H[a+76>>2]=b;oa(b)}b=H[a+60>>2];if(b){H[a- -64>>2]=b;oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}H[a>>2]=12620;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}oa(a)}function cb(a){var b=0;if(a){b=H[a+76>>2];if(b){H[a+80>>2]=b;oa(b)}b=H[a- -64>>2];if(b){H[a+68>>2]=b;oa(b)}b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}b=H[a+24>>2];if(b){H[a+28>>2]=b;oa(b)}b=H[a+12>>2];if(b){H[a+16>>2]=b;oa(b)}b=H[a>>2];if(b){H[a+4>>2]=b;oa(b)}oa(a)}}function Jd(a,b,c){var d=0,e=0,f=0,g=0;f=ca-16|0;ca=f;d=ca-16|0;ca=d;b=b-a>>2;while(1){if(b){H[d+12>>2]=a;e=b>>>1|0;H[d+12>>2]=H[d+12>>2]+(e<<2);g=(e^-1)+b|0;b=e;e=K[H[d+12>>2]>>2]>2];b=e?g:b;a=e?H[d+12>>2]+4|0:a;continue}break}ca=d+16|0;ca=f+16|0;return a}function oc(a){var b=0;b=H[a+84>>2];if(b){H[a+88>>2]=b;oa(b)}b=H[a+72>>2];if(b){H[a+76>>2]=b;oa(b)}b=H[a+52>>2];if(b){H[a+56>>2]=b;oa(b)}b=H[a+40>>2];if(b){H[a+44>>2]=b;oa(b)}b=H[a+28>>2];if(b){H[a+32>>2]=b;oa(b)}b=H[a+12>>2];if(b){oa(b)}a=H[a>>2];if(a){oa(a)}}function Xc(a,b){var c=0,d=0;d=pa(40);H[d>>2]=-1;c=d+8|0;H[c+16>>2]=0;H[c+20>>2]=0;H[c+8>>2]=0;H[c>>2]=0;H[c+4>>2]=0;H[c+24>>2]=0;H[c+28>>2]=0;ea[H[H[a>>2]+16>>2]](a,d);a=H[b+88>>2];H[b+88>>2]=d;if(a){b=H[a+8>>2];if(b){H[a+12>>2]=b;oa(b)}oa(a)}return 1}function Ma(a){var b=0,c=0,d=0;b=a;a:{if(b&3){while(1){if(!I[b|0]){break a}b=b+1|0;if(b&3){continue}break}}while(1){c=b;b=b+4|0;d=H[c>>2];if(!((d^-1)&d-16843009&-2139062144)){continue}break}while(1){b=c;c=b+1|0;if(I[b|0]){continue}break}}return b-a|0}function Ba(a){var b=0,c=0,d=0,e=0,f=0;d=I[a+12|0];c=H[a+8>>2];a:{if(c>>>0>4095){break a}b=H[a+4>>2];if((b|0)<=0){break a}b=b-1|0;H[a+4>>2]=b;c=I[b+H[a>>2]|0]|c<<8}d=0-d&255;b=N(d,c>>>8|0);e=c&255;f=e>>>0>>0;H[a+8>>2]=f?b+e|0:c-(b+d|0)|0;return f}function od(a,b){H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=1984;H[a+12>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;H[a+32>>2]=0;H[a+36>>2]=0;H[a+40>>2]=0;H[a>>2]=2328;H[a+60>>2]=b;H[a+44>>2]=0;H[a+48>>2]=0;H[a+52>>2]=0;H[a+56>>2]=0;return a}function mc(a,b){var c=0,d=0,e=0;c=Ma(b);if(c>>>0<2147483632){a:{b:{if(c>>>0>=11){d=(c|15)+1|0;e=pa(d);H[a+8>>2]=d|-2147483648;H[a>>2]=e;H[a+4>>2]=c;d=c+e|0;break b}F[a+11|0]=c;d=a+c|0;e=a;if(!c){break a}}va(e,b,c)}F[d|0]=0;return a}Na();v()}function Ng(a){a=a|0;var b=0,c=0,d=0;if(a){if(F[a+27|0]<0){oa(H[a+16>>2])}b=H[a>>2];if(b){c=b;d=H[a+4>>2];if((b|0)!=(d|0)){while(1){c=d-12|0;if(F[d-1|0]<0){oa(H[c>>2])}d=c;if((d|0)!=(b|0)){continue}break}c=H[a>>2]}H[a+4>>2]=b;oa(c)}oa(a)}}function Jb(a,b){var c=0,d=0,e=0;a:{c=H[a>>2];b:{if(H[a+8>>2]-c>>2>>>0>=b>>>0){break b}if(b>>>0>=1073741824){break a}d=H[a+4>>2]-c|0;e=b<<2;b=va(pa(e),c,d);H[a+8>>2]=b+e;H[a+4>>2]=b+d;H[a>>2]=b;if(!c){break b}oa(c)}return}sa();v()}function Ga(a){a=a|0;var b=0,c=0;if(a){b=H[a+88>>2];H[a+88>>2]=0;if(b){c=H[b+8>>2];if(c){H[b+12>>2]=c;oa(c)}oa(b)}b=H[a+68>>2];if(b){H[a+72>>2]=b;oa(b)}b=H[a+64>>2];H[a+64>>2]=0;if(b){c=H[b>>2];if(c){H[b+4>>2]=c;oa(c)}oa(b)}oa(a)}}function Nd(a){var b=0,c=0,d=0;if(F[H[a>>2]]-48>>>0>=10){return 0}while(1){d=H[a>>2];c=-1;if(b>>>0<=214748364){c=F[d|0]-48|0;b=N(b,10);c=(c|0)>(b^2147483647)?-1:c+b|0}H[a>>2]=d+1;b=c;if(F[d+1|0]-48>>>0<10){continue}break}return b}function Cg(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;b=H[b+96>>2];a=pa(12);b=b+N(c,12)|0;c=H[b+4>>2];H[a>>2]=H[b>>2];H[a+4>>2]=c;H[a+8>>2]=H[b+8>>2];b=H[d>>2];if(b){H[d+4>>2]=b;oa(b)}H[d>>2]=a;a=a+12|0;H[d+8>>2]=a;H[d+4>>2]=a;return 1}function Ai(a){a=a|0;var b=0;H[a+24>>2]=1832;H[a>>2]=11048;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}H[a>>2]=2448;b=H[a+20>>2];H[a+20>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}H[a>>2]=2232;b=H[a+16>>2];H[a+16>>2]=0;if(b){Ga(b)}return a|0}function Sj(a,b,c,d){var e=0,f=0,g=0,h=0;f=b^d;g=f>>31;e=b>>31;a=a^e;h=a-e|0;e=(b^e)-((a>>>0>>0)+e|0)|0;a=d>>31;b=c^a;f=f>>31;a=Tj(h,e,b-a|0,(a^d)-((a>>>0>b>>>0)+a|0)|0)^f;b=a-f|0;da=(g^da)-((a>>>0>>0)+g|0)|0;return b}function yi(a){a=a|0;var b=0;H[a+24>>2]=1832;H[a>>2]=11048;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}H[a>>2]=2448;b=H[a+20>>2];H[a+20>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}H[a>>2]=2232;b=H[a+16>>2];H[a+16>>2]=0;if(b){Ga(b)}oa(a)}function Yb(a,b,c){var d=0,e=0,f=0;e=ca-16|0;ca=e;d=H[a+8>>2]&2147483647;a:{if(d>>>0>c>>>0){d=H[a>>2];H[a+4>>2]=c;yb(d,b,c);F[e+15|0]=0;F[c+d|0]=I[e+15|0];break a}f=a;a=H[a+4>>2];Gd(f,d-1|0,(c-d|0)+1|0,a,a,c,b)}ca=e+16|0}function Bf(a,b){a=a|0;b=b|0;var c=0,d=0;c=ca-16|0;ca=c;a=H[a+4>>2];a:{if((a|0)==-1){break a}F[c+15|0]=a;d=H[b+20>>2];if(!!H[b+16>>2]&(d|0)>=0|(d|0)>0){break a}Wb(b,H[b+4>>2],c+15|0,c+16|0)}ca=c+16|0;return(a|0)!=-1|0}function Xb(a,b,c){var d=0,e=0;d=ca-16|0;ca=d;a:{if(c>>>0<=10){F[a+11|0]=I[a+11|0]&128|c;F[a+11|0]=I[a+11|0]&127;yb(a,b,c);F[d+15|0]=0;F[a+c|0]=I[d+15|0];break a}e=a;a=I[a+11|0]&127;Gd(e,10,c-10|0,a,a,c,b)}ca=d+16|0}function Rj(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;e=c>>>16|0;f=a>>>16|0;j=N(e,f);g=c&65535;h=a&65535;i=N(g,h);f=(i>>>16|0)+N(f,g)|0;e=(f&65535)+N(e,h)|0;da=(N(b,c)+j|0)+N(a,d)+(f>>>16)+(e>>>16)|0;return i&65535|e<<16}function Dd(a,b,c){var d=0;d=H[a+16>>2];if(!d){H[a+36>>2]=1;H[a+24>>2]=c;H[a+16>>2]=b;return}a:{if((b|0)==(d|0)){if(H[a+24>>2]!=2){break a}H[a+24>>2]=c;return}F[a+54|0]=1;H[a+24>>2]=2;H[a+36>>2]=H[a+36>>2]+1}}function th(){var a=0;a=Eb(pa(96));H[a+64>>2]=0;H[a+68>>2]=0;H[a+88>>2]=0;H[a+72>>2]=0;H[a+76>>2]=0;F[a+77|0]=0;F[a+78|0]=0;F[a+79|0]=0;F[a+80|0]=0;F[a+81|0]=0;F[a+82|0]=0;F[a+83|0]=0;F[a+84|0]=0;return a|0}function zi(a,b){a=a|0;b=b|0;var c=0,d=0;H[b>>2]=2;c=H[b+8>>2];d=H[b+12>>2]-c|0;if(d>>>0<=4294967291){kc(b+8|0,d+4|0);c=H[b+8>>2]}b=c+d|0;a=H[a+4>>2];F[b|0]=a;F[b+1|0]=a>>>8;F[b+2|0]=a>>>16;F[b+3|0]=a>>>24}function rj(a){a=a|0;var b=0;H[a>>2]=5580;b=H[a+96>>2];if(b){oa(b)}b=H[a+84>>2];if(b){oa(b)}b=H[a+72>>2];if(b){oa(b)}b=H[a+60>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function ib(a,b,c,d,e){var f=0;f=ca-256|0;ca=f;if(!(e&73728|(c|0)<=(d|0))){d=c-d|0;c=d>>>0<256;ra(f,b&255,c?d:256);if(!c){while(1){Ab(a,f,256);d=d-256|0;if(d>>>0>255){continue}break}}Ab(a,f,d)}ca=f+256|0}function Ij(a){a=a|0;var b=0;H[a>>2]=3564;b=H[a+96>>2];if(b){oa(b)}b=H[a+84>>2];if(b){oa(b)}b=H[a+72>>2];if(b){oa(b)}b=H[a+60>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function Ch(a){a=a|0;var b=0,c=0,d=0;b=H[a+8>>2];d=H[a+12>>2];if((b|0)==(d|0)){return 1}while(1){c=H[b>>2];c=ea[H[H[c>>2]+16>>2]](c,H[a+32>>2])|0;if(c){b=b+4|0;if((d|0)!=(b|0)){continue}}break}return c|0}function Yd(a,b){var c=0,d=0;c=H[a+8>>2];a=H[a+12>>2];if((c|0)!=(a|0)){a=a-c>>2;d=a>>>0<=1?1:a;a=0;while(1){if(H[H[(a<<2)+c>>2]+60>>2]==(b|0)){return a}a=a+1|0;if((d|0)!=(a|0)){continue}break}}return-1}function qj(a){a=a|0;var b=0;H[a>>2]=5580;b=H[a+96>>2];if(b){oa(b)}b=H[a+84>>2];if(b){oa(b)}b=H[a+72>>2];if(b){oa(b)}b=H[a+60>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function Hj(a){a=a|0;var b=0;H[a>>2]=3564;b=H[a+96>>2];if(b){oa(b)}b=H[a+84>>2];if(b){oa(b)}b=H[a+72>>2];if(b){oa(b)}b=H[a+60>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function $d(a,b,c){var d=0,e=0;d=a+4|0;a=nb(a,b);a:{if((d|0)==(a|0)){break a}b=H[a+32>>2];d=H[a+28>>2];if((b|0)==(d|0)){break a}Cc(c,b-d|0);c=Dc(c);b=H[a+28>>2];qa(c,b,H[a+32>>2]-b|0);e=1}return e}function Qf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0;e=ca-16|0;ca=e;a=_(H[a+60>>2],b|0,c|0,d&255,e+8|0)|0;if(a){H[3992]=a;a=-1}else{a=0}ca=e+16|0;da=a?-1:H[e+12>>2];return(a?-1:H[e+8>>2])|0}function Sd(a){var b=0;b=H[a+72>>2];H[a+72>>2]=b-1|b;b=H[a>>2];if(b&8){H[a>>2]=b|32;return-1}H[a+4>>2]=0;H[a+8>>2]=0;b=H[a+44>>2];H[a+28>>2]=b;H[a+20>>2]=b;H[a+16>>2]=b+H[a+48>>2];return 0}function Eb(a){H[a+8>>2]=0;H[a+12>>2]=0;H[a>>2]=0;H[a+40>>2]=0;H[a+44>>2]=0;H[a+28>>2]=9;F[a+24|0]=1;H[a+56>>2]=-1;H[a+60>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+48>>2]=0;H[a+52>>2]=0;return a}function hf(a,b){a=a|0;b=b|0;var c=0,d=0;d=H[a+16>>2];c=0;a:{if(H[a+20>>2]-d>>2<=(b|0)){break a}b=H[(b<<2)+d>>2];c=0;if((b|0)<0){break a}c=rb(H[H[a+36>>2]+(b<<2)>>2])}return c|0}function Mg(){var a=0,b=0;a=pa(40);H[a+4>>2]=0;H[a+8>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;b=a+16|0;H[b>>2]=0;H[b+4>>2]=0;H[a>>2]=a+4;H[a+12>>2]=b;H[a+32>>2]=0;H[a+36>>2]=0;return a|0}function Vf(a,b){a=a|0;b=b|0;var c=0,d=0;Wd(a,b);a:{if((b|0)<0){break a}d=H[a+88>>2];c=H[a+84>>2];if(d-c>>2<=(b|0)){break a}c=(b<<2)+c|0;b=c+4|0;va(c,b,d-b|0);H[a+88>>2]=d-4}}function Rh(a){a=a|0;var b=0;H[a+8>>2]=12804;H[a>>2]=12640;b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}H[a+8>>2]=12620;b=H[a+44>>2];if(b){oa(b)}b=H[a+32>>2];if(b){oa(b)}return a|0}function Lh(a){a=a|0;var b=0;H[a+8>>2]=11872;H[a>>2]=12932;b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}H[a+8>>2]=12124;b=H[a+44>>2];if(b){oa(b)}b=H[a+32>>2];if(b){oa(b)}return a|0}function zb(a){var b=0,c=0;b=H[3958];c=a+7&-8;a=b+c|0;a:{if(a>>>0<=b>>>0?c:0){break a}if(a>>>0>fa()<<16>>>0){if(!($(a|0)|0)){break a}}H[3958]=a;return b}H[3992]=48;return-1}function bj(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;H[a+4>>2]=b;b=H[H[H[b+4>>2]+8>>2]+(c<<2)>>2];H[a+12>>2]=c;H[a+8>>2]=b;a=H[a+8>>2];if(I[a+24|0]==3){d=H[a+28>>2]==9}return d|0}function wf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=H[a+8>>2];a:{if(!I[d+24|0]){break a}if(!mb(d,H[b+4>>2]-H[b>>2]>>2)){break a}e=ea[H[H[a>>2]+32>>2]](a,b,c)|0}return e|0}function Qh(a){a=a|0;var b=0;H[a+8>>2]=12804;H[a>>2]=12640;b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}H[a+8>>2]=12620;b=H[a+44>>2];if(b){oa(b)}b=H[a+32>>2];if(b){oa(b)}oa(a)}function Kh(a){a=a|0;var b=0;H[a+8>>2]=11872;H[a>>2]=12932;b=H[a+56>>2];if(b){H[a+60>>2]=b;oa(b)}H[a+8>>2]=12124;b=H[a+44>>2];if(b){oa(b)}b=H[a+32>>2];if(b){oa(b)}oa(a)}function nj(a){a=a|0;var b=0;H[a>>2]=5816;b=H[a+76>>2];if(b){oa(b)}b=H[a+68>>2];H[a+68>>2]=0;if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function Ra(a,b){if(b){Ra(a,H[b>>2]);Ra(a,H[b+4>>2]);a=H[b+28>>2];H[b+28>>2]=0;if(a){Ra(a+12|0,H[a+16>>2]);Qa(a,H[a+4>>2]);oa(a)}if(F[b+27|0]<0){oa(H[b+16>>2])}oa(b)}}function Gi(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;H[a+4>>2]=b;d=H[H[H[b+4>>2]+8>>2]+(c<<2)>>2];H[a+12>>2]=c;H[a+8>>2]=d;return H[H[H[H[b+4>>2]+8>>2]+(c<<2)>>2]+28>>2]==9|0}function Ej(a){a=a|0;var b=0;H[a>>2]=3812;b=H[a+76>>2];if(b){oa(b)}b=H[a+68>>2];H[a+68>>2]=0;if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function Vc(a){H[a+40>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;H[a>>2]=13280;H[a+12>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;H[a+32>>2]=0;G[a+36>>1]=0;return a}function Hd(a,b){var c=0,d=0,e=0,f=0;H[a>>2]=15260;H[a>>2]=15372;c=Ma(b);d=pa(c+13|0);H[d+8>>2]=0;H[d+4>>2]=c;H[d>>2]=c;e=a,f=qa(d+12|0,b,c+1|0),H[e+4>>2]=f;return a}function jg(a,b){a=a|0;b=b|0;var c=0;a:{if(!(ea[H[H[a>>2]+36>>2]](a,b)|0)){break a}if(!(ea[H[H[a>>2]+40>>2]](a,b)|0)){break a}c=ea[H[H[a>>2]+44>>2]](a)|0}return c|0}function mj(a){a=a|0;var b=0;H[a>>2]=5816;b=H[a+76>>2];if(b){oa(b)}b=H[a+68>>2];H[a+68>>2]=0;if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function Dj(a){a=a|0;var b=0;H[a>>2]=3812;b=H[a+76>>2];if(b){oa(b)}b=H[a+68>>2];H[a+68>>2]=0;if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function Xe(a){a=a|0;var b=0;a:{if(!H[a- -64>>2]|!H[a+68>>2]|(!H[a+44>>2]|!H[a+48>>2])){break a}if(!H[a+52>>2]|!H[a+56>>2]){break a}b=H[a+92>>2]!=-1}return b|0}function cf(a){a=a|0;var b=0;H[a>>2]=2448;b=H[a+20>>2];H[a+20>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}H[a>>2]=2232;b=H[a+16>>2];H[a+16>>2]=0;if(b){Ga(b)}return a|0}function Pj(a,b){a=a|0;b=b|0;var c=0;b=H[b+88>>2];if(!(!b|H[b>>2]!=2)){c=a;a=H[b+8>>2];H[c+4>>2]=I[a|0]|I[a+1|0]<<8|(I[a+2|0]<<16|I[a+3|0]<<24);c=1}return c|0}function tc(a){a=a|0;var b=0;a:{if(!H[a+48>>2]|!H[a+52>>2]|(!H[a+28>>2]|!H[a+32>>2])){break a}if(!H[a+36>>2]|!H[a+40>>2]){break a}b=H[a+76>>2]!=-1}return b|0}function Sh(a){a=a|0;var b=0;H[a>>2]=12804;b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}H[a>>2]=12620;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}return a|0}function He(a){a=a|0;var b=0;H[a>>2]=11872;b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}H[a>>2]=12124;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}return a|0}function bf(a){a=a|0;var b=0;H[a>>2]=2448;b=H[a+20>>2];H[a+20>>2]=0;if(b){ea[H[H[b>>2]+4>>2]](b)}H[a>>2]=2232;b=H[a+16>>2];H[a+16>>2]=0;if(b){Ga(b)}oa(a)}function wh(){var a=0,b=0;b=pa(40);H[b>>2]=-1;a=b+8|0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=0;H[a>>2]=0;H[a+4>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;return b|0}function gf(a,b){a=a|0;b=b|0;var c=0,d=0;d=H[a+4>>2];a:{if(d){c=1;if(I[d+36|0]<2){break a}}c=ea[H[H[a>>2]+48>>2]](a,H[b+4>>2]-H[b>>2]>>2)|0}return c|0}function ci(a){a=a|0;var b=0;H[a>>2]=11872;b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}H[a>>2]=12124;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}oa(a)}function Mh(a){a=a|0;var b=0;H[a>>2]=12804;b=H[a+48>>2];if(b){H[a+52>>2]=b;oa(b)}H[a>>2]=12620;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}oa(a)}function Ha(a){H[a+8>>2]=0;H[a+12>>2]=0;H[a>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+32>>2]=0;H[a+24>>2]=0;H[a+28>>2]=0;G[a+38>>1]=0;F[a+36|0]=0;return a}function Hf(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;if(Ya(a,H[b+8>>2],f)){Cd(b,c,d,e);return}a=H[a+8>>2];ea[H[H[a>>2]+20>>2]](a,b,c,d,e,f)}function Ei(a,b,c){a=a|0;b=b|0;c=c|0;a:{if(I[H[a+4>>2]+36|0]>=2){b=0;if(!(ea[H[H[a>>2]+52>>2]](a)|0)){break a}}b=Xc(a+24|0,H[a+16>>2])}return b|0}function Fi(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;a:{if(I[H[a+4>>2]+36|0]<=1){d=0;if(!(ea[H[H[a>>2]+52>>2]](a)|0)){break a}}d=nd(a,b,c)}return d|0}function gh(){var a=0;a=_d(pa(108));H[a+84>>2]=0;H[a+88>>2]=0;H[a>>2]=13664;H[a+92>>2]=0;H[a+96>>2]=0;H[a+100>>2]=0;H[a+104>>2]=0;return a|0}function Zd(a,b){var c=0;c=-1;a:{if((b|0)==-1|(b|0)>4){break a}b=N(b,12)+a|0;a=H[b+20>>2];if((H[b+24>>2]-a|0)<=0){break a}c=H[a>>2]}return c}function lc(a,b,c,d,e,f,g){H[a>>2]=0;H[a+56>>2]=b;H[a+48>>2]=0;H[a+52>>2]=0;H[a+40>>2]=f;H[a+44>>2]=g;F[a+32|0]=e;H[a+28>>2]=d;F[a+24|0]=c}function aj(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;a:{if(I[H[a+4>>2]+36|0]<=1){d=0;if(!xc(a+24|0,H[a+8>>2],c)){break a}}d=nd(a,b,c)}return d|0}function $i(a,b,c){a=a|0;b=b|0;c=c|0;a:{if(I[H[a+4>>2]+36|0]>=2){b=0;if(!xc(a+24|0,rb(a),c)){break a}}b=Xc(a+24|0,H[a+16>>2])}return b|0}function Yf(a){a=a|0;var b=0;H[a>>2]=13664;b=H[a+96>>2];if(b){H[a+100>>2]=b;oa(b)}b=H[a+84>>2];if(b){H[a+88>>2]=b;oa(b)}return _b(a)|0}function Dc(a){var b=0;if(I[a+11|0]>>>7|0){b=H[a+4>>2]}else{b=I[a+11|0]&127}if(!b){af(1232);v()}if(I[a+11|0]>>>7|0){a=H[a>>2]}return a}function Xf(a){a=a|0;var b=0;H[a>>2]=13664;b=H[a+96>>2];if(b){H[a+100>>2]=b;oa(b)}b=H[a+84>>2];if(b){H[a+88>>2]=b;oa(b)}oa(_b(a))}function zj(a){a=a|0;var b=0;H[a>>2]=4040;b=H[a+76>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function jj(a){a=a|0;var b=0;H[a>>2]=6032;b=H[a+76>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function Qa(a,b){if(b){Qa(a,H[b>>2]);Qa(a,H[b+4>>2]);a=H[b+28>>2];if(a){H[b+32>>2]=a;oa(a)}if(F[b+27|0]<0){oa(H[b+16>>2])}oa(b)}}function Vg(){var a=0;a=pa(28);H[a>>2]=0;H[a+4>>2]=0;H[a+24>>2]=0;H[a+16>>2]=0;H[a+20>>2]=0;H[a+8>>2]=0;H[a+12>>2]=0;return a|0}function wg(a){a=a|0;var b=0;H[a>>2]=1984;b=H[a+16>>2];if(b){H[a+20>>2]=b;oa(b)}b=H[a+4>>2];if(b){H[a+8>>2]=b;oa(b)}return a|0}function eh(){var a=0,b=0;a=pa(24);H[a+4>>2]=0;H[a+8>>2]=0;b=a+16|0;H[b>>2]=0;H[b+4>>2]=0;H[a>>2]=a+4;H[a+12>>2]=b;return a|0}function Kf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;if(Ya(a,H[b+8>>2],0)){Dd(b,c,d);return}a=H[a+8>>2];ea[H[H[a>>2]+28>>2]](a,b,c,d)}function yj(a){a=a|0;var b=0;H[a>>2]=4040;b=H[a+76>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function ij(a){a=a|0;var b=0;H[a>>2]=6032;b=H[a+76>>2];if(b){oa(b)}H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function pa(a){var b=0;a=a?a:1;a:{while(1){b=Ec(a);if(b){break a}b=H[4422];if(b){ea[b|0]();continue}break}X();v()}return b}function Kb(a,b){if(b){Kb(a,H[b>>2]);Kb(a,H[b+4>>2]);if(F[b+39|0]<0){oa(H[b+28>>2])}if(F[b+27|0]<0){oa(H[b+16>>2])}oa(b)}}function Ad(a){a=a|0;var b=0,c=0;H[a>>2]=15372;b=H[a+4>>2]-12|0;c=H[b+8>>2]-1|0;H[b+8>>2]=c;if((c|0)<0){oa(b)}return a|0}function lh(){var a=0;a=pa(24);H[a+8>>2]=0;H[a+12>>2]=0;H[a+4>>2]=-1;H[a>>2]=1832;H[a+16>>2]=0;H[a+20>>2]=0;return a|0}function pd(a,b,c){a=a|0;b=b|0;c=c|0;H[a+4>>2]=b;b=H[H[H[b+4>>2]+8>>2]+(c<<2)>>2];H[a+12>>2]=c;H[a+8>>2]=b;return 1}function wc(a){a=a|0;var b=0;if(!(!H[a+60>>2]|!H[a+44>>2]|(!H[a+48>>2]|!H[a+52>>2]))){b=H[a+56>>2]!=0}return b|0}function Id(a,b){if(I[a+11|0]>>>7|0){H[a+4>>2]=b;return}F[a+11|0]=I[a+11|0]&128|b;F[a+11|0]=I[a+11|0]&127}function wj(a){a=a|0;var b=0;H[a>>2]=4276;H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function fj(a){a=a|0;var b=0;H[a>>2]=6256;H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function bi(a){a=a|0;var b=0;H[a>>2]=12124;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}return a|0}function Uh(a){a=a|0;var b=0;H[a>>2]=12620;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}return a|0}function lg(a){a=a|0;if(a){if(F[a+39|0]<0){oa(H[a+28>>2])}Oc(a+12|0,H[a+16>>2]);Kb(a,H[a+4>>2]);oa(a)}}function Pb(a){a=a|0;var b=0;if(!(!H[a+52>>2]|(!H[a+44>>2]|!H[a+48>>2]))){b=H[a+56>>2]!=0}return b|0}function vj(a){a=a|0;var b=0;H[a>>2]=4276;H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function vc(a,b){a=a|0;b=b|0;var c=0;if(!(H[b+56>>2]|!b|I[b+24|0]!=3)){H[a+60>>2]=b;c=1}return c|0}function ej(a){a=a|0;var b=0;H[a>>2]=6256;H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function ai(a){a=a|0;var b=0;H[a>>2]=12124;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}oa(a)}function Th(a){a=a|0;var b=0;H[a>>2]=12620;b=H[a+36>>2];if(b){oa(b)}b=H[a+24>>2];if(b){oa(b)}oa(a)}function xh(a,b,c){a=a|0;b=b|0;c=c|0;H[a+16>>2]=0;H[a+20>>2]=0;H[a>>2]=b;H[a+8>>2]=c;H[a+12>>2]=0}function We(a,b){a=a|0;b=b|0;var c=0;if(!(H[b+56>>2]|I[b+24|0]!=3)){H[a- -64>>2]=b;c=1}return c|0}function yc(a){var b=0;b=H[a+16>>2];if(b){H[a+20>>2]=b;oa(b)}b=H[a>>2];if(b){H[a+4>>2]=b;oa(b)}}function sc(a,b){a=a|0;b=b|0;var c=0;if(!(H[b+56>>2]|I[b+24|0]!=3)){H[a+48>>2]=b;c=1}return c|0}function Gf(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;if(Ya(a,H[b+8>>2],f)){Cd(b,c,d,e)}}function wa(){var a=0;a=Bc(4);H[a>>2]=15260;H[a>>2]=15220;H[a>>2]=15240;Y(a|0,15352,14);v()}function sf(a){a=a|0;var b=0;H[a>>2]=2232;b=H[a+16>>2];H[a+16>>2]=0;if(b){Ga(b)}return a|0}function Kj(a){a=a|0;var b=0;H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}return a|0}function mi(a){a=a|0;var b=0;H[a>>2]=1832;b=H[a+8>>2];if(b){H[a+12>>2]=b;oa(b)}return a|0}function Ci(a){a=a|0;var b=0;b=rb(a);return Je(a+24|0,b?b:H[a+8>>2],H[H[a+4>>2]+32>>2])|0}function rf(a){a=a|0;var b=0;H[a>>2]=2232;b=H[a+16>>2];H[a+16>>2]=0;if(b){Ga(b)}oa(a)}function ji(a){a=a|0;var b=0;H[a>>2]=1832;b=H[a+8>>2];if(b){H[a+12>>2]=b;oa(b)}oa(a)} +function Ub(a){a=a|0;var b=0;H[a>>2]=3272;b=H[a+32>>2];if(b){H[a+36>>2]=b;oa(b)}oa(a)}function Za(a){var b=0;H[a+16>>2]=0;b=H[a>>2];H[a+4>>2]=b;H[a+12>>2]=b;if(b){oa(b)}}function Oc(a,b){if(b){Oc(a,H[b>>2]);Oc(a,H[b+4>>2]);Kb(b+20|0,H[b+24>>2]);oa(b)}}function wi(a){a=a|0;if(!H[a+44>>2]){return 0}return ea[H[H[a>>2]+48>>2]](a)|0}function vh(a){a=a|0;var b=0;if(a){b=H[a+8>>2];if(b){H[a+12>>2]=b;oa(b)}oa(a)}}function Uj(a){var b=0;while(1){if(a){a=a-1&a;b=b+1|0;continue}break}return b}function Lf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;if(Ya(a,H[b+8>>2],0)){Dd(b,c,d)}}function ui(a,b){a=a|0;b=b|0;a=H[a+48>>2];return ea[H[H[a>>2]+20>>2]](a,b)|0}function ni(a,b){a=a|0;b=b|0;a=H[a+48>>2];return ea[H[H[a>>2]+12>>2]](a,b)|0}function li(a,b){a=a|0;b=b|0;a=H[a+48>>2];return ea[H[H[a>>2]+16>>2]](a,b)|0}function lb(){var a=0;a=pa(12);H[a>>2]=0;H[a+4>>2]=0;H[a+8>>2]=0;return a|0}function kb(a){a=a|0;var b=0;if(a){b=H[a>>2];if(b){H[a+4>>2]=b;oa(b)}oa(a)}}function Vj(a){var b=0;b=a&31;a=0-a&31;return(-1>>>b&-2)<>>a} +function dh(a,b,c){a=a|0;b=b|0;c=c|0;H[a+32>>2]=c;H[a+28>>2]=b;return 1}function ch(a){a=a|0;if(a){Ra(a+12|0,H[a+16>>2]);Qa(a,H[a+4>>2]);oa(a)}}function Rd(a,b,c){a:{if(H[c+76>>2]<0){a=Fc(a,b,c);break a}a=Fc(a,b,c)}}function Mb(a,b){a=a|0;b=b|0;if(b>>>0<=1){H[a+28>>2]=b}return b>>>0<2|0}function Fh(a,b){a=a|0;b=b|0;F[b+84|0]=1;H[b+72>>2]=H[b+68>>2];return 1}function si(a){a=a|0;a=H[a+48>>2];return ea[H[H[a>>2]+24>>2]](a)|0}function ri(a){a=a|0;a=H[a+48>>2];return ea[H[H[a>>2]+28>>2]](a)|0}function oi(a){a=a|0;a=H[a+48>>2];return ea[H[H[a>>2]+36>>2]](a)|0}function ih(){var a=0;a=pa(8);H[a+4>>2]=-1;H[a>>2]=1032;return a|0}function Gg(a,b,c){a=a|0;b=b|0;c=c|0;return H[H[b+8>>2]+(c<<2)>>2]}function _i(a,b){a=a|0;b=b|0;return Fd(a+24|0,rb(a),H[a+8>>2])|0}function Bi(a,b){a=a|0;b=b|0;return Re(a+24|0,rb(a),H[a+8>>2])|0}function xf(a,b){a=a|0;b=b|0;H[a+12>>2]=-1;H[a+8>>2]=b;return 1}function ne(a,b){a=a|0;b=b|0;return ea[H[H[a>>2]+12>>2]](a,b)|0}function Ff(a){a=a|0;if(!a){return 0}return(Ed(a,15068)|0)!=0|0}function Di(a,b){a=a|0;b=b|0;return ea[H[H[a>>2]+56>>2]](a,b)|0}function $g(a){a=a|0;if(a){if(F[a+15|0]<0){oa(H[a+4>>2])}oa(a)}}function kh(a,b){a=a|0;b=b|0;return O(L[H[a+8>>2]+(b<<2)>>2])}function af(a){a=Hd(Bc(8),a);H[a>>2]=15472;Y(a|0,15504,1);v()}function Ue(a){a=Hd(Bc(8),a);H[a>>2]=15420;Y(a|0,15452,1);v()}function _g(a,b){a=a|0;b=b|0;return O(L[H[a>>2]+(b<<2)>>2])}function fh(a){a=a|0;return(H[a+100>>2]-H[a+96>>2]|0)/12|0}function ah(a){a=a|0;return(F[a+15|0]<0?H[a+4>>2]:a+4|0)|0}function _f(a,b){a=a|0;b=b|0;return H[H[a+4>>2]+(b<<2)>>2]}function Pf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;da=0;return 0}function Ke(a){a=Vc(a);H[a+44>>2]=0;H[a>>2]=11180;return a}function ie(a,b){a=a|0;b=b|0;return H[H[a>>2]+(b<<2)>>2]}function Xg(a,b){a=a|0;b=b|0;return G[H[a>>2]+(b<<1)>>1]}function Wg(a,b){a=a|0;b=b|0;return J[H[a>>2]+(b<<1)>>1]}function Zb(a,b){var c=0;c=pa(b);H[a+4>>2]=b;H[a>>2]=c}function Jg(a,b,c){a=a|0;b=b|0;c=c|0;return Zd(b,c)|0}function _d(a){H[a>>2]=13724;ra(a+4|0,0,80);return a}function me(a){a=a|0;return H[a+12>>2]-H[a+8>>2]>>2}function Qj(a){if(a){return 31-Q(a-1^a)|0}return 32}function cc(a){a=a|0;if(a){ea[H[H[a>>2]+4>>2]](a)}}function Zg(a,b){a=a|0;b=b|0;return F[H[a>>2]+b|0]}function Yg(a,b){a=a|0;b=b|0;return I[H[a>>2]+b|0]}function Uf(a){a=a|0;return H[a+8>>2]-H[a+4>>2]>>2}function jd(a,b){a=a|0;b=b|0;H[a+4>>2]=b;return 1}function je(a){a=a|0;return H[a+4>>2]-H[a>>2]>>1}function Qc(a){a=a|0;return H[a+4>>2]-H[a>>2]>>2}function le(a){a=a|0;return H[a+4>>2]-H[a>>2]|0}function Ab(a,b,c){if(!(I[a|0]&32)){Fc(b,c,a)}}function vf(a,b,c){a=a|0;b=b|0;c=c|0;return 1}function hi(a,b){a=a|0;b=b|0;return I[b+24|0]}function Pg(a,b){a=a|0;b=b|0;return H[b+8>>2]}function Nj(a){a=a|0;return I[H[a+8>>2]+24|0]}function Li(a){a=a|0;H[a>>2]=10032;return a|0}function Eg(a,b){a=a|0;b=b|0;return H[b+4>>2]}function Yi(a){a=a|0;H[a>>2]=7144;return a|0}function Ui(a){a=a|0;H[a>>2]=8080;return a|0}function Sf(a){a=a|0;return aa(H[a+60>>2])|0}function Pi(a){a=a|0;H[a>>2]=9028;return a|0}function jh(a){a=a|0;return O(L[a+20>>2])}function Ji(a){a=a|0;H[a>>2]=10032;oa(a)}function Xi(a){a=a|0;H[a>>2]=7144;oa(a)}function Si(a){a=a|0;H[a>>2]=8080;oa(a)}function Oi(a){a=a|0;H[a>>2]=9028;oa(a)}function sh(a){a=a|0;return H[a+88>>2]}function rh(a){a=a|0;return H[a+56>>2]}function oh(a){a=a|0;return H[a+40>>2]}function nh(a){a=a|0;return H[a+48>>2]}function mh(a){a=a|0;return H[a+60>>2]}function eb(a){a=a|0;return H[a+28>>2]}function df(){H[4292]=17048;H[4274]=42}function Rc(a){a=a|0;return H[a+80>>2]}function qh(a){a=a|0;return F[a+24|0]}function ph(a){a=a|0;return I[a+32|0]}function md(a,b){a=a|0;b=b|0;return-1}function db(a){a=a|0;return H[a+4>>2]}function bh(a){a=a|0;return!H[a>>2]|0}function _e(a,b){a=a|0;b=b|0;return 6}function Zc(a){a=a|0;return H[a+8>>2]}function Pd(a,b){a=a|0;b=b|0;return 1}function Ja(a,b){a=a|0;b=b|0;return 0}function Bj(a,b){a=a|0;b=b|0;return 2}function Bc(a){return Ec(a+80|0)+80|0}function pe(a){a=a|0;return H[a>>2]}function yh(){return Ha(pa(40))|0}function uh(){return Eb(pa(64))|0}function hh(){return _d(pa(84))|0}function Sc(a){a=a|0;if(a){oa(a)}}function zc(a){a=a|0;Ad(a);oa(a)}function Ef(a){a=a|0;return 1171}function Df(a){a=a|0;return 1245}function Cf(a){a=a|0;return 1211}function Ta(a){a=a|0;return a|0}function yf(a){a=a|0;oa(rd(a))}function fi(a){a=a|0;oa(Be(a))}function ei(a){a=a|0;oa(Ae(a))}function di(a){a=a|0;oa(ze(a))}function Tf(a){a=a|0;oa(_b(a))}function ld(a){a=a|0;return 3}function _a(a){a=a|0;return 0}function Ze(a){a=a|0;return 5}function Tb(a){a=a|0;return 2}function Ob(a){a=a|0;return 6}function Da(a){a=a|0;return 1}function $e(a){a=a|0;return 4}function sa(){Ue(1164);v()}function Na(){Ue(1232);v()}function La(a){a=a|0;oa(a)}function Ca(){af(1164);v()}function fb(a){a=a|0;v()}function eg(){return 10}function dg(){return 11}function cg(){return 12}function kg(){return 5}function ig(){return 6}function hg(){return 7}function gg(){return 8}function fg(){return 9}function fe(){return 3}function ee(){return 4}function bg(){return-2}function bc(){return-1}function ag(){return-3}function ac(){return 1}function Zf(){return-5}function Qb(){return 0}function Nc(){return 2}function $f(){return-4}function Nf(){X();v()}function Td(a){a=a|0} +// EMSCRIPTEN_END_FUNCS +e=I;p(q);var ea=c([null,Ad,Ta,La,Tb,Pj,zi,Gh,Fd,Bf,xc,Nh,_e,Bj,Ta,mi,ji,Da,gj,Ti,Ki,Re,xi,Je,_e,hi,wg,fb,dh,ke,jg,_f,Uf,eb,Ja,Nf,Pd,Da,rd,yf,Of,Af,zf,sf,rf,pd,xf,wf,vf,Pd,uf,tf,kf,jf,qf,pf,hf,of,nf,mf,lf,cf,bf,pd,gf,ff,nd,ef,Nj,Oj,Kj,Ub,Da,db,Pb,_a,md,Ja,_a,Da,Mj,Lj,fb,fb,Ub,Tb,Pb,Jj,Ij,Hj,$e,Pb,Gj,Fj,Ej,Dj,ld,wc,Da,Ja,vc,Cj,Aj,zj,yj,Ze,wc,Da,Ja,vc,Ye,xj,wj,vj,Ob,Xe,Da,Ja,We,Ve,uj,Ta,La,Mb,eb,Nb,fb,Ub,Da,Pb,tj,fb,Ub,Tb,Pb,sj,rj,qj,$e,Pb,pj,oj,nj,mj,ld,wc,Da,Ja,vc,lj,kj,jj,ij,Ze,wc,Da,Ja,vc,Ye,hj,fj,ej,Ob,Xe,Da,Ja,We,Ve,dj,Ta,La,Mb,eb,Lb,fb,Ub,_a,Da,cj,cf,bf,bj,$i,aj,Zi,Tb,_i,Yi,Xi,Ob,db,tc,Da,Ja,sc,Da,Tb,Te,Wi,Ta,La,Mb,eb,Nb,Ui,Si,Ob,tc,Da,Ja,sc,Te,Ri,Ta,La,Mb,eb,Lb,Ta,La,_a,Da,_a,md,Ja,Vi,Qi,Pi,Oi,Ob,db,tc,Da,Ja,sc,Da,ld,Se,Ni,Ta,La,Mb,eb,Nb,Li,Ji,Ob,tc,Da,Ja,sc,Se,Ii,Ta,La,Mb,eb,Lb,La,_a,Da,_a,md,Ja,Mi,Hi,Ai,yi,Gi,Ei,Fi,Di,Ci,Bi,vi,fb,Da,Da,wi,Dh,Ch,Da,_a,Ja,Ja,qi,pi,ti,ui,ri,oi,ni,li,si,Be,fi,jd,id,hd,gd,ki,Da,db,Zc,Ae,ei,jd,id,hd,gd,ii,Da,db,Zc,ze,di,jd,id,hd,gd,gi,Da,db,Zc,He,ci,Ie,bi,ai,Zh,Yh,Xh,Wh,_h,Vh,$h,Uh,Th,Rh,Qh,Ph,Oh,Sh,Mh,Lh,Kh,Jh,Ih,Wc,ve,Hh,Ta,La,Fh,Eh,fb,_a,Da,Wc,Ah,Bh,Wc,ve,zh,Yf,Xf,Wf,Vf,_b,Tf,Xd,Wd,Sf,Rf,Qf,_a,Pf,Ta,La,Td,Td,Mf,Gf,If,Lf,La,Hf,Jf,Kf,La,Df,La,Cf,La,Ef,zc,db,zc,zc]);function fa(){return E.byteLength/65536|0}function ka(la){la=la|0;var ga=fa()|0;var ha=ga+la|0;if(ga=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}function stringToUTF8Array(str,heap,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx}function lengthBytesUTF8(str){var len=0;for(var i=0;i=55296&&c<=57343){len+=4;++i}else{len+=3}}return len}var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||16777216;assert(INITIAL_MEMORY>=65536,"INITIAL_MEMORY should be larger than STACK_SIZE, was "+INITIAL_MEMORY+"! (STACK_SIZE="+65536+")");if(Module["wasmMemory"]){wasmMemory=Module["wasmMemory"]}else{wasmMemory=new WebAssembly.Memory({"initial":INITIAL_MEMORY/65536,"maximum":2147483648/65536})}updateMemoryViews();INITIAL_MEMORY=wasmMemory.buffer.byteLength;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function keepRuntimeAlive(){return noExitRuntime}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}function isFileURI(filename){return filename.startsWith("file://")}var wasmBinaryFile;wasmBinaryFile="draco_decoder.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}function getBinary(file){try{if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}var binary=tryParseAsDataURI(file);if(binary){return binary}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}catch(err){abort(err)}}function getBinaryPromise(){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"&&!isFileURI(wasmBinaryFile)){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw"failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary(wasmBinaryFile)})}else{if(readAsync){return new Promise(function(resolve,reject){readAsync(wasmBinaryFile,function(response){resolve(new Uint8Array(response))},reject)})}}}return Promise.resolve().then(function(){return getBinary(wasmBinaryFile)})}function createWasm(){var info={"a":wasmImports};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;wasmTable=Module["asm"]["j"];addOnInit(Module["asm"]["i"]);removeRunDependency("wasm-instantiate")}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}function instantiateArrayBuffer(receiver){return getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(function(instance){return instance}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason)})}function instantiateAsync(){if(!wasmBinary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(wasmBinaryFile)&&!isFileURI(wasmBinaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){var result=WebAssembly.instantiateStreaming(response,info);return result.then(receiveInstantiationResult,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(receiveInstantiationResult)})})}else{return instantiateArrayBuffer(receiveInstantiationResult)}}if(Module["instantiateWasm"]){try{var exports=Module["instantiateWasm"](info,receiveInstance);return exports}catch(e){err("Module.instantiateWasm callback failed with error: "+e);readyPromiseReject(e)}}instantiateAsync().catch(readyPromiseReject);return{}}function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){callbacks.shift()(Module)}}function intArrayToString(array){var ret=[];for(var i=0;i255){chr&=255}ret.push(String.fromCharCode(chr))}return ret.join("")}function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_refcount=function(refcount){HEAP32[this.ptr>>2]=refcount};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);this.set_refcount(0);this.set_caught(false);this.set_rethrown(false)};this.add_ref=function(){var value=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=value+1};this.release_ref=function(){var prev=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=prev-1;return prev===1};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr}}var exceptionLast=0;var uncaughtExceptionCount=0;function ___cxa_throw(ptr,type,destructor){var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw ptr}function _abort(){abort("")}function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num)}function getHeapMax(){return 2147483648}function emscripten_realloc_buffer(size){var b=wasmMemory.buffer;try{wasmMemory.grow(size-b.byteLength+65535>>>16);updateMemoryViews();return 1}catch(e){}}function _emscripten_resize_heap(requestedSize){var oldSize=HEAPU8.length;requestedSize=requestedSize>>>0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}let alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=emscripten_realloc_buffer(newSize);if(replacement){return true}}return false}var SYSCALLS={varargs:undefined,get:function(){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret},getStr:function(ptr){var ret=UTF8ToString(ptr);return ret}};function _fd_close(fd){return 52}function _fd_seek(fd,offset_low,offset_high,whence,newOffset){return 70}var printCharBuffers=[null,[],[]];function printChar(stream,curr){var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}}function _fd_write(fd,iov,iovcnt,pnum){var num=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j>2]=num;return 0}function intArrayFromString(stringy,dontAddNull,length){var len=length>0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array}var decodeBase64=typeof atob=="function"?atob:function(input){var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{enc1=keyStr.indexOf(input.charAt(i++));enc2=keyStr.indexOf(input.charAt(i++));enc3=keyStr.indexOf(input.charAt(i++));enc4=keyStr.indexOf(input.charAt(i++));chr1=enc1<<2|enc2>>4;chr2=(enc2&15)<<4|enc3>>2;chr3=(enc3&3)<<6|enc4;output=output+String.fromCharCode(chr1);if(enc3!==64){output=output+String.fromCharCode(chr2)}if(enc4!==64){output=output+String.fromCharCode(chr3)}}while(i0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();function WrapperObject(){}WrapperObject.prototype=Object.create(WrapperObject.prototype);WrapperObject.prototype.constructor=WrapperObject;WrapperObject.prototype.__class__=WrapperObject;WrapperObject.__cache__={};Module["WrapperObject"]=WrapperObject;function getCache(__class__){return(__class__||WrapperObject).__cache__}Module["getCache"]=getCache;function wrapPointer(ptr,__class__){var cache=getCache(__class__);var ret=cache[ptr];if(ret)return ret;ret=Object.create((__class__||WrapperObject).prototype);ret.ptr=ptr;return cache[ptr]=ret}Module["wrapPointer"]=wrapPointer;function castObject(obj,__class__){return wrapPointer(obj.ptr,__class__)}Module["castObject"]=castObject;Module["NULL"]=wrapPointer(0);function destroy(obj){if(!obj["__destroy__"])throw"Error: Cannot destroy object. (Did you create it yourself?)";obj["__destroy__"]();delete getCache(obj.__class__)[obj.ptr]}Module["destroy"]=destroy;function compare(obj1,obj2){return obj1.ptr===obj2.ptr}Module["compare"]=compare;function getPointer(obj){return obj.ptr}Module["getPointer"]=getPointer;function getClass(obj){return obj.__class__}Module["getClass"]=getClass;var ensureCache={buffer:0,size:0,pos:0,temps:[],needed:0,prepare:function(){if(ensureCache.needed){for(var i=0;i=ensureCache.size){assert(len>0);ensureCache.needed+=len;ret=Module["_malloc"](len);ensureCache.temps.push(ret)}else{ret=ensureCache.buffer+ensureCache.pos;ensureCache.pos+=len}return ret},copy:function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HI@5|4{|pj7?>~Q29@(JtX~| z;QCG`;J1>#jdX%^l5~o6Kj}0{f4B3U@_jogo9{cg|4z~aq`LMF0GsLYMqM|NY{FX`r)?PoIhlzJ~|;`LGOE6PD^;RAmcm0FGZi2&A~;Z`3$%QgQFKKv3t jI`!dwO0TC5&f<9B@5#l>$GA4>>>0,$jscomp.propertyToPolyfillSymbol[h]=$jscomp.IS_SYMBOL_NATIVE? +$jscomp.global.Symbol(h):$jscomp.POLYFILL_PREFIX+l+"$"+h),$jscomp.defineProperty(p,$jscomp.propertyToPolyfillSymbol[h],{configurable:!0,writable:!0,value:n})))}; +$jscomp.polyfill("Promise",function(k){function n(){this.batch_=null}function l(f){return f instanceof h?f:new h(function(q,v){q(f)})}if(k&&(!($jscomp.FORCE_POLYFILL_PROMISE||$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION&&"undefined"===typeof $jscomp.global.PromiseRejectionEvent)||!$jscomp.global.Promise||-1===$jscomp.global.Promise.toString().indexOf("[native code]")))return k;n.prototype.asyncExecute=function(f){if(null==this.batch_){this.batch_=[];var q=this;this.asyncExecuteFunction(function(){q.executeBatch_()})}this.batch_.push(f)}; +var p=$jscomp.global.setTimeout;n.prototype.asyncExecuteFunction=function(f){p(f,0)};n.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var f=this.batch_;this.batch_=[];for(var q=0;q=A}},"es6","es3"); +$jscomp.polyfill("Array.prototype.copyWithin",function(k){function n(l){l=Number(l);return Infinity===l||-Infinity===l?l:l|0}return k?k:function(l,p,h){var A=this.length;l=n(l);p=n(p);h=void 0===h?A:n(h);l=0>l?Math.max(A+l,0):Math.min(l,A);p=0>p?Math.max(A+p,0):Math.min(p,A);h=0>h?Math.max(A+h,0):Math.min(h,A);if(lp;)--h in this?this[--l]=this[h]:delete this[--l];return this}},"es6","es3"); +$jscomp.typedArrayCopyWithin=function(k){return k?k:Array.prototype.copyWithin};$jscomp.polyfill("Int8Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Uint8Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Uint8ClampedArray.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Int16Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5"); +$jscomp.polyfill("Uint16Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Int32Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Uint32Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Float32Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Float64Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5"); +var DracoDecoderModule=function(){var k="undefined"!==typeof document&&document.currentScript?document.currentScript.src:void 0;"undefined"!==typeof __filename&&(k=k||__filename);return function(n){function l(e){return a.locateFile?a.locateFile(e,U):U+e}function p(e,b,c){var d=b+c;for(c=b;e[c]&&!(c>=d);)++c;if(16g?d+=String.fromCharCode(g):(g-=65536,d+=String.fromCharCode(55296|g>>10,56320|g&1023))}}else d+=String.fromCharCode(g)}return d}function h(e,b){return e?p(ea,e,b):""}function A(){var e=ja.buffer;a.HEAP8=Y=new Int8Array(e);a.HEAP16=new Int16Array(e);a.HEAP32=ca=new Int32Array(e);a.HEAPU8=ea=new Uint8Array(e);a.HEAPU16=new Uint16Array(e);a.HEAPU32=V=new Uint32Array(e);a.HEAPF32=new Float32Array(e);a.HEAPF64=new Float64Array(e)}function f(e){if(a.onAbort)a.onAbort(e); +e="Aborted("+e+")";da(e);wa=!0;e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info.");ka(e);throw e;}function q(e){try{if(e==P&&fa)return new Uint8Array(fa);if(ma)return ma(e);throw"both async and sync fetching of the wasm failed";}catch(b){f(b)}}function v(){if(!fa&&(xa||ha)){if("function"==typeof fetch&&!P.startsWith("file://"))return fetch(P,{credentials:"same-origin"}).then(function(e){if(!e.ok)throw"failed to load wasm binary file at '"+P+"'";return e.arrayBuffer()}).catch(function(){return q(P)}); +if(na)return new Promise(function(e,b){na(P,function(c){e(new Uint8Array(c))},b)})}return Promise.resolve().then(function(){return q(P)})}function z(e){for(;0>2]=b};this.get_type=function(){return V[this.ptr+4>>2]};this.set_destructor=function(b){V[this.ptr+8>>2]=b};this.get_destructor=function(){return V[this.ptr+8>>2]};this.set_refcount=function(b){ca[this.ptr>>2]=b};this.set_caught=function(b){Y[this.ptr+ +12>>0]=b?1:0};this.get_caught=function(){return 0!=Y[this.ptr+12>>0]};this.set_rethrown=function(b){Y[this.ptr+13>>0]=b?1:0};this.get_rethrown=function(){return 0!=Y[this.ptr+13>>0]};this.init=function(b,c){this.set_adjusted_ptr(0);this.set_type(b);this.set_destructor(c);this.set_refcount(0);this.set_caught(!1);this.set_rethrown(!1)};this.add_ref=function(){ca[this.ptr>>2]+=1};this.release_ref=function(){var b=ca[this.ptr>>2];ca[this.ptr>>2]=b-1;return 1===b};this.set_adjusted_ptr=function(b){V[this.ptr+ +16>>2]=b};this.get_adjusted_ptr=function(){return V[this.ptr+16>>2]};this.get_exception_ptr=function(){if(ya(this.get_type()))return V[this.excPtr>>2];var b=this.get_adjusted_ptr();return 0!==b?b:this.excPtr}}function ba(){function e(){if(!la&&(la=!0,a.calledRun=!0,!wa)){za=!0;z(oa);Aa(a);if(a.onRuntimeInitialized)a.onRuntimeInitialized();if(a.postRun)for("function"==typeof a.postRun&&(a.postRun=[a.postRun]);a.postRun.length;)Ba.unshift(a.postRun.shift());z(Ba)}}if(!(0=d?b++:2047>=d?b+=2:55296<=d&&57343>= +d?(b+=4,++c):b+=3}b=Array(b+1);c=0;d=b.length;if(0=u){var X=e.charCodeAt(++g);u=65536+((u&1023)<<10)|X&1023}if(127>=u){if(c>=d)break;b[c++]=u}else{if(2047>=u){if(c+1>=d)break;b[c++]=192|u>>6}else{if(65535>=u){if(c+2>=d)break;b[c++]=224|u>>12}else{if(c+3>=d)break;b[c++]=240|u>>18;b[c++]=128|u>>12&63}b[c++]=128|u>>6&63}b[c++]=128|u&63}}b[c]=0}e=r.alloc(b,Y);r.copy(b,Y,e);return e}return e}function pa(e){if("object"===typeof e){var b= +r.alloc(e,Y);r.copy(e,Y,b);return b}return e}function Z(){throw"cannot construct a VoidPtr, no constructor in IDL";}function S(){this.ptr=Da();x(S)[this.ptr]=this}function Q(){this.ptr=Ea();x(Q)[this.ptr]=this}function W(){this.ptr=Fa();x(W)[this.ptr]=this}function w(){this.ptr=Ga();x(w)[this.ptr]=this}function C(){this.ptr=Ha();x(C)[this.ptr]=this}function F(){this.ptr=Ia();x(F)[this.ptr]=this}function G(){this.ptr=Ja();x(G)[this.ptr]=this}function E(){this.ptr=Ka();x(E)[this.ptr]=this}function T(){this.ptr= +La();x(T)[this.ptr]=this}function B(){throw"cannot construct a Status, no constructor in IDL";}function H(){this.ptr=Ma();x(H)[this.ptr]=this}function I(){this.ptr=Na();x(I)[this.ptr]=this}function J(){this.ptr=Oa();x(J)[this.ptr]=this}function K(){this.ptr=Pa();x(K)[this.ptr]=this}function L(){this.ptr=Qa();x(L)[this.ptr]=this}function M(){this.ptr=Ra();x(M)[this.ptr]=this}function N(){this.ptr=Sa();x(N)[this.ptr]=this}function y(){this.ptr=Ta();x(y)[this.ptr]=this}function m(){this.ptr=Ua();x(m)[this.ptr]= +this}n=void 0===n?{}:n;var a="undefined"!=typeof n?n:{},Aa,ka;a.ready=new Promise(function(e,b){Aa=e;ka=b});var Va=!1,Wa=!1;a.onRuntimeInitialized=function(){Va=!0;if(Wa&&"function"===typeof a.onModuleLoaded)a.onModuleLoaded(a)};a.onModuleParsed=function(){Wa=!0;if(Va&&"function"===typeof a.onModuleLoaded)a.onModuleLoaded(a)};a.isVersionSupported=function(e){if("string"!==typeof e)return!1;e=e.split(".");return 2>e.length||3=e[1]?!0:0!=e[0]||10>>=0;if(2147483648=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,e+100663296);var g=Math;d=Math.max(e,d);g=g.min.call(g,2147483648,d+(65536-d%65536)%65536);a:{d=ja.buffer;try{ja.grow(g-d.byteLength+65535>>>16);A();var u=1;break a}catch(X){}u=void 0}if(u)return!0}return!1},f:function(e){return 52},d:function(e,b,c,d,g){return 70},c:function(e,b,c,d){for(var g=0,u=0;u>2],ab=V[b+4>>2];b+=8;for(var sa=0;sa>2]=g;return 0}};(function(){function e(g,u){a.asm=g.exports;ja=a.asm.h;A();oa.unshift(a.asm.i);aa--;a.monitorRunDependencies&&a.monitorRunDependencies(aa);0==aa&&(null!==ra&&(clearInterval(ra),ra=null),ia&&(g=ia,ia=null,g()))}function b(g){e(g.instance)}function c(g){return v().then(function(u){return WebAssembly.instantiate(u,d)}).then(function(u){return u}).then(g,function(u){da("failed to asynchronously prepare wasm: "+u);f(u)})}var d={a:xd};aa++;a.monitorRunDependencies&&a.monitorRunDependencies(aa); +if(a.instantiateWasm)try{return a.instantiateWasm(d,e)}catch(g){da("Module.instantiateWasm callback failed with error: "+g),ka(g)}(function(){return fa||"function"!=typeof WebAssembly.instantiateStreaming||P.startsWith("data:application/octet-stream;base64,")||P.startsWith("file://")||Ya||"function"!=typeof fetch?c(b):fetch(P,{credentials:"same-origin"}).then(function(g){return WebAssembly.instantiateStreaming(g,d).then(b,function(u){da("wasm streaming compile failed: "+u);da("falling back to ArrayBuffer instantiation"); +return c(b)})})})().catch(ka);return{}})();var bb=a._emscripten_bind_VoidPtr___destroy___0=function(){return(bb=a._emscripten_bind_VoidPtr___destroy___0=a.asm.k).apply(null,arguments)},Da=a._emscripten_bind_DecoderBuffer_DecoderBuffer_0=function(){return(Da=a._emscripten_bind_DecoderBuffer_DecoderBuffer_0=a.asm.l).apply(null,arguments)},cb=a._emscripten_bind_DecoderBuffer_Init_2=function(){return(cb=a._emscripten_bind_DecoderBuffer_Init_2=a.asm.m).apply(null,arguments)},db=a._emscripten_bind_DecoderBuffer___destroy___0= +function(){return(db=a._emscripten_bind_DecoderBuffer___destroy___0=a.asm.n).apply(null,arguments)},Ea=a._emscripten_bind_AttributeTransformData_AttributeTransformData_0=function(){return(Ea=a._emscripten_bind_AttributeTransformData_AttributeTransformData_0=a.asm.o).apply(null,arguments)},eb=a._emscripten_bind_AttributeTransformData_transform_type_0=function(){return(eb=a._emscripten_bind_AttributeTransformData_transform_type_0=a.asm.p).apply(null,arguments)},fb=a._emscripten_bind_AttributeTransformData___destroy___0= +function(){return(fb=a._emscripten_bind_AttributeTransformData___destroy___0=a.asm.q).apply(null,arguments)},Fa=a._emscripten_bind_GeometryAttribute_GeometryAttribute_0=function(){return(Fa=a._emscripten_bind_GeometryAttribute_GeometryAttribute_0=a.asm.r).apply(null,arguments)},gb=a._emscripten_bind_GeometryAttribute___destroy___0=function(){return(gb=a._emscripten_bind_GeometryAttribute___destroy___0=a.asm.s).apply(null,arguments)},Ga=a._emscripten_bind_PointAttribute_PointAttribute_0=function(){return(Ga= +a._emscripten_bind_PointAttribute_PointAttribute_0=a.asm.t).apply(null,arguments)},hb=a._emscripten_bind_PointAttribute_size_0=function(){return(hb=a._emscripten_bind_PointAttribute_size_0=a.asm.u).apply(null,arguments)},ib=a._emscripten_bind_PointAttribute_GetAttributeTransformData_0=function(){return(ib=a._emscripten_bind_PointAttribute_GetAttributeTransformData_0=a.asm.v).apply(null,arguments)},jb=a._emscripten_bind_PointAttribute_attribute_type_0=function(){return(jb=a._emscripten_bind_PointAttribute_attribute_type_0= +a.asm.w).apply(null,arguments)},kb=a._emscripten_bind_PointAttribute_data_type_0=function(){return(kb=a._emscripten_bind_PointAttribute_data_type_0=a.asm.x).apply(null,arguments)},lb=a._emscripten_bind_PointAttribute_num_components_0=function(){return(lb=a._emscripten_bind_PointAttribute_num_components_0=a.asm.y).apply(null,arguments)},mb=a._emscripten_bind_PointAttribute_normalized_0=function(){return(mb=a._emscripten_bind_PointAttribute_normalized_0=a.asm.z).apply(null,arguments)},nb=a._emscripten_bind_PointAttribute_byte_stride_0= +function(){return(nb=a._emscripten_bind_PointAttribute_byte_stride_0=a.asm.A).apply(null,arguments)},ob=a._emscripten_bind_PointAttribute_byte_offset_0=function(){return(ob=a._emscripten_bind_PointAttribute_byte_offset_0=a.asm.B).apply(null,arguments)},pb=a._emscripten_bind_PointAttribute_unique_id_0=function(){return(pb=a._emscripten_bind_PointAttribute_unique_id_0=a.asm.C).apply(null,arguments)},qb=a._emscripten_bind_PointAttribute___destroy___0=function(){return(qb=a._emscripten_bind_PointAttribute___destroy___0= +a.asm.D).apply(null,arguments)},Ha=a._emscripten_bind_AttributeQuantizationTransform_AttributeQuantizationTransform_0=function(){return(Ha=a._emscripten_bind_AttributeQuantizationTransform_AttributeQuantizationTransform_0=a.asm.E).apply(null,arguments)},rb=a._emscripten_bind_AttributeQuantizationTransform_InitFromAttribute_1=function(){return(rb=a._emscripten_bind_AttributeQuantizationTransform_InitFromAttribute_1=a.asm.F).apply(null,arguments)},sb=a._emscripten_bind_AttributeQuantizationTransform_quantization_bits_0= +function(){return(sb=a._emscripten_bind_AttributeQuantizationTransform_quantization_bits_0=a.asm.G).apply(null,arguments)},tb=a._emscripten_bind_AttributeQuantizationTransform_min_value_1=function(){return(tb=a._emscripten_bind_AttributeQuantizationTransform_min_value_1=a.asm.H).apply(null,arguments)},ub=a._emscripten_bind_AttributeQuantizationTransform_range_0=function(){return(ub=a._emscripten_bind_AttributeQuantizationTransform_range_0=a.asm.I).apply(null,arguments)},vb=a._emscripten_bind_AttributeQuantizationTransform___destroy___0= +function(){return(vb=a._emscripten_bind_AttributeQuantizationTransform___destroy___0=a.asm.J).apply(null,arguments)},Ia=a._emscripten_bind_AttributeOctahedronTransform_AttributeOctahedronTransform_0=function(){return(Ia=a._emscripten_bind_AttributeOctahedronTransform_AttributeOctahedronTransform_0=a.asm.K).apply(null,arguments)},wb=a._emscripten_bind_AttributeOctahedronTransform_InitFromAttribute_1=function(){return(wb=a._emscripten_bind_AttributeOctahedronTransform_InitFromAttribute_1=a.asm.L).apply(null, +arguments)},xb=a._emscripten_bind_AttributeOctahedronTransform_quantization_bits_0=function(){return(xb=a._emscripten_bind_AttributeOctahedronTransform_quantization_bits_0=a.asm.M).apply(null,arguments)},yb=a._emscripten_bind_AttributeOctahedronTransform___destroy___0=function(){return(yb=a._emscripten_bind_AttributeOctahedronTransform___destroy___0=a.asm.N).apply(null,arguments)},Ja=a._emscripten_bind_PointCloud_PointCloud_0=function(){return(Ja=a._emscripten_bind_PointCloud_PointCloud_0=a.asm.O).apply(null, +arguments)},zb=a._emscripten_bind_PointCloud_num_attributes_0=function(){return(zb=a._emscripten_bind_PointCloud_num_attributes_0=a.asm.P).apply(null,arguments)},Ab=a._emscripten_bind_PointCloud_num_points_0=function(){return(Ab=a._emscripten_bind_PointCloud_num_points_0=a.asm.Q).apply(null,arguments)},Bb=a._emscripten_bind_PointCloud___destroy___0=function(){return(Bb=a._emscripten_bind_PointCloud___destroy___0=a.asm.R).apply(null,arguments)},Ka=a._emscripten_bind_Mesh_Mesh_0=function(){return(Ka= +a._emscripten_bind_Mesh_Mesh_0=a.asm.S).apply(null,arguments)},Cb=a._emscripten_bind_Mesh_num_faces_0=function(){return(Cb=a._emscripten_bind_Mesh_num_faces_0=a.asm.T).apply(null,arguments)},Db=a._emscripten_bind_Mesh_num_attributes_0=function(){return(Db=a._emscripten_bind_Mesh_num_attributes_0=a.asm.U).apply(null,arguments)},Eb=a._emscripten_bind_Mesh_num_points_0=function(){return(Eb=a._emscripten_bind_Mesh_num_points_0=a.asm.V).apply(null,arguments)},Fb=a._emscripten_bind_Mesh___destroy___0=function(){return(Fb= +a._emscripten_bind_Mesh___destroy___0=a.asm.W).apply(null,arguments)},La=a._emscripten_bind_Metadata_Metadata_0=function(){return(La=a._emscripten_bind_Metadata_Metadata_0=a.asm.X).apply(null,arguments)},Gb=a._emscripten_bind_Metadata___destroy___0=function(){return(Gb=a._emscripten_bind_Metadata___destroy___0=a.asm.Y).apply(null,arguments)},Hb=a._emscripten_bind_Status_code_0=function(){return(Hb=a._emscripten_bind_Status_code_0=a.asm.Z).apply(null,arguments)},Ib=a._emscripten_bind_Status_ok_0=function(){return(Ib= +a._emscripten_bind_Status_ok_0=a.asm._).apply(null,arguments)},Jb=a._emscripten_bind_Status_error_msg_0=function(){return(Jb=a._emscripten_bind_Status_error_msg_0=a.asm.$).apply(null,arguments)},Kb=a._emscripten_bind_Status___destroy___0=function(){return(Kb=a._emscripten_bind_Status___destroy___0=a.asm.aa).apply(null,arguments)},Ma=a._emscripten_bind_DracoFloat32Array_DracoFloat32Array_0=function(){return(Ma=a._emscripten_bind_DracoFloat32Array_DracoFloat32Array_0=a.asm.ba).apply(null,arguments)}, +Lb=a._emscripten_bind_DracoFloat32Array_GetValue_1=function(){return(Lb=a._emscripten_bind_DracoFloat32Array_GetValue_1=a.asm.ca).apply(null,arguments)},Mb=a._emscripten_bind_DracoFloat32Array_size_0=function(){return(Mb=a._emscripten_bind_DracoFloat32Array_size_0=a.asm.da).apply(null,arguments)},Nb=a._emscripten_bind_DracoFloat32Array___destroy___0=function(){return(Nb=a._emscripten_bind_DracoFloat32Array___destroy___0=a.asm.ea).apply(null,arguments)},Na=a._emscripten_bind_DracoInt8Array_DracoInt8Array_0= +function(){return(Na=a._emscripten_bind_DracoInt8Array_DracoInt8Array_0=a.asm.fa).apply(null,arguments)},Ob=a._emscripten_bind_DracoInt8Array_GetValue_1=function(){return(Ob=a._emscripten_bind_DracoInt8Array_GetValue_1=a.asm.ga).apply(null,arguments)},Pb=a._emscripten_bind_DracoInt8Array_size_0=function(){return(Pb=a._emscripten_bind_DracoInt8Array_size_0=a.asm.ha).apply(null,arguments)},Qb=a._emscripten_bind_DracoInt8Array___destroy___0=function(){return(Qb=a._emscripten_bind_DracoInt8Array___destroy___0= +a.asm.ia).apply(null,arguments)},Oa=a._emscripten_bind_DracoUInt8Array_DracoUInt8Array_0=function(){return(Oa=a._emscripten_bind_DracoUInt8Array_DracoUInt8Array_0=a.asm.ja).apply(null,arguments)},Rb=a._emscripten_bind_DracoUInt8Array_GetValue_1=function(){return(Rb=a._emscripten_bind_DracoUInt8Array_GetValue_1=a.asm.ka).apply(null,arguments)},Sb=a._emscripten_bind_DracoUInt8Array_size_0=function(){return(Sb=a._emscripten_bind_DracoUInt8Array_size_0=a.asm.la).apply(null,arguments)},Tb=a._emscripten_bind_DracoUInt8Array___destroy___0= +function(){return(Tb=a._emscripten_bind_DracoUInt8Array___destroy___0=a.asm.ma).apply(null,arguments)},Pa=a._emscripten_bind_DracoInt16Array_DracoInt16Array_0=function(){return(Pa=a._emscripten_bind_DracoInt16Array_DracoInt16Array_0=a.asm.na).apply(null,arguments)},Ub=a._emscripten_bind_DracoInt16Array_GetValue_1=function(){return(Ub=a._emscripten_bind_DracoInt16Array_GetValue_1=a.asm.oa).apply(null,arguments)},Vb=a._emscripten_bind_DracoInt16Array_size_0=function(){return(Vb=a._emscripten_bind_DracoInt16Array_size_0= +a.asm.pa).apply(null,arguments)},Wb=a._emscripten_bind_DracoInt16Array___destroy___0=function(){return(Wb=a._emscripten_bind_DracoInt16Array___destroy___0=a.asm.qa).apply(null,arguments)},Qa=a._emscripten_bind_DracoUInt16Array_DracoUInt16Array_0=function(){return(Qa=a._emscripten_bind_DracoUInt16Array_DracoUInt16Array_0=a.asm.ra).apply(null,arguments)},Xb=a._emscripten_bind_DracoUInt16Array_GetValue_1=function(){return(Xb=a._emscripten_bind_DracoUInt16Array_GetValue_1=a.asm.sa).apply(null,arguments)}, +Yb=a._emscripten_bind_DracoUInt16Array_size_0=function(){return(Yb=a._emscripten_bind_DracoUInt16Array_size_0=a.asm.ta).apply(null,arguments)},Zb=a._emscripten_bind_DracoUInt16Array___destroy___0=function(){return(Zb=a._emscripten_bind_DracoUInt16Array___destroy___0=a.asm.ua).apply(null,arguments)},Ra=a._emscripten_bind_DracoInt32Array_DracoInt32Array_0=function(){return(Ra=a._emscripten_bind_DracoInt32Array_DracoInt32Array_0=a.asm.va).apply(null,arguments)},$b=a._emscripten_bind_DracoInt32Array_GetValue_1= +function(){return($b=a._emscripten_bind_DracoInt32Array_GetValue_1=a.asm.wa).apply(null,arguments)},ac=a._emscripten_bind_DracoInt32Array_size_0=function(){return(ac=a._emscripten_bind_DracoInt32Array_size_0=a.asm.xa).apply(null,arguments)},bc=a._emscripten_bind_DracoInt32Array___destroy___0=function(){return(bc=a._emscripten_bind_DracoInt32Array___destroy___0=a.asm.ya).apply(null,arguments)},Sa=a._emscripten_bind_DracoUInt32Array_DracoUInt32Array_0=function(){return(Sa=a._emscripten_bind_DracoUInt32Array_DracoUInt32Array_0= +a.asm.za).apply(null,arguments)},cc=a._emscripten_bind_DracoUInt32Array_GetValue_1=function(){return(cc=a._emscripten_bind_DracoUInt32Array_GetValue_1=a.asm.Aa).apply(null,arguments)},dc=a._emscripten_bind_DracoUInt32Array_size_0=function(){return(dc=a._emscripten_bind_DracoUInt32Array_size_0=a.asm.Ba).apply(null,arguments)},ec=a._emscripten_bind_DracoUInt32Array___destroy___0=function(){return(ec=a._emscripten_bind_DracoUInt32Array___destroy___0=a.asm.Ca).apply(null,arguments)},Ta=a._emscripten_bind_MetadataQuerier_MetadataQuerier_0= +function(){return(Ta=a._emscripten_bind_MetadataQuerier_MetadataQuerier_0=a.asm.Da).apply(null,arguments)},fc=a._emscripten_bind_MetadataQuerier_HasEntry_2=function(){return(fc=a._emscripten_bind_MetadataQuerier_HasEntry_2=a.asm.Ea).apply(null,arguments)},gc=a._emscripten_bind_MetadataQuerier_GetIntEntry_2=function(){return(gc=a._emscripten_bind_MetadataQuerier_GetIntEntry_2=a.asm.Fa).apply(null,arguments)},hc=a._emscripten_bind_MetadataQuerier_GetIntEntryArray_3=function(){return(hc=a._emscripten_bind_MetadataQuerier_GetIntEntryArray_3= +a.asm.Ga).apply(null,arguments)},ic=a._emscripten_bind_MetadataQuerier_GetDoubleEntry_2=function(){return(ic=a._emscripten_bind_MetadataQuerier_GetDoubleEntry_2=a.asm.Ha).apply(null,arguments)},jc=a._emscripten_bind_MetadataQuerier_GetStringEntry_2=function(){return(jc=a._emscripten_bind_MetadataQuerier_GetStringEntry_2=a.asm.Ia).apply(null,arguments)},kc=a._emscripten_bind_MetadataQuerier_NumEntries_1=function(){return(kc=a._emscripten_bind_MetadataQuerier_NumEntries_1=a.asm.Ja).apply(null,arguments)}, +lc=a._emscripten_bind_MetadataQuerier_GetEntryName_2=function(){return(lc=a._emscripten_bind_MetadataQuerier_GetEntryName_2=a.asm.Ka).apply(null,arguments)},mc=a._emscripten_bind_MetadataQuerier___destroy___0=function(){return(mc=a._emscripten_bind_MetadataQuerier___destroy___0=a.asm.La).apply(null,arguments)},Ua=a._emscripten_bind_Decoder_Decoder_0=function(){return(Ua=a._emscripten_bind_Decoder_Decoder_0=a.asm.Ma).apply(null,arguments)},nc=a._emscripten_bind_Decoder_DecodeArrayToPointCloud_3=function(){return(nc= +a._emscripten_bind_Decoder_DecodeArrayToPointCloud_3=a.asm.Na).apply(null,arguments)},oc=a._emscripten_bind_Decoder_DecodeArrayToMesh_3=function(){return(oc=a._emscripten_bind_Decoder_DecodeArrayToMesh_3=a.asm.Oa).apply(null,arguments)},pc=a._emscripten_bind_Decoder_GetAttributeId_2=function(){return(pc=a._emscripten_bind_Decoder_GetAttributeId_2=a.asm.Pa).apply(null,arguments)},qc=a._emscripten_bind_Decoder_GetAttributeIdByName_2=function(){return(qc=a._emscripten_bind_Decoder_GetAttributeIdByName_2= +a.asm.Qa).apply(null,arguments)},rc=a._emscripten_bind_Decoder_GetAttributeIdByMetadataEntry_3=function(){return(rc=a._emscripten_bind_Decoder_GetAttributeIdByMetadataEntry_3=a.asm.Ra).apply(null,arguments)},sc=a._emscripten_bind_Decoder_GetAttribute_2=function(){return(sc=a._emscripten_bind_Decoder_GetAttribute_2=a.asm.Sa).apply(null,arguments)},tc=a._emscripten_bind_Decoder_GetAttributeByUniqueId_2=function(){return(tc=a._emscripten_bind_Decoder_GetAttributeByUniqueId_2=a.asm.Ta).apply(null,arguments)}, +uc=a._emscripten_bind_Decoder_GetMetadata_1=function(){return(uc=a._emscripten_bind_Decoder_GetMetadata_1=a.asm.Ua).apply(null,arguments)},vc=a._emscripten_bind_Decoder_GetAttributeMetadata_2=function(){return(vc=a._emscripten_bind_Decoder_GetAttributeMetadata_2=a.asm.Va).apply(null,arguments)},wc=a._emscripten_bind_Decoder_GetFaceFromMesh_3=function(){return(wc=a._emscripten_bind_Decoder_GetFaceFromMesh_3=a.asm.Wa).apply(null,arguments)},xc=a._emscripten_bind_Decoder_GetTriangleStripsFromMesh_2= +function(){return(xc=a._emscripten_bind_Decoder_GetTriangleStripsFromMesh_2=a.asm.Xa).apply(null,arguments)},yc=a._emscripten_bind_Decoder_GetTrianglesUInt16Array_3=function(){return(yc=a._emscripten_bind_Decoder_GetTrianglesUInt16Array_3=a.asm.Ya).apply(null,arguments)},zc=a._emscripten_bind_Decoder_GetTrianglesUInt32Array_3=function(){return(zc=a._emscripten_bind_Decoder_GetTrianglesUInt32Array_3=a.asm.Za).apply(null,arguments)},Ac=a._emscripten_bind_Decoder_GetAttributeFloat_3=function(){return(Ac= +a._emscripten_bind_Decoder_GetAttributeFloat_3=a.asm._a).apply(null,arguments)},Bc=a._emscripten_bind_Decoder_GetAttributeFloatForAllPoints_3=function(){return(Bc=a._emscripten_bind_Decoder_GetAttributeFloatForAllPoints_3=a.asm.$a).apply(null,arguments)},Cc=a._emscripten_bind_Decoder_GetAttributeIntForAllPoints_3=function(){return(Cc=a._emscripten_bind_Decoder_GetAttributeIntForAllPoints_3=a.asm.ab).apply(null,arguments)},Dc=a._emscripten_bind_Decoder_GetAttributeInt8ForAllPoints_3=function(){return(Dc= +a._emscripten_bind_Decoder_GetAttributeInt8ForAllPoints_3=a.asm.bb).apply(null,arguments)},Ec=a._emscripten_bind_Decoder_GetAttributeUInt8ForAllPoints_3=function(){return(Ec=a._emscripten_bind_Decoder_GetAttributeUInt8ForAllPoints_3=a.asm.cb).apply(null,arguments)},Fc=a._emscripten_bind_Decoder_GetAttributeInt16ForAllPoints_3=function(){return(Fc=a._emscripten_bind_Decoder_GetAttributeInt16ForAllPoints_3=a.asm.db).apply(null,arguments)},Gc=a._emscripten_bind_Decoder_GetAttributeUInt16ForAllPoints_3= +function(){return(Gc=a._emscripten_bind_Decoder_GetAttributeUInt16ForAllPoints_3=a.asm.eb).apply(null,arguments)},Hc=a._emscripten_bind_Decoder_GetAttributeInt32ForAllPoints_3=function(){return(Hc=a._emscripten_bind_Decoder_GetAttributeInt32ForAllPoints_3=a.asm.fb).apply(null,arguments)},Ic=a._emscripten_bind_Decoder_GetAttributeUInt32ForAllPoints_3=function(){return(Ic=a._emscripten_bind_Decoder_GetAttributeUInt32ForAllPoints_3=a.asm.gb).apply(null,arguments)},Jc=a._emscripten_bind_Decoder_GetAttributeDataArrayForAllPoints_5= +function(){return(Jc=a._emscripten_bind_Decoder_GetAttributeDataArrayForAllPoints_5=a.asm.hb).apply(null,arguments)},Kc=a._emscripten_bind_Decoder_SkipAttributeTransform_1=function(){return(Kc=a._emscripten_bind_Decoder_SkipAttributeTransform_1=a.asm.ib).apply(null,arguments)},Lc=a._emscripten_bind_Decoder_GetEncodedGeometryType_Deprecated_1=function(){return(Lc=a._emscripten_bind_Decoder_GetEncodedGeometryType_Deprecated_1=a.asm.jb).apply(null,arguments)},Mc=a._emscripten_bind_Decoder_DecodeBufferToPointCloud_2= +function(){return(Mc=a._emscripten_bind_Decoder_DecodeBufferToPointCloud_2=a.asm.kb).apply(null,arguments)},Nc=a._emscripten_bind_Decoder_DecodeBufferToMesh_2=function(){return(Nc=a._emscripten_bind_Decoder_DecodeBufferToMesh_2=a.asm.lb).apply(null,arguments)},Oc=a._emscripten_bind_Decoder___destroy___0=function(){return(Oc=a._emscripten_bind_Decoder___destroy___0=a.asm.mb).apply(null,arguments)},Pc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_INVALID_TRANSFORM=function(){return(Pc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_INVALID_TRANSFORM= +a.asm.nb).apply(null,arguments)},Qc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_NO_TRANSFORM=function(){return(Qc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_NO_TRANSFORM=a.asm.ob).apply(null,arguments)},Rc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_QUANTIZATION_TRANSFORM=function(){return(Rc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_QUANTIZATION_TRANSFORM=a.asm.pb).apply(null,arguments)},Sc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_OCTAHEDRON_TRANSFORM= +function(){return(Sc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_OCTAHEDRON_TRANSFORM=a.asm.qb).apply(null,arguments)},Tc=a._emscripten_enum_draco_GeometryAttribute_Type_INVALID=function(){return(Tc=a._emscripten_enum_draco_GeometryAttribute_Type_INVALID=a.asm.rb).apply(null,arguments)},Uc=a._emscripten_enum_draco_GeometryAttribute_Type_POSITION=function(){return(Uc=a._emscripten_enum_draco_GeometryAttribute_Type_POSITION=a.asm.sb).apply(null,arguments)},Vc=a._emscripten_enum_draco_GeometryAttribute_Type_NORMAL= +function(){return(Vc=a._emscripten_enum_draco_GeometryAttribute_Type_NORMAL=a.asm.tb).apply(null,arguments)},Wc=a._emscripten_enum_draco_GeometryAttribute_Type_COLOR=function(){return(Wc=a._emscripten_enum_draco_GeometryAttribute_Type_COLOR=a.asm.ub).apply(null,arguments)},Xc=a._emscripten_enum_draco_GeometryAttribute_Type_TEX_COORD=function(){return(Xc=a._emscripten_enum_draco_GeometryAttribute_Type_TEX_COORD=a.asm.vb).apply(null,arguments)},Yc=a._emscripten_enum_draco_GeometryAttribute_Type_GENERIC= +function(){return(Yc=a._emscripten_enum_draco_GeometryAttribute_Type_GENERIC=a.asm.wb).apply(null,arguments)},Zc=a._emscripten_enum_draco_EncodedGeometryType_INVALID_GEOMETRY_TYPE=function(){return(Zc=a._emscripten_enum_draco_EncodedGeometryType_INVALID_GEOMETRY_TYPE=a.asm.xb).apply(null,arguments)},$c=a._emscripten_enum_draco_EncodedGeometryType_POINT_CLOUD=function(){return($c=a._emscripten_enum_draco_EncodedGeometryType_POINT_CLOUD=a.asm.yb).apply(null,arguments)},ad=a._emscripten_enum_draco_EncodedGeometryType_TRIANGULAR_MESH= +function(){return(ad=a._emscripten_enum_draco_EncodedGeometryType_TRIANGULAR_MESH=a.asm.zb).apply(null,arguments)},bd=a._emscripten_enum_draco_DataType_DT_INVALID=function(){return(bd=a._emscripten_enum_draco_DataType_DT_INVALID=a.asm.Ab).apply(null,arguments)},cd=a._emscripten_enum_draco_DataType_DT_INT8=function(){return(cd=a._emscripten_enum_draco_DataType_DT_INT8=a.asm.Bb).apply(null,arguments)},dd=a._emscripten_enum_draco_DataType_DT_UINT8=function(){return(dd=a._emscripten_enum_draco_DataType_DT_UINT8= +a.asm.Cb).apply(null,arguments)},ed=a._emscripten_enum_draco_DataType_DT_INT16=function(){return(ed=a._emscripten_enum_draco_DataType_DT_INT16=a.asm.Db).apply(null,arguments)},fd=a._emscripten_enum_draco_DataType_DT_UINT16=function(){return(fd=a._emscripten_enum_draco_DataType_DT_UINT16=a.asm.Eb).apply(null,arguments)},gd=a._emscripten_enum_draco_DataType_DT_INT32=function(){return(gd=a._emscripten_enum_draco_DataType_DT_INT32=a.asm.Fb).apply(null,arguments)},hd=a._emscripten_enum_draco_DataType_DT_UINT32= +function(){return(hd=a._emscripten_enum_draco_DataType_DT_UINT32=a.asm.Gb).apply(null,arguments)},id=a._emscripten_enum_draco_DataType_DT_INT64=function(){return(id=a._emscripten_enum_draco_DataType_DT_INT64=a.asm.Hb).apply(null,arguments)},jd=a._emscripten_enum_draco_DataType_DT_UINT64=function(){return(jd=a._emscripten_enum_draco_DataType_DT_UINT64=a.asm.Ib).apply(null,arguments)},kd=a._emscripten_enum_draco_DataType_DT_FLOAT32=function(){return(kd=a._emscripten_enum_draco_DataType_DT_FLOAT32=a.asm.Jb).apply(null, +arguments)},ld=a._emscripten_enum_draco_DataType_DT_FLOAT64=function(){return(ld=a._emscripten_enum_draco_DataType_DT_FLOAT64=a.asm.Kb).apply(null,arguments)},md=a._emscripten_enum_draco_DataType_DT_BOOL=function(){return(md=a._emscripten_enum_draco_DataType_DT_BOOL=a.asm.Lb).apply(null,arguments)},nd=a._emscripten_enum_draco_DataType_DT_TYPES_COUNT=function(){return(nd=a._emscripten_enum_draco_DataType_DT_TYPES_COUNT=a.asm.Mb).apply(null,arguments)},od=a._emscripten_enum_draco_StatusCode_OK=function(){return(od= +a._emscripten_enum_draco_StatusCode_OK=a.asm.Nb).apply(null,arguments)},pd=a._emscripten_enum_draco_StatusCode_DRACO_ERROR=function(){return(pd=a._emscripten_enum_draco_StatusCode_DRACO_ERROR=a.asm.Ob).apply(null,arguments)},qd=a._emscripten_enum_draco_StatusCode_IO_ERROR=function(){return(qd=a._emscripten_enum_draco_StatusCode_IO_ERROR=a.asm.Pb).apply(null,arguments)},rd=a._emscripten_enum_draco_StatusCode_INVALID_PARAMETER=function(){return(rd=a._emscripten_enum_draco_StatusCode_INVALID_PARAMETER= +a.asm.Qb).apply(null,arguments)},sd=a._emscripten_enum_draco_StatusCode_UNSUPPORTED_VERSION=function(){return(sd=a._emscripten_enum_draco_StatusCode_UNSUPPORTED_VERSION=a.asm.Rb).apply(null,arguments)},td=a._emscripten_enum_draco_StatusCode_UNKNOWN_VERSION=function(){return(td=a._emscripten_enum_draco_StatusCode_UNKNOWN_VERSION=a.asm.Sb).apply(null,arguments)};a._malloc=function(){return(a._malloc=a.asm.Tb).apply(null,arguments)};a._free=function(){return(a._free=a.asm.Ub).apply(null,arguments)}; +var ya=function(){return(ya=a.asm.Vb).apply(null,arguments)};a.___start_em_js=15856;a.___stop_em_js=15954;var la;ia=function b(){la||ba();la||(ia=b)};if(a.preInit)for("function"==typeof a.preInit&&(a.preInit=[a.preInit]);0=r.size?(0>>=0;switch(c.BYTES_PER_ELEMENT){case 2:d>>>=1;break;case 4:d>>>=2;break;case 8:d>>>=3}for(var g=0;gb.byteLength)return a.INVALID_GEOMETRY_TYPE;switch(b[7]){case 0:return a.POINT_CLOUD;case 1:return a.TRIANGULAR_MESH;default:return a.INVALID_GEOMETRY_TYPE}};return n.ready}}(); +"object"===typeof exports&&"object"===typeof module?module.exports=DracoDecoderModule:"function"===typeof define&&define.amd?define([],function(){return DracoDecoderModule}):"object"===typeof exports&&(exports.DracoDecoderModule=DracoDecoderModule); diff --git a/libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_decoder.js b/libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_decoder.js new file mode 100644 index 000000000..7c84b0be2 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_decoder.js @@ -0,0 +1,33 @@ + +var DracoDecoderModule = (() => { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename; + return ( +function(DracoDecoderModule = {}) { + +var Module=typeof DracoDecoderModule!="undefined"?DracoDecoderModule:{};var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise(function(resolve,reject){readyPromiseResolve=resolve;readyPromiseReject=reject});var isRuntimeInitialized=false;var isModuleParsed=false;Module["onRuntimeInitialized"]=function(){isRuntimeInitialized=true;if(isModuleParsed){if(typeof Module["onModuleLoaded"]==="function"){Module["onModuleLoaded"](Module)}}};Module["onModuleParsed"]=function(){isModuleParsed=true;if(isRuntimeInitialized){if(typeof Module["onModuleLoaded"]==="function"){Module["onModuleLoaded"](Module)}}};function isVersionSupported(versionString){if(typeof versionString!=="string")return false;const version=versionString.split(".");if(version.length<2||version.length>3)return false;if(version[0]==1&&version[1]>=0&&version[1]<=5)return true;if(version[0]!=0||version[1]>10)return false;return true}Module["isVersionSupported"]=isVersionSupported;var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;function logExceptionOnExit(e){if(e instanceof ExitStatus)return;let toLog=e;err("exiting due to exception: "+toLog)}if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");if(ENVIRONMENT_IS_WORKER){scriptDirectory=nodePath.dirname(scriptDirectory)+"/"}else{scriptDirectory=__dirname+"/"}read_=(filename,binary)=>{var ret=tryParseAsDataURI(filename);if(ret){return binary?ret:ret.toString()}filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return fs.readFileSync(filename,binary?undefined:"utf8")};readBinary=filename=>{var ret=read_(filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}return ret};readAsync=(filename,onload,onerror)=>{var ret=tryParseAsDataURI(filename);if(ret){onload(ret)}filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);fs.readFile(filename,function(err,data){if(err)onerror(err);else onload(data.buffer)})};if(process["argv"].length>1){thisProgram=process["argv"][1].replace(/\\/g,"/")}arguments_=process["argv"].slice(2);quit_=(status,toThrow)=>{if(keepRuntimeAlive()){process["exitCode"]=status;throw toThrow}logExceptionOnExit(toThrow);process["exit"](status)};Module["inspect"]=function(){return"[Emscripten Module object]"}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptDir){scriptDirectory=_scriptDir}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=url=>{try{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText}catch(err){var data=tryParseAsDataURI(url);if(data){return intArrayToString(data)}throw err}};if(ENVIRONMENT_IS_WORKER){readBinary=url=>{try{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}catch(err){var data=tryParseAsDataURI(url);if(data){return data}throw err}}}readAsync=(url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}var data=tryParseAsDataURI(url);if(data){onload(data.buffer);return}onerror()};xhr.onerror=onerror;xhr.send(null)}}setWindowTitle=title=>document.title=title}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;var WebAssembly={Memory:function(opts){this.buffer=new ArrayBuffer(opts["initial"]*65536)},Module:function(binary){},Instance:function(module,info){this.exports=( +// EMSCRIPTEN_START_ASM +function instantiate(ia){function c(d){d.set=function(a,b){this[a]=b};d.get=function(a){return this[a]};return d}var e;var f=new Uint8Array(123);for(var a=25;a>=0;--a){f[48+a]=52+a;f[65+a]=a;f[97+a]=26+a}f[43]=62;f[47]=63;function l(m,n,o){var g,h,a=0,i=n,j=o.length,k=n+(j*3>>2)-(o[j-2]=="=")-(o[j-1]=="=");for(;a>4;if(i>2;if(i>2];o=F[c+12>>2];g=F[c+16>>2];a:{if((e|0)>=(o|0)&g>>>0>=I[c+8>>2]|(e|0)>(o|0)){break a}o=G[g+F[c>>2]|0];g=g+1|0;e=g?e:e+1|0;F[c+16>>2]=g;F[c+20>>2]=e;b:{switch(o|0){case 0:e=a;f=b;g=d;a=0;d=0;j=Z+-64|0;Z=j;F[j+56>>2]=0;F[j+48>>2]=0;F[j+52>>2]=0;F[j+40>>2]=0;F[j+44>>2]=0;F[j+32>>2]=0;F[j+36>>2]=0;F[j+24>>2]=0;F[j+28>>2]=0;F[j+16>>2]=0;F[j+20>>2]=0;F[j+8>>2]=0;F[j+12>>2]=0;c:{if(!Nd(j+8|0,c)){break c}if(!Md(j+8|0,c)|(F[j+20>>2]?0:e)){break c}hc(c,0,0);if(e){s=f<<2;t=F[j+36>>2];u=F[j+48>>2];x=F[j+24>>2];l=F[j+56>>2];i=F[j+52>>2];while(1){d:{if(l>>>0>16383){break d}while(1){if((i|0)<=0){break d}i=i-1|0;F[j+52>>2]=i;l=G[i+u|0]|l<<8;F[j+56>>2]=l;if(l>>>0<16384){continue}break}}a=l&4095;r=F[(a<<2)+x>>2];b=(r<<3)+t|0;l=(L(F[b>>2],l>>>12|0)+a|0)-F[b+4>>2]|0;F[j+56>>2]=l;if((f|0)>0){a=0;if(!G[c+36|0]|r>>>0>32){break c}o=d+f|0;e:{if(!r){ma(g+(d<<2)|0,0,s);break e}y=r&-2;z=r&1;b=F[c+32>>2];h=F[c+28>>2];q=F[c+24>>2];while(1){k=0;a=b;m=0;n=0;if((r|0)!=1){while(1){p=q+(a>>>3|0)|0;f:{if(p>>>0>=h>>>0){p=0;break f}p=G[p|0];b=a+1|0;F[c+32>>2]=b;p=p>>>(a&7)&1;a=b}p=p<>>3|0)|0;if(v>>>0>>0){m=G[v|0];b=a+1|0;F[c+32>>2]=b;m=m>>>(a&7)&1;a=b}v=k|1;k=k+2|0;m=p|m<>>3|0)|0;if(p>>>0>>0){p=G[p|0];b=a+1|0;F[c+32>>2]=b;a=p>>>(a&7)&1}else{a=0}m=a<>2]=m;d=d+1|0;if((o|0)!=(d|0)){continue}break}}d=o}w=f+w|0;if(e>>>0>w>>>0){continue}break}}D[c+36|0]=0;f=F[c+20>>2];a=0;m=F[c+32>>2]+7|0;a=m>>>0<7?1:a;m=a<<29|m>>>3;b=m+F[c+16>>2]|0;a=(a>>>3|0)+f|0;F[c+16>>2]=b;F[c+20>>2]=b>>>0>>0?a+1|0:a;a=1}b=F[j+36>>2];if(b){F[j+40>>2]=b;ja(b)}b=F[j+24>>2];if(b){F[j+28>>2]=b;ja(b)}b=F[j+8>>2];if(b){F[j+12>>2]=b;ja(b)}Z=j- -64|0;return a;case 1:break b;default:break a}}b=0;e=F[c+20>>2];o=F[c+12>>2];g=F[c+16>>2];g:{if((e|0)>=(o|0)&g>>>0>=I[c+8>>2]|(e|0)>(o|0)){break g}o=G[g+F[c>>2]|0];g=g+1|0;e=g?e:e+1|0;F[c+16>>2]=g;F[c+20>>2]=e;h:{switch(o-1|0){case 8:o=a;r=d;e=Z+-64|0;Z=e;F[e+56>>2]=0;F[e+48>>2]=0;F[e+52>>2]=0;F[e+40>>2]=0;F[e+44>>2]=0;F[e+32>>2]=0;F[e+36>>2]=0;F[e+24>>2]=0;F[e+28>>2]=0;F[e+16>>2]=0;F[e+20>>2]=0;F[e+8>>2]=0;F[e+12>>2]=0;h=e+8|0;i:{j:{if(!H[c+38>>1]){break j}if(!Ta(1,h+12|0,c)){break j}b=F[c+8>>2];d=F[c+16>>2];f=b-d|0;i=F[h+12>>2];b=F[c+12>>2]-(F[c+20>>2]+(b>>>0>>0)|0)|0;if(f>>>0>>6>>>0&(b|0)<=0|(b|0)<0){break j}b=F[h>>2];a=F[h+4>>2]-b>>2;k:{if(a>>>0>>0){qa(h,i-a|0);i=F[h+12>>2];break k}if(a>>>0<=i>>>0){break k}F[h+4>>2]=b+(i<<2)}g=1;if(!i){break i}f=F[c+16>>2];d=F[c+20>>2];s=F[h>>2];j=F[c+8>>2];n=F[c+12>>2];b=0;while(1){g=0;if((d|0)>=(n|0)&f>>>0>=j>>>0|(d|0)>(n|0)){break i}g=F[c>>2];p=G[g+f|0];a=d;f=f+1|0;a=f?a:a+1|0;F[c+16>>2]=f;d=a;F[c+20>>2]=a;a=p>>>2|0;l=0;l:{m:{n:{o:{t=p&3;switch(t|0){case 0:break m;case 3:break o;default:break n}}a=a+b|0;g=0;if(a>>>0>=i>>>0){break i}ma(s+(b<<2)|0,0,(p&252)+4|0);b=a;break l}while(1){if((f|0)==(j|0)&(d|0)==(n|0)){break j}i=G[f+g|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;a=i<<(l<<3|6)|a;l=l+1|0;if((t|0)!=(l|0)){continue}break}}F[s+(b<<2)>>2]=a}b=b+1|0;i=F[h+12>>2];if(b>>>0>>0){continue}break}a=h+16|0;n=F[h>>2];d=F[h+16>>2];b=F[h+20>>2]-d|0;p:{if(b>>>0<=32767){qa(a,8192-(b>>>2|0)|0);break p}if((b|0)==32768){break p}F[h+20>>2]=d+32768}d=h+28|0;b=F[d>>2];f=F[h+32>>2]-b>>3;q:{if(f>>>0>>0){_a(d,i-f|0);b=F[d>>2];break q}if(f>>>0>i>>>0){F[h+32>>2]=(i<<3)+b}if(!i){break j}}j=F[a>>2];f=0;d=0;while(1){g=n+(f<<2)|0;l=F[g>>2];h=(f<<3)+b|0;a=d;F[h+4>>2]=a;F[h>>2]=l;g=F[g>>2];d=g+a|0;if(d>>>0>8192){break j}r:{if(a>>>0>=d>>>0){break r}l=0;h=g&7;if(h){while(1){F[j+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((h|0)!=(l|0)){continue}break}}if(g-1>>>0<=6){break r}while(1){g=j+(a<<2)|0;F[g>>2]=f;F[g+28>>2]=f;F[g+24>>2]=f;F[g+20>>2]=f;F[g+16>>2]=f;F[g+12>>2]=f;F[g+8>>2]=f;F[g+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((i|0)!=(f|0)){continue}break}k=(d|0)==8192}g=k}s:{if(!g|(F[e+20>>2]?0:o)){break s}d=0;k=Z-16|0;Z=k;t:{if(!Sa(1,k+8|0,c)){break t}a=F[c+8>>2];f=F[c+16>>2];g=a-f|0;j=F[k+12>>2];i=F[c+20>>2];a=F[c+12>>2]-(i+(a>>>0>>0)|0)|0;b=F[k+8>>2];if((j|0)==(a|0)&g>>>0>>0|a>>>0>>0){break t}a=i+j|0;g=b+f|0;a=g>>>0>>0?a+1|0:a;F[c+16>>2]=g;F[c+20>>2]=a;if((b|0)<=0){break t}a=f+F[c>>2]|0;F[e+48>>2]=a;c=b-1|0;f=c+a|0;g=G[f|0];u:{if(g>>>0<=63){F[e+52>>2]=c;a=G[f|0]&63;break u}v:{switch((g>>>6|0)-1|0){case 0:if(b>>>0<2){break t}b=b-2|0;F[e+52>>2]=b;a=a+b|0;a=G[a+1|0]<<8&16128|G[a|0];break u;case 1:if(b>>>0<3){break t}b=b-3|0;F[e+52>>2]=b;a=a+b|0;a=G[a+1|0]<<8|G[a+2|0]<<16&4128768|G[a|0];break u;default:break v}}b=b-4|0;F[e+52>>2]=b;a=a+b|0;a=(G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24))&1073741823}F[e+56>>2]=a+32768;d=a>>>0<8355840}Z=k+16|0;if(!d){break s}if(!o){m=1;break s}b=F[e+52>>2];a=F[e+56>>2];c=F[e+36>>2];d=F[e+48>>2];f=F[e+24>>2];while(1){w:{if(a>>>0>32767){break w}while(1){if((b|0)<=0){break w}b=b-1|0;F[e+52>>2]=b;a=G[b+d|0]|a<<8;F[e+56>>2]=a;if(a>>>0<32768){continue}break}}m=a&8191;k=F[f+(m<<2)>>2];g=c+(k<<3)|0;a=(L(F[g>>2],a>>>13|0)+m|0)-F[g+4>>2]|0;F[e+56>>2]=a;F[r+(q<<2)>>2]=k;m=1;q=q+1|0;if((o|0)!=(q|0)){continue}break}}a=F[e+36>>2];if(a){F[e+40>>2]=a;ja(a)}a=F[e+24>>2];if(a){F[e+28>>2]=a;ja(a)}a=F[e+8>>2];if(a){F[e+12>>2]=a;ja(a)}Z=e- -64|0;b=m;break g;case 9:o=a;r=d;g=Z+-64|0;Z=g;F[g+56>>2]=0;F[g+48>>2]=0;F[g+52>>2]=0;F[g+40>>2]=0;F[g+44>>2]=0;F[g+32>>2]=0;F[g+36>>2]=0;F[g+24>>2]=0;F[g+28>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;F[g+8>>2]=0;F[g+12>>2]=0;h=g+8|0;x:{y:{if(!H[c+38>>1]){break y}if(!Ta(1,h+12|0,c)){break y}b=F[c+8>>2];d=F[c+16>>2];f=b-d|0;i=F[h+12>>2];b=F[c+12>>2]-(F[c+20>>2]+(b>>>0>>0)|0)|0;if(f>>>0>>6>>>0&(b|0)<=0|(b|0)<0){break y}b=F[h>>2];a=F[h+4>>2]-b>>2;z:{if(a>>>0>>0){qa(h,i-a|0);i=F[h+12>>2];break z}if(a>>>0<=i>>>0){break z}F[h+4>>2]=b+(i<<2)}e=1;if(!i){break x}f=F[c+16>>2];d=F[c+20>>2];s=F[h>>2];j=F[c+8>>2];n=F[c+12>>2];b=0;while(1){e=0;if((d|0)>=(n|0)&f>>>0>=j>>>0|(d|0)>(n|0)){break x}t=F[c>>2];p=G[t+f|0];e=d;f=f+1|0;e=f?e:e+1|0;F[c+16>>2]=f;d=e;F[c+20>>2]=e;a=p>>>2|0;l=0;A:{B:{C:{D:{e=p&3;switch(e|0){case 0:break B;case 3:break D;default:break C}}a=a+b|0;e=0;if(a>>>0>=i>>>0){break x}ma(s+(b<<2)|0,0,(p&252)+4|0);b=a;break A}while(1){if((f|0)==(j|0)&(d|0)==(n|0)){break y}i=G[f+t|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;a=i<<(l<<3|6)|a;l=l+1|0;if((e|0)!=(l|0)){continue}break}}F[s+(b<<2)>>2]=a}b=b+1|0;i=F[h+12>>2];if(b>>>0>>0){continue}break}a=h+16|0;n=F[h>>2];d=F[h+16>>2];b=F[h+20>>2]-d|0;E:{if(b>>>0<=131071){qa(a,32768-(b>>>2|0)|0);break E}if((b|0)==131072){break E}F[h+20>>2]=d+131072}d=h+28|0;b=F[d>>2];f=F[h+32>>2]-b>>3;F:{if(f>>>0>>0){_a(d,i-f|0);b=F[d>>2];break F}if(f>>>0>i>>>0){F[h+32>>2]=(i<<3)+b}if(!i){break y}}j=F[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;l=F[e>>2];h=(f<<3)+b|0;a=d;F[h+4>>2]=a;F[h>>2]=l;e=F[e>>2];d=e+a|0;if(d>>>0>32768){break y}G:{if(a>>>0>=d>>>0){break G}l=0;h=e&7;if(h){while(1){F[j+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((h|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break G}while(1){e=j+(a<<2)|0;F[e>>2]=f;F[e+28>>2]=f;F[e+24>>2]=f;F[e+20>>2]=f;F[e+16>>2]=f;F[e+12>>2]=f;F[e+8>>2]=f;F[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((i|0)!=(f|0)){continue}break}k=(d|0)==32768}e=k}H:{if(!e|(F[g+20>>2]?0:o)){break H}d=0;f=Z-16|0;Z=f;I:{if(!Sa(1,f+8|0,c)){break I}e=F[c+8>>2];b=F[c+16>>2];k=e-b|0;j=F[f+12>>2];i=F[c+20>>2];e=F[c+12>>2]-(i+(b>>>0>e>>>0)|0)|0;a=F[f+8>>2];if((j|0)==(e|0)&k>>>0>>0|e>>>0>>0){break I}e=i+j|0;k=a+b|0;e=k>>>0>>0?e+1|0:e;F[c+16>>2]=k;F[c+20>>2]=e;if((a|0)<=0){break I}b=b+F[c>>2]|0;F[g+48>>2]=b;c=a-1|0;e=c+b|0;k=G[e|0];J:{if(k>>>0<=63){F[g+52>>2]=c;a=G[e|0]&63;break J}K:{switch((k>>>6|0)-1|0){case 0:if(a>>>0<2){break I}a=a-2|0;F[g+52>>2]=a;a=a+b|0;a=G[a+1|0]<<8&16128|G[a|0];break J;case 1:if(a>>>0<3){break I}a=a-3|0;F[g+52>>2]=a;a=a+b|0;a=G[a+1|0]<<8|G[a+2|0]<<16&4128768|G[a|0];break J;default:break K}}a=a-4|0;F[g+52>>2]=a;a=a+b|0;a=(G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24))&1073741823}F[g+56>>2]=a+131072;d=a>>>0<33423360}Z=f+16|0;if(!d){break H}if(!o){m=1;break H}b=F[g+52>>2];a=F[g+56>>2];c=F[g+36>>2];d=F[g+48>>2];f=F[g+24>>2];while(1){L:{if(a>>>0>131071){break L}while(1){if((b|0)<=0){break L}b=b-1|0;F[g+52>>2]=b;a=G[b+d|0]|a<<8;F[g+56>>2]=a;if(a>>>0<131072){continue}break}}m=a&32767;e=F[f+(m<<2)>>2];k=c+(e<<3)|0;a=(L(F[k>>2],a>>>15|0)+m|0)-F[k+4>>2]|0;F[g+56>>2]=a;F[r+(q<<2)>>2]=e;m=1;q=q+1|0;if((o|0)!=(q|0)){continue}break}}a=F[g+36>>2];if(a){F[g+40>>2]=a;ja(a)}a=F[g+24>>2];if(a){F[g+28>>2]=a;ja(a)}a=F[g+8>>2];if(a){F[g+12>>2]=a;ja(a)}Z=g- -64|0;b=m;break g;case 10:o=a;r=d;g=Z+-64|0;Z=g;F[g+56>>2]=0;F[g+48>>2]=0;F[g+52>>2]=0;F[g+40>>2]=0;F[g+44>>2]=0;F[g+32>>2]=0;F[g+36>>2]=0;F[g+24>>2]=0;F[g+28>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;F[g+8>>2]=0;F[g+12>>2]=0;h=g+8|0;M:{N:{if(!H[c+38>>1]){break N}if(!Ta(1,h+12|0,c)){break N}b=F[c+8>>2];d=F[c+16>>2];f=b-d|0;i=F[h+12>>2];b=F[c+12>>2]-(F[c+20>>2]+(b>>>0>>0)|0)|0;if(f>>>0>>6>>>0&(b|0)<=0|(b|0)<0){break N}b=F[h>>2];a=F[h+4>>2]-b>>2;O:{if(a>>>0>>0){qa(h,i-a|0);i=F[h+12>>2];break O}if(a>>>0<=i>>>0){break O}F[h+4>>2]=b+(i<<2)}e=1;if(!i){break M}f=F[c+16>>2];d=F[c+20>>2];s=F[h>>2];j=F[c+8>>2];n=F[c+12>>2];b=0;while(1){e=0;if((d|0)>=(n|0)&f>>>0>=j>>>0|(d|0)>(n|0)){break M}t=F[c>>2];p=G[t+f|0];a=d;f=f+1|0;a=f?a:a+1|0;F[c+16>>2]=f;d=a;F[c+20>>2]=a;a=p>>>2|0;l=0;P:{Q:{R:{S:{u=p&3;switch(u|0){case 0:break Q;case 3:break S;default:break R}}a=a+b|0;e=0;if(a>>>0>=i>>>0){break M}ma(s+(b<<2)|0,0,(p&252)+4|0);b=a;break P}while(1){if((f|0)==(j|0)&(d|0)==(n|0)){break N}i=G[f+t|0];e=d;f=f+1|0;e=f?e:e+1|0;F[c+16>>2]=f;d=e;F[c+20>>2]=e;a=i<<(l<<3|6)|a;l=l+1|0;if((u|0)!=(l|0)){continue}break}}F[s+(b<<2)>>2]=a}b=b+1|0;i=F[h+12>>2];if(b>>>0>>0){continue}break}a=h+16|0;n=F[h>>2];d=F[h+16>>2];b=F[h+20>>2]-d|0;T:{if(b>>>0<=262143){qa(a,65536-(b>>>2|0)|0);break T}if((b|0)==262144){break T}F[h+20>>2]=d+262144}d=h+28|0;b=F[d>>2];f=F[h+32>>2]-b>>3;U:{if(f>>>0>>0){_a(d,i-f|0);b=F[d>>2];break U}if(f>>>0>i>>>0){F[h+32>>2]=(i<<3)+b}if(!i){break N}}j=F[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;l=F[e>>2];h=(f<<3)+b|0;a=d;F[h+4>>2]=a;F[h>>2]=l;e=F[e>>2];d=e+a|0;if(d>>>0>65536){break N}V:{if(a>>>0>=d>>>0){break V}l=0;h=e&7;if(h){while(1){F[j+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((h|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break V}while(1){e=j+(a<<2)|0;F[e>>2]=f;F[e+28>>2]=f;F[e+24>>2]=f;F[e+20>>2]=f;F[e+16>>2]=f;F[e+12>>2]=f;F[e+8>>2]=f;F[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((i|0)!=(f|0)){continue}break}k=(d|0)==65536}e=k}W:{if(!e|(F[g+20>>2]?0:o)){break W}d=0;e=Z-16|0;Z=e;X:{if(!Sa(1,e+8|0,c)){break X}a=F[c+8>>2];f=F[c+16>>2];k=a-f|0;j=F[e+12>>2];i=F[c+20>>2];a=F[c+12>>2]-(i+(a>>>0>>0)|0)|0;b=F[e+8>>2];if((j|0)==(a|0)&k>>>0>>0|a>>>0>>0){break X}a=i+j|0;k=b+f|0;a=k>>>0>>0?a+1|0:a;F[c+16>>2]=k;F[c+20>>2]=a;if((b|0)<=0){break X}a=f+F[c>>2]|0;F[g+48>>2]=a;c=b-1|0;f=c+a|0;k=G[f|0];Y:{if(k>>>0<=63){F[g+52>>2]=c;a=G[f|0]&63;break Y}Z:{switch((k>>>6|0)-1|0){case 0:if(b>>>0<2){break X}b=b-2|0;F[g+52>>2]=b;a=a+b|0;a=G[a+1|0]<<8&16128|G[a|0];break Y;case 1:if(b>>>0<3){break X}b=b-3|0;F[g+52>>2]=b;a=a+b|0;a=G[a+1|0]<<8|G[a+2|0]<<16&4128768|G[a|0];break Y;default:break Z}}b=b-4|0;F[g+52>>2]=b;a=a+b|0;a=(G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24))&1073741823}F[g+56>>2]=a+262144;d=a>>>0<66846720}Z=e+16|0;if(!d){break W}if(!o){m=1;break W}b=F[g+52>>2];a=F[g+56>>2];c=F[g+36>>2];d=F[g+48>>2];f=F[g+24>>2];while(1){_:{if(a>>>0>262143){break _}while(1){if((b|0)<=0){break _}b=b-1|0;F[g+52>>2]=b;a=G[b+d|0]|a<<8;F[g+56>>2]=a;if(a>>>0<262144){continue}break}}m=a&65535;e=F[f+(m<<2)>>2];k=c+(e<<3)|0;a=(L(F[k>>2],a>>>16|0)+m|0)-F[k+4>>2]|0;F[g+56>>2]=a;F[r+(q<<2)>>2]=e;m=1;q=q+1|0;if((o|0)!=(q|0)){continue}break}}a=F[g+36>>2];if(a){F[g+40>>2]=a;ja(a)}a=F[g+24>>2];if(a){F[g+28>>2]=a;ja(a)}a=F[g+8>>2];if(a){F[g+12>>2]=a;ja(a)}Z=g- -64|0;b=m;break g;case 11:o=a;r=d;g=Z+-64|0;Z=g;F[g+56>>2]=0;F[g+48>>2]=0;F[g+52>>2]=0;F[g+40>>2]=0;F[g+44>>2]=0;F[g+32>>2]=0;F[g+36>>2]=0;F[g+24>>2]=0;F[g+28>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;F[g+8>>2]=0;F[g+12>>2]=0;h=g+8|0;$:{aa:{if(!H[c+38>>1]){break aa}if(!Ta(1,h+12|0,c)){break aa}b=F[c+8>>2];d=F[c+16>>2];f=b-d|0;i=F[h+12>>2];b=F[c+12>>2]-(F[c+20>>2]+(b>>>0>>0)|0)|0;if(f>>>0>>6>>>0&(b|0)<=0|(b|0)<0){break aa}b=F[h>>2];a=F[h+4>>2]-b>>2;ba:{if(a>>>0>>0){qa(h,i-a|0);i=F[h+12>>2];break ba}if(a>>>0<=i>>>0){break ba}F[h+4>>2]=b+(i<<2)}e=1;if(!i){break $}f=F[c+16>>2];d=F[c+20>>2];s=F[h>>2];j=F[c+8>>2];n=F[c+12>>2];b=0;while(1){e=0;if((d|0)>=(n|0)&f>>>0>=j>>>0|(d|0)>(n|0)){break $}t=F[c>>2];p=G[t+f|0];e=d;f=f+1|0;e=f?e:e+1|0;F[c+16>>2]=f;d=e;F[c+20>>2]=e;a=p>>>2|0;l=0;ca:{da:{ea:{fa:{e=p&3;switch(e|0){case 0:break da;case 3:break fa;default:break ea}}a=a+b|0;e=0;if(a>>>0>=i>>>0){break $}ma(s+(b<<2)|0,0,(p&252)+4|0);b=a;break ca}while(1){if((f|0)==(j|0)&(d|0)==(n|0)){break aa}i=G[f+t|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;a=i<<(l<<3|6)|a;l=l+1|0;if((e|0)!=(l|0)){continue}break}}F[s+(b<<2)>>2]=a}b=b+1|0;i=F[h+12>>2];if(b>>>0>>0){continue}break}a=h+16|0;n=F[h>>2];d=F[h+16>>2];b=F[h+20>>2]-d|0;ga:{if(b>>>0<=1048575){qa(a,262144-(b>>>2|0)|0);break ga}if((b|0)==1048576){break ga}F[h+20>>2]=d- -1048576}d=h+28|0;b=F[d>>2];f=F[h+32>>2]-b>>3;ha:{if(f>>>0>>0){_a(d,i-f|0);b=F[d>>2];break ha}if(f>>>0>i>>>0){F[h+32>>2]=(i<<3)+b}if(!i){break aa}}j=F[a>>2];f=0;d=0;while(1){e=n+(f<<2)|0;l=F[e>>2];h=(f<<3)+b|0;a=d;F[h+4>>2]=a;F[h>>2]=l;e=F[e>>2];d=e+a|0;if(d>>>0>262144){break aa}ia:{if(a>>>0>=d>>>0){break ia}l=0;h=e&7;if(h){while(1){F[j+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((h|0)!=(l|0)){continue}break}}if(e-1>>>0<=6){break ia}while(1){e=j+(a<<2)|0;F[e>>2]=f;F[e+28>>2]=f;F[e+24>>2]=f;F[e+20>>2]=f;F[e+16>>2]=f;F[e+12>>2]=f;F[e+8>>2]=f;F[e+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((i|0)!=(f|0)){continue}break}k=(d|0)==262144}e=k}ja:{if(!e|(F[g+20>>2]?0:o)){break ja}d=0;f=Z-16|0;Z=f;ka:{if(!Sa(1,f+8|0,c)){break ka}e=F[c+8>>2];b=F[c+16>>2];k=e-b|0;j=F[f+12>>2];i=F[c+20>>2];e=F[c+12>>2]-(i+(b>>>0>e>>>0)|0)|0;a=F[f+8>>2];if((j|0)==(e|0)&k>>>0>>0|e>>>0>>0){break ka}e=i+j|0;k=a+b|0;e=k>>>0>>0?e+1|0:e;F[c+16>>2]=k;F[c+20>>2]=e;if((a|0)<=0){break ka}b=b+F[c>>2]|0;F[g+48>>2]=b;c=a-1|0;e=c+b|0;k=G[e|0];la:{if(k>>>0<=63){F[g+52>>2]=c;a=G[e|0]&63;break la}ma:{switch((k>>>6|0)-1|0){case 0:if(a>>>0<2){break ka}a=a-2|0;F[g+52>>2]=a;a=a+b|0;a=G[a+1|0]<<8&16128|G[a|0];break la;case 1:if(a>>>0<3){break ka}a=a-3|0;F[g+52>>2]=a;a=a+b|0;a=G[a+1|0]<<8|G[a+2|0]<<16&4128768|G[a|0];break la;default:break ma}}a=a-4|0;F[g+52>>2]=a;a=a+b|0;a=(G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24))&1073741823}F[g+56>>2]=a- -1048576;d=a>>>0<267386880}Z=f+16|0;if(!d){break ja}if(!o){m=1;break ja}b=F[g+52>>2];a=F[g+56>>2];c=F[g+36>>2];d=F[g+48>>2];f=F[g+24>>2];while(1){na:{if(a>>>0>1048575){break na}while(1){if((b|0)<=0){break na}b=b-1|0;F[g+52>>2]=b;a=G[b+d|0]|a<<8;F[g+56>>2]=a;if(a>>>0<1048576){continue}break}}m=a&262143;e=F[f+(m<<2)>>2];k=c+(e<<3)|0;a=(L(F[k>>2],a>>>18|0)+m|0)-F[k+4>>2]|0;F[g+56>>2]=a;F[r+(q<<2)>>2]=e;m=1;q=q+1|0;if((o|0)!=(q|0)){continue}break}}a=F[g+36>>2];if(a){F[g+40>>2]=a;ja(a)}a=F[g+24>>2];if(a){F[g+28>>2]=a;ja(a)}a=F[g+8>>2];if(a){F[g+12>>2]=a;ja(a)}Z=g- -64|0;b=m;break g;case 12:o=a;r=d;e=Z+-64|0;Z=e;F[e+56>>2]=0;F[e+48>>2]=0;F[e+52>>2]=0;F[e+40>>2]=0;F[e+44>>2]=0;F[e+32>>2]=0;F[e+36>>2]=0;F[e+24>>2]=0;F[e+28>>2]=0;F[e+16>>2]=0;F[e+20>>2]=0;F[e+8>>2]=0;F[e+12>>2]=0;h=e+8|0;oa:{pa:{if(!H[c+38>>1]){break pa}if(!Ta(1,h+12|0,c)){break pa}b=F[c+8>>2];d=F[c+16>>2];f=b-d|0;i=F[h+12>>2];b=F[c+12>>2]-(F[c+20>>2]+(b>>>0>>0)|0)|0;if(f>>>0>>6>>>0&(b|0)<=0|(b|0)<0){break pa}b=F[h>>2];a=F[h+4>>2]-b>>2;qa:{if(a>>>0>>0){qa(h,i-a|0);i=F[h+12>>2];break qa}if(a>>>0<=i>>>0){break qa}F[h+4>>2]=b+(i<<2)}g=1;if(!i){break oa}f=F[c+16>>2];d=F[c+20>>2];s=F[h>>2];j=F[c+8>>2];n=F[c+12>>2];b=0;while(1){g=0;if((d|0)>=(n|0)&f>>>0>=j>>>0|(d|0)>(n|0)){break oa}g=F[c>>2];p=G[g+f|0];a=d;f=f+1|0;a=f?a:a+1|0;F[c+16>>2]=f;d=a;F[c+20>>2]=a;a=p>>>2|0;l=0;ra:{sa:{ta:{ua:{t=p&3;switch(t|0){case 0:break sa;case 3:break ua;default:break ta}}a=a+b|0;g=0;if(a>>>0>=i>>>0){break oa}ma(s+(b<<2)|0,0,(p&252)+4|0);b=a;break ra}while(1){if((f|0)==(j|0)&(d|0)==(n|0)){break pa}i=G[f+g|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;a=i<<(l<<3|6)|a;l=l+1|0;if((t|0)!=(l|0)){continue}break}}F[s+(b<<2)>>2]=a}b=b+1|0;i=F[h+12>>2];if(b>>>0>>0){continue}break}a=h+16|0;n=F[h>>2];d=F[h+16>>2];b=F[h+20>>2]-d|0;va:{if(b>>>0<=2097151){qa(a,524288-(b>>>2|0)|0);break va}if((b|0)==2097152){break va}F[h+20>>2]=d+2097152}d=h+28|0;b=F[d>>2];f=F[h+32>>2]-b>>3;wa:{if(f>>>0>>0){_a(d,i-f|0);b=F[d>>2];break wa}if(f>>>0>i>>>0){F[h+32>>2]=(i<<3)+b}if(!i){break pa}}j=F[a>>2];f=0;d=0;while(1){g=n+(f<<2)|0;l=F[g>>2];h=(f<<3)+b|0;a=d;F[h+4>>2]=a;F[h>>2]=l;g=F[g>>2];d=g+a|0;if(d>>>0>524288){break pa}xa:{if(a>>>0>=d>>>0){break xa}l=0;h=g&7;if(h){while(1){F[j+(a<<2)>>2]=f;a=a+1|0;l=l+1|0;if((h|0)!=(l|0)){continue}break}}if(g-1>>>0<=6){break xa}while(1){g=j+(a<<2)|0;F[g>>2]=f;F[g+28>>2]=f;F[g+24>>2]=f;F[g+20>>2]=f;F[g+16>>2]=f;F[g+12>>2]=f;F[g+8>>2]=f;F[g+4>>2]=f;a=a+8|0;if((d|0)!=(a|0)){continue}break}}f=f+1|0;if((i|0)!=(f|0)){continue}break}k=(d|0)==524288}g=k}ya:{if(!g|(F[e+20>>2]?0:o)){break ya}d=0;k=Z-16|0;Z=k;za:{if(!Sa(1,k+8|0,c)){break za}a=F[c+8>>2];f=F[c+16>>2];g=a-f|0;j=F[k+12>>2];i=F[c+20>>2];a=F[c+12>>2]-(i+(a>>>0>>0)|0)|0;b=F[k+8>>2];if((j|0)==(a|0)&g>>>0>>0|a>>>0>>0){break za}a=i+j|0;g=b+f|0;a=g>>>0>>0?a+1|0:a;F[c+16>>2]=g;F[c+20>>2]=a;if((b|0)<=0){break za}a=f+F[c>>2]|0;F[e+48>>2]=a;c=b-1|0;f=c+a|0;g=G[f|0];Aa:{if(g>>>0<=63){F[e+52>>2]=c;a=G[f|0]&63;break Aa}Ba:{switch((g>>>6|0)-1|0){case 0:if(b>>>0<2){break za}b=b-2|0;F[e+52>>2]=b;a=a+b|0;a=G[a+1|0]<<8&16128|G[a|0];break Aa;case 1:if(b>>>0<3){break za}b=b-3|0;F[e+52>>2]=b;a=a+b|0;a=G[a+1|0]<<8|G[a+2|0]<<16&4128768|G[a|0];break Aa;default:break Ba}}b=b-4|0;F[e+52>>2]=b;a=a+b|0;a=(G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24))&1073741823}F[e+56>>2]=a+2097152;d=a>>>0<534773760}Z=k+16|0;if(!d){break ya}if(!o){m=1;break ya}b=F[e+52>>2];a=F[e+56>>2];c=F[e+36>>2];d=F[e+48>>2];f=F[e+24>>2];while(1){Ca:{if(a>>>0>2097151){break Ca}while(1){if((b|0)<=0){break Ca}b=b-1|0;F[e+52>>2]=b;a=G[b+d|0]|a<<8;F[e+56>>2]=a;if(a>>>0<2097152){continue}break}}m=a&524287;k=F[f+(m<<2)>>2];g=c+(k<<3)|0;a=(L(F[g>>2],a>>>19|0)+m|0)-F[g+4>>2]|0;F[e+56>>2]=a;F[r+(q<<2)>>2]=k;m=1;q=q+1|0;if((o|0)!=(q|0)){continue}break}}a=F[e+36>>2];if(a){F[e+40>>2]=a;ja(a)}a=F[e+24>>2];if(a){F[e+28>>2]=a;ja(a)}a=F[e+8>>2];if(a){F[e+12>>2]=a;ja(a)}Z=e- -64|0;b=m;break g;case 17:b=Ld(a,c,d);break g;case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:b=Z+-64|0;Z=b;F[b+56>>2]=0;F[b+48>>2]=0;F[b+52>>2]=0;F[b+40>>2]=0;F[b+44>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;F[b+24>>2]=0;F[b+28>>2]=0;F[b+16>>2]=0;F[b+20>>2]=0;F[b+8>>2]=0;F[b+12>>2]=0;Da:{if(!Nd(b+8|0,c)|(F[b+20>>2]?0:a)){break Da}if(!Md(b+8|0,c)){break Da}if(!a){f=1;break Da}m=F[b+52>>2];c=F[b+56>>2];e=F[b+36>>2];g=F[b+48>>2];o=F[b+24>>2];while(1){Ea:{if(c>>>0>16383){break Ea}while(1){if((m|0)<=0){break Ea}m=m-1|0;F[b+52>>2]=m;c=G[g+m|0]|c<<8;F[b+56>>2]=c;if(c>>>0<16384){continue}break}}f=c&4095;j=F[o+(f<<2)>>2];r=e+(j<<3)|0;c=(L(F[r>>2],c>>>12|0)+f|0)-F[r+4>>2]|0;F[b+56>>2]=c;F[(k<<2)+d>>2]=j;f=1;k=k+1|0;if((k|0)!=(a|0)){continue}break}}a=F[b+36>>2];if(a){F[b+40>>2]=a;ja(a)}a=F[b+24>>2];if(a){F[b+28>>2]=a;ja(a)}a=F[b+8>>2];if(a){F[b+12>>2]=a;ja(a)}Z=b- -64|0;b=f;break g;case 13:case 14:case 15:case 16:break h;default:break g}}b=Ld(a,c,d)}f=b}return f}function ih(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,J=0,K=0,M=0,N=0,O=0,P=0;u=Z+-64|0;Z=u;F[a+132>>2]=0;if(F[a+148>>2]){b=F[a+144>>2];if(b){while(1){f=F[b>>2];ja(b);b=f;if(b){continue}break}}b=0;F[a+144>>2]=0;f=F[a+140>>2];a:{if(!f){break a}if(f>>>0>=4){c=f&-4;while(1){e=b<<2;F[e+F[a+136>>2]>>2]=0;F[F[a+136>>2]+(e|4)>>2]=0;F[F[a+136>>2]+(e|8)>>2]=0;F[F[a+136>>2]+(e|12)>>2]=0;b=b+4|0;d=d+4|0;if((c|0)!=(d|0)){continue}break}}f=f&3;if(!f){break a}d=0;while(1){F[F[a+136>>2]+(b<<2)>>2]=0;b=b+1|0;d=d+1|0;if((f|0)!=(d|0)){continue}break}}F[a+148>>2]=0}b:{c:{if(!Da(1,u+60|0,F[F[a+4>>2]+32>>2])){break c}F[a+156>>2]=F[u+60>>2];if(!Da(1,u+56|0,F[F[a+4>>2]+32>>2])){break c}e=F[u+56>>2];if(e>>>0>1431655765|I[a+156>>2]>L(e,3)>>>0){break c}b=F[F[a+4>>2]+32>>2];c=F[b+8>>2];k=F[b+12>>2];d=F[b+20>>2];f=F[b+16>>2];if((k|0)<=(d|0)&f>>>0>=c>>>0|(d|0)>(k|0)){break c}k=G[f+F[b>>2]|0];f=f+1|0;d=f?d:d+1|0;F[b+16>>2]=f;F[b+20>>2]=d;if(!Da(1,u+52|0,b)){break c}q=F[u+52>>2];if(q>>>0>e>>>0|e>>>0>q+((q>>>0)/3|0)>>>0){break c}if(!Da(1,u+48|0,F[F[a+4>>2]+32>>2])){break c}d=F[u+48>>2];if(d>>>0>q>>>0){break c}F[a+28>>2]=F[a+24>>2];f=Zb(ka(88));b=F[a+8>>2];F[a+8>>2]=f;if(b){Za(b);if(!F[a+8>>2]){break c}}F[a+164>>2]=F[a+160>>2];Ib(a+160|0,e);F[a+176>>2]=F[a+172>>2];Ib(a+172|0,e);F[a- -64>>2]=0;F[a+92>>2]=-1;F[a+84>>2]=-1;F[a+88>>2]=-1;F[a+40>>2]=F[a+36>>2];F[a+52>>2]=F[a+48>>2];F[a+76>>2]=F[a+72>>2];A=a+216|0;Dd(A);Cd(A,k);if(!_c(F[a+8>>2],e,d+F[a+156>>2]|0)){break c}b=F[a+156>>2];D[u+8|0]=1;Ea(a+120|0,b+d|0,u+8|0);if((Bd(a,F[F[a+4>>2]+32>>2])|0)==-1){break c}c=a+232|0;b=c;F[b+144>>2]=a;f=F[($[F[F[a>>2]+32>>2]](a)|0)+32>>2];f=F[f>>2]+F[f+16>>2]|0;e=F[($[F[F[a>>2]+32>>2]](a)|0)+32>>2];e=F[e+8>>2]-F[e+16>>2]|0;O=b,P=H[F[($[F[F[a>>2]+32>>2]](a)|0)+32>>2]+38>>1],E[O+38>>1]=P;F[b>>2]=f;F[b+16>>2]=0;F[b+20>>2]=0;F[b+8>>2]=e;F[b+12>>2]=0;O=b,P=$[F[F[a>>2]+36>>2]](a)|0,F[O+148>>2]=P;F[a+372>>2]=k;F[a+384>>2]=d+F[a+156>>2];K=Ja(u+8|0);k=K;f=0;j=Z-16|0;Z=j;d:{if(!Aa(b+80|0,b)){break d}if(!yd(c)){break d}b=F[c+4>>2];F[k>>2]=F[c>>2];F[k+4>>2]=b;b=F[c+36>>2];F[k+32>>2]=F[c+32>>2];F[k+36>>2]=b;b=F[c+28>>2];F[k+24>>2]=F[c+24>>2];F[k+28>>2]=b;b=F[c+20>>2];F[k+16>>2]=F[c+16>>2];F[k+20>>2]=b;b=F[c+12>>2];F[k+8>>2]=F[c+8>>2];F[k+12>>2]=b;F[c+176>>2]=2;F[c+180>>2]=7;b=F[c+152>>2];if((b|0)<0){break d}F[j+12>>2]=0;f=2;h=F[c+156>>2];e=F[c+160>>2]-h>>2;e:{if(e>>>0>>0){Fa(c+156|0,b-e|0,j+12|0);f=F[c+176>>2];d=F[c+180>>2];break e}d=7;if(b>>>0>=e>>>0){break e}F[c+160>>2]=h+(b<<2)}e=c+184|0;d=(d-f|0)+1|0;b=F[c+188>>2];f=F[c+184>>2];s=(b-f|0)/12|0;f:{if(d>>>0>s>>>0){h=0;b=d-s|0;o=F[e+8>>2];f=F[e+4>>2];g:{if(b>>>0<=(o-f|0)/12>>>0){if(b){b=L(b,12)-12|0;b=(b-((b>>>0)%12|0)|0)+12|0;f=ma(f,0,b)+b|0}F[e+4>>2]=f;break g}h:{i:{j:{s=F[e>>2];g=(f-s|0)/12|0;d=g+b|0;if(d>>>0<357913942){o=(o-s|0)/12|0;i=o<<1;o=o>>>0>=178956970?357913941:d>>>0>>0?i:d;if(o){if(o>>>0>=357913942){break j}h=ka(L(o,12))}d=L(g,12)+h|0;b=L(b,12)-12|0;g=(b-((b>>>0)%12|0)|0)+12|0;b=ma(d,0,g);g=b+g|0;h=L(o,12)+h|0;if((f|0)==(s|0)){break i}while(1){d=d-12|0;f=f-12|0;F[d>>2]=F[f>>2];F[d+4>>2]=F[f+4>>2];F[d+8>>2]=F[f+8>>2];F[f+8>>2]=0;F[f>>2]=0;F[f+4>>2]=0;if((f|0)!=(s|0)){continue}break}F[e+8>>2]=h;b=F[e+4>>2];F[e+4>>2]=g;f=F[e>>2];F[e>>2]=d;if((b|0)==(f|0)){break h}while(1){d=b-12|0;h=F[d>>2];if(h){F[b-8>>2]=h;ja(h)}b=d;if((f|0)!=(b|0)){continue}break}break h}break b}oa();v()}F[e+8>>2]=h;F[e+4>>2]=g;F[e>>2]=b}if(f){ja(f)}}d=F[c+188>>2];break f}if(d>>>0>=s>>>0){d=b;break f}d=f+L(d,12)|0;if((d|0)!=(b|0)){while(1){f=b-12|0;h=F[f>>2];if(h){F[b-8>>2]=h;ja(h)}b=f;if((d|0)!=(b|0)){continue}break}}F[c+188>>2]=d}s=c+196|0;f=F[c+184>>2];b=(d-f|0)/12|0;o=F[c+196>>2];h=F[c+200>>2]-o>>2;k:{if(b>>>0>h>>>0){qa(s,b-h|0);f=F[c+184>>2];d=F[c+188>>2];break k}if(b>>>0>=h>>>0){break k}F[c+200>>2]=o+(b<<2)}if((d|0)==(f|0)){f=1;break d}b=0;while(1){l:{if(!Da(1,j+8|0,k)){break l}f=F[j+8>>2];d=F[c+148>>2];if(f>>>0>(F[d+4>>2]-F[d>>2]>>2>>>0)/3>>>0){break l}if(f){g=L(b,12);h=g+F[e>>2]|0;d=F[h>>2];o=F[h+4>>2]-d>>2;m:{if(o>>>0>>0){qa(h,f-o|0);d=F[g+F[e>>2]>>2];break m}if(f>>>0>=o>>>0){break m}F[h+4>>2]=(f<<2)+d}mc(f,1,k,d);F[F[s>>2]+(b<<2)>>2]=f}f=1;b=b+1|0;if(b>>>0<(F[c+188>>2]-F[c+184>>2]|0)/12>>>0){continue}break d}break}f=0}Z=j+16|0;n:{if(!f){break n}e=0;c=0;d=0;b=0;k=0;f=0;s=0;o=0;l=Z-96|0;Z=l;F[l+72>>2]=0;F[l+64>>2]=0;F[l+68>>2]=0;F[l+48>>2]=0;F[l+52>>2]=0;F[l+40>>2]=0;F[l+44>>2]=0;F[l+56>>2]=1065353216;F[l+32>>2]=0;F[l+24>>2]=0;F[l+28>>2]=0;j=a;C=F[a+124>>2];o:{p:{q:{r:{s:{if((q|0)<=0){break s}J=j+232|0;M=F[j+216>>2]!=F[j+220>>2];B=1;t:{while(1){h=s;s=h+1|0;u:{v:{w:{g=F[j+404>>2];if((g|0)==-1){F[j+400>>2]=7;break w}a=-1;i=F[j+428>>2]+(g<<2)|0;m=F[i>>2];g=m-1|0;F[i>>2]=g;if((m|0)<=0){break r}g=F[F[F[j+416>>2]+L(F[j+404>>2],12)>>2]+(g<<2)>>2];if(g>>>0>4){break r}i=F[(g<<2)+8896>>2];F[j+400>>2]=i;if(!g){if((b|0)==(c|0)){break r}i=-1;m=F[j+8>>2];B=F[m+24>>2];t=c-4|0;e=F[t>>2];g=-1;x:{if((e|0)==-1){break x}p=e+1|0;p=(p>>>0)%3|0?p:e-2|0;g=-1;if((p|0)==-1){break x}g=F[F[m>>2]+(p<<2)>>2]}n=F[B+(g<<2)>>2];if((n|0)!=-1){i=n+1|0;i=(i>>>0)%3|0?i:n-2|0}if((e|0)!=-1&F[F[m+12>>2]+(e<<2)>>2]!=-1|(e|0)==(i|0)){break r}n=F[m+12>>2];if((i|0)!=-1&F[n+(i<<2)>>2]!=-1){break r}p=L(h,3);h=p+1|0;F[n+(e<<2)>>2]=h;x=h<<2;F[x+n>>2]=e;r=p+2|0;F[n+(i<<2)>>2]=r;w=r<<2;F[w+n>>2]=i;n=-1;h=-1;y:{if((e|0)==-1){break y}z:{if((e>>>0)%3|0){e=e-1|0;break z}e=e+2|0;h=-1;if((e|0)==-1){break y}}h=F[F[m>>2]+(e<<2)>>2]}e=h;A:{if((i|0)==-1){break A}h=i+1|0;h=(h>>>0)%3|0?h:i-2|0;if((h|0)==-1){break A}n=F[F[m>>2]+(h<<2)>>2]}if((e|0)==(g|0)|(g|0)==(n|0)){break r}a=F[m>>2];F[a+(p<<2)>>2]=g;F[a+x>>2]=n;F[a+w>>2]=e;if((e|0)!=-1){F[B+(e<<2)>>2]=r}a=F[j+120>>2]+(g>>>3&536870908)|0;e=F[a>>2];O=a,P=oi(g)&e,F[O>>2]=P;F[t>>2]=p;e=b;kc(J,p);break u}B:{switch(i-1|0){case 2:case 4:if((b|0)==(c|0)){break r}r=c-4|0;e=F[r>>2];i=F[j+8>>2];m=F[i+12>>2];if((e|0)!=-1&F[m+(e<<2)>>2]!=-1){break r}c=L(h,3);n=(g|0)==3;g=c+(n?2:1)|0;t=g<<2;F[t+m>>2]=e;F[m+(e<<2)>>2]=g;Ma(i+24|0,8324);p=F[j+8>>2];m=F[p+24>>2];if(F[p+28>>2]-m>>2>(C|0)){break r}a=F[p>>2];w=a+t|0;p=F[i+28>>2];i=F[i+24>>2];t=(p-i>>2)-1|0;F[w>>2]=t;if((i|0)!=(p|0)){F[m+(t<<2)>>2]=g}g=n?c:c+2|0;w=a+(c+n<<2)|0;C:{if((e|0)==-1){F[a+(g<<2)>>2]=-1;i=-1;break C}D:{E:{F:{if((e>>>0)%3|0){i=e-1|0;break F}i=e+2|0;if((i|0)==-1){break E}}i=F[a+(i<<2)>>2];F[a+(g<<2)>>2]=i;if((i|0)==-1){break D}F[m+(i<<2)>>2]=g;break D}F[a+(g<<2)>>2]=-1}i=e+1|0;e=(i>>>0)%3|0?i:e-2|0;i=-1;if((e|0)==-1){break C}i=F[a+(e<<2)>>2]}F[w>>2]=i;F[r>>2]=c;e=b;break v;case 6:break w;case 0:break B;default:break r}}if((e|0)==(c|0)){break r}f=c-4|0;m=F[f>>2];F[l+68>>2]=f;n=F[l+44>>2];G:{if(!n){break G}g=F[l+40>>2];p=ni(n)>>>0>1;a=h&n+2147483647;H:{if(!p){break H}a=h;if(a>>>0>>0){break H}a=(h>>>0)%(n>>>0)|0}i=a;a=F[g+(i<<2)>>2];if(!a){break G}a=F[a>>2];if(!a){break G}I:{if(!p){g=n-1|0;while(1){n=F[a+4>>2];J:{if((n|0)!=(h|0)){if((i|0)==(g&n)){break J}break G}if((h|0)==F[a+8>>2]){break I}}a=F[a>>2];if(a){continue}break}break G}while(1){g=F[a+4>>2];K:{if((g|0)!=(h|0)){if(g>>>0>=n>>>0){g=(g>>>0)%(n>>>0)|0}if((g|0)==(i|0)){break K}break G}if((h|0)==F[a+8>>2]){break I}}a=F[a>>2];if(a){continue}break}break G}if((f|0)!=(k|0)){F[f>>2]=F[a+12>>2];F[l+68>>2]=c;f=c;break G}b=k-e|0;c=b>>2;d=c+1|0;if(d>>>0>=1073741824){break b}f=b>>>1|0;d=b>>>0>=2147483644?1073741823:d>>>0>>0?f:d;if(d){if(d>>>0>=1073741824){break p}f=ka(d<<2)}else{f=0}b=f+(c<<2)|0;F[b>>2]=F[a+12>>2];d=f+(d<<2)|0;f=b+4|0;if((e|0)!=(k|0)){while(1){b=b-4|0;k=k-4|0;F[b>>2]=F[k>>2];if((e|0)!=(k|0)){continue}break}}F[l+72>>2]=d;F[l+68>>2]=f;F[l+64>>2]=b;if(e){ja(e)}e=b;k=d}if((e|0)==(f|0)){break t}x=f-4|0;a=F[x>>2];if((a|0)==(m|0)){break t}i=(a|0)==-1;g=F[j+8>>2];if(!i&F[F[g+12>>2]+(a<<2)>>2]!=-1){break t}n=F[g+12>>2];if((m|0)!=-1&F[n+(m<<2)>>2]!=-1){break t}p=L(h,3);t=p+2|0;F[n+(a<<2)>>2]=t;c=t<<2;F[c+n>>2]=a;h=p+1|0;F[n+(m<<2)>>2]=h;w=h<<2;F[w+n>>2]=m;L:{M:{N:{if(!i){if((a>>>0)%3|0){h=a-1|0;break N}h=a+2|0;if((h|0)!=-1){break N}i=F[g>>2];h=-1;break M}h=-1;i=F[g>>2];F[i+(p<<2)>>2]=-1;r=-1;break L}i=F[g>>2];h=F[i+(h<<2)>>2]}F[(p<<2)+i>>2]=h;r=a+1|0;a=(r>>>0)%3|0?r:a-2|0;r=-1;if((a|0)==-1){break L}r=F[(a<<2)+i>>2]}F[i+w>>2]=r;O:{if((m|0)==-1){F[c+i>>2]=-1;r=-1;c=-1;break O}P:{Q:{R:{if((m>>>0)%3|0){a=m-1|0;break R}a=m+2|0;if((a|0)==-1){break Q}}a=F[(a<<2)+i>>2];F[c+i>>2]=a;if((a|0)==-1){break P}F[F[g+24>>2]+(a<<2)>>2]=t;break P}F[c+i>>2]=-1}r=-1;a=m+1|0;a=(a>>>0)%3|0?a:m-2|0;c=-1;if((a|0)==-1){break O}r=F[(a<<2)+i>>2];c=a}a=F[j+388>>2];t=h<<2;m=a+t|0;w=a;a=r<<2;F[m>>2]=F[m>>2]+F[w+a>>2];w=a;a=F[g+24>>2];m=w+a|0;if((h|0)!=-1){F[a+t>>2]=F[m>>2]}a=c;while(1){if((a|0)!=-1){F[(a<<2)+i>>2]=h;t=a+1|0;a=(t>>>0)%3|0?t:a-2|0;g=-1;S:{if((a|0)==-1){break S}a=F[n+(a<<2)>>2];g=-1;if((a|0)==-1){break S}g=a+1|0;g=(g>>>0)%3|0?g:a-2|0}a=g;if((c|0)!=(a|0)){continue}break t}break}F[m>>2]=-1;T:{U:{if(M){break U}if((y|0)!=(z|0)){F[z>>2]=r;z=z+4|0;F[l+28>>2]=z;break U}a=y-o|0;g=a>>2;c=g+1|0;if(c>>>0>=1073741824){break T}h=a>>>1|0;h=a>>>0>=2147483644?1073741823:c>>>0>>0?h:c;if(h){if(h>>>0>=1073741824){break p}c=ka(h<<2)}else{c=0}a=c+(g<<2)|0;F[a>>2]=r;z=a+4|0;if((o|0)!=(y|0)){while(1){a=a-4|0;y=y-4|0;F[a>>2]=F[y>>2];if((o|0)!=(y|0)){continue}break}}y=c+(h<<2)|0;F[l+32>>2]=y;F[l+28>>2]=z;F[l+24>>2]=a;if(o){ja(o)}o=a}F[x>>2]=p;c=f;kc(J,p);break u}break b}g=F[j+8>>2];Ma(g+24|0,8324);a=-1;k=F[j+8>>2];f=L(h,3);i=F[g+28>>2];m=F[g+24>>2];n=i-m|0;g=n>>2;p=g-1|0;F[F[k>>2]+(f<<2)>>2]=p;Ma(k+24|0,8324);r=f+1|0;F[F[k>>2]+(r<<2)>>2]=(F[k+28>>2]-F[k+24>>2]>>2)-1;k=F[j+8>>2];Ma(k+24|0,8324);t=f+2|0;F[F[k>>2]+(t<<2)>>2]=(F[k+28>>2]-F[k+24>>2]>>2)-1;x=F[j+8>>2];k=F[x+24>>2];if(F[x+28>>2]-k>>2>(C|0)){break r}V:{W:{if((i|0)!=(m|0)){F[k+(p<<2)>>2]=f;a=0;if((n|0)==-4){break W}}F[k+(g<<2)>>2]=r;a=g+1|0;if((a|0)==-1){break V}}F[k+(a<<2)>>2]=t}if((d|0)!=(c|0)){F[c>>2]=f;f=c+4|0;F[l+68>>2]=f;k=d;break v}a=d-b|0;k=a>>2;e=k+1|0;if(e>>>0>=1073741824){break b}c=a>>>1|0;a=a>>>0>=2147483644?1073741823:e>>>0>>0?c:e;if(a){if(a>>>0>=1073741824){break p}c=ka(a<<2)}else{c=0}e=c+(k<<2)|0;F[e>>2]=f;k=c+(a<<2)|0;f=e+4|0;if((b|0)!=(d|0)){while(1){e=e-4|0;d=d-4|0;F[e>>2]=F[d>>2];if((b|0)!=(d|0)){continue}break}}F[l+72>>2]=k;F[l+68>>2]=f;F[l+64>>2]=e;if(b){ja(b)}d=k;b=e}kc(J,F[f-4>>2]);a=F[j+40>>2];X:{if((a|0)==F[j+36>>2]){break X}c=a-12|0;g=F[c+4>>2];h=q+(h^-1)|0;if(g>>>0>h>>>0){break t}if((g|0)!=(h|0)){break X}i=G[a-4|0];g=F[c>>2];F[j+40>>2]=c;if((g|0)<0){break t}m=f-4|0;a=F[m>>2];F[l+20>>2]=q+(g^-1);c=l+20|0;F[l+88>>2]=c;Fb(l,l+40|0,c,l+88|0);g=F[l>>2];Y:{if(i&1){c=-1;if((a|0)==-1){break Y}c=a+1|0;c=(c>>>0)%3|0?c:a-2|0;break Y}c=-1;if((a|0)==-1){break Y}c=a-1|0;if((a>>>0)%3|0){break Y}c=a+2|0}F[g+12>>2]=c;a=F[j+40>>2];if((a|0)==F[j+36>>2]){break X}while(1){c=a-12|0;g=F[c+4>>2];if(g>>>0>h>>>0){break t}if((g|0)!=(h|0)){break X}i=G[a-4|0];g=F[c>>2];F[j+40>>2]=c;if((g|0)<0){break t}a=F[m>>2];F[l+20>>2]=q+(g^-1);c=l+20|0;F[l+88>>2]=c;Fb(l,l+40|0,c,l+88|0);g=F[l>>2];Z:{if(i&1){c=-1;if((a|0)==-1){break Z}c=a+1|0;c=(c>>>0)%3|0?c:a-2|0;break Z}c=-1;if((a|0)==-1){break Z}c=a-1|0;if((a>>>0)%3|0){break Z}c=a+2|0}F[g+12>>2]=c;a=F[j+40>>2];if((a|0)!=F[j+36>>2]){continue}break}}c=f}B=(q|0)>(s|0);if((q|0)!=(s|0)){continue}break}s=q;break s}a=-1;if(B){break r}}a=-1;c=F[j+8>>2];if(F[c+28>>2]-F[c+24>>2]>>2>(C|0)){break r}if((b|0)!=(f|0)){m=j+72|0;k=j+60|0;n=j+312|0;while(1){f=f-4|0;q=F[f>>2];F[l+68>>2]=f;_:{if(wa(n)){g=F[j+8>>2];o=F[g>>2];if(((F[g+4>>2]-o>>2>>>0)/3|0)<=(s|0)){a=-1;break r}b=-1;i=F[g+24>>2];a=-1;$:{if((q|0)==-1){break $}e=q+1|0;e=(e>>>0)%3|0?e:q-2|0;a=-1;if((e|0)==-1){break $}a=F[o+(e<<2)>>2]}e=a;a=F[i+(e<<2)>>2];aa:{if((a|0)==-1){h=1;c=-1;break aa}h=1;c=-1;d=a+1|0;a=(d>>>0)%3|0?d:a-2|0;if((a|0)==-1){break aa}h=0;b=a+1|0;b=(b>>>0)%3|0?b:a-2|0;if((b|0)!=-1){c=F[o+(b<<2)>>2]}b=a}a=-1;d=-1;i=F[i+(c<<2)>>2];if((i|0)!=-1){d=i+1|0;d=(d>>>0)%3|0?d:i-2|0}if((b|0)==(q|0)|(d|0)==(q|0)|((q|0)!=-1&F[F[g+12>>2]+(q<<2)>>2]!=-1|(b|0)==(d|0))){break r}if(!h&F[F[g+12>>2]+(b<<2)>>2]!=-1){break r}h=-1;g=F[g+12>>2];i=-1;ba:{if((d|0)==-1){break ba}if(F[g+(d<<2)>>2]!=-1){break r}a=d+1|0;a=(a>>>0)%3|0?a:d-2|0;i=-1;if((a|0)==-1){break ba}i=F[o+(a<<2)>>2]}a=L(s,3);F[l>>2]=a;F[g+(a<<2)>>2]=q;F[g+(q<<2)>>2]=a;a=F[l>>2]+1|0;F[g+(a<<2)>>2]=b;F[g+(b<<2)>>2]=a;a=F[l>>2]+2|0;F[g+(a<<2)>>2]=d;F[g+(d<<2)>>2]=a;a=F[l>>2];F[o+(a<<2)>>2]=c;b=a+1|0;d=o+(b<<2)|0;F[d>>2]=i;q=a+2|0;o=o+(q<<2)|0;F[o>>2]=e;a=F[j+120>>2];e=b?c:-1;c=a+(e>>>3&536870908)|0;g=F[c>>2];O=c,P=oi(e)&g,F[O>>2]=P;h=(b|0)!=-1?F[d>>2]:h;b=a+(h>>>3&536870908)|0;d=F[b>>2];O=b,P=oi(h)&d,F[O>>2]=P;d=-1;d=(q|0)!=-1?F[o>>2]:d;a=a+(d>>>3&536870908)|0;b=F[a>>2];O=a,P=oi(d)&b,F[O>>2]=P;D[l+88|0]=1;wd(k,l+88|0);Ma(m,l);s=s+1|0;b=F[l+64>>2];break _}d=F[j+64>>2];a=F[j+68>>2];if((d|0)==a<<5){if((d+1|0)<0){break b}if(d>>>0<=1073741822){a=a<<6;d=(d&-32)+32|0;a=a>>>0>d>>>0?a:d}else{a=2147483647}$a(k,a);d=F[j+64>>2]}F[j+64>>2]=d+1;a=F[j+60>>2]+(d>>>3&536870908)|0;e=F[a>>2];O=a,P=oi(d)&e,F[O>>2]=P;d=F[j+76>>2];if((d|0)!=F[j+80>>2]){F[d>>2]=q;F[j+76>>2]=d+4;break _}c=F[m>>2];a=d-c|0;o=a>>2;e=o+1|0;if(e>>>0>=1073741824){break b}h=a>>>1|0;h=a>>>0>=2147483644?1073741823:e>>>0>>0?h:e;if(h){if(h>>>0>=1073741824){break p}a=ka(h<<2)}else{a=0}e=a+(o<<2)|0;F[e>>2]=q;q=e+4|0;if((d|0)!=(c|0)){while(1){e=e-4|0;d=d-4|0;F[e>>2]=F[d>>2];if((d|0)!=(c|0)){continue}break}}F[j+80>>2]=a+(h<<2);F[j+76>>2]=q;F[j+72>>2]=e;if(!c){break _}ja(c)}if((b|0)!=(f|0)){continue}break}c=F[j+8>>2]}a=-1;if(((F[c+4>>2]-F[c>>2]>>2>>>0)/3|0)!=(s|0)){break r}a=F[c+28>>2]-F[c+24>>2]>>2;f=F[l+24>>2];h=F[l+28>>2];if((f|0)==(h|0)){break q}while(1){b=F[f>>2];k=F[c+24>>2];d=a-1|0;e=k+(d<<2)|0;if(F[e>>2]==-1){while(1){d=a-2|0;a=a-1|0;e=k+(d<<2)|0;if(F[e>>2]==-1){continue}break}}if(b>>>0<=d>>>0){F[l>>2]=c;e=F[e>>2];D[l+12|0]=1;F[l+8>>2]=e;F[l+4>>2]=e;if((e|0)!=-1){while(1){e=F[F[j+8>>2]>>2]+(e<<2)|0;if(F[e>>2]!=(d|0)){a=-1;break r}F[e>>2]=b;nc(l);e=F[l+8>>2];if((e|0)!=-1){continue}break}c=F[j+8>>2]}k=F[c+24>>2];e=k+(d<<2)|0;if((b|0)!=-1){F[k+(b<<2)>>2]=F[e>>2]}F[e>>2]=-1;e=1<>2];b=k+(b>>>3&536870908)|0;k=k+(d>>>3&536870908)|0;d=1<>2]&d){e=e|F[b>>2]}else{e=F[b>>2]&(e^-1)}F[b>>2]=e;F[k>>2]=F[k>>2]&(d^-1);a=a-1|0}f=f+4|0;if((h|0)!=(f|0)){continue}break}}f=F[l+24>>2]}if(f){ja(f)}b=F[l+48>>2];if(b){while(1){d=F[b>>2];ja(b);b=d;if(b){continue}break}}b=F[l+40>>2];F[l+40>>2]=0;if(b){ja(b)}b=F[l+64>>2];if(b){F[l+68>>2]=b;ja(b)}Z=l+96|0;break o}oa();v()}f=a;if((a|0)==-1){break n}a=K;b=F[a+16>>2];d=b+F[a>>2]|0;b=F[a+8>>2]-b|0;a=F[F[j+4>>2]+32>>2];E[a+38>>1]=H[a+38>>1];F[a>>2]=d;F[a+16>>2]=0;F[a+20>>2]=0;F[a+8>>2]=b;F[a+12>>2]=0;ca:{if(F[j+216>>2]==F[j+220>>2]){break ca}a=F[j+8>>2];if(F[a+4>>2]==F[a>>2]){break ca}b=0;while(1){if(Ad(j,b)){b=b+3|0;a=F[j+8>>2];if(b>>>0>2]-F[a>>2]>>2>>>0){continue}break ca}break}break n}if(G[j+308|0]){D[j+308|0]=0;d=F[j+292>>2];a=0;e=F[j+304>>2]+7|0;a=e>>>0<7?1:a;e=a<<29|e>>>3;b=e+F[j+288>>2]|0;a=(a>>>3|0)+d|0;F[j+288>>2]=b;F[j+292>>2]=b>>>0>>0?a+1|0:a}b=F[j+216>>2];if((b|0)!=F[j+220>>2]){a=0;while(1){e=L(a,144);Zc((e+b|0)+4|0,F[j+8>>2]);d=F[A>>2];c=d+e|0;b=F[c+132>>2];c=F[c+136>>2];if((b|0)!=(c|0)){while(1){Xc((e+F[A>>2]|0)+4|0,F[b>>2]);b=b+4|0;if((c|0)!=(b|0)){continue}break}d=F[A>>2]}if(!Yc((d+e|0)+4|0)){break n}a=a+1|0;b=F[j+216>>2];if(a>>>0<(F[j+220>>2]-b|0)/144>>>0){continue}break}}a=F[j+8>>2];Hb(j+184|0,F[a+28>>2]-F[a+24>>2]>>2);d=F[j+216>>2];if((d|0)!=F[j+220>>2]){b=0;while(1){a=L(b,144)+d|0;d=F[a+60>>2]-F[a+56>>2]>>2;c=a+104|0;a=F[j+8>>2];a=F[a+28>>2]-F[a+24>>2]>>2;Hb(c,(a|0)<(d|0)?d:a);b=b+1|0;d=F[j+216>>2];if(b>>>0<(F[j+220>>2]-d|0)/144>>>0){continue}break}}N=zd(j,f)}}Z=u- -64|0;return N|0}na();v()}function lh(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,J=0,K=0,M=0,N=0;t=Z+-64|0;Z=t;F[a+132>>2]=0;if(F[a+148>>2]){c=F[a+144>>2];if(c){while(1){b=F[c>>2];ja(c);c=b;if(b){continue}break}}c=0;F[a+144>>2]=0;b=F[a+140>>2];a:{if(!b){break a}if(b>>>0>=4){h=b&-4;while(1){e=c<<2;F[e+F[a+136>>2]>>2]=0;F[F[a+136>>2]+(e|4)>>2]=0;F[F[a+136>>2]+(e|8)>>2]=0;F[F[a+136>>2]+(e|12)>>2]=0;c=c+4|0;g=g+4|0;if((h|0)!=(g|0)){continue}break}}b=b&3;if(!b){break a}g=0;while(1){F[F[a+136>>2]+(c<<2)>>2]=0;c=c+1|0;g=g+1|0;if((b|0)!=(g|0)){continue}break}}F[a+148>>2]=0}b:{if(!Da(1,t+60|0,F[F[a+4>>2]+32>>2])){break b}F[a+156>>2]=F[t+60>>2];if(!Da(1,t+56|0,F[F[a+4>>2]+32>>2])){break b}e=F[t+56>>2];if(e>>>0>1431655765|I[a+156>>2]>L(e,3)>>>0){break b}c=F[F[a+4>>2]+32>>2];h=F[c+8>>2];m=F[c+12>>2];b=F[c+20>>2];g=F[c+16>>2];if((m|0)<=(b|0)&g>>>0>=h>>>0|(b|0)>(m|0)){break b}h=G[g+F[c>>2]|0];g=g+1|0;b=g?b:b+1|0;F[c+16>>2]=g;F[c+20>>2]=b;if(!Da(1,t+52|0,c)){break b}n=F[t+52>>2];if(n>>>0>e>>>0|e>>>0>n+((n>>>0)/3|0)>>>0){break b}if(!Da(1,t+48|0,F[F[a+4>>2]+32>>2])){break b}c=F[t+48>>2];if(c>>>0>n>>>0){break b}F[a+28>>2]=F[a+24>>2];g=Zb(ka(88));b=F[a+8>>2];F[a+8>>2]=g;if(b){Za(b);if(!F[a+8>>2]){break b}}F[a+164>>2]=F[a+160>>2];Ib(a+160|0,e);F[a+176>>2]=F[a+172>>2];Ib(a+172|0,e);F[a- -64>>2]=0;F[a+92>>2]=-1;F[a+84>>2]=-1;F[a+88>>2]=-1;F[a+40>>2]=F[a+36>>2];F[a+52>>2]=F[a+48>>2];F[a+76>>2]=F[a+72>>2];y=a+216|0;Dd(y);Cd(y,h);if(!_c(F[a+8>>2],e,c+F[a+156>>2]|0)){break b}b=F[a+156>>2];D[t+8|0]=1;Ea(a+120|0,b+c|0,t+8|0);if((Bd(a,F[F[a+4>>2]+32>>2])|0)==-1){break b}c=a+232|0;F[c+144>>2]=a;b=F[($[F[F[a>>2]+32>>2]](a)|0)+32>>2];b=F[b>>2]+F[b+16>>2]|0;g=F[($[F[F[a>>2]+32>>2]](a)|0)+32>>2];g=F[g+8>>2]-F[g+16>>2]|0;M=c,N=H[F[($[F[F[a>>2]+32>>2]](a)|0)+32>>2]+38>>1],E[M+38>>1]=N;F[c>>2]=b;F[c+16>>2]=0;F[c+20>>2]=0;F[c+8>>2]=g;F[c+12>>2]=0;F[a+372>>2]=h;C=Ja(t+8|0);h=C;m=0;d=Z-16|0;Z=d;b=F[c+4>>2];F[c+40>>2]=F[c>>2];F[c+44>>2]=b;b=F[c+36>>2];F[c+72>>2]=F[c+32>>2];F[c+76>>2]=b;g=F[c+28>>2];b=c- -64|0;F[b>>2]=F[c+24>>2];F[b+4>>2]=g;b=F[c+20>>2];F[c+56>>2]=F[c+16>>2];F[c+60>>2]=b;b=F[c+12>>2];F[c+48>>2]=F[c+8>>2];F[c+52>>2]=b;c:{d:{if(hc(c+40|0,1,d+8|0)){b=F[c+44>>2];F[c>>2]=F[c+40>>2];F[c+4>>2]=b;b=F[c+76>>2];F[c+32>>2]=F[c+72>>2];F[c+36>>2]=b;b=F[c+68>>2];F[c+24>>2]=F[c+64>>2];F[c+28>>2]=b;g=F[c+60>>2];f=g;b=F[c+56>>2];F[c+16>>2]=b;F[c+20>>2]=g;e=F[c+52>>2];g=F[c+48>>2];F[c+8>>2]=g;F[c+12>>2]=e;k=F[d+12>>2];i=e-((b>>>0>g>>>0)+f|0)|0;e=g-b|0;g=F[d+8>>2];if((k|0)==(i|0)&e>>>0>=g>>>0|i>>>0>k>>>0){break d}}break c}e=f+k|0;b=b+g|0;e=b>>>0>>0?e+1|0:e;F[c+16>>2]=b;F[c+20>>2]=e;if(!Aa(c+80|0,c)){break c}if(!yd(c)){break c}b=F[c+4>>2];F[h>>2]=F[c>>2];F[h+4>>2]=b;b=F[c+36>>2];F[h+32>>2]=F[c+32>>2];F[h+36>>2]=b;b=F[c+28>>2];F[h+24>>2]=F[c+24>>2];F[h+28>>2]=b;b=F[c+20>>2];F[h+16>>2]=F[c+16>>2];F[h+20>>2]=b;b=F[c+12>>2];F[h+8>>2]=F[c+8>>2];F[h+12>>2]=b;m=1}Z=d+16|0;e:{if(!m){break e}b=0;c=0;g=0;m=0;j=Z-96|0;Z=j;F[j+72>>2]=0;F[j+64>>2]=0;F[j+68>>2]=0;F[j+48>>2]=0;F[j+52>>2]=0;F[j+40>>2]=0;F[j+44>>2]=0;F[j+56>>2]=1065353216;F[j+32>>2]=0;F[j+24>>2]=0;F[j+28>>2]=0;h=a;B=F[a+124>>2];f:{g:{h:{i:{j:{k:{l:{m:{if((n|0)<=0){break m}J=F[h+216>>2]!=F[h+220>>2];z=1;while(1){e=m;m=e+1|0;n:{o:{p:{q:{r:{s:{t:{u:{v:{w:{x:{y:{z:{A:{B:{if(!G[h+308|0]){break B}k=F[h+296>>2];d=F[h+304>>2];a=k+(d>>>3|0)|0;l=F[h+300>>2];if(a>>>0>=l>>>0){break B}f=G[a|0];a=d+1|0;F[h+304>>2]=a;p=f>>>(d&7)&1;if(!p){break B}i=0;f=a>>>3|0;r=k+f|0;C:{if(r>>>0>=l>>>0){d=a;a=0;break C}r=G[r|0];d=d+2|0;F[h+304>>2]=d;f=d>>>3|0;a=r>>>(a&7)&1}f=f+k|0;if(f>>>0>>0){f=G[f|0];F[h+304>>2]=d+1;i=f>>>(d&7)<<1&2}f=-1;i=p|(a|i)<<1;switch(i-1|0){case 6:break y;case 0:break z;case 2:case 4:break A;default:break l}}if((c|0)==(g|0)){f=-1;break l}d=-1;i=F[h+8>>2];z=F[i+24>>2];r=c-4|0;b=F[r>>2];a=-1;D:{if((b|0)==-1){break D}k=b+1|0;k=(k>>>0)%3|0?k:b-2|0;a=-1;if((k|0)==-1){break D}a=F[F[i>>2]+(k<<2)>>2]}f=F[z+(a<<2)>>2];if((f|0)!=-1){d=f+1|0;d=(d>>>0)%3|0?d:f-2|0}if((b|0)==(d|0)){f=-1;break l}if((b|0)!=-1){f=-1;if(F[F[i+12>>2]+(b<<2)>>2]!=-1){break l}}k=F[i+12>>2];if((d|0)!=-1){f=-1;if(F[k+(d<<2)>>2]!=-1){break l}}l=L(e,3);e=l+1|0;F[k+(b<<2)>>2]=e;s=e<<2;F[s+k>>2]=b;p=l+2|0;F[k+(d<<2)>>2]=p;u=p<<2;F[u+k>>2]=d;k=-1;e=-1;E:{if((b|0)==-1){break E}F:{if((b>>>0)%3|0){b=b-1|0;break F}b=b+2|0;e=-1;if((b|0)==-1){break E}}e=F[F[i>>2]+(b<<2)>>2]}b=e;G:{if((d|0)==-1){break G}e=d+1|0;e=(e>>>0)%3|0?e:d-2|0;if((e|0)==-1){break G}k=F[F[i>>2]+(e<<2)>>2]}f=-1;if((a|0)==(b|0)|(a|0)==(k|0)){break l}e=F[i>>2];F[e+(l<<2)>>2]=a;F[e+s>>2]=k;F[e+u>>2]=b;if((b|0)!=-1){F[z+(b<<2)>>2]=p}b=F[h+120>>2]+(a>>>3&536870908)|0;e=F[b>>2];M=b,N=oi(a)&e,F[M>>2]=N;F[r>>2]=l;b=g;break n}if((c|0)==(g|0)){break l}r=c-4|0;b=F[r>>2];a=F[h+8>>2];d=F[a+12>>2];if((b|0)!=-1&F[d+(b<<2)>>2]!=-1){break l}l=(i|0)==5;i=L(e,3);p=(l?2:1)+i|0;s=p<<2;F[s+d>>2]=b;F[d+(b<<2)>>2]=p;Ma(a+24|0,8324);d=F[h+8>>2];k=F[d+24>>2];if(F[d+28>>2]-k>>2>(B|0)){break l}d=F[d>>2];u=d+s|0;f=F[a+28>>2];a=F[a+24>>2];s=(f-a>>2)-1|0;F[u>>2]=s;if((a|0)!=(f|0)){F[k+(s<<2)>>2]=p}f=l?i:i+2|0;l=d+(i+l<<2)|0;H:{if((b|0)==-1){F[d+(f<<2)>>2]=-1;a=-1;break H}I:{J:{K:{if((b>>>0)%3|0){a=b-1|0;break K}a=b+2|0;if((a|0)==-1){break J}}a=F[d+(a<<2)>>2];F[d+(f<<2)>>2]=a;if((a|0)==-1){break I}F[k+(a<<2)>>2]=f;break I}F[d+(f<<2)>>2]=-1}f=b+1|0;b=(f>>>0)%3|0?f:b-2|0;a=-1;if((b|0)==-1){break H}a=F[d+(b<<2)>>2]}F[l>>2]=a;F[r>>2]=i;b=g;break t}if((b|0)==(c|0)){break l}a=c-4|0;k=F[a>>2];F[j+68>>2]=a;l=F[j+44>>2];L:{if(!l){c=a;break L}f=F[j+40>>2];p=ni(l)>>>0>1;d=e&l+2147483647;M:{if(!p){break M}d=e;if(d>>>0>>0){break M}d=(e>>>0)%(l>>>0)|0}i=d;d=F[f+(i<<2)>>2];if(!d){c=a;break L}d=F[d>>2];if(!d){c=a;break L}N:{if(!p){f=l-1|0;while(1){l=F[d+4>>2];O:{if((l|0)!=(e|0)){if((i|0)==(f&l)){break O}c=a;break L}if((e|0)==F[d+8>>2]){break N}}d=F[d>>2];if(d){continue}break}c=a;break L}while(1){f=F[d+4>>2];P:{if((f|0)!=(e|0)){if(f>>>0>=l>>>0){f=(f>>>0)%(l>>>0)|0}if((f|0)==(i|0)){break P}c=a;break L}if((e|0)==F[d+8>>2]){break N}}d=F[d>>2];if(d){continue}break}c=a;break L}if((a|0)!=(q|0)){F[a>>2]=F[d+12>>2];F[j+68>>2]=c;break L}a=q-b|0;g=a>>2;c=g+1|0;if(c>>>0>=1073741824){break x}f=a>>>1|0;f=a>>>0>=2147483644?1073741823:c>>>0>>0?f:c;if(f){if(f>>>0>=1073741824){break j}a=ka(f<<2)}else{a=0}g=a+(g<<2)|0;F[g>>2]=F[d+12>>2];c=g+4|0;if((b|0)!=(q|0)){while(1){g=g-4|0;q=q-4|0;F[g>>2]=F[q>>2];if((b|0)!=(q|0)){continue}break}}q=a+(f<<2)|0;F[j+72>>2]=q;F[j+68>>2]=c;F[j+64>>2]=g;if(b){ja(b)}}if((c|0)==(g|0)){break p}s=c-4|0;b=F[s>>2];if((b|0)==(k|0)){break p}a=(b|0)==-1;f=F[h+8>>2];if(!a&F[F[f+12>>2]+(b<<2)>>2]!=-1){break p}l=F[f+12>>2];if((k|0)!=-1&F[l+(k<<2)>>2]!=-1){break p}p=L(e,3);r=p+2|0;F[l+(b<<2)>>2]=r;e=r<<2;F[e+l>>2]=b;d=p+1|0;F[l+(k<<2)>>2]=d;u=d<<2;F[u+l>>2]=k;if(a){break w}if((b>>>0)%3|0){d=b-1|0;break s}d=b+2|0;if((d|0)!=-1){break s}a=F[f>>2];d=-1;break r}i=F[h+8>>2];Ma(i+24|0,8324);d=F[h+8>>2];a=L(e,3);k=F[i+28>>2];l=F[i+24>>2];p=k-l|0;i=p>>2;r=i-1|0;F[F[d>>2]+(a<<2)>>2]=r;Ma(d+24|0,8324);s=a+1|0;F[F[d>>2]+(s<<2)>>2]=(F[d+28>>2]-F[d+24>>2]>>2)-1;d=F[h+8>>2];Ma(d+24|0,8324);u=a+2|0;F[F[d>>2]+(u<<2)>>2]=(F[d+28>>2]-F[d+24>>2]>>2)-1;A=F[h+8>>2];d=F[A+24>>2];if(F[A+28>>2]-d>>2>(B|0)){break l}Q:{R:{if((k|0)!=(l|0)){F[d+(r<<2)>>2]=a;f=0;if((p|0)==-4){break R}}F[d+(i<<2)>>2]=s;f=i+1|0;if((f|0)==-1){break Q}}F[d+(f<<2)>>2]=u}if((c|0)!=(q|0)){F[c>>2]=a;c=c+4|0;F[j+68>>2]=c;break t}g=c-b|0;i=g>>2;d=i+1|0;if(d>>>0>=1073741824){break v}f=g>>>1|0;d=g>>>0>=2147483644?1073741823:d>>>0>>0?f:d;if(d){if(d>>>0>=1073741824){break j}f=ka(d<<2)}else{f=0}g=f+(i<<2)|0;F[g>>2]=a;q=f+(d<<2)|0;a=g+4|0;if((b|0)!=(c|0)){while(1){g=g-4|0;c=c-4|0;F[g>>2]=F[c>>2];if((b|0)!=(c|0)){continue}break}}F[j+72>>2]=q;F[j+68>>2]=a;F[j+64>>2]=g;if(!b){break u}ja(b);break u}na();v()}d=-1;a=F[f>>2];F[a+(p<<2)>>2]=-1;i=-1;break q}na();v()}c=a;b=g}a=F[h+40>>2];if((a|0)==F[h+36>>2]){break n}d=a-12|0;i=F[d+4>>2];f=n+(e^-1)|0;if(i>>>0>f>>>0){break p}if((f|0)!=(i|0)){break n}i=G[a-4|0];e=F[d>>2];F[h+40>>2]=d;if((e|0)<0){break p}k=c-4|0;a=F[k>>2];F[j+20>>2]=n+(e^-1);e=j+20|0;F[j+88>>2]=e;Fb(j,j+40|0,e,j+88|0);d=F[j>>2];S:{if(i&1){e=-1;if((a|0)==-1){break S}e=a+1|0;e=(e>>>0)%3|0?e:a-2|0;break S}e=-1;if((a|0)==-1){break S}e=a-1|0;if((a>>>0)%3|0){break S}e=a+2|0}F[d+12>>2]=e;d=F[h+40>>2];if((d|0)==F[h+36>>2]){break n}while(1){a=d-12|0;e=F[a+4>>2];if(e>>>0>f>>>0){break p}if((f|0)!=(e|0)){break n}d=G[d-4|0];e=F[a>>2];F[h+40>>2]=a;if((e|0)<0){break p}a=F[k>>2];F[j+20>>2]=n+(e^-1);e=j+20|0;F[j+88>>2]=e;Fb(j,j+40|0,e,j+88|0);i=F[j>>2];T:{if(d&1){e=-1;if((a|0)==-1){break T}e=a+1|0;e=(e>>>0)%3|0?e:a-2|0;break T}e=-1;if((a|0)==-1){break T}e=a-1|0;if((a>>>0)%3|0){break T}e=a+2|0}F[i+12>>2]=e;d=F[h+40>>2];if((d|0)!=F[h+36>>2]){continue}break}break n}a=F[f>>2];d=F[a+(d<<2)>>2]}F[(p<<2)+a>>2]=d;A=b+1|0;b=(A>>>0)%3|0?A:b-2|0;i=-1;if((b|0)==-1){break q}i=F[(b<<2)+a>>2]}F[a+u>>2]=i;U:{if((k|0)==-1){F[a+e>>2]=-1;i=-1;e=-1;break U}V:{W:{X:{if((k>>>0)%3|0){b=k-1|0;break X}b=k+2|0;if((b|0)==-1){break W}}b=F[(b<<2)+a>>2];F[a+e>>2]=b;if((b|0)==-1){break V}F[F[f+24>>2]+(b<<2)>>2]=r;break V}F[a+e>>2]=-1}i=-1;b=k+1|0;b=(b>>>0)%3|0?b:k-2|0;e=-1;if((b|0)==-1){break U}i=F[(b<<2)+a>>2];e=b}b=F[f+24>>2];k=b+(i<<2)|0;if((d|0)!=-1){F[b+(d<<2)>>2]=F[k>>2]}b=e;while(1){if((b|0)==-1){break o}F[(b<<2)+a>>2]=d;r=b+1|0;b=(r>>>0)%3|0?r:b-2|0;f=-1;Y:{if((b|0)==-1){break Y}b=F[l+(b<<2)>>2];f=-1;if((b|0)==-1){break Y}f=b+1|0;f=(f>>>0)%3|0?f:b-2|0}b=f;if((e|0)!=(b|0)){continue}break}}f=-1;if(!z){break m}break l}F[k>>2]=-1;Z:{if(J){break Z}if((w|0)!=(x|0)){F[x>>2]=i;x=x+4|0;F[j+28>>2]=x;break Z}a=w-o|0;d=a>>2;b=d+1|0;if(b>>>0>=1073741824){break i}e=a>>>1|0;e=a>>>0>=2147483644?1073741823:b>>>0>>0?e:b;if(e){if(e>>>0>=1073741824){break j}a=ka(e<<2)}else{a=0}b=a+(d<<2)|0;F[b>>2]=i;x=b+4|0;if((o|0)!=(w|0)){while(1){b=b-4|0;w=w-4|0;F[b>>2]=F[w>>2];if((o|0)!=(w|0)){continue}break}}w=a+(e<<2)|0;F[j+32>>2]=w;F[j+28>>2]=x;F[j+24>>2]=b;if(o){ja(o)}o=b}F[s>>2]=p;b=g}z=(m|0)<(n|0);if((m|0)!=(n|0)){continue}break}m=n}f=-1;a=F[h+8>>2];if(F[a+28>>2]-F[a+24>>2]>>2>(B|0)){break l}if((c|0)!=(g|0)){l=h+72|0;e=h+60|0;w=h+312|0;while(1){c=c-4|0;i=F[c>>2];F[j+68>>2]=c;_:{if(wa(w)){q=F[h+8>>2];k=F[q>>2];if(((F[q+4>>2]-k>>2>>>0)/3|0)<=(m|0)){f=-1;break l}a=-1;f=-1;b=-1;x=F[q+24>>2];g=-1;$:{if((i|0)==-1){break $}n=i+1|0;n=(n>>>0)%3|0?n:i-2|0;g=-1;if((n|0)==-1){break $}g=F[k+(n<<2)>>2]}n=g;o=F[x+(n<<2)>>2];aa:{if((o|0)==-1){d=1;g=-1;break aa}d=1;p=o+1|0;o=(p>>>0)%3|0?p:o-2|0;g=-1;if((o|0)==-1){break aa}d=0;a=o;g=a+1|0;g=(g>>>0)%3|0?g:a-2|0;if((g|0)!=-1){g=F[k+(g<<2)>>2]}else{g=-1}}o=F[(g<<2)+x>>2];if((o|0)!=-1){b=o+1|0;b=(b>>>0)%3|0?b:o-2|0}if((a|0)==(i|0)|(b|0)==(i|0)|((i|0)!=-1&F[F[q+12>>2]+(i<<2)>>2]!=-1|(a|0)==(b|0))){break l}if(!d&F[F[q+12>>2]+(a<<2)>>2]!=-1){break l}d=-1;o=F[q+12>>2];q=-1;ba:{if((b|0)==-1){break ba}if(F[o+(b<<2)>>2]!=-1){break l}f=b+1|0;f=(f>>>0)%3|0?f:b-2|0;q=-1;if((f|0)==-1){break ba}q=F[k+(f<<2)>>2]}f=L(m,3);F[j>>2]=f;F[o+(f<<2)>>2]=i;F[o+(i<<2)>>2]=f;f=F[j>>2]+1|0;F[o+(f<<2)>>2]=a;F[o+(a<<2)>>2]=f;a=F[j>>2]+2|0;F[o+(a<<2)>>2]=b;F[o+(b<<2)>>2]=a;a=F[j>>2];F[k+(a<<2)>>2]=g;b=a+1|0;f=k+(b<<2)|0;F[f>>2]=q;o=a+2|0;i=k+(o<<2)|0;F[i>>2]=n;a=F[h+120>>2];g=b?g:-1;n=a+(g>>>3&536870908)|0;k=F[n>>2];M=n,N=oi(g)&k,F[M>>2]=N;d=(b|0)!=-1?F[f>>2]:d;b=a+(d>>>3&536870908)|0;g=F[b>>2];M=b,N=oi(d)&g,F[M>>2]=N;b=-1;b=(o|0)!=-1?F[i>>2]:b;a=a+(b>>>3&536870908)|0;g=F[a>>2];M=a,N=oi(b)&g,F[M>>2]=N;D[j+88|0]=1;wd(e,j+88|0);Ma(l,j);m=m+1|0;g=F[j+64>>2];break _}b=F[h+64>>2];a=F[h+68>>2];if((b|0)==a<<5){if((b+1|0)<0){break h}if(b>>>0<=1073741822){a=a<<6;b=(b&-32)+32|0;a=a>>>0>b>>>0?a:b}else{a=2147483647}$a(e,a);b=F[h+64>>2]}F[h+64>>2]=b+1;a=F[h+60>>2]+(b>>>3&536870908)|0;d=F[a>>2];M=a,N=oi(b)&d,F[M>>2]=N;b=F[h+76>>2];if((b|0)!=F[h+80>>2]){F[b>>2]=i;F[h+76>>2]=b+4;break _}f=F[l>>2];a=b-f|0;o=a>>2;d=o+1|0;if(d>>>0>=1073741824){break g}n=a>>>1|0;n=a>>>0>=2147483644?1073741823:d>>>0>>0?n:d;if(n){if(n>>>0>=1073741824){break j}a=ka(n<<2)}else{a=0}d=a+(o<<2)|0;F[d>>2]=i;o=d+4|0;if((b|0)!=(f|0)){while(1){d=d-4|0;b=b-4|0;F[d>>2]=F[b>>2];if((b|0)!=(f|0)){continue}break}}F[h+80>>2]=a+(n<<2);F[h+76>>2]=o;F[h+72>>2]=d;if(!f){break _}ja(f)}if((c|0)!=(g|0)){continue}break}a=F[h+8>>2]}f=-1;if(((F[a+4>>2]-F[a>>2]>>2>>>0)/3|0)!=(m|0)){break l}f=F[a+28>>2]-F[a+24>>2]>>2;c=F[j+24>>2];n=F[j+28>>2];if((c|0)==(n|0)){break k}while(1){g=F[c>>2];e=F[a+24>>2];b=f-1|0;d=e+(b<<2)|0;if(F[d>>2]==-1){while(1){b=f-2|0;f=f-1|0;d=e+(b<<2)|0;if(F[d>>2]==-1){continue}break}}if(b>>>0>=g>>>0){F[j>>2]=a;d=F[d>>2];D[j+12|0]=1;F[j+8>>2]=d;F[j+4>>2]=d;if((d|0)!=-1){while(1){a=F[F[h+8>>2]>>2]+(d<<2)|0;if(F[a>>2]!=(b|0)){f=-1;break l}F[a>>2]=g;nc(j);d=F[j+8>>2];if((d|0)!=-1){continue}break}a=F[h+8>>2]}m=F[a+24>>2];e=m+(b<<2)|0;if((g|0)!=-1){F[m+(g<<2)>>2]=F[e>>2]}F[e>>2]=-1;e=1<>2];g=m+(g>>>3&536870908)|0;d=1<>>3&536870908)|0;if(d&F[m>>2]){b=e|F[g>>2]}else{b=F[g>>2]&(e^-1)}F[g>>2]=b;F[m>>2]=F[m>>2]&(d^-1);f=f-1|0}c=c+4|0;if((n|0)!=(c|0)){continue}break}}c=F[j+24>>2]}if(c){ja(c)}a=F[j+48>>2];if(a){while(1){c=F[a>>2];ja(a);a=c;if(a){continue}break}}a=F[j+40>>2];F[j+40>>2]=0;if(a){ja(a)}a=F[j+64>>2];if(a){F[j+68>>2]=a;ja(a)}Z=j+96|0;a=f;break f}oa();v()}na();v()}na();v()}na();v()}b=a;if((a|0)==-1){break e}a=C;c=F[a+16>>2];g=c+F[a>>2]|0;c=F[a+8>>2]-c|0;a=F[F[h+4>>2]+32>>2];E[a+38>>1]=H[a+38>>1];F[a>>2]=g;F[a+16>>2]=0;F[a+20>>2]=0;F[a+8>>2]=c;F[a+12>>2]=0;ca:{if(F[h+216>>2]==F[h+220>>2]){break ca}a=F[h+8>>2];if(F[a+4>>2]==F[a>>2]){break ca}c=0;while(1){if(Ad(h,c)){c=c+3|0;a=F[h+8>>2];if(c>>>0>2]-F[a>>2]>>2>>>0){continue}break ca}break}break e}if(G[h+308|0]){D[h+308|0]=0;g=F[h+292>>2];a=0;e=F[h+304>>2]+7|0;a=e>>>0<7?1:a;c=a>>>3|0;m=a<<29|e>>>3;a=m+F[h+288>>2]|0;e=c+g|0;F[h+288>>2]=a;F[h+292>>2]=a>>>0>>0?e+1|0:e}c=F[h+216>>2];if((c|0)!=F[h+220>>2]){a=0;while(1){e=L(a,144);Zc((e+c|0)+4|0,F[h+8>>2]);g=F[y>>2];m=g+e|0;c=F[m+132>>2];m=F[m+136>>2];if((c|0)!=(m|0)){while(1){Xc((e+F[y>>2]|0)+4|0,F[c>>2]);c=c+4|0;if((m|0)!=(c|0)){continue}break}g=F[y>>2]}if(!Yc((g+e|0)+4|0)){break e}a=a+1|0;c=F[h+216>>2];if(a>>>0<(F[h+220>>2]-c|0)/144>>>0){continue}break}}a=F[h+8>>2];Hb(h+184|0,F[a+28>>2]-F[a+24>>2]>>2);g=F[h+216>>2];if((g|0)!=F[h+220>>2]){c=0;while(1){a=L(c,144)+g|0;g=F[a+60>>2]-F[a+56>>2]>>2;e=a+104|0;a=F[h+8>>2];a=F[a+28>>2]-F[a+24>>2]>>2;Hb(e,(a|0)<(g|0)?g:a);c=c+1|0;g=F[h+216>>2];if(c>>>0<(F[h+220>>2]-g|0)/144>>>0){continue}break}}K=zd(h,b)}}Z=t- -64|0;return K|0}function Cf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,E=0,H=0,I=0,J=0,K=0,M=0,N=0,O=0;B=c;c=0;m=Z-96|0;Z=m;l=m+16|0;ma(l,0,76);F[m+92>>2]=-1;F[m+8>>2]=0;F[m>>2]=0;F[m+4>>2]=0;r=Z-16|0;Z=r;F[l+68>>2]=0;F[l+72>>2]=0;F[l>>2]=b;s=Z-16|0;Z=s;u=b;a=F[b+20>>2];a:{if((F[b+24>>2]-a|0)<=0){break a}a=F[a>>2];if((a|0)==-1){break a}c=F[F[u+8>>2]+(a<<2)>>2]}b:{c:{d:{if(!c){a=0;break d}a=F[u+100>>2];e=F[u+96>>2];F[s+8>>2]=0;F[s>>2]=0;F[s+4>>2]=0;f=a-e|0;b=(f|0)/12|0;e:{if((a|0)==(e|0)){break e}if(b>>>0>=357913942){break c}d=ka(f);F[s>>2]=d;F[s+8>>2]=d+L(b,12);a=0;n=d;f=f-12|0;d=(f-((f>>>0)%12|0)|0)+12|0;f=ma(n,0,d);F[s+4>>2]=d+f;if(G[c+84|0]){c=b>>>0<=1?1:b;h=c&1;if(b>>>0>=2){g=c&-2;c=0;while(1){d=L(a,12);b=d+e|0;i=F[b+4>>2];j=F[b>>2];d=d+f|0;F[d+8>>2]=F[b+8>>2];F[d>>2]=j;F[d+4>>2]=i;d=L(a|1,12);b=d+e|0;i=F[b+4>>2];j=F[b>>2];d=d+f|0;F[d+8>>2]=F[b+8>>2];F[d>>2]=j;F[d+4>>2]=i;a=a+2|0;c=c+2|0;if((g|0)!=(c|0)){continue}break}}if(!h){break e}b=L(a,12);a=b+e|0;c=F[a+4>>2];e=F[a>>2];b=b+f|0;F[b+8>>2]=F[a+8>>2];F[b>>2]=e;F[b+4>>2]=c;break e}h=b>>>0<=1?1:b;a=F[c+68>>2];c=0;while(1){d=L(c,12);b=d+e|0;g=F[a+(F[b>>2]<<2)>>2];i=F[a+(F[b+4>>2]<<2)>>2];d=d+f|0;F[d+8>>2]=F[a+(F[b+8>>2]<<2)>>2];F[d+4>>2]=i;F[d>>2]=g;c=c+1|0;if((h|0)!=(c|0)){continue}break}}d=0;H=Z-16|0;Z=H;h=ka(88);Zb(h);C=Z-16|0;Z=C;F[h+80>>2]=0;F[h+84>>2]=0;a=F[h+76>>2];F[h+76>>2]=0;if(a){ja(a)}F[h+68>>2]=0;F[h+72>>2]=0;b=h- -64|0;a=F[b>>2];F[b>>2]=0;if(a){ja(a)}g=F[s+4>>2];b=F[s>>2];c=(g-b|0)/12|0;a=L(c,3);f=F[h>>2];e=F[h+4>>2]-f>>2;f:{if(a>>>0>e>>>0){nd(h,a-e|0);g=F[s+4>>2];b=F[s>>2];c=(g-b|0)/12|0;break f}if(a>>>0>=e>>>0){break f}F[h+4>>2]=f+(a<<2)}g:{if((b|0)==(g|0)){break g}e=c>>>0<=1?1:c;g=e&1;a=F[h>>2];if(c>>>0>=2){i=e&-2;c=0;while(1){e=L(d,12);j=e+a|0;f=b+e|0;F[j>>2]=F[f>>2];F[a+(e|4)>>2]=F[f+4>>2];F[j+8>>2]=F[f+8>>2];f=L(d|1,12);e=f+a|0;f=b+f|0;F[e>>2]=F[f>>2];F[e+4>>2]=F[f+4>>2];F[e+8>>2]=F[f+8>>2];d=d+2|0;c=c+2|0;if((i|0)!=(c|0)){continue}break}}if(!g){break g}c=L(d,12);a=c+a|0;b=b+c|0;F[a>>2]=F[b>>2];F[a+4>>2]=F[b+4>>2];F[a+8>>2]=F[b+8>>2]}F[C+12>>2]=-1;a=0;e=0;g=0;f=Z-32|0;Z=f;h:{i:{w=C+12|0;j:{if(!w){break j}c=F[h+4>>2];j=F[h>>2];d=c-j|0;i=d>>2;n=F[h+12>>2];b=F[h+16>>2]-n>>2;k:{if(i>>>0>b>>>0){ab(h+12|0,i-b|0,10228);c=F[h+4>>2];j=F[h>>2];d=c-j|0;i=d>>2;break k}if(b>>>0<=i>>>0){break k}F[h+16>>2]=n+(i<<2)}F[f+24>>2]=0;F[f+16>>2]=0;F[f+20>>2]=0;b=(c|0)==(j|0);if(!b){if((d|0)<0){break i}e=ka(d);F[f+20>>2]=e;F[f+16>>2]=e;F[f+24>>2]=(i<<2)+e}l:{m:{n:{o:{p:{if(d){while(1){i=F[(a<<2)+j>>2];b=F[f+20>>2]-e>>2;q:{if(i>>>0>>0){break q}F[f>>2]=0;d=i+1|0;if(d>>>0>b>>>0){Fa(f+16|0,d-b|0,f);j=F[h>>2];c=F[h+4>>2];e=F[f+16>>2];break q}if(b>>>0<=d>>>0){break q}F[f+20>>2]=(d<<2)+e}b=(i<<2)+e|0;F[b>>2]=F[b>>2]+1;a=a+1|0;d=c-j|0;i=d>>2;if(a>>>0>>0){continue}break}break p}d=0;if(!b){break o}break n}if((c|0)==(j|0)){d=0;break n}if(d>>>0>=2147483645){break m}}d=ka(d<<1);ma(d,255,i<<3)}F[f+8>>2]=0;F[f>>2]=0;F[f+4>>2]=0;b=F[f+20>>2];a=b-e|0;t=a>>2;r:{s:{if((b|0)==(e|0)){break s}if((a|0)<0){break r}q=ka(a);F[f>>2]=q;F[f+8>>2]=(t<<2)+q;b=ma(q,0,a);F[f+4>>2]=b+a;c=t>>>0<=1?1:t;n=c&3;a=0;if(c-1>>>0>=3){o=c&-4;while(1){c=g<<2;F[c+b>>2]=a;x=c|4;a=F[c+e>>2]+a|0;F[x+b>>2]=a;y=c|8;a=a+F[e+x>>2]|0;F[y+b>>2]=a;c=c|12;a=a+F[e+y>>2]|0;F[c+b>>2]=a;a=a+F[c+e>>2]|0;g=g+4|0;p=p+4|0;if((o|0)!=(p|0)){continue}break}}if(!n){break s}while(1){c=g<<2;F[c+b>>2]=a;g=g+1|0;a=F[c+e>>2]+a|0;k=k+1|0;if((n|0)!=(k|0)){continue}break}}if(!i){break l}x=F[h+40>>2];y=F[h+12>>2];n=0;while(1){I=n<<2;a=I+j|0;k=-1;c=n+1|0;b=(c>>>0)%3|0?c:n-2|0;if((b|0)!=-1){k=F[(b<<2)+j>>2]}b=F[a>>2];t:{u:{if(!((n>>>0)%3|0)){p=-1;a=n+2|0;if((a|0)!=-1){p=F[(a<<2)+j>>2]}if(!((b|0)==(k|0)|(b|0)==(p|0))&(k|0)!=(p|0)){break u}x=x+1|0;F[h+40>>2]=x;c=n+3|0;break t}p=F[a-4>>2]}a=p<<2;A=F[a+e>>2];v:{w:{if((A|0)<=0){break w}a=F[a+q>>2];g=0;while(1){o=(a<<3)+d|0;z=F[o>>2];if((z|0)==-1){break w}x:{if((k|0)!=(z|0)){break x}o=F[o+4>>2];if((o|0)!=-1){z=F[(o<<2)+j>>2]}else{z=-1}if((z|0)==(b|0)){break x}while(1){y:{b=a;g=g+1|0;if((A|0)<=(g|0)){break y}a=b+1|0;J=(a<<3)+d|0;z=F[J>>2];K=(b<<3)+d|0;F[K+4>>2]=F[J+4>>2];F[K>>2]=z;if((z|0)!=-1){continue}}break}F[(b<<3)+d>>2]=-1;if((o|0)==-1){break w}F[y+I>>2]=o;F[y+(o<<2)>>2]=n;break v}a=a+1|0;g=g+1|0;if((A|0)!=(g|0)){continue}break}}a=k<<2;k=F[a+e>>2];if((k|0)<=0){break v}a=F[a+q>>2];g=0;while(1){b=(a<<3)+d|0;if(F[b>>2]==-1){F[b>>2]=p;F[b+4>>2]=n;break v}a=a+1|0;g=g+1|0;if((k|0)!=(g|0)){continue}break}}}n=c;if(n>>>0>>0){continue}break}break l}break i}na();v()}F[w>>2]=t;if(q){ja(q)}if(d){ja(d)}a=F[f+16>>2];if(!a){break j}F[f+20>>2]=a;ja(a)}Z=f+32|0;x=(w|0)!=0;if(x){k=Z-32|0;Z=k;a=F[h>>2];g=F[h+4>>2];F[k+24>>2]=0;F[k+16>>2]=0;F[k+20>>2]=0;if((a|0)==(g|0)){c=g}else{a=g-a|0;if((a|0)<0){break i}a=a>>2;b=(a-1>>>5|0)+1|0;c=ka(b<<2);F[k+24>>2]=b;F[k+20>>2]=0;F[k+16>>2]=c;Yb(k+16|0,a);g=F[h>>2];c=F[h+4>>2]}F[k+8>>2]=0;F[k>>2]=0;while(1){z:{o=0;i=0;if((c|0)==(g|0)){break z}while(1){b=F[k+16>>2];A:{if(F[b+(i>>>3&536870908)>>2]>>>i&1){break A}c=F[k>>2];F[k+4>>2]=c;e=F[h+12>>2];a=i;while(1){B:{f=a+1|0;d=a;a=(f>>>0)%3|0?f:a-2|0;if((a|0)==-1){break B}a=F[e+(a<<2)>>2];if((a|0)==-1){break B}f=a+1|0;a=(f>>>0)%3|0?f:a-2|0;if((i|0)==(a|0)|(a|0)==-1){break B}if(!(F[b+(a>>>3&536870908)>>2]>>>a&1)){continue}}break}j=d;C:{D:{E:{while(1){a=F[k+16>>2]+(j>>>3&536870908)|0;F[a>>2]=F[a>>2]|1<>>0)%3|0?a:j-2|0;g=F[h>>2];y=(j>>>0)%3|0;b=(y?-1:2)+j|0;n=F[k>>2];A=(n|0)==(c|0);F:{if(A){break F}w=F[(f<<2)+g>>2];q=F[h+12>>2];a=n;if((b|0)!=-1){e=q+(b<<2)|0;while(1){G:{if((w|0)!=F[a>>2]){break G}p=F[a+4>>2];t=F[e>>2];if((p|0)==(t|0)){break G}e=b;c=-1;a=-1;if((p|0)==-1){break C}break D}a=a+8|0;if((c|0)!=(a|0)){continue}break}break F}while(1){if((w|0)==F[a>>2]){t=-1;e=-1;p=F[a+4>>2];if((p|0)!=-1){break D}}a=a+8|0;if((c|0)!=(a|0)){continue}break}}b=F[(b<<2)+g>>2];H:{if(F[k+8>>2]!=(c|0)){F[c>>2]=b;F[c+4>>2]=f;c=c+8|0;F[k+4>>2]=c;break H}a=c-n|0;p=a>>3;e=p+1|0;if(e>>>0>=536870912){break i}g=a>>>2|0;g=a>>>0>=2147483640?536870911:e>>>0>>0?g:e;if(g){if(g>>>0>=536870912){break E}e=ka(g<<3)}else{e=0}a=e+(p<<3)|0;F[a>>2]=b;F[a+4>>2]=f;b=a+8|0;if(!A){while(1){c=c-8|0;f=F[c+4>>2];a=a-8|0;F[a>>2]=F[c>>2];F[a+4>>2]=f;if((c|0)!=(n|0)){continue}break}c=F[k>>2]}F[k+8>>2]=e+(g<<3);F[k+4>>2]=b;F[k>>2]=a;if(c){ja(c)}c=b}I:{J:{if(y){a=j-1|0;break J}a=j+2|0;if((a|0)==-1){break I}}a=F[F[h+12>>2]+(a<<2)>>2];if((a|0)==-1){break I}j=a+((a>>>0)%3|0?-1:2)|0;if((d|0)==(j|0)){break I}if((j|0)!=-1){continue}}break}g=F[h>>2];break A}oa();v()}c=F[q+(p<<2)>>2];b=e;a=p}if((t|0)!=-1){F[q+(t<<2)>>2]=-1}if((c|0)!=-1){F[q+(c<<2)>>2]=-1}F[q+(b<<2)>>2]=-1;F[q+(a<<2)>>2]=-1;o=1}i=i+1|0;c=F[h+4>>2];if(i>>>0>2>>>0){continue}break}if(o){continue}}break}a=F[k>>2];if(a){ja(a)}a=F[k+16>>2];if(a){ja(a)}Z=k+32|0;n=0;g=Z-32|0;Z=g;e=F[C+12>>2];F[h+36>>2]=e;p=h+24|0;b=F[h+24>>2];a=F[h+28>>2]-b>>2;K:{L:{if(a>>>0>>0){ab(p,e-a|0,10228);F[g+24>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;break L}if(a>>>0>e>>>0){F[h+28>>2]=b+(e<<2)}F[g+24>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;if(!e){break K}}if((e|0)<0){break i}a=(e-1>>>5|0)+1|0;b=ka(a<<2);F[g+24>>2]=a;F[g+20>>2]=0;F[g+16>>2]=b;Yb(g+16|0,e)}a=F[h>>2];b=F[h+4>>2];F[g+8>>2]=0;F[g>>2]=0;F[g+4>>2]=0;M:{if((a|0)==(b|0)){a=b}else{a=b-a|0;if((a|0)<0){break i}a=a>>2;b=(a-1>>>5|0)+1|0;c=ka(b<<2);F[g+8>>2]=b;F[g+4>>2]=0;F[g>>2]=c;Yb(g,a);b=F[h>>2];a=F[h+4>>2]}if(a-b>>>0<12){break M}N:{while(1){q=L(n,3);d=(q<<2)+b|0;f=F[d>>2];c=-1;i=q+1|0;if((i|0)!=-1){c=F[(i<<2)+b>>2]}O:{if((c|0)==(f|0)){break O}i=f;f=F[d+8>>2];if((i|0)==(f|0)|(c|0)==(f|0)){break O}k=0;i=F[g>>2];while(1){f=k+q|0;if(!(F[(f>>>3&536870908)+i>>2]>>>f&1)){a=F[(f<<2)+b>>2];c=1<>2];b=a>>>5|0;i=F[d+(b<<2)>>2];t=c&i;if(t){c=F[h+28>>2];P:{if((c|0)!=F[h+32>>2]){F[c>>2]=-1;F[h+28>>2]=c+4;break P}i=F[p>>2];b=c-i|0;o=b>>2;d=o+1|0;if(d>>>0>=1073741824){break i}j=b>>>1|0;j=b>>>0>=2147483644?1073741823:d>>>0>>0?j:d;if(j){if(j>>>0>=1073741824){break N}b=ka(j<<2)}else{b=0}d=b+(o<<2)|0;F[d>>2]=-1;o=d+4|0;if((c|0)!=(i|0)){while(1){d=d-4|0;c=c-4|0;F[d>>2]=F[c>>2];if((c|0)!=(i|0)){continue}break}}F[h+32>>2]=b+(j<<2);F[h+28>>2]=o;F[h+24>>2]=d;if(!i){break P}ja(i)}c=F[h+52>>2];Q:{if((c|0)!=F[h+56>>2]){F[c>>2]=a;F[h+52>>2]=c+4;break Q}i=F[h+48>>2];b=c-i|0;o=b>>2;d=o+1|0;if(d>>>0>=1073741824){break i}j=b>>>1|0;j=b>>>0>=2147483644?1073741823:d>>>0>>0?j:d;if(j){if(j>>>0>=1073741824){break N}b=ka(j<<2)}else{b=0}d=b+(o<<2)|0;F[d>>2]=a;a=d+4|0;if((c|0)!=(i|0)){while(1){d=d-4|0;c=c-4|0;F[d>>2]=F[c>>2];if((c|0)!=(i|0)){continue}break}}F[h+56>>2]=b+(j<<2);F[h+52>>2]=a;F[h+48>>2]=d;if(!i){break Q}ja(i)}c=F[g+20>>2];a=F[g+24>>2];if((c|0)==a<<5){if((c+1|0)<0){break i}b=g+16|0;if(c>>>0<=1073741822){a=a<<6;c=(c&-32)+32|0;a=a>>>0>c>>>0?a:c}else{a=2147483647}$a(b,a);c=F[g+20>>2]}F[g+20>>2]=c+1;d=F[g+16>>2];a=d+(c>>>3&536870908)|0;b=F[a>>2];N=a,O=oi(c)&b,F[N>>2]=O;c=1<>>5|0;i=F[(b<<2)+d>>2];a=e;e=a+1|0}F[(b<<2)+d>>2]=c|i;o=F[h+24>>2]+(a<<2)|0;j=F[h+12>>2];b=F[h>>2];i=F[g>>2];c=f;R:{S:{T:{while(1){if((c|0)==-1){break T}d=(c>>>3&536870908)+i|0;F[d>>2]=F[d>>2]|1<>2]=c;if(t){F[(c<<2)+b>>2]=a}w=c+1|0;c=(w>>>0)%3|0?w:c-2|0;d=-1;U:{if((c|0)==-1){break U}c=F[j+(c<<2)>>2];d=-1;if((c|0)==-1){break U}d=c+1|0;d=(d>>>0)%3|0?d:c-2|0}c=d;if((f|0)!=(c|0)){continue}break}if((f|0)!=-1){break R}c=1;break S}if((f>>>0)%3|0){c=f-1|0;break S}c=f+2|0;if((c|0)==-1){break R}}c=F[j+(c<<2)>>2];if((c|0)==-1){break R}V:{if((c>>>0)%3|0){c=c-1|0;break V}c=c+2|0;if((c|0)==-1){break R}}f=F[h+12>>2];b=F[h>>2];while(1){d=(c>>>3&536870908)+i|0;F[d>>2]=F[d>>2]|1<>2]=a}W:{if((c>>>0)%3|0){c=c-1|0;break W}c=c+2|0;if((c|0)==-1){break R}}c=F[f+(c<<2)>>2];if((c|0)==-1){break R}c=c+((c>>>0)%3|0?-1:2)|0;if((c|0)!=-1){continue}break}}}k=k+1|0;if((k|0)!=3){continue}break}b=F[h>>2];a=F[h+4>>2]}n=n+1|0;if(n>>>0<(a-b>>2>>>0)/3>>>0){continue}break}break M}oa();v()}c=0;F[h+44>>2]=0;a=F[g+16>>2];b=F[g+20>>2];if(b){e=b&31;b=(b>>>3&536870908)+a|0;d=a;i=0;while(1){if(!(F[d>>2]>>>c&1)){i=i+1|0;F[h+44>>2]=i}f=(c|0)==31;c=f?0:c+1|0;d=(f<<2)+d|0;if((b|0)!=(d|0)|(c|0)!=(e|0)){continue}break}}b=F[g>>2];if(b){ja(b);a=F[g+16>>2]}if(a){ja(a)}Z=g+32|0}Z=C+16|0;if(!x){F[H+8>>2]=0;Za(h);h=0}Z=H+16|0;a=h;break h}na();v()}b=F[s>>2];if(!b){break d}F[s+4>>2]=b;ja(b)}Z=s+16|0;break b}na();v()}c=F[l+4>>2];b=a;F[l+4>>2]=a;if(c){Za(c);b=F[l+4>>2]}X:{if(!b){break X}a=F[u+100>>2];c=F[u+96>>2];D[r+12|0]=0;Ea(l+56|0,(a-c|0)/12|0,r+12|0);a=F[u+100>>2];c=F[u+96>>2];if((a|0)==(c|0)){break X}while(1){if(!(F[F[l+56>>2]+(E>>>3&536870908)>>2]>>>E&1)){a=L(E,3);Vb(l,0,a);c=F[l+8>>2];e=F[l+12>>2];Vb(l,1,a+1|0);f=F[l+20>>2];d=F[l+24>>2];Vb(l,2,a+2|0);n=(c|0)==(e|0)?-1:0;a=d-f>>2;c=e-c>>2;e=a>>>0>c>>>0;c=F[l+36>>2]-F[l+32>>2]>>2>>>0>(e?a:c)>>>0?2:e?1:n;Y:{if(F[l+68>>2]<=0){break Y}F[r+12>>2]=F[l+76>>2];F[r+8>>2]=m;Qa(r+8|0,r+12|0);a=F[((c<<2)+l|0)+44>>2];if((a|0)<0){a=-1}else{e=(a>>>0)/3|0;a=F[(F[F[l>>2]+96>>2]+L(e,12)|0)+(a-L(e,3)<<2)>>2]}F[r+12>>2]=a;F[r+8>>2]=m;Qa(r+8|0,r+12|0);e=F[l+72>>2];F[l+72>>2]=e+2;if(!(e&1)){break Y}F[r+12>>2]=a;F[r+8>>2]=m;Qa(r+8|0,r+12|0);F[l+72>>2]=F[l+72>>2]+1}d=0;e=Z-16|0;Z=e;F[l+68>>2]=F[l+68>>2]+1;a=L(c,12)+l|0;a=F[a+12>>2]-F[a+8>>2]|0;if((a|0)>0){a=a>>>2|0;h=a>>>0<=1?1:a;c=F[((c<<2)+l|0)+44>>2];while(1){a=c;f=(a>>>0)/3|0;c=(a|0)==-1;g=c?-1:f;i=F[l+56>>2]+(g>>>3&536870908)|0;F[i>>2]=F[i>>2]|1<>2]=F[l+72>>2]+1;Z:{_:{$:{aa:{ba:{if(!d){ca:{if((a|0)>=0){F[e+12>>2]=F[(F[F[l>>2]+96>>2]+L(f,12)|0)+((a>>>0)%3<<2)>>2];F[e+8>>2]=m;Qa(e+8|0,e+12|0);break ca}F[e+12>>2]=-1;F[e+8>>2]=m;Qa(e+8|0,e+12|0);if(c){break ba}}c=-1;f=a+1|0;f=(f>>>0)%3|0?f:a-2|0;if((f|0)>=0){g=(f>>>0)/3|0;f=F[(F[F[l>>2]+96>>2]+L(g,12)|0)+(f-L(g,3)<<2)>>2]}else{f=-1}F[e+12>>2]=f;F[e+8>>2]=m;Qa(e+8|0,e+12|0);f=((a>>>0)%3|0?-1:2)+a|0;if((f|0)<0){break aa}c=(f>>>0)/3|0;c=F[(F[F[l>>2]+96>>2]+L(c,12)|0)+(f-L(c,3)<<2)>>2];break aa}c=(a|0)<0?-1:F[(F[F[l>>2]+96>>2]+L(f,12)|0)+((a>>>0)%3<<2)>>2];F[l+76>>2]=c;F[e+12>>2]=c;F[e+8>>2]=m;Qa(e+8|0,e+12|0);if(d&1){c=-1;if((a|0)==-1){break Z}if((L(f,3)|0)!=(a|0)){a=a-1|0;break _}a=a+2|0;break $}c=-1;if((a|0)==-1){break Z}c=a+1|0;a=(c>>>0)%3|0?c:a-2|0;break $}c=-1;F[e+12>>2]=-1;F[e+8>>2]=m;Qa(e+8|0,e+12|0)}F[l+76>>2]=c;F[e+12>>2]=c;F[e+8>>2]=m;Qa(e+8|0,e+12|0)}c=-1;if((a|0)==-1){break Z}}c=F[F[F[l+4>>2]+12>>2]+(a<<2)>>2]}d=d+1|0;if((h|0)!=(d|0)){continue}break}}Z=e+16|0;c=F[u+96>>2];a=F[u+100>>2]}E=E+1|0;if(E>>>0<(a-c|0)/12>>>0){continue}break}}Z=r+16|0;da:{if(b){a=F[B>>2];if(a){F[B+4>>2]=a;ja(a)}F[B>>2]=F[m>>2];F[B+4>>2]=F[m+4>>2];F[B+8>>2]=F[m+8>>2];M=F[m+84>>2];break da}a=F[m>>2];if(!a){break da}F[m+4>>2]=a;ja(a)}a=F[m+72>>2];if(a){ja(a)}a=F[m+48>>2];if(a){F[m+52>>2]=a;ja(a)}a=F[m+36>>2];if(a){F[m+40>>2]=a;ja(a)}a=F[m+24>>2];if(a){F[m+28>>2]=a;ja(a)}a=F[m+20>>2];F[m+20>>2]=0;if(a){Za(a)}Z=m+96|0;return M|0}function sf(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0;i=b;a=0;b=0;a:{b:{switch(d-1|0){case 0:j=F[i+80>>2];h=G[c+24|0];c:{if((L(j,h)|0)!=(e|0)){break c}d=F[c+28>>2]!=1;b=G[c+84|0];if(!(d|!b)){la(f,F[F[c>>2]>>2]+F[c+48>>2]|0,e);b=1;break c}if(h){a=ka(h);ma(a,0,h)}d:{if(!j){b=1;break d}if(!d){if(h){d=0;e=0;while(1){i=d+f|0;k=F[F[c>>2]>>2];m=F[c+48>>2];g=F[c+40>>2];b=ki(g,F[c+44>>2],G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],0);n=b;b=b+m|0;la(i,la(a,b+k|0,g),h);d=d+h|0;b=1;e=e+1|0;if((j|0)!=(e|0)){continue}break}break d}if(b){b=1;h=F[c>>2];e=F[c+48>>2];f=F[c+40>>2];i=F[c+44>>2];if((j|0)!=1){g=j&-2;c=0;d=0;while(1){k=F[h>>2];m=ki(f,i,c,0)+e|0;k=la(a,k+m|0,f);m=F[h>>2];n=ki(f,i,c|1,0)+e|0;la(k,m+n|0,f);c=c+2|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}g=c}if(!(j&1)){break d}c=F[h>>2];d=ki(g,0,f,i)+e|0;la(a,c+d|0,f);break d}b=1;h=F[c>>2];e=F[c+48>>2];g=F[c+68>>2];f=F[c+40>>2];i=F[c+44>>2];c=0;if((j|0)!=1){k=j&-2;d=0;while(1){m=F[h>>2];n=c<<2;l=ki(f,i,F[n+g>>2],0)+e|0;m=la(a,m+l|0,f);l=F[h>>2];n=ki(f,i,F[g+(n|4)>>2],0)+e|0;la(m,l+n|0,f);c=c+2|0;d=d+2|0;if((k|0)!=(d|0)){continue}break}}if(!(j&1)){break d}d=F[h>>2];c=ki(f,i,F[g+(c<<2)>>2],0)+e|0;la(a,c+d|0,f);break d}b=0;if(!h){d=0;while(1){if(!Cb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],a)){break d}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break d}d=0;e=0;while(1){if(!Cb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],a)){break d}la(d+f|0,a,h);d=d+h|0;e=e+1|0;b=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}}if(!a){break c}ja(a)}break a;case 2:n=G[c+24|0];l=n<<1;j=F[i+80>>2];e:{if((L(l,j)|0)!=(e|0)){break e}i=F[c+28>>2]!=3;d=G[c+84|0];if(!(i|!d)){la(f,F[F[c>>2]>>2]+F[c+48>>2]|0,e);a=1;break e}f:{if(!n){e=0;break f}e=ka(l);ma(e,0,l)}g:{if(!j){a=1;break g}if(!i){o=F[c+68>>2];k=F[c>>2];b=F[c+48>>2];i=F[c+40>>2];m=F[c+44>>2];if(n){if(!d){c=0;d=0;while(1){a=1;g=F[k>>2];p=ki(i,m,F[o+(d<<2)>>2],0)+b|0;la((c<<1)+f|0,la(e,g+p|0,i),l);c=c+n|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break g}c=0;while(1){a=1;o=F[k>>2];p=ki(g,h,i,m)+b|0;la((c<<1)+f|0,la(e,o+p|0,i),l);c=c+n|0;d=h;g=g+1|0;d=g?d:d+1|0;h=d;if((j|0)!=(g|0)|d){continue}break}break g}if(!d){a=1;c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=F[k>>2];g=c<<2;n=ki(i,m,F[g+o>>2],0)+b|0;h=la(e,h+n|0,i);n=F[k>>2];g=ki(i,m,F[o+(g|4)>>2],0)+b|0;la(h,g+n|0,i);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break g}d=F[k>>2];b=ki(i,m,F[o+(c<<2)>>2],0)+b|0;la(e,b+d|0,i);break g}n=j&1;a=1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){d=F[k>>2];l=ki(g,h,i,m)+b|0;d=la(e,d+l|0,i);l=F[k>>2];o=ki(i,m,g|1,h)+b|0;la(d,l+o|0,i);g=g+2|0;h=g>>>0<2?h+1|0:h;f=f+2|0;d=f>>>0<2?c+1|0:c;c=d;if((f|0)!=(j|0)|c){continue}break}}if(!n){break g}c=F[k>>2];b=ki(g,h,i,m)+b|0;la(e,b+c|0,i);break g}if(!n){d=0;while(1){if(!Ab(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break g}d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break g}d=0;while(1){if(!Ab(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break g}la((b<<1)+f|0,e,l);b=b+n|0;d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break e}ja(e)}b=a;break a;case 4:l=G[c+24|0];o=l<<2;j=F[i+80>>2];h:{if((L(o,j)|0)!=(e|0)){break h}i=F[c+28>>2]!=5;d=G[c+84|0];if(!(i|!d)){la(f,F[F[c>>2]>>2]+F[c+48>>2]|0,e);b=1;break h}i:{if(!l){e=0;break i}e=ka(o);ma(e,0,o)}b=1;j:{if(!j){break j}if(!i){a=F[c+68>>2];m=F[c>>2];i=F[c+48>>2];k=F[c+40>>2];n=F[c+44>>2];if(l){if(!d){c=0;d=0;while(1){g=F[m>>2];p=ki(k,n,F[a+(d<<2)>>2],0)+i|0;la((c<<2)+f|0,la(e,g+p|0,k),o);c=c+l|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break j}c=0;while(1){d=F[m>>2];p=ki(g,h,k,n)+i|0;la((c<<2)+f|0,la(e,d+p|0,k),o);c=c+l|0;g=g+1|0;a=g?h:h+1|0;h=a;if((j|0)!=(g|0)|h){continue}break}break j}if(!d){c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=F[m>>2];g=c<<2;l=ki(k,n,F[g+a>>2],0)+i|0;h=la(e,h+l|0,k);l=F[m>>2];g=ki(k,n,F[a+(g|4)>>2],0)+i|0;la(h,g+l|0,k);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break j}d=F[m>>2];a=ki(k,n,F[a+(c<<2)>>2],0)+i|0;la(e,a+d|0,k);break j}l=j&1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){a=F[m>>2];d=ki(g,h,k,n)+i|0;a=la(e,a+d|0,k);d=F[m>>2];o=ki(k,n,g|1,h)+i|0;la(a,d+o|0,k);d=h;g=g+2|0;h=g>>>0<2?d+1|0:d;f=f+2|0;a=f>>>0<2?c+1|0:c;c=a;if((f|0)!=(j|0)|c){continue}break}}if(!l){break j}a=F[m>>2];c=ki(g,h,k,n)+i|0;la(e,a+c|0,k);break j}b=0;if(!l){d=0;while(1){if(!yb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break j}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break j}d=0;while(1){if(!yb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break j}la((a<<2)+f|0,e,o);a=a+l|0;d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break h}ja(e)}break a;case 1:j=F[i+80>>2];h=G[c+24|0];k:{if((L(j,h)|0)!=(e|0)){break k}d=F[c+28>>2]!=2;b=G[c+84|0];if(!(d|!b)){la(f,F[F[c>>2]>>2]+F[c+48>>2]|0,e);b=1;break k}if(h){a=ka(h);ma(a,0,h)}l:{if(!j){b=1;break l}if(!d){if(h){d=0;e=0;while(1){i=d+f|0;k=F[F[c>>2]>>2];m=F[c+48>>2];g=F[c+40>>2];b=ki(g,F[c+44>>2],G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],0);n=b;b=b+m|0;la(i,la(a,b+k|0,g),h);d=d+h|0;b=1;e=e+1|0;if((j|0)!=(e|0)){continue}break}break l}if(b){b=1;h=F[c>>2];e=F[c+48>>2];f=F[c+40>>2];i=F[c+44>>2];if((j|0)!=1){g=j&-2;c=0;d=0;while(1){k=F[h>>2];m=ki(f,i,c,0)+e|0;k=la(a,k+m|0,f);m=F[h>>2];n=ki(f,i,c|1,0)+e|0;la(k,m+n|0,f);c=c+2|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}g=c}if(!(j&1)){break l}c=F[h>>2];d=ki(g,0,f,i)+e|0;la(a,c+d|0,f);break l}b=1;h=F[c>>2];e=F[c+48>>2];g=F[c+68>>2];f=F[c+40>>2];i=F[c+44>>2];c=0;if((j|0)!=1){k=j&-2;d=0;while(1){m=F[h>>2];n=c<<2;l=ki(f,i,F[n+g>>2],0)+e|0;m=la(a,m+l|0,f);l=F[h>>2];n=ki(f,i,F[g+(n|4)>>2],0)+e|0;la(m,l+n|0,f);c=c+2|0;d=d+2|0;if((k|0)!=(d|0)){continue}break}}if(!(j&1)){break l}d=F[h>>2];c=ki(f,i,F[g+(c<<2)>>2],0)+e|0;la(a,c+d|0,f);break l}b=0;if(!h){d=0;while(1){if(!Bb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],a)){break l}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break l}d=0;e=0;while(1){if(!Bb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],a)){break l}la(d+f|0,a,h);d=d+h|0;e=e+1|0;b=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}}if(!a){break k}ja(a)}break a;case 3:n=G[c+24|0];l=n<<1;j=F[i+80>>2];m:{if((L(l,j)|0)!=(e|0)){break m}i=F[c+28>>2]!=4;d=G[c+84|0];if(!(i|!d)){la(f,F[F[c>>2]>>2]+F[c+48>>2]|0,e);a=1;break m}n:{if(!n){e=0;break n}e=ka(l);ma(e,0,l)}o:{if(!j){a=1;break o}if(!i){o=F[c+68>>2];k=F[c>>2];b=F[c+48>>2];i=F[c+40>>2];m=F[c+44>>2];if(n){if(!d){c=0;d=0;while(1){a=1;g=F[k>>2];p=ki(i,m,F[o+(d<<2)>>2],0)+b|0;la((c<<1)+f|0,la(e,g+p|0,i),l);c=c+n|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break o}c=0;while(1){a=1;o=F[k>>2];p=ki(g,h,i,m)+b|0;la((c<<1)+f|0,la(e,o+p|0,i),l);c=c+n|0;d=h;g=g+1|0;d=g?d:d+1|0;h=d;if((j|0)!=(g|0)|d){continue}break}break o}if(!d){a=1;c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=F[k>>2];g=c<<2;n=ki(i,m,F[g+o>>2],0)+b|0;h=la(e,h+n|0,i);n=F[k>>2];g=ki(i,m,F[o+(g|4)>>2],0)+b|0;la(h,g+n|0,i);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break o}d=F[k>>2];b=ki(i,m,F[o+(c<<2)>>2],0)+b|0;la(e,b+d|0,i);break o}n=j&1;a=1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){d=F[k>>2];l=ki(g,h,i,m)+b|0;d=la(e,d+l|0,i);l=F[k>>2];o=ki(i,m,g|1,h)+b|0;la(d,l+o|0,i);g=g+2|0;h=g>>>0<2?h+1|0:h;f=f+2|0;d=f>>>0<2?c+1|0:c;c=d;if((f|0)!=(j|0)|c){continue}break}}if(!n){break o}c=F[k>>2];b=ki(g,h,i,m)+b|0;la(e,b+c|0,i);break o}if(!n){d=0;while(1){if(!zb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break o}d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break o}d=0;while(1){if(!zb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break o}la((b<<1)+f|0,e,l);b=b+n|0;d=d+1|0;a=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break m}ja(e)}b=a;break a;case 5:l=G[c+24|0];o=l<<2;j=F[i+80>>2];p:{if((L(o,j)|0)!=(e|0)){break p}i=F[c+28>>2]!=6;d=G[c+84|0];if(!(i|!d)){la(f,F[F[c>>2]>>2]+F[c+48>>2]|0,e);b=1;break p}q:{if(!l){e=0;break q}e=ka(o);ma(e,0,o)}b=1;r:{if(!j){break r}if(!i){a=F[c+68>>2];m=F[c>>2];i=F[c+48>>2];k=F[c+40>>2];n=F[c+44>>2];if(l){if(!d){c=0;d=0;while(1){g=F[m>>2];p=ki(k,n,F[a+(d<<2)>>2],0)+i|0;la((c<<2)+f|0,la(e,g+p|0,k),o);c=c+l|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}break r}c=0;while(1){d=F[m>>2];p=ki(g,h,k,n)+i|0;la((c<<2)+f|0,la(e,d+p|0,k),o);c=c+l|0;g=g+1|0;a=g?h:h+1|0;h=a;if((j|0)!=(g|0)|h){continue}break}break r}if(!d){c=0;if((j|0)!=1){f=j&-2;d=0;while(1){h=F[m>>2];g=c<<2;l=ki(k,n,F[g+a>>2],0)+i|0;h=la(e,h+l|0,k);l=F[m>>2];g=ki(k,n,F[a+(g|4)>>2],0)+i|0;la(h,g+l|0,k);c=c+2|0;d=d+2|0;if((f|0)!=(d|0)){continue}break}}if(!(j&1)){break r}d=F[m>>2];a=ki(k,n,F[a+(c<<2)>>2],0)+i|0;la(e,a+d|0,k);break r}l=j&1;if((j|0)!=1){j=j&-2;f=0;c=0;while(1){a=F[m>>2];d=ki(g,h,k,n)+i|0;a=la(e,a+d|0,k);d=F[m>>2];o=ki(k,n,g|1,h)+i|0;la(a,d+o|0,k);d=h;g=g+2|0;h=g>>>0<2?d+1|0:d;f=f+2|0;a=f>>>0<2?c+1|0:c;c=a;if((f|0)!=(j|0)|c){continue}break}}if(!l){break r}a=F[m>>2];c=ki(g,h,k,n)+i|0;la(e,a+c|0,k);break r}b=0;if(!l){d=0;while(1){if(!xb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break r}d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}break r}d=0;while(1){if(!xb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],e)){break r}la((a<<2)+f|0,e,o);a=a+l|0;d=d+1|0;b=j>>>0<=d>>>0;if((d|0)!=(j|0)){continue}break}}if(!e){break p}ja(e)}break a;case 8:p=G[c+24|0];q=p<<2;k=F[i+80>>2];s:{if((L(q,k)|0)!=(e|0)){break s}i=F[c+28>>2];t:{if(!p){break t}a=ka(q);d=a;m=q-4|0;l=(m>>>2|0)+1&7;if(l){e=0;while(1){F[d>>2]=-1073741824;d=d+4|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}if(m>>>0<28){break t}e=(p<<2)+a|0;while(1){F[d+24>>2]=-1073741824;F[d+28>>2]=-1073741824;F[d+16>>2]=-1073741824;F[d+20>>2]=-1073741824;F[d+8>>2]=-1073741824;F[d+12>>2]=-1073741824;F[d>>2]=-1073741824;F[d+4>>2]=-1073741824;d=d+32|0;if((e|0)!=(d|0)){continue}break}}u:{if(!k){b=1;break u}if((i|0)==9){r=F[c+68>>2];l=F[c>>2];i=F[c+48>>2];s=G[c+84|0];m=F[c+44>>2];c=F[c+40>>2];o=c;if(p){e=0;d=0;while(1){h=(e<<2)+f|0;g=F[l>>2];b=ki(c,m,s?d:F[r+(d<<2)>>2],0)+i|0;la(h,la(a,b+g|0,o),q);e=e+p|0;b=1;d=d+1|0;if((k|0)!=(d|0)){continue}break}break u}if(!s){b=1;d=0;if((k|0)!=1){f=k&-2;e=0;while(1){h=F[l>>2];g=d<<2;j=ki(c,m,F[g+r>>2],0)+i|0;h=la(a,h+j|0,o);j=F[l>>2];g=ki(c,m,F[r+(g|4)>>2],0)+i|0;la(h,j+g|0,o);d=d+2|0;e=e+2|0;if((f|0)!=(e|0)){continue}break}}if(!(k&1)){break u}e=F[l>>2];c=ki(c,m,F[r+(d<<2)>>2],0)+i|0;la(a,c+e|0,o);break u}f=k&1;b=1;if((k|0)!=1){k=k&-2;while(1){d=F[l>>2];e=ki(g,h,c,m)+i|0;d=la(a,d+e|0,o);e=F[l>>2];p=ki(c,m,g|1,h)+i|0;la(d,e+p|0,o);g=g+2|0;h=g>>>0<2?h+1|0:h;d=j;e=n+2|0;d=e>>>0<2?d+1|0:d;n=e;j=d;if((e|0)!=(k|0)|d){continue}break}}if(!f){break u}d=F[l>>2];c=ki(g,h,c,m)+i|0;la(a,c+d|0,o);break u}if(!p){d=0;while(1){if(!lb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],a)){break u}d=d+1|0;b=k>>>0<=d>>>0;if((d|0)!=(k|0)){continue}break}break u}e=0;d=0;while(1){if(!lb(c,G[c+84|0]?d:F[F[c+68>>2]+(d<<2)>>2],D[c+24|0],a)){break u}la((e<<2)+f|0,a,q);e=e+p|0;d=d+1|0;b=k>>>0<=d>>>0;if((d|0)!=(k|0)){continue}break}}if(!a){break s}ja(a)}a=b;break;default:break b}}b=a}return b|0}function Pd(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;h=Z-80|0;Z=h;e=F[c+36>>2];F[h+72>>2]=F[c+32>>2];F[h+76>>2]=e;f=F[c+28>>2];e=h- -64|0;F[e>>2]=F[c+24>>2];F[e+4>>2]=f;e=F[c+20>>2];F[h+56>>2]=F[c+16>>2];F[h+60>>2]=e;e=F[c+12>>2];F[h+48>>2]=F[c+8>>2];F[h+52>>2]=e;e=F[c+4>>2];F[h+40>>2]=F[c>>2];F[h+44>>2]=e;jc(a,h+40|0,h+24|0);a:{if(F[a>>2]){break a}if(D[a+15|0]<0){ja(F[a+4>>2])}if(G[h+31|0]!=1){b=ka(32);D[b+20|0]=0;c=G[1446]|G[1447]<<8|(G[1448]<<16|G[1449]<<24);D[b+16|0]=c;D[b+17|0]=c>>>8;D[b+18|0]=c>>>16;D[b+19|0]=c>>>24;c=G[1442]|G[1443]<<8|(G[1444]<<16|G[1445]<<24);d=G[1438]|G[1439]<<8|(G[1440]<<16|G[1441]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1434]|G[1435]<<8|(G[1436]<<16|G[1437]<<24);d=G[1430]|G[1431]<<8|(G[1432]<<16|G[1433]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-1;ra(a+4|0,b,20);ja(b);break a}j=Z-16|0;Z=j;b:{c:{switch(G[h+32|0]){case 0:e=Kd(ka(48));F[e>>2]=9864;F[h+8>>2]=0;F[h+12>>2]=0;F[h>>2]=0;F[h+4>>2]=0;F[h+16>>2]=e;break b;case 1:e=Kd(ka(52));F[e+48>>2]=0;F[e>>2]=8176;F[h+8>>2]=0;F[h+12>>2]=0;F[h>>2]=0;F[h+4>>2]=0;F[h+16>>2]=e;break b;default:break c}}f=ka(32);D[f+28|0]=0;e=G[1520]|G[1521]<<8|(G[1522]<<16|G[1523]<<24);D[f+24|0]=e;D[f+25|0]=e>>>8;D[f+26|0]=e>>>16;D[f+27|0]=e>>>24;e=G[1516]|G[1517]<<8|(G[1518]<<16|G[1519]<<24);g=G[1512]|G[1513]<<8|(G[1514]<<16|G[1515]<<24);D[f+16|0]=g;D[f+17|0]=g>>>8;D[f+18|0]=g>>>16;D[f+19|0]=g>>>24;D[f+20|0]=e;D[f+21|0]=e>>>8;D[f+22|0]=e>>>16;D[f+23|0]=e>>>24;e=G[1508]|G[1509]<<8|(G[1510]<<16|G[1511]<<24);g=G[1504]|G[1505]<<8|(G[1506]<<16|G[1507]<<24);D[f+8|0]=g;D[f+9|0]=g>>>8;D[f+10|0]=g>>>16;D[f+11|0]=g>>>24;D[f+12|0]=e;D[f+13|0]=e>>>8;D[f+14|0]=e>>>16;D[f+15|0]=e>>>24;e=G[1500]|G[1501]<<8|(G[1502]<<16|G[1503]<<24);g=G[1496]|G[1497]<<8|(G[1498]<<16|G[1499]<<24);D[f|0]=g;D[f+1|0]=g>>>8;D[f+2|0]=g>>>16;D[f+3|0]=g>>>24;D[f+4|0]=e;D[f+5|0]=e>>>8;D[f+6|0]=e>>>16;D[f+7|0]=e>>>24;F[j>>2]=-1;e=j|4;ra(e,f,28);k=D[j+15|0];F[h>>2]=F[j>>2];g=h+4|0;d:{if((k|0)>=0){k=F[e+4>>2];F[g>>2]=F[e>>2];F[g+4>>2]=k;F[g+8>>2]=F[e+8>>2];F[h+16>>2]=0;break d}ra(g,F[j+4>>2],F[j+8>>2]);e=D[j+15|0];F[h+16>>2]=0;if((e|0)>=0){break d}ja(F[j+4>>2])}ja(f)}Z=j+16|0;e=F[h>>2];e:{if(e){F[a>>2]=e;a=a+4|0;if(D[h+15|0]>=0){b=h|4;c=F[b+4>>2];F[a>>2]=F[b>>2];F[a+4>>2]=c;F[a+8>>2]=F[b+8>>2];break e}ra(a,F[h+4>>2],F[h+8>>2]);break e}e=F[h+16>>2];F[h+16>>2]=0;F[e+44>>2]=d;f=Z-32|0;Z=f;F[e+32>>2]=c;F[e+40>>2]=b;F[e+4>>2]=d;jc(a,c,f+16|0);f:{if(F[a>>2]){break f}if(D[a+15|0]<0){ja(F[a+4>>2])}b=G[f+23|0];if(($[F[F[e>>2]+8>>2]](e)|0)!=(b|0)){b=ka(64);D[b+50|0]=0;c=G[1304]|G[1305]<<8;D[b+48|0]=c;D[b+49|0]=c>>>8;c=G[1300]|G[1301]<<8|(G[1302]<<16|G[1303]<<24);d=G[1296]|G[1297]<<8|(G[1298]<<16|G[1299]<<24);D[b+40|0]=d;D[b+41|0]=d>>>8;D[b+42|0]=d>>>16;D[b+43|0]=d>>>24;D[b+44|0]=c;D[b+45|0]=c>>>8;D[b+46|0]=c>>>16;D[b+47|0]=c>>>24;c=G[1292]|G[1293]<<8|(G[1294]<<16|G[1295]<<24);d=G[1288]|G[1289]<<8|(G[1290]<<16|G[1291]<<24);D[b+32|0]=d;D[b+33|0]=d>>>8;D[b+34|0]=d>>>16;D[b+35|0]=d>>>24;D[b+36|0]=c;D[b+37|0]=c>>>8;D[b+38|0]=c>>>16;D[b+39|0]=c>>>24;c=G[1284]|G[1285]<<8|(G[1286]<<16|G[1287]<<24);d=G[1280]|G[1281]<<8|(G[1282]<<16|G[1283]<<24);D[b+24|0]=d;D[b+25|0]=d>>>8;D[b+26|0]=d>>>16;D[b+27|0]=d>>>24;D[b+28|0]=c;D[b+29|0]=c>>>8;D[b+30|0]=c>>>16;D[b+31|0]=c>>>24;c=G[1276]|G[1277]<<8|(G[1278]<<16|G[1279]<<24);d=G[1272]|G[1273]<<8|(G[1274]<<16|G[1275]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1268]|G[1269]<<8|(G[1270]<<16|G[1271]<<24);d=G[1264]|G[1265]<<8|(G[1266]<<16|G[1267]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1260]|G[1261]<<8|(G[1262]<<16|G[1263]<<24);d=G[1256]|G[1257]<<8|(G[1258]<<16|G[1259]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-1;ra(a+4|0,b,50);ja(b);break f}c=G[f+21|0];D[e+36|0]=c;d=G[f+22|0];D[e+37|0]=d;if((c|0)!=2){b=ka(32);D[b+26|0]=0;c=G[1427]|G[1428]<<8;D[b+24|0]=c;D[b+25|0]=c>>>8;c=G[1423]|G[1424]<<8|(G[1425]<<16|G[1426]<<24);d=G[1419]|G[1420]<<8|(G[1421]<<16|G[1422]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1415]|G[1416]<<8|(G[1417]<<16|G[1418]<<24);d=G[1411]|G[1412]<<8|(G[1413]<<16|G[1414]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1407]|G[1408]<<8|(G[1409]<<16|G[1410]<<24);d=G[1403]|G[1404]<<8|(G[1405]<<16|G[1406]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-5;ra(a+4|0,b,26);ja(b);break f}b=b?2:3;if((b|0)!=(d|0)){b=ka(32);D[b+26|0]=0;c=G[1400]|G[1401]<<8;D[b+24|0]=c;D[b+25|0]=c>>>8;c=G[1396]|G[1397]<<8|(G[1398]<<16|G[1399]<<24);d=G[1392]|G[1393]<<8|(G[1394]<<16|G[1395]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1388]|G[1389]<<8|(G[1390]<<16|G[1391]<<24);d=G[1384]|G[1385]<<8|(G[1386]<<16|G[1387]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1380]|G[1381]<<8|(G[1382]<<16|G[1383]<<24);d=G[1376]|G[1377]<<8|(G[1378]<<16|G[1379]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-5;ra(a+4|0,b,26);ja(b);break f}E[F[e+32>>2]+38>>1]=b|512;g:{if(E[f+26>>1]>=0){break g}j=Z-16|0;Z=j;d=ka(36);b=d;F[b+4>>2]=0;F[b+8>>2]=0;F[b+24>>2]=0;F[b+28>>2]=0;b=b+16|0;F[b>>2]=0;F[b+4>>2]=0;F[d>>2]=d+4;F[d+32>>2]=0;F[d+12>>2]=b;F[j>>2]=0;c=F[e+32>>2];k=Z-16|0;Z=k;b=0;h:{if(!d){break h}F[j>>2]=c;F[k+12>>2]=0;b=0;if(!fb(1,k+12|0,c)){break h}n=F[k+12>>2];if(n){while(1){i:{if(fb(1,k+8|0,F[j>>2])){b=ka(28);F[b+4>>2]=0;F[b+8>>2]=0;c=b+16|0;F[c>>2]=0;F[c+4>>2]=0;F[b>>2]=b+4;F[b+12>>2]=c;F[b+24>>2]=F[k+8>>2];if(Vc(j,b)){break i}Ca(b+12|0,F[b+16>>2]);Ba(b,F[b+4>>2]);ja(b)}b=0;break h}g=Z-16|0;Z=g;F[g+8>>2]=b;j:{if(!b){break j}c=F[d+28>>2];k:{if(c>>>0>2]){F[g+8>>2]=0;F[c>>2]=b;F[d+28>>2]=c+4;break k}c=0;l:{m:{n:{i=F[d+24>>2];m=F[d+28>>2]-i>>2;b=m+1|0;if(b>>>0<1073741824){i=F[d+32>>2]-i|0;l=i>>>1|0;i=i>>>0>=2147483644?1073741823:b>>>0>>0?l:b;if(i){if(i>>>0>=1073741824){break n}c=ka(i<<2)}l=F[g+8>>2];F[g+8>>2]=0;b=(m<<2)+c|0;F[b>>2]=l;i=(i<<2)+c|0;m=b+4|0;c=F[d+28>>2];l=F[d+24>>2];if((c|0)==(l|0)){break m}while(1){c=c-4|0;p=F[c>>2];F[c>>2]=0;b=b-4|0;F[b>>2]=p;if((c|0)!=(l|0)){continue}break}F[d+32>>2]=i;i=F[d+28>>2];F[d+28>>2]=m;c=F[d+24>>2];F[d+24>>2]=b;if((c|0)==(i|0)){break l}while(1){i=i-4|0;b=F[i>>2];F[i>>2]=0;if(b){Ca(b+12|0,F[b+16>>2]);Ba(b,F[b+4>>2]);ja(b)}if((c|0)!=(i|0)){continue}break}break l}na();v()}oa();v()}F[d+32>>2]=i;F[d+28>>2]=m;F[d+24>>2]=b}if(c){ja(c)}}b=F[g+8>>2];F[g+8>>2]=0;if(!b){break j}Ca(b+12|0,F[b+16>>2]);Ba(b,F[b+4>>2]);ja(b)}Z=g+16|0;o=o+1|0;if((n|0)!=(o|0)){continue}break}}b=Vc(j,d)}Z=k+16|0;o:{if(b){c=F[e+4>>2];b=F[c+4>>2];F[c+4>>2]=d;if(b){ic(b)}F[a>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a+12>>2]=0;break o}b=ka(32);D[b+26|0]=0;c=G[1549]|G[1550]<<8;D[b+24|0]=c;D[b+25|0]=c>>>8;c=G[1545]|G[1546]<<8|(G[1547]<<16|G[1548]<<24);g=G[1541]|G[1542]<<8|(G[1543]<<16|G[1544]<<24);D[b+16|0]=g;D[b+17|0]=g>>>8;D[b+18|0]=g>>>16;D[b+19|0]=g>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1537]|G[1538]<<8|(G[1539]<<16|G[1540]<<24);g=G[1533]|G[1534]<<8|(G[1535]<<16|G[1536]<<24);D[b+8|0]=g;D[b+9|0]=g>>>8;D[b+10|0]=g>>>16;D[b+11|0]=g>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1529]|G[1530]<<8|(G[1531]<<16|G[1532]<<24);g=G[1525]|G[1526]<<8|(G[1527]<<16|G[1528]<<24);D[b|0]=g;D[b+1|0]=g>>>8;D[b+2|0]=g>>>16;D[b+3|0]=g>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-1;ra(a+4|0,b,26);ja(b);F[j+8>>2]=0;ic(d)}Z=j+16|0;if(F[a>>2]){break f}if(D[a+15|0]>=0){break g}ja(F[a+4>>2])}if(!($[F[F[e>>2]+12>>2]](e)|0)){b=ka(48);D[b+33|0]=0;D[b+32|0]=G[1374];c=G[1370]|G[1371]<<8|(G[1372]<<16|G[1373]<<24);d=G[1366]|G[1367]<<8|(G[1368]<<16|G[1369]<<24);D[b+24|0]=d;D[b+25|0]=d>>>8;D[b+26|0]=d>>>16;D[b+27|0]=d>>>24;D[b+28|0]=c;D[b+29|0]=c>>>8;D[b+30|0]=c>>>16;D[b+31|0]=c>>>24;c=G[1362]|G[1363]<<8|(G[1364]<<16|G[1365]<<24);d=G[1358]|G[1359]<<8|(G[1360]<<16|G[1361]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1354]|G[1355]<<8|(G[1356]<<16|G[1357]<<24);d=G[1350]|G[1351]<<8|(G[1352]<<16|G[1353]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1346]|G[1347]<<8|(G[1348]<<16|G[1349]<<24);d=G[1342]|G[1343]<<8|(G[1344]<<16|G[1345]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-1;ra(a+4|0,b,33);ja(b);break f}if(!($[F[F[e>>2]+20>>2]](e)|0)){b=Eb(f,1552);F[a>>2]=-1;c=a+4|0;if(D[b+11|0]>=0){d=F[b+4>>2];F[c>>2]=F[b>>2];F[c+4>>2]=d;F[c+8>>2]=F[b+8>>2];break f}ra(c,F[b>>2],F[b+4>>2]);if(D[b+11|0]>=0){break f}ja(F[b>>2]);break f}if(!($[F[F[e>>2]+24>>2]](e)|0)){b=Eb(f,1307);F[a>>2]=-1;c=a+4|0;if(D[b+11|0]>=0){d=F[b+4>>2];F[c>>2]=F[b>>2];F[c+4>>2]=d;F[c+8>>2]=F[b+8>>2];break f}ra(c,F[b>>2],F[b+4>>2]);if(D[b+11|0]>=0){break f}ja(F[b>>2]);break f}F[a>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a+12>>2]=0}Z=f+32|0;if(!F[a>>2]){if(D[a+15|0]<0){ja(F[a+4>>2])}F[a>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a+12>>2]=0}$[F[F[e>>2]+4>>2]](e)}a=F[h+16>>2];F[h+16>>2]=0;if(a){$[F[F[a>>2]+4>>2]](a)}if(D[h+15|0]>=0){break a}ja(F[h+4>>2])}Z=h+80|0}function Ub(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;l=Z-16|0;Z=l;a:{b:{c:{d:{e:{f:{g:{h:{i:{if(a>>>0<=244){g=F[2941];h=a>>>0<11?16:a+11&-8;c=h>>>3|0;b=g>>>c|0;if(b&3){c=c+((b^-1)&1)|0;a=c<<3;b=a+11804|0;d=F[a+11812>>2];a=F[d+8>>2];j:{if((b|0)==(a|0)){m=11764,n=oi(c)&g,F[m>>2]=n;break j}F[a+12>>2]=b;F[b+8>>2]=a}a=d+8|0;b=c<<3;F[d+4>>2]=b|3;b=b+d|0;F[b+4>>2]=F[b+4>>2]|1;break a}k=F[2943];if(k>>>0>=h>>>0){break i}if(b){a=2<>2];a=F[e+8>>2];k:{if((b|0)==(a|0)){g=oi(d)&g;F[2941]=g;break k}F[a+12>>2]=b;F[b+8>>2]=a}F[e+4>>2]=h|3;c=e+h|0;a=d<<3;d=a-h|0;F[c+4>>2]=d|1;F[a+e>>2]=d;if(k){b=(k&-8)+11804|0;f=F[2946];a=1<<(k>>>3);l:{if(!(a&g)){F[2941]=a|g;a=b;break l}a=F[b+8>>2]}F[b+8>>2]=f;F[a+12>>2]=f;F[f+12>>2]=b;F[f+8>>2]=a}a=e+8|0;F[2946]=c;F[2943]=d;break a}j=F[2942];if(!j){break i}c=F[(ji(0-j&j)<<2)+12068>>2];f=(F[c+4>>2]&-8)-h|0;b=c;while(1){m:{a=F[b+16>>2];if(!a){a=F[b+20>>2];if(!a){break m}}b=(F[a+4>>2]&-8)-h|0;d=b>>>0>>0;f=d?b:f;c=d?a:c;b=a;continue}break}i=F[c+24>>2];d=F[c+12>>2];if((d|0)!=(c|0)){a=F[c+8>>2];F[a+12>>2]=d;F[d+8>>2]=a;break b}b=c+20|0;a=F[b>>2];if(!a){a=F[c+16>>2];if(!a){break h}b=c+16|0}while(1){e=b;d=a;b=a+20|0;a=F[b>>2];if(a){continue}b=d+16|0;a=F[d+16>>2];if(a){continue}break}F[e>>2]=0;break b}h=-1;if(a>>>0>4294967231){break i}a=a+11|0;h=a&-8;j=F[2942];if(!j){break i}f=0-h|0;g=0;n:{if(h>>>0<256){break n}g=31;if(h>>>0>16777215){break n}a=O(a>>>8|0);g=((h>>>38-a&1)-(a<<1)|0)+62|0}b=F[(g<<2)+12068>>2];o:{p:{q:{if(!b){a=0;break q}a=0;c=h<<((g|0)!=31?25-(g>>>1|0)|0:0);while(1){r:{e=(F[b+4>>2]&-8)-h|0;if(e>>>0>=f>>>0){break r}d=b;f=e;if(e){break r}f=0;a=b;break p}e=F[b+20>>2];b=F[((c>>>29&4)+b|0)+16>>2];a=e?(e|0)==(b|0)?a:e:a;c=c<<1;if(b){continue}break}}if(!(a|d)){d=0;a=2<>2]}if(!a){break o}}while(1){b=(F[a+4>>2]&-8)-h|0;c=b>>>0>>0;f=c?b:f;d=c?a:d;b=F[a+16>>2];if(b){a=b}else{a=F[a+20>>2]}if(a){continue}break}}if(!d|F[2943]-h>>>0<=f>>>0){break i}g=F[d+24>>2];c=F[d+12>>2];if((d|0)!=(c|0)){a=F[d+8>>2];F[a+12>>2]=c;F[c+8>>2]=a;break c}b=d+20|0;a=F[b>>2];if(!a){a=F[d+16>>2];if(!a){break g}b=d+16|0}while(1){e=b;c=a;b=a+20|0;a=F[b>>2];if(a){continue}b=c+16|0;a=F[c+16>>2];if(a){continue}break}F[e>>2]=0;break c}a=F[2943];if(a>>>0>=h>>>0){d=F[2946];b=a-h|0;s:{if(b>>>0>=16){c=d+h|0;F[c+4>>2]=b|1;F[a+d>>2]=b;F[d+4>>2]=h|3;break s}F[d+4>>2]=a|3;a=a+d|0;F[a+4>>2]=F[a+4>>2]|1;c=0;b=0}F[2943]=b;F[2946]=c;a=d+8|0;break a}i=F[2944];if(i>>>0>h>>>0){b=i-h|0;F[2944]=b;c=F[2947];a=c+h|0;F[2947]=a;F[a+4>>2]=b|1;F[c+4>>2]=h|3;a=c+8|0;break a}a=0;j=h+47|0;if(F[3059]){c=F[3061]}else{F[3062]=-1;F[3063]=-1;F[3060]=4096;F[3061]=4096;F[3059]=l+12&-16^1431655768;F[3064]=0;F[3052]=0;c=4096}e=j+c|0;f=0-c|0;b=e&f;if(b>>>0<=h>>>0){break a}d=F[3051];if(d){c=F[3049];g=c+b|0;if(d>>>0>>0|c>>>0>=g>>>0){break a}}t:{if(!(G[12208]&4)){u:{v:{w:{x:{d=F[2947];if(d){a=12212;while(1){c=F[a>>2];if(c>>>0<=d>>>0&d>>>0>2]>>>0){break x}a=F[a+8>>2];if(a){continue}break}}c=eb(0);if((c|0)==-1){break u}g=b;d=F[3060];a=d-1|0;if(a&c){g=(b-c|0)+(a+c&0-d)|0}if(g>>>0<=h>>>0){break u}d=F[3051];if(d){a=F[3049];f=a+g|0;if(d>>>0>>0|a>>>0>=f>>>0){break u}}a=eb(g);if((c|0)!=(a|0)){break w}break t}g=f&e-i;c=eb(g);if((c|0)==(F[a>>2]+F[a+4>>2]|0)){break v}a=c}if((a|0)==-1){break u}if(h+48>>>0<=g>>>0){c=a;break t}c=F[3061];c=c+(j-g|0)&0-c;if((eb(c)|0)==-1){break u}g=c+g|0;c=a;break t}if((c|0)!=-1){break t}}F[3052]=F[3052]|4}c=eb(b);a=eb(0);if((c|0)==-1|(a|0)==-1|a>>>0<=c>>>0){break d}g=a-c|0;if(g>>>0<=h+40>>>0){break d}}a=F[3049]+g|0;F[3049]=a;if(a>>>0>I[3050]){F[3050]=a}y:{e=F[2947];if(e){a=12212;while(1){d=F[a>>2];b=F[a+4>>2];if((d+b|0)==(c|0)){break y}a=F[a+8>>2];if(a){continue}break}break f}a=F[2945];if(!(a>>>0<=c>>>0?a:0)){F[2945]=c}a=0;F[3054]=g;F[3053]=c;F[2949]=-1;F[2950]=F[3059];F[3056]=0;while(1){d=a<<3;b=d+11804|0;F[d+11812>>2]=b;F[d+11816>>2]=b;a=a+1|0;if((a|0)!=32){continue}break}d=g-40|0;a=c+8&7?-8-c&7:0;b=d-a|0;F[2944]=b;a=a+c|0;F[2947]=a;F[a+4>>2]=b|1;F[(c+d|0)+4>>2]=40;F[2948]=F[3063];break e}if(G[a+12|0]&8|d>>>0>e>>>0|c>>>0<=e>>>0){break f}F[a+4>>2]=b+g;a=e+8&7?-8-e&7:0;c=a+e|0;F[2947]=c;b=F[2944]+g|0;a=b-a|0;F[2944]=a;F[c+4>>2]=a|1;F[(b+e|0)+4>>2]=40;F[2948]=F[3063];break e}d=0;break b}c=0;break c}if(I[2945]>c>>>0){F[2945]=c}b=c+g|0;a=12212;z:{A:{B:{C:{D:{E:{while(1){if((b|0)!=F[a>>2]){a=F[a+8>>2];if(a){continue}break E}break}if(!(G[a+12|0]&8)){break D}}a=12212;while(1){b=F[a>>2];if(b>>>0<=e>>>0){f=b+F[a+4>>2]|0;if(f>>>0>e>>>0){break C}}a=F[a+8>>2];continue}}F[a>>2]=c;F[a+4>>2]=F[a+4>>2]+g;j=(c+8&7?-8-c&7:0)+c|0;F[j+4>>2]=h|3;g=b+(b+8&7?-8-b&7:0)|0;i=h+j|0;a=g-i|0;if((e|0)==(g|0)){F[2947]=i;a=F[2944]+a|0;F[2944]=a;F[i+4>>2]=a|1;break A}if(F[2946]==(g|0)){F[2946]=i;a=F[2943]+a|0;F[2943]=a;F[i+4>>2]=a|1;F[a+i>>2]=a;break A}f=F[g+4>>2];if((f&3)==1){e=f&-8;F:{if(f>>>0<=255){d=F[g+8>>2];b=f>>>3|0;c=F[g+12>>2];if((c|0)==(d|0)){m=11764,n=F[2941]&oi(b),F[m>>2]=n;break F}F[d+12>>2]=c;F[c+8>>2]=d;break F}h=F[g+24>>2];c=F[g+12>>2];G:{if((g|0)!=(c|0)){b=F[g+8>>2];F[b+12>>2]=c;F[c+8>>2]=b;break G}H:{f=g+20|0;b=F[f>>2];if(b){break H}f=g+16|0;b=F[f>>2];if(b){break H}c=0;break G}while(1){d=f;c=b;f=c+20|0;b=F[f>>2];if(b){continue}f=c+16|0;b=F[c+16>>2];if(b){continue}break}F[d>>2]=0}if(!h){break F}d=F[g+28>>2];b=(d<<2)+12068|0;I:{if(F[b>>2]==(g|0)){F[b>>2]=c;if(c){break I}m=11768,n=F[2942]&oi(d),F[m>>2]=n;break F}F[h+(F[h+16>>2]==(g|0)?16:20)>>2]=c;if(!c){break F}}F[c+24>>2]=h;b=F[g+16>>2];if(b){F[c+16>>2]=b;F[b+24>>2]=c}b=F[g+20>>2];if(!b){break F}F[c+20>>2]=b;F[b+24>>2]=c}g=e+g|0;f=F[g+4>>2];a=a+e|0}F[g+4>>2]=f&-2;F[i+4>>2]=a|1;F[a+i>>2]=a;if(a>>>0<=255){b=(a&-8)+11804|0;c=F[2941];a=1<<(a>>>3);J:{if(!(c&a)){F[2941]=a|c;a=b;break J}a=F[b+8>>2]}F[b+8>>2]=i;F[a+12>>2]=i;F[i+12>>2]=b;F[i+8>>2]=a;break A}f=31;if(a>>>0<=16777215){b=O(a>>>8|0);f=((a>>>38-b&1)-(b<<1)|0)+62|0}F[i+28>>2]=f;F[i+16>>2]=0;F[i+20>>2]=0;b=(f<<2)+12068|0;d=F[2942];c=1<>2]=i;break K}f=a<<((f|0)!=31?25-(f>>>1|0)|0:0);c=F[b>>2];while(1){b=c;if((F[c+4>>2]&-8)==(a|0)){break B}c=f>>>29|0;f=f<<1;d=(c&4)+b|0;c=F[d+16>>2];if(c){continue}break}F[d+16>>2]=i}F[i+24>>2]=b;F[i+12>>2]=i;F[i+8>>2]=i;break A}d=g-40|0;a=c+8&7?-8-c&7:0;b=d-a|0;F[2944]=b;a=a+c|0;F[2947]=a;F[a+4>>2]=b|1;F[(c+d|0)+4>>2]=40;F[2948]=F[3063];a=(f+(f-39&7?39-f&7:0)|0)-47|0;d=a>>>0>>0?e:a;F[d+4>>2]=27;a=F[3056];F[d+16>>2]=F[3055];F[d+20>>2]=a;a=F[3054];F[d+8>>2]=F[3053];F[d+12>>2]=a;F[3055]=d+8;F[3054]=g;F[3053]=c;F[3056]=0;a=d+24|0;while(1){F[a+4>>2]=7;b=a+8|0;a=a+4|0;if(b>>>0>>0){continue}break}if((d|0)==(e|0)){break e}F[d+4>>2]=F[d+4>>2]&-2;f=d-e|0;F[e+4>>2]=f|1;F[d>>2]=f;if(f>>>0<=255){b=(f&-8)+11804|0;c=F[2941];a=1<<(f>>>3);L:{if(!(c&a)){F[2941]=a|c;a=b;break L}a=F[b+8>>2]}F[b+8>>2]=e;F[a+12>>2]=e;F[e+12>>2]=b;F[e+8>>2]=a;break e}a=31;if(f>>>0<=16777215){a=O(f>>>8|0);a=((f>>>38-a&1)-(a<<1)|0)+62|0}F[e+28>>2]=a;F[e+16>>2]=0;F[e+20>>2]=0;b=(a<<2)+12068|0;d=F[2942];c=1<>2]=e;break M}a=f<<((a|0)!=31?25-(a>>>1|0)|0:0);d=F[b>>2];while(1){b=d;if((f|0)==(F[b+4>>2]&-8)){break z}c=a>>>29|0;a=a<<1;c=(c&4)+b|0;d=F[c+16>>2];if(d){continue}break}F[c+16>>2]=e}F[e+24>>2]=b;F[e+12>>2]=e;F[e+8>>2]=e;break e}a=F[b+8>>2];F[a+12>>2]=i;F[b+8>>2]=i;F[i+24>>2]=0;F[i+12>>2]=b;F[i+8>>2]=a}a=j+8|0;break a}a=F[b+8>>2];F[a+12>>2]=e;F[b+8>>2]=e;F[e+24>>2]=0;F[e+12>>2]=b;F[e+8>>2]=a}a=F[2944];if(a>>>0<=h>>>0){break d}b=a-h|0;F[2944]=b;c=F[2947];a=c+h|0;F[2947]=a;F[a+4>>2]=b|1;F[c+4>>2]=h|3;a=c+8|0;break a}F[2940]=48;a=0;break a}N:{if(!g){break N}b=F[d+28>>2];a=(b<<2)+12068|0;O:{if(F[a>>2]==(d|0)){F[a>>2]=c;if(c){break O}j=oi(b)&j;F[2942]=j;break N}F[g+(F[g+16>>2]==(d|0)?16:20)>>2]=c;if(!c){break N}}F[c+24>>2]=g;a=F[d+16>>2];if(a){F[c+16>>2]=a;F[a+24>>2]=c}a=F[d+20>>2];if(!a){break N}F[c+20>>2]=a;F[a+24>>2]=c}P:{if(f>>>0<=15){a=f+h|0;F[d+4>>2]=a|3;a=a+d|0;F[a+4>>2]=F[a+4>>2]|1;break P}F[d+4>>2]=h|3;e=d+h|0;F[e+4>>2]=f|1;F[e+f>>2]=f;if(f>>>0<=255){b=(f&-8)+11804|0;c=F[2941];a=1<<(f>>>3);Q:{if(!(c&a)){F[2941]=a|c;a=b;break Q}a=F[b+8>>2]}F[b+8>>2]=e;F[a+12>>2]=e;F[e+12>>2]=b;F[e+8>>2]=a;break P}a=31;if(f>>>0<=16777215){a=O(f>>>8|0);a=((f>>>38-a&1)-(a<<1)|0)+62|0}F[e+28>>2]=a;F[e+16>>2]=0;F[e+20>>2]=0;b=(a<<2)+12068|0;R:{c=1<>2]=e;break S}a=f<<((a|0)!=31?25-(a>>>1|0)|0:0);h=F[b>>2];while(1){b=h;if((F[b+4>>2]&-8)==(f|0)){break R}c=a>>>29|0;a=a<<1;c=(c&4)+b|0;h=F[c+16>>2];if(h){continue}break}F[c+16>>2]=e}F[e+24>>2]=b;F[e+12>>2]=e;F[e+8>>2]=e;break P}a=F[b+8>>2];F[a+12>>2]=e;F[b+8>>2]=e;F[e+24>>2]=0;F[e+12>>2]=b;F[e+8>>2]=a}a=d+8|0;break a}T:{if(!i){break T}b=F[c+28>>2];a=(b<<2)+12068|0;U:{if(F[a>>2]==(c|0)){F[a>>2]=d;if(d){break U}m=11768,n=oi(b)&j,F[m>>2]=n;break T}F[i+(F[i+16>>2]==(c|0)?16:20)>>2]=d;if(!d){break T}}F[d+24>>2]=i;a=F[c+16>>2];if(a){F[d+16>>2]=a;F[a+24>>2]=d}a=F[c+20>>2];if(!a){break T}F[d+20>>2]=a;F[a+24>>2]=d}V:{if(f>>>0<=15){a=f+h|0;F[c+4>>2]=a|3;a=a+c|0;F[a+4>>2]=F[a+4>>2]|1;break V}F[c+4>>2]=h|3;d=c+h|0;F[d+4>>2]=f|1;F[d+f>>2]=f;if(k){b=(k&-8)+11804|0;e=F[2946];a=1<<(k>>>3);W:{if(!(a&g)){F[2941]=a|g;a=b;break W}a=F[b+8>>2]}F[b+8>>2]=e;F[a+12>>2]=e;F[e+12>>2]=b;F[e+8>>2]=a}F[2946]=d;F[2943]=f}a=c+8|0}Z=l+16|0;return a|0}function Vc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0;m=Z-32|0;Z=m;o=ka(12);F[o+8>>2]=0;F[o+4>>2]=b;F[o>>2]=0;s=o+12|0;b=s;a:{b:{c:{while(1){b=b-12|0;w=F[b+8>>2];j=F[b+4>>2];t=F[b>>2];if(t){if((w|0)>1e3){break a}F[m+24>>2]=0;F[m+16>>2]=0;F[m+20>>2]=0;d=1;c=F[a>>2];e=F[c+8>>2];h=F[c+12>>2];g=F[c+20>>2];f=F[c+16>>2];d:{if((h|0)<=(g|0)&f>>>0>=e>>>0|(g|0)>(h|0)){break d}e=G[f+F[c>>2]|0];h=c;c=g;f=f+1|0;c=f?c:c+1|0;F[h+16>>2]=f;F[h+20>>2]=c;Sb(m+16|0,e);if(e){c=F[a>>2];n=Tb(m+16|0);p=F[c+8>>2];g=F[c+12>>2];h=F[c+20>>2];f=F[c+16>>2];k=f+e|0;h=k>>>0>>0?h+1|0:h;if((g|0)<=(h|0)&k>>>0>p>>>0|(g|0)<(h|0)){break d}la(n,f+F[c>>2]|0,e);d=F[c+20>>2];f=e;e=e+F[c+16>>2]|0;d=f>>>0>e>>>0?d+1|0:d;F[c+16>>2]=e;F[c+20>>2]=d}j=ka(24);c=j;F[c+4>>2]=0;F[c+8>>2]=0;c=c+16|0;F[c>>2]=0;F[c+4>>2]=0;F[j>>2]=j+4;F[j+12>>2]=c;e=Z-32|0;Z=e;h=t+12|0;c=m+16|0;u=Ya(h,c);i=t+16|0;e:{if((u|0)==(i|0)){F[e+16>>2]=c;f:{g:{d=F[h+4>>2];h:{if(!d){f=h+4|0;c=f;break h}f=G[c+11|0];g=f<<24>>24<0;n=g?F[c>>2]:c;g=g?F[c+4>>2]:f;while(1){c=d;d=G[c+27|0];f=d<<24>>24<0;d=f?F[c+20>>2]:d;p=d>>>0>>0;i:{j:{k:{l:{k=p?d:g;m:{if(k){f=f?F[c+16>>2]:c+16|0;q=sa(n,f,k);if(!q){if(d>>>0>g>>>0){break m}break l}if((q|0)>=0){break l}break m}if(d>>>0<=g>>>0){break k}}f=c;d=F[c>>2];if(d){continue}break h}d=sa(f,n,k);if(d){break j}}if(p){break i}break g}if((d|0)>=0){break g}}d=F[c+4>>2];if(d){continue}break}f=c+4|0}d=ka(32);n=d+16|0;g=F[e+16>>2];n:{if(D[g+11|0]>=0){p=F[g+4>>2];F[n>>2]=F[g>>2];F[n+4>>2]=p;F[n+8>>2]=F[g+8>>2];break n}ra(n,F[g>>2],F[g+4>>2])}F[d+8>>2]=c;F[d>>2]=0;F[d+4>>2]=0;F[d+28>>2]=0;F[f>>2]=d;c=d;g=F[F[h>>2]>>2];if(g){F[h>>2]=g;c=F[f>>2]}nb(F[h+4>>2],c);F[h+8>>2]=F[h+8>>2]+1;c=1;break f}d=c;c=0}D[e+28|0]=c;F[e+24>>2]=d;d=F[e+24>>2];c=F[d+28>>2];F[d+28>>2]=j;if(!c){break e}Ca(c+12|0,F[c+16>>2]);Ba(c,F[c+4>>2]);ja(c);break e}if(!j){break e}Ca(j+12|0,F[j+16>>2]);Ba(j,F[j+4>>2]);ja(j)}Z=e+32|0;d=(i|0)!=(u|0)}if(D[m+27|0]<0){ja(F[m+16>>2])}if(d){break a}}if(!j){break a}F[m+16>>2]=0;if(!fb(1,m+16|0,F[a>>2])){break a}q=0;x=F[m+16>>2];if(x){while(1){d=0;i=Z-32|0;Z=i;F[i+24>>2]=0;F[i+16>>2]=0;F[i+20>>2]=0;c=F[a>>2];f=F[c+8>>2];o:{p:{h=F[c+12>>2];g=F[c+20>>2];e=F[c+16>>2];q:{if((h|0)<=(g|0)&e>>>0>=f>>>0|(g|0)>(h|0)){break q}f=G[e+F[c>>2]|0];h=c;c=g;e=e+1|0;c=e?c:c+1|0;F[h+16>>2]=e;F[h+20>>2]=c;Sb(i+16|0,f);if(f){e=F[a>>2];n=Tb(i+16|0);p=F[e+8>>2];g=F[e+12>>2];c=F[e+20>>2];h=F[e+16>>2];k=h+f|0;c=k>>>0>>0?c+1|0:c;if(k>>>0>p>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break q}la(n,h+F[e>>2]|0,f);c=F[e+20>>2];g=f;f=f+F[e+16>>2]|0;c=g>>>0>f>>>0?c+1|0:c;F[e+16>>2]=f;F[e+20>>2]=c}F[i+12>>2]=0;if(!fb(1,i+12|0,F[a>>2])){break q}f=F[i+12>>2];if(!f){break q}e=F[a>>2];c=F[e+8>>2];h=F[e+16>>2];g=c-h|0;c=F[e+12>>2]-(F[e+20>>2]+(c>>>0>>0)|0)|0;if((c|0)<=0&f>>>0>g>>>0|(c|0)<0){break q}F[i+8>>2]=0;F[i>>2]=0;F[i+4>>2]=0;if((f|0)<0){break p}d=ka(f);F[i>>2]=d;c=d+f|0;F[i+8>>2]=c;l=ma(d,0,f);F[i+4>>2]=c;h=F[e+12>>2];y=h;p=F[e+8>>2];c=F[e+20>>2];k=F[e+16>>2];g=f+k|0;c=g>>>0>>0?c+1|0:c;u=g;n=c;r:{if((c|0)<=(h|0)&g>>>0<=p>>>0|(c|0)<(h|0)){la(l,F[e>>2]+k|0,f);d=F[e+20>>2];c=f+F[e+16>>2]|0;d=c>>>0>>0?d+1|0:d;F[e+16>>2]=c;F[e+20>>2]=d;h=Z-48|0;Z=h;e=Ya(j,i+16|0);if((e|0)!=(j+4|0)){c=F[e+4>>2];s:{if(!c){c=e;while(1){d=F[c+8>>2];f=F[d>>2]!=(c|0);c=d;if(f){continue}break}break s}while(1){d=c;c=F[c>>2];if(c){continue}break}}if((e|0)==F[j>>2]){F[j>>2]=d}F[j+8>>2]=F[j+8>>2]-1;f=F[j+4>>2];t:{u:{g=e;d=e;e=F[d>>2];if(e){c=F[g+4>>2];if(!c){break u}while(1){d=c;c=F[c>>2];if(c){continue}break}}e=F[d+4>>2];if(e){break u}e=0;k=1;break t}F[e+8>>2]=F[d+8>>2];k=0}l=F[d+8>>2];c=F[l>>2];v:{if((d|0)==(c|0)){F[l>>2]=e;if((d|0)==(f|0)){c=0;f=e;break v}c=F[l+4>>2];break v}F[l+4>>2]=e}r=!G[d+12|0];if((d|0)!=(g|0)){l=F[g+8>>2];F[d+8>>2]=l;F[l+(((g|0)!=F[F[g+8>>2]>>2])<<2)>>2]=d;l=F[g>>2];F[d>>2]=l;F[l+8>>2]=d;l=F[g+4>>2];F[d+4>>2]=l;if(l){F[l+8>>2]=d}D[d+12|0]=G[g+12|0];f=(f|0)==(g|0)?d:f}w:{if(r|!f){break w}if(k){while(1){e=G[c+12|0];x:{d=F[c+8>>2];if(F[d>>2]!=(c|0)){if(!e){D[c+12|0]=1;D[d+12|0]=0;e=F[d+4>>2];k=F[e>>2];F[d+4>>2]=k;if(k){F[k+8>>2]=d}F[e+8>>2]=F[d+8>>2];k=F[d+8>>2];F[(((d|0)!=F[k>>2])<<2)+k>>2]=e;F[e>>2]=d;F[d+8>>2]=e;d=c;c=F[c>>2];f=(c|0)==(f|0)?d:f;c=F[c+4>>2]}y:{z:{d=F[c>>2];A:{if(!(G[d+12|0]?0:d)){e=F[c+4>>2];if(G[e+12|0]?0:e){break A}D[c+12|0]=0;c=F[c+8>>2];B:{if((f|0)==(c|0)){c=f;break B}if(G[c+12|0]){break x}}D[c+12|0]=1;break w}e=F[c+4>>2];if(!e){break z}}if(G[e+12|0]){break z}d=c;break y}D[d+12|0]=1;D[c+12|0]=0;e=F[d+4>>2];F[c>>2]=e;if(e){F[e+8>>2]=c}F[d+8>>2]=F[c+8>>2];e=F[c+8>>2];F[((F[e>>2]!=(c|0))<<2)+e>>2]=d;F[d+4>>2]=c;F[c+8>>2]=d;e=c}c=F[d+8>>2];D[d+12|0]=G[c+12|0];D[c+12|0]=1;D[e+12|0]=1;d=F[c+4>>2];e=F[d>>2];F[c+4>>2]=e;if(e){F[e+8>>2]=c}F[d+8>>2]=F[c+8>>2];e=F[c+8>>2];F[(((c|0)!=F[e>>2])<<2)+e>>2]=d;F[d>>2]=c;F[c+8>>2]=d;break w}if(!e){D[c+12|0]=1;D[d+12|0]=0;e=F[c+4>>2];F[d>>2]=e;if(e){F[e+8>>2]=d}F[c+8>>2]=F[d+8>>2];e=F[d+8>>2];F[(((d|0)!=F[e>>2])<<2)+e>>2]=c;F[c+4>>2]=d;F[d+8>>2]=c;f=(d|0)==(f|0)?c:f;c=F[d>>2]}e=F[c>>2];C:{if(!(!e|G[e+12|0])){d=c;break C}d=F[c+4>>2];if(!(G[d+12|0]?0:d)){D[c+12|0]=0;c=F[c+8>>2];if((c|0)!=(f|0)?G[c+12|0]:0){break x}D[c+12|0]=1;break w}if(e){if(!G[e+12|0]){d=c;break C}d=F[c+4>>2]}D[d+12|0]=1;D[c+12|0]=0;e=F[d>>2];F[c+4>>2]=e;if(e){F[e+8>>2]=c}F[d+8>>2]=F[c+8>>2];e=F[c+8>>2];F[((F[e>>2]!=(c|0))<<2)+e>>2]=d;F[d>>2]=c;F[c+8>>2]=d;e=c}c=F[d+8>>2];D[d+12|0]=G[c+12|0];D[c+12|0]=1;D[e+12|0]=1;d=F[c>>2];e=F[d+4>>2];F[c>>2]=e;if(e){F[e+8>>2]=c}F[d+8>>2]=F[c+8>>2];e=F[c+8>>2];F[(((c|0)!=F[e>>2])<<2)+e>>2]=d;F[d+4>>2]=c;F[c+8>>2]=d;break w}d=c;c=F[c+8>>2];c=F[(((d|0)==F[c>>2])<<2)+c>>2];continue}}D[e+12|0]=1}c=F[g+28>>2];if(c){F[g+32>>2]=c;ja(c)}if(D[g+27|0]<0){ja(F[g+16>>2])}ja(g)}F[h+8>>2]=0;F[h>>2]=0;F[h+4>>2]=0;c=F[i+4>>2];d=F[i>>2];f=c-d|0;e=0;D:{E:{if((c|0)!=(d|0)){if((f|0)<0){break E}e=ka(f);c=ma(e,0,f);g=c+f|0;F[h+8>>2]=g;F[h+4>>2]=g;F[h>>2]=c;c=d}la(e,c,f);F:{if(D[i+27|0]>=0){F[h+24>>2]=F[i+24>>2];c=F[i+20>>2];F[h+16>>2]=F[i+16>>2];F[h+20>>2]=c;break F}ra(h+16|0,F[i+16>>2],F[i+20>>2])}Tc(h+28|0,h);f=h+16|0;c=f;G:{H:{d=F[j+4>>2];I:{if(!d){e=j+4|0;c=e;break I}e=G[c+11|0];g=e<<24>>24<0;k=g?F[c>>2]:c;g=g?F[c+4>>2]:e;while(1){c=d;d=G[c+27|0];e=d<<24>>24<0;d=e?F[c+20>>2]:d;l=d>>>0>>0;J:{K:{L:{M:{r=l?d:g;N:{if(r){e=e?F[c+16>>2]:c+16|0;z=sa(k,e,r);if(!z){if(d>>>0>g>>>0){break N}break M}if((z|0)>=0){break M}break N}if(d>>>0<=g>>>0){break L}}e=c;d=F[c>>2];if(d){continue}break I}d=sa(e,k,r);if(d){break K}}if(l){break J}break H}if((d|0)>=0){break H}}d=F[c+4>>2];if(d){continue}break}e=c+4|0}d=ka(40);F[d+24>>2]=F[f+8>>2];g=F[f+4>>2];F[d+16>>2]=F[f>>2];F[d+20>>2]=g;F[f>>2]=0;F[f+4>>2]=0;F[f+8>>2]=0;Tc(d+28|0,f+12|0);F[d+8>>2]=c;F[d>>2]=0;F[d+4>>2]=0;F[e>>2]=d;c=d;f=F[F[j>>2]>>2];if(f){F[j>>2]=f;c=F[e>>2]}nb(F[j+4>>2],c);F[j+8>>2]=F[j+8>>2]+1;c=1;break G}d=c;c=0}D[h+44|0]=c;F[h+40>>2]=d;c=F[h+28>>2];if(c){F[h+32>>2]=c;ja(c)}if(D[h+27|0]<0){ja(F[h+16>>2])}c=F[h>>2];if(c){F[h+4>>2]=c;ja(c)}Z=h+48|0;break D}na();v()}d=F[i>>2];if(!d){break r}}F[i+4>>2]=d;ja(d)}d=(n|0)<=(y|0)&p>>>0>=u>>>0|(n|0)<(y|0)}if(D[i+27|0]<0){ja(F[i+16>>2])}Z=i+32|0;break o}na();v()}if(!d){break a}q=q+1|0;if((x|0)!=(q|0)){continue}break}}F[m+12>>2]=0;if(!fb(1,m+12|0,F[a>>2])){break a}c=F[a>>2];e=F[c+8>>2];f=F[c+16>>2];h=e-f|0;d=F[m+12>>2];c=F[c+12>>2]-(F[c+20>>2]+(e>>>0>>0)|0)|0;if(h>>>0>>0&(c|0)<=0|(c|0)<0){break a}if(d){q=0;h=((t|0)!=0)+w|0;while(1){O:{if(b>>>0>>0){F[b+8>>2]=h;F[b+4>>2]=0;F[b>>2]=j;b=b+12|0;d=F[m+12>>2];break O}c=b-o|0;g=(c|0)/12|0;b=g+1|0;if(b>>>0>=357913942){break c}e=(s-o|0)/12|0;f=e<<1;e=e>>>0>=178956970?357913941:b>>>0>>0?f:b;if(e){if(e>>>0>=357913942){break b}f=ka(L(e,12))}else{f=0}b=f+L(g,12)|0;F[b+8>>2]=h;F[b+4>>2]=0;F[b>>2]=j;c=pa(b+L((c|0)/-12|0,12)|0,o,c);s=f+L(e,12)|0;b=b+12|0;if(o){ja(o)}o=c}q=q+1|0;if(q>>>0>>0){continue}break}}if((b|0)!=(o|0)){continue}break}A=1;break a}na();v()}oa();v()}if(o){ja(o)}Z=m+32|0;return A}function me(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;h=Z-48|0;Z=h;a:{if((c|0)!=1){break a}i=F[a+4>>2];c=F[a+12>>2];F[h+40>>2]=0;F[h+32>>2]=0;F[h+36>>2]=0;F[h+24>>2]=0;F[h+28>>2]=0;F[h+16>>2]=0;F[h+20>>2]=0;F[h+8>>2]=0;F[h+12>>2]=0;d=h+8|0;b:{if((b|0)==-2){break b}k=F[F[F[i+4>>2]+8>>2]+(c<<2)>>2];if(($[F[F[i>>2]+8>>2]](i)|0)==1){j=Z-32|0;Z=j;l=F[F[F[i+4>>2]+8>>2]+(c<<2)>>2];c:{d:{e:{if(($[F[F[i>>2]+8>>2]](i)|0)!=1|b-1>>>0>5){break e}g=$[F[F[i>>2]+36>>2]](i)|0;f=$[F[F[i>>2]+44>>2]](i,c)|0;if(!g|!f){break e}c=$[F[F[i>>2]+40>>2]](i,c)|0;if(c){a=F[i+44>>2];F[j+12>>2]=c;F[j+8>>2]=a;F[j+20>>2]=f;F[j+16>>2]=f+12;f=j+8|0;a=0;f:{g:{switch(b-1|0){case 0:b=ka(60);F[b+4>>2]=l;F[b>>2]=2960;a=F[d+4>>2];F[b+8>>2]=F[d>>2];F[b+12>>2]=a;a=F[d+12>>2];F[b+16>>2]=F[d+8>>2];F[b+20>>2]=a;a=F[d+20>>2];F[b+24>>2]=F[d+16>>2];F[b+28>>2]=a;F[b+40>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;a=F[d+24>>2];g=F[d+28>>2];if((a|0)!=(g|0)){c=g-a|0;if((c|0)<0){break d}e=ka(c);F[b+32>>2]=e;F[b+40>>2]=(c&-4)+e;while(1){F[e>>2]=F[a>>2];e=e+4|0;a=a+4|0;if((g|0)!=(a|0)){continue}break}F[b+36>>2]=e}a=F[f+4>>2];F[b+44>>2]=F[f>>2];F[b+48>>2]=a;a=F[f+12>>2];F[b+52>>2]=F[f+8>>2];F[b+56>>2]=a;F[b>>2]=2252;a=b;break f;case 3:b=ka(112);F[b+4>>2]=l;F[b>>2]=2960;a=F[d+4>>2];F[b+8>>2]=F[d>>2];F[b+12>>2]=a;a=F[d+12>>2];F[b+16>>2]=F[d+8>>2];F[b+20>>2]=a;a=F[d+20>>2];F[b+24>>2]=F[d+16>>2];F[b+28>>2]=a;F[b+40>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;a=F[d+24>>2];g=F[d+28>>2];if((a|0)!=(g|0)){c=g-a|0;if((c|0)<0){break d}e=ka(c);F[b+32>>2]=e;F[b+40>>2]=(c&-4)+e;while(1){F[e>>2]=F[a>>2];e=e+4|0;a=a+4|0;if((g|0)!=(a|0)){continue}break}F[b+36>>2]=e}a=F[f+4>>2];F[b+44>>2]=F[f>>2];F[b+48>>2]=a;a=F[f+12>>2];F[b+52>>2]=F[f+8>>2];F[b+56>>2]=a;F[b+60>>2]=0;F[b+64>>2]=0;F[b>>2]=3016;F[b+68>>2]=0;F[b+72>>2]=0;F[b+76>>2]=0;F[b+80>>2]=0;F[b+84>>2]=0;F[b+88>>2]=0;F[b+92>>2]=0;F[b+96>>2]=0;F[b+100>>2]=0;F[b+104>>2]=0;F[b+108>>2]=0;a=b;break f;case 4:b=ka(104);F[b+4>>2]=l;F[b>>2]=2960;a=F[d+4>>2];F[b+8>>2]=F[d>>2];F[b+12>>2]=a;a=F[d+12>>2];F[b+16>>2]=F[d+8>>2];F[b+20>>2]=a;a=F[d+20>>2];F[b+24>>2]=F[d+16>>2];F[b+28>>2]=a;F[b+40>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;a=F[d+24>>2];g=F[d+28>>2];if((a|0)!=(g|0)){c=g-a|0;if((c|0)<0){break d}e=ka(c);F[b+32>>2]=e;F[b+40>>2]=(c&-4)+e;while(1){F[e>>2]=F[a>>2];e=e+4|0;a=a+4|0;if((g|0)!=(a|0)){continue}break}F[b+36>>2]=e}a=F[f+4>>2];F[b+44>>2]=F[f>>2];F[b+48>>2]=a;a=F[f+12>>2];F[b+52>>2]=F[f+8>>2];F[b+56>>2]=a;F[b+84>>2]=0;F[b+76>>2]=0;F[b+80>>2]=0;F[b+60>>2]=0;F[b+64>>2]=0;F[b>>2]=3264;a=F[f+4>>2];F[b+88>>2]=F[f>>2];F[b+92>>2]=a;a=F[f+12>>2];F[b+96>>2]=F[f+8>>2];F[b+100>>2]=a;a=b;break f;case 5:break g;default:break f}}a=ka(128);F[a+4>>2]=l;F[a>>2]=2960;b=F[d+4>>2];F[a+8>>2]=F[d>>2];F[a+12>>2]=b;b=F[d+12>>2];F[a+16>>2]=F[d+8>>2];F[a+20>>2]=b;b=F[d+20>>2];F[a+24>>2]=F[d+16>>2];F[a+28>>2]=b;F[a+40>>2]=0;F[a+32>>2]=0;F[a+36>>2]=0;h:{i:{c=F[d+28>>2];b=F[d+24>>2];if((c|0)!=(b|0)){c=c-b|0;if((c|0)<0){break i}b=ka(c);F[a+36>>2]=b;F[a+32>>2]=b;F[a+40>>2]=(c&-4)+b;e=F[d+24>>2];c=F[d+28>>2];if((e|0)!=(c|0)){while(1){F[b>>2]=F[e>>2];b=b+4|0;e=e+4|0;if((c|0)!=(e|0)){continue}break}}F[a+36>>2]=b}F[a>>2]=2904;b=F[f+4>>2];F[a+44>>2]=F[f>>2];F[a+48>>2]=b;b=F[f+12>>2];F[a+52>>2]=F[f+8>>2];F[a+56>>2]=b;b=a- -64|0;F[b>>2]=0;F[b+4>>2]=0;F[a+60>>2]=4128;F[a>>2]=3500;b=F[f+4>>2];F[a+72>>2]=F[f>>2];F[a+76>>2]=b;b=F[f+12>>2];F[a+80>>2]=F[f+8>>2];F[a+84>>2]=b;F[a+104>>2]=1065353216;F[a+108>>2]=-1;F[a+96>>2]=-1;F[a+100>>2]=-1;F[a+88>>2]=1;F[a+92>>2]=-1;F[a+60>>2]=3736;F[a+112>>2]=0;F[a+116>>2]=0;D[a+117|0]=0;D[a+118|0]=0;D[a+119|0]=0;D[a+120|0]=0;D[a+121|0]=0;D[a+122|0]=0;D[a+123|0]=0;D[a+124|0]=0;break h}na();v()}break f}e=a;break e}a=F[i+44>>2];F[j+12>>2]=g;F[j+8>>2]=a;F[j+20>>2]=f;F[j+16>>2]=f+12;f=j+8|0;a=0;j:{k:{switch(b-1|0){case 0:b=ka(60);F[b+4>>2]=l;F[b>>2]=2960;a=F[d+4>>2];F[b+8>>2]=F[d>>2];F[b+12>>2]=a;a=F[d+12>>2];F[b+16>>2]=F[d+8>>2];F[b+20>>2]=a;a=F[d+20>>2];F[b+24>>2]=F[d+16>>2];F[b+28>>2]=a;F[b+40>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;a=F[d+24>>2];g=F[d+28>>2];if((a|0)!=(g|0)){c=g-a|0;if((c|0)<0){break d}e=ka(c);F[b+32>>2]=e;F[b+40>>2]=(c&-4)+e;while(1){F[e>>2]=F[a>>2];e=e+4|0;a=a+4|0;if((g|0)!=(a|0)){continue}break}F[b+36>>2]=e}a=F[f+4>>2];F[b+44>>2]=F[f>>2];F[b+48>>2]=a;a=F[f+12>>2];F[b+52>>2]=F[f+8>>2];F[b+56>>2]=a;F[b>>2]=4156;a=b;break j;case 3:b=ka(112);F[b+4>>2]=l;F[b>>2]=2960;a=F[d+4>>2];F[b+8>>2]=F[d>>2];F[b+12>>2]=a;a=F[d+12>>2];F[b+16>>2]=F[d+8>>2];F[b+20>>2]=a;a=F[d+20>>2];F[b+24>>2]=F[d+16>>2];F[b+28>>2]=a;F[b+40>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;a=F[d+24>>2];g=F[d+28>>2];if((a|0)!=(g|0)){c=g-a|0;if((c|0)<0){break d}e=ka(c);F[b+32>>2]=e;F[b+40>>2]=(c&-4)+e;while(1){F[e>>2]=F[a>>2];e=e+4|0;a=a+4|0;if((g|0)!=(a|0)){continue}break}F[b+36>>2]=e}a=F[f+4>>2];F[b+44>>2]=F[f>>2];F[b+48>>2]=a;a=F[f+12>>2];F[b+52>>2]=F[f+8>>2];F[b+56>>2]=a;F[b+60>>2]=0;F[b+64>>2]=0;F[b>>2]=4580;F[b+68>>2]=0;F[b+72>>2]=0;F[b+76>>2]=0;F[b+80>>2]=0;F[b+84>>2]=0;F[b+88>>2]=0;F[b+92>>2]=0;F[b+96>>2]=0;F[b+100>>2]=0;F[b+104>>2]=0;F[b+108>>2]=0;a=b;break j;case 4:b=ka(104);F[b+4>>2]=l;F[b>>2]=2960;a=F[d+4>>2];F[b+8>>2]=F[d>>2];F[b+12>>2]=a;a=F[d+12>>2];F[b+16>>2]=F[d+8>>2];F[b+20>>2]=a;a=F[d+20>>2];F[b+24>>2]=F[d+16>>2];F[b+28>>2]=a;F[b+40>>2]=0;F[b+32>>2]=0;F[b+36>>2]=0;a=F[d+24>>2];g=F[d+28>>2];if((a|0)!=(g|0)){c=g-a|0;if((c|0)<0){break d}e=ka(c);F[b+32>>2]=e;F[b+40>>2]=(c&-4)+e;while(1){F[e>>2]=F[a>>2];e=e+4|0;a=a+4|0;if((g|0)!=(a|0)){continue}break}F[b+36>>2]=e}a=F[f+4>>2];F[b+44>>2]=F[f>>2];F[b+48>>2]=a;a=F[f+12>>2];F[b+52>>2]=F[f+8>>2];F[b+56>>2]=a;F[b+84>>2]=0;F[b+76>>2]=0;F[b+80>>2]=0;F[b+60>>2]=0;F[b+64>>2]=0;F[b>>2]=4816;a=F[f+4>>2];F[b+88>>2]=F[f>>2];F[b+92>>2]=a;a=F[f+12>>2];F[b+96>>2]=F[f+8>>2];F[b+100>>2]=a;a=b;break j;case 5:break k;default:break j}}a=ka(128);F[a+4>>2]=l;F[a>>2]=2960;b=F[d+4>>2];F[a+8>>2]=F[d>>2];F[a+12>>2]=b;b=F[d+12>>2];F[a+16>>2]=F[d+8>>2];F[a+20>>2]=b;b=F[d+20>>2];F[a+24>>2]=F[d+16>>2];F[a+28>>2]=b;F[a+40>>2]=0;F[a+32>>2]=0;F[a+36>>2]=0;l:{m:{c=F[d+28>>2];b=F[d+24>>2];if((c|0)!=(b|0)){c=c-b|0;if((c|0)<0){break m}b=ka(c);F[a+36>>2]=b;F[a+32>>2]=b;F[a+40>>2]=(c&-4)+b;e=F[d+24>>2];c=F[d+28>>2];if((e|0)!=(c|0)){while(1){F[b>>2]=F[e>>2];b=b+4|0;e=e+4|0;if((c|0)!=(e|0)){continue}break}}F[a+36>>2]=b}F[a>>2]=4524;b=F[f+4>>2];F[a+44>>2]=F[f>>2];F[a+48>>2]=b;b=F[f+12>>2];F[a+52>>2]=F[f+8>>2];F[a+56>>2]=b;b=a- -64|0;F[b>>2]=0;F[b+4>>2]=0;F[a+60>>2]=5624;F[a>>2]=5040;b=F[f+4>>2];F[a+72>>2]=F[f>>2];F[a+76>>2]=b;b=F[f+12>>2];F[a+80>>2]=F[f+8>>2];F[a+84>>2]=b;F[a+104>>2]=1065353216;F[a+108>>2]=-1;F[a+96>>2]=-1;F[a+100>>2]=-1;F[a+88>>2]=1;F[a+92>>2]=-1;F[a+60>>2]=5260;F[a+112>>2]=0;F[a+116>>2]=0;D[a+117|0]=0;D[a+118|0]=0;D[a+119|0]=0;D[a+120|0]=0;D[a+121|0]=0;D[a+122|0]=0;D[a+123|0]=0;D[a+124|0]=0;break l}na();v()}break j}e=a}Z=j+32|0;break c}na();v()}if(e){break b}}e=ka(44);F[e+4>>2]=k;F[e>>2]=2960;a=F[d+4>>2];F[e+8>>2]=F[d>>2];F[e+12>>2]=a;a=F[d+12>>2];F[e+16>>2]=F[d+8>>2];F[e+20>>2]=a;a=F[d+20>>2];F[e+24>>2]=F[d+16>>2];F[e+28>>2]=a;F[e+40>>2]=0;F[e+32>>2]=0;F[e+36>>2]=0;n:{c=F[d+24>>2];b=F[d+28>>2];if((c|0)!=(b|0)){a=b-c|0;if((a|0)<0){break n}k=ka(a);F[e+32>>2]=k;F[e+40>>2]=(a&-4)+k;while(1){F[k>>2]=F[c>>2];k=k+4|0;c=c+4|0;if((b|0)!=(c|0)){continue}break}F[e+36>>2]=k}F[e>>2]=5652;break b}na();v()}k=e;a=F[h+32>>2];if(!a){break a}F[h+36>>2]=a;ja(a)}Z=h+48|0;return k|0}function rf(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0;m=Z-16|0;Z=m;F[m+12>>2]=b;b=ka(32);F[m>>2]=b;F[m+4>>2]=24;F[m+8>>2]=-2147483616;c=G[1196]|G[1197]<<8|(G[1198]<<16|G[1199]<<24);d=G[1192]|G[1193]<<8|(G[1194]<<16|G[1195]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1188]|G[1189]<<8|(G[1190]<<16|G[1191]<<24);d=G[1184]|G[1185]<<8|(G[1186]<<16|G[1187]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1180]|G[1181]<<8|(G[1182]<<16|G[1183]<<24);d=G[1176]|G[1177]<<8|(G[1178]<<16|G[1179]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;D[b+24|0]=0;l=Z-48|0;Z=l;f=F[m+12>>2];d=a;a=a+16|0;b=F[a>>2];a:{b:{if(!b){break b}c=a;while(1){e=(f|0)>F[b+16>>2];c=e?c:b;b=F[(e?b+4|0:b)>>2];if(b){continue}break}if((a|0)==(c|0)){break b}if((f|0)>=F[c+16>>2]){break a}}F[l+28>>2]=0;F[l+32>>2]=0;y=l+24|0;F[l+24>>2]=y|4;a=l+16|0;F[a>>2]=0;F[a+4>>2]=0;F[l+8>>2]=f;F[l+12>>2]=a;t=l+8|0;a=t;x=Z-16|0;Z=x;u=d+12|0;c=F[u+4>>2];c:{d:{if(!c){o=u+4|0;d=o;break d}a=F[a>>2];while(1){d=c;b=F[c+16>>2];if((b|0)>(a|0)){o=d;c=F[d>>2];if(c){continue}break d}if((a|0)<=(b|0)){g=d;a=0;break c}c=F[d+4>>2];if(c){continue}break}o=d+4|0}g=ka(32);b=F[t>>2];q=g+24|0;a=q;F[a>>2]=0;F[a+4>>2]=0;F[g+16>>2]=b;r=g+20|0;F[r>>2]=a;c=F[t+4>>2];z=t+8|0;if((c|0)!=(z|0)){while(1){p=Z-16|0;Z=p;a=p+8|0;k=c+16|0;e:{f:{g:{h:{i:{j:{k:{f=q;e=r+4|0;l:{if((f|0)==(e|0)){break l}b=G[f+27|0];h=b<<24>>24<0;i=G[k+11|0];n=i<<24>>24;j=(n|0)<0;i=j?F[k+4>>2]:i;b=h?F[f+20>>2]:b;s=i>>>0>b>>>0;w=s?b:i;if(w){j=j?F[k>>2]:k;h=h?F[f+16>>2]:f+16|0;A=sa(j,h,w);if(!A){if(b>>>0>i>>>0){break l}break k}if((A|0)>=0){break k}break l}if(b>>>0<=i>>>0){break j}}h=F[f>>2];m:{a=f;n:{if((a|0)==F[r>>2]){break n}o:{if(!h){b=f;while(1){a=F[b+8>>2];i=F[a>>2]==(b|0);b=a;if(i){continue}break}break o}b=h;while(1){a=b;b=F[b+4>>2];if(b){continue}break}}i=G[k+11|0];s=i<<24>>24;b=(s|0)<0;j=G[a+27|0];n=j<<24>>24<0;p:{i=b?F[k+4>>2]:i;j=n?F[a+20>>2]:j;w=i>>>0>>0?i:j;if(w){b=sa(n?F[a+16>>2]:a+16|0,b?F[k>>2]:k,w);if(b){break p}}if(i>>>0>j>>>0){break n}break m}if((b|0)>=0){break m}}if(!h){F[p+12>>2]=f;a=f;break e}F[p+12>>2]=a;a=a+4|0;break e}b=F[e>>2];if(!b){F[p+12>>2]=e;a=e;break e}h=(s|0)<0?F[k>>2]:k;f=e;while(1){a=b;b=G[b+27|0];e=b<<24>>24<0;b=e?F[a+20>>2]:b;k=b>>>0>>0;q:{r:{s:{t:{n=k?b:i;u:{if(n){e=e?F[a+16>>2]:a+16|0;j=sa(h,e,n);if(!j){if(b>>>0>i>>>0){break u}break t}if((j|0)>=0){break t}break u}if(b>>>0<=i>>>0){break s}}f=a;b=F[a>>2];if(b){continue}break g}b=sa(e,h,n);if(b){break r}}if(k){break q}break g}if((b|0)>=0){break g}}f=a+4|0;b=F[a+4>>2];if(b){continue}break}break g}b=sa(h,j,w);if(b){break i}}if(s){break h}break f}if((b|0)>=0){break f}}h=F[f+4>>2];v:{if(!h){b=f;while(1){a=F[b+8>>2];j=F[a>>2]!=(b|0);b=a;if(j){continue}break}break v}b=h;while(1){a=b;b=F[b>>2];if(b){continue}break}}w:{x:{if((a|0)==(e|0)){break x}j=G[a+27|0];b=j<<24>>24<0;y:{j=b?F[a+20>>2]:j;s=i>>>0>j>>>0?j:i;if(s){b=sa((n|0)<0?F[k>>2]:k,b?F[a+16>>2]:a+16|0,s);if(b){break y}}if(i>>>0>>0){break x}break w}if((b|0)>=0){break w}}if(!h){F[p+12>>2]=f;a=f+4|0;break e}F[p+12>>2]=a;break e}b=F[e>>2];if(!b){F[p+12>>2]=e;a=e;break e}h=(n|0)<0?F[k>>2]:k;f=e;while(1){a=b;b=G[b+27|0];e=b<<24>>24<0;b=e?F[a+20>>2]:b;k=b>>>0>>0;z:{A:{B:{C:{n=k?b:i;D:{if(n){e=e?F[a+16>>2]:a+16|0;j=sa(h,e,n);if(!j){if(b>>>0>i>>>0){break D}break C}if((j|0)>=0){break C}break D}if(b>>>0<=i>>>0){break B}}f=a;b=F[a>>2];if(b){continue}break g}b=sa(e,h,n);if(b){break A}}if(k){break z}break g}if((b|0)>=0){break g}}f=a+4|0;b=F[a+4>>2];if(b){continue}break}}F[p+12>>2]=a;a=f;break e}F[p+12>>2]=f;F[a>>2]=f}f=a;a=F[a>>2];if(a){b=0}else{a=ka(40);b=a+16|0;E:{if(D[c+27|0]>=0){e=F[c+20>>2];F[b>>2]=F[c+16>>2];F[b+4>>2]=e;F[b+8>>2]=F[c+24>>2];break E}ra(b,F[c+16>>2],F[c+20>>2])}b=a+28|0;F:{if(D[c+39|0]>=0){e=F[c+32>>2];F[b>>2]=F[c+28>>2];F[b+4>>2]=e;F[b+8>>2]=F[c+36>>2];break F}ra(b,F[c+28>>2],F[c+32>>2])}F[a+8>>2]=F[p+12>>2];F[a>>2]=0;F[a+4>>2]=0;F[f>>2]=a;b=a;e=F[F[r>>2]>>2];if(e){F[r>>2]=e;b=F[f>>2]}nb(F[r+4>>2],b);F[r+8>>2]=F[r+8>>2]+1;b=1}D[x+12|0]=b;F[x+8>>2]=a;Z=p+16|0;b=F[c+4>>2];G:{if(b){while(1){c=b;b=F[b>>2];if(b){continue}break G}}while(1){a=c;c=F[c+8>>2];if((a|0)!=F[c>>2]){continue}break}}if((c|0)!=(z|0)){continue}break}}F[g+8>>2]=d;F[g>>2]=0;F[g+4>>2]=0;F[o>>2]=g;c=g;a=F[F[u>>2]>>2];if(a){F[u>>2]=a;c=F[o>>2]}nb(F[u+4>>2],c);F[u+8>>2]=F[u+8>>2]+1;a=1}D[l+44|0]=a;F[l+40>>2]=g;Z=x+16|0;c=F[l+40>>2];ib(t|4,F[l+16>>2]);ib(y,F[l+28>>2])}f=Z-48|0;Z=f;d=f+8|0;g=Z-32|0;Z=g;o=g+32|0;b=o;a=g+21|0;H:{if((b|0)==(a|0)){break H}}e=b-a|0;I:{if((e|0)<=9){h=61;if((e|0)<(I[2684]<=1|0)){break I}}D[a|0]=49;b=a+1|0;h=0}F[g+12>>2]=h;F[g+8>>2]=b;h=Z-16|0;Z=h;e=Z-16|0;Z=e;J:{q=F[g+8>>2];g=q-a|0;if(g>>>0<=2147483631){K:{if(g>>>0<11){D[d+11|0]=g|G[d+11|0]&128;D[d+11|0]=G[d+11|0]&127;b=d;break K}t=e+8|0;if(g>>>0>=11){k=g+16&-16;b=k-1|0;b=(b|0)==11?k:b}else{b=10}sb(t,b+1|0);b=F[e+8>>2];F[d>>2]=b;F[d+8>>2]=F[d+8>>2]&-2147483648|F[e+12>>2]&2147483647;F[d+8>>2]=F[d+8>>2]|-2147483648;F[d+4>>2]=g}while(1){if((a|0)!=(q|0)){D[b|0]=G[a|0];b=b+1|0;a=a+1|0;continue}break}D[e+7|0]=0;D[b|0]=G[e+7|0];Z=e+16|0;break J}za();v()}Z=h+16|0;Z=o;F[f+32>>2]=m;L:{M:{a=c+20|0;d=F[a+4>>2];N:{if(!d){g=a+4|0;c=g;break N}b=G[m+11|0];c=b<<24>>24<0;e=c?F[m>>2]:m;b=c?F[m+4>>2]:b;while(1){c=d;d=G[c+27|0];g=d<<24>>24<0;d=g?F[c+20>>2]:d;o=d>>>0>>0;O:{P:{Q:{R:{h=o?d:b;S:{if(h){g=g?F[c+16>>2]:c+16|0;q=sa(e,g,h);if(!q){if(b>>>0>>0){break S}break R}if((q|0)>=0){break R}break S}if(b>>>0>=d>>>0){break Q}}g=c;d=F[c>>2];if(d){continue}break N}d=sa(g,e,h);if(d){break P}}if(o){break O}break M}if((d|0)>=0){break M}}d=F[c+4>>2];if(d){continue}break}g=c+4|0}d=ka(40);e=d+16|0;b=F[f+32>>2];T:{if(D[b+11|0]>=0){o=F[b+4>>2];F[e>>2]=F[b>>2];F[e+4>>2]=o;F[e+8>>2]=F[b+8>>2];break T}ra(e,F[b>>2],F[b+4>>2])}F[d+8>>2]=c;F[d>>2]=0;F[d+4>>2]=0;F[d+36>>2]=0;F[d+28>>2]=0;F[d+32>>2]=0;F[g>>2]=d;c=d;b=F[F[a>>2]>>2];if(b){F[a>>2]=b;c=F[g>>2]}nb(F[a+4>>2],c);F[a+8>>2]=F[a+8>>2]+1;a=1;break L}d=c;a=0}D[f+44|0]=a;F[f+40>>2]=d;a=F[f+40>>2];if(D[a+39|0]<0){ja(F[a+28>>2])}b=F[f+12>>2];F[a+28>>2]=F[f+8>>2];F[a+32>>2]=b;F[a+36>>2]=F[f+16>>2];Z=f+48|0;Z=l+48|0;if(D[m+11|0]<0){ja(F[m>>2])}Z=m+16|0}function zd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;h=Z-32|0;Z=h;g=F[F[a+4>>2]+44>>2];c=F[a+8>>2];d=F[c>>2];c=F[c+4>>2];F[h+24>>2]=0;F[h+16>>2]=0;F[h+20>>2]=0;d=(c-d>>2>>>0)/3|0;c=F[g+96>>2];f=(F[g+100>>2]-c|0)/12|0;a:{if(d>>>0>f>>>0){e=d-f|0;i=F[g+104>>2];c=F[g+100>>2];if(e>>>0<=(i-c|0)/12>>>0){b:{if(!e){break b}d=c;f=L(e,12)-12|0;i=((f>>>0)/12|0)+1&3;if(i){while(1){l=F[h+20>>2];F[d>>2]=F[h+16>>2];F[d+4>>2]=l;F[d+8>>2]=F[h+24>>2];d=d+12|0;j=j+1|0;if((i|0)!=(j|0)){continue}break}}c=L(e,12)+c|0;if(f>>>0<36){break b}while(1){f=F[h+20>>2];F[d>>2]=F[h+16>>2];F[d+4>>2]=f;F[d+8>>2]=F[h+24>>2];F[d+20>>2]=F[h+24>>2];f=F[h+20>>2];F[d+12>>2]=F[h+16>>2];F[d+16>>2]=f;F[d+32>>2]=F[h+24>>2];f=F[h+20>>2];F[d+24>>2]=F[h+16>>2];F[d+28>>2]=f;f=F[h+20>>2];F[d+36>>2]=F[h+16>>2];F[d+40>>2]=f;F[d+44>>2]=F[h+24>>2];d=d+48|0;if((d|0)!=(c|0)){continue}break}}F[g+100>>2]=c;break a}c:{f=F[g+96>>2];n=(c-f|0)/12|0;d=n+e|0;if(d>>>0<357913942){f=(i-f|0)/12|0;i=f<<1;i=f>>>0>=178956970?357913941:d>>>0>>0?i:d;if(i){if(i>>>0>=357913942){break c}l=ka(L(i,12))}f=L(n,12)+l|0;d=f;e=L(e,12);n=e-12|0;q=((n>>>0)/12|0)+1&3;if(q){while(1){r=F[h+20>>2];F[d>>2]=F[h+16>>2];F[d+4>>2]=r;F[d+8>>2]=F[h+24>>2];d=d+12|0;j=j+1|0;if((q|0)!=(j|0)){continue}break}}e=e+f|0;if(n>>>0>=36){while(1){j=F[h+20>>2];F[d>>2]=F[h+16>>2];F[d+4>>2]=j;F[d+8>>2]=F[h+24>>2];F[d+20>>2]=F[h+24>>2];j=F[h+20>>2];F[d+12>>2]=F[h+16>>2];F[d+16>>2]=j;F[d+32>>2]=F[h+24>>2];j=F[h+20>>2];F[d+24>>2]=F[h+16>>2];F[d+28>>2]=j;j=F[h+20>>2];F[d+36>>2]=F[h+16>>2];F[d+40>>2]=j;F[d+44>>2]=F[h+24>>2];d=d+48|0;if((e|0)!=(d|0)){continue}break}}j=F[g+96>>2];if((j|0)!=(c|0)){while(1){c=c-12|0;n=F[c+4>>2];f=f-12|0;d=f;F[d>>2]=F[c>>2];F[d+4>>2]=n;F[d+8>>2]=F[c+8>>2];if((c|0)!=(j|0)){continue}break}c=F[g+96>>2]}F[g+104>>2]=L(i,12)+l;F[g+100>>2]=e;F[g+96>>2]=f;if(c){ja(c)}break a}na();v()}oa();v()}if(d>>>0>=f>>>0){break a}F[g+100>>2]=c+L(d,12)}d:{if(F[a+216>>2]==F[a+220>>2]){j=F[a+4>>2];c=F[j+44>>2];d=F[c+100>>2];f=F[c+96>>2];if((d|0)!=(f|0)){c=(d-f|0)/12|0;o=c>>>0<=1?1:c;c=0;while(1){d=F[a+8>>2];i=f+L(c,12)|0;g=L(c,3);e:{f:{if((g|0)==-1){e=F[(F[d>>2]+(g<<2)|0)+4>>2];k=-1;g=1;break f}e=-1;k=F[F[d>>2]+(g<<2)>>2];l=g+1|0;if((l|0)==-1){g=0;break f}e=F[F[d>>2]+(l<<2)>>2];g=g+2|0;m=-1;if((g|0)==-1){break e}}m=F[F[d>>2]+(g<<2)>>2]}F[i+8>>2]=m;F[i+4>>2]=e;F[i>>2]=k;c=c+1|0;if((o|0)!=(c|0)){continue}break}}F[F[j+4>>2]+80>>2]=b;c=1;break d}d=0;F[h+24>>2]=0;F[h+16>>2]=0;F[h+20>>2]=0;l=F[a+8>>2];c=F[l>>2];g=F[l+4>>2];F[h+8>>2]=0;F[h>>2]=0;F[h+4>>2]=0;b=0;g:{h:{i:{j:{k:{l:{if((c|0)!=(g|0)){c=g-c|0;if((c|0)<0){break l}b=ka(c);F[h>>2]=b;F[h+8>>2]=(c&-4)+b;u=h,w=ma(b,0,c)+c|0,F[u+4>>2]=w}c=F[l+24>>2];if((F[l+28>>2]-c|0)<4){break h}f=0;while(1){g=F[(p<<2)+c>>2];m:{if((g|0)==-1){break m}n:{if(F[F[a+120>>2]+(p>>>3&536870908)>>2]>>>p&1){break n}n=F[a+216>>2];c=F[a+220>>2];if((n|0)==(c|0)){break n}e=g+2|0;i=(g>>>0)%3|0;q=i?g-1|0:e;c=(c-n|0)/144|0;r=c>>>0<=1?1:c;j=0;t=(i|0)!=0|(e|0)!=-1;while(1){s=g<<2;i=L(j,144)+n|0;c=F[s+F[F[i+68>>2]>>2]>>2];o:{if(!(F[F[i+16>>2]+(c>>>3&536870908)>>2]>>>c&1)){break o}c=-1;p:{if(!t){break p}e=F[F[l+12>>2]+(q<<2)>>2];c=-1;if((e|0)==-1){break p}c=e-1|0;if((e>>>0)%3|0){break p}c=e+2|0}if((g|0)==(c|0)){break o}e=s;s=F[i+32>>2];i=F[e+s>>2];while(1){e=0;if((c|0)==-1){break g}if((i|0)!=F[s+(c<<2)>>2]){g=c;break n}q:{r:{if((c>>>0)%3|0){e=c-1|0;break r}e=c+2|0;m=-1;if((e|0)==-1){break q}}c=F[F[l+12>>2]+(e<<2)>>2];m=-1;if((c|0)==-1){break q}m=c-1|0;if((c>>>0)%3|0){break q}m=c+2|0}c=m;if((g|0)!=(c|0)){continue}break}}j=j+1|0;if((r|0)!=(j|0)){continue}break}}i=k-f|0;e=i>>2;F[(g<<2)+b>>2]=e;s:{if(k>>>0>>0){F[k>>2]=g;k=k+4|0;F[h+20>>2]=k;break s}c=e+1|0;if(c>>>0>=1073741824){break k}d=o-f|0;k=d>>>1|0;c=d>>>0>=2147483644?1073741823:c>>>0>>0?k:c;if(c){if(c>>>0>=1073741824){break j}d=ka(c<<2)}else{d=0}e=d+(e<<2)|0;F[e>>2]=g;m=c<<2;c=pa(d,f,i);o=m+c|0;F[h+24>>2]=o;k=e+4|0;F[h+20>>2]=k;F[h+16>>2]=c;if(f){ja(f);l=F[a+8>>2]}f=c}if((g|0)==-1){break m}t:{if((g>>>0)%3|0){c=g-1|0;break t}c=g+2|0;if((c|0)==-1){break m}}c=F[F[l+12>>2]+(c<<2)>>2];if((c|0)==-1){break m}c=c+((c>>>0)%3|0?-1:2)|0;if((c|0)==-1){break m}e=g;if((c|0)==(g|0)){break m}while(1){i=c;u:{v:{c=F[a+220>>2];j=F[a+216>>2];if((c|0)==(j|0)){break v}c=(c-j|0)/144|0;n=c>>>0<=1?1:c;c=0;while(1){q=F[(j+L(c,144)|0)+32>>2];r=i<<2;if(F[q+r>>2]==F[q+(e<<2)>>2]){c=c+1|0;if((n|0)!=(c|0)){continue}break v}break}j=k-d|0;e=j>>2;F[b+r>>2]=e;if(k>>>0>>0){F[k>>2]=i;k=k+4|0;F[h+20>>2]=k;f=d;break u}c=e+1|0;if(c>>>0>=1073741824){break i}f=o-d|0;k=f>>>1|0;c=f>>>0>=2147483644?1073741823:c>>>0>>0?k:c;if(c){if(c>>>0>=1073741824){break j}f=ka(c<<2)}else{f=0}e=f+(e<<2)|0;F[e>>2]=i;m=c<<2;c=pa(f,d,j);o=m+c|0;F[h+24>>2]=o;k=e+4|0;F[h+20>>2]=k;F[h+16>>2]=c;if(!d){d=c;break u}ja(d);l=F[a+8>>2];d=c;break u}F[(i<<2)+b>>2]=F[(e<<2)+b>>2]}if((i|0)==-1){break m}w:{if((i>>>0)%3|0){c=i-1|0;break w}c=i+2|0;if((c|0)==-1){break m}}c=F[F[l+12>>2]+(c<<2)>>2];if((c|0)==-1){break m}c=c+((c>>>0)%3|0?-1:2)|0;if((c|0)==-1){break m}e=i;if((c|0)!=(g|0)){continue}break}}p=p+1|0;c=F[l+24>>2];if((p|0)>2]-c>>2){continue}break}break h}na();v()}na();v()}oa();v()}na();v()}i=F[a+4>>2];a=F[i+44>>2];c=F[a+100>>2];a=F[a+96>>2];x:{if((c|0)==(a|0)){break x}g=(c-a|0)/12|0;f=g>>>0<=1?1:g;l=f&1;c=0;if(g>>>0>=2){j=f&-2;g=0;while(1){e=L(c,12);f=e+b|0;o=F[f>>2];p=F[f+4>>2];e=a+e|0;F[e+8>>2]=F[f+8>>2];F[e>>2]=o;F[e+4>>2]=p;e=L(c|1,12);f=e+b|0;o=F[f>>2];p=F[f+4>>2];e=a+e|0;F[e+8>>2]=F[f+8>>2];F[e>>2]=o;F[e+4>>2]=p;c=c+2|0;g=g+2|0;if((j|0)!=(g|0)){continue}break}}if(!l){break x}g=L(c,12);c=g+b|0;f=F[c>>2];e=F[c+4>>2];a=a+g|0;F[a+8>>2]=F[c+8>>2];F[a>>2]=f;F[a+4>>2]=e}F[F[i+4>>2]+80>>2]=k-d>>2;e=1}c=e;if(b){ja(b)}if(!d){break d}F[h+20>>2]=d;ja(d)}Z=h+32|0;return c}function de(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,G=0,H=0,I=0,J=0,K=0,M=0,N=0,O=0,P=0;g=Z+-64|0;Z=g;F[a+8>>2]=e;y=a+32|0;f=F[y>>2];d=F[a+36>>2]-f>>2;a:{b:{if(d>>>0>>0){qa(y,e-d|0);F[g+56>>2]=0;F[g+60>>2]=0;F[g+48>>2]=0;F[g+52>>2]=0;F[g+40>>2]=0;F[g+44>>2]=0;F[g+32>>2]=0;F[g+36>>2]=0;F[g+24>>2]=0;F[g+28>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;F[g>>2]=0;break b}if(d>>>0>e>>>0){F[a+36>>2]=f+(e<<2)}F[g+56>>2]=0;F[g+60>>2]=0;F[g+48>>2]=0;F[g+52>>2]=0;F[g+40>>2]=0;F[g+44>>2]=0;F[g+32>>2]=0;F[g+36>>2]=0;F[g+24>>2]=0;F[g+28>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;F[g>>2]=0;d=0;if(!e){break a}}Fa(g+16|0,e,g);h=F[g+28>>2];d=F[g+32>>2]}F[g>>2]=0;d=d-h>>2;c:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break c}F[g+32>>2]=(e<<2)+h;break c}Fa(g+16|12,e-d|0,g)}F[g>>2]=0;f=F[g+40>>2];d=F[g+44>>2]-f>>2;d:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break d}F[g+44>>2]=f+(e<<2);break d}Fa(g+40|0,e-d|0,g)}F[g>>2]=0;f=F[g+52>>2];d=F[g+56>>2]-f>>2;e:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break e}F[g+56>>2]=f+(e<<2);break e}Fa(g+52|0,e-d|0,g)}f:{if(F[a+8>>2]<=0){break f}i=F[g+16>>2];j=F[a+32>>2];h=0;while(1){d=h<<2;f=F[d+i>>2];m=F[a+16>>2];g:{if((f|0)>(m|0)){F[d+j>>2]=m;break g}d=d+j|0;m=F[a+12>>2];if((m|0)>(f|0)){F[d>>2]=m;break g}F[d>>2]=f}h=h+1|0;d=F[a+8>>2];if((h|0)<(d|0)){continue}break}if((d|0)<=0){break f}d=0;while(1){i=d<<2;f=i+c|0;i=F[b+i>>2]+F[j+i>>2]|0;F[f>>2]=i;h:{if((i|0)>F[a+16>>2]){i=i-F[a+20>>2]|0}else{if((i|0)>=F[a+12>>2]){break h}i=i+F[a+20>>2]|0}F[f>>2]=i}d=d+1|0;if((d|0)>2]){continue}break}}H=F[a+52>>2];t=F[a+48>>2];z=ka(16);d=z;F[d>>2]=0;F[d+4>>2]=0;F[d+8>>2]=0;F[d+12>>2]=0;F[g+8>>2]=0;F[g>>2]=0;F[g+4>>2]=0;i:{if(e){if(e>>>0>=1073741824){break i}d=e<<2;r=ka(d);F[g>>2]=r;F[g+8>>2]=d+r;ma(r,0,d)}A=1;d=F[a+56>>2];B=F[d>>2];d=F[d+4>>2]-B|0;j:{if((d|0)<8){break j}w=d>>2;I=(w|0)<=2?2:w;J=w>>>0<=1?1:w;C=e&-2;D=e&1;K=e&-4;E=e&3;G=e-1|0;M=e<<2;N=e>>>0<4;A=0;m=1;while(1){k:{l:{m:{n:{if((m|0)!=(J|0)){o:{p:{f=F[(m<<2)+B>>2];if((f|0)==-1){break p}k=1;d=f+2|0;j=(f>>>0)%3|0;x=j?f-1|0:d;s=1<>2];O=n+(x>>>3&536870908)|0;i=0;P=(j|0)!=0|(d|0)!=-1;d=f;q:{while(1){r:{if(F[n+(d>>>3&536870908)>>2]>>>d&1){break r}j=F[F[F[t+64>>2]+12>>2]+(d<<2)>>2];if((j|0)==-1){break r}l=F[H>>2];h=F[t+28>>2];p=F[l+(F[h+(j<<2)>>2]<<2)>>2];if((p|0)>=(m|0)){break r}q=j+1|0;q=F[l+(F[h+(((q>>>0)%3|0?q:j-2|0)<<2)>>2]<<2)>>2];if((q|0)>=(m|0)){break r}h=F[l+(F[h+(j+((j>>>0)%3|0?-1:2)<<2)>>2]<<2)>>2];if((h|0)>=(m|0)){break r}s:{if(!e){break s}j=F[(g+16|0)+L(i,12)>>2];l=L(e,h);q=L(e,q);p=L(e,p);h=0;o=0;if(G){while(1){F[j+(h<<2)>>2]=(F[(h+l<<2)+c>>2]+F[(h+q<<2)+c>>2]|0)-F[(h+p<<2)+c>>2];u=h|1;F[j+(u<<2)>>2]=(F[(l+u<<2)+c>>2]+F[(q+u<<2)+c>>2]|0)-F[(p+u<<2)+c>>2];h=h+2|0;o=o+2|0;if((C|0)!=(o|0)){continue}break}}if(!D){break s}F[j+(h<<2)>>2]=(F[(h+l<<2)+c>>2]+F[(h+q<<2)+c>>2]|0)-F[(h+p<<2)+c>>2]}j=4;i=i+1|0;if((i|0)==4){break q}}t:{if(k&1){h=d-2|0;j=d+1|0;d=-1;j=(j>>>0)%3|0?j:h;if((j|0)==-1|F[n+(j>>>3&536870908)>>2]>>>j&1){break t}j=F[F[F[t+64>>2]+12>>2]+(j<<2)>>2];if((j|0)==-1){break t}d=j+1|0;d=(d>>>0)%3|0?d:j-2|0;break t}u:{if((d>>>0)%3|0){h=d-1|0;break u}h=d+2|0;d=-1;if((h|0)==-1){break t}}d=-1;if(F[n+(h>>>3&536870908)>>2]>>>h&1){break t}j=F[F[F[t+64>>2]+12>>2]+(h<<2)>>2];if((j|0)==-1){break t}if((j>>>0)%3|0){d=j-1|0;break t}d=j+2|0}v:{if((d|0)==(f|0)){break v}if((d|0)==-1&k){if(!P|s&F[O>>2]){break v}d=F[F[F[t+64>>2]+12>>2]+(x<<2)>>2];if((d|0)==-1){break v}k=0;d=(d>>>0)%3|0?d-1|0:d+2|0}if((d|0)!=-1){continue}}break}j=i;if((j|0)<=0){break p}}if(e){ma(r,0,M)}d=j-1|0;q=(d<<2)+z|0;d=L(d,12)+a|0;u=d;x=F[d- -64>>2];k=0;d=F[g>>2];f=0;while(1){i=F[q>>2];F[q>>2]=i+1;if(i>>>0>=x>>>0){break j}w:{if(F[F[u+60>>2]+(i>>>3&536870908)>>2]>>>i&1){break w}f=f+1|0;if(!e){break w}n=F[(g+16|0)+L(k,12)>>2];i=0;h=0;p=0;if(!N){while(1){l=h<<2;o=l+d|0;F[o>>2]=F[l+n>>2]+F[o>>2];o=l|4;s=o+d|0;F[s>>2]=F[n+o>>2]+F[s>>2];o=l|8;s=o+d|0;F[s>>2]=F[n+o>>2]+F[s>>2];l=l|12;o=l+d|0;F[o>>2]=F[l+n>>2]+F[o>>2];h=h+4|0;p=p+4|0;if((K|0)!=(p|0)){continue}break}}if(!E){break w}while(1){l=h<<2;p=l+d|0;F[p>>2]=F[l+n>>2]+F[p>>2];h=h+1|0;i=i+1|0;if((E|0)!=(i|0)){continue}break}}k=k+1|0;if((k|0)!=(j|0)){continue}break}i=L(e,m);if(!f){break o}if(!e){break l}h=0;d=0;if(G){break n}break m}i=L(e,m)}if(F[a+8>>2]<=0){break k}k=(L(m-1|0,e)<<2)+c|0;j=F[y>>2];h=0;while(1){d=h<<2;f=F[d+k>>2];n=F[a+16>>2];x:{if((f|0)>(n|0)){F[d+j>>2]=n;break x}d=d+j|0;n=F[a+12>>2];if((n|0)>(f|0)){F[d>>2]=n;break x}F[d>>2]=f}h=h+1|0;f=F[a+8>>2];if((h|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=i<<2;h=f+c|0;k=b+f|0;while(1){i=d<<2;f=i+h|0;i=F[i+k>>2]+F[j+i>>2]|0;F[f>>2]=i;y:{if((i|0)>F[a+16>>2]){i=i-F[a+20>>2]|0}else{if((i|0)>=F[a+12>>2]){break y}i=i+F[a+20>>2]|0}F[f>>2]=i}d=d+1|0;if((d|0)>2]){continue}break}break k}ta();v()}while(1){j=h<<2;k=j+r|0;F[k>>2]=F[k>>2]/(f|0);j=(j|4)+r|0;F[j>>2]=F[j>>2]/(f|0);h=h+2|0;d=d+2|0;if((C|0)!=(d|0)){continue}break}}if(!D){break l}d=(h<<2)+r|0;F[d>>2]=F[d>>2]/(f|0)}if(F[a+8>>2]<=0){break k}j=F[y>>2];h=0;while(1){d=h<<2;f=F[d+r>>2];k=F[a+16>>2];z:{if((f|0)>(k|0)){F[d+j>>2]=k;break z}d=d+j|0;k=F[a+12>>2];if((k|0)>(f|0)){F[d>>2]=k;break z}F[d>>2]=f}h=h+1|0;f=F[a+8>>2];if((h|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=i<<2;h=f+c|0;k=b+f|0;while(1){i=d<<2;f=i+h|0;i=F[i+k>>2]+F[j+i>>2]|0;F[f>>2]=i;A:{if((i|0)>F[a+16>>2]){i=i-F[a+20>>2]|0}else{if((i|0)>=F[a+12>>2]){break A}i=i+F[a+20>>2]|0}F[f>>2]=i}d=d+1|0;if((d|0)>2]){continue}break}}m=m+1|0;A=(w|0)<=(m|0);if((m|0)!=(I|0)){continue}break}}a=F[g>>2];if(a){ja(a)}ja(z);a=F[g+52>>2];if(a){F[g+56>>2]=a;ja(a)}a=F[g+40>>2];if(a){F[g+44>>2]=a;ja(a)}a=F[g+28>>2];if(a){F[g+32>>2]=a;ja(a)}a=F[g+16>>2];if(a){F[g+20>>2]=a;ja(a)}Z=g- -64|0;return A|0}na();v()}function $h(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,G=0,H=0,I=0,J=0,K=0,M=0,N=0;h=Z+-64|0;Z=h;F[a+8>>2]=e;x=a+32|0;f=F[x>>2];d=F[a+36>>2]-f>>2;a:{b:{if(d>>>0>>0){qa(x,e-d|0);F[h+56>>2]=0;F[h+60>>2]=0;F[h+48>>2]=0;F[h+52>>2]=0;F[h+40>>2]=0;F[h+44>>2]=0;F[h+32>>2]=0;F[h+36>>2]=0;F[h+24>>2]=0;F[h+28>>2]=0;F[h+16>>2]=0;F[h+20>>2]=0;F[h>>2]=0;break b}if(d>>>0>e>>>0){F[a+36>>2]=f+(e<<2)}F[h+56>>2]=0;F[h+60>>2]=0;F[h+48>>2]=0;F[h+52>>2]=0;F[h+40>>2]=0;F[h+44>>2]=0;F[h+32>>2]=0;F[h+36>>2]=0;F[h+24>>2]=0;F[h+28>>2]=0;F[h+16>>2]=0;F[h+20>>2]=0;F[h>>2]=0;d=0;if(!e){break a}}Fa(h+16|0,e,h);i=F[h+28>>2];d=F[h+32>>2]}F[h>>2]=0;d=d-i>>2;c:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break c}F[h+32>>2]=(e<<2)+i;break c}Fa(h+16|12,e-d|0,h)}F[h>>2]=0;f=F[h+40>>2];d=F[h+44>>2]-f>>2;d:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break d}F[h+44>>2]=f+(e<<2);break d}Fa(h+40|0,e-d|0,h)}F[h>>2]=0;f=F[h+52>>2];d=F[h+56>>2]-f>>2;e:{if(d>>>0>=e>>>0){if(d>>>0<=e>>>0){break e}F[h+56>>2]=f+(e<<2);break e}Fa(h+52|0,e-d|0,h)}f:{if(F[a+8>>2]<=0){break f}g=F[h+16>>2];j=F[a+32>>2];i=0;while(1){d=i<<2;f=F[d+g>>2];m=F[a+16>>2];g:{if((f|0)>(m|0)){F[d+j>>2]=m;break g}d=d+j|0;m=F[a+12>>2];if((m|0)>(f|0)){F[d>>2]=m;break g}F[d>>2]=f}i=i+1|0;d=F[a+8>>2];if((i|0)<(d|0)){continue}break}if((d|0)<=0){break f}d=0;while(1){g=d<<2;f=g+c|0;g=F[b+g>>2]+F[g+j>>2]|0;F[f>>2]=g;h:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break h}g=g+F[a+20>>2]|0}F[f>>2]=g}d=d+1|0;if((d|0)>2]){continue}break}}H=F[a+52>>2];A=F[a+48>>2];y=ka(16);d=y;F[d>>2]=0;F[d+4>>2]=0;F[d+8>>2]=0;F[d+12>>2]=0;F[h+8>>2]=0;F[h>>2]=0;F[h+4>>2]=0;i:{if(e){if(e>>>0>=1073741824){break i}d=e<<2;t=ka(d);F[h>>2]=t;F[h+8>>2]=d+t;ma(t,0,d)}z=1;d=F[a+56>>2];B=F[d>>2];d=F[d+4>>2]-B|0;j:{if((d|0)<8){break j}w=d>>2;I=(w|0)<=2?2:w;J=w>>>0<=1?1:w;C=e&-2;D=e&1;K=e&-4;E=e&3;G=e-1|0;M=e<<2;N=e>>>0<4;z=0;m=1;while(1){k:{l:{m:{n:{if((m|0)!=(J|0)){o:{p:{f=F[(m<<2)+B>>2];if((f|0)==-1){break p}n=F[A+12>>2];d=f+2|0;g=(f>>>0)%3|0;q=n+((g?f-1|0:d)<<2)|0;j=0;u=(g|0)!=0|(d|0)!=-1;k=1;d=f;q:{while(1){g=F[n+(d<<2)>>2];r:{if((g|0)==-1){break r}l=-1;p=F[H>>2];r=F[A>>2];i=p+(F[r+(g<<2)>>2]<<2)|0;o=g+1|0;o=(o>>>0)%3|0?o:g-2|0;if((o|0)!=-1){l=F[r+(o<<2)>>2]}o=F[i>>2];s:{t:{if((g>>>0)%3|0){i=g-1|0;break t}i=g+2|0;s=-1;if((i|0)==-1){break s}}s=F[r+(i<<2)>>2]}if((m|0)<=(o|0)){break r}i=F[p+(l<<2)>>2];if((i|0)>=(m|0)){break r}l=F[p+(s<<2)>>2];if((l|0)>=(m|0)){break r}g=F[(h+16|0)+L(j,12)>>2];u:{if(!e){break u}l=L(e,l);r=L(e,i);p=L(e,o);i=0;s=0;if(G){while(1){F[g+(i<<2)>>2]=(F[(i+l<<2)+c>>2]+F[(i+r<<2)+c>>2]|0)-F[(i+p<<2)+c>>2];o=i|1;F[g+(o<<2)>>2]=(F[(l+o<<2)+c>>2]+F[(o+r<<2)+c>>2]|0)-F[(o+p<<2)+c>>2];i=i+2|0;s=s+2|0;if((C|0)!=(s|0)){continue}break}}if(!D){break u}F[g+(i<<2)>>2]=(F[(i+l<<2)+c>>2]+F[(i+r<<2)+c>>2]|0)-F[(i+p<<2)+c>>2]}g=4;j=j+1|0;if((j|0)==4){break q}}v:{if(k&1){i=d+1|0;d=(i>>>0)%3|0?i:d-2|0;g=-1;if((d|0)==-1){break v}d=F[n+(d<<2)>>2];g=-1;if((d|0)==-1){break v}g=d+1|0;g=(g>>>0)%3|0?g:d-2|0;break v}w:{if((d>>>0)%3|0){i=d-1|0;break w}i=d+2|0;g=-1;if((i|0)==-1){break v}}d=F[n+(i<<2)>>2];g=-1;if((d|0)==-1){break v}g=d-1|0;if((d>>>0)%3|0){break v}g=d+2|0}d=g;x:{if((f|0)==(d|0)){break x}if((d|0)==-1&k){if(!u){break x}d=F[q>>2];if((d|0)==-1){break x}k=0;d=(d>>>0)%3|0?d-1|0:d+2|0}if((d|0)!=-1){continue}}break}g=j;if((g|0)<=0){break p}}if(e){ma(t,0,M)}d=g-1|0;r=(d<<2)+y|0;d=L(d,12)+a|0;o=d;s=F[d- -64>>2];k=0;d=F[h>>2];f=0;while(1){j=F[r>>2];F[r>>2]=j+1;if(j>>>0>=s>>>0){break j}y:{if(F[F[o+60>>2]+(j>>>3&536870908)>>2]>>>j&1){break y}f=f+1|0;if(!e){break y}j=F[(h+16|0)+L(k,12)>>2];l=0;i=0;p=0;if(!N){while(1){n=i<<2;q=n+d|0;F[q>>2]=F[j+n>>2]+F[q>>2];q=n|4;u=q+d|0;F[u>>2]=F[j+q>>2]+F[u>>2];q=n|8;u=q+d|0;F[u>>2]=F[j+q>>2]+F[u>>2];n=n|12;q=n+d|0;F[q>>2]=F[j+n>>2]+F[q>>2];i=i+4|0;p=p+4|0;if((K|0)!=(p|0)){continue}break}}if(!E){break y}while(1){n=i<<2;p=n+d|0;F[p>>2]=F[j+n>>2]+F[p>>2];i=i+1|0;l=l+1|0;if((E|0)!=(l|0)){continue}break}}k=k+1|0;if((k|0)!=(g|0)){continue}break}g=L(e,m);if(!f){break o}if(!e){break l}i=0;d=0;if(G){break n}break m}g=L(e,m)}if(F[a+8>>2]<=0){break k}k=(L(m-1|0,e)<<2)+c|0;j=F[x>>2];i=0;while(1){d=i<<2;f=F[d+k>>2];l=F[a+16>>2];z:{if((f|0)>(l|0)){F[d+j>>2]=l;break z}d=d+j|0;l=F[a+12>>2];if((l|0)>(f|0)){F[d>>2]=l;break z}F[d>>2]=f}i=i+1|0;f=F[a+8>>2];if((i|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=g<<2;i=f+c|0;k=b+f|0;while(1){g=d<<2;f=g+i|0;g=F[g+k>>2]+F[g+j>>2]|0;F[f>>2]=g;A:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break A}g=g+F[a+20>>2]|0}F[f>>2]=g}d=d+1|0;if((d|0)>2]){continue}break}break k}ta();v()}while(1){j=i<<2;k=j+t|0;F[k>>2]=F[k>>2]/(f|0);j=(j|4)+t|0;F[j>>2]=F[j>>2]/(f|0);i=i+2|0;d=d+2|0;if((C|0)!=(d|0)){continue}break}}if(!D){break l}d=(i<<2)+t|0;F[d>>2]=F[d>>2]/(f|0)}if(F[a+8>>2]<=0){break k}j=F[x>>2];i=0;while(1){d=i<<2;f=F[d+t>>2];k=F[a+16>>2];B:{if((f|0)>(k|0)){F[d+j>>2]=k;break B}d=d+j|0;k=F[a+12>>2];if((k|0)>(f|0)){F[d>>2]=k;break B}F[d>>2]=f}i=i+1|0;f=F[a+8>>2];if((i|0)<(f|0)){continue}break}d=0;if((f|0)<=0){break k}f=g<<2;i=f+c|0;k=b+f|0;while(1){g=d<<2;f=g+i|0;g=F[g+k>>2]+F[g+j>>2]|0;F[f>>2]=g;C:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break C}g=g+F[a+20>>2]|0}F[f>>2]=g}d=d+1|0;if((d|0)>2]){continue}break}}m=m+1|0;z=(w|0)<=(m|0);if((m|0)!=(I|0)){continue}break}}a=F[h>>2];if(a){ja(a)}ja(y);a=F[h+52>>2];if(a){F[h+56>>2]=a;ja(a)}a=F[h+40>>2];if(a){F[h+44>>2]=a;ja(a)}a=F[h+28>>2];if(a){F[h+32>>2]=a;ja(a)}a=F[h+16>>2];if(a){F[h+20>>2]=a;ja(a)}Z=h- -64|0;return z|0}na();v()}function Yh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,E=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,$=0,aa=0;a:{b:{if((e|0)!=2){break b}F[a+8>>2]=2;F[a- -64>>2]=f;M=a+32|0;e=F[M>>2];d=F[a+36>>2]-e|0;c:{if(d>>>0<=7){qa(M,2-(d>>>2|0)|0);break c}if((d|0)==8){break c}F[a+36>>2]=e+8}i=1;d=F[a+56>>2];d=F[d+4>>2]-F[d>>2]|0;if((d|0)<=0){break b}o=a+60|0;d=d>>>2|0;X=d>>>0<=1?1:d;Y=a+68|0;d=0;while(1){f=F[a+56>>2];e=F[f>>2];if(F[f+4>>2]-e>>2>>>0<=d>>>0){break a}k=Z-80|0;Z=k;f=-1;d:{e:{e=F[e+(d<<2)>>2];if((e|0)==-1){break e}i=F[o+32>>2];g=e+1|0;g=(g>>>0)%3|0?g:e-2|0;if((g|0)!=-1){f=F[F[i>>2]+(g<<2)>>2]}p=-1;e=e+((e>>>0)%3|0?-1:2)|0;if((e|0)!=-1){p=F[F[i>>2]+(e<<2)>>2]}i=F[o+36>>2];e=F[i>>2];i=F[i+4>>2]-e>>2;if(i>>>0<=f>>>0|i>>>0<=p>>>0){break e}f:{g:{h:{i:{j:{k:{j=F[e+(p<<2)>>2];f=F[e+(f<<2)>>2];if((j|0)>=(d|0)|(f|0)>=(d|0)){break k}i=(j<<3)+c|0;w=F[i+4>>2];g=(f<<3)+c|0;e=F[g+4>>2];l=F[i>>2];i=F[g>>2];if(!((l|0)!=(i|0)|(e|0)!=(w|0))){F[o+8>>2]=i;F[o+12>>2]=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|0;h=_+N|0;h=f>>>0>>0?h+1|0:h;n=i-f|0;f=T-((f>>>0>i>>>0)+h|0)|0;n=ki(n,f,n,f);x=_;f=g;h=li(ki(j,q,A,I),_,r,s);i=h+z|0;g=_+O|0;g=h>>>0>i>>>0?g+1|0:g;h=f-i|0;f=U-((f>>>0>>0)+g|0)|0;g=ki(h,f,h,f);i=g+n|0;f=_+x|0;f=g>>>0>i>>>0?f+1|0:f;n=i;g=li(ki(j,q,C,J),_,r,s);i=g+B|0;h=_+P|0;h=g>>>0>i>>>0?h+1|0:h;g=m-i|0;i=V-((i>>>0>m>>>0)+h|0)|0;m=ki(g,i,g,i);i=m+n|0;g=_+f|0;f=ki(i,i>>>0>>0?g+1|0:g,r,s);i=_;m=i;if(!i&f>>>0<=1){break i}h=f;while(1){g=e<<1|l>>>31;l=l<<1;e=g;n=!i&h>>>0>7|(i|0)!=0;h=(i&3)<<30|h>>>2;i=i>>>2|0;if(n){continue}break}break h}if((d|0)>(f|0)){e=f<<1}else{if((d|0)<=0){F[o+8>>2]=0;F[o+12>>2]=0;break j}e=(d<<1)-2|0}e=(e<<2)+c|0;F[o+8>>2]=F[e>>2];F[o+12>>2]=F[e+4>>2]}p=1;break f}e=m;l=f;if(f-1|0){break g}}while(1){i=mi(f,m,l,e);h=e+_|0;e=i+l|0;h=e>>>0>>0?h+1|0:h;l=(h&1)<<31|e>>>1;e=h>>>1|0;i=ki(l,e,l,e);g=_;if((m|0)==(g|0)&f>>>0>>0|g>>>0>m>>>0){continue}break}}f=F[o+20>>2];if(!f){break f}g=f-1|0;h=F[F[o+16>>2]+(g>>>3&536870908)>>2];F[o+20>>2]=g;p=1;f=ki(j,q,y,w);i=_;n=ki(r,s,K,S);m=n+f|0;f=_+i|0;f=m>>>0>>0?f+1|0:f;i=ki(l,e,E,W);g=h>>>g&1;h=g?0-i|0:i;m=h+m|0;n=f;f=_;i=n+(g?0-(f+((i|0)!=0)|0)|0:f)|0;$=o,aa=li(m,h>>>0>m>>>0?i+1|0:i,r,s),F[$+12>>2]=aa;f=ki(j,q,E,W);i=_;j=ki(r,s,Q,R);f=j+f|0;h=_+i|0;e=ki(l,e,y,w);i=0-e|0;l=_;h=(f>>>0>>0?h+1|0:h)+(g?l:0-(((e|0)!=0)+l|0)|0)|0;i=g?e:i;f=i+f|0;$=o,aa=li(f,f>>>0>>0?h+1|0:h,r,s),F[$+8>>2]=aa}Z=k+80|0;e=p;break d}ta();v()}i=e;if(!e){return 0}l:{if(F[a+8>>2]<=0){break l}l=F[M>>2];e=0;while(1){f=e<<2;g=F[f+Y>>2];j=F[a+16>>2];m:{if((g|0)>(j|0)){F[f+l>>2]=j;break m}f=f+l|0;j=F[a+12>>2];if((j|0)>(g|0)){F[f>>2]=j;break m}F[f>>2]=g}e=e+1|0;g=F[a+8>>2];if((e|0)<(g|0)){continue}break}f=0;if((g|0)<=0){break l}e=d<<3;j=e+c|0;q=b+e|0;while(1){g=f<<2;e=g+j|0;g=F[g+q>>2]+F[g+l>>2]|0;F[e>>2]=g;n:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break n}g=g+F[a+20>>2]|0}F[e>>2]=g}f=f+1|0;if((f|0)>2]){continue}break}}d=d+1|0;if((X|0)!=(d|0)){continue}break}}return i|0}ta();v()}function hi(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,E=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,$=0,aa=0;a:{b:{if((e|0)!=2){break b}F[a+8>>2]=2;F[a- -64>>2]=f;M=a+32|0;e=F[M>>2];d=F[a+36>>2]-e|0;c:{if(d>>>0<=7){qa(M,2-(d>>>2|0)|0);break c}if((d|0)==8){break c}F[a+36>>2]=e+8}p=1;d=F[a+56>>2];d=F[d+4>>2]-F[d>>2]|0;if((d|0)<=0){break b}o=a+60|0;d=d>>>2|0;X=d>>>0<=1?1:d;Y=a+68|0;d=0;while(1){e=F[a+56>>2];h=F[e>>2];if(F[e+4>>2]-h>>2>>>0<=d>>>0){break a}k=Z-80|0;Z=k;f=-1;h=F[h+(d<<2)>>2];e=-1;d:{if((h|0)==-1){break d}e=h+1|0;f=(e>>>0)%3|0?e:h-2|0;e=h-1|0;if((h>>>0)%3|0){break d}e=h+2|0}g=F[o+36>>2];h=F[g>>2];e:{f:{g:{h:{i:{g=F[g+4>>2]-h>>2;i=f<<2;f=F[F[o+32>>2]+28>>2];j=F[i+f>>2];if(g>>>0<=j>>>0){break i}e=F[f+(e<<2)>>2];if(e>>>0>=g>>>0){break i}j:{k:{l=F[h+(e<<2)>>2];f=F[h+(j<<2)>>2];if((l|0)>=(d|0)|(f|0)>=(d|0)){break k}h=(l<<3)+c|0;w=F[h+4>>2];g=(f<<3)+c|0;e=F[g+4>>2];j=F[h>>2];h=F[g>>2];if(!((j|0)!=(h|0)|(e|0)!=(w|0))){F[o+8>>2]=h;F[o+12>>2]=e;break j}p=F[F[o+4>>2]+(d<<2)>>2];F[k+72>>2]=0;F[k+76>>2]=0;g=k- -64|0;F[g>>2]=0;F[g+4>>2]=0;F[k+56>>2]=0;F[k+60>>2]=0;g=F[o>>2];if(!G[g+84|0]){p=F[F[g+68>>2]+(p<<2)>>2]}Ga(g,p,D[g+24|0],k+56|0);p=F[F[o+4>>2]+(f<<2)>>2];F[k+48>>2]=0;F[k+52>>2]=0;F[k+40>>2]=0;F[k+44>>2]=0;F[k+32>>2]=0;F[k+36>>2]=0;g=F[o>>2];if(!G[g+84|0]){p=F[F[g+68>>2]+(p<<2)>>2]}Ga(g,p,D[g+24|0],k+32|0);p=F[F[o+4>>2]+(l<<2)>>2];F[k+24>>2]=0;F[k+28>>2]=0;F[k+16>>2]=0;F[k+20>>2]=0;F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;j=j<<1;e=g;n=!h&i>>>0>7|(h|0)!=0;i=(h&3)<<30|i>>>2;h=h>>>2|0;if(n){continue}break}break g}if((d|0)>(f|0)){e=f<<1}else{if((d|0)<=0){F[o+8>>2]=0;F[o+12>>2]=0;break j}e=(d<<1)-2|0}e=(e<<2)+c|0;F[o+8>>2]=F[e>>2];F[o+12>>2]=F[e+4>>2]}p=1;break e}ta();v()}e=m;j=f;if(f-1|0){break f}}while(1){h=mi(f,m,j,e);i=e+_|0;e=h+j|0;i=e>>>0>>0?i+1|0:i;j=(i&1)<<31|e>>>1;e=i>>>1|0;h=ki(j,e,j,e);g=_;if((m|0)==(g|0)&f>>>0>>0|g>>>0>m>>>0){continue}break}}f=F[o+20>>2];if(!f){break e}g=f-1|0;i=F[F[o+16>>2]+(g>>>3&536870908)>>2];F[o+20>>2]=g;p=1;f=ki(l,q,y,w);h=_;n=ki(r,s,K,S);m=n+f|0;f=_+h|0;f=m>>>0>>0?f+1|0:f;h=ki(j,e,E,W);g=i>>>g&1;i=g?0-h|0:h;m=i+m|0;n=f;f=_;h=n+(g?0-(f+((h|0)!=0)|0)|0:f)|0;$=o,aa=li(m,i>>>0>m>>>0?h+1|0:h,r,s),F[$+12>>2]=aa;f=ki(l,q,E,W);h=_;l=ki(r,s,Q,R);f=l+f|0;i=_+h|0;e=ki(j,e,y,w);h=0-e|0;j=_;i=(f>>>0>>0?i+1|0:i)+(g?j:0-(((e|0)!=0)+j|0)|0)|0;h=g?e:h;f=h+f|0;$=o,aa=li(f,f>>>0>>0?i+1|0:i,r,s),F[$+8>>2]=aa}Z=k+80|0;if(!p){return 0}l:{if(F[a+8>>2]<=0){break l}g=F[M>>2];e=0;while(1){f=e<<2;h=F[f+Y>>2];j=F[a+16>>2];m:{if((h|0)>(j|0)){F[f+g>>2]=j;break m}f=f+g|0;j=F[a+12>>2];if((j|0)>(h|0)){F[f>>2]=j;break m}F[f>>2]=h}e=e+1|0;h=F[a+8>>2];if((e|0)<(h|0)){continue}break}f=0;if((h|0)<=0){break l}e=d<<3;j=e+c|0;l=b+e|0;while(1){h=f<<2;e=h+j|0;h=F[h+l>>2]+F[h+g>>2]|0;F[e>>2]=h;n:{if((h|0)>F[a+16>>2]){i=h-F[a+20>>2]|0}else{if((h|0)>=F[a+12>>2]){break n}i=h+F[a+20>>2]|0}F[e>>2]=i}f=f+1|0;if((f|0)>2]){continue}break}}d=d+1|0;if((X|0)!=(d|0)){continue}break}}return p|0}ta();v()}function Gd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;n=Z-96|0;Z=n;m=F[a+4>>2];d=F[m+32>>2];j=F[d+8>>2];i=F[d+12>>2];e=i;c=F[d+20>>2];f=F[d+16>>2];a:{if((e|0)<=(c|0)&f>>>0>=j>>>0|(c|0)>(e|0)){break a}o=F[d>>2];h=G[o+f|0];g=f+1|0;e=g?c:c+1|0;F[d+16>>2]=g;F[d+20>>2]=e;if((e|0)>=(i|0)&g>>>0>=j>>>0|(e|0)>(i|0)){break a}p=G[g+o|0];g=f+2|0;e=g>>>0<2?c+1|0:c;F[d+16>>2]=g;F[d+20>>2]=e;l=h<<24>>24;b:{if((l|0)>=0){k=F[a+216>>2];if(h>>>0>=(F[a+220>>2]-k|0)/144>>>0){break a}k=k+L(h,144)|0;if(F[k>>2]<0){break b}break a}if(F[a+212>>2]>=0){break a}k=a+212|0}F[k>>2]=b;c:{d:{e:{f:{g:{h:{k=H[m+36>>1];i:{if(((k<<8|k>>>8)&65535)>>>0>=258){if((e|0)>=(i|0)&g>>>0>=j>>>0|(e|0)>(i|0)){break a}e=G[g+o|0];f=f+3|0;c=f>>>0<3?c+1|0:c;F[d+16>>2]=f;F[d+20>>2]=c;if(e>>>0>1){break a}d=e>>>0<2?e:0;if(!p){break i}if(!d){break h}break a}if(p){break g}d=0}if((l|0)<0){e=a+184|0}else{c=F[a+216>>2]+L(h,144)|0;D[c+100|0]=0;e=c+104|0}if((d|0)!=1){break e}c=Z-112|0;Z=c;g=F[F[a+4>>2]+44>>2];d=ka(120);F[d>>2]=8924;F[d+4>>2]=0;F[d+116>>2]=0;F[d+112>>2]=e;F[d+108>>2]=g;F[d+12>>2]=0;F[d+16>>2]=0;F[d+20>>2]=0;F[d+24>>2]=0;F[d+28>>2]=0;F[d+32>>2]=0;F[d+36>>2]=0;F[d+40>>2]=0;F[d+44>>2]=0;F[d+48>>2]=0;F[d+52>>2]=0;F[d+56>>2]=0;F[d+60>>2]=0;F[d+8>>2]=9136;f=d- -64|0;F[f>>2]=0;F[f+4>>2]=0;F[d+72>>2]=0;F[d+76>>2]=0;F[d+80>>2]=0;F[d+84>>2]=0;F[d+88>>2]=0;F[d+104>>2]=0;F[d+96>>2]=0;F[d+100>>2]=0;f=F[a+8>>2];F[c+48>>2]=0;F[c+52>>2]=0;F[c+40>>2]=0;F[c+44>>2]=0;j=c+32|0;F[j>>2]=0;F[j+4>>2]=0;F[c+24>>2]=0;F[c+28>>2]=0;h=c- -64|0;F[h>>2]=0;F[h+4>>2]=0;F[c+72>>2]=0;F[c+76>>2]=0;F[c+80>>2]=0;F[c+84>>2]=0;F[c+88>>2]=0;F[c+104>>2]=0;F[c+16>>2]=0;F[c+20>>2]=0;F[c+56>>2]=0;F[c+60>>2]=0;F[c+8>>2]=9136;F[c+96>>2]=0;F[c+100>>2]=0;F[c+12>>2]=f;h=F[f>>2];i=F[f+4>>2];D[c+111|0]=0;k=j;j=c+111|0;Ea(k,(i-h>>2>>>0)/3|0,j);h=F[c+12>>2];i=F[h+28>>2];h=F[h+24>>2];D[c+111|0]=0;Ea(c+44|0,i-h>>2,j);F[c+28>>2]=d;F[c+24>>2]=g;F[c+20>>2]=e;F[c+16>>2]=f;f=d+8|0;e=c+8|0;lc(f,e);j:{if((e|0)==(f|0)){F[d+92>>2]=F[e+84>>2];break j}gb(d+56|0,F[e+48>>2],F[e+52>>2]);gb(d+68|0,F[e+60>>2],F[e- -64>>2]);gb(d+80|0,F[e+72>>2],F[e+76>>2]);F[d+92>>2]=F[e+84>>2];k:{h=F[e+92>>2];j=F[e+88>>2];i=h-j|0;e=i>>2;f=F[d+104>>2];g=F[d+96>>2];if(e>>>0<=f-g>>2>>>0){i=F[d+100>>2]-g|0;f=i+j|0;m=i>>2;i=e>>>0>m>>>0?f:h;l=i-j|0;if((i|0)!=(j|0)){pa(g,j,l)}if(e>>>0>m>>>0){e=F[d+100>>2];if((h|0)!=(i|0)){while(1){F[e>>2]=F[f>>2];e=e+4|0;f=f+4|0;if((h|0)!=(f|0)){continue}break}}F[d+100>>2]=e;break k}F[d+100>>2]=g+l;break k}if(g){F[d+100>>2]=g;ja(g);F[d+104>>2]=0;F[d+96>>2]=0;F[d+100>>2]=0;f=0}l:{if((i|0)<0){break l}g=f>>>1|0;e=f>>>0>=2147483644?1073741823:e>>>0>>0?g:e;if(e>>>0>=1073741824){break l}f=e<<2;e=ka(f);F[d+96>>2]=e;F[d+104>>2]=e+f;if((h|0)!=(j|0)){f=e;e=(i-4&-4)+4|0;e=la(f,j,e)+e|0}F[d+100>>2]=e;break k}na();v()}}F[c+8>>2]=9136;e=F[c+96>>2];if(e){F[c+100>>2]=e;ja(e)}e=F[c+80>>2];if(e){F[c+84>>2]=e;ja(e)}e=F[c+68>>2];if(e){F[c+72>>2]=e;ja(e)}e=F[c+56>>2];if(e){F[c+60>>2]=e;ja(e)}F[c+8>>2]=9372;e=F[c+44>>2];if(e){ja(e)}e=F[c+32>>2];if(e){ja(e)}Z=c+112|0;break d}if((l|0)>=0){break f}break a}if((l|0)<0){break a}}e=F[a+216>>2];c=F[m+44>>2];d=ka(80);F[d>>2]=9684;F[d+4>>2]=0;F[d+76>>2]=0;F[d+68>>2]=c;F[d+8>>2]=8624;F[d+12>>2]=0;F[d+16>>2]=0;F[d+20>>2]=0;F[d+24>>2]=0;F[d+28>>2]=0;F[d+32>>2]=0;F[d+36>>2]=0;F[d+40>>2]=0;F[d+44>>2]=0;F[d+48>>2]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ea(k,(l-i>>2>>>0)/3|0,h);i=F[c+4>>2];l=F[i+28>>2];i=F[i+24>>2];D[c+63|0]=0;Ea(c+36|0,l-i>>2,h);F[c+20>>2]=d;F[c+16>>2]=g;F[c+12>>2]=e;F[c+8>>2]=f;lc(d+8|0,c);gb(j,F[c+48>>2],F[c+52>>2]);F[c>>2]=9556;e=F[c+48>>2];if(e){F[c+52>>2]=e;ja(e)}F[c>>2]=9372;e=F[c+36>>2];if(e){ja(e)}e=F[c+24>>2];if(e){ja(e)}Z=c- -64|0}if(!d){break a}}d=yc(ka(64),d);c=F[a+4>>2];a=d;d=b;m:{n:{if((d|0)>=0){g=c+8|0;b=F[c+12>>2];j=F[c+8>>2];e=b-j>>2;o:{if((e|0)>(d|0)){break o}f=d+1|0;if(d>>>0>=e>>>0){Pb(g,f-e|0);break o}if(e>>>0<=f>>>0){break o}f=j+(f<<2)|0;if((f|0)!=(b|0)){while(1){b=b-4|0;e=F[b>>2];F[b>>2]=0;if(e){$[F[F[e>>2]+4>>2]](e)}if((b|0)!=(f|0)){continue}break}}F[c+12>>2]=f}c=F[g>>2]+(d<<2)|0;b=F[c>>2];F[c>>2]=a;if(b){break n}break m}b=a;if(!a){break m}}$[F[F[b>>2]+4>>2]](b)}q=(d^-1)>>>31|0}Z=n+96|0;return q|0}function Ab(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=M(0),n=M(0),o=0;a:{b:{if(!d){break b}c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=D[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=H[b>>1];b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=E[b>>1];if((e|0)<0){break b}E[(g<<1)+d>>1]=e;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=F[b>>2];if(e+32768>>>0>65535){break b}E[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=F[b>>2];if(e>>>0>32767){break b}E[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;k=F[e+4>>2];while(1){if(b>>>0>=k>>>0){break b}h=F[b+4>>2];e=F[b>>2];i=e+32768|0;h=i>>>0<32768?h+1|0:h;if(!h&i>>>0>65535|h){break b}E[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=F[b+4>>2];e=F[b>>2];if(!k&e>>>0>32767|k){break b}E[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=F[a>>2];j=F[e>>2];g=j;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-j|0;if(!G[a+32|0]){j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(32767)|m>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(32767)|mM(1)){break d}e=(b<<1)+d|0;l=R(+m*32767+.5);f:{if(N(l)<2147483648){i=~~l;break f}i=-2147483648}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=1;if(c>>>0<=e>>>0){break d}ma((e<<1)+d|0,0,c-e<<1)}return j;case 9:g:{h:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=F[a>>2];j=F[e>>2];g=j;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-j|0;if(!G[a+32|0]){j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=K[g>>3];if(l>=32767|l<-32768|l!=l){break g}o=N(l);if(o==Infinity){break g}e=(b<<1)+d|0;if(o<2147483648){i=~~l}else{i=-2147483648}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=K[g>>3];if(l>=32767|l<-32768|(N(l)==Infinity|l!=l)){break g}if(l<0|l>1){break g}e=(b<<1)+d|0;l=R(l*32767+.5);i:{if(N(l)<2147483648){i=~~l;break i}i=-2147483648}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=1;if(c>>>0<=e>>>0){break g}ma((e<<1)+d|0,0,c-e<<1)}return j;case 10:break c;default:break b}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}ma((e<<1)+d|0,0,(c&255)-e<<1)}return j}ma((e<<1)+d|0,0,(c&255)-e<<1);return 1}function yb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=M(0),n=M(0),o=0;a:{b:{if(!d){break b}c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=D[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=E[b>>1];b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=H[b>>1];b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=F[b>>2];b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=F[b>>2];if((e|0)<0){break b}F[(g<<2)+d>>2]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;k=F[e+4>>2];while(1){if(b>>>0>=k>>>0){break b}h=F[b+4>>2];e=F[b>>2];if(e- -2147483648>>>0<2147483648?h+1|0:h){break b}F[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=F[b+4>>2];e=F[b>>2];if(!k&e>>>0>2147483647|k){break b}F[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=F[a>>2];j=F[e>>2];g=j;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-j|0;if(!G[a+32|0]){j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(2147483648)|m>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(2147483648)|mM(1)){break d}e=(b<<2)+d|0;l=R(+m*2147483647+.5);f:{if(N(l)<2147483648){i=~~l;break f}i=-2147483648}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}j=1;if(c>>>0<=e>>>0){break d}ma((e<<2)+d|0,0,c-e<<2)}return j;case 9:g:{h:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=F[a>>2];j=F[e>>2];g=j;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-j|0;if(!G[a+32|0]){j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=K[g>>3];if(l>=2147483647|l<-2147483648|l!=l){break g}o=N(l);if(o==Infinity){break g}e=(b<<2)+d|0;if(o<2147483648){i=~~l}else{i=-2147483648}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=0;if((b|0)>=(e|0)){break g}b=0;while(1){l=K[g>>3];if(l>=2147483647|l<-2147483648|(N(l)==Infinity|l!=l)){break g}if(l<0|l>1){break g}e=(b<<2)+d|0;l=R(l*2147483647+.5);i:{if(N(l)<2147483648){i=~~l;break i}i=-2147483648}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}j=1;if(c>>>0<=e>>>0){break g}ma((e<<2)+d|0,0,c-e<<2)}return j;case 10:break c;default:break b}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}j=1;if(e>>>0>=f>>>0){break b}ma((e<<2)+d|0,0,(c&255)-e<<2)}return j}ma((e<<2)+d|0,0,(c&255)-e<<2);return 1}function zb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=M(0);a:{b:{if(!d){break b}c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=D[b|0];if((e|0)<0){break b}E[(g<<1)+d>>1]=e&255;b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){return 0}e=E[b>>1];if((e|0)<0){break b}E[(g<<1)+d>>1]=e;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=H[b>>1];b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=F[b>>2];if(e>>>0>65535){break b}E[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=F[b>>2];if(e>>>0>65535){break b}E[(g<<1)+d>>1]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=F[b+4>>2];e=F[b>>2];if(!k&e>>>0>65535|k){break b}E[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}k=F[b+4>>2];e=F[b>>2];if(!k&e>>>0>65535|k){break b}E[(g<<1)+d>>1]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=F[a>>2];l=F[e>>2];g=l;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-l|0;if(!G[a+32|0]){l=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(65535)|m=M(0)){i=~~m>>>0}else{i=0}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}l=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(65535)|mM(1)){break d}e=(b<<1)+d|0;j=R(+m*65535+.5);f:{if(j<4294967296&j>=0){i=~~j>>>0;break f}i=0}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}l=1;if(c>>>0<=e>>>0){break d}ma((e<<1)+d|0,0,c-e<<1)}return l;case 9:g:{h:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=F[a>>2];l=F[e>>2];g=l;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-l|0;if(!G[a+32|0]){l=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=K[g>>3];if(j>=65535|j<0|(N(j)==Infinity|j!=j)){break g}e=(b<<1)+d|0;if(j<4294967296&j>=0){i=~~j>>>0}else{i=0}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}l=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=K[g>>3];if(j>=65535|j<0|(N(j)==Infinity|j!=j)){break g}if(j>1){break g}e=(b<<1)+d|0;j=R(j*65535+.5);i:{if(j<4294967296&j>=0){i=~~j>>>0;break i}i=0}E[e>>1]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}l=1;if(c>>>0<=e>>>0){break g}ma((e<<1)+d|0,0,c-e<<1)}return l;case 10:break c;default:break b}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];k=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+k|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}E[(g<<1)+d>>1]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break b}ma((e<<1)+d|0,0,(c&255)-e<<1)}return l}ma((e<<1)+d|0,0,(c&255)-e<<1);return 1}function Ga(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=M(0),l=0,m=0,n=M(0),o=0;a:{if(!d){break a}b:{c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;i=D[b|0];F[e>>2]=i;F[e+4>>2]=i>>31;b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;F[e>>2]=G[b|0];F[e+4>>2]=0;b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;i=E[b>>1];F[e>>2]=i;F[e+4>>2]=i>>31;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;F[e>>2]=H[b>>1];F[e+4>>2]=0;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;i=F[b>>2];F[e>>2]=i;F[e+4>>2]=i>>31;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;F[e>>2]=F[b>>2];F[e+4>>2]=0;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}i=F[b+4>>2];e=(g<<3)+d|0;F[e>>2]=F[b>>2];F[e+4>>2]=i;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=F[b>>2];i=F[b+4>>2];if((i|0)<0){break a}j=(g<<3)+d|0;F[j>>2]=e;F[j+4>>2]=i;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 8:d:{e=G[a+24|0];f=c&255;if(!(e>>>0>>0?e:f)){break d}if(G[a+32|0]){break a}e=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+e|0;e=F[a>>2];i=F[e+4>>2];e=F[e>>2];if((b|0)>=(i-e|0)){break a}g=b+e|0;h=c&255;b=0;while(1){k=J[g>>2];if(k>=M(0x8000000000000000)|k=M(1)?~~(k>M(0)?M(P(M(R(M(k*M(2.3283064365386963e-10)))),M(4294967296))):M(S(M(M(k-M(~~k>>>0>>>0))*M(2.3283064365386963e-10)))))>>>0:0;m=~~k>>>0;break e}j=-2147483648;m=0}F[e>>2]=m;F[e+4>>2]=j;b=b+1|0;e=G[a+24|0];if(b>>>0>=(e>>>0>>0?e:h)>>>0){break d}g=g+4|0;if(i>>>0>g>>>0){continue}break}break a}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 9:f:{e=G[a+24|0];f=c&255;if(!(e>>>0>>0?e:f)){break f}if(G[a+32|0]){break a}e=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+e|0;e=F[a>>2];i=F[e+4>>2];e=F[e>>2];if((b|0)>=(i-e|0)){break a}g=b+e|0;h=c&255;b=0;while(1){l=K[g>>3];if(l>=0x8000000000000000|l<-0x8000000000000000|l!=l){break a}o=N(l);if(o==Infinity){break a}e=(b<<3)+d|0;g:{if(o<0x8000000000000000){j=N(l)>=1?~~(l>0?P(R(l*2.3283064365386963e-10),4294967295):S((l-+(~~l>>>0>>>0))*2.3283064365386963e-10))>>>0:0;m=~~l>>>0;break g}j=-2147483648;m=0}F[e>>2]=m;F[e+4>>2]=j;b=b+1|0;e=G[a+24|0];if(b>>>0>=(e>>>0>>0?e:h)>>>0){break f}g=g+8|0;if(i>>>0>g>>>0){continue}break}break a}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0;break b;case 10:break c;default:break a}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);j=b;b=b+i|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break a}e=(g<<3)+d|0;F[e>>2]=G[b|0];F[e+4>>2]=0;b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}if(e>>>0>=f>>>0){break a}d=(e<<3)+d|0;a=(c&255)-e|0}ma(d,0,a<<3)}}function le(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;j=a;a:{b:{c:{d:{e:{f:{g:{h:{a=F[a+8>>2];switch(F[a+28>>2]-1|0){case 4:break c;case 5:break d;case 2:break e;case 3:break f;case 0:break g;case 1:break h;default:break a}}f=G[a+24|0];c=ka(f);a=F[j+16>>2];if(F[a+80>>2]){g=F[F[a>>2]>>2]+F[a+48>>2]|0}else{g=0}if(!b){break b}if(f){o=f&252;l=f&3;h=f>>>0<4;while(1){a=0;e=0;if(!h){while(1){k=g+(d<<2)|0;D[a+c|0]=F[k>>2];D[(a|1)+c|0]=F[k+4>>2];D[(a|2)+c|0]=F[k+8>>2];D[(a|3)+c|0]=F[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){D[a+c|0]=F[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}la(F[F[F[j+8>>2]+64>>2]>>2]+m|0,c,f);m=f+m|0;n=n+1|0;if((n|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,f);a=a+f|0;la(a+F[F[F[j+8>>2]+64>>2]>>2]|0,c,f);a=a+f|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,f);break b}f=G[a+24|0];c=ka(f);a=F[j+16>>2];if(F[a+80>>2]){g=F[F[a>>2]>>2]+F[a+48>>2]|0}else{g=0}if(!b){break b}if(f){o=f&252;l=f&3;h=f>>>0<4;while(1){a=0;e=0;if(!h){while(1){k=g+(d<<2)|0;D[a+c|0]=F[k>>2];D[(a|1)+c|0]=F[k+4>>2];D[(a|2)+c|0]=F[k+8>>2];D[(a|3)+c|0]=F[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){D[a+c|0]=F[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}la(F[F[F[j+8>>2]+64>>2]>>2]+m|0,c,f);m=f+m|0;n=n+1|0;if((n|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,f);a=a+f|0;la(a+F[F[F[j+8>>2]+64>>2]>>2]|0,c,f);a=a+f|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,f);break b}h=G[a+24|0];i=h<<1;c=ka(i);a=F[j+16>>2];if(F[a+80>>2]){g=F[F[a>>2]>>2]+F[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<1;k=g+(d<<2)|0;E[f+c>>1]=F[k>>2];E[(f|2)+c>>1]=F[k+4>>2];E[(f|4)+c>>1]=F[k+8>>2];E[(f|6)+c>>1]=F[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){E[(a<<1)+c>>1]=F[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}la(F[F[F[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;la(a+F[F[F[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);break b}h=G[a+24|0];i=h<<1;c=ka(i);a=F[j+16>>2];if(F[a+80>>2]){g=F[F[a>>2]>>2]+F[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<1;k=g+(d<<2)|0;E[f+c>>1]=F[k>>2];E[(f|2)+c>>1]=F[k+4>>2];E[(f|4)+c>>1]=F[k+8>>2];E[(f|6)+c>>1]=F[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){E[(a<<1)+c>>1]=F[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}la(F[F[F[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;la(a+F[F[F[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);break b}h=G[a+24|0];i=h<<2;c=ka(i);a=F[j+16>>2];if(F[a+80>>2]){g=F[F[a>>2]>>2]+F[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<2;k=g+(d<<2)|0;F[f+c>>2]=F[k>>2];F[(f|4)+c>>2]=F[k+4>>2];F[(f|8)+c>>2]=F[k+8>>2];F[(f|12)+c>>2]=F[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){F[(a<<2)+c>>2]=F[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}la(F[F[F[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;la(a+F[F[F[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);break b}h=G[a+24|0];i=h<<2;c=ka(i);a=F[j+16>>2];if(F[a+80>>2]){g=F[F[a>>2]>>2]+F[a+48>>2]|0}else{g=0}if(!b){break b}if(h){o=h&252;l=h&3;h=h>>>0<4;while(1){a=0;e=0;if(!h){while(1){f=a<<2;k=g+(d<<2)|0;F[f+c>>2]=F[k>>2];F[(f|4)+c>>2]=F[k+4>>2];F[(f|8)+c>>2]=F[k+8>>2];F[(f|12)+c>>2]=F[k+12>>2];a=a+4|0;d=d+4|0;e=e+4|0;if((o|0)!=(e|0)){continue}break}}e=0;if(l){while(1){F[(a<<2)+c>>2]=F[g+(d<<2)>>2];a=a+1|0;d=d+1|0;e=e+1|0;if((l|0)!=(e|0)){continue}break}}la(F[F[F[j+8>>2]+64>>2]>>2]+n|0,c,i);n=i+n|0;m=m+1|0;if((m|0)!=(b|0)){continue}break}break b}a=0;if((b|0)!=1){g=b&-2;while(1){la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i);a=a+i|0;la(a+F[F[F[j+8>>2]+64>>2]>>2]|0,c,i);a=a+i|0;d=d+2|0;if((g|0)!=(d|0)){continue}break}}if(!(b&1)){break b}la(F[F[F[j+8>>2]+64>>2]>>2]+a|0,c,i)}ja(c);c=1}return c|0}function xb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=M(0);a:{b:{if(!d){break b}c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=D[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=E[b>>1];b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=H[b>>1];b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=F[b>>2];b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=F[b>>2];b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=F[b>>2];if(F[b+4>>2]){break b}F[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}e=F[b>>2];if(F[b+4>>2]){break b}F[(g<<2)+d>>2]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 8:d:{e:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break e}e=F[a>>2];k=F[e>>2];g=k;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-k|0;if(!G[a+32|0]){k=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(4294967296)|m=M(0)){i=~~m>>>0}else{i=0}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}k=0;if((b|0)>=(e|0)){break d}b=0;while(1){m=J[g>>2];if(m>=M(4294967296)|mM(1)){break d}e=(b<<2)+d|0;j=R(+m*4294967295+.5);f:{if(j<4294967296&j>=0){i=~~j>>>0;break f}i=0}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break e}g=g+4|0;if(f>>>0>g>>>0){continue}break}break d}k=1;if(c>>>0<=e>>>0){break d}ma((e<<2)+d|0,0,c-e<<2)}return k;case 9:g:{h:{e=G[a+24|0];c=c&255;if(!(c>>>0>e>>>0?e:c)){break h}e=F[a>>2];k=F[e>>2];g=k;f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+f|0;g=b+g|0;f=F[e+4>>2];e=f-k|0;if(!G[a+32|0]){k=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=K[g>>3];if(j>=4294967295|j<0|(N(j)==Infinity|j!=j)){break g}e=(b<<2)+d|0;if(j<4294967296&j>=0){i=~~j>>>0}else{i=0}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}k=0;if((b|0)>=(e|0)){break g}b=0;while(1){j=K[g>>3];if(j>=4294967295|j<0|(N(j)==Infinity|j!=j)){break g}if(j>1){break g}e=(b<<2)+d|0;j=R(j*4294967295+.5);i:{if(j<4294967296&j>=0){i=~~j>>>0;break i}i=0}F[e>>2]=i;b=b+1|0;e=G[a+24|0];if(b>>>0>=(c>>>0>e>>>0?e:c)>>>0){break h}g=g+8|0;if(f>>>0>g>>>0){continue}break}break g}k=1;if(c>>>0<=e>>>0){break g}ma((e<<2)+d|0,0,c-e<<2)}return k;case 10:break c;default:break b}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];h=F[e>>2];l=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);i=b;b=b+l|0;b=b+h|0;h=F[e+4>>2];while(1){if(b>>>0>=h>>>0){break b}F[(g<<2)+d>>2]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}ma((e<<2)+d|0,0,(c&255)-e<<2)}return k}ma((e<<2)+d|0,0,(c&255)-e<<2);return 1}function rd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;a:{b:{c:{d:{e:{if(F[a+92>>2]==F[a+88>>2]){break e}c=F[a+52>>2];f:{if((c|0)!=F[a+56>>2]){F[c>>2]=b;F[a+52>>2]=c+4;break f}h=F[a+48>>2];g=c-h|0;d=g>>2;f=d+1|0;if(f>>>0>=1073741824){break a}e=g>>>1|0;g=g>>>0>=2147483644?1073741823:f>>>0>>0?e:f;if(g){if(g>>>0>=1073741824){break d}e=ka(g<<2)}else{e=0}f=e+(d<<2)|0;F[f>>2]=b;d=f+4|0;if((c|0)!=(h|0)){while(1){f=f-4|0;c=c-4|0;F[f>>2]=F[c>>2];if((c|0)!=(h|0)){continue}break}}F[a+56>>2]=e+(g<<2);F[a+52>>2]=d;F[a+48>>2]=f;if(!h){break f}ja(h)}F[a+84>>2]=0;c=-1;e=-1;g:{if((b|0)==-1){break g}d=F[a+4>>2];e=b+1|0;e=(e>>>0)%3|0?e:b-2|0;if((e|0)!=-1){c=F[F[d>>2]+(e<<2)>>2]}h:{if((b>>>0)%3|0){l=b-1|0;break h}l=b+2|0;e=-1;if((l|0)==-1){break g}}e=F[F[d>>2]+(l<<2)>>2]}i=e>>>3&536870908;d=F[a+36>>2];h=d+(c>>>3&536870908)|0;g=F[h>>2];f=1<>2]=f|g;f=a+8|0;if((b|0)!=-1){d=b+1|0;d=(d>>>0)%3|0?d:b-2|0}else{d=-1}Ka(f,c,d);d=F[a+36>>2]}f=d+i|0;d=F[f>>2];c=1<>2]=c|d;d=a+8|0;c=-1;i:{if((b|0)==-1){break i}c=b-1|0;if((b>>>0)%3|0){break i}c=b+2|0}Ka(d,e,c)}c=-1;c=(b|0)!=-1?F[F[F[a+4>>2]>>2]+(b<<2)>>2]:c;f=F[a+36>>2]+(c>>>3&536870908)|0;d=F[f>>2];e=1<>2]=d|e;Ka(a+8|0,c,b)}d=F[a+84>>2];if((d|0)>2){break e}while(1){e=L(d,12)+a|0;b=F[e+52>>2];if((b|0)==F[e+48>>2]){d=d+1|0;if((d|0)!=3){continue}break e}b=b-4|0;c=F[b>>2];F[e+52>>2]=b;F[a+84>>2]=d;if((c|0)==-1){break e}f=F[a+24>>2];b=(c>>>0)/3|0;j:{if(F[f+(b>>>3&268435452)>>2]>>>b&1){break j}k:{while(1){k=(c>>>0)/3|0;b=(k>>>3&268435452)+f|0;F[b>>2]=F[b>>2]|1<>2]>>2]+(c<<2)>>2]:d;f=F[a+36>>2]+(d>>>3&536870908)|0;e=F[f>>2];b=1<>2]=b|e;i=F[(F[F[a+16>>2]+96>>2]+L(k,12)|0)+((c>>>0)%3<<2)>>2];l=F[F[a+20>>2]+4>>2];f=F[l+4>>2];t:{if((f|0)!=F[l+8>>2]){F[f>>2]=i;F[l+4>>2]=f+4;break t}j=F[l>>2];h=f-j|0;g=h>>2;e=g+1|0;if(e>>>0>=1073741824){break s}b=h>>>1|0;h=h>>>0>=2147483644?1073741823:b>>>0>e>>>0?b:e;if(h){if(h>>>0>=1073741824){break d}e=ka(h<<2)}else{e=0}b=e+(g<<2)|0;F[b>>2]=i;g=b+4|0;if((f|0)!=(j|0)){while(1){b=b-4|0;f=f-4|0;F[b>>2]=F[f>>2];if((f|0)!=(j|0)){continue}break}}F[l+8>>2]=e+(h<<2);F[l+4>>2]=g;F[l>>2]=b;if(!j){break t}ja(j)}j=F[a+12>>2];f=F[j+4>>2];u:{if((f|0)!=F[j+8>>2]){F[f>>2]=c;F[j+4>>2]=f+4;break u}i=F[j>>2];h=f-i|0;g=h>>2;e=g+1|0;if(e>>>0>=1073741824){break r}b=h>>>1|0;h=h>>>0>=2147483644?1073741823:b>>>0>e>>>0?b:e;if(h){if(h>>>0>=1073741824){break d}e=ka(h<<2)}else{e=0}b=e+(g<<2)|0;F[b>>2]=c;g=b+4|0;if((f|0)!=(i|0)){while(1){b=b-4|0;f=f-4|0;F[b>>2]=F[f>>2];if((f|0)!=(i|0)){continue}break}}F[j+8>>2]=e+(h<<2);F[j+4>>2]=g;F[j>>2]=b;if(!i){break u}ja(i)}b=F[a+12>>2];F[F[b+12>>2]+(d<<2)>>2]=F[b+24>>2];F[b+24>>2]=F[b+24>>2]+1}if((c|0)==-1){break k}g=F[a+4>>2];f=-1;b=c+1|0;b=(b>>>0)%3|0?b:c-2|0;if((b|0)!=-1){f=F[F[g+12>>2]+(b<<2)>>2]}v:{w:{if((L(k,3)|0)!=(c|0)){d=c-1|0;break w}d=c+2|0;c=-1;if((d|0)==-1){break v}}c=F[F[g+12>>2]+(d<<2)>>2]}d=(c|0)==-1;e=(c>>>0)/3|0;if((f|0)!=-1){b=(f>>>0)/3|0;b=F[F[a+24>>2]+(b>>>3&268435452)>>2]&1<>2]+(b>>>3&536870908)>>2]>>>b&1){break x}k=0;b=F[F[g>>2]+(c<<2)>>2];if(!(F[F[a+36>>2]+(b>>>3&536870908)>>2]>>>b&1)){b=F[a+88>>2]+(b<<2)|0;e=F[b>>2];F[b>>2]=e+1;k=(e|0)<=0?2:1}if(F[a+84>>2]>=(k|0)&l){break m}j=L(k,12)+a|0;b=F[j+52>>2];y:{if((b|0)!=F[j+56>>2]){F[b>>2]=c;F[j+52>>2]=b+4;break y}i=F[j+48>>2];h=b-i|0;d=h>>2;g=d+1|0;if(g>>>0>=1073741824){break c}e=h>>>1|0;g=h>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(g){if(g>>>0>=1073741824){break d}e=ka(g<<2)}else{e=0}d=e+(d<<2)|0;F[d>>2]=c;c=d+4|0;if((b|0)!=(i|0)){while(1){d=d-4|0;b=b-4|0;F[d>>2]=F[b>>2];if((b|0)!=(i|0)){continue}break}}F[j+48>>2]=d;F[j+52>>2]=c;F[j+56>>2]=e+(g<<2);if(!i){break y}ja(i)}if(F[a+84>>2]<=(k|0)){break x}F[a+84>>2]=k}if(l){break k}c=-1;if((f|0)==-1){break n}}c=F[F[F[a+4>>2]>>2]+(f<<2)>>2]}b=0;if(!(F[F[a+36>>2]+(c>>>3&536870908)>>2]>>>c&1)){b=F[a+88>>2]+(c<<2)|0;c=F[b>>2];F[b>>2]=c+1;b=(c|0)<=0?2:1}if(F[a+84>>2]<(b|0)){break l}c=f}f=F[a+24>>2];continue}break}k=L(b,12)+a|0;c=F[k+52>>2];z:{if((c|0)!=F[k+56>>2]){F[c>>2]=f;F[k+52>>2]=c+4;break z}i=F[k+48>>2];h=c-i|0;d=h>>2;g=d+1|0;if(g>>>0>=1073741824){break b}e=h>>>1|0;g=h>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(g){if(g>>>0>=1073741824){break d}e=ka(g<<2)}else{e=0}d=e+(d<<2)|0;F[d>>2]=f;f=d+4|0;if((c|0)!=(i|0)){while(1){d=d-4|0;c=c-4|0;F[d>>2]=F[c>>2];if((c|0)!=(i|0)){continue}break}}F[k+48>>2]=d;F[k+52>>2]=f;F[k+56>>2]=e+(g<<2);if(!i){break z}ja(i)}d=F[a+84>>2];if((d|0)<=(b|0)){break j}F[a+84>>2]=b;d=b;break j}d=F[a+84>>2]}if((d|0)<3){continue}break}}return 1}oa();v()}na();v()}na();v()}na();v()}function Mc(a){var b=0,c=0,d=0,e=0,f=0,g=0;e=Z-16|0;Z=e;F[e+12>>2]=a;a:{if(a>>>0<=211){d=F[Lc(10352,10544,e+12|0)>>2];break a}if(a>>>0>=4294967292){V();v()}f=(a>>>0)/210|0;d=L(f,210);F[e+8>>2]=a-d;g=Lc(10544,10736,e+8|0)-10544>>2;while(1){d=F[(g<<2)+10544>>2]+d|0;a=5;while(1){b:{if((a|0)==47){a=211;while(1){b=(d>>>0)/(a>>>0)|0;if(b>>>0>>0){break a}if((L(a,b)|0)==(d|0)){break b}b=a+10|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+12|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+16|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+18|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+22|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+28|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+30|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+36|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+40|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+42|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+46|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+52|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+58|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+60|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+66|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+70|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+72|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+78|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+82|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+88|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+96|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+100|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+102|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+106|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+108|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+112|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+120|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+126|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+130|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+136|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+138|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+142|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+148|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+150|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+156|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+162|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+166|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+168|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+172|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+178|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+180|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+186|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+190|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+192|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+196|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+198|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}if((L(b,c)|0)==(d|0)){break b}b=a+208|0;c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}a=a+210|0;if((L(b,c)|0)!=(d|0)){continue}break}break b}b=F[(a<<2)+10352>>2];c=(d>>>0)/(b>>>0)|0;if(b>>>0>c>>>0){break a}a=a+1|0;if((L(b,c)|0)!=(d|0)){continue}}break}d=g+1|0;a=(d|0)==48;g=a?0:d;f=a+f|0;d=L(f,210);continue}}Z=e+16|0;return d}function lb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=M(0),k=0,l=0;a:{if(!d){break a}b:{c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(D[b|0]);J[(h<<2)+d>>2]=i?M(j/M(127)):j;b=b+1|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(G[b|0]);J[(h<<2)+d>>2]=i?M(j/M(255)):j;b=b+1|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(E[b>>1]);J[(h<<2)+d>>2]=i?M(j/M(32767)):j;b=b+2|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(H[b>>1]);J[(h<<2)+d>>2]=i?M(j/M(65535)):j;b=b+2|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(F[b>>2]);J[(h<<2)+d>>2]=i?M(j*M(4.656612873077393e-10)):j;b=b+4|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(I[b>>2]);J[(h<<2)+d>>2]=i?M(j*M(2.3283064365386963e-10)):j;b=b+4|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(+I[b>>2]+ +F[b+4>>2]*4294967296);J[(h<<2)+d>>2]=i?M(j*M(10842021724855044e-35)):j;b=b+8|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];i=G[a+32|0];while(1){if(b>>>0>=g>>>0){break a}j=M(+I[b>>2]+ +I[b+4>>2]*4294967296);J[(h<<2)+d>>2]=i?M(j*M(5.421010862427522e-20)):j;b=b+8|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 8:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];while(1){if(b>>>0>=g>>>0){break a}J[(h<<2)+d>>2]=J[b>>2];b=b+4|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 9:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];while(1){if(b>>>0>=g>>>0){break a}J[(h<<2)+d>>2]=K[b>>3];b=b+8|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0;break b;case 10:break c;default:break a}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[a>>2];g=F[e>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);k=b;b=b+i|0;b=b+g|0;g=F[e+4>>2];while(1){if(b>>>0>=g>>>0){break a}J[(h<<2)+d>>2]=G[b|0]?M(1):M(0);b=b+1|0;h=h+1|0;e=G[a+24|0];if(h>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}l=1;if(e>>>0>=f>>>0){break a}d=(e<<2)+d|0;a=(c&255)-e|0}ma(d,0,a<<2)}return l}function Cb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=M(0),m=M(0);a:{b:{if(!d){break b}c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}D[d+g|0]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){return 0}e=D[b|0];if((e|0)<0){break b}D[d+g|0]=e;b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>1];if((e+128&65535)>>>0>255){break b}D[d+g|0]=e;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>1];if(e>>>0>127){break b}D[d+g|0]=e;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=F[b>>2];if(e+128>>>0>255){break b}D[d+g|0]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=F[b>>2];if(e>>>0>127){break b}D[d+g|0]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}i=F[b+4>>2];e=F[b>>2];h=e+128|0;i=h>>>0<128?i+1|0:i;if(!i&h>>>0>255|i){break b}D[d+g|0]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}i=F[b+4>>2];e=F[b>>2];if(!i&e>>>0>127|i){break b}D[d+g|0]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 8:e=G[a+24|0];c=c&255;d:{if(c>>>0>e>>>0?e:c){e=F[F[a>>2]>>2];f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+f|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break d}l=J[b>>2];if(l>=M(127)|lM(1)){break d}j=R(+l*127+.5);if(!(N(j)<2147483648)){break f}h=~~j;break e}if(!(m>>0<(c>>>0>e>>>0?e:c)>>>0){continue}break}}k=1;if(c>>>0<=e>>>0){break d}ma(d+e|0,0,c-e|0)}return k;case 9:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}j=K[b>>3];if(j>=127|j<-128|(N(j)==Infinity|j!=j)){break b}e=d+g|0;if(G[a+32|0]){if(j<0|j>1){break b}j=R(j*127+.5)}g:{if(N(j)<2147483648){h=~~j;break g}h=-2147483648}D[e|0]=h;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 10:break c;default:break b}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}D[d+g|0]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}ma(d+e|0,0,(c&255)-e|0)}return k}ma(d+e|0,0,(c&255)-e|0);return 1}function Bb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=M(0);a:{b:{if(!d){break b}c:{switch(F[a+28>>2]-1|0){case 0:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){return 0}e=D[b|0];if((e|0)<0){break b}D[d+g|0]=e;b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 1:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}D[d+g|0]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 2:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>1];if(e>>>0>255){break b}D[d+g|0]=e;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 3:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=H[b>>1];if(e>>>0>255){break b}D[d+g|0]=e;b=b+2|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 4:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=F[b>>2];if(e>>>0>255){break b}D[d+g|0]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 5:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}e=F[b>>2];if(e>>>0>255){break b}D[d+g|0]=e;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 6:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}i=F[b+4>>2];e=F[b>>2];if(!i&e>>>0>255|i){break b}D[d+g|0]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 7:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}i=F[b+4>>2];e=F[b>>2];if(!i&e>>>0>255|i){break b}D[d+g|0]=e;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 8:e=G[a+24|0];c=c&255;d:{if(c>>>0>e>>>0?e:c){e=F[F[a>>2]>>2];f=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+f|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break d}l=J[b>>2];if(l>=M(255)|lM(1)){break d}j=R(+l*255+.5);if(!(j<4294967296&j>=0)){break f}h=~~j>>>0;break e}if(!(l=M(0))){break f}h=~~l>>>0;break e}h=0}D[e|0]=h;b=b+4|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(c>>>0>e>>>0?e:c)>>>0){continue}break}}k=1;if(c>>>0<=e>>>0){break d}ma(d+e|0,0,c-e|0)}return k;case 9:e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}j=K[b>>3];if(j>=255|j<0|(N(j)==Infinity|j!=j)){break b}e=d+g|0;if(G[a+32|0]){if(j>1){break b}j=R(j*255+.5)}g:{if(j<4294967296&j>=0){h=~~j>>>0;break g}h=0}D[e|0]=h;b=b+8|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}break a;case 10:break c;default:break b}}e=G[a+24|0];f=c&255;if(e>>>0>>0?e:f){e=F[F[a>>2]>>2];i=F[a+48>>2];b=ki(F[a+40>>2],F[a+44>>2],b,0);h=b;b=b+i|0;b=b+e|0;while(1){if(I[F[a>>2]+4>>2]<=b>>>0){break b}D[d+g|0]=G[b|0];b=b+1|0;g=g+1|0;e=G[a+24|0];if(g>>>0<(e>>>0>>0?e:f)>>>0){continue}break}}k=1;if(e>>>0>=f>>>0){break b}ma(d+e|0,0,(c&255)-e|0)}return k}ma(d+e|0,0,(c&255)-e|0);return 1}function jc(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;e=Z-48|0;Z=e;f=H[5053]|H[5054]<<16;d=H[5051]|H[5052]<<16;E[e+38>>1]=d;E[e+40>>1]=d>>>16;E[e+42>>1]=f;E[e+44>>1]=f>>>16;d=F[2525];F[e+32>>2]=F[2524];F[e+36>>2]=d;d=F[2523];F[e+24>>2]=F[2522];F[e+28>>2]=d;d=F[2521];F[e+16>>2]=F[2520];F[e+20>>2]=d;g=F[b+8>>2];i=F[b+12>>2];h=F[b+20>>2];d=F[b+16>>2];f=d+5|0;h=f>>>0<5?h+1|0:h;a:{b:{if(g>>>0>>0&(h|0)>=(i|0)|(h|0)>(i|0)){d=ya(e+16|0);if(d>>>0>=2147483632){break a}c:{d:{if(d>>>0>=11){b=(d|15)+1|0;c=ka(b);F[e+8>>2]=b|-2147483648;F[e>>2]=c;F[e+4>>2]=d;b=c+d|0;break d}D[e+11|0]=d;b=d+e|0;c=e;if(!d){break c}}la(c,e+16|0,d)}D[b|0]=0;F[a>>2]=-2;b=a+4|0;if(D[e+11|0]>=0){a=F[e+4>>2];F[b>>2]=F[e>>2];F[b+4>>2]=a;F[b+8>>2]=F[e+8>>2];break b}ra(b,F[e>>2],F[e+4>>2]);if(D[e+11|0]>=0){break b}ja(F[e>>2]);break b}f=d+F[b>>2]|0;d=G[f|0]|G[f+1|0]<<8|(G[f+2|0]<<16|G[f+3|0]<<24);D[c|0]=d;D[c+1|0]=d>>>8;D[c+2|0]=d>>>16;D[c+3|0]=d>>>24;D[c+4|0]=G[f+4|0];d=F[b+20>>2];f=F[b+16>>2]+5|0;d=f>>>0<5?d+1|0:d;F[b+16>>2]=f;F[b+20>>2]=d;if(sa(c,1250,5)){d=ka(32);D[d+17|0]=0;D[d+16|0]=G[1494];c=G[1490]|G[1491]<<8|(G[1492]<<16|G[1493]<<24);b=G[1486]|G[1487]<<8|(G[1488]<<16|G[1489]<<24);D[d+8|0]=b;D[d+9|0]=b>>>8;D[d+10|0]=b>>>16;D[d+11|0]=b>>>24;D[d+12|0]=c;D[d+13|0]=c>>>8;D[d+14|0]=c>>>16;D[d+15|0]=c>>>24;c=G[1482]|G[1483]<<8|(G[1484]<<16|G[1485]<<24);b=G[1478]|G[1479]<<8|(G[1480]<<16|G[1481]<<24);D[d|0]=b;D[d+1|0]=b>>>8;D[d+2|0]=b>>>16;D[d+3|0]=b>>>24;D[d+4|0]=c;D[d+5|0]=c>>>8;D[d+6|0]=c>>>16;D[d+7|0]=c>>>24;F[a>>2]=-1;ra(a+4|0,d,17);ja(d);break b}g=F[b+12>>2];if((g|0)<=(d|0)&I[b+8>>2]<=f>>>0|(d|0)>(g|0)){d=ya(e+16|0);if(d>>>0>=2147483632){break a}e:{f:{if(d>>>0>=11){b=(d|15)+1|0;c=ka(b);F[e+8>>2]=b|-2147483648;F[e>>2]=c;F[e+4>>2]=d;b=c+d|0;break f}D[e+11|0]=d;b=d+e|0;c=e;if(!d){break e}}la(c,e+16|0,d)}D[b|0]=0;F[a>>2]=-2;b=a+4|0;if(D[e+11|0]>=0){a=F[e+4>>2];F[b>>2]=F[e>>2];F[b+4>>2]=a;F[b+8>>2]=F[e+8>>2];break b}ra(b,F[e>>2],F[e+4>>2]);if(D[e+11|0]>=0){break b}ja(F[e>>2]);break b}D[c+5|0]=G[f+F[b>>2]|0];g=F[b+20>>2];d=F[b+16>>2]+1|0;g=d?g:g+1|0;F[b+16>>2]=d;F[b+20>>2]=g;f=F[b+12>>2];if((f|0)<=(g|0)&I[b+8>>2]<=d>>>0|(g|0)>(f|0)){d=ya(e+16|0);if(d>>>0>=2147483632){break a}g:{h:{if(d>>>0>=11){b=(d|15)+1|0;c=ka(b);F[e+8>>2]=b|-2147483648;F[e>>2]=c;F[e+4>>2]=d;b=c+d|0;break h}D[e+11|0]=d;b=d+e|0;c=e;if(!d){break g}}la(c,e+16|0,d)}D[b|0]=0;F[a>>2]=-2;b=a+4|0;if(D[e+11|0]>=0){a=F[e+4>>2];F[b>>2]=F[e>>2];F[b+4>>2]=a;F[b+8>>2]=F[e+8>>2];break b}ra(b,F[e>>2],F[e+4>>2]);if(D[e+11|0]>=0){break b}ja(F[e>>2]);break b}D[c+6|0]=G[d+F[b>>2]|0];h=F[b+20>>2];d=F[b+16>>2]+1|0;h=d?h:h+1|0;F[b+16>>2]=d;F[b+20>>2]=h;f=F[b+12>>2];if((f|0)<=(h|0)&I[b+8>>2]<=d>>>0|(f|0)<(h|0)){d=ya(e+16|0);if(d>>>0>=2147483632){break a}i:{j:{if(d>>>0>=11){b=(d|15)+1|0;c=ka(b);F[e+8>>2]=b|-2147483648;F[e>>2]=c;F[e+4>>2]=d;b=c+d|0;break j}D[e+11|0]=d;b=d+e|0;c=e;if(!d){break i}}la(c,e+16|0,d)}D[b|0]=0;F[a>>2]=-2;b=a+4|0;if(D[e+11|0]>=0){a=F[e+4>>2];F[b>>2]=F[e>>2];F[b+4>>2]=a;F[b+8>>2]=F[e+8>>2];break b}ra(b,F[e>>2],F[e+4>>2]);if(D[e+11|0]>=0){break b}ja(F[e>>2]);break b}D[c+7|0]=G[d+F[b>>2]|0];g=F[b+20>>2];d=F[b+16>>2]+1|0;g=d?g:g+1|0;F[b+16>>2]=d;F[b+20>>2]=g;f=F[b+12>>2];if((f|0)<=(g|0)&I[b+8>>2]<=d>>>0|(g|0)>(f|0)){c=Eb(e,e+16|0);F[a>>2]=-2;b=a+4|0;if(D[c+11|0]>=0){a=F[c+4>>2];F[b>>2]=F[c>>2];F[b+4>>2]=a;F[b+8>>2]=F[c+8>>2];break b}ra(b,F[c>>2],F[c+4>>2]);if(D[c+11|0]>=0){break b}ja(F[c>>2]);break b}D[c+8|0]=G[d+F[b>>2]|0];d=F[b+20>>2];g=F[b+16>>2];f=g+1|0;i=f?d:d+1|0;F[b+16>>2]=f;F[b+20>>2]=i;i=F[b+8>>2];h=F[b+12>>2];g=g+3|0;d=g>>>0<3?d+1|0:d;if(g>>>0>i>>>0&(d|0)>=(h|0)|(d|0)>(h|0)){c=Eb(e,e+16|0);F[a>>2]=-2;b=a+4|0;if(D[c+11|0]>=0){a=F[c+4>>2];F[b>>2]=F[c>>2];F[b+4>>2]=a;F[b+8>>2]=F[c+8>>2];break b}ra(b,F[c>>2],F[c+4>>2]);if(D[c+11|0]>=0){break b}ja(F[c>>2]);break b}d=c;c=F[b>>2]+f|0;E[d+10>>1]=G[c|0]|G[c+1|0]<<8;g=F[b+20>>2];c=F[b+16>>2]+2|0;g=c>>>0<2?g+1|0:g;F[b+16>>2]=c;F[b+20>>2]=g;F[a+8>>2]=0;F[a+12>>2]=0;F[a>>2]=0;F[a+4>>2]=0}Z=e+48|0;return}za();v()}function Mb(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0;e=Z-96|0;Z=e;f=F[a+16>>2];D[e+92|0]=1;F[e+88>>2]=b;F[e+84>>2]=b;F[e+80>>2]=f;j=F[a+20>>2];d=F[j>>2];a:{b:{f=F[F[f+28>>2]+(b<<2)>>2];if(f>>>0>2]-d>>2>>>0){d=F[F[a+8>>2]+(F[d+(f<<2)>>2]<<2)>>2];f=F[a+4>>2];if(!G[f+84|0]){d=F[F[f+68>>2]+(d<<2)>>2]}F[e+72>>2]=0;F[e+76>>2]=0;j=e- -64|0;F[j>>2]=0;F[j+4>>2]=0;F[e+56>>2]=0;F[e+60>>2]=0;Ga(f,d,D[f+24|0],e+56|0);if((b|0)!=-1){f=b+1|0;j=(f>>>0)%3|0?f:b-2|0;m=((b>>>0)%3|0?-1:2)+b|0;while(1){d=j;f=m;c:{if(!F[a+28>>2]){break c}f=b+1|0;d=(f>>>0)%3|0?f:b-2|0;f=b-1|0;if((b>>>0)%3|0){break c}f=b+2|0}n=F[a+20>>2];b=F[n>>2];d=F[F[F[a+16>>2]+28>>2]+(d<<2)>>2];if(d>>>0>=F[n+4>>2]-b>>2>>>0){break b}d=F[F[a+8>>2]+(F[b+(d<<2)>>2]<<2)>>2];b=F[a+4>>2];if(!G[b+84|0]){d=F[F[b+68>>2]+(d<<2)>>2]}F[e+48>>2]=0;F[e+52>>2]=0;F[e+40>>2]=0;F[e+44>>2]=0;F[e+32>>2]=0;F[e+36>>2]=0;Ga(b,d,D[b+24|0],e+32|0);d=F[a+20>>2];b=F[d>>2];f=F[F[F[a+16>>2]+28>>2]+(f<<2)>>2];if(f>>>0>=F[d+4>>2]-b>>2>>>0){break a}d=F[F[a+8>>2]+(F[b+(f<<2)>>2]<<2)>>2];b=F[a+4>>2];if(!G[b+84|0]){d=F[F[b+68>>2]+(d<<2)>>2]}F[e+24>>2]=0;F[e+28>>2]=0;F[e+16>>2]=0;F[e+20>>2]=0;F[e+8>>2]=0;F[e+12>>2]=0;Ga(b,d,D[b+24|0],e+8|0);g=F[e+8>>2];b=F[e+56>>2];d=g-b|0;p=F[e+60>>2];t=F[e+12>>2]-(p+(b>>>0>g>>>0)|0)|0;h=F[e+40>>2];f=F[e+64>>2];n=h-f|0;u=F[e+68>>2];y=F[e+44>>2]-(u+(f>>>0>h>>>0)|0)|0;g=ki(d,t,n,y);w=o-g|0;x=i-(_+(g>>>0>o>>>0)|0)|0;i=w;h=F[e+16>>2];g=h-f|0;u=F[e+20>>2]-((f>>>0>h>>>0)+u|0)|0;k=F[e+32>>2];h=k-b|0;w=F[e+36>>2]-((b>>>0>k>>>0)+p|0)|0;b=ki(g,u,h,w);o=i+b|0;i=_+x|0;i=b>>>0>o>>>0?i+1|0:i;b=l;l=d;p=t;k=F[e+48>>2];f=F[e+72>>2];d=k-f|0;t=F[e+76>>2];x=F[e+52>>2]-(t+(f>>>0>k>>>0)|0)|0;l=ki(l,p,d,x);k=b+l|0;b=_+q|0;b=k>>>0>>0?b+1|0:b;l=F[e+24>>2];p=l-f|0;f=F[e+28>>2]-((f>>>0>l>>>0)+t|0)|0;q=ki(p,f,h,w);l=k-q|0;q=b-(_+(k>>>0>>0)|0)|0;b=ki(g,u,d,x);d=r-b|0;b=s-(_+(b>>>0>r>>>0)|0)|0;s=ki(p,f,n,y);r=s+d|0;b=_+b|0;s=r>>>0>>0?b+1|0:b;b=F[e+88>>2];f=F[e+80>>2];d:{if(G[e+92|0]){e:{f:{g:{h:{if((b|0)==-1){break h}d=b+1|0;b=(d>>>0)%3|0?d:b-2|0;if((b|0)==-1|F[F[f>>2]+(b>>>3&536870908)>>2]>>>b&1){break h}b=F[F[F[f+64>>2]+12>>2]+(b<<2)>>2];if((b|0)!=-1){break g}}F[e+88>>2]=-1;break f}d=b+1|0;b=(d>>>0)%3|0?d:b-2|0;F[e+88>>2]=b;if((b|0)!=-1){break e}}b=F[e+84>>2];d=-1;i:{if((b|0)==-1){break i}j:{if((b>>>0)%3|0){b=b-1|0;break j}b=b+2|0;d=-1;if((b|0)==-1){break i}}d=-1;if(F[F[f>>2]+(b>>>3&536870908)>>2]>>>b&1){break i}b=F[F[F[f+64>>2]+12>>2]+(b<<2)>>2];d=-1;if((b|0)==-1){break i}d=b-1|0;if((b>>>0)%3|0){break i}d=b+2|0}D[e+92|0]=0;F[e+88>>2]=d;break d}if((b|0)!=F[e+84>>2]){break d}F[e+88>>2]=-1;break d}d=-1;k:{if((b|0)==-1){break k}l:{if((b>>>0)%3|0){b=b-1|0;break l}b=b+2|0;d=-1;if((b|0)==-1){break k}}d=-1;if(F[F[f>>2]+(b>>>3&536870908)>>2]>>>b&1){break k}b=F[F[F[f+64>>2]+12>>2]+(b<<2)>>2];d=-1;if((b|0)==-1){break k}d=b-1|0;if((b>>>0)%3|0){break k}d=b+2|0}F[e+88>>2]=d}b=F[e+88>>2];if((b|0)!=-1){continue}break}}b=s>>31;f=b^r;d=f-b|0;b=(b^s)-((b>>>0>f>>>0)+b|0)|0;m=-1;f=2147483647;g=q>>31;h=g^l;j=h-g|0;n=(g^q)-((h>>>0>>0)+g|0)|0;h=n;k=j^-1;g=h^2147483647;n=i;m:{n:{if(!F[a+28>>2]){if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break m}b=b+h|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;f=a;g=i;a=g>>31;d=a;m=d^o;a=m-d|0;i=a;d=(d^g)-((d>>>0>m>>>0)+d|0)|0;a=a+f|0;d=d^2147483647;i=(d|0)==(b|0)&(i^-1)>>>0>>0|b>>>0>d>>>0;a=i?-1:a;if(!(i&0)&(a|0)<=536870912|(a|0)<536870912){break m}b=0;a=a>>>29|0;break n}o:{if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break o}b=b+h|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;k=i;d=i>>31;h=d^o;i=h-d|0;j=(d^k)-((d>>>0>h>>>0)+d|0)|0;g=j^2147483647;d=a;a=i;if((g|0)==(b|0)&d>>>0>(a^-1)>>>0|b>>>0>g>>>0){break o}b=b+j|0;m=a+d|0;b=m>>>0>>0?b+1|0:b;f=b;if(!b&m>>>0<536870913){break m}}b=f>>>29|0;a=(f&536870911)<<3|m>>>29}o=li(o,n,a,b);l=li(l,q,a,b);r=li(r,s,a,b)}F[c+8>>2]=o;F[c+4>>2]=l;F[c>>2]=r;Z=e+96|0;return}ta();v()}ta();v()}ta();v()}function te(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;g=Z-16|0;Z=g;f=1;m=$[F[F[a>>2]+24>>2]](a)|0;a:{if((m|0)<=0){break a}r=a+48|0;f=0;while(1){b:{c:{if(!F[($[F[F[a>>2]+28>>2]](a)|0)+40>>2]){break c}o=l<<2;d=F[o+F[a+36>>2]>>2];c=F[d+8>>2];e=bb(d);if(!e){break c}h=F[($[F[F[a>>2]+28>>2]](a)|0)+40>>2];F[g+12>>2]=F[c+56>>2];d=ka(32);F[g>>2]=d;F[g+4>>2]=24;F[g+8>>2]=-2147483616;c=G[1196]|G[1197]<<8|(G[1198]<<16|G[1199]<<24);b=G[1192]|G[1193]<<8|(G[1194]<<16|G[1195]<<24);D[d+16|0]=b;D[d+17|0]=b>>>8;D[d+18|0]=b>>>16;D[d+19|0]=b>>>24;D[d+20|0]=c;D[d+21|0]=c>>>8;D[d+22|0]=c>>>16;D[d+23|0]=c>>>24;c=G[1188]|G[1189]<<8|(G[1190]<<16|G[1191]<<24);b=G[1184]|G[1185]<<8|(G[1186]<<16|G[1187]<<24);D[d+8|0]=b;D[d+9|0]=b>>>8;D[d+10|0]=b>>>16;D[d+11|0]=b>>>24;D[d+12|0]=c;D[d+13|0]=c>>>8;D[d+14|0]=c>>>16;D[d+15|0]=c>>>24;c=G[1180]|G[1181]<<8|(G[1182]<<16|G[1183]<<24);b=G[1176]|G[1177]<<8|(G[1178]<<16|G[1179]<<24);D[d|0]=b;D[d+1|0]=b>>>8;D[d+2|0]=b>>>16;D[d+3|0]=b>>>24;D[d+4|0]=c;D[d+5|0]=c>>>8;D[d+6|0]=c>>>16;D[d+7|0]=c>>>24;D[d+24|0]=0;c=h+16|0;b=F[c>>2];d:{e:{if(!b){break e}i=F[g+12>>2];d=c;while(1){k=(i|0)>F[b+16>>2];d=k?d:b;b=F[(k?b+4|0:b)>>2];if(b){continue}break}if((c|0)==(d|0)|(i|0)>2]){break e}b=F[d+24>>2];if(!b){break e}i=d+20|0;d=G[g+11|0];c=d<<24>>24<0;k=c?F[g>>2]:g;d=c?F[g+4>>2]:d;while(1){c=G[b+27|0];j=c<<24>>24<0;c=j?F[b+20>>2]:c;p=c>>>0>>0;f:{g:{h:{i:{j:{k:{n=p?c:d;if(n){j=j?F[b+16>>2]:b+16|0;q=sa(k,j,n);if(q){break k}if(c>>>0<=d>>>0){break j}break f}if(c>>>0<=d>>>0){break i}break f}if((q|0)<0){break f}}c=sa(j,k,n);if(c){break h}}if(p){break g}d=gc(i,g);break d}if((c|0)<0){break g}d=gc(i,g);break d}b=b+4|0}b=F[b>>2];if(b){continue}break}}d=gc(h,g)}if(D[g+11|0]<0){ja(F[g>>2])}if(!d){break c}d=0;c=F[F[o+F[a+36>>2]>>2]+8>>2];if(!F[c+64>>2]){b=ka(32);F[b+16>>2]=0;F[b+20>>2]=0;F[b+8>>2]=0;F[b>>2]=0;F[b+4>>2]=0;F[b+24>>2]=0;F[b+28>>2]=0;f=F[c+64>>2];F[c+64>>2]=b;if(f){b=F[f>>2];if(b){F[f+4>>2]=b;ja(b)}ja(f);b=F[c+64>>2]}F[c>>2]=b;f=F[b+20>>2];F[c+8>>2]=F[b+16>>2];F[c+12>>2]=f;f=F[b+24>>2];b=F[b+28>>2];F[c+48>>2]=0;F[c+52>>2]=0;F[c+40>>2]=0;F[c+44>>2]=0;F[c+16>>2]=f;F[c+20>>2]=b}l:{D[c+24|0]=G[e+24|0];F[c+28>>2]=F[e+28>>2];D[c+32|0]=G[e+32|0];b=F[e+44>>2];F[c+40>>2]=F[e+40>>2];F[c+44>>2]=b;b=F[e+52>>2];F[c+48>>2]=F[e+48>>2];F[c+52>>2]=b;F[c+56>>2]=F[e+56>>2];b=F[e+12>>2];F[c+8>>2]=F[e+8>>2];F[c+12>>2]=b;b=F[e+20>>2];F[c+16>>2]=F[e+16>>2];F[c+20>>2]=b;F[c+60>>2]=F[e+60>>2];f=F[e>>2];m:{if(!f){F[c>>2]=0;b=1;break m}h=F[c>>2];b=0;if(!h){break m}b=F[f>>2];f=F[f+4>>2]-b|0;md(h,b,f,0);b=1}if(!b){break l}D[c+84|0]=G[e+84|0];F[c+80>>2]=F[e+80>>2];if((c|0)!=(e|0)){gb(c+68|0,F[e+68>>2],F[e+72>>2])}n:{h=F[e+88>>2];o:{if(h){f=ka(40);e=F[h>>2];F[f+16>>2]=0;F[f+8>>2]=0;F[f+12>>2]=0;F[f>>2]=e;e=F[h+12>>2];b=F[h+8>>2];if((e|0)!=(b|0)){b=e-b|0;if((b|0)<0){break n}e=ka(b);F[f+12>>2]=e;F[f+8>>2]=e;F[f+16>>2]=b+e;b=F[h+8>>2];i=F[h+12>>2];p:{if((b|0)==(i|0)){break p}k=i+(b^-1)|0;j=i-b&7;if(j){while(1){D[e|0]=G[b|0];e=e+1|0;b=b+1|0;d=d+1|0;if((j|0)!=(d|0)){continue}break}}if(k>>>0<7){break p}while(1){D[e|0]=G[b|0];D[e+1|0]=G[b+1|0];D[e+2|0]=G[b+2|0];D[e+3|0]=G[b+3|0];D[e+4|0]=G[b+4|0];D[e+5|0]=G[b+5|0];D[e+6|0]=G[b+6|0];D[e+7|0]=G[b+7|0];e=e+8|0;b=b+8|0;if((i|0)!=(b|0)){continue}break}}F[f+12>>2]=e}d=F[h+36>>2];F[f+32>>2]=F[h+32>>2];F[f+36>>2]=d;d=F[h+28>>2];F[f+24>>2]=F[h+24>>2];F[f+28>>2]=d;e=F[c+88>>2];F[c+88>>2]=f;if(e){break o}break l}e=F[c+88>>2];F[c+88>>2]=0;if(!e){break l}}d=F[e+8>>2];if(d){F[e+12>>2]=d;ja(d)}ja(e);break l}na();v()}break b}d=F[F[a+36>>2]+(l<<2)>>2];if(!($[F[F[d>>2]+24>>2]](d,r)|0)){break a}}l=l+1|0;f=(m|0)<=(l|0);if((l|0)!=(m|0)){continue}break}}Z=g+16|0;return f|0}function Jg(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;f=Z-32|0;Z=f;a:{if(!hb(1,f+28|0,F[a+32>>2])){break a}if(!hb(1,f+24|0,F[a+32>>2])){break a}l=F[f+28>>2];if(l>>>0>1431655765){break a}d=F[a+32>>2];c=d;i=F[c+8>>2];b=F[c+16>>2];h=F[c+12>>2];c=F[c+20>>2];g=li(i-b|0,h-(c+(b>>>0>i>>>0)|0)|0,3,0);if(!_&g>>>0>>0){break a}n=F[f+24>>2];g=ki(l,0,3,0);if(!_&g>>>0>>0|((c|0)>=(h|0)&b>>>0>=i>>>0|(c|0)>(h|0))){break a}i=G[b+F[d>>2]|0];b=b+1|0;c=b?c:c+1|0;F[d+16>>2]=b;F[d+20>>2]=c;b:{c:{if(!i){d=0;c=Z-32|0;Z=c;F[c+24>>2]=0;F[c+16>>2]=0;F[c+20>>2]=0;d:{e:{b=L(l,3);if(b){if(b>>>0>=1073741824){break e}i=L(l,12);d=ka(i);ma(d,0,i)}b=mc(b,1,F[a+32>>2],d);f:{g:{if(!(!l|!b)){i=0;while(1){h:{g=e;b=(i<<2)+d|0;h=F[b>>2];e=h>>>1|0;h=g+(h&1?0-e|0:e)|0;if((h|0)<0){break h}F[c>>2]=h;e=F[b+4>>2];g=e>>>1|0;h=h+(e&1?0-g|0:g)|0;if((h|0)<0){break h}F[c+4>>2]=h;b=F[b+8>>2];e=b>>>1|0;e=h+(b&1?0-e|0:e)|0;if((e|0)<0){break h}F[c+8>>2]=e;mb(F[a+44>>2]+96|0,c);i=i+3|0;b=1;j=j+1|0;if((j|0)!=(l|0)){continue}break g}break}b=0;break g}if(!d){break f}}ja(d)}Z=c+32|0;break d}na();v()}if(b){break c}break a}if(n>>>0<=255){if(!l){break c}while(1){i:{F[f+16>>2]=0;F[f+8>>2]=0;F[f+12>>2]=0;d=F[a+32>>2];b=d;i=F[b+16>>2];e=F[b+8>>2];c=F[b+20>>2];g=F[b+12>>2];b=g;if(e>>>0<=i>>>0&(c|0)>=(b|0)|(b|0)<(c|0)){break i}j=F[d>>2];m=G[j+i|0];b=c;h=i+1|0;b=h?b:b+1|0;F[d+16>>2]=h;F[d+20>>2]=b;F[f+8>>2]=m;m=e>>>0>>0&(c|0)>=(g|0)|(c|0)>(g|0);e=m?i:e;g=m?c:g;if((e|0)==(h|0)&(g|0)==(b|0)){break i}m=G[h+j|0];b=c;h=i+2|0;b=h>>>0<2?b+1|0:b;F[d+16>>2]=h;F[d+20>>2]=b;F[f+12>>2]=m;if((e|0)==(h|0)&(b|0)==(g|0)){break i}h=G[h+j|0];b=c;c=i+3|0;b=c>>>0<3?b+1|0:b;F[d+16>>2]=c;F[d+20>>2]=b;F[f+16>>2]=h;mb(F[a+44>>2]+96|0,f+8|0);k=k+1|0;if((l|0)!=(k|0)){continue}break c}break}k=0;break a}if(n>>>0<=65535){if(!l){break c}while(1){j:{F[f+16>>2]=0;F[f+8>>2]=0;F[f+12>>2]=0;j=F[a+32>>2];b=j;c=F[b+8>>2];d=F[b+12>>2];h=F[b+16>>2];b=F[b+20>>2];i=b;e=h+2|0;b=e>>>0<2?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break j}m=F[j>>2];g=m+h|0;g=G[g|0]|G[g+1|0]<<8;F[j+16>>2]=e;F[j+20>>2]=b;F[f+8>>2]=g;b=i;g=h+4|0;b=g>>>0<4?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break j}e=e+m|0;e=G[e|0]|G[e+1|0]<<8;F[j+16>>2]=g;F[j+20>>2]=b;F[f+12>>2]=e;e=c;b=i;c=h+6|0;b=c>>>0<6?b+1|0:b;if(c>>>0>e>>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break j}d=g+m|0;d=G[d|0]|G[d+1|0]<<8;F[j+16>>2]=c;F[j+20>>2]=b;F[f+16>>2]=d;mb(F[a+44>>2]+96|0,f+8|0);k=k+1|0;if((l|0)!=(k|0)){continue}break c}break}k=0;break a}k:{if(n>>>0>2097151){break k}b=H[a+36>>1];if(((b<<8|b>>>8)&65535)>>>0<514){break k}if(!l){break c}while(1){l:{F[f+16>>2]=0;F[f+8>>2]=0;F[f+12>>2]=0;if(!hb(1,f+4|0,F[a+32>>2])){break l}F[f+8>>2]=F[f+4>>2];if(!hb(1,f+4|0,F[a+32>>2])){break l}F[f+12>>2]=F[f+4>>2];if(!hb(1,f+4|0,F[a+32>>2])){break l}F[f+16>>2]=F[f+4>>2];mb(F[a+44>>2]+96|0,f+8|0);k=k+1|0;if((l|0)!=(k|0)){continue}break c}break}k=0;break a}if(!l){break c}while(1){F[f+16>>2]=0;F[f+8>>2]=0;F[f+12>>2]=0;j=F[a+32>>2];b=j;c=F[b+8>>2];d=F[b+12>>2];h=F[b+16>>2];b=F[b+20>>2];i=b;e=h+4|0;b=e>>>0<4?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break b}m=F[j>>2];g=m+h|0;g=G[g|0]|G[g+1|0]<<8|(G[g+2|0]<<16|G[g+3|0]<<24);F[j+16>>2]=e;F[j+20>>2]=b;F[f+8>>2]=g;b=i;g=h+8|0;b=g>>>0<8?b+1|0:b;if(c>>>0>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break b}e=e+m|0;e=G[e|0]|G[e+1|0]<<8|(G[e+2|0]<<16|G[e+3|0]<<24);F[j+16>>2]=g;F[j+20>>2]=b;F[f+12>>2]=e;e=c;b=i;c=h+12|0;b=c>>>0<12?b+1|0:b;if(c>>>0>e>>>0&(b|0)>=(d|0)|(b|0)>(d|0)){break b}d=g+m|0;d=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);F[j+16>>2]=c;F[j+20>>2]=b;F[f+16>>2]=d;mb(F[a+44>>2]+96|0,f+8|0);k=k+1|0;if((l|0)!=(k|0)){continue}break}}F[F[a+4>>2]+80>>2]=n;k=1;break a}k=0}Z=f+32|0;return k|0}function Ld(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0;g=Z+-64|0;Z=g;F[g+56>>2]=0;F[g+48>>2]=0;F[g+52>>2]=0;F[g+40>>2]=0;F[g+44>>2]=0;F[g+32>>2]=0;F[g+36>>2]=0;F[g+24>>2]=0;F[g+28>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;F[g+8>>2]=0;F[g+12>>2]=0;h=g+8|0;a:{b:{if(!H[b+38>>1]){break b}if(!Ta(1,h+12|0,b)){break b}e=F[b+8>>2];f=F[b+16>>2];j=e-f|0;k=F[h+12>>2];e=F[b+12>>2]-(F[b+20>>2]+(e>>>0>>0)|0)|0;if(j>>>0>>6>>>0&(e|0)<=0|(e|0)<0){break b}e=F[h>>2];d=F[h+4>>2]-e>>2;c:{if(d>>>0>>0){qa(h,k-d|0);k=F[h+12>>2];break c}if(d>>>0<=k>>>0){break c}F[h+4>>2]=e+(k<<2)}i=1;if(!k){break a}e=F[b+16>>2];d=F[b+20>>2];r=F[h>>2];l=F[b+8>>2];o=F[b+12>>2];j=0;while(1){i=0;if((d|0)>=(o|0)&e>>>0>=l>>>0|(d|0)>(o|0)){break a}i=F[b>>2];p=G[i+e|0];e=e+1|0;d=e?d:d+1|0;F[b+16>>2]=e;F[b+20>>2]=d;f=p>>>2|0;m=0;d:{e:{f:{g:{s=p&3;switch(s|0){case 3:break g;case 0:break e;default:break f}}f=f+j|0;i=0;if(f>>>0>=k>>>0){break a}ma(r+(j<<2)|0,0,(p&252)+4|0);j=f;break d}while(1){if((e|0)==(l|0)&(d|0)==(o|0)){break b}k=G[e+i|0];e=e+1|0;d=e?d:d+1|0;F[b+16>>2]=e;F[b+20>>2]=d;f=k<<(m<<3|6)|f;m=m+1|0;if((s|0)!=(m|0)){continue}break}}F[r+(j<<2)>>2]=f}j=j+1|0;k=F[h+12>>2];if(j>>>0>>0){continue}break}d=h+16|0;o=F[h>>2];f=F[h+16>>2];e=F[h+20>>2]-f|0;h:{if(e>>>0<=4194303){qa(d,1048576-(e>>>2|0)|0);break h}if((e|0)==4194304){break h}F[h+20>>2]=f+4194304}e=h+28|0;j=F[e>>2];f=F[h+32>>2]-j>>3;i:{if(f>>>0>>0){_a(e,k-f|0);j=F[e>>2];break i}if(f>>>0>k>>>0){F[h+32>>2]=(k<<3)+j}if(!k){break b}}l=F[d>>2];d=0;i=0;while(1){e=o+(d<<2)|0;h=F[e>>2];m=(d<<3)+j|0;f=i;F[m+4>>2]=f;F[m>>2]=h;e=F[e>>2];i=e+f|0;if(i>>>0>1048576){break b}j:{if(f>>>0>=i>>>0){break j}m=0;h=e&7;if(h){while(1){F[l+(f<<2)>>2]=d;f=f+1|0;m=m+1|0;if((h|0)!=(m|0)){continue}break}}if(e-1>>>0<=6){break j}while(1){e=l+(f<<2)|0;F[e>>2]=d;F[e+28>>2]=d;F[e+24>>2]=d;F[e+20>>2]=d;F[e+16>>2]=d;F[e+12>>2]=d;F[e+8>>2]=d;F[e+4>>2]=d;f=f+8|0;if((i|0)!=(f|0)){continue}break}}d=d+1|0;if((k|0)!=(d|0)){continue}break}n=(i|0)==1048576}i=n}k:{if(!i|(F[g+20>>2]?0:a)){break k}i=0;j=Z-16|0;Z=j;l:{if(!Sa(1,j+8|0,b)){break l}d=F[b+8>>2];f=F[b+16>>2];l=d-f|0;n=F[j+12>>2];h=F[b+20>>2];d=F[b+12>>2]-(h+(d>>>0>>0)|0)|0;e=F[j+8>>2];if((n|0)==(d|0)&e>>>0>l>>>0|d>>>0>>0){break l}d=h+n|0;l=e+f|0;d=l>>>0>>0?d+1|0:d;F[b+16>>2]=l;F[b+20>>2]=d;if((e|0)<=0){break l}b=f+F[b>>2]|0;F[g+48>>2]=b;d=e-1|0;f=d+b|0;l=G[f|0];m:{if(l>>>0<=63){F[g+52>>2]=d;b=G[f|0]&63;break m}n:{switch((l>>>6|0)-1|0){case 0:if(e>>>0<2){break l}d=e-2|0;F[g+52>>2]=d;b=b+d|0;b=G[b+1|0]<<8&16128|G[b|0];break m;case 1:if(e>>>0<3){break l}d=e-3|0;F[g+52>>2]=d;b=b+d|0;b=G[b+1|0]<<8|G[b+2|0]<<16&4128768|G[b|0];break m;default:break n}}d=e-4|0;F[g+52>>2]=d;b=b+d|0;b=(G[b|0]|G[b+1|0]<<8|(G[b+2|0]<<16|G[b+3|0]<<24))&1073741823}F[g+56>>2]=b+4194304;i=b>>>0<1069547520}Z=j+16|0;if(!i){break k}if(!a){t=1;break k}b=F[g+52>>2];f=F[g+56>>2];d=F[g+36>>2];e=F[g+48>>2];j=F[g+24>>2];while(1){o:{if(f>>>0>4194303){break o}while(1){if((b|0)<=0){break o}b=b-1|0;F[g+52>>2]=b;f=G[b+e|0]|f<<8;F[g+56>>2]=f;if(f>>>0<4194304){continue}break}}i=f&1048575;l=F[j+(i<<2)>>2];n=d+(l<<3)|0;f=(L(F[n>>2],f>>>20|0)+i|0)-F[n+4>>2]|0;F[g+56>>2]=f;F[(q<<2)+c>>2]=l;t=1;q=q+1|0;if((q|0)!=(a|0)){continue}break}}a=F[g+36>>2];if(a){F[g+40>>2]=a;ja(a)}a=F[g+24>>2];if(a){F[g+28>>2]=a;ja(a)}a=F[g+8>>2];if(a){F[g+12>>2]=a;ja(a)}Z=g- -64|0;return t}function kh(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=M(0),f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=M(0),p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0;if(F[c>>2]==F[c+4>>2]){m=F[d+80>>2];u=Z-16|0;Z=u;g=F[a+4>>2];k=G[b+24|0];h=F[d+48>>2];n=F[F[d>>2]>>2];c=u+8|0;F[c>>2]=1065353216;d=c;J[c>>2]=M(-1<>2];c=ka(k<<2);a:{if(!m|!k){break a}p=h+n|0;o=J[d>>2];n=F[a+8>>2];v=F[b>>2];d=F[b+48>>2];g=F[b+40>>2];w=F[b+44>>2];if(!G[b+84|0]){f=F[b+68>>2];s=k&254;t=k&1;a=0;while(1){b=F[v>>2];l=ki(g,w,F[f+(i<<2)>>2],0)+d|0;h=la(c,b+l|0,g);b=0;q=0;if((k|0)!=1){while(1){l=p+(a<<2)|0;j=b<<2;e=M(R(M(M(o*M(J[j+h>>2]-J[n+j>>2]))+M(.5))));b:{if(M(N(e))>2]=r;j=j|4;e=M(R(M(M(o*M(J[j+h>>2]-J[n+j>>2]))+M(.5))));c:{if(M(N(e))>2]=j;b=b+2|0;a=a+2|0;q=q+2|0;if((s|0)!=(q|0)){continue}break}}if(t){l=p+(a<<2)|0;b=b<<2;e=M(R(M(M(o*M(J[b+h>>2]-J[b+n>>2]))+M(.5))));d:{if(M(N(e))>2]=b;a=a+1|0}i=i+1|0;if((m|0)!=(i|0)){continue}break}break a}s=k&254;t=k&1;a=0;while(1){b=F[v>>2];h=ki(g,w,i,l)+d|0;j=la(c,b+h|0,g);b=0;q=0;if((k|0)!=1){while(1){h=p+(a<<2)|0;f=b<<2;e=M(R(M(M(o*M(J[f+j>>2]-J[f+n>>2]))+M(.5))));e:{if(M(N(e))>2]=r;f=f|4;e=M(R(M(M(o*M(J[f+j>>2]-J[f+n>>2]))+M(.5))));f:{if(M(N(e))>2]=f;b=b+2|0;a=a+2|0;q=q+2|0;if((s|0)!=(q|0)){continue}break}}if(t){h=p+(a<<2)|0;b=b<<2;e=M(R(M(M(o*M(J[b+j>>2]-J[b+n>>2]))+M(.5))));g:{if(M(N(e))>2]=b;a=a+1|0}b=l;i=i+1|0;b=i?b:b+1|0;l=b;if((i|0)!=(m|0)|b){continue}break}}ja(c);Z=u+16|0;return 1}j=Z-16|0;Z=j;m=F[a+4>>2];i=G[b+24|0];g=F[d+48>>2];h=F[F[d>>2]>>2];d=j+8|0;F[d>>2]=1065353216;l=d;J[d>>2]=M(-1<>2];d=ka(i<<2);m=F[c+4>>2];q=F[c>>2];h:{if(!i|(m|0)==(q|0)){break h}n=h+g|0;c=m-q>>2;u=c>>>0<=1?1:c;o=J[l>>2];h=F[a+8>>2];v=F[b>>2];l=F[b+48>>2];m=F[b+40>>2];w=F[b+44>>2];if(G[b+84|0]){s=i&254;t=i&1;a=0;c=0;while(1){b=F[v>>2];g=ki(m,w,F[q+(c<<2)>>2],0)+l|0;p=la(d,b+g|0,m);b=0;k=0;if((i|0)!=1){while(1){g=n+(a<<2)|0;f=b<<2;e=M(R(M(M(o*M(J[f+p>>2]-J[h+f>>2]))+M(.5))));i:{if(M(N(e))>2]=r;f=f|4;e=M(R(M(M(o*M(J[f+p>>2]-J[h+f>>2]))+M(.5))));j:{if(M(N(e))>2]=f;b=b+2|0;a=a+2|0;k=k+2|0;if((s|0)!=(k|0)){continue}break}}if(t){g=n+(a<<2)|0;b=b<<2;e=M(R(M(M(o*M(J[b+p>>2]-J[b+h>>2]))+M(.5))));k:{if(M(N(e))>2]=b;a=a+1|0}c=c+1|0;if((u|0)!=(c|0)){continue}break}break h}s=F[b+68>>2];t=i&254;x=i&1;a=0;c=0;while(1){b=F[v>>2];g=ki(m,w,F[s+(F[q+(c<<2)>>2]<<2)>>2],0)+l|0;p=la(d,b+g|0,m);b=0;k=0;if((i|0)!=1){while(1){g=n+(a<<2)|0;f=b<<2;e=M(R(M(M(o*M(J[f+p>>2]-J[h+f>>2]))+M(.5))));l:{if(M(N(e))>2]=r;f=f|4;e=M(R(M(M(o*M(J[f+p>>2]-J[h+f>>2]))+M(.5))));m:{if(M(N(e))>2]=f;b=b+2|0;a=a+2|0;k=k+2|0;if((t|0)!=(k|0)){continue}break}}if(x){g=n+(a<<2)|0;b=b<<2;e=M(R(M(M(o*M(J[b+p>>2]-J[b+h>>2]))+M(.5))));n:{if(M(N(e))>2]=b;a=a+1|0}c=c+1|0;if((u|0)!=(c|0)){continue}break}}ja(d);Z=j+16|0;return 1} +function Cd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;c=F[a+4>>2];e=F[a>>2];f=(c-e|0)/144|0;if(f>>>0>>0){e=a;b=b-f|0;h=F[a+8>>2];c=F[a+4>>2];a:{if(b>>>0<=(h-c|0)/144>>>0){b:{if(!b){break b}a=c;f=b&7;if(f){while(1){va(a);a=a+144|0;d=d+1|0;if((f|0)!=(d|0)){continue}break}}c=L(b,144)+c|0;if((b-1&268435455)>>>0<7){break b}while(1){va(a);va(a+144|0);va(a+288|0);va(a+432|0);va(a+576|0);va(a+720|0);va(a+864|0);va(a+1008|0);a=a+1152|0;if((c|0)!=(a|0)){continue}break}}F[e+4>>2]=c;break a}c:{d:{e:{a=c;c=F[e>>2];i=(a-c|0)/144|0;a=i+b|0;if(a>>>0<29826162){c=(h-c|0)/144|0;f=c<<1;f=c>>>0>=14913080?29826161:a>>>0>>0?f:a;if(f){if(f>>>0>=29826162){break e}g=ka(L(f,144))}c=L(i,144)+g|0;a=c;h=b&7;if(h){while(1){va(a);a=a+144|0;d=d+1|0;if((h|0)!=(d|0)){continue}break}}h=L(b,144)+c|0;if((b-1&268435455)>>>0>=7){while(1){va(a);va(a+144|0);va(a+288|0);va(a+432|0);va(a+576|0);va(a+720|0);va(a+864|0);va(a+1008|0);a=a+1152|0;if((h|0)!=(a|0)){continue}break}}b=L(f,144)+g|0;d=F[e+4>>2];f=F[e>>2];if((d|0)==(f|0)){break d}while(1){c=c-144|0;d=d-144|0;a=d;F[c>>2]=F[a>>2];F[c+4>>2]=F[a+4>>2];F[c+8>>2]=F[a+8>>2];F[c+12>>2]=F[a+12>>2];F[a+12>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[c+16>>2]=F[a+16>>2];F[c+20>>2]=F[a+20>>2];F[c+24>>2]=F[a+24>>2];F[a+24>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;g=G[a+28|0];F[c+40>>2]=0;F[c+32>>2]=0;F[c+36>>2]=0;D[c+28|0]=g;F[c+32>>2]=F[a+32>>2];F[c+36>>2]=F[a+36>>2];F[c+40>>2]=F[a+40>>2];F[a+40>>2]=0;F[a+32>>2]=0;F[a+36>>2]=0;F[c+52>>2]=0;F[c+44>>2]=0;F[c+48>>2]=0;F[c+44>>2]=F[a+44>>2];F[c+48>>2]=F[a+48>>2];F[c+52>>2]=F[a+52>>2];F[a+52>>2]=0;F[a+44>>2]=0;F[a+48>>2]=0;g=c- -64|0;F[g>>2]=0;F[c+56>>2]=0;F[c+60>>2]=0;F[c+56>>2]=F[a+56>>2];F[c+60>>2]=F[a+60>>2];i=g;g=a- -64|0;F[i>>2]=F[g>>2];F[g>>2]=0;F[a+56>>2]=0;F[a+60>>2]=0;F[c+68>>2]=F[a+68>>2];g=F[a+72>>2];F[c+84>>2]=0;F[c+76>>2]=0;F[c+80>>2]=0;F[c+72>>2]=g;F[c+76>>2]=F[a+76>>2];F[c+80>>2]=F[a+80>>2];F[c+84>>2]=F[a+84>>2];F[a+84>>2]=0;F[a+76>>2]=0;F[a+80>>2]=0;F[c+96>>2]=0;F[c+88>>2]=0;F[c+92>>2]=0;F[c+88>>2]=F[a+88>>2];F[c+92>>2]=F[a+92>>2];F[c+96>>2]=F[a+96>>2];F[a+96>>2]=0;F[a+88>>2]=0;F[a+92>>2]=0;g=G[a+100|0];F[c+112>>2]=0;F[c+104>>2]=0;F[c+108>>2]=0;D[c+100|0]=g;F[c+104>>2]=F[a+104>>2];F[c+108>>2]=F[a+108>>2];F[c+112>>2]=F[a+112>>2];F[a+112>>2]=0;F[a+104>>2]=0;F[a+108>>2]=0;F[c+124>>2]=0;F[c+116>>2]=0;F[c+120>>2]=0;F[c+116>>2]=F[a+116>>2];F[c+120>>2]=F[a+120>>2];F[c+124>>2]=F[a+124>>2];F[a+124>>2]=0;F[a+116>>2]=0;F[a+120>>2]=0;g=F[a+128>>2];F[c+140>>2]=0;F[c+132>>2]=0;F[c+136>>2]=0;F[c+128>>2]=g;F[c+132>>2]=F[a+132>>2];F[c+136>>2]=F[a+136>>2];F[c+140>>2]=F[a+140>>2];F[a+140>>2]=0;F[a+132>>2]=0;F[a+136>>2]=0;if((a|0)!=(f|0)){continue}break}F[e+8>>2]=b;a=F[e+4>>2];F[e+4>>2]=h;d=F[e>>2];F[e>>2]=c;if((a|0)==(d|0)){break c}while(1){b=a-144|0;c=F[b+132>>2];if(c){F[a-8>>2]=c;ja(c)}c=F[a-28>>2];if(c){F[a-24>>2]=c;ja(c)}c=F[a-40>>2];if(c){F[a-36>>2]=c;ja(c)}Gb(a-140|0);a=b;if((d|0)!=(a|0)){continue}break}break c}na();v()}oa();v()}F[e+8>>2]=b;F[e+4>>2]=h;F[e>>2]=c}if(d){ja(d)}}return}if(b>>>0>>0){e=e+L(b,144)|0;if((e|0)!=(c|0)){while(1){b=c-144|0;d=F[b+132>>2];if(d){F[c-8>>2]=d;ja(d)}d=F[c-28>>2];if(d){F[c-24>>2]=d;ja(d)}d=F[c-40>>2];if(d){F[c-36>>2]=d;ja(d)}Gb(c-140|0);c=b;if((e|0)!=(c|0)){continue}break}}F[a+4>>2]=e}}function Yc(a){var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;F[a+56>>2]=F[a+52>>2];F[a+44>>2]=F[a+40>>2];b=F[a+64>>2];c=F[b+24>>2];if((c|0)==F[b+28>>2]){return 1}a:{b:{c:{while(1){g=i;i=F[(k<<2)+c>>2];d:{if((i|0)==-1){i=g;break d}b=F[a+56>>2];e:{if((b|0)!=F[a+60>>2]){F[b>>2]=g;F[a+56>>2]=b+4;break e}d=F[a+52>>2];e=b-d|0;h=e>>2;c=h+1|0;if(c>>>0>=1073741824){break c}f=e>>>1|0;f=e>>>0>=2147483644?1073741823:c>>>0>>0?f:c;if(f){if(f>>>0>=1073741824){break b}e=ka(f<<2)}else{e=0}c=e+(h<<2)|0;F[c>>2]=g;h=c+4|0;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[a+60>>2]=e+(f<<2);F[a+56>>2]=h;F[a+52>>2]=c;if(!d){break e}ja(d)}f:{g:{if(!(F[F[a+12>>2]+(k>>>3&536870908)>>2]>>>k&1)){break g}e=i+1|0;e=(e>>>0)%3|0?e:i-2|0;if((e|0)==-1|F[F[a>>2]+(e>>>3&536870908)>>2]>>>e&1){break g}e=F[F[F[a+64>>2]+12>>2]+(e<<2)>>2];if((e|0)==-1){break g}b=e+1|0;b=(b>>>0)%3|0?b:e-2|0;if((b|0)==-1){break g}c=F[a+64>>2];f=F[a>>2];while(1){e=b;b=-1;d=e+1|0;d=(d>>>0)%3|0?d:e-2|0;h:{if((d|0)==-1|F[f+(d>>>3&536870908)>>2]>>>d&1){break h}d=F[F[c+12>>2]+(d<<2)>>2];if((d|0)==-1){break h}b=d+1|0;b=(b>>>0)%3|0?b:d-2|0}if((b|0)!=(i|0)){if((b|0)==-1){break f}continue}break}return 0}e=i}F[F[a+28>>2]+(e<<2)>>2]=g;b=F[a+44>>2];i:{if((b|0)!=F[a+48>>2]){F[b>>2]=e;F[a+44>>2]=b+4;break i}d=F[a+40>>2];i=b-d|0;h=i>>2;c=h+1|0;if(c>>>0>=1073741824){break a}f=i>>>1|0;f=i>>>0>=2147483644?1073741823:c>>>0>>0?f:c;if(f){if(f>>>0>=1073741824){break b}i=ka(f<<2)}else{i=0}c=i+(h<<2)|0;F[c>>2]=e;h=c+4|0;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[a+48>>2]=i+(f<<2);F[a+44>>2]=h;F[a+40>>2]=c;if(!d){break i}ja(d)}i=g+1|0;b=F[a+64>>2];if((e|0)==-1){break d}j:{if((e>>>0)%3|0){c=e-1|0;break j}c=e+2|0;if((c|0)==-1){break d}}d=F[F[b+12>>2]+(c<<2)>>2];if((d|0)==-1){break d}f=d+((d>>>0)%3|0?-1:2)|0;if((f|0)==-1|(e|0)==(f|0)){break d}while(1){b=f+1|0;b=(b>>>0)%3|0?b:f-2|0;if(F[F[a>>2]+(b>>>3&536870908)>>2]>>>b&1){b=F[a+56>>2];k:{if((b|0)!=F[a+60>>2]){F[b>>2]=i;F[a+56>>2]=b+4;break k}d=F[a+52>>2];g=b-d|0;j=g>>2;c=j+1|0;if(c>>>0>=1073741824){break c}h=g>>>1|0;h=g>>>0>=2147483644?1073741823:c>>>0>>0?h:c;if(h){if(h>>>0>=1073741824){break b}g=ka(h<<2)}else{g=0}c=g+(j<<2)|0;F[c>>2]=i;j=c+4|0;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[a+60>>2]=g+(h<<2);F[a+56>>2]=j;F[a+52>>2]=c;if(!d){break k}ja(d)}d=i+1|0;b=F[a+44>>2];l:{if((b|0)!=F[a+48>>2]){F[b>>2]=f;F[a+44>>2]=b+4;break l}h=F[a+40>>2];g=b-h|0;l=g>>2;c=l+1|0;if(c>>>0>=1073741824){break a}j=g>>>1|0;j=g>>>0>=2147483644?1073741823:c>>>0>>0?j:c;if(j){if(j>>>0>=1073741824){break b}g=ka(j<<2)}else{g=0}c=g+(l<<2)|0;F[c>>2]=f;l=c+4|0;if((b|0)!=(h|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(h|0)){continue}break}}F[a+48>>2]=g+(j<<2);F[a+44>>2]=l;F[a+40>>2]=c;if(!h){break l}ja(h)}g=i;i=d}F[F[a+28>>2]+(f<<2)>>2]=g;b=F[a+64>>2];m:{if((f>>>0)%3|0){c=f-1|0;break m}c=f+2|0;if((c|0)==-1){break d}}d=F[F[b+12>>2]+(c<<2)>>2];if((d|0)==-1){break d}f=d+((d>>>0)%3|0?-1:2)|0;if((f|0)==-1){break d}if((e|0)!=(f|0)){continue}break}}k=k+1|0;c=F[b+24>>2];if(k>>>0>2]-c>>2>>>0){continue}break}return 1}na();v()}oa();v()}na();v()}function Kb(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0,x=0,y=0;f=Z-96|0;Z=f;e=F[a+16>>2];D[f+92|0]=1;F[f+88>>2]=b;F[f+84>>2]=b;F[f+80>>2]=e;a:{if((b|0)==-1){break a}j=F[a+20>>2];d=F[j>>2];e=F[F[e>>2]+(b<<2)>>2];if(e>>>0>=F[j+4>>2]-d>>2>>>0){break a}e=F[F[a+8>>2]+(F[d+(e<<2)>>2]<<2)>>2];d=F[a+4>>2];if(!G[d+84|0]){e=F[F[d+68>>2]+(e<<2)>>2]}F[f+72>>2]=0;F[f+76>>2]=0;j=f- -64|0;F[j>>2]=0;F[j+4>>2]=0;F[f+56>>2]=0;F[f+60>>2]=0;Ga(d,e,D[d+24|0],f+56|0);e=b+1|0;j=(e>>>0)%3|0?e:b-2|0;n=((b>>>0)%3|0?-1:2)+b|0;b:{c:{while(1){d=j;e=n;d:{if(!F[a+28>>2]){break d}e=b+1|0;d=(e>>>0)%3|0?e:b-2|0;e=b-1|0;if((b>>>0)%3|0){break d}e=b+2|0}if((d|0)==-1){break b}m=F[a+20>>2];b=F[m>>2];d=F[F[F[a+16>>2]>>2]+(d<<2)>>2];if(d>>>0>=F[m+4>>2]-b>>2>>>0){break b}d=F[F[a+8>>2]+(F[(d<<2)+b>>2]<<2)>>2];b=F[a+4>>2];if(!G[b+84|0]){d=F[F[b+68>>2]+(d<<2)>>2]}F[f+48>>2]=0;F[f+52>>2]=0;F[f+40>>2]=0;F[f+44>>2]=0;F[f+32>>2]=0;F[f+36>>2]=0;Ga(b,d,D[b+24|0],f+32|0);if((e|0)==-1){break c}d=F[a+20>>2];b=F[d>>2];e=F[F[F[a+16>>2]>>2]+(e<<2)>>2];if(e>>>0>=F[d+4>>2]-b>>2>>>0){break c}d=F[F[a+8>>2]+(F[b+(e<<2)>>2]<<2)>>2];b=F[a+4>>2];if(!G[b+84|0]){d=F[F[b+68>>2]+(d<<2)>>2]}F[f+24>>2]=0;F[f+28>>2]=0;F[f+16>>2]=0;F[f+20>>2]=0;F[f+8>>2]=0;F[f+12>>2]=0;Ga(b,d,D[b+24|0],f+8|0);g=F[f+8>>2];b=F[f+56>>2];d=g-b|0;p=F[f+60>>2];t=F[f+12>>2]-(p+(b>>>0>g>>>0)|0)|0;i=F[f+40>>2];e=F[f+64>>2];m=i-e|0;u=F[f+68>>2];y=F[f+44>>2]-(u+(e>>>0>i>>>0)|0)|0;g=ki(d,t,m,y);w=o-g|0;x=h-(_+(g>>>0>o>>>0)|0)|0;h=w;i=F[f+16>>2];g=i-e|0;u=F[f+20>>2]-((e>>>0>i>>>0)+u|0)|0;k=F[f+32>>2];i=k-b|0;w=F[f+36>>2]-((b>>>0>k>>>0)+p|0)|0;b=ki(g,u,i,w);o=h+b|0;h=_+x|0;h=b>>>0>o>>>0?h+1|0:h;b=l;l=d;p=t;k=F[f+48>>2];e=F[f+72>>2];d=k-e|0;t=F[f+76>>2];x=F[f+52>>2]-(t+(e>>>0>k>>>0)|0)|0;l=ki(l,p,d,x);k=b+l|0;b=_+q|0;b=k>>>0>>0?b+1|0:b;l=F[f+24>>2];p=l-e|0;e=F[f+28>>2]-((e>>>0>l>>>0)+t|0)|0;q=ki(p,e,i,w);l=k-q|0;q=b-(_+(k>>>0>>0)|0)|0;b=ki(g,u,d,x);d=r-b|0;b=s-(_+(b>>>0>r>>>0)|0)|0;s=ki(p,e,m,y);r=s+d|0;b=_+b|0;s=r>>>0>>0?b+1|0:b;nc(f+80|0);b=F[f+88>>2];if((b|0)!=-1){continue}break}b=s>>31;e=b^r;d=e-b|0;b=(b^s)-((b>>>0>e>>>0)+b|0)|0;n=-1;e=2147483647;m=q>>31;g=m;i=g^l;j=i-g|0;m=(g^q)-((i>>>0>>0)+g|0)|0;i=m;k=j^-1;g=i^2147483647;m=h;e:{f:{if(!F[a+28>>2]){if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break e}b=b+i|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;e=a;g=h;a=g>>31;d=a;n=d^o;a=n-d|0;h=a;d=(d^g)-((d>>>0>n>>>0)+d|0)|0;a=a+e|0;d=d^2147483647;h=(d|0)==(b|0)&(h^-1)>>>0>>0|b>>>0>d>>>0;a=h?-1:a;if(!(h&0)&(a|0)<=536870912|(a|0)<536870912){break e}b=0;a=a>>>29|0;break f}g:{if((b|0)==(g|0)&d>>>0>k>>>0|b>>>0>g>>>0){break g}b=b+i|0;a=d+j|0;b=a>>>0>>0?b+1|0:b;k=h;h=h>>31;g=h;i=g^o;h=i-g|0;j=(g^k)-((g>>>0>i>>>0)+g|0)|0;g=j^2147483647;d=a;a=h;if((g|0)==(b|0)&d>>>0>(a^-1)>>>0|b>>>0>g>>>0){break g}b=b+j|0;n=a+d|0;b=n>>>0>>0?b+1|0:b;e=b;if(!b&n>>>0<536870913){break e}}b=e>>>29|0;a=(e&536870911)<<3|n>>>29}o=li(o,m,a,b);l=li(l,q,a,b);r=li(r,s,a,b)}F[c+8>>2]=o;F[c+4>>2]=l;F[c>>2]=r;Z=f+96|0;return}ta();v()}ta();v()}ta();v()}function Nc(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;a:{if((b|0)<0){break a}c=F[a+12>>2];d=F[a+8>>2];if(c-d>>2>>>0<=b>>>0){break a}d=d+(b<<2)|0;e=F[d>>2];i=F[e+60>>2];f=F[e+56>>2];e=d+4|0;if((e|0)!=(c|0)){while(1){h=F[e>>2];F[e>>2]=0;g=F[d>>2];F[d>>2]=h;if(g){xa(g)}d=d+4|0;e=e+4|0;if((e|0)!=(c|0)){continue}break}c=F[a+12>>2]}if((c|0)!=(d|0)){while(1){c=c-4|0;e=F[c>>2];F[c>>2]=0;if(e){xa(e)}if((c|0)!=(d|0)){continue}break}}F[a+12>>2]=d;g=F[a+4>>2];b:{if(!g|(i|0)<0){break b}c=F[g+24>>2];d=F[g+28>>2];if((c|0)==(d|0)){break b}while(1){if((i|0)==F[F[c>>2]+24>>2]){d=c+4|0;i=F[g+28>>2];if((d|0)!=(i|0)){while(1){h=F[d>>2];F[d>>2]=0;e=F[c>>2];F[c>>2]=h;if(e){Ca(e+12|0,F[e+16>>2]);Ba(e,F[e+4>>2]);ja(e)}c=c+4|0;d=d+4|0;if((i|0)!=(d|0)){continue}break}d=F[g+28>>2]}if((c|0)!=(d|0)){while(1){d=d-4|0;e=F[d>>2];F[d>>2]=0;if(e){Ca(e+12|0,F[e+16>>2]);Ba(e,F[e+4>>2]);ja(e)}if((c|0)!=(d|0)){continue}break}}F[g+28>>2]=c;break b}c=c+4|0;if((d|0)!=(c|0)){continue}break}}c:{if((f|0)>4){break c}d:{e=L(f,12)+a|0;c=F[e+20>>2];d=F[e+24>>2];if((c|0)==(d|0)){break d}while(1){if(F[c>>2]==(b|0)){break d}c=c+4|0;if((d|0)!=(c|0)){continue}break}break c}if((c|0)==(d|0)){break c}f=c;c=c+4|0;pa(f,c,d-c|0);F[e+24>>2]=d-4}c=F[a+24>>2];d=F[a+20>>2];e:{if((c|0)==(d|0)){break e}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=F[h>>2];if((j|0)>(b|0)){F[h>>2]=j-1}f=d+(f|4)|0;h=F[f>>2];if((h|0)>(b|0)){F[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break e}c=d+(c<<2)|0;d=F[c>>2];if((d|0)<=(b|0)){break e}F[c>>2]=d-1}c=F[a+36>>2];d=F[a+32>>2];f:{if((c|0)==(d|0)){break f}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=F[h>>2];if((j|0)>(b|0)){F[h>>2]=j-1}f=d+(f|4)|0;h=F[f>>2];if((h|0)>(b|0)){F[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break f}c=d+(c<<2)|0;d=F[c>>2];if((d|0)<=(b|0)){break f}F[c>>2]=d-1}c=F[a+48>>2];d=F[a+44>>2];g:{if((c|0)==(d|0)){break g}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=F[h>>2];if((j|0)>(b|0)){F[h>>2]=j-1}f=d+(f|4)|0;h=F[f>>2];if((h|0)>(b|0)){F[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break g}c=d+(c<<2)|0;d=F[c>>2];if((d|0)<=(b|0)){break g}F[c>>2]=d-1}c=F[a+60>>2];d=F[a+56>>2];h:{if((c|0)==(d|0)){break h}e=c-d|0;c=e>>2;g=c>>>0<=1?1:c;i=g&1;c=0;if(e>>>0>=8){g=g&-2;e=0;while(1){f=c<<2;h=f+d|0;j=F[h>>2];if((j|0)>(b|0)){F[h>>2]=j-1}f=d+(f|4)|0;h=F[f>>2];if((h|0)>(b|0)){F[f>>2]=h-1}c=c+2|0;e=e+2|0;if((g|0)!=(e|0)){continue}break}}if(!i){break h}c=d+(c<<2)|0;d=F[c>>2];if((d|0)<=(b|0)){break h}F[c>>2]=d-1}c=F[a+72>>2];a=F[a+68>>2];if((c|0)==(a|0)){break a}d=c-a|0;c=d>>2;e=c>>>0<=1?1:c;g=e&1;c=0;if(d>>>0>=8){d=e&-2;e=0;while(1){i=c<<2;f=i+a|0;h=F[f>>2];if((h|0)>(b|0)){F[f>>2]=h-1}i=a+(i|4)|0;f=F[i>>2];if((f|0)>(b|0)){F[i>>2]=f-1}c=c+2|0;e=e+2|0;if((d|0)!=(e|0)){continue}break}}if(!g){break a}f=b;a=a+(c<<2)|0;b=F[a>>2];if((f|0)>=(b|0)){break a}F[a>>2]=b-1}}function ja(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;a:{if(!a){break a}d=a-8|0;b=F[a-4>>2];a=b&-8;f=d+a|0;b:{if(b&1){break b}if(!(b&3)){break a}b=F[d>>2];d=d-b|0;if(d>>>0>>0<=255){e=F[d+8>>2];b=b>>>3|0;c=F[d+12>>2];if((c|0)==(e|0)){i=11764,j=F[2941]&oi(b),F[i>>2]=j;break b}F[e+12>>2]=c;F[c+8>>2]=e;break b}h=F[d+24>>2];b=F[d+12>>2];c:{if((d|0)!=(b|0)){c=F[d+8>>2];F[c+12>>2]=b;F[b+8>>2]=c;break c}d:{e=d+20|0;c=F[e>>2];if(c){break d}e=d+16|0;c=F[e>>2];if(c){break d}b=0;break c}while(1){g=e;b=c;e=b+20|0;c=F[e>>2];if(c){continue}e=b+16|0;c=F[b+16>>2];if(c){continue}break}F[g>>2]=0}if(!h){break b}e=F[d+28>>2];c=(e<<2)+12068|0;e:{if(F[c>>2]==(d|0)){F[c>>2]=b;if(b){break e}i=11768,j=F[2942]&oi(e),F[i>>2]=j;break b}F[h+(F[h+16>>2]==(d|0)?16:20)>>2]=b;if(!b){break b}}F[b+24>>2]=h;c=F[d+16>>2];if(c){F[b+16>>2]=c;F[c+24>>2]=b}c=F[d+20>>2];if(!c){break b}F[b+20>>2]=c;F[c+24>>2]=b;break b}b=F[f+4>>2];if((b&3)!=3){break b}F[2943]=a;F[f+4>>2]=b&-2;F[d+4>>2]=a|1;F[a+d>>2]=a;return}if(d>>>0>=f>>>0){break a}b=F[f+4>>2];if(!(b&1)){break a}f:{if(!(b&2)){if(F[2947]==(f|0)){F[2947]=d;a=F[2944]+a|0;F[2944]=a;F[d+4>>2]=a|1;if(F[2946]!=(d|0)){break a}F[2943]=0;F[2946]=0;return}if(F[2946]==(f|0)){F[2946]=d;a=F[2943]+a|0;F[2943]=a;F[d+4>>2]=a|1;F[a+d>>2]=a;return}a=(b&-8)+a|0;g:{if(b>>>0<=255){e=F[f+8>>2];b=b>>>3|0;c=F[f+12>>2];if((c|0)==(e|0)){i=11764,j=F[2941]&oi(b),F[i>>2]=j;break g}F[e+12>>2]=c;F[c+8>>2]=e;break g}h=F[f+24>>2];b=F[f+12>>2];h:{if((f|0)!=(b|0)){c=F[f+8>>2];F[c+12>>2]=b;F[b+8>>2]=c;break h}i:{e=f+20|0;c=F[e>>2];if(c){break i}e=f+16|0;c=F[e>>2];if(c){break i}b=0;break h}while(1){g=e;b=c;e=b+20|0;c=F[e>>2];if(c){continue}e=b+16|0;c=F[b+16>>2];if(c){continue}break}F[g>>2]=0}if(!h){break g}e=F[f+28>>2];c=(e<<2)+12068|0;j:{if(F[c>>2]==(f|0)){F[c>>2]=b;if(b){break j}i=11768,j=F[2942]&oi(e),F[i>>2]=j;break g}F[h+(F[h+16>>2]==(f|0)?16:20)>>2]=b;if(!b){break g}}F[b+24>>2]=h;c=F[f+16>>2];if(c){F[b+16>>2]=c;F[c+24>>2]=b}c=F[f+20>>2];if(!c){break g}F[b+20>>2]=c;F[c+24>>2]=b}F[d+4>>2]=a|1;F[a+d>>2]=a;if(F[2946]!=(d|0)){break f}F[2943]=a;return}F[f+4>>2]=b&-2;F[d+4>>2]=a|1;F[a+d>>2]=a}if(a>>>0<=255){b=(a&-8)+11804|0;c=F[2941];a=1<<(a>>>3);k:{if(!(c&a)){F[2941]=a|c;a=b;break k}a=F[b+8>>2]}F[b+8>>2]=d;F[a+12>>2]=d;F[d+12>>2]=b;F[d+8>>2]=a;return}e=31;if(a>>>0<=16777215){b=O(a>>>8|0);e=((a>>>38-b&1)-(b<<1)|0)+62|0}F[d+28>>2]=e;F[d+16>>2]=0;F[d+20>>2]=0;g=(e<<2)+12068|0;l:{m:{c=F[2942];b=1<>2]=d;F[d+24>>2]=g;break n}e=a<<((e|0)!=31?25-(e>>>1|0)|0:0);b=F[g>>2];while(1){c=b;if((F[b+4>>2]&-8)==(a|0)){break m}b=e>>>29|0;e=e<<1;g=c+(b&4)|0;b=F[g+16>>2];if(b){continue}break}F[g+16>>2]=d;F[d+24>>2]=c}F[d+12>>2]=d;F[d+8>>2]=d;break l}a=F[c+8>>2];F[a+12>>2]=d;F[c+8>>2]=d;F[d+24>>2]=0;F[d+12>>2]=c;F[d+8>>2]=a}a=F[2949]-1|0;F[2949]=a?a:-1}}function di(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;F[a+8>>2]=e;n=a+32|0;h=F[n>>2];f=F[a+36>>2]-h>>2;a:{if(f>>>0>>0){qa(n,e-f|0);d=F[a+8>>2];break a}d=e;if(d>>>0>=f>>>0){break a}F[a+36>>2]=h+(e<<2);d=e}s=F[a+52>>2];p=F[a+48>>2];f=0;h=e>>>0>1073741823?-1:e<<2;m=ma(ka(h),0,h);b:{if((d|0)<=0){break b}g=F[a+32>>2];while(1){d=f<<2;h=F[d+m>>2];j=F[a+16>>2];c:{if((h|0)>(j|0)){F[d+g>>2]=j;break c}d=d+g|0;j=F[a+12>>2];if((j|0)>(h|0)){F[d>>2]=j;break c}F[d>>2]=h}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}if((d|0)<=0){break b}f=0;while(1){h=f<<2;d=h+c|0;h=F[b+h>>2]+F[g+h>>2]|0;F[d>>2]=h;d:{if((h|0)>F[a+16>>2]){i=h-F[a+20>>2]|0}else{if((h|0)>=F[a+12>>2]){break d}i=h+F[a+20>>2]|0}F[d>>2]=i}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}f=F[a+56>>2];q=F[f>>2];f=F[f+4>>2]-q|0;if((f|0)>=5){o=f>>>2|0;t=o>>>0<=2?2:o;u=e&-2;w=e&1;h=1;while(1){e:{f:{if((h|0)!=(o|0)){r=L(e,h);f=F[(h<<2)+q>>2];if((f|0)==-1){break f}f=F[F[p+12>>2]+(f<<2)>>2];if((f|0)==-1){break f}j=F[s>>2];g=F[p>>2];k=F[j+(F[g+(f<<2)>>2]<<2)>>2];i=f+1|0;i=(i>>>0)%3|0?i:f-2|0;if((i|0)!=-1){i=F[g+(i<<2)>>2]}else{i=-1}g:{h:{if((f>>>0)%3|0){f=f-1|0;break h}f=f+2|0;l=-1;if((f|0)==-1){break g}}l=F[g+(f<<2)>>2]}if((h|0)<=(k|0)){break f}f=F[(i<<2)+j>>2];if((f|0)>=(h|0)){break f}g=F[j+(l<<2)>>2];if((g|0)>=(h|0)){break f}i:{if((e|0)<=0){break i}g=L(e,g);j=L(e,f);k=L(e,k);f=0;l=0;if((e|0)!=1){while(1){F[(f<<2)+m>>2]=(F[(f+g<<2)+c>>2]+F[(f+j<<2)+c>>2]|0)-F[(f+k<<2)+c>>2];i=f|1;F[(i<<2)+m>>2]=(F[(g+i<<2)+c>>2]+F[(j+i<<2)+c>>2]|0)-F[(i+k<<2)+c>>2];f=f+2|0;l=l+2|0;if((u|0)!=(l|0)){continue}break}}if(!w){break i}F[(f<<2)+m>>2]=(F[(f+g<<2)+c>>2]+F[(f+j<<2)+c>>2]|0)-F[(f+k<<2)+c>>2]}if((d|0)<=0){break e}j=F[n>>2];f=0;while(1){d=f<<2;g=F[d+m>>2];k=F[a+16>>2];j:{if((g|0)>(k|0)){F[d+j>>2]=k;break j}d=d+j|0;k=F[a+12>>2];if((k|0)>(g|0)){F[d>>2]=k;break j}F[d>>2]=g}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;i=b+d|0;while(1){g=f<<2;d=g+k|0;g=F[g+i>>2]+F[g+j>>2]|0;F[d>>2]=g;k:{if((g|0)>F[a+16>>2]){l=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break k}l=g+F[a+20>>2]|0}F[d>>2]=l}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}break e}ta();v()}if((d|0)<=0){break e}k=(L(h-1|0,e)<<2)+c|0;j=F[n>>2];f=0;while(1){d=f<<2;g=F[d+k>>2];i=F[a+16>>2];l:{if((g|0)>(i|0)){F[d+j>>2]=i;break l}d=d+j|0;i=F[a+12>>2];if((i|0)>(g|0)){F[d>>2]=i;break l}F[d>>2]=g}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;i=b+d|0;while(1){g=f<<2;d=g+k|0;g=F[g+i>>2]+F[g+j>>2]|0;F[d>>2]=g;m:{if((g|0)>F[a+16>>2]){l=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break m}l=g+F[a+20>>2]|0}F[d>>2]=l}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}h=h+1|0;if((t|0)!=(h|0)){continue}break}}ja(m);return 1}function od(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;if((b|0)==-1){return 1}g=(b>>>0)/3|0;if(!(F[F[a+24>>2]+(g>>>3&268435452)>>2]>>>g&1)){e=F[a+48>>2];F[a+52>>2]=e;a:{if((e|0)!=F[a+56>>2]){F[e>>2]=b;F[a+52>>2]=e+4;break a}d=ka(4);F[d>>2]=b;c=d+4|0;F[a+56>>2]=c;F[a+52>>2]=c;F[a+48>>2]=d;if(!e){break a}ja(e)}c=b+1|0;i=(c>>>0)%3|0?c:b-2|0;c=F[F[a+4>>2]+28>>2];k=F[(i<<2)+c>>2];if((k|0)==-1){return 0}e=(b-L(g,3)|0?-1:2)+b|0;j=F[c+(e<<2)>>2];if((j|0)==-1){return 0}b=F[a+36>>2];g=b+(k>>>3&536870908)|0;d=F[g>>2];c=1<>2]=c|d;Ka(a+8|0,k,i);b=F[a+36>>2]}d=(j>>>3&536870908)+b|0;c=F[d>>2];b=1<>2]=b|c;Ka(a+8|0,j,e)}f=F[a+52>>2];if((f|0)==F[a+48>>2]){return 1}k=a+8|0;while(1){b:{c:{f=f-4|0;b=F[f>>2];if((b|0)==-1){break c}c=(b>>>0)/3|0;g=F[a+24>>2]+(c>>>3&268435452)|0;d=F[g>>2];c=1<>2]=c|d;h=F[a+4>>2];c=F[F[h+28>>2]+(b<<2)>>2];if((c|0)==-1){return 0}while(1){d=b;d:{e:{j=F[a+36>>2]+(c>>>3&536870908)|0;i=F[j>>2];e=1<>2]+(c<<2)>>2];g:{if((g|0)==-1){break g}b=g+1|0;b=(b>>>0)%3|0?b:g-2|0;if((b|0)==-1|F[F[h>>2]+(b>>>3&536870908)>>2]>>>b&1){break g}g=F[F[F[h+64>>2]+12>>2]+(b<<2)>>2];if((g|0)!=-1){break f}}F[j>>2]=e|i;Ka(k,c,d);h=F[a+4>>2];break e}F[j>>2]=e|i;Ka(k,c,d);h=F[a+4>>2];b=g+1|0;if((((b>>>0)%3|0?b:g-2|0)|0)==-1){break e}b=-1;h:{if((d|0)==-1){break h}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1|F[F[h>>2]+(c>>>3&536870908)>>2]>>>c&1){break h}b=F[F[F[h+64>>2]+12>>2]+(c<<2)>>2]}c=(b>>>0)/3|0;d=1<>2];e=c>>>5|0;j=F[f+(e<<2)>>2];break d}i:{j:{if((d|0)==-1){break j}c=-1;b=d+1|0;b=(b>>>0)%3|0?b:d-2|0;if(!((b|0)==-1|F[F[h>>2]+(b>>>3&536870908)>>2]>>>b&1)){c=F[F[F[h+64>>2]+12>>2]+(b<<2)>>2]}k:{l:{if((d>>>0)%3|0){f=d-1|0;break l}f=d+2|0;b=-1;if((f|0)==-1){break k}}b=-1;if(F[F[h>>2]+(f>>>3&536870908)>>2]>>>f&1){break k}b=F[F[F[h+64>>2]+12>>2]+(f<<2)>>2]}g=(b|0)==-1;i=g?-1:(b>>>0)/3|0;if((c|0)!=-1){f=F[a+24>>2];d=(c>>>0)/3|0;e=d>>>5|0;j=F[f+(e<<2)>>2];d=1<>2];e=i>>>5|0;j=F[f+(e<<2)>>2];if(!(d&j)){break d}}f=F[a+52>>2]-4|0;F[a+52>>2]=f;break b}if(g){b=c;break d}if(F[(i>>>3&536870908)+f>>2]>>>i&1){b=c;break d}h=F[a+52>>2];F[h-4>>2]=b;if(F[a+56>>2]!=(h|0)){F[h>>2]=c;f=h+4|0;break c}m:{i=F[a+48>>2];e=h-i|0;g=e>>2;d=g+1|0;if(d>>>0<1073741824){b=e>>>1|0;e=e>>>0>=2147483644?1073741823:b>>>0>d>>>0?b:d;if(e){if(e>>>0>=1073741824){break m}d=ka(e<<2)}else{d=0}b=d+(g<<2)|0;F[b>>2]=c;f=b+4|0;if((h|0)!=(i|0)){while(1){b=b-4|0;h=h-4|0;F[b>>2]=F[h>>2];if((h|0)!=(i|0)){continue}break}}F[a+56>>2]=d+(e<<2);F[a+52>>2]=f;F[a+48>>2]=b;if(!i){break b}ja(i);f=F[a+52>>2];break b}na();v()}oa();v()}F[(e<<2)+f>>2]=d|j;c=F[F[h+28>>2]+(b<<2)>>2];if((c|0)!=-1){continue}break}return 0}F[a+52>>2]=f}if(F[a+48>>2]!=(f|0)){continue}break}}return 1}function he(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,w=0;F[a+8>>2]=e;m=a+32|0;h=F[m>>2];f=F[a+36>>2]-h>>2;a:{if(f>>>0>>0){qa(m,e-f|0);d=F[a+8>>2];break a}d=e;if(d>>>0>=f>>>0){break a}F[a+36>>2]=h+(e<<2);d=e}s=F[a+52>>2];n=F[a+48>>2];f=0;h=e>>>0>1073741823?-1:e<<2;l=ma(ka(h),0,h);b:{if((d|0)<=0){break b}g=F[a+32>>2];while(1){d=f<<2;h=F[d+l>>2];i=F[a+16>>2];c:{if((h|0)>(i|0)){F[d+g>>2]=i;break c}d=d+g|0;i=F[a+12>>2];if((i|0)>(h|0)){F[d>>2]=i;break c}F[d>>2]=h}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}if((d|0)<=0){break b}f=0;while(1){h=f<<2;d=h+c|0;h=F[b+h>>2]+F[g+h>>2]|0;F[d>>2]=h;d:{if((h|0)>F[a+16>>2]){h=h-F[a+20>>2]|0}else{if((h|0)>=F[a+12>>2]){break d}h=h+F[a+20>>2]|0}F[d>>2]=h}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}f=F[a+56>>2];q=F[f>>2];f=F[f+4>>2]-q|0;if((f|0)>=5){o=f>>>2|0;t=o>>>0<=2?2:o;u=e&-2;w=e&1;h=1;while(1){e:{f:{if((h|0)!=(o|0)){r=L(e,h);f=F[(h<<2)+q>>2];if((f|0)==-1|F[F[n>>2]+(f>>>3&536870908)>>2]>>>f&1){break f}f=F[F[F[n+64>>2]+12>>2]+(f<<2)>>2];if((f|0)==-1){break f}i=F[s>>2];g=F[n+28>>2];k=F[i+(F[g+(f<<2)>>2]<<2)>>2];if((k|0)>=(h|0)){break f}j=f+1|0;j=F[i+(F[g+(((j>>>0)%3|0?j:f-2|0)<<2)>>2]<<2)>>2];if((j|0)>=(h|0)){break f}f=F[i+(F[g+(f+((f>>>0)%3|0?-1:2)<<2)>>2]<<2)>>2];if((f|0)>=(h|0)){break f}g:{if((e|0)<=0){break g}g=L(e,f);i=L(e,j);k=L(e,k);f=0;p=0;if((e|0)!=1){while(1){F[(f<<2)+l>>2]=(F[(f+g<<2)+c>>2]+F[(f+i<<2)+c>>2]|0)-F[(f+k<<2)+c>>2];j=f|1;F[(j<<2)+l>>2]=(F[(g+j<<2)+c>>2]+F[(i+j<<2)+c>>2]|0)-F[(k+j<<2)+c>>2];f=f+2|0;p=p+2|0;if((u|0)!=(p|0)){continue}break}}if(!w){break g}F[(f<<2)+l>>2]=(F[(f+g<<2)+c>>2]+F[(f+i<<2)+c>>2]|0)-F[(f+k<<2)+c>>2]}if((d|0)<=0){break e}i=F[m>>2];f=0;while(1){d=f<<2;g=F[d+l>>2];k=F[a+16>>2];h:{if((g|0)>(k|0)){F[d+i>>2]=k;break h}d=d+i|0;k=F[a+12>>2];if((k|0)>(g|0)){F[d>>2]=k;break h}F[d>>2]=g}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;j=b+d|0;while(1){g=f<<2;d=g+k|0;g=F[g+j>>2]+F[g+i>>2]|0;F[d>>2]=g;i:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break i}g=g+F[a+20>>2]|0}F[d>>2]=g}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}break e}ta();v()}if((d|0)<=0){break e}k=(L(h-1|0,e)<<2)+c|0;i=F[m>>2];f=0;while(1){d=f<<2;g=F[d+k>>2];j=F[a+16>>2];j:{if((g|0)>(j|0)){F[d+i>>2]=j;break j}d=d+i|0;j=F[a+12>>2];if((j|0)>(g|0)){F[d>>2]=j;break j}F[d>>2]=g}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}f=0;if((d|0)<=0){break e}d=r<<2;k=d+c|0;j=b+d|0;while(1){g=f<<2;d=g+k|0;g=F[g+j>>2]+F[g+i>>2]|0;F[d>>2]=g;k:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break k}g=g+F[a+20>>2]|0}F[d>>2]=g}d=F[a+8>>2];f=f+1|0;if((d|0)>(f|0)){continue}break}}h=h+1|0;if((t|0)!=(h|0)){continue}break}}ja(l);return 1}function Fb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=M(0),k=0,l=0,m=M(0);i=F[c>>2];a:{b:{f=F[b+4>>2];if(!f){break b}g=ni(f);c:{if(g>>>0>=2){e=i;if(f>>>0<=e>>>0){e=(i>>>0)%(f>>>0)|0}c=F[F[b>>2]+(e<<2)>>2];if(!c){break b}if(g>>>0<=1){break c}while(1){c=F[c>>2];if(!c){break b}g=F[c+4>>2];if((g|0)!=(i|0)){if(f>>>0<=g>>>0){g=(g>>>0)%(f>>>0)|0}if((e|0)!=(g|0)){break b}}if(F[c+8>>2]!=(i|0)){continue}break}b=0;break a}e=f-1&i;c=F[F[b>>2]+(e<<2)>>2];if(!c){break b}}h=f-1|0;while(1){c=F[c>>2];if(!c){break b}g=F[c+4>>2];if((g|0)!=(i|0)&(g&h)!=(e|0)){break b}if(F[c+8>>2]!=(i|0)){continue}break}b=0;break a}c=ka(16);d=F[F[d>>2]>>2];F[c+12>>2]=0;F[c+8>>2]=d;F[c+4>>2]=i;F[c>>2]=0;m=M(F[b+12>>2]+1>>>0);j=J[b+16>>2];d:{if(m>M(j*M(f>>>0))?0:f){break d}e=2;d=(f-1&f)!=0|f>>>0<3|f<<1;j=M(S(M(m/j)));e:{if(j=M(0)){g=~~j>>>0;break e}g=0}d=d>>>0>g>>>0?d:g;f:{if((d|0)==1){break f}if(!(d&d-1)){e=d;break f}e=Mc(d);f=F[b+4>>2]}g:{if(e>>>0<=f>>>0){if(e>>>0>=f>>>0){break g}g=f>>>0<3;j=M(S(M(M(I[b+12>>2])/J[b+16>>2])));h:{if(j=M(0)){d=~~j>>>0;break h}d=0}i:{j:{if(g){break j}if(ni(f)>>>0>1){break j}d=d>>>0<2?d:1<<32-O(d-1|0);break i}d=Mc(d)}e=d>>>0>>0?e:d;if(f>>>0<=e>>>0){break g}}f=0;g=0;h=e;k:{l:{m:{n:{if(e){if(h>>>0>=1073741824){break n}d=ka(h<<2);e=F[b>>2];F[b>>2]=d;if(e){ja(e)}F[b+4>>2]=h;d=0;if(h>>>0>=4){e=h&-4;while(1){k=d<<2;F[k+F[b>>2]>>2]=0;F[F[b>>2]+(k|4)>>2]=0;F[F[b>>2]+(k|8)>>2]=0;F[F[b>>2]+(k|12)>>2]=0;d=d+4|0;g=g+4|0;if((e|0)!=(g|0)){continue}break}}e=h&3;if(e){while(1){F[F[b>>2]+(d<<2)>>2]=0;d=d+1|0;f=f+1|0;if((e|0)!=(f|0)){continue}break}}e=F[b+8>>2];if(!e){break k}d=b+8|0;f=F[e+4>>2];g=ni(h);if(g>>>0<2){break m}f=f>>>0>=h>>>0?(f>>>0)%(h>>>0)|0:f;F[F[b>>2]+(f<<2)>>2]=d;d=F[e>>2];if(!d){break k}if(g>>>0<=1){break l}while(1){g=F[d+4>>2];if(h>>>0<=g>>>0){g=(g>>>0)%(h>>>0)|0}o:{if((f|0)==(g|0)){e=d;break o}l=g<<2;k=l+F[b>>2]|0;if(!F[k>>2]){F[k>>2]=e;e=d;f=g;break o}F[e>>2]=F[d>>2];F[d>>2]=F[F[l+F[b>>2]>>2]>>2];F[F[l+F[b>>2]>>2]>>2]=d}d=F[e>>2];if(d){continue}break}break k}d=F[b>>2];F[b>>2]=0;if(d){ja(d)}F[b+4>>2]=0;break k}oa();v()}f=h-1&f;F[F[b>>2]+(f<<2)>>2]=d;d=F[e>>2];if(!d){break k}}k=h-1|0;while(1){g=k&F[d+4>>2];p:{if((g|0)==(f|0)){e=d;break p}l=g<<2;h=l+F[b>>2]|0;if(F[h>>2]){F[e>>2]=F[d>>2];F[d>>2]=F[F[l+F[b>>2]>>2]>>2];F[F[l+F[b>>2]>>2]>>2]=d;break p}F[h>>2]=e;e=d;f=g}d=F[e>>2];if(d){continue}break}}}f=F[b+4>>2];d=f-1|0;if(!(d&f)){e=d&i;break d}if(f>>>0>i>>>0){e=i;break d}e=(i>>>0)%(f>>>0)|0}e=F[b>>2]+(e<<2)|0;d=F[e>>2];q:{r:{if(!d){d=b+8|0;F[c>>2]=F[d>>2];F[b+8>>2]=c;F[e>>2]=d;d=F[c>>2];if(!d){break q}d=F[d+4>>2];e=f-1|0;s:{if(!(e&f)){d=d&e;break s}if(d>>>0>>0){break s}d=(d>>>0)%(f>>>0)|0}d=F[b>>2]+(d<<2)|0;break r}F[c>>2]=F[d>>2]}F[d>>2]=c}F[b+12>>2]=F[b+12>>2]+1;b=1}D[a+4|0]=b;F[a>>2]=c}function Vb(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;j=L(b,12)+a|0;F[j+12>>2]=F[j+8>>2];m=(c|0)==-1?-1:(c>>>0)/3|0;d=1;k=c;a:{b:{c:{while(1){d:{l=d;if(!d){if((k|0)==-1){break d}if((Wc(a,((k>>>0)%3|0?-1:2)+k|0)|0)==-1){break a}c=k+1|0;d=(c>>>0)%3|0?c:k-2|0;if((d|0)==-1){break a}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1){break a}d=F[F[F[a+4>>2]+12>>2]+(c<<2)>>2];if((d|0)==-1){break a}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1){break a}m=(c>>>0)/3|0}e:{d=F[a+56>>2]+(m>>>3&536870908)|0;h=F[d>>2];e=1<>2]=e|h;d=F[j+12>>2];f:{if((d|0)!=F[j+16>>2]){F[d>>2]=m;F[j+12>>2]=d+4;break f}n=F[j+8>>2];h=d-n|0;e=h>>2;i=e+1|0;if(i>>>0>=1073741824){break c}g=h>>>1|0;i=h>>>0>=2147483644?1073741823:i>>>0>>0?g:i;if(i){if(i>>>0>=1073741824){break b}g=ka(i<<2)}else{g=0}h=g+(e<<2)|0;F[h>>2]=m;e=h+4|0;if((d|0)!=(n|0)){while(1){h=h-4|0;d=d-4|0;F[h>>2]=F[d>>2];if((d|0)!=(n|0)){continue}break}}F[j+8>>2]=h;F[j+12>>2]=e;F[j+16>>2]=g+(i<<2);if(!n){break f}ja(n)}g=f+1|0;g:{h:{i:{if(!f){break i}if(g&1){if((c|0)==-1){c=-1;break g}d=c+1|0;c=(d>>>0)%3|0?d:c-2|0;break i}k=l?k:c;if((c|0)==-1){c=-1;break g}if((c>>>0)%3|0){d=c-1|0;break h}c=c+2|0}d=c;c=-1;if((d|0)==-1){break g}}c=F[F[F[a+4>>2]+12>>2]+(d<<2)>>2];h=-1;f=-1;e=d+1|0;e=(e>>>0)%3|0?e:d-2|0;if((e|0)>=0){f=(e>>>0)/3|0;f=F[(F[F[a>>2]+96>>2]+L(f,12)|0)+(e-L(f,3)<<2)>>2]}j:{if((c|0)==-1){break j}i=((c>>>0)%3|0?-1:2)+c|0;if((i|0)<0){break j}e=(i>>>0)/3|0;h=F[(F[F[a>>2]+96>>2]+L(e,12)|0)+(i-L(e,3)<<2)>>2]}if((f|0)!=(h|0)){c=-1;break g}k:{l:{f=((d>>>0)%3|0?-1:2)+d|0;if((f|0)>=0){d=(f>>>0)/3|0;if((c|0)!=-1){break l}c=-1;break g}d=-1;if((c|0)!=-1){break k}c=-1;break g}d=F[(F[F[a>>2]+96>>2]+L(d,12)|0)+(f-L(d,3)<<2)>>2]}f=c+1|0;e=(f>>>0)%3|0?f:c-2|0;if((e|0)>=0){f=(e>>>0)/3|0;f=F[(F[F[a>>2]+96>>2]+L(f,12)|0)+(e-L(f,3)<<2)>>2]}else{f=-1}if((f|0)!=(d|0)){c=-1;break g}f=g;m=(c>>>0)/3|0;d=F[a+56>>2]+(m>>>3&268435452)|0;h=F[d>>2];e=1<>2]-4|0;g=F[l>>2];d=F[a+56>>2]+(g>>>3&536870908)|0;c=F[d>>2];o=d,p=oi(g)&c,F[o>>2]=p;F[j+12>>2]=l;break a}d=0;if(l){continue}break a}break}k=-1;Wc(a,-1);break a}na();v()}oa();v()}F[((b<<2)+a|0)+44>>2]=k;b=F[j+12>>2];i=F[j+8>>2];m:{if((b|0)==(i|0)){break m}c=b-i|0;b=c>>2;b=b>>>0<=1?1:b;k=b&1;e=F[a+56>>2];d=0;if(c>>>0>=8){f=b&-2;c=0;while(1){l=d<<2;g=F[l+i>>2];b=e+(g>>>3&536870908)|0;a=F[b>>2];o=b,p=oi(g)&a,F[o>>2]=p;g=F[i+(l|4)>>2];b=e+(g>>>3&536870908)|0;a=F[b>>2];o=b,p=oi(g)&a,F[o>>2]=p;d=d+2|0;c=c+2|0;if((f|0)!=(c|0)){continue}break}}if(!k){break m}c=F[i+(d<<2)>>2];b=e+(c>>>3&536870908)|0;a=F[b>>2];o=b,p=oi(c)&a,F[o>>2]=p}}function pd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;if((b|0)==-1){return 1}g=(b>>>0)/3|0;if(!(F[F[a+24>>2]+(g>>>3&268435452)>>2]>>>g&1)){f=F[a+48>>2];F[a+52>>2]=f;a:{if((f|0)!=F[a+56>>2]){F[f>>2]=b;F[a+52>>2]=f+4;break a}d=ka(4);F[d>>2]=b;c=d+4|0;F[a+56>>2]=c;F[a+52>>2]=c;F[a+48>>2]=d;if(!f){break a}ja(f)}e=-1;d=F[a+4>>2];c=b+1|0;i=(c>>>0)%3|0?c:b-2|0;if((i|0)!=-1){e=F[F[d>>2]+(i<<2)>>2]}b:{h=b-L(g,3)|0;if(h){c=b-1|0;break b}c=b+2|0;if((c|0)!=-1){break b}return 0}if((e|0)==-1){return 0}j=F[F[d>>2]+(c<<2)>>2];if((j|0)==-1){return 0}c=F[a+36>>2];f=c+(e>>>3&536870908)|0;g=F[f>>2];d=1<>2]=d|g;Ka(a+8|0,e,i);c=F[a+36>>2]}g=(j>>>3&536870908)+c|0;d=F[g>>2];c=1<>2]=c|d;Ka(a+8|0,j,(h?-1:2)+b|0)}c=F[a+52>>2];if((c|0)==F[a+48>>2]){return 1}j=a+8|0;while(1){c:{d:{c=c-4|0;b=F[c>>2];if((b|0)==-1){break d}d=(b>>>0)/3|0;f=F[a+24>>2]+(d>>>3&268435452)|0;g=F[f>>2];d=1<>2]=d|g;while(1){i=F[a+4>>2];e=F[F[i>>2]+(b<<2)>>2];if((e|0)==-1){return 0}e:{f:{h=F[a+36>>2]+(e>>>3&536870908)|0;f=F[h>>2];g=1<>2]+(e<<2)>>2];h:{if((d|0)==-1){break h}c=d+1|0;c=(c>>>0)%3|0?c:d-2|0;if((c|0)==-1){break h}d=F[F[i+12>>2]+(c<<2)>>2];if((d|0)!=-1){break g}}F[h>>2]=f|g;Ka(j,e,b);break f}F[h>>2]=f|g;Ka(j,e,b);c=d+1|0;if((((c>>>0)%3|0?c:d-2|0)|0)==-1){break f}c=b-2|0;d=b+1|0;b=-1;c=(d>>>0)%3|0?d:c;if((c|0)!=-1){b=F[F[F[a+4>>2]+12>>2]+(c<<2)>>2]}c=(b>>>0)/3|0;d=1<>2];f=c>>>5|0;i=F[e+(f<<2)>>2];break e}c=-1;g=F[a+4>>2];d=b+1|0;d=(d>>>0)%3|0?d:b-2|0;if((d|0)!=-1){c=F[F[g+12>>2]+(d<<2)>>2]}i:{j:{if((b>>>0)%3|0){e=b-1|0;break j}e=b+2|0;b=-1;if((e|0)==-1){break i}}b=F[F[g+12>>2]+(e<<2)>>2]}g=(b|0)==-1;h=g?-1:(b>>>0)/3|0;k:{if((c|0)!=-1){e=F[a+24>>2];d=(c>>>0)/3|0;f=d>>>5|0;i=F[e+(f<<2)>>2];d=1<>2];f=h>>>5|0;i=F[e+(f<<2)>>2];if(!(d&i)){break e}}c=F[a+52>>2]-4|0;F[a+52>>2]=c;break c}if(g){b=c;break e}if(F[(h>>>3&536870908)+e>>2]>>>h&1){b=c;break e}e=F[a+52>>2];F[e-4>>2]=b;if(F[a+56>>2]!=(e|0)){F[e>>2]=c;c=e+4|0;break d}l:{h=F[a+48>>2];f=e-h|0;g=f>>2;d=g+1|0;if(d>>>0<1073741824){b=f>>>1|0;f=f>>>0>=2147483644?1073741823:b>>>0>d>>>0?b:d;if(f){if(f>>>0>=1073741824){break l}d=ka(f<<2)}else{d=0}b=d+(g<<2)|0;F[b>>2]=c;c=b+4|0;if((e|0)!=(h|0)){while(1){b=b-4|0;e=e-4|0;F[b>>2]=F[e>>2];if((e|0)!=(h|0)){continue}break}}F[a+56>>2]=d+(f<<2);F[a+52>>2]=c;F[a+48>>2]=b;if(!h){break c}ja(h);c=F[a+52>>2];break c}na();v()}oa();v()}F[(f<<2)+e>>2]=d|i;if((b|0)!=-1){continue}break}return 0}F[a+52>>2]=c}if(F[a+48>>2]!=(c|0)){continue}break}}return 1}function ee(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=Z-32|0;Z=h;a:{b:{if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[F[a+48>>2]+64>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}c:{if(d){Na(a+60|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[F[a+48>>2]+64>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}if(d){e=0;Na(a+72|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[F[a+48>>2]+64>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}if(d){e=0;Na(a+84|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[F[a+48>>2]+64>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}if(d){e=0;Na(a+96|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}e=0;c=F[b+8>>2];f=F[b+12>>2];d=c;c=F[b+20>>2];i=c;g=F[b+16>>2];j=g+4|0;c=j>>>0<4?c+1|0:c;if(d>>>0>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break a}m=F[b>>2];k=m+g|0;l=G[k|0]|G[k+1|0]<<8|(G[k+2|0]<<16|G[k+3|0]<<24);F[b+16>>2]=j;F[b+20>>2]=c;k=d;d=f;c=i;f=g+8|0;c=f>>>0<8?c+1|0:c;if(f>>>0>k>>>0&(c|0)>=(d|0)|(c|0)>(d|0)){break a}d=j+m|0;d=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);F[b+16>>2]=f;F[b+20>>2]=c;if((d|0)<(l|0)){break a}F[a+16>>2]=d;F[a+12>>2]=l;c=(d>>31)-((l>>31)+(d>>>0>>0)|0)|0;b=d-l|0;if(!c&b>>>0>2147483646|c){break a}e=1;b=b+1|0;F[a+20>>2]=b;c=b>>>1|0;F[a+24>>2]=c;F[a+28>>2]=0-c;if(b&1){break a}F[a+24>>2]=c-1;break a}}e=0}Z=h+32|0;return e|0}function ai(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=Z-32|0;Z=h;a:{b:{if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[a+48>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}c:{if(d){Na(a+60|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[a+48>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}if(d){e=0;Na(a+72|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[a+48>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}if(d){e=0;Na(a+84|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}if(!Oa(1,h+28|0,b)){break b}d=F[h+28>>2];c=F[a+48>>2];if(d>>>0>F[c+4>>2]-F[c>>2]>>2>>>0){break b}if(d){e=0;Na(a+96|0,d);c=h+8|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;if(!Aa(c,b)){break c}while(1){f=1<>2]+(e>>>3&536870908)|0;if(j){i=f|F[g>>2]}else{i=F[g>>2]&(f^-1)}F[g>>2]=i;e=e+1|0;if((d|0)!=(e|0)){continue}break}}e=0;c=F[b+8>>2];f=F[b+12>>2];d=c;c=F[b+20>>2];i=c;g=F[b+16>>2];j=g+4|0;c=j>>>0<4?c+1|0:c;if(d>>>0>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break a}m=F[b>>2];k=m+g|0;l=G[k|0]|G[k+1|0]<<8|(G[k+2|0]<<16|G[k+3|0]<<24);F[b+16>>2]=j;F[b+20>>2]=c;k=d;d=f;c=i;f=g+8|0;c=f>>>0<8?c+1|0:c;if(f>>>0>k>>>0&(c|0)>=(d|0)|(c|0)>(d|0)){break a}d=j+m|0;d=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);F[b+16>>2]=f;F[b+20>>2]=c;if((d|0)<(l|0)){break a}F[a+16>>2]=d;F[a+12>>2]=l;c=(d>>31)-((l>>31)+(d>>>0>>0)|0)|0;b=d-l|0;if(!c&b>>>0>2147483646|c){break a}e=1;b=b+1|0;F[a+20>>2]=b;c=b>>>1|0;F[a+24>>2]=c;F[a+28>>2]=0-c;if(b&1){break a}F[a+24>>2]=c-1;break a}}e=0}Z=h+32|0;return e|0}function uh(a){a=a|0;var b=0,c=0,d=0,e=0;c=F[a+32>>2];d=F[c+16>>2];e=F[c+12>>2];b=F[c+20>>2];if(I[c+8>>2]>d>>>0&(e|0)>=(b|0)|(b|0)<(e|0)){e=G[F[c>>2]+d|0];d=d+1|0;b=d?b:b+1|0;F[c+16>>2]=d;F[c+20>>2]=b;b=F[a+48>>2];F[a+48>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}a:{b:{c:{d:{switch(e|0){case 0:b=ka(384);F[b>>2]=8284;ma(b+4|0,0,80);F[b+96>>2]=0;F[b+100>>2]=0;F[b+92>>2]=-1;F[b+84>>2]=-1;F[b+88>>2]=-1;F[b+104>>2]=0;F[b+108>>2]=0;F[b+112>>2]=0;F[b+116>>2]=0;F[b+120>>2]=0;F[b+124>>2]=0;F[b+128>>2]=0;F[b+132>>2]=0;F[b+136>>2]=0;F[b+140>>2]=0;F[b+144>>2]=0;F[b+148>>2]=0;F[b+156>>2]=0;F[b+160>>2]=0;F[b+152>>2]=1065353216;F[b+164>>2]=0;F[b+168>>2]=0;F[b+172>>2]=0;F[b+176>>2]=0;F[b+180>>2]=0;F[b+184>>2]=0;F[b+188>>2]=0;F[b+192>>2]=0;F[b+196>>2]=0;F[b+200>>2]=0;F[b+204>>2]=0;F[b+208>>2]=0;F[b+212>>2]=-1;F[b+216>>2]=0;F[b+220>>2]=0;F[b+224>>2]=0;Ja(b+232|0);Ja(b+272|0);c=b+312|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;Ja(b+328|0);F[b+376>>2]=0;F[b+368>>2]=0;F[b+372>>2]=0;break c;case 2:break d;default:break b}}b=ka(440);F[b>>2]=8336;ma(b+4|0,0,80);F[b+96>>2]=0;F[b+100>>2]=0;F[b+92>>2]=-1;F[b+84>>2]=-1;F[b+88>>2]=-1;F[b+104>>2]=0;F[b+108>>2]=0;F[b+112>>2]=0;F[b+116>>2]=0;F[b+120>>2]=0;F[b+124>>2]=0;F[b+128>>2]=0;F[b+132>>2]=0;F[b+136>>2]=0;F[b+140>>2]=0;F[b+144>>2]=0;F[b+148>>2]=0;F[b+156>>2]=0;F[b+160>>2]=0;F[b+152>>2]=1065353216;F[b+164>>2]=0;F[b+168>>2]=0;F[b+172>>2]=0;F[b+176>>2]=0;F[b+180>>2]=0;F[b+184>>2]=0;F[b+188>>2]=0;F[b+192>>2]=0;F[b+196>>2]=0;F[b+200>>2]=0;F[b+204>>2]=0;F[b+208>>2]=0;F[b+212>>2]=-1;F[b+216>>2]=0;F[b+220>>2]=0;F[b+224>>2]=0;Ja(b+232|0);Ja(b+272|0);c=b+312|0;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;Ja(b+328|0);F[b+392>>2]=0;F[b+396>>2]=0;F[b+384>>2]=0;F[b+388>>2]=0;F[b+376>>2]=0;F[b+380>>2]=0;F[b+368>>2]=0;F[b+372>>2]=0;F[b+416>>2]=0;F[b+420>>2]=0;F[b+408>>2]=2;F[b+412>>2]=7;F[b+400>>2]=-1;F[b+404>>2]=-1;F[b+424>>2]=0;F[b+428>>2]=0;F[b+432>>2]=0;F[b+436>>2]=0}c=F[a+48>>2];F[a+48>>2]=b;if(!c){break a}$[F[F[c>>2]+4>>2]](c)}b=F[a+48>>2];if(b){break a}return 0}a=$[F[F[b>>2]+8>>2]](b,a)|0}else{a=0}return a|0}function ei(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;g=Z-32|0;Z=g;F[a+68>>2]=f;d=F[a+56>>2];e=F[d>>2];d=F[d+4>>2];F[g+24>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+60|0;d=d>>>2|0;n=d>>>0<=1?1:d;o=a+112|0;while(1){e=F[a+56>>2];d=F[e>>2];if(F[e+4>>2]-d>>2>>>0<=j>>>0){break a}Mb(m,F[d+(j<<2)>>2],g+16|0);i=F[g+20>>2];d=i>>31;h=F[g+16>>2];e=h>>31;f=(d^i)-d+((e^h)-e)|0;k=F[g+24>>2];d=k>>31;e=(d^k)-d|0;d=0;l=e;e=e+f|0;d=l>>>0>e>>>0?1:d;b:{if(!(d|e)){F[g+16>>2]=F[a+108>>2];break b}f=F[a+108>>2];l=f>>31;h=li(ki(f,l,h,h>>31),_,e,d);F[g+16>>2]=h;d=li(ki(f,l,i,i>>31),_,e,d);F[g+20>>2]=d;e=d;d=d>>31;e=(e^d)-d|0;d=h>>31;d=e+((d^h)-d|0)|0;if((k|0)>=0){F[g+24>>2]=f-d;break b}F[g+24>>2]=d-f}d=wa(o);f=F[g+16>>2];c:{if(d){F[g+24>>2]=0-F[g+24>>2];e=0-F[g+20>>2]|0;F[g+20>>2]=e;f=0-f|0;F[g+16>>2]=f;break c}e=F[g+20>>2]}d:{if((f|0)>=0){f=F[a+108>>2];d=f+F[g+24>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=F[g+24>>2];f=d>>31;f=(d^f)-f|0;break e}d=F[g+24>>2];f=d>>31;f=F[a+100>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=F[a+100>>2]+(d-(d^e)|0)|0}e=F[a+100>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}i=F[a+108>>2];if((i|0)>=(d|0)){break g}d=(i<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}i=F[a+108>>2];if((i|0)<=(d|0)){break h}d=(i<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=F[a+108>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=F[a+108>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}F[g+12>>2]=d;F[g+8>>2]=f;j:{if(F[a+8>>2]<=0){break j}i=F[a+32>>2];f=0;while(1){d=f<<2;e=F[d+(g+8|0)>>2];h=F[a+16>>2];k:{if((e|0)>(h|0)){F[d+i>>2]=h;break k}d=d+i|0;h=F[a+12>>2];if((h|0)>(e|0)){F[d>>2]=h;break k}F[d>>2]=e}f=f+1|0;e=F[a+8>>2];if((f|0)<(e|0)){continue}break}d=0;if((e|0)<=0){break j}e=j<<3;h=e+c|0;k=b+e|0;while(1){f=d<<2;e=f+h|0;f=F[f+k>>2]+F[f+i>>2]|0;F[e>>2]=f;l:{if((f|0)>F[a+16>>2]){f=f-F[a+20>>2]|0}else{if((f|0)>=F[a+12>>2]){break l}f=f+F[a+20>>2]|0}F[e>>2]=f}d=d+1|0;if((d|0)>2]){continue}break}}j=j+1|0;if((n|0)!=(j|0)){continue}break}}Z=g+32|0;return 1}ta();v()}function Vh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;g=Z-32|0;Z=g;F[a+68>>2]=f;d=F[a+56>>2];e=F[d>>2];d=F[d+4>>2];F[g+24>>2]=0;F[g+16>>2]=0;F[g+20>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+60|0;d=d>>>2|0;n=d>>>0<=1?1:d;o=a+112|0;while(1){e=F[a+56>>2];d=F[e>>2];if(F[e+4>>2]-d>>2>>>0<=j>>>0){break a}Kb(m,F[d+(j<<2)>>2],g+16|0);i=F[g+20>>2];d=i>>31;h=F[g+16>>2];e=h>>31;f=(d^i)-d+((e^h)-e)|0;k=F[g+24>>2];d=k>>31;e=(d^k)-d|0;d=0;l=e;e=e+f|0;d=l>>>0>e>>>0?1:d;b:{if(!(d|e)){F[g+16>>2]=F[a+108>>2];break b}f=F[a+108>>2];l=f>>31;h=li(ki(f,l,h,h>>31),_,e,d);F[g+16>>2]=h;d=li(ki(f,l,i,i>>31),_,e,d);F[g+20>>2]=d;e=d;d=d>>31;e=(e^d)-d|0;d=h>>31;d=e+((d^h)-d|0)|0;if((k|0)>=0){F[g+24>>2]=f-d;break b}F[g+24>>2]=d-f}d=wa(o);f=F[g+16>>2];c:{if(d){F[g+24>>2]=0-F[g+24>>2];e=0-F[g+20>>2]|0;F[g+20>>2]=e;f=0-f|0;F[g+16>>2]=f;break c}e=F[g+20>>2]}d:{if((f|0)>=0){f=F[a+108>>2];d=f+F[g+24>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=F[g+24>>2];f=d>>31;f=(d^f)-f|0;break e}d=F[g+24>>2];f=d>>31;f=F[a+100>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=F[a+100>>2]+(d-(d^e)|0)|0}e=F[a+100>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}i=F[a+108>>2];if((i|0)>=(d|0)){break g}d=(i<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}i=F[a+108>>2];if((i|0)<=(d|0)){break h}d=(i<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=F[a+108>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=F[a+108>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}F[g+12>>2]=d;F[g+8>>2]=f;j:{if(F[a+8>>2]<=0){break j}i=F[a+32>>2];f=0;while(1){d=f<<2;e=F[d+(g+8|0)>>2];h=F[a+16>>2];k:{if((e|0)>(h|0)){F[d+i>>2]=h;break k}d=d+i|0;h=F[a+12>>2];if((h|0)>(e|0)){F[d>>2]=h;break k}F[d>>2]=e}f=f+1|0;e=F[a+8>>2];if((f|0)<(e|0)){continue}break}d=0;if((e|0)<=0){break j}e=j<<3;h=e+c|0;k=b+e|0;while(1){f=d<<2;e=f+h|0;f=F[f+k>>2]+F[f+i>>2]|0;F[e>>2]=f;l:{if((f|0)>F[a+16>>2]){f=f-F[a+20>>2]|0}else{if((f|0)>=F[a+12>>2]){break l}f=f+F[a+20>>2]|0}F[e>>2]=f}d=d+1|0;if((d|0)>2]){continue}break}}j=j+1|0;if((n|0)!=(j|0)){continue}break}}Z=g+32|0;return 1}ta();v()}function $a(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=Z-32|0;Z=h;a:{b:{if(F[a+8>>2]<<5>>>0>=b>>>0){break b}if((b|0)<0){break a}b=(b-1>>>5|0)+1|0;c=ka(b<<2);F[h+24>>2]=b;F[h+20>>2]=0;F[h+16>>2]=c;b=F[a>>2];F[h+12>>2]=0;F[h+8>>2]=b;c=F[a+4>>2];F[h+4>>2]=c&31;F[h>>2]=b+(c>>>3&536870908);e=Z-32|0;Z=e;i=F[h+4>>2];g=F[h+12>>2];j=F[h>>2];d=F[h+8>>2];b=(i-g|0)+(j-d<<3)|0;f=F[h+20>>2];c=b+f|0;F[h+20>>2]=c;if(!((c-1^f-1)>>>0<32?f:0)){F[F[h+16>>2]+((c>>>0>=33?c-1>>>5|0:0)<<2)>>2]=0}c=F[h+16>>2]+(f>>>3&536870908)|0;f=f&31;c:{if((f|0)==(g|0)){if((b|0)<=0){break c}if(g){i=32-g|0;f=(b|0)<(i|0)?b:i;i=-1<>>i-f;F[c>>2]=F[c>>2]&(i^-1)|i&F[d>>2];d=d+4|0;c=(g+f>>>3&536870908)+c|0;b=b-f|0}g=(b|0)/32|0;if(b+31>>>0>=63){pa(c,d,g<<2)}b=b-(g<<5)|0;if((b|0)<=0){break c}f=c;c=g<<2;g=f+c|0;b=-1>>>32-b|0;F[g>>2]=F[g>>2]&(b^-1)|b&F[c+d>>2];break c}F[e+28>>2]=g;F[e+24>>2]=d;F[e+20>>2]=i;F[e+16>>2]=j;F[e+12>>2]=f;F[e+8>>2]=c;b=F[e+28>>2];c=F[e+24>>2];g=(F[e+20>>2]-b|0)+(F[e+16>>2]-c<<3)|0;d:{if((g|0)<=0){b=F[e+12>>2];d=F[e+8>>2];break d}e:{if(!b){b=F[e+12>>2];break e}d=F[e+12>>2];j=32-d|0;k=32-b|0;f=(g|0)<(k|0)?g:k;i=f>>>0>j>>>0?j:f;l=F[e+8>>2];m=F[l>>2]&(-1<>>j-i^-1);j=F[c>>2]&(-1<>>k-f);F[l>>2]=m|(b>>>0>>0?j<>>b-d|0);c=d+i|0;b=c&31;F[e+12>>2]=b;d=l+(c>>>3&536870908)|0;F[e+8>>2]=d;c=f-i|0;if((c|0)>0){F[d>>2]=F[d>>2]&(-1>>>32-c^-1)|j>>>i+F[e+28>>2];F[e+12>>2]=c;b=c}g=g-f|0;c=F[e+24>>2]+4|0;F[e+24>>2]=c}i=-1<=32){j=i^-1;while(1){d=F[e+8>>2];c=F[c>>2];F[d>>2]=j&F[d>>2]|c<>2]=d+4;F[d+4>>2]=i&F[d+4>>2]|c>>>f;c=F[e+24>>2]+4|0;F[e+24>>2]=c;d=g>>>0>63;g=g-32|0;if(d){continue}break}}d=F[e+8>>2];if((g|0)<=0){break d}j=f;f=(g|0)>(f|0)?f:g;j=F[d>>2]&(i&-1>>>j-f^-1);i=F[c>>2]&-1>>>32-g;F[d>>2]=j|i<>2]=c;d=(b>>>3&536870908)+d|0;F[e+8>>2]=d;b=g-f|0;if((b|0)<=0){b=c;break d}F[d>>2]=F[d>>2]&(-1>>>32-b^-1)|i>>>f;F[e+12>>2]=b}F[e+4>>2]=b;F[e>>2]=d}Z=e+32|0;b=F[a>>2];F[a>>2]=F[h+16>>2];F[h+16>>2]=b;c=F[a+4>>2];F[a+4>>2]=F[h+20>>2];F[h+20>>2]=c;c=F[a+8>>2];F[a+8>>2]=F[h+24>>2];F[h+24>>2]=c;if(!b){break b}ja(b)}Z=h+32|0;return}na();v()}function xc(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;n=$[F[F[a>>2]+44>>2]](a)|0;a:{if((n|0)<=0){break a}i=F[b+4>>2]-F[b>>2]>>2;e=Z+-64|0;Z=e;f=kb(e);d=L(F[2541],n);cc(f,F[F[a+8>>2]+56>>2],n&255,5,0,d,d>>31);f=bc(ka(96),f);D[f+84|0]=1;F[f+72>>2]=F[f+68>>2];ac(f,i);F[f+60>>2]=F[F[a+8>>2]+60>>2];d=F[a+16>>2];F[a+16>>2]=f;if(d){xa(d)}Z=e- -64|0;h=F[a+16>>2];if(!F[h+80>>2]){break a}j=F[F[h>>2]>>2];if(!j){break a}m=F[c+12>>2];e=m;d=F[c+20>>2];g=F[c+8>>2];k=F[c+16>>2];if((e|0)<=(d|0)&g>>>0<=k>>>0|(d|0)>(e|0)){break a}l=L(i,n);i=j+F[h+48>>2]|0;h=F[c>>2];j=G[h+k|0];e=k+1|0;f=e?d:d+1|0;F[c+16>>2]=e;F[c+20>>2]=f;b:{c:{if(j){if(mc(l,n,c,i)){break c}break a}if((f|0)>=(m|0)&e>>>0>=g>>>0|(f|0)>(m|0)){break a}g=G[e+h|0];f=k+2|0;d=f>>>0<2?d+1|0:d;F[c+16>>2]=f;F[c+20>>2]=d;d=F[F[a+16>>2]+64>>2];d=F[d+4>>2]-F[d>>2]|0;if((g|0)==F[2541]){e=l<<2;if(e>>>0>d>>>0){break a}g=F[c+8>>2];k=F[c+12>>2];j=F[c+20>>2];d=F[c+16>>2];f=e+d|0;j=f>>>0>>0?j+1|0:j;if(f>>>0>g>>>0&(j|0)>=(k|0)|(j|0)>(k|0)){break a}la(i,d+F[c>>2]|0,e);f=F[c+20>>2];d=e+F[c+16>>2]|0;f=d>>>0>>0?f+1|0:f;F[c+16>>2]=d;F[c+20>>2]=f;break c}if(d>>>0>>0){break a}d=F[c+8>>2];f=F[c+16>>2];e=d-f|0;m=d>>>0>>0;d=F[c+20>>2];k=F[c+12>>2]-(m+d|0)|0;m=ki(g,0,l,0)>>>0>e>>>0;e=_;if(m&(e|0)>=(k|0)|(e|0)>(k|0)){break a}e=1;if(!l){break b}h=0;while(1){k=F[c+8>>2];j=F[c+12>>2];e=f+g|0;d=e>>>0>>0?d+1|0:d;if(e>>>0>k>>>0&(d|0)>=(j|0)|(d|0)>(j|0)){return 0}la(i+(h<<2)|0,F[c>>2]+f|0,g);d=F[c+20>>2];f=g+F[c+16>>2]|0;d=f>>>0>>0?d+1|0:d;F[c+16>>2]=f;F[c+20>>2]=d;h=h+1|0;if((l|0)!=(h|0)){continue}break}}e=1;if(!l){break b}d=F[a+20>>2];if(d){e=0;if($[F[F[d>>2]+32>>2]](d)|0){break b}}g=0;h=0;d:{if((l|0)<=0){break d}if((l|0)!=1){f=l&-2;while(1){e=g<<2;d=F[e+i>>2];F[e+i>>2]=0-(d&1)^d>>>1;d=e|4;e=F[d+i>>2];F[d+i>>2]=0-(e&1)^e>>>1;g=g+2|0;h=h+2|0;if((f|0)!=(h|0)){continue}break}}if(!(l&1)){break d}d=g<<2;f=F[d+i>>2];F[d+i>>2]=0-(f&1)^f>>>1}e=0}d=e;f=F[a+20>>2];e:{if(!f){break e}if(!($[F[F[f>>2]+40>>2]](f,c)|0)){break a}if(d){break e}a=F[a+20>>2];if(!($[F[F[a>>2]+44>>2]](a,i,i,l,n,F[b>>2])|0)){break a}}o=1}return o|0}function Lh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=Z-48|0;Z=g;d=F[a+8>>2];if(d-2>>>0<=28){F[a+76>>2]=d;e=-1<>2]=d;F[a+80>>2]=e^-1;F[a+92>>2]=(d|0)/2;J[a+88>>2]=M(2)/M(d|0)}F[a+52>>2]=f;d=F[a+40>>2];e=F[d>>2];d=F[d+4>>2];F[g+16>>2]=0;F[g+8>>2]=0;F[g+12>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+8|0;n=a+44|0;d=d>>>2|0;o=d>>>0<=1?1:d;p=a+96|0;while(1){e=F[a+40>>2];d=F[e>>2];if(F[e+4>>2]-d>>2>>>0<=j>>>0){break a}Mb(n,F[d+(j<<2)>>2],g+8|0);h=F[g+12>>2];d=h>>31;i=F[g+8>>2];e=i>>31;f=(d^h)-d+((e^i)-e)|0;l=F[g+16>>2];d=l>>31;e=(d^l)-d|0;d=0;k=e;e=e+f|0;d=k>>>0>e>>>0?1:d;b:{if(!(d|e)){F[g+8>>2]=F[a+92>>2];break b}f=F[a+92>>2];k=f>>31;i=li(ki(f,k,i,i>>31),_,e,d);F[g+8>>2]=i;d=li(ki(f,k,h,h>>31),_,e,d);F[g+12>>2]=d;e=d>>31;e=(d^e)-e|0;d=i>>31;d=e+((d^i)-d|0)|0;if((l|0)>=0){F[g+16>>2]=f-d;break b}F[g+16>>2]=d-f}d=wa(p);f=F[g+8>>2];c:{if(d){F[g+16>>2]=0-F[g+16>>2];e=0-F[g+12>>2]|0;F[g+12>>2]=e;f=0-f|0;F[g+8>>2]=f;break c}e=F[g+12>>2]}d:{if((f|0)>=0){f=F[a+92>>2];d=f+F[g+16>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=F[g+16>>2];f=d>>31;f=(d^f)-f|0;break e}d=F[g+16>>2];f=d>>31;f=F[a+84>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=F[a+84>>2]+(d-(d^e)|0)|0}e=F[a+84>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}h=F[a+92>>2];if((h|0)>=(d|0)){break g}d=(h<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}h=F[a+92>>2];if((h|0)<=(d|0)){break h}d=(h<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=F[a+92>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=F[a+92>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}e=j<<3;h=e+b|0;i=F[h>>2];h=F[h+4>>2];F[g+36>>2]=d;F[g+32>>2]=f;F[g+24>>2]=i;F[g+28>>2]=h;Jb(g+40|0,m,g+32|0,g+24|0);d=c+e|0;F[d>>2]=F[g+40>>2];F[d+4>>2]=F[g+44>>2];j=j+1|0;if((o|0)!=(j|0)){continue}break}}Z=g+48|0;return 1}ta();v()}function Hh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=Z-48|0;Z=g;d=F[a+8>>2];if(d-2>>>0<=28){F[a+76>>2]=d;e=-1<>2]=d;F[a+80>>2]=e^-1;F[a+92>>2]=(d|0)/2;J[a+88>>2]=M(2)/M(d|0)}F[a+52>>2]=f;d=F[a+40>>2];e=F[d>>2];d=F[d+4>>2];F[g+16>>2]=0;F[g+8>>2]=0;F[g+12>>2]=0;a:{d=d-e|0;if((d|0)>0){m=a+8|0;n=a+44|0;d=d>>>2|0;o=d>>>0<=1?1:d;p=a+96|0;while(1){e=F[a+40>>2];d=F[e>>2];if(F[e+4>>2]-d>>2>>>0<=j>>>0){break a}Kb(n,F[d+(j<<2)>>2],g+8|0);h=F[g+12>>2];d=h>>31;i=F[g+8>>2];e=i>>31;f=(d^h)-d+((e^i)-e)|0;l=F[g+16>>2];d=l>>31;e=(d^l)-d|0;d=0;k=e;e=e+f|0;d=k>>>0>e>>>0?1:d;b:{if(!(d|e)){F[g+8>>2]=F[a+92>>2];break b}f=F[a+92>>2];k=f>>31;i=li(ki(f,k,i,i>>31),_,e,d);F[g+8>>2]=i;d=li(ki(f,k,h,h>>31),_,e,d);F[g+12>>2]=d;e=d>>31;e=(d^e)-e|0;d=i>>31;d=e+((d^i)-d|0)|0;if((l|0)>=0){F[g+16>>2]=f-d;break b}F[g+16>>2]=d-f}d=wa(p);f=F[g+8>>2];c:{if(d){F[g+16>>2]=0-F[g+16>>2];e=0-F[g+12>>2]|0;F[g+12>>2]=e;f=0-f|0;F[g+8>>2]=f;break c}e=F[g+12>>2]}d:{if((f|0)>=0){f=F[a+92>>2];d=f+F[g+16>>2]|0;f=e+f|0;break d}e:{if((e|0)<0){d=F[g+16>>2];f=d>>31;f=(d^f)-f|0;break e}d=F[g+16>>2];f=d>>31;f=F[a+84>>2]+(f-(d^f)|0)|0}if((d|0)<0){d=e>>31;d=(d^e)-d|0;break d}d=e>>31;d=F[a+84>>2]+(d-(d^e)|0)|0}e=F[a+84>>2];f:{if(!(d|f)){d=e;f=d;break f}if(!((d|0)!=(e|0)|f)){f=d;break f}if(!((e|0)!=(f|0)|d)){d=f;break f}g:{if(f){break g}h=F[a+92>>2];if((h|0)>=(d|0)){break g}d=(h<<1)-d|0;f=0;break f}h:{if((e|0)!=(f|0)){break h}h=F[a+92>>2];if((h|0)<=(d|0)){break h}d=(h<<1)-d|0;break f}i:{if((d|0)!=(e|0)){break i}e=F[a+92>>2];if((e|0)<=(f|0)){break i}f=(e<<1)-f|0;break f}if(d){break f}d=0;e=F[a+92>>2];if((e|0)>=(f|0)){break f}f=(e<<1)-f|0}e=j<<3;h=e+b|0;i=F[h>>2];h=F[h+4>>2];F[g+36>>2]=d;F[g+32>>2]=f;F[g+24>>2]=i;F[g+28>>2]=h;Jb(g+40|0,m,g+32|0,g+24|0);d=c+e|0;F[d>>2]=F[g+40>>2];F[d+4>>2]=F[g+44>>2];j=j+1|0;if((o|0)!=(j|0)){continue}break}}Z=g+48|0;return 1}ta();v()}function Nd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;a:{if(!H[b+38>>1]){break a}if(!Ta(1,a+12|0,b)){break a}d=F[b+8>>2];e=F[b+16>>2];g=d-e|0;f=F[a+12>>2];d=F[b+12>>2]-(F[b+20>>2]+(d>>>0>>0)|0)|0;if(g>>>0>>6>>>0&(d|0)<=0|(d|0)<0){break a}d=F[a>>2];c=F[a+4>>2]-d>>2;b:{if(c>>>0>>0){qa(a,f-c|0);f=F[a+12>>2];break b}if(c>>>0<=f>>>0){break b}F[a+4>>2]=d+(f<<2)}if(!f){return 1}d=F[b+16>>2];c=F[b+20>>2];l=F[a>>2];j=F[b+8>>2];i=F[b+12>>2];g=0;while(1){if((c|0)>=(i|0)&d>>>0>=j>>>0|(c|0)>(i|0)){return 0}m=F[b>>2];k=G[m+d|0];d=d+1|0;c=d?c:c+1|0;F[b+16>>2]=d;F[b+20>>2]=c;e=k>>>2|0;h=0;c:{d:{e:{f:{n=k&3;switch(n|0){case 3:break f;case 0:break d;default:break e}}e=e+g|0;if(e>>>0>=f>>>0){return 0}ma(l+(g<<2)|0,0,(k&252)+4|0);g=e;break c}while(1){if((d|0)==(j|0)&(c|0)==(i|0)){break a}f=G[d+m|0];d=d+1|0;c=d?c:c+1|0;F[b+16>>2]=d;F[b+20>>2]=c;e=f<<(h<<3|6)|e;h=h+1|0;if((n|0)!=(h|0)){continue}break}}F[l+(g<<2)>>2]=e}f=F[a+12>>2];g=g+1|0;if(f>>>0>g>>>0){continue}break}b=a+16|0;j=F[a>>2];d=F[a+16>>2];c=F[a+20>>2]-d|0;g:{if(c>>>0<=16383){qa(b,4096-(c>>>2|0)|0);break g}if((c|0)==16384){break g}F[a+20>>2]=d+16384}c=a+28|0;g=F[c>>2];d=F[a+32>>2]-g>>3;h:{if(d>>>0>>0){_a(c,f-d|0);g=F[c>>2];break h}if(d>>>0>f>>>0){F[a+32>>2]=(f<<3)+g}if(!f){break a}}d=F[b>>2];b=0;a=0;while(1){c=j+(b<<2)|0;h=F[c>>2];e=a;i=(b<<3)+g|0;F[i+4>>2]=a;F[i>>2]=h;c=F[c>>2];a=c+a|0;if(a>>>0>4096){break a}i:{if(a>>>0<=e>>>0){break i}h=0;i=c&7;if(i){while(1){F[d+(e<<2)>>2]=b;e=e+1|0;h=h+1|0;if((i|0)!=(h|0)){continue}break}}if(c-1>>>0<=6){break i}while(1){c=d+(e<<2)|0;F[c>>2]=b;F[c+28>>2]=b;F[c+24>>2]=b;F[c+20>>2]=b;F[c+16>>2]=b;F[c+12>>2]=b;F[c+8>>2]=b;F[c+4>>2]=b;e=e+8|0;if((e|0)!=(a|0)){continue}break}}b=b+1|0;if((f|0)!=(b|0)){continue}break}o=(a|0)==4096}return o}function qf(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;f=Z-32|0;Z=f;e=f+8|0;c=Z-80|0;Z=c;a=F[b+36>>2];F[c+72>>2]=F[b+32>>2];F[c+76>>2]=a;d=F[b+28>>2];a=c- -64|0;F[a>>2]=F[b+24>>2];F[a+4>>2]=d;a=F[b+20>>2];F[c+56>>2]=F[b+16>>2];F[c+60>>2]=a;a=F[b+12>>2];F[c+48>>2]=F[b+8>>2];F[c+52>>2]=a;a=F[b+4>>2];F[c+40>>2]=F[b>>2];F[c+44>>2]=a;jc(c+8|0,c+40|0,c+24|0);a=F[c+8>>2];a:{if(a){F[e>>2]=a;a=e+4|0;if(D[c+23|0]>=0){b=c+8|4;e=F[b+4>>2];F[a>>2]=F[b>>2];F[a+4>>2]=e;F[a+8>>2]=F[b+8>>2];break a}ra(a,F[c+12>>2],F[c+16>>2]);if(D[c+23|0]>=0){break a}ja(F[c+12>>2]);break a}if(D[c+23|0]<0){ja(F[c+12>>2])}a=G[c+31|0];if(a>>>0>=2){b=ka(32);D[b+26|0]=0;a=G[1475]|G[1476]<<8;D[b+24|0]=a;D[b+25|0]=a>>>8;a=G[1471]|G[1472]<<8|(G[1473]<<16|G[1474]<<24);d=G[1467]|G[1468]<<8|(G[1469]<<16|G[1470]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=a;D[b+21|0]=a>>>8;D[b+22|0]=a>>>16;D[b+23|0]=a>>>24;a=G[1463]|G[1464]<<8|(G[1465]<<16|G[1466]<<24);d=G[1459]|G[1460]<<8|(G[1461]<<16|G[1462]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=a;D[b+13|0]=a>>>8;D[b+14|0]=a>>>16;D[b+15|0]=a>>>24;a=G[1455]|G[1456]<<8|(G[1457]<<16|G[1458]<<24);d=G[1451]|G[1452]<<8|(G[1453]<<16|G[1454]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=a;D[b+5|0]=a>>>8;D[b+6|0]=a>>>16;D[b+7|0]=a>>>24;F[c+8>>2]=-1;a=c+8|4;ra(a,b,26);d=D[c+23|0];F[e>>2]=F[c+8>>2];e=e+4|0;if((d|0)>=0){d=F[a+4>>2];F[e>>2]=F[a>>2];F[e+4>>2]=d;F[e+8>>2]=F[a+8>>2];ja(b);break a}ra(e,F[c+12>>2],F[c+16>>2]);if(D[c+23|0]<0){ja(F[c+12>>2])}ja(b);break a}F[e>>2]=0;F[e+4>>2]=0;F[e+16>>2]=a;F[e+8>>2]=0;F[e+12>>2]=0}Z=c+80|0;a=F[f+24>>2];if(D[f+23|0]<0){ja(F[f+12>>2])}Z=f+32|0;return a|0}function Ph(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;e=Z-32|0;Z=e;a:{if((c|0)!=3){break a}c=F[a+4>>2];f=F[a+12>>2];F[e+24>>2]=-1;F[e+16>>2]=-1;F[e+20>>2]=1065353216;F[e+8>>2]=-1;F[e+12>>2]=-1;if((b|0)==-2){break a}i=F[F[F[c+4>>2]+8>>2]+(f<<2)>>2];if(($[F[F[c>>2]+8>>2]](c)|0)==1){h=F[F[F[c+4>>2]+8>>2]+(f<<2)>>2];b:{if(($[F[F[c>>2]+8>>2]](c)|0)!=1|b-1>>>0>5){break b}g=$[F[F[c>>2]+36>>2]](c)|0;a=$[F[F[c>>2]+44>>2]](c,f)|0;if(!g|!a){break b}f=$[F[F[c>>2]+40>>2]](c,f)|0;c:{if(f){if((b|0)!=6){break b}b=F[c+44>>2];d=ka(112);F[d+4>>2]=h;c=F[e+12>>2];F[d+8>>2]=F[e+8>>2];F[d+12>>2]=c;c=F[e+20>>2];F[d+16>>2]=F[e+16>>2];F[d+20>>2]=c;F[d+24>>2]=F[e+24>>2];F[d+40>>2]=a;c=a+12|0;F[d+36>>2]=c;F[d+32>>2]=f;F[d+28>>2]=b;F[d+68>>2]=a;F[d- -64>>2]=c;F[d+60>>2]=f;F[d+56>>2]=b;F[d+48>>2]=0;F[d+52>>2]=0;F[d>>2]=5928;F[d+88>>2]=1065353216;F[d+92>>2]=-1;F[d+80>>2]=-1;F[d+84>>2]=-1;F[d+72>>2]=1;F[d+76>>2]=-1;F[d+44>>2]=6492;a=d+96|0;break c}if((b|0)!=6){break b}b=F[c+44>>2];d=ka(112);F[d+4>>2]=h;c=F[e+12>>2];F[d+8>>2]=F[e+8>>2];F[d+12>>2]=c;c=F[e+20>>2];F[d+16>>2]=F[e+16>>2];F[d+20>>2]=c;F[d+24>>2]=F[e+24>>2];F[d+40>>2]=a;c=a+12|0;F[d+36>>2]=c;F[d+32>>2]=g;F[d+28>>2]=b;F[d+68>>2]=a;F[d- -64>>2]=c;F[d+60>>2]=g;F[d+56>>2]=b;F[d+48>>2]=0;F[d+52>>2]=0;F[d>>2]=6932;F[d+88>>2]=1065353216;F[d+92>>2]=-1;F[d+80>>2]=-1;F[d+84>>2]=-1;F[d+72>>2]=1;F[d+76>>2]=-1;F[d+44>>2]=7352;a=d+96|0}F[a>>2]=0;F[a+4>>2]=0;D[a+5|0]=0;D[a+6|0]=0;D[a+7|0]=0;D[a+8|0]=0;D[a+9|0]=0;D[a+10|0]=0;D[a+11|0]=0;D[a+12|0]=0}if(d){break a}}d=ka(28);F[d+4>>2]=i;a=F[e+12>>2];F[d+8>>2]=F[e+8>>2];F[d+12>>2]=a;a=F[e+20>>2];F[d+16>>2]=F[e+16>>2];F[d+20>>2]=a;F[d+24>>2]=F[e+24>>2];F[d>>2]=7764}Z=e+32|0;return d|0}function $c(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;f=Z-80|0;Z=f;a:{if(!Wb(1,f+76|0,b)){break a}k=F[f+76>>2];if(!k){break a}c=F[b+8>>2];e=F[b+16>>2];c=ki(c-e|0,F[b+12>>2]-(F[b+20>>2]+(c>>>0>>0)|0)|0,5,0);e=_;if(c>>>0>>0&(e|0)<=0|(e|0)<0){break a}c=F[a+4>>2];d=F[a+8>>2]-c>>2;b:{if(d>>>0>>0){qa(a+4|0,k-d|0);break b}if(d>>>0<=k>>>0){break b}F[a+8>>2]=c+(k<<2)}p=a+16|0;l=F[a+32>>2];while(1){g=F[b+12>>2];c=g;d=F[b+20>>2];h=F[b+8>>2];e=F[b+16>>2];if((c|0)<=(d|0)&h>>>0<=e>>>0|(c|0)<(d|0)){d=0;break a}m=F[b>>2];q=G[m+e|0];c=d;i=e+1|0;c=i?c:c+1|0;F[b+16>>2]=i;F[b+20>>2]=c;if(h>>>0<=i>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){d=0;break a}i=G[i+m|0];c=d;j=e+2|0;c=j>>>0<2?c+1|0:c;F[b+16>>2]=j;F[b+20>>2]=c;if(h>>>0<=j>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){d=0;break a}j=G[j+m|0];c=d;n=e+3|0;c=n>>>0<3?c+1|0:c;F[b+16>>2]=n;F[b+20>>2]=c;if(h>>>0<=n>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){d=0;break a}h=G[m+n|0];c=d;d=e+4|0;c=d>>>0<4?c+1|0:c;F[b+16>>2]=d;F[b+20>>2]=c;if(q>>>0>4){d=0;break a}if((i-12&255)>>>0<245){d=0;break a}if(!j){d=0;break a}c=kb(f+8|0);g=(h|0)!=0;d=i-1|0;if(d>>>0<=10){d=F[(d<<2)+10148>>2]}else{d=-1}d=L(d,j);cc(c,q,j,i,g,d,d>>31);if(Wb(1,f+4|0,b)){e=F[f+4>>2];F[f+68>>2]=e;d=bc(ka(96),c);$[F[F[l>>2]+8>>2]](l,F[l+12>>2]-F[l+8>>2]>>2,d);d=(F[l+12>>2]-F[l+8>>2]>>2)-1|0;h=d<<2;F[F[h+F[l+8>>2]>>2]+60>>2]=e;F[F[a+4>>2]+(o<<2)>>2]=d;c=F[a+16>>2];e=F[a+20>>2]-c>>2;c:{if((e|0)>(d|0)){break c}F[f>>2]=-1;d=d+1|0;if(d>>>0>e>>>0){Fa(p,d-e|0,f);c=F[p>>2];break c}if(d>>>0>=e>>>0){break c}F[a+20>>2]=(d<<2)+c}F[c+h>>2]=o;d=1;o=o+1|0;if((o|0)!=(k|0)){continue}break a}break}d=0}Z=f+80|0;return d|0}function Oc(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;k=Z-16|0;Z=k;F[k+8>>2]=c;h=F[a+12>>2];d=F[a+8>>2];g=h-d>>2;a:{if((g|0)>(b|0)){break a}e=b+1|0;if(e>>>0>g>>>0){l=e-g|0;f=F[a+16>>2];d=F[a+12>>2];if(l>>>0<=f-d>>2>>>0){if(l){e=d;d=l<<2;d=ma(e,0,d)+d|0}F[a+12>>2]=d;break a}b:{c:{d:{m=F[a+8>>2];g=d-m>>2;i=g+l|0;if(i>>>0<1073741824){e=f-m|0;f=e>>>1|0;e=e>>>0>=2147483644?1073741823:f>>>0>i>>>0?f:i;if(e){if(e>>>0>=1073741824){break d}j=ka(e<<2)}h=(g<<2)+j|0;f=l<<2;i=ma(h,0,f);g=f+i|0;e=(e<<2)+j|0;if((d|0)==(m|0)){break c}while(1){d=d-4|0;f=F[d>>2];F[d>>2]=0;h=h-4|0;F[h>>2]=f;if((d|0)!=(m|0)){continue}break}F[a+16>>2]=e;e=F[a+12>>2];F[a+12>>2]=g;d=F[a+8>>2];F[a+8>>2]=h;if((d|0)==(e|0)){break b}while(1){e=e-4|0;f=F[e>>2];F[e>>2]=0;if(f){xa(f)}if((d|0)!=(e|0)){continue}break}break b}na();v()}oa();v()}F[a+16>>2]=e;F[a+12>>2]=g;F[a+8>>2]=i}if(d){ja(d)}break a}if(e>>>0>=g>>>0){break a}d=d+(e<<2)|0;if((d|0)!=(h|0)){while(1){h=h-4|0;c=F[h>>2];F[h>>2]=0;if(c){xa(c)}if((d|0)!=(h|0)){continue}break}c=F[k+8>>2]}F[a+12>>2]=d}e:{f:{d=F[c+56>>2];g:{if((d|0)>4){break g}j=L(d,12)+a|0;d=F[j+24>>2];if((d|0)!=F[j+28>>2]){F[d>>2]=b;F[j+24>>2]=d+4;break g}i=F[j+20>>2];g=d-i|0;f=g>>2;e=f+1|0;if(e>>>0>=1073741824){break f}d=g>>>1|0;e=g>>>0>=2147483644?1073741823:d>>>0>e>>>0?d:e;if(e){if(e>>>0>=1073741824){break e}d=ka(e<<2)}else{d=0}f=d+(f<<2)|0;F[f>>2]=b;d=pa(d,i,g);F[j+20>>2]=d;F[j+24>>2]=f+4;F[j+28>>2]=d+(e<<2);if(!i){break g}ja(i)}F[c+60>>2]=b;a=F[a+8>>2];F[k+8>>2]=0;a=a+(b<<2)|0;b=F[a>>2];F[a>>2]=c;if(b){xa(b)}a=F[k+8>>2];F[k+8>>2]=0;if(a){xa(a)}Z=k+16|0;return}na();v()}oa();v()}function Pf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;i=c;d=a;a:{if(F[a+12>>2]==(b|0)){break a}a=b;b=F[d+4>>2];e=F[d>>2];if((b|0)!=(e|0)){while(1){c=b-12|0;if(D[b-1|0]<0){ja(F[c>>2])}b=c;if((e|0)!=(b|0)){continue}break}}F[d+12>>2]=a;F[d+4>>2]=e;c=F[a>>2];j=a+4|0;if((c|0)==(j|0)){break a}while(1){a=F[d+4>>2];b:{if((a|0)!=F[d+8>>2]){c:{if(D[c+27|0]>=0){b=F[c+20>>2];F[a>>2]=F[c+16>>2];F[a+4>>2]=b;F[a+8>>2]=F[c+24>>2];break c}ra(a,F[c+16>>2],F[c+20>>2])}F[d+4>>2]=a+12;break b}g=0;d:{e:{f:{a=F[d+4>>2];e=F[d>>2];f=(a-e|0)/12|0;b=f+1|0;if(b>>>0<357913942){h=(F[d+8>>2]-e|0)/12|0;k=h<<1;b=h>>>0>=178956970?357913941:b>>>0>>0?k:b;if(b){if(b>>>0>=357913942){break f}g=ka(L(b,12))}h=L(b,12);b=L(f,12)+g|0;g:{if(D[c+27|0]>=0){f=F[c+20>>2];F[b>>2]=F[c+16>>2];F[b+4>>2]=f;F[b+8>>2]=F[c+24>>2];break g}ra(b,F[c+16>>2],F[c+20>>2]);e=F[d>>2];a=F[d+4>>2]}g=g+h|0;f=b+12|0;if((a|0)==(e|0)){break e}while(1){a=a-12|0;h=F[a+4>>2];b=b-12|0;F[b>>2]=F[a>>2];F[b+4>>2]=h;F[b+8>>2]=F[a+8>>2];F[a>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;if((a|0)!=(e|0)){continue}break}F[d+8>>2]=g;a=F[d+4>>2];F[d+4>>2]=f;e=F[d>>2];F[d>>2]=b;if((a|0)==(e|0)){break d}while(1){b=a-12|0;if(D[a-1|0]<0){ja(F[b>>2])}a=b;if((e|0)!=(b|0)){continue}break}break d}na();v()}oa();v()}F[d+8>>2]=g;F[d+4>>2]=f;F[d>>2]=b}if(e){ja(e)}}b=F[c+4>>2];h:{if(b){while(1){a=b;b=F[b>>2];if(b){continue}break h}}while(1){a=F[c+8>>2];b=F[a>>2]!=(c|0);c=a;if(b){continue}break}}c=a;if((j|0)!=(a|0)){continue}break}}a=0;i:{if((i|0)<0){break i}b=F[d>>2];if((F[d+4>>2]-b|0)/12>>>0<=i>>>0){break i}a=b+L(i,12)|0;a=D[a+11|0]<0?F[a>>2]:a}return a|0}function Ad(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;i=Z-16|0;Z=i;F[i>>2]=b;f=-1;a:{if((b|0)==-1){F[i+4>>2]=-1;break a}f=b+1|0;F[i+4>>2]=(f>>>0)%3|0?f:b-2|0;if((b>>>0)%3|0){f=b-1|0;break a}f=b+2|0}F[i+8>>2]=f;n=(b>>>0)/3|0;b:{c:{d:{while(1){e:{f:{j=F[(l<<2)+i>>2];if((j|0)!=-1){f=F[F[F[a+8>>2]+12>>2]+(j<<2)>>2];if((f|0)!=-1){break f}}f=0;g=F[a+216>>2];if((g|0)==F[a+220>>2]){break e}while(1){g=L(f,144)+g|0;d=F[g+136>>2];c=F[g+140>>2];g:{if(d>>>0>>0){F[d>>2]=j;F[g+136>>2]=d+4;break g}e=d;d=F[g+132>>2];k=e-d|0;e=k>>2;h=e+1|0;if(h>>>0>=1073741824){break d}m=e<<2;c=c-d|0;e=c>>>1|0;h=c>>>0>=2147483644?1073741823:h>>>0>>0?e:h;if(h){if(h>>>0>=1073741824){break c}c=ka(h<<2)}else{c=0}e=m+c|0;F[e>>2]=j;c=pa(c,d,k);F[g+132>>2]=c;F[g+136>>2]=e+4;F[g+140>>2]=c+(h<<2);if(!d){break g}ja(d)}f=f+1|0;g=F[a+216>>2];if(f>>>0<(F[a+220>>2]-g|0)/144>>>0){continue}break}break e}if((b|0)==-1|(f>>>0)/3>>>0>>0){break e}f=0;if(F[a+220>>2]==F[a+216>>2]){break e}while(1){h:{if(!wa(F[a+368>>2]+(f<<4)|0)){break h}g=F[a+216>>2]+L(f,144)|0;d=F[g+136>>2];c=F[g+140>>2];if(d>>>0>>0){F[d>>2]=j;F[g+136>>2]=d+4;break h}e=d;d=F[g+132>>2];k=e-d|0;e=k>>2;h=e+1|0;if(h>>>0>=1073741824){break b}m=e<<2;c=c-d|0;e=c>>>1|0;h=c>>>0>=2147483644?1073741823:h>>>0>>0?e:h;if(h){if(h>>>0>=1073741824){break c}c=ka(h<<2)}else{c=0}e=m+c|0;F[e>>2]=j;c=pa(c,d,k);F[g+132>>2]=c;F[g+136>>2]=e+4;F[g+140>>2]=c+(h<<2);if(!d){break h}ja(d)}f=f+1|0;if(f>>>0<(F[a+220>>2]-F[a+216>>2]|0)/144>>>0){continue}break}}l=l+1|0;if((l|0)!=3){continue}break}Z=i+16|0;return 1}na();v()}oa();v()}na();v()}function Bd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=Z-16|0;Z=h;m=-1;a:{b:{c:{if(!Da(1,h+12|0,b)){break c}j=F[h+12>>2];if(j){c=F[a+8>>2];if((F[c+4>>2]-F[c>>2]>>2>>>0)/3>>>0>>0){break c}while(1){if(!Da(1,h+8|0,b)){break c}c=F[h+8>>2];if(!Da(1,h+8|0,b)){break c}g=c+g|0;c=F[h+8>>2];if(g>>>0>>0){break c}e=g-c|0;c=F[a+40>>2];d:{if((c|0)!=F[a+44>>2]){F[c+4>>2]=g;F[c>>2]=e;F[a+40>>2]=c+12;j=F[h+12>>2];break d}d=c;c=F[a+36>>2];l=d-c|0;d=(l|0)/12|0;f=d+1|0;if(f>>>0>=357913942){break b}i=d<<1;f=d>>>0>=178956970?357913941:f>>>0>>0?i:f;if(f){if(f>>>0>=357913942){break a}i=ka(L(f,12))}else{i=0}d=i+L(d,12)|0;F[d+4>>2]=g;F[d>>2]=e;e=pa(d+L((l|0)/-12|0,12)|0,c,l);F[a+44>>2]=i+L(f,12);F[a+40>>2]=d+12;F[a+36>>2]=e;if(!c){break d}ja(c)}k=k+1|0;if(k>>>0>>0){continue}break}g=0;hc(b,0,0);if(j){while(1){c=G[b+36|0];d=H[F[a+4>>2]+36>>1];e:{f:{if(((d<<8|d>>>8)&65535)>>>0<=513){if(!c){break e}e=0;d=F[b+32>>2];k=d>>>3|0;f=F[b+24>>2];c=k+f|0;i=F[b+28>>2];g:{if(c>>>0>=i>>>0){c=d;break g}e=G[c|0];c=d+1|0;F[b+32>>2]=c;k=c>>>3|0;e=e>>>(d&7)&1}if(i>>>0>f+k>>>0){break f}break e}if(!c){break e}e=0;c=F[b+32>>2];d=F[b+24>>2]+(c>>>3|0)|0;if(d>>>0>=I[b+28>>2]){break e}e=G[d|0]>>>(c&7)&1}F[b+32>>2]=c+1}c=F[a+36>>2]+L(g,12)|0;D[c+8|0]=G[c+8|0]&254|e&1;g=g+1|0;if((j|0)!=(g|0)){continue}break}}D[b+36|0]=0;d=F[b+20>>2];a=0;e=F[b+32>>2]+7|0;a=e>>>0<7?1:a;e=a<<29|e>>>3;c=e+F[b+16>>2]|0;a=(a>>>3|0)+d|0;F[b+16>>2]=c;F[b+20>>2]=c>>>0>>0?a+1|0:a}m=F[b+16>>2]}Z=h+16|0;return m}na();v()}oa();v()}function xf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;m=Z-16|0;Z=m;l=F[b+80>>2];e=G[c+24|0];a=L(l,e);a:{b:{c:{d:{b=F[c+28>>2];if(!(!G[c+84|0]|(b|0)!=1&(b|0)!=2)){b=F[c+48>>2];c=F[F[c>>2]>>2];F[m+8>>2]=0;F[m>>2]=0;F[m+4>>2]=0;if(a){if((a|0)<0){break d}f=ka(a);h=la(f,b+c|0,a)+a|0}a=F[d>>2];if(a){F[d+4>>2]=a;ja(a)}F[d+8>>2]=h;F[d+4>>2]=h;F[d>>2]=f;b=1;break a}if(e){f=ka(e);ma(f,0,e)}e:{i=F[d+4>>2];b=F[d>>2];g=i-b|0;f:{if(g>>>0>>0){k=a-g|0;j=F[d+8>>2];if(k>>>0<=j-i>>>0){n=d,o=ma(i,0,k)+k|0,F[n+4>>2]=o;break f}if((a|0)<0){break e}i=j-b|0;j=i<<1;i=i>>>0>=1073741823?2147483647:a>>>0>>0?j:a;j=ka(i);ma(j+g|0,0,k);g=pa(j,b,g);F[d+8>>2]=g+i;F[d+4>>2]=a+g;F[d>>2]=g;if(!b){break f}ja(b);break f}if(a>>>0>=g>>>0){break f}F[d+4>>2]=a+b}if(!l){b=1;break c}if(!e){b=0;a=0;while(1){if(!Cb(c,G[c+84|0]?a:F[F[c+68>>2]+(a<<2)>>2],D[c+24|0],f)){break c}a=a+1|0;b=l>>>0<=a>>>0;if((a|0)!=(l|0)){continue}break}break c}i=e&252;g=e&3;b=0;j=e>>>0<4;e=0;while(1){if(!Cb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],f)){break c}b=0;a=0;k=0;if(!j){while(1){D[F[d>>2]+h|0]=G[a+f|0];D[(F[d>>2]+h|0)+1|0]=G[(a|1)+f|0];D[(F[d>>2]+h|0)+2|0]=G[(a|2)+f|0];D[(F[d>>2]+h|0)+3|0]=G[(a|3)+f|0];a=a+4|0;h=h+4|0;k=k+4|0;if((i|0)!=(k|0)){continue}break}}if(g){while(1){D[F[d>>2]+h|0]=G[a+f|0];a=a+1|0;h=h+1|0;b=b+1|0;if((g|0)!=(b|0)){continue}break}}e=e+1|0;b=l>>>0<=e>>>0;if((e|0)!=(l|0)){continue}break}break b}na();v()}na();v()}if(!f){break a}}ja(f)}Z=m+16|0;return b&1}function wf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;m=Z-16|0;Z=m;l=F[b+80>>2];e=G[c+24|0];a=L(l,e);a:{b:{c:{d:{b=F[c+28>>2];if(!(!G[c+84|0]|(b|0)!=1&(b|0)!=2)){b=F[c+48>>2];c=F[F[c>>2]>>2];F[m+8>>2]=0;F[m>>2]=0;F[m+4>>2]=0;if(a){if((a|0)<0){break d}f=ka(a);h=la(f,b+c|0,a)+a|0}a=F[d>>2];if(a){F[d+4>>2]=a;ja(a)}F[d+8>>2]=h;F[d+4>>2]=h;F[d>>2]=f;b=1;break a}if(e){f=ka(e);ma(f,0,e)}e:{i=F[d+4>>2];b=F[d>>2];g=i-b|0;f:{if(g>>>0>>0){k=a-g|0;j=F[d+8>>2];if(k>>>0<=j-i>>>0){n=d,o=ma(i,0,k)+k|0,F[n+4>>2]=o;break f}if((a|0)<0){break e}i=j-b|0;j=i<<1;i=i>>>0>=1073741823?2147483647:a>>>0>>0?j:a;j=ka(i);ma(j+g|0,0,k);g=pa(j,b,g);F[d+8>>2]=g+i;F[d+4>>2]=a+g;F[d>>2]=g;if(!b){break f}ja(b);break f}if(a>>>0>=g>>>0){break f}F[d+4>>2]=a+b}if(!l){b=1;break c}if(!e){b=0;a=0;while(1){if(!Bb(c,G[c+84|0]?a:F[F[c+68>>2]+(a<<2)>>2],D[c+24|0],f)){break c}a=a+1|0;b=l>>>0<=a>>>0;if((a|0)!=(l|0)){continue}break}break c}i=e&252;g=e&3;b=0;j=e>>>0<4;e=0;while(1){if(!Bb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],f)){break c}b=0;a=0;k=0;if(!j){while(1){D[F[d>>2]+h|0]=G[a+f|0];D[(F[d>>2]+h|0)+1|0]=G[(a|1)+f|0];D[(F[d>>2]+h|0)+2|0]=G[(a|2)+f|0];D[(F[d>>2]+h|0)+3|0]=G[(a|3)+f|0];a=a+4|0;h=h+4|0;k=k+4|0;if((i|0)!=(k|0)){continue}break}}if(g){while(1){D[F[d>>2]+h|0]=G[a+f|0];a=a+1|0;h=h+1|0;b=b+1|0;if((g|0)!=(b|0)){continue}break}}e=e+1|0;b=l>>>0<=e>>>0;if((e|0)!=(l|0)){continue}break}break b}na();v()}na();v()}if(!f){break a}}ja(f)}Z=m+16|0;return b&1}function Jb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;k=F[b+16>>2];h=F[c+4>>2]-k|0;e=F[c>>2]-k|0;F[c>>2]=e;f=h;F[c+4>>2]=f;l=F[b+16>>2];f=f>>31;g=(h^f)-f|0;f=e>>31;m=l>>>0>=g+((f^e)-f|0)>>>0;a:{if(m){f=h;break a}b:{c:{if((e|0)>=0){g=1;j=1;if((h|0)>=0){break b}i=1;g=-1;j=-1;if(e){break c}break b}i=-1;g=-1;j=-1;if((h|0)<=0){break b}}g=(h|0)<=0?-1:1;j=i}n=L(j,l);f=(e<<1)-n|0;i=(L(g,j)|0)>=0;e=L(g,l);f=((i?0-f|0:f)+e|0)/2|0;F[c+4>>2]=f;e=(h<<1)-e|0;e=((i?0-e|0:e)+n|0)/2|0;F[c>>2]=e}d:{e:{f:{g:{h:{i:{j:{if(e){if((e|0)<0){break j}if((f|0)>=0){break i}break f}if(f){break h}j=1;g=0;f=0;i=0;break d}j=1;if((f|0)>0){break g}i=(f|0)>0?3:0;g=f;f=e;break d}g=0-f|0;f=0-e|0;i=2;break e}if((f|0)<=0){break f}}f=0-f|0;g=e;i=3;break e}g=0-e|0;i=1}F[c>>2]=f;F[c+4>>2]=g;j=0}e=F[d>>2]+f|0;h=F[b+16>>2];k:{if((e|0)>(h|0)){e=e-F[b+4>>2]|0;break k}if((0-h|0)<=(e|0)){break k}e=F[b+4>>2]+e|0}c=F[d+4>>2]+g|0;l:{if((h|0)<(c|0)){c=c-F[b+4>>2]|0;break l}if((0-h|0)<=(c|0)){break l}c=F[b+4>>2]+c|0}m:{if(j){b=c;break m}b=c;n:{o:{p:{d=4-i|0;switch((d>>>0<4?d:0-i|0)-1|0){case 2:break n;case 1:break o;case 0:break p;default:break m}}b=0-e|0;e=c;break m}b=0-c|0;e=0-e|0;break m}b=e;e=0-c|0}q:{if(m){c=b;break q}r:{s:{if((e|0)>=0){c=1;f=1;if((b|0)>=0){break r}d=1;c=-1;f=-1;if(e){break s}break r}d=-1;c=-1;f=-1;if((b|0)<=0){break r}}c=(b|0)<=0?-1:1;f=d}d=e<<1;e=L(f,h);d=d-e|0;f=(L(c,f)|0)>=0;g=f?0-d|0:d;d=L(c,h);c=(g+d|0)/2|0;b=(b<<1)-d|0;e=(e+(f?0-b|0:b)|0)/2|0}b=a;F[b>>2]=e+k;F[b+4>>2]=c+k}function Uh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;F[a+8>>2]=e;m=a+32|0;h=F[m>>2];g=F[a+36>>2]-h>>2;a:{if(g>>>0>>0){qa(m,e-g|0);f=F[a+8>>2];break a}f=e;if(f>>>0>=g>>>0){break a}F[a+36>>2]=h+(e<<2);f=e}g=e>>>0>1073741823?-1:e<<2;n=ma(ka(g),0,g);b:{if((f|0)<=0){break b}h=F[a+32>>2];while(1){f=i<<2;g=F[f+n>>2];j=F[a+16>>2];c:{if((g|0)>(j|0)){F[f+h>>2]=j;break c}f=f+h|0;j=F[a+12>>2];if((j|0)>(g|0)){F[f>>2]=j;break c}F[f>>2]=g}f=F[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}if((f|0)<=0){break b}i=0;while(1){g=i<<2;f=g+c|0;g=F[b+g>>2]+F[g+h>>2]|0;F[f>>2]=g;d:{if((g|0)>F[a+16>>2]){g=g-F[a+20>>2]|0}else{if((g|0)>=F[a+12>>2]){break d}g=g+F[a+20>>2]|0}F[f>>2]=g}f=F[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}}if(!((d|0)<=(e|0)|(f|0)<=0)){p=0-e<<2;g=e;while(1){e:{if((f|0)<=0){break e}l=g<<2;o=l+c|0;q=o+p|0;j=F[m>>2];i=0;while(1){f=i<<2;h=F[f+q>>2];k=F[a+16>>2];f:{if((h|0)>(k|0)){F[f+j>>2]=k;break f}f=f+j|0;k=F[a+12>>2];if((k|0)>(h|0)){F[f>>2]=k;break f}F[f>>2]=h}f=F[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}i=0;if((f|0)<=0){break e}l=b+l|0;while(1){h=i<<2;f=h+o|0;h=F[h+l>>2]+F[h+j>>2]|0;F[f>>2]=h;g:{if((h|0)>F[a+16>>2]){h=h-F[a+20>>2]|0}else{if((h|0)>=F[a+12>>2]){break g}h=h+F[a+20>>2]|0}F[f>>2]=h}f=F[a+8>>2];i=i+1|0;if((f|0)>(i|0)){continue}break}}g=e+g|0;if((g|0)<(d|0)){continue}break}}ja(n);return 1}function yf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;j=F[b+80>>2];b=G[c+24|0];g=L(j,b);a:{if(!b){break a}h=b<<2;f=ka(h);a=f;k=b&7;if(k){while(1){F[a>>2]=-1073741824;a=a+4|0;e=e+1|0;if((k|0)!=(e|0)){continue}break}}if((b-1&1073741823)>>>0<7){break a}e=f+h|0;while(1){F[a+24>>2]=-1073741824;F[a+28>>2]=-1073741824;F[a+16>>2]=-1073741824;F[a+20>>2]=-1073741824;F[a+8>>2]=-1073741824;F[a+12>>2]=-1073741824;F[a>>2]=-1073741824;F[a+4>>2]=-1073741824;a=a+32|0;if((e|0)!=(a|0)){continue}break}}e=F[d>>2];a=F[d+4>>2]-e>>2;b:{if(a>>>0>>0){qa(d,g-a|0);break b}if(a>>>0<=g>>>0){break b}F[d+4>>2]=e+(g<<2)}c:{d:{e:{if(!j){i=1;break e}if(!b){a=0;while(1){if(!lb(c,G[c+84|0]?a:F[F[c+68>>2]+(a<<2)>>2],D[c+24|0],f)){break e}a=a+1|0;i=j>>>0<=a>>>0;if((a|0)!=(j|0)){continue}break}break e}n=b&252;k=b&3;o=b>>>0<4;e=0;b=0;while(1){if(!lb(c,G[c+84|0]?b:F[F[c+68>>2]+(b<<2)>>2],D[c+24|0],f)){break e}m=F[d>>2];i=0;a=0;l=0;if(!o){while(1){g=(e<<2)+m|0;h=a<<2;J[g>>2]=J[h+f>>2];J[g+4>>2]=J[(h|4)+f>>2];J[g+8>>2]=J[(h|8)+f>>2];J[g+12>>2]=J[(h|12)+f>>2];a=a+4|0;e=e+4|0;l=l+4|0;if((n|0)!=(l|0)){continue}break}}if(k){while(1){J[(e<<2)+m>>2]=J[(a<<2)+f>>2];a=a+1|0;e=e+1|0;i=i+1|0;if((k|0)!=(i|0)){continue}break}}b=b+1|0;i=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break d}if(!f){break c}}ja(f)}return i|0}function $d(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;k=Z-16|0;Z=k;c=F[b+20>>2];d=F[b+16>>2];e=d+4|0;c=e>>>0<4?c+1|0:c;g=F[b+12>>2];a:{if(I[b+8>>2]>>0&(g|0)<=(c|0)|(c|0)>(g|0)){break a}d=d+F[b>>2]|0;h=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);F[b+16>>2]=e;F[b+20>>2]=c;if((h|0)<0){break a}Na(a+76|0,h);c=k;F[c>>2]=0;F[c+4>>2]=0;D[c+5|0]=0;D[c+6|0]=0;D[c+7|0]=0;D[c+8|0]=0;D[c+9|0]=0;D[c+10|0]=0;D[c+11|0]=0;D[c+12|0]=0;b:{if(!Aa(c,b)){break b}if(h){g=1;while(1){d=1<>2]+(i>>>3&536870908)|0;e=e^g;if(e&1){d=F[f>>2]&(d^-1)}else{d=d|F[f>>2]}g=e^1;F[f>>2]=d;i=i+1|0;if((h|0)!=(i|0)){continue}break}}i=0;c=F[b+8>>2];e=F[b+12>>2];f=e;e=F[b+20>>2];g=e;l=F[b+16>>2];d=l+4|0;e=d>>>0<4?e+1|0:e;h=d;if(d>>>0>c>>>0&(e|0)>=(f|0)|(e|0)>(f|0)){break b}m=F[b>>2];d=m+l|0;j=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);F[b+16>>2]=h;F[b+20>>2]=e;d=c;c=g;e=l+8|0;c=e>>>0<8?c+1|0:c;if(d>>>0>>0&(c|0)>=(f|0)|(c|0)>(f|0)){break b}d=h+m|0;d=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);F[b+16>>2]=e;F[b+20>>2]=c;if((d|0)<(j|0)){break b}F[a+16>>2]=d;F[a+12>>2]=j;c=(d>>31)-((j>>31)+(d>>>0>>0)|0)|0;b=d-j|0;if(!c&b>>>0>2147483646|c){break b}i=1;c=b+1|0;F[a+20>>2]=c;b=c>>>1|0;F[a+24>>2]=b;F[a+28>>2]=0-b;if(c&1){break b}F[a+24>>2]=b-1}}Z=k+16|0;return i|0}function tf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=Z-16|0;Z=k;j=F[b+80>>2];e=G[c+24|0];b=L(j,e);a:{b:{c:{d:{f=F[c+28>>2];if(!(!G[c+84|0]|(f|0)!=5&(f|0)!=6)){e=F[c+48>>2];c=F[F[c>>2]>>2];F[k+8>>2]=0;F[k>>2]=0;F[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<2;a=ka(b);g=la(a,c+e|0,b)+b|0}b=F[d>>2];if(b){F[d+4>>2]=b;ja(b)}F[d+8>>2]=g;F[d+4>>2]=g;F[d>>2]=a;h=1;break a}if(e){f=e<<2;a=ka(f);ma(a,0,f)}i=F[d>>2];f=F[d+4>>2]-i>>2;e:{if(f>>>0>>0){qa(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}F[d+4>>2]=i+(b<<2)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!xb(c,G[c+84|0]?b:F[F[c+68>>2]+(b<<2)>>2],D[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!xb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],a)){break c}n=F[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<2)+n|0;i=b<<2;F[f>>2]=F[i+a>>2];F[f+4>>2]=F[(i|4)+a>>2];F[f+8>>2]=F[(i|8)+a>>2];F[f+12>>2]=F[(i|12)+a>>2];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){F[(g<<2)+n>>2]=F[(b<<2)+a>>2];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}na();v()}if(!a){break a}}ja(a)}Z=k+16|0;return h|0}function cd(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=Z-16|0;Z=k;j=F[b+80>>2];e=G[c+24|0];b=L(j,e);a:{b:{c:{d:{f=F[c+28>>2];if(!(!G[c+84|0]|(f|0)!=5&(f|0)!=6)){e=F[c+48>>2];c=F[F[c>>2]>>2];F[k+8>>2]=0;F[k>>2]=0;F[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<2;a=ka(b);g=la(a,c+e|0,b)+b|0}b=F[d>>2];if(b){F[d+4>>2]=b;ja(b)}F[d+8>>2]=g;F[d+4>>2]=g;F[d>>2]=a;h=1;break a}if(e){f=e<<2;a=ka(f);ma(a,0,f)}i=F[d>>2];f=F[d+4>>2]-i>>2;e:{if(f>>>0>>0){qa(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}F[d+4>>2]=i+(b<<2)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!yb(c,G[c+84|0]?b:F[F[c+68>>2]+(b<<2)>>2],D[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!yb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],a)){break c}n=F[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<2)+n|0;i=b<<2;F[f>>2]=F[i+a>>2];F[f+4>>2]=F[(i|4)+a>>2];F[f+8>>2]=F[(i|8)+a>>2];F[f+12>>2]=F[(i|12)+a>>2];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){F[(g<<2)+n>>2]=F[(b<<2)+a>>2];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}na();v()}if(!a){break a}}ja(a)}Z=k+16|0;return h|0}function vf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=Z-16|0;Z=k;j=F[b+80>>2];e=G[c+24|0];b=L(j,e);a:{b:{c:{d:{f=F[c+28>>2];if(!(!G[c+84|0]|(f|0)!=3&(f|0)!=4)){e=F[c+48>>2];c=F[F[c>>2]>>2];F[k+8>>2]=0;F[k>>2]=0;F[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<1;a=ka(b);g=la(a,c+e|0,b)+b|0}b=F[d>>2];if(b){F[d+4>>2]=b;ja(b)}F[d+8>>2]=g;F[d+4>>2]=g;F[d>>2]=a;h=1;break a}if(e){f=e<<1;a=ka(f);ma(a,0,f)}i=F[d>>2];f=F[d+4>>2]-i>>1;e:{if(f>>>0>>0){kd(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}F[d+4>>2]=i+(b<<1)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!Ab(c,G[c+84|0]?b:F[F[c+68>>2]+(b<<2)>>2],D[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!Ab(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],a)){break c}n=F[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<1)+n|0;i=b<<1;E[f>>1]=H[i+a>>1];E[f+2>>1]=H[(i|2)+a>>1];E[f+4>>1]=H[(i|4)+a>>1];E[f+6>>1]=H[(i|6)+a>>1];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){E[(g<<1)+n>>1]=H[(b<<1)+a>>1];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}na();v()}if(!a){break a}}ja(a)}Z=k+16|0;return h|0}function uf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;a=0;k=Z-16|0;Z=k;j=F[b+80>>2];e=G[c+24|0];b=L(j,e);a:{b:{c:{d:{f=F[c+28>>2];if(!(!G[c+84|0]|(f|0)!=3&(f|0)!=4)){e=F[c+48>>2];c=F[F[c>>2]>>2];F[k+8>>2]=0;F[k>>2]=0;F[k+4>>2]=0;if(b){if((b|0)<0){break d}b=b<<1;a=ka(b);g=la(a,c+e|0,b)+b|0}b=F[d>>2];if(b){F[d+4>>2]=b;ja(b)}F[d+8>>2]=g;F[d+4>>2]=g;F[d>>2]=a;h=1;break a}if(e){f=e<<1;a=ka(f);ma(a,0,f)}i=F[d>>2];f=F[d+4>>2]-i>>1;e:{if(f>>>0>>0){kd(d,b-f|0);break e}if(b>>>0>=f>>>0){break e}F[d+4>>2]=i+(b<<1)}if(!j){h=1;break c}if(!e){b=0;while(1){if(!zb(c,G[c+84|0]?b:F[F[c+68>>2]+(b<<2)>>2],D[c+24|0],a)){break c}b=b+1|0;h=j>>>0<=b>>>0;if((b|0)!=(j|0)){continue}break}break c}o=e&252;m=e&3;p=e>>>0<4;e=0;while(1){if(!zb(c,G[c+84|0]?e:F[F[c+68>>2]+(e<<2)>>2],D[c+24|0],a)){break c}n=F[d>>2];l=0;b=0;h=0;if(!p){while(1){f=(g<<1)+n|0;i=b<<1;E[f>>1]=H[i+a>>1];E[f+2>>1]=H[(i|2)+a>>1];E[f+4>>1]=H[(i|4)+a>>1];E[f+6>>1]=H[(i|6)+a>>1];b=b+4|0;g=g+4|0;h=h+4|0;if((o|0)!=(h|0)){continue}break}}if(m){while(1){E[(g<<1)+n>>1]=H[(b<<1)+a>>1];b=b+1|0;g=g+1|0;l=l+1|0;if((l|0)!=(m|0)){continue}break}}e=e+1|0;h=j>>>0<=e>>>0;if((e|0)!=(j|0)){continue}break}break b}na();v()}if(!a){break a}}ja(a)}Z=k+16|0;return h|0}function kc(a,b){var c=0,d=0,e=0,f=0,g=0;f=-1;d=-1;a:{if((b|0)==-1){break a}d=b+1|0;f=(d>>>0)%3|0?d:b-2|0;d=b-1|0;if((b>>>0)%3|0){break a}d=b+2|0}b:{c:{d:{switch(F[a+168>>2]){case 0:case 1:e=F[a+148>>2];c=1;b=F[a+156>>2];g=b+(((f|0)==-1?-1:F[F[e>>2]+(f<<2)>>2])<<2)|0;F[g>>2]=F[g>>2]+1;b=(((d|0)==-1?-1:F[F[e>>2]+(d<<2)>>2])<<2)+b|0;break c;case 5:e=F[a+148>>2];c=-1;c=((b|0)!=-1?F[F[e>>2]+(b<<2)>>2]:c)<<2;b=F[a+156>>2];c=c+b|0;F[c>>2]=F[c>>2]+1;c=(((f|0)==-1?-1:F[F[e>>2]+(f<<2)>>2])<<2)+b|0;F[c>>2]=F[c>>2]+1;c=2;b=(((d|0)==-1?-1:F[F[e>>2]+(d<<2)>>2])<<2)+b|0;break c;case 3:e=F[a+148>>2];c=-1;c=((b|0)!=-1?F[F[e>>2]+(b<<2)>>2]:c)<<2;b=F[a+156>>2];c=c+b|0;F[c>>2]=F[c>>2]+1;c=(((f|0)==-1?-1:F[F[e>>2]+(f<<2)>>2])<<2)+b|0;F[c>>2]=F[c>>2]+2;c=1;b=(((d|0)==-1?-1:F[F[e>>2]+(d<<2)>>2])<<2)+b|0;break c;case 7:break d;default:break b}}e=F[a+148>>2];c=-1;c=((b|0)!=-1?F[F[e>>2]+(b<<2)>>2]:c)<<2;b=F[a+156>>2];c=c+b|0;F[c>>2]=F[c>>2]+2;c=(((f|0)==-1?-1:F[F[e>>2]+(f<<2)>>2])<<2)+b|0;F[c>>2]=F[c>>2]+2;c=2;b=(((d|0)==-1?-1:F[F[e>>2]+(d<<2)>>2])<<2)+b|0}F[b>>2]=F[b>>2]+c}c=a;b=F[F[a+156>>2]+(((f|0)==-1?-1:F[F[F[a+148>>2]>>2]+(f<<2)>>2])<<2)>>2];d=F[a+180>>2];a=F[a+176>>2];F[c+172>>2]=(a|0)<=(b|0)?((b|0)<(d|0)?b:d)-a|0:0}function Dg(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;a:{b=F[a+32>>2];f=F[b+8>>2];h=F[b+12>>2];g=F[b+20>>2];c=F[b+16>>2];e=0;b:{if((h|0)<=(g|0)&c>>>0>=f>>>0|(g|0)>(h|0)){break b}f=G[F[b>>2]+c|0];e=b;b=g;c=c+1|0;b=c?b:b+1|0;F[e+16>>2]=c;F[e+20>>2]=b;c:{if(!f){break c}while(1){if($[F[F[a>>2]+16>>2]](a,d)|0){d=d+1|0;if((f|0)!=(d|0)){continue}break c}break}return 0}d=F[a+8>>2];b=F[a+12>>2];if((d|0)!=(b|0)){while(1){c=F[d>>2];if(!($[F[F[c>>2]+8>>2]](c,a,F[a+4>>2])|0)){break a}d=d+4|0;if((b|0)!=(d|0)){continue}break}}d:{if(!f){break d}d=0;while(1){b=F[F[a+8>>2]+(d<<2)>>2];if(!($[F[F[b>>2]+12>>2]](b,F[a+32>>2])|0)){break a}d=d+1|0;if((f|0)!=(d|0)){continue}break}if(!f){break d}i=a+20|0;b=0;while(1){d=0;j=b<<2;c=F[j+F[a+8>>2]>>2];k=$[F[F[c>>2]+24>>2]](c)|0;if((k|0)>0){while(1){c=F[F[a+8>>2]+j>>2];c=$[F[F[c>>2]+20>>2]](c,d)|0;e=F[a+20>>2];g=F[a+24>>2]-e>>2;e:{if(c>>>0>>0){break e}h=c+1|0;if(h>>>0>g>>>0){qa(i,h-g|0);e=F[i>>2];break e}if(g>>>0<=h>>>0){break e}F[a+24>>2]=(h<<2)+e}F[(c<<2)+e>>2]=b;d=d+1|0;if((k|0)!=(d|0)){continue}break}}b=b+1|0;if((f|0)!=(b|0)){continue}break}}e=0;if(!($[F[F[a>>2]+28>>2]](a)|0)){break b}e=$[F[F[a>>2]+32>>2]](a)|0}return e|0}return 0}function Ye(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;Oc(a,b,c);c=F[a+84>>2];d=F[a+88>>2]-c>>2;a:{if((d|0)>(b|0)){break a}b=b+1|0;if(b>>>0>d>>>0){b:{d=b-d|0;e=F[a+92>>2];c=F[a+88>>2];if(d>>>0<=e-c>>2>>>0){c:{if(!d){break c}b=c;e=d&7;if(e){while(1){F[b>>2]=1;b=b+4|0;f=f+1|0;if((e|0)!=(f|0)){continue}break}}c=(d<<2)+c|0;if((d-1&1073741823)>>>0<7){break c}while(1){F[b+24>>2]=1;F[b+28>>2]=1;F[b+16>>2]=1;F[b+20>>2]=1;F[b+8>>2]=1;F[b+12>>2]=1;F[b>>2]=1;F[b+4>>2]=1;b=b+32|0;if((c|0)!=(b|0)){continue}break}}F[a+88>>2]=c;break b}d:{b=c;c=F[a+84>>2];i=b-c|0;g=i>>2;b=g+d|0;if(b>>>0<1073741824){e=e-c|0;h=e>>>1|0;e=e>>>0>=2147483644?1073741823:b>>>0>>0?h:b;if(e){if(e>>>0>=1073741824){break d}j=ka(e<<2)}g=(g<<2)+j|0;b=g;h=d&7;if(h){while(1){F[b>>2]=1;b=b+4|0;f=f+1|0;if((h|0)!=(f|0)){continue}break}}f=g+(d<<2)|0;if((d-1&1073741823)>>>0>=7){while(1){F[b+24>>2]=1;F[b+28>>2]=1;F[b+16>>2]=1;F[b+20>>2]=1;F[b+8>>2]=1;F[b+12>>2]=1;F[b>>2]=1;F[b+4>>2]=1;b=b+32|0;if((f|0)!=(b|0)){continue}break}}b=pa(j,c,i);F[a+88>>2]=f;F[a+84>>2]=b;F[a+92>>2]=b+(e<<2);if(c){ja(c)}break b}na();v()}oa();v()}return}if(b>>>0>=d>>>0){break a}F[a+88>>2]=c+(b<<2)}}function ab(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=F[a+8>>2];e=F[a+4>>2];if(d-e>>2>>>0>=b>>>0){a:{if(!b){break a}d=e;g=b&7;if(g){while(1){F[d>>2]=F[c>>2];d=d+4|0;f=f+1|0;if((g|0)!=(f|0)){continue}break}}e=(b<<2)+e|0;if((b-1&1073741823)>>>0<7){break a}while(1){F[d>>2]=F[c>>2];F[d+4>>2]=F[c>>2];F[d+8>>2]=F[c>>2];F[d+12>>2]=F[c>>2];F[d+16>>2]=F[c>>2];F[d+20>>2]=F[c>>2];F[d+24>>2]=F[c>>2];F[d+28>>2]=F[c>>2];d=d+32|0;if((e|0)!=(d|0)){continue}break}}F[a+4>>2]=e;return}b:{i=F[a>>2];f=e-i>>2;h=f+b|0;if(h>>>0<1073741824){j=d-i|0;d=j>>>1|0;h=j>>>0>=2147483644?1073741823:d>>>0>h>>>0?d:h;if(h){if(h>>>0>=1073741824){break b}k=ka(h<<2)}f=(f<<2)+k|0;d=f;j=b&7;if(j){while(1){F[d>>2]=F[c>>2];d=d+4|0;g=g+1|0;if((j|0)!=(g|0)){continue}break}}g=(b<<2)+f|0;if((b-1&1073741823)>>>0>=7){while(1){F[d>>2]=F[c>>2];F[d+4>>2]=F[c>>2];F[d+8>>2]=F[c>>2];F[d+12>>2]=F[c>>2];F[d+16>>2]=F[c>>2];F[d+20>>2]=F[c>>2];F[d+24>>2]=F[c>>2];F[d+28>>2]=F[c>>2];d=d+32|0;if((g|0)!=(d|0)){continue}break}}if((e|0)!=(i|0)){while(1){f=f-4|0;e=e-4|0;F[f>>2]=F[e>>2];if((e|0)!=(i|0)){continue}break}}F[a+8>>2]=(h<<2)+k;F[a+4>>2]=g;F[a>>2]=f;if(i){ja(i)}return}na();v()}oa();v()}function Xb(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=F[a+8>>2];e=F[a>>2];if(d-e>>2>>>0>=b>>>0){f=F[a+4>>2];h=f-e>>2;i=b>>>0>h>>>0?h:b;a:{if(!i){break a}d=e;g=i;j=g&7;if(j){while(1){F[d>>2]=F[c>>2];g=g-1|0;d=d+4|0;k=k+1|0;if((k|0)!=(j|0)){continue}break}}if(i>>>0<8){break a}while(1){F[d>>2]=F[c>>2];F[d+4>>2]=F[c>>2];F[d+8>>2]=F[c>>2];F[d+12>>2]=F[c>>2];F[d+16>>2]=F[c>>2];F[d+20>>2]=F[c>>2];F[d+24>>2]=F[c>>2];F[d+28>>2]=F[c>>2];d=d+32|0;g=g-8|0;if(g){continue}break}}if(b>>>0>h>>>0){b=(b-h<<2)+f|0;while(1){F[f>>2]=F[c>>2];f=f+4|0;if((b|0)!=(f|0)){continue}break}F[a+4>>2]=b;return}F[a+4>>2]=e+(b<<2);return}if(e){F[a+4>>2]=e;ja(e);F[a+8>>2]=0;F[a>>2]=0;F[a+4>>2]=0;d=0}b:{if(b>>>0>=1073741824){break b}e=d>>>1|0;d=d>>>0>=2147483644?1073741823:b>>>0>>0?e:b;if(d>>>0>=1073741824){break b}d=d<<2;e=ka(d);F[a>>2]=e;F[a+8>>2]=d+e;c=F[c>>2];d=e;g=b&7;if(g){while(1){F[d>>2]=c;d=d+4|0;f=f+1|0;if((g|0)!=(f|0)){continue}break}}e=e+(b<<2)|0;if((b-1&1073741823)>>>0>=7){while(1){F[d+28>>2]=c;F[d+24>>2]=c;F[d+20>>2]=c;F[d+16>>2]=c;F[d+12>>2]=c;F[d+8>>2]=c;F[d+4>>2]=c;F[d>>2]=c;d=d+32|0;if((e|0)!=(d|0)){continue}break}}F[a+4>>2]=e;return}na();v()}function Ka(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;f=(c>>>0)/3|0;j=F[(F[F[a+8>>2]+96>>2]+L(f,12)|0)+(c-L(f,3)<<2)>>2];a:{h=F[F[a+12>>2]+4>>2];e=F[h+4>>2];if((e|0)!=F[h+8>>2]){F[e>>2]=j;F[h+4>>2]=e+4;break a}b:{i=F[h>>2];f=e-i|0;g=f>>2;d=g+1|0;if(d>>>0<1073741824){k=g<<2;g=f>>>1|0;g=f>>>0>=2147483644?1073741823:d>>>0>>0?g:d;if(g){if(g>>>0>=1073741824){break b}f=ka(g<<2)}else{f=0}d=k+f|0;F[d>>2]=j;j=d+4|0;if((e|0)!=(i|0)){while(1){d=d-4|0;e=e-4|0;F[d>>2]=F[e>>2];if((e|0)!=(i|0)){continue}break}}F[h+8>>2]=f+(g<<2);F[h+4>>2]=j;F[h>>2]=d;if(i){ja(i)}break a}na();v()}oa();v()}c:{d:{h=F[a+4>>2];e=F[h+4>>2];e:{if((e|0)!=F[h+8>>2]){F[e>>2]=c;F[h+4>>2]=e+4;break e}i=F[h>>2];f=e-i|0;j=f>>2;d=j+1|0;if(d>>>0>=1073741824){break d}g=f>>>1|0;g=f>>>0>=2147483644?1073741823:d>>>0>>0?g:d;if(g){if(g>>>0>=1073741824){break c}f=ka(g<<2)}else{f=0}d=f+(j<<2)|0;F[d>>2]=c;c=d+4|0;if((e|0)!=(i|0)){while(1){d=d-4|0;e=e-4|0;F[d>>2]=F[e>>2];if((e|0)!=(i|0)){continue}break}}F[h+8>>2]=f+(g<<2);F[h+4>>2]=c;F[h>>2]=d;if(!i){break e}ja(i)}a=F[a+4>>2];F[F[a+12>>2]+(b<<2)>>2]=F[a+24>>2];F[a+24>>2]=F[a+24>>2]+1;return}na();v()}oa();v()}function pb(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0;h=d-c|0;if((h|0)<=0){return}a:{e=F[a+8>>2];i=F[a+4>>2];if((e-i|0)>=(h|0)){j=i-b|0;if((j|0)>=(h|0)){f=i;g=d;break a}f=i;g=c+j|0;if((g|0)!=(d|0)){e=g;while(1){D[f|0]=G[e|0];f=f+1|0;e=e+1|0;if((e|0)!=(d|0)){continue}break}}F[a+4>>2]=f;if((j|0)>0){break a}return}k=F[a>>2];g=(i-k|0)+h|0;if((g|0)>=0){j=b-k|0;f=e-k|0;e=f<<1;f=f>>>0>=1073741823?2147483647:e>>>0>g>>>0?e:g;if(f){e=ka(f)}else{e=0}g=j+e|0;if((c|0)!=(d|0)){g=la(g,c,h)+h|0}d=pa(e,k,j);c=i-b|0;b=pa(g,b,c);F[a+8>>2]=e+f;F[a+4>>2]=b+c;F[a>>2]=d;if(k){ja(k)}return}na();v()}e=f;d=e-h|0;if(i>>>0>d>>>0){while(1){D[e|0]=G[d|0];e=e+1|0;d=d+1|0;if(i>>>0>d>>>0){continue}break}}F[a+4>>2]=e;a=b+h|0;if((a|0)!=(f|0)){a=f-a|0;pa(f-a|0,b,a)}if((c|0)==(g|0)){return}f=(c^-1)+g|0;a=g-c&7;b:{if(!a){e=b;break b}d=0;e=b;while(1){D[e|0]=G[c|0];e=e+1|0;c=c+1|0;d=d+1|0;if((a|0)!=(d|0)){continue}break}}if(f>>>0<7){return}while(1){D[e|0]=G[c|0];D[e+1|0]=G[c+1|0];D[e+2|0]=G[c+2|0];D[e+3|0]=G[c+3|0];D[e+4|0]=G[c+4|0];D[e+5|0]=G[c+5|0];D[e+6|0]=G[c+6|0];D[e+7|0]=G[c+7|0];e=e+8|0;c=c+8|0;if((g|0)!=(c|0)){continue}break}}function la(a,b,c){var d=0,e=0,f=0;if(c>>>0>=512){Y(a|0,b|0,c|0);return a}e=a+c|0;a:{if(!((a^b)&3)){b:{if(!(a&3)){c=a;break b}if(!c){c=a;break b}c=a;while(1){D[c|0]=G[b|0];b=b+1|0;c=c+1|0;if(!(c&3)){break b}if(c>>>0>>0){continue}break}}d=e&-4;c:{if(d>>>0<64){break c}f=d+-64|0;if(f>>>0>>0){break c}while(1){F[c>>2]=F[b>>2];F[c+4>>2]=F[b+4>>2];F[c+8>>2]=F[b+8>>2];F[c+12>>2]=F[b+12>>2];F[c+16>>2]=F[b+16>>2];F[c+20>>2]=F[b+20>>2];F[c+24>>2]=F[b+24>>2];F[c+28>>2]=F[b+28>>2];F[c+32>>2]=F[b+32>>2];F[c+36>>2]=F[b+36>>2];F[c+40>>2]=F[b+40>>2];F[c+44>>2]=F[b+44>>2];F[c+48>>2]=F[b+48>>2];F[c+52>>2]=F[b+52>>2];F[c+56>>2]=F[b+56>>2];F[c+60>>2]=F[b+60>>2];b=b- -64|0;c=c- -64|0;if(f>>>0>=c>>>0){continue}break}}if(c>>>0>=d>>>0){break a}while(1){F[c>>2]=F[b>>2];b=b+4|0;c=c+4|0;if(d>>>0>c>>>0){continue}break}break a}if(e>>>0<4){c=a;break a}d=e-4|0;if(d>>>0>>0){c=a;break a}c=a;while(1){D[c|0]=G[b|0];D[c+1|0]=G[b+1|0];D[c+2|0]=G[b+2|0];D[c+3|0]=G[b+3|0];b=b+4|0;c=c+4|0;if(d>>>0>=c>>>0){continue}break}}if(c>>>0>>0){while(1){D[c|0]=G[b|0];b=b+1|0;c=c+1|0;if((e|0)!=(c|0)){continue}break}}return a}function sd(a){a=a|0;var b=0,c=0,d=0,e=0,f=0;F[a>>2]=8336;d=a+232|0;b=F[d+196>>2];if(b){F[d+200>>2]=b;ja(b)}c=F[d+184>>2];if(c){b=c;e=F[d+188>>2];if((b|0)!=(e|0)){while(1){b=e-12|0;f=F[b>>2];if(f){F[e-8>>2]=f;ja(f)}e=b;if((b|0)!=(c|0)){continue}break}b=F[d+184>>2]}F[d+188>>2]=c;ja(b)}b=F[d+156>>2];if(b){F[d+160>>2]=b;ja(b)}c=F[d+136>>2];F[d+136>>2]=0;if(c){e=c-4|0;b=F[e>>2];if(b){b=c+(b<<4)|0;while(1){b=b-16|0;if((c|0)!=(b|0)){continue}break}}ja(e)}td(a+216|0);b=F[a+196>>2];if(b){F[a+200>>2]=b;ja(b)}b=F[a+184>>2];if(b){F[a+188>>2]=b;ja(b)}b=F[a+172>>2];if(b){F[a+176>>2]=b;ja(b)}b=F[a+160>>2];if(b){F[a+164>>2]=b;ja(b)}b=F[a+144>>2];if(b){while(1){c=F[b>>2];ja(b);b=c;if(b){continue}break}}b=F[a+136>>2];F[a+136>>2]=0;if(b){ja(b)}b=F[a+120>>2];if(b){ja(b)}b=F[a+108>>2];if(b){ja(b)}b=F[a+96>>2];if(b){ja(b)}b=F[a+72>>2];if(b){F[a+76>>2]=b;ja(b)}b=F[a+60>>2];if(b){ja(b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}b=F[a+36>>2];if(b){F[a+40>>2]=b;ja(b)}b=F[a+24>>2];if(b){F[a+28>>2]=b;ja(b)}b=F[a+12>>2];if(b){F[a+16>>2]=b;ja(b)}b=F[a+8>>2];F[a+8>>2]=0;if(b){Za(b)}return a|0}function Fa(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;d=F[a+8>>2];e=F[a+4>>2];if(d-e>>2>>>0>=b>>>0){a:{if(!b){break a}d=e;f=b&7;if(f){while(1){F[d>>2]=F[c>>2];d=d+4|0;h=h+1|0;if((f|0)!=(h|0)){continue}break}}e=(b<<2)+e|0;if((b-1&1073741823)>>>0<7){break a}while(1){F[d>>2]=F[c>>2];F[d+4>>2]=F[c>>2];F[d+8>>2]=F[c>>2];F[d+12>>2]=F[c>>2];F[d+16>>2]=F[c>>2];F[d+20>>2]=F[c>>2];F[d+24>>2]=F[c>>2];F[d+28>>2]=F[c>>2];d=d+32|0;if((e|0)!=(d|0)){continue}break}}F[a+4>>2]=e;return}b:{i=F[a>>2];j=e-i|0;f=j>>2;g=f+b|0;if(g>>>0<1073741824){d=d-i|0;e=d>>>1|0;g=d>>>0>=2147483644?1073741823:e>>>0>g>>>0?e:g;if(g){if(g>>>0>=1073741824){break b}k=ka(g<<2)}f=(f<<2)+k|0;d=f;e=b&7;if(e){while(1){F[d>>2]=F[c>>2];d=d+4|0;h=h+1|0;if((e|0)!=(h|0)){continue}break}}e=f+(b<<2)|0;if((b-1&1073741823)>>>0>=7){while(1){F[d>>2]=F[c>>2];F[d+4>>2]=F[c>>2];F[d+8>>2]=F[c>>2];F[d+12>>2]=F[c>>2];F[d+16>>2]=F[c>>2];F[d+20>>2]=F[c>>2];F[d+24>>2]=F[c>>2];F[d+28>>2]=F[c>>2];d=d+32|0;if((e|0)!=(d|0)){continue}break}}b=pa(k,i,j);F[a+4>>2]=e;F[a>>2]=b;F[a+8>>2]=b+(g<<2);if(i){ja(i)}return}na();v()}oa();v()}function Sb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;if(G[a+11|0]>>>7|0){d=F[a+4>>2]}else{d=G[a+11|0]&127}if(d>>>0>>0){h=Z-16|0;Z=h;b=b-d|0;if(b){g=G[a+11|0]>>>7|0?(F[a+8>>2]&2147483647)-1|0:10;if(G[a+11|0]>>>7|0){d=F[a+4>>2]}else{d=G[a+11|0]&127}i=d+b|0;if(g-d>>>0>>0){a:{e=Z-16|0;Z=e;c=i-g|0;if(c>>>0<=2147483631-g>>>0){if(G[a+11|0]>>>7|0){f=F[a>>2]}else{f=a}if(g>>>0<1073741799){F[e+12>>2]=g<<1;F[e>>2]=c+g;c=Z-16|0;Z=c;Z=c+16|0;c=e+12|0;c=F[(I[e>>2]>2]?c:e)>>2];if(c>>>0>=11){j=c+16&-16;c=j-1|0;c=(c|0)==11?j:c}else{c=10}c=c+1|0}else{c=2147483631}sb(e,c);c=F[e>>2];if(d){db(c,f,d)}if((g|0)!=10){ja(f)}F[a>>2]=c;F[a+8>>2]=F[a+8>>2]&-2147483648|F[e+4>>2]&2147483647;F[a+8>>2]=F[a+8>>2]|-2147483648;Z=e+16|0;break a}za();v()}}f=d;if(G[a+11|0]>>>7|0){d=F[a>>2]}else{d=a}f=f+d|0;e=Z-16|0;Z=e;D[e+15|0]=0;while(1){if(b){D[f|0]=G[e+15|0];b=b-1|0;f=f+1|0;continue}break}Z=e+16|0;Ic(a,i);D[h+15|0]=0;D[d+i|0]=G[h+15|0]}Z=h+16|0;return}if(G[a+11|0]>>>7|0){d=F[a>>2]}else{d=a}f=Z-16|0;Z=f;Ic(a,b);D[f+15|0]=0;D[b+d|0]=G[f+15|0];Z=f+16|0}function Zc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;g=Z-16|0;Z=g;a:{b:{if(b){F[a+88>>2]=0;F[a+92>>2]=0;d=F[a+84>>2];F[a+84>>2]=0;if(d){ja(d)}F[a+76>>2]=0;F[a+80>>2]=0;d=F[a+72>>2];F[a+72>>2]=0;if(d){ja(d)}d=F[b>>2];c=F[b+4>>2];D[g+15|0]=0;Ea(a,c-d>>2,g+15|0);d=F[b+28>>2];c=F[b+24>>2];D[g+14|0]=0;Ea(a+12|0,d-c>>2,g+14|0);Xb(a+28|0,F[b+4>>2]-F[b>>2]>>2,10284);c=F[b+28>>2]-F[b+24>>2]|0;f=c>>2;e=F[a+52>>2];c:{if(f>>>0<=F[a+60>>2]-e>>2>>>0){break c}if((c|0)<0){break b}d=F[a+56>>2];c=ka(c);f=c+(f<<2)|0;h=c+(d-e&-4)|0;c=h;if((d|0)!=(e|0)){while(1){c=c-4|0;d=d-4|0;F[c>>2]=F[d>>2];if((d|0)!=(e|0)){continue}break}}F[a+60>>2]=f;F[a+56>>2]=h;F[a+52>>2]=c;if(!e){break c}ja(e)}c=F[b+28>>2]-F[b+24>>2]|0;f=c>>2;e=F[a+40>>2];d:{if(f>>>0<=F[a+48>>2]-e>>2>>>0){break d}if((c|0)<0){break a}d=F[a+44>>2];c=ka(c);f=c+(f<<2)|0;h=c+(d-e&-4)|0;c=h;if((d|0)!=(e|0)){while(1){c=c-4|0;d=d-4|0;F[c>>2]=F[d>>2];if((d|0)!=(e|0)){continue}break}}F[a+48>>2]=f;F[a+44>>2]=h;F[a+40>>2]=c;if(!e){break d}ja(e)}D[a+24|0]=1;F[a+64>>2]=b}Z=g+16|0;return}na();v()}na();v()}function nb(a,b){var c=0,d=0,e=0;c=(a|0)==(b|0);D[b+12|0]=c;a:{if(c){break a}while(1){d=F[b+8>>2];if(G[d+12|0]){break a}b:{c=F[d+8>>2];e=F[c>>2];if((e|0)==(d|0)){e=F[c+4>>2];if(!(!e|G[e+12|0])){break b}c:{if(F[d>>2]==(b|0)){b=d;break c}b=F[d+4>>2];a=F[b>>2];F[d+4>>2]=a;if(a){F[a+8>>2]=d;c=F[d+8>>2]}F[b+8>>2]=c;a=F[d+8>>2];F[((F[a>>2]!=(d|0))<<2)+a>>2]=b;F[b>>2]=d;F[d+8>>2]=b;c=F[b+8>>2];d=F[c>>2]}D[b+12|0]=1;D[c+12|0]=0;a=F[d+4>>2];F[c>>2]=a;if(a){F[a+8>>2]=c}F[d+8>>2]=F[c+8>>2];a=F[c+8>>2];F[((F[a>>2]!=(c|0))<<2)+a>>2]=d;F[d+4>>2]=c;F[c+8>>2]=d;return}if(!(G[e+12|0]|!e)){break b}d:{if(F[d>>2]!=(b|0)){b=d;break d}a=F[b+4>>2];F[d>>2]=a;if(a){F[a+8>>2]=d;c=F[d+8>>2]}F[b+8>>2]=c;a=F[d+8>>2];F[((F[a>>2]!=(d|0))<<2)+a>>2]=b;F[b+4>>2]=d;F[d+8>>2]=b;c=F[b+8>>2]}D[b+12|0]=1;D[c+12|0]=0;a=F[c+4>>2];b=F[a>>2];F[c+4>>2]=b;if(b){F[b+8>>2]=c}F[a+8>>2]=F[c+8>>2];b=F[c+8>>2];F[((F[b>>2]!=(c|0))<<2)+b>>2]=a;F[a>>2]=c;F[c+8>>2]=a;break a}D[d+12|0]=1;D[c+12|0]=(a|0)==(c|0);D[e+12|0]=1;b=c;if((c|0)!=(a|0)){continue}break}}}function mi(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{if(b){if(!c){break k}if(!d){break j}e=O(d)-O(b)|0;if(e>>>0<=31){break i}break c}if((d|0)==1|d>>>0>1){break c}_=0;a=(a>>>0)/(c>>>0)|0;break a}if(!a){break h}if(!d|d-1&d){break g}a=b>>>ji(d)|0;_=0;break a}if(!(c-1&c)){break f}h=(O(c)+33|0)-O(b)|0;g=0-h|0;break d}h=e+1|0;g=63-e|0;break d}_=0;a=(b>>>0)/(d>>>0)|0;break a}e=O(d)-O(b)|0;if(e>>>0<31){break e}break c}if((c|0)==1){break b}d=ji(c);c=d&31;if((d&63)>>>0>=32){a=b>>>c|0}else{e=b>>>c|0;a=((1<>>c}_=e;break a}h=e+1|0;g=63-e|0}e=h&63;f=e&31;if(e>>>0>=32){e=0;i=b>>>f|0}else{e=b>>>f|0;i=((1<>>f}g=g&63;f=g&31;if(g>>>0>=32){b=a<>>32-f|b<>>31;e=i<<1|b>>>31;f=m-(j+(e>>>0>g>>>0)|0)>>31;k=c&f;i=e-k|0;e=j-((d&f)+(e>>>0>>0)|0)|0;b=b<<1|a>>>31;a=l|a<<1;l=f&1;h=h-1|0;if(h){continue}break}}_=b<<1|a>>>31;a=l|a<<1;break a}a=0;b=0}_=b}return a}function yh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;c=F[b+88>>2];if(!(!c|F[c>>2]!=1)){e=F[c+8>>2];F[a+4>>2]=G[e|0]|G[e+1|0]<<8|(G[e+2|0]<<16|G[e+3|0]<<24);f=a+8|0;d=G[b+24|0];h=F[a+8>>2];g=F[a+12>>2]-h>>2;a:{if(d>>>0>g>>>0){qa(f,d-g|0);d=G[b+24|0];e=F[c+8>>2];break a}if(d>>>0>=g>>>0){break a}F[a+12>>2]=h+(d<<2)}b:{if(!d){b=4;break b}h=d&3;f=F[f>>2];c:{if(d-1>>>0<3){b=4;d=0;break c}k=d&252;d=0;b=4;while(1){g=d<<2;c=b+e|0;F[g+f>>2]=G[c|0]|G[c+1|0]<<8|(G[c+2|0]<<16|G[c+3|0]<<24);F[f+(g|4)>>2]=G[c+4|0]|G[c+5|0]<<8|(G[c+6|0]<<16|G[c+7|0]<<24);F[f+(g|8)>>2]=G[c+8|0]|G[c+9|0]<<8|(G[c+10|0]<<16|G[c+11|0]<<24);F[f+(g|12)>>2]=G[c+12|0]|G[c+13|0]<<8|(G[c+14|0]<<16|G[c+15|0]<<24);d=d+4|0;b=b+16|0;i=i+4|0;if((k|0)!=(i|0)){continue}break}}if(!h){break b}while(1){c=b+e|0;F[f+(d<<2)>>2]=G[c|0]|G[c+1|0]<<8|(G[c+2|0]<<16|G[c+3|0]<<24);d=d+1|0;b=b+4|0;j=j+1|0;if((h|0)!=(j|0)){continue}break}}d=a;a=b+e|0;F[d+20>>2]=G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24);d=1}return d|0}function Yg(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0,h=0;g=Z-16|0;Z=g;e=F[a+4>>2];d=F[e>>2];a:{b=F[a+12>>2];c=F[b+28>>2]-F[b+24>>2]|0;f=c>>2;b:{if(f>>>0<=F[e+8>>2]-d>>2>>>0){break b}if((c|0)<0){break a}b=F[e+4>>2];c=ka(c);f=c+(f<<2)|0;h=c+(b-d&-4)|0;c=h;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[e+8>>2]=f;F[e+4>>2]=h;F[e>>2]=c;if(!d){break b}ja(d)}b=F[a+12>>2];c=F[b+28>>2];b=F[b+24>>2];F[g+12>>2]=0;b=c-b>>2;d=a+96|0;e=F[d>>2];c=F[a+100>>2]-e>>2;c:{if(b>>>0>c>>>0){Fa(d,b-c|0,g+12|0);break c}if(b>>>0>=c>>>0){break c}F[a+100>>2]=e+(b<<2)}e=a+8|0;b=F[a+116>>2];d:{if(b){d=F[b>>2];if((d|0)==F[b+4>>2]){c=1;break d}b=0;while(1){c=rd(e,F[(b<<2)+d>>2]);if(!c){break d}f=F[a+116>>2];d=F[f>>2];b=b+1|0;if(b>>>0>2]-d>>2>>>0){continue}break}break d}c=1;a=F[a+12>>2];a=F[a+4>>2]-F[a>>2]|0;if(a>>>0<12){break d}a=(a>>2>>>0)/3|0;b=0;while(1){c=rd(e,L(b,3));if(!c){break d}b=b+1|0;if((a|0)!=(b|0)){continue}break}}Z=g+16|0;return c|0}na();v()}function md(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;a:{b:{c:{if(!b){if((d|0)<0){break a}f=F[a+4>>2];b=F[a>>2];d=f-b|0;if(c>>>0>d>>>0){g=c-d|0;e=F[a+8>>2];if(g>>>0<=e-f>>>0){i=a,j=ma(f,0,g)+g|0,F[i+4>>2]=j;break c}if((c|0)<0){break b}f=e-b|0;e=f<<1;f=f>>>0>=1073741823?2147483647:c>>>0>>0?e:c;e=ka(f);ma(e+d|0,0,g);d=pa(e,b,d);F[a+8>>2]=d+f;F[a+4>>2]=c+d;F[a>>2]=d;if(!b){break c}ja(b);break c}if(c>>>0>=d>>>0){break c}F[a+4>>2]=b+c;break c}if((d|0)<0){break a}e=F[a+4>>2];f=F[a>>2];g=e-f|0;d:{if((d|0)<=0&c>>>0<=g>>>0|(d|0)<0){break d}if(c>>>0>g>>>0){d=c-g|0;h=F[a+8>>2];if(d>>>0<=h-e>>>0){i=a,j=ma(e,0,d)+d|0,F[i+4>>2]=j;break d}if((c|0)<0){break b}e=h-f|0;h=e<<1;e=e>>>0>=1073741823?2147483647:c>>>0>>0?h:c;h=ka(e);ma(h+g|0,0,d);d=pa(h,f,g);F[a+8>>2]=d+e;F[a+4>>2]=c+d;F[a>>2]=d;if(!f){break d}ja(f);break d}if(c>>>0>=g>>>0){break d}F[a+4>>2]=c+f}if(!c){break c}pa(F[a>>2],b,c)}b=F[a+28>>2];c=F[a+24>>2]+1|0;b=c?b:b+1|0;F[a+24>>2]=c;F[a+28>>2]=b;g=1;break a}na();v()}return g}function Lg(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;k=F[a+12>>2];c=F[a+68>>2];d=F[c+80>>2];D[b+84|0]=0;n=b+68|0;i=F[b+68>>2];e=F[b+72>>2]-i>>2;a:{if(e>>>0>>0){ab(n,d-e|0,9124);c=F[a+68>>2];d=F[c+80>>2];break a}if(d>>>0>=e>>>0){break a}F[b+72>>2]=i+(d<<2)}b=F[c+100>>2];e=F[c+96>>2];i=(b-e|0)/12|0;m=1;b:{if((b|0)==(e|0)){break b}k=F[k+28>>2];f=F[k>>2];if((f|0)==-1){return 0}o=i>>>0<=1?1:i;c=e;b=0;m=0;while(1){g=F[c>>2];if(g>>>0>=d>>>0){break b}j=F[F[a+72>>2]+12>>2];h=F[j+(f<<2)>>2];if(h>>>0>=d>>>0){break b}f=F[n>>2];F[f+(g<<2)>>2]=h;g=k+(l<<2)|0;h=F[g+4>>2];if((h|0)==-1){break b}l=F[c+4>>2];if(l>>>0>=d>>>0){break b}h=F[(h<<2)+j>>2];if(h>>>0>=d>>>0){break b}F[f+(l<<2)>>2]=h;g=F[g+8>>2];if((g|0)==-1){break b}c=F[c+8>>2];if(c>>>0>=d>>>0){break b}j=F[(g<<2)+j>>2];if(j>>>0>=d>>>0){break b}F[f+(c<<2)>>2]=j;b=b+1|0;m=i>>>0<=b>>>0;if((b|0)==(o|0)){break b}c=e+L(b,12)|0;l=L(b,3);f=F[k+(l<<2)>>2];if((f|0)!=-1){continue}break}}return m|0}function ag(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;h=F[d+80>>2];e=Z-48|0;Z=e;a=F[a+4>>2];m=a-2|0;a:{if(m>>>0>28){break a}j=F[F[d>>2]>>2]+F[d+48>>2]|0;F[e+16>>2]=a;a=-1<>2]=a^-1;a=-2-a|0;F[e+24>>2]=a;F[e+32>>2]=(a|0)/2;J[e+28>>2]=M(2)/M(a|0);f=F[c>>2];if((f|0)!=F[c+4>>2]){a=0;d=0;while(1){g=F[(d<<2)+f>>2];h=e+36|0;k=F[F[b>>2]>>2];l=F[b+48>>2];f=F[b+40>>2];i=F[b+44>>2];if(!G[b+84|0]){g=F[F[b+68>>2]+(g<<2)>>2]}g=ki(f,i,g,0);i=g;g=g+l|0;la(h,g+k|0,f);Kc(e+16|0,h,e+12|0,e+8|0);f=a<<2;F[f+j>>2]=F[e+12>>2];F[(f|4)+j>>2]=F[e+8>>2];a=a+2|0;d=d+1|0;f=F[c>>2];if(d>>>0>2]-f>>2>>>0){continue}break}break a}if(!h){break a}d=0;a=0;while(1){k=e+36|0;l=F[F[b>>2]>>2];i=F[b+48>>2];c=F[b+40>>2];f=ki(c,F[b+44>>2],G[b+84|0]?a:F[F[b+68>>2]+(a<<2)>>2],0);g=f;f=f+i|0;la(k,f+l|0,c);Kc(e+16|0,k,e+12|0,e+8|0);c=d<<2;F[c+j>>2]=F[e+12>>2];F[(c|4)+j>>2]=F[e+8>>2];d=d+2|0;a=a+1|0;if((h|0)!=(a|0)){continue}break}}Z=e+48|0;return m>>>0<29|0}function Zg(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;c=F[a+12>>2];d=F[a+108>>2];e=F[d+80>>2];D[b+84|0]=0;m=b+68|0;h=F[b+68>>2];f=F[b+72>>2]-h>>2;a:{if(f>>>0>>0){ab(m,e-f|0,9124);d=F[a+108>>2];e=F[d+80>>2];break a}if(e>>>0>=f>>>0){break a}F[b+72>>2]=h+(e<<2)}b=F[d+100>>2];f=F[d+96>>2];h=(b-f|0)/12|0;k=1;b:{if((b|0)==(f|0)){break b}n=h>>>0<=1?1:h;o=F[c>>2];c=0;d=f;b=0;k=0;while(1){c=(c<<2)+o|0;i=F[c>>2];if((i|0)==-1){break b}g=F[d>>2];if(g>>>0>=e>>>0){break b}l=F[F[a+112>>2]+12>>2];j=F[l+(i<<2)>>2];if(j>>>0>=e>>>0){break b}i=F[m>>2];F[i+(g<<2)>>2]=j;g=F[c+4>>2];if((g|0)==-1){break b}j=F[d+4>>2];if(j>>>0>=e>>>0){break b}g=F[(g<<2)+l>>2];if(g>>>0>=e>>>0){break b}F[i+(j<<2)>>2]=g;c=F[c+8>>2];if((c|0)==-1){break b}d=F[d+8>>2];if(d>>>0>=e>>>0){break b}c=F[(c<<2)+l>>2];if(c>>>0>=e>>>0){break b}F[i+(d<<2)>>2]=c;b=b+1|0;k=h>>>0<=b>>>0;if((b|0)==(n|0)){break b}c=L(b,3);d=f+L(b,12)|0;if((b|0)!=1431655765){continue}break}}return k|0}function xd(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=M(0),j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0;k=Z-16|0;Z=k;if(F[c+28>>2]==9){d=F[a+4>>2];h=G[c+24|0];e=h<<2;f=ka(e);l=k+8|0;F[l>>2]=1065353216;i=J[a+20>>2];d=-1<0){J[l>>2]=i/M(d|0)}o=(d|0)>0;a:{if(!o){break a}j=F[c+80>>2];if(!j){break a}if(h){p=F[F[b>>2]>>2]+F[b+48>>2]|0;t=h&254;u=h&1;b=0;while(1){m=F[a+8>>2];i=J[l>>2];d=0;n=0;if((h|0)!=1){while(1){g=d<<2;q=(b<<2)+p|0;J[g+f>>2]=M(i*M(F[q>>2]))+J[g+m>>2];g=g|4;J[g+f>>2]=M(i*M(F[q+4>>2]))+J[g+m>>2];d=d+2|0;b=b+2|0;n=n+2|0;if((t|0)!=(n|0)){continue}break}}if(u){d=d<<2;J[d+f>>2]=M(i*M(F[(b<<2)+p>>2]))+J[d+m>>2];b=b+1|0}la(F[F[c+64>>2]>>2]+r|0,f,e);r=e+r|0;s=s+1|0;if((s|0)!=(j|0)){continue}break}break a}b=0;if((j|0)!=1){a=j&-2;d=0;while(1){la(F[F[c+64>>2]>>2]+b|0,f,e);b=b+e|0;la(b+F[F[c+64>>2]>>2]|0,f,e);b=b+e|0;d=d+2|0;if((a|0)!=(d|0)){continue}break}}if(!(j&1)){break a}la(F[F[c+64>>2]>>2]+b|0,f,e)}ja(f)}Z=k+16|0;return o|0}function Rg(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0;c=F[a+12>>2];d=F[a+68>>2];e=F[d+80>>2];D[b+84|0]=0;m=b+68|0;h=F[b+68>>2];f=F[b+72>>2]-h>>2;a:{if(f>>>0>>0){ab(m,e-f|0,9124);d=F[a+68>>2];e=F[d+80>>2];break a}if(e>>>0>=f>>>0){break a}F[b+72>>2]=h+(e<<2)}b=F[d+100>>2];f=F[d+96>>2];h=(b-f|0)/12|0;k=1;b:{if((b|0)==(f|0)){break b}n=h>>>0<=1?1:h;o=F[c>>2];c=0;d=f;b=0;k=0;while(1){c=(c<<2)+o|0;i=F[c>>2];if((i|0)==-1){break b}g=F[d>>2];if(g>>>0>=e>>>0){break b}l=F[F[a+72>>2]+12>>2];j=F[l+(i<<2)>>2];if(j>>>0>=e>>>0){break b}i=F[m>>2];F[i+(g<<2)>>2]=j;g=F[c+4>>2];if((g|0)==-1){break b}j=F[d+4>>2];if(j>>>0>=e>>>0){break b}g=F[(g<<2)+l>>2];if(g>>>0>=e>>>0){break b}F[i+(j<<2)>>2]=g;c=F[c+8>>2];if((c|0)==-1){break b}d=F[d+8>>2];if(d>>>0>=e>>>0){break b}c=F[(c<<2)+l>>2];if(c>>>0>=e>>>0){break b}F[i+(d<<2)>>2]=c;b=b+1|0;k=h>>>0<=b>>>0;if((b|0)==(n|0)){break b}c=L(b,3);d=f+L(b,12)|0;if((b|0)!=1431655765){continue}break}}return k|0}function Na(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;d=Z-16|0;Z=d;a:{f=F[a+4>>2];b:{if(f>>>0>>0){e=b-f|0;c=F[a+8>>2];g=c<<5;c:{if(!(e>>>0>g>>>0|f>>>0>g-e>>>0)){F[a+4>>2]=b;h=f&31;b=F[a>>2]+(f>>>3&536870908)|0;break c}F[d+8>>2]=0;F[d>>2]=0;F[d+4>>2]=0;if((b|0)<0){break a}if(g>>>0<=1073741822){c=c<<6;b=b+31&-32;b=b>>>0>>0?c:b}else{b=2147483647}$a(d,b);f=F[a+4>>2];F[d+4>>2]=f+e;i=F[a>>2];b=F[d>>2];d:{if((f|0)<=0){break d}c=f>>>5|0;if(f>>>0>=32){pa(b,i,c<<2)}g=c<<2;b=g+b|0;h=f&31;if(h){c=-1>>>32-h|0;F[b>>2]=F[b>>2]&(c^-1)|F[i+g>>2]&c}i=F[a>>2]}F[a>>2]=F[d>>2];F[d>>2]=i;c=F[a+4>>2];F[a+4>>2]=F[d+4>>2];F[d+4>>2]=c;c=F[a+8>>2];F[a+8>>2]=F[d+8>>2];F[d+8>>2]=c;if(!i){break c}ja(i)}if(!e){break b}if(h){c=32-h|0;a=c>>>0>>0?c:e;F[b>>2]=F[b>>2]&(-1<>>c-a^-1);e=e-a|0;b=b+4|0}a=e>>>5|0;if(e>>>0>=32){ma(b,0,a<<2)}if((e&-32)==(e|0)){break b}a=(a<<2)+b|0;F[a>>2]=F[a>>2]&(-1>>>32-(e&31)^-1);break b}F[a+4>>2]=b}Z=d+16|0;return}na();v()}function Aa(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0;i=Z-16|0;Z=i;f=F[b+20>>2];h=F[b+12>>2];c=F[b+16>>2];a:{if((f|0)>=(h|0)&c>>>0>=I[b+8>>2]|(f|0)>(h|0)){break a}D[a+12|0]=G[c+F[b>>2]|0];c=F[b+20>>2];f=F[b+16>>2]+1|0;c=f?c:c+1|0;F[b+16>>2]=f;F[b+20>>2]=c;if(!Qd(1,i+12|0,b)){break a}h=F[b+8>>2];f=F[b+16>>2];g=h-f|0;c=F[i+12>>2];d=f>>>0>h>>>0;h=F[b+20>>2];e=F[b+12>>2]-(d+h|0)|0;if(g>>>0>>0&(e|0)<=0|(e|0)<0|(c|0)<=0){break a}g=f+F[b>>2]|0;F[a>>2]=g;b:{c:{e=c-1|0;j=e+g|0;d=G[j|0];d:{if(d>>>0<=63){F[a+4>>2]=e;d=G[j|0]&63;break d}e:{switch((d>>>6|0)-1|0){case 1:break c;case 0:break e;default:break a}}if(c>>>0<2){break a}e=c-2|0;F[a+4>>2]=e;g=g+e|0;d=G[g+1|0]<<8&16128|G[g|0]}F[a+8>>2]=d+4096;break b}if(c>>>0<3){break a}e=c-3|0;F[a+4>>2]=e;d=a;a=g+e|0;a=G[a+1|0]<<8|G[a+2|0]<<16&4128768|G[a|0];F[d+8>>2]=a+4096;if(a>>>0>1044479){break a}}a=h;d=c;c=c+f|0;a=d>>>0>c>>>0?a+1|0:a;F[b+16>>2]=c;F[b+20>>2]=a;k=1}Z=i+16|0;return k}function qd(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;e=F[a+12>>2];i=F[a+8>>2];d=e-i>>2;b=G[b+24|0];a:{if(d>>>0>>0){qa(a+8|0,b-d|0);i=F[a+8>>2];e=F[a+12>>2];break a}if(b>>>0>=d>>>0){break a}e=(b<<2)+i|0;F[a+12>>2]=e}b=0;f=F[c+8>>2];h=F[c+12>>2];j=F[c+20>>2];e=e-i|0;d=F[c+16>>2];g=e+d|0;j=e>>>0>g>>>0?j+1|0:j;b:{if(f>>>0>>0&(h|0)<=(j|0)|(h|0)<(j|0)){break b}la(i,d+F[c>>2]|0,e);d=F[c+20>>2];g=e;e=e+F[c+16>>2]|0;d=g>>>0>e>>>0?d+1|0:d;F[c+16>>2]=e;F[c+20>>2]=d;f=F[c+8>>2];h=F[c+12>>2];g=e+4|0;d=g>>>0<4?d+1|0:d;if(f>>>0>>0&(d|0)>=(h|0)|(d|0)>(h|0)){break b}d=e+F[c>>2]|0;F[a+20>>2]=G[d|0]|G[d+1|0]<<8|(G[d+2|0]<<16|G[d+3|0]<<24);d=F[c+20>>2];g=d;f=d;e=F[c+16>>2];d=e+4|0;f=d>>>0<4?f+1|0:f;F[c+16>>2]=d;F[c+20>>2]=f;h=F[c+12>>2];if((f|0)>=(h|0)&d>>>0>=I[c+8>>2]|(f|0)>(h|0)){break b}f=G[d+F[c>>2]|0];d=g;e=e+5|0;d=e>>>0<5?d+1|0:d;F[c+16>>2]=e;F[c+20>>2]=d;if(f-1>>>0>29){break b}F[a+4>>2]=f;b=1}return b|0}function Kc(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;j=+J[b>>2];k=+J[b+4>>2];l=+J[b+8>>2];g=N(j)+N(k)+N(l);a:{if(!(g>1e-6)){j=1;k=0;e=0;break a}g=1/g;k=g*k;j=g*j;e=g*l<0}h=F[a+16>>2];l=+(h|0);g=R(j*l+.5);b:{if(N(g)<2147483648){m=~~g;break b}m=-2147483648}f=m>>31;i=(f^m)-f|0;g=R(k*l+.5);c:{if(N(g)<2147483648){f=~~g;break c}f=-2147483648}b=f>>31;b=h-(i+((f^b)-b|0)|0)|0;i=(b|0)>0?b:0;e=e?0-i|0:i;f=f+(b>>31&((f|0)>0?b:0-b|0))|0;d:{if((m|0)>=0){b=e+h|0;a=F[a+8>>2];e=h+f|0;break d}b=f>>31;b=(b^f)-b|0;a=F[a+8>>2];b=(e|0)<0?b:a-b|0;e=(f|0)<0?i:a-i|0}e:{if(!(b|e)){b=a;break e}if(!((a|0)!=(b|0)|e)){b=a;break e}if(!((a|0)!=(e|0)|b)){b=a;break e}if(!((b|0)<=(h|0)|e)){b=(h<<1)-b|0;a=0;break e}if(!((a|0)!=(e|0)|(b|0)>=(h|0))){b=(h<<1)-b|0;break e}if(!((a|0)!=(b|0)|(e|0)>=(h|0))){b=a;a=(h<<1)-e|0;break e}if(b){a=e;break e}b=0;if((e|0)<=(h|0)){a=e;break e}a=(h<<1)-e|0}F[c>>2]=a;F[d>>2]=b}function ye(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0;a:{if(!$c(a,b)){break a}h=a+36|0;g=$[F[F[a>>2]+24>>2]](a)|0;e=F[a+40>>2];d=F[a+36>>2];c=e-d>>2;b:{if(g>>>0>c>>>0){Pb(h,g-c|0);break b}if(c>>>0<=g>>>0){break b}d=d+(g<<2)|0;if((d|0)!=(e|0)){while(1){e=e-4|0;c=F[e>>2];F[e>>2]=0;if(c){$[F[F[c>>2]+4>>2]](c)}if((d|0)!=(e|0)){continue}break}}F[a+40>>2]=d}c=1;if((g|0)<=0){break a}e=0;while(1){c:{c=F[b+20>>2];f=F[b+12>>2];d=F[b+16>>2];if((c|0)>=(f|0)&d>>>0>=I[b+8>>2]|(c|0)>(f|0)){break c}f=G[F[b>>2]+d|0];d=d+1|0;c=d?c:c+1|0;F[b+16>>2]=d;F[b+20>>2]=c;d=$[F[F[a>>2]+48>>2]](a,f)|0;f=e<<2;i=f+F[a+36>>2]|0;c=F[i>>2];F[i>>2]=d;if(c){$[F[F[c>>2]+4>>2]](c)}c=F[F[h>>2]+f>>2];if(!c){break c}if(!(k=c,l=$[F[F[a>>2]+28>>2]](a)|0,m=$[F[F[a>>2]+20>>2]](a,e)|0,j=F[F[c>>2]+8>>2],$[j](k|0,l|0,m|0)|0)){break c}c=1;e=e+1|0;if((g|0)!=(e|0)){continue}break a}break}c=0}return c|0}function Xc(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;g=F[a>>2];c=g+(b>>>3&536870908)|0;F[c>>2]=F[c>>2]|1<>2];e=(b|0)==-1;d=-1;a:{if(e){break a}c=b+1|0;c=(c>>>0)%3|0?c:b-2|0;d=-1;if((c|0)==-1){break a}d=F[F[f>>2]+(c<<2)>>2]}c=F[a+12>>2];h=(d>>>3&536870908)+c|0;F[h>>2]=F[h>>2]|1<>>0)%3|0){e=b-1|0;break e}e=b+2|0;d=-1;if((e|0)==-1){break d}}d=F[F[f>>2]+(e<<2)>>2]}e=(d>>>3&536870908)+c|0;F[e>>2]=F[e>>2]|1<>2]+(b<<2)>>2];if((b|0)==-1){break b}D[a+24|0]=0;a=(b>>>3&536870908)+g|0;F[a>>2]=F[a>>2]|1<>>0)%3|0?a:b-2|0;if((a|0)!=-1){d=F[F[f>>2]+(a<<2)>>2]}a=c+(d>>>3&536870908)|0;F[a>>2]=F[a>>2]|1<>>0)%3|0){b=b-1|0;break g}b=b+2|0;a=-1;if((b|0)==-1){break f}}a=F[F[f>>2]+(b<<2)>>2]}b=1<>>3&536870908)|0;c=F[a>>2];break c}a=c+536870908|0;b=F[c+536870908>>2];c=-2147483648}F[a>>2]=b|c}}function zc(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=M(0),f=M(0),g=M(0),h=M(0),i=M(0),j=0,k=M(0),l=M(0),m=M(0),n=M(0),o=0;a:{if(F[c+28>>2]!=9|G[c+24|0]!=3){break a}a=F[a+4>>2];if(a-2>>>0>28){break a}o=1;j=F[c+80>>2];if(!j){break a}k=M(M(2)/M((1<>2]>>2]+F[c+48>>2]|0;a=F[F[b>>2]>>2]+F[b+48>>2]|0;b=0;while(1){g=M(0);l=M(0);m=M(0);e=M(M(M(F[a>>2])*k)+M(-1));f=M(M(M(F[a+4>>2])*k)+M(-1));i=M(M(M(1)-M(N(e)))-M(N(f)));h=M(Q(M(-i),M(0)));n=M(-h);f=M(f+(f>>8;D[c+10|0]=d>>>16;D[c+11|0]=d>>>24;d=(w(l),y(2));D[c+4|0]=d;D[c+5|0]=d>>>8;D[c+6|0]=d>>>16;D[c+7|0]=d>>>24;d=(w(g),y(2));D[c|0]=d;D[c+1|0]=d>>>8;D[c+2|0]=d>>>16;D[c+3|0]=d>>>24;c=c+12|0;b=b+1|0;if((j|0)!=(b|0)){continue}break}}return o|0}function Md(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;g=Z-16|0;Z=g;a:{if(!Sa(1,g+8|0,b)){break a}d=F[b+8>>2];e=F[b+16>>2];f=d-e|0;h=F[g+12>>2];c=d>>>0>>0;d=F[b+20>>2];i=F[b+12>>2]-(c+d|0)|0;c=F[g+8>>2];if((h|0)==(i|0)&c>>>0>f>>>0|h>>>0>i>>>0){break a}d=d+h|0;f=c+e|0;d=f>>>0>>0?d+1|0:d;F[b+16>>2]=f;F[b+20>>2]=d;if((c|0)<=0){break a}b=F[b>>2]+e|0;F[a+40>>2]=b;e=c-1|0;d=b+e|0;f=G[d|0];b:{if(f>>>0<=63){F[a+44>>2]=e;b=G[d|0]&63;break b}c:{switch((f>>>6|0)-1|0){case 0:if(c>>>0<2){break a}c=c-2|0;F[a+44>>2]=c;b=b+c|0;b=G[b+1|0]<<8&16128|G[b|0];break b;case 1:if(c>>>0<3){break a}c=c-3|0;F[a+44>>2]=c;b=b+c|0;b=G[b+1|0]<<8|G[b+2|0]<<16&4128768|G[b|0];break b;default:break c}}c=c-4|0;F[a+44>>2]=c;b=b+c|0;b=(G[b|0]|G[b+1|0]<<8|(G[b+2|0]<<16|G[b+3|0]<<24))&1073741823}F[a+48>>2]=b+16384;j=b>>>0<4177920}Z=g+16|0;return j}function Tf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;a:{a=Z-32|0;Z=a;e=ya(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){g=(e|15)+1|0;f=ka(g);F[a+24>>2]=g|-2147483648;F[a+16>>2]=f;F[a+20>>2]=e;g=e+f|0;break c}D[a+27|0]=e;f=a+16|0;g=e+f|0;if(!e){break b}}la(f,c,e)}D[g|0]=0;F[a+8>>2]=0;F[a>>2]=0;F[a+4>>2]=0;d:{c=Ya(b,a+16|0);if((c|0)==(b+4|0)){break d}b=F[c+28>>2];e=F[c+32>>2];if((b|0)==(e|0)){break d}b=e-b|0;if(b&3){break d}e=b>>>2|0;f=F[a+4>>2];b=F[a>>2];g=f-b>>2;e:{if(e>>>0>g>>>0){qa(a,e-g|0);b=F[a>>2];f=F[a+4>>2];break e}if(e>>>0>=g>>>0){break e}f=(e<<2)+b|0;F[a+4>>2]=f}if((b|0)!=(f|0)){e=b;b=F[c+28>>2];la(e,b,F[c+32>>2]-b|0);break d}ta();v()}b=F[d>>2];if(b){F[d+4>>2]=b;ja(b)}F[d>>2]=F[a>>2];F[d+4>>2]=F[a+4>>2];F[d+8>>2]=F[a+8>>2];if(D[a+27|0]<0){ja(F[a+16>>2])}Z=a+32|0;break a}za();v()}}function ud(a){a=a|0;var b=0,c=0,d=0,e=0;F[a>>2]=8284;d=F[a+368>>2];F[a+368>>2]=0;if(d){e=d-4|0;b=F[e>>2];if(b){c=(b<<4)+d|0;while(1){c=c-16|0;if((d|0)!=(c|0)){continue}break}}ja(e)}td(a+216|0);b=F[a+196>>2];if(b){F[a+200>>2]=b;ja(b)}b=F[a+184>>2];if(b){F[a+188>>2]=b;ja(b)}b=F[a+172>>2];if(b){F[a+176>>2]=b;ja(b)}b=F[a+160>>2];if(b){F[a+164>>2]=b;ja(b)}c=F[a+144>>2];if(c){while(1){b=F[c>>2];ja(c);c=b;if(b){continue}break}}b=F[a+136>>2];F[a+136>>2]=0;if(b){ja(b)}b=F[a+120>>2];if(b){ja(b)}b=F[a+108>>2];if(b){ja(b)}b=F[a+96>>2];if(b){ja(b)}b=F[a+72>>2];if(b){F[a+76>>2]=b;ja(b)}b=F[a+60>>2];if(b){ja(b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}b=F[a+36>>2];if(b){F[a+40>>2]=b;ja(b)}b=F[a+24>>2];if(b){F[a+28>>2]=b;ja(b)}b=F[a+12>>2];if(b){F[a+16>>2]=b;ja(b)}b=F[a+8>>2];F[a+8>>2]=0;if(b){Za(b)}return a|0}function Vf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0;d=Z-16|0;Z=d;a:{e=ya(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){f=(e|15)+1|0;a=ka(f);F[d+8>>2]=f|-2147483648;F[d>>2]=a;F[d+4>>2]=e;f=a+e|0;break c}D[d+11|0]=e;f=d+e|0;a=d;if(!e){break b}}la(a,c,e)}D[f|0]=0;c=G[d+11|0];e=c<<24>>24;b=F[b+4>>2];a=0;d:{if(!b){break d}a=c;c=(e|0)<0;a=c?F[d+4>>2]:a;f=c?F[d>>2]:d;while(1){c=G[b+27|0];g=c<<24>>24<0;c=g?F[b+20>>2]:c;i=c>>>0>>0;e:{f:{g:{h:{i:{j:{h=i?c:a;if(h){g=g?F[b+16>>2]:b+16|0;j=sa(f,g,h);if(j){break j}if(a>>>0>=c>>>0){break i}break e}if(a>>>0>=c>>>0){break h}break e}if((j|0)<0){break e}}c=sa(g,f,h);if(c){break g}}if(i){break f}a=1;break d}if((c|0)<0){break f}a=1;break d}b=b+4|0}b=F[b>>2];if(b){continue}break}a=0}if((e|0)<0){ja(F[d>>2])}Z=d+16|0;break a}za();v()}return a|0}function lc(a,b){var c=0,d=0;c=F[b+8>>2];F[a+4>>2]=F[b+4>>2];F[a+8>>2]=c;F[a+20>>2]=F[b+20>>2];c=F[b+16>>2];F[a+12>>2]=F[b+12>>2];F[a+16>>2]=c;a:{b:{if((a|0)!=(b|0)){c=F[b+28>>2];if(c){d=F[a+24>>2];if(F[a+32>>2]<<5>>>0>>0){if(d){ja(d);F[a+32>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;c=F[b+28>>2]}if((c|0)<0){break b}c=(c-1>>>5|0)+1|0;d=ka(c<<2);F[a+32>>2]=c;F[a+28>>2]=0;F[a+24>>2]=d;c=F[b+28>>2]}pa(d,F[b+24>>2],(c-1>>>3&536870908)+4|0);c=F[b+28>>2]}else{c=0}F[a+28>>2]=c;c=F[b+40>>2];if(c){d=F[a+36>>2];if(F[a+44>>2]<<5>>>0>>0){if(d){ja(d);F[a+44>>2]=0;F[a+36>>2]=0;F[a+40>>2]=0;c=F[b+40>>2]}if((c|0)<0){break a}c=(c-1>>>5|0)+1|0;d=ka(c<<2);F[a+44>>2]=c;F[a+40>>2]=0;F[a+36>>2]=d;c=F[b+40>>2]}pa(d,F[b+36>>2],(c-1>>>3&536870908)+4|0);b=F[b+40>>2]}else{b=0}F[a+40>>2]=b}return}na();v()}na();v()}function nc(a){var b=0,c=0,d=0;b=F[a+8>>2];d=F[a>>2];a:{if(G[a+12|0]){b:{c:{d:{e:{if((b|0)==-1){break e}c=b+1|0;b=(c>>>0)%3|0?c:b-2|0;if((b|0)==-1){break e}b=F[F[d+12>>2]+(b<<2)>>2];if((b|0)!=-1){break d}}F[a+8>>2]=-1;break c}c=b+1|0;b=(c>>>0)%3|0?c:b-2|0;F[a+8>>2]=b;if((b|0)!=-1){break b}}c=F[a+4>>2];b=-1;f:{if((c|0)==-1){break f}g:{if((c>>>0)%3|0){c=c-1|0;break g}c=c+2|0;b=-1;if((c|0)==-1){break f}}c=F[F[d+12>>2]+(c<<2)>>2];b=-1;if((c|0)==-1){break f}b=c-1|0;if((c>>>0)%3|0){break f}b=c+2|0}D[a+12|0]=0;F[a+8>>2]=b;return}if((b|0)!=F[a+4>>2]){break a}F[a+8>>2]=-1;return}c=-1;h:{if((b|0)==-1){break h}i:{if((b>>>0)%3|0){b=b-1|0;break i}b=b+2|0;c=-1;if((b|0)==-1){break h}}b=F[F[d+12>>2]+(b<<2)>>2];c=-1;if((b|0)==-1){break h}c=b-1|0;if((b>>>0)%3|0){break h}c=b+2|0}F[a+8>>2]=c}}function Od(a){var b=0,c=0,d=0;b=ka(32);D[b+26|0]=0;c=G[1475]|G[1476]<<8;D[b+24|0]=c;D[b+25|0]=c>>>8;c=G[1471]|G[1472]<<8|(G[1473]<<16|G[1474]<<24);d=G[1467]|G[1468]<<8|(G[1469]<<16|G[1470]<<24);D[b+16|0]=d;D[b+17|0]=d>>>8;D[b+18|0]=d>>>16;D[b+19|0]=d>>>24;D[b+20|0]=c;D[b+21|0]=c>>>8;D[b+22|0]=c>>>16;D[b+23|0]=c>>>24;c=G[1463]|G[1464]<<8|(G[1465]<<16|G[1466]<<24);d=G[1459]|G[1460]<<8|(G[1461]<<16|G[1462]<<24);D[b+8|0]=d;D[b+9|0]=d>>>8;D[b+10|0]=d>>>16;D[b+11|0]=d>>>24;D[b+12|0]=c;D[b+13|0]=c>>>8;D[b+14|0]=c>>>16;D[b+15|0]=c>>>24;c=G[1455]|G[1456]<<8|(G[1457]<<16|G[1458]<<24);d=G[1451]|G[1452]<<8|(G[1453]<<16|G[1454]<<24);D[b|0]=d;D[b+1|0]=d>>>8;D[b+2|0]=d>>>16;D[b+3|0]=d>>>24;D[b+4|0]=c;D[b+5|0]=c>>>8;D[b+6|0]=c>>>16;D[b+7|0]=c>>>24;F[a>>2]=-1;ra(a+4|0,b,26);ja(b)}function Kg(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0;e=F[a+4>>2];d=F[e>>2];a:{b=F[a+12>>2];c=F[b+56>>2]-F[b+52>>2]|0;f=c>>2;b:{if(f>>>0<=F[e+8>>2]-d>>2>>>0){break b}if((c|0)<0){break a}b=F[e+4>>2];c=ka(c);f=c+(f<<2)|0;g=c+(b-d&-4)|0;c=g;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[e+8>>2]=f;F[e+4>>2]=g;F[e>>2]=c;if(!d){break b}ja(d)}e=a+8|0;b=F[a+76>>2];c:{if(b){d=F[b>>2];if((d|0)==F[b+4>>2]){return 1}b=0;while(1){c=od(e,F[(b<<2)+d>>2]);if(!c){break c}f=F[a+76>>2];d=F[f>>2];b=b+1|0;if(b>>>0>2]-d>>2>>>0){continue}break}break c}c=1;a=F[F[a+12>>2]+64>>2];a=F[a+4>>2]-F[a>>2]|0;if(a>>>0<12){break c}a=(a>>2>>>0)/3|0;b=0;while(1){c=od(e,L(b,3));if(!c){break c}b=b+1|0;if((a|0)!=(b|0)){continue}break}}return c|0}na();v()}function Qg(a){a=a|0;var b=0,c=0,d=0,e=0,f=0,g=0;e=F[a+4>>2];d=F[e>>2];a:{b=F[a+12>>2];c=F[b+28>>2]-F[b+24>>2]|0;f=c>>2;b:{if(f>>>0<=F[e+8>>2]-d>>2>>>0){break b}if((c|0)<0){break a}b=F[e+4>>2];c=ka(c);f=c+(f<<2)|0;g=c+(b-d&-4)|0;c=g;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[e+8>>2]=f;F[e+4>>2]=g;F[e>>2]=c;if(!d){break b}ja(d)}e=a+8|0;b=F[a+76>>2];c:{if(b){d=F[b>>2];if((d|0)==F[b+4>>2]){return 1}b=0;while(1){c=pd(e,F[(b<<2)+d>>2]);if(!c){break c}f=F[a+76>>2];d=F[f>>2];b=b+1|0;if(b>>>0>2]-d>>2>>>0){continue}break}break c}c=1;a=F[a+12>>2];a=F[a+4>>2]-F[a>>2]|0;if(a>>>0<12){break c}a=(a>>2>>>0)/3|0;b=0;while(1){c=pd(e,L(b,3));if(!c){break c}b=b+1|0;if((a|0)!=(b|0)){continue}break}}return c|0}na();v()}function pa(a,b,c){var d=0,e=0;a:{if((a|0)==(b|0)){break a}e=a+c|0;if(b-e>>>0<=0-(c<<1)>>>0){return la(a,b,c)}d=(a^b)&3;b:{c:{if(a>>>0>>0){if(d){d=a;break b}if(!(a&3)){d=a;break c}d=a;while(1){if(!c){break a}D[d|0]=G[b|0];b=b+1|0;c=c-1|0;d=d+1|0;if(d&3){continue}break}break c}d:{if(d){break d}if(e&3){while(1){if(!c){break a}c=c-1|0;d=c+a|0;D[d|0]=G[b+c|0];if(d&3){continue}break}}if(c>>>0<=3){break d}while(1){c=c-4|0;F[c+a>>2]=F[b+c>>2];if(c>>>0>3){continue}break}}if(!c){break a}while(1){c=c-1|0;D[c+a|0]=G[b+c|0];if(c){continue}break}break a}if(c>>>0<=3){break b}while(1){F[d>>2]=F[b>>2];b=b+4|0;d=d+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}while(1){D[d|0]=G[b|0];d=d+1|0;b=b+1|0;c=c-1|0;if(c){continue}break}}return a}function Pb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;d=F[a+8>>2];c=F[a+4>>2];if(d-c>>2>>>0>=b>>>0){if(b){b=b<<2;c=ma(c,0,b)+b|0}F[a+4>>2]=c;return}a:{b:{c:{g=F[a>>2];f=c-g>>2;e=f+b|0;if(e>>>0<1073741824){d=d-g|0;h=d>>>1|0;e=d>>>0>=2147483644?1073741823:e>>>0>>0?h:e;if(e){if(e>>>0>=1073741824){break c}i=ka(e<<2)}d=(f<<2)+i|0;f=b<<2;b=ma(d,0,f);f=b+f|0;e=(e<<2)+i|0;if((c|0)==(g|0)){break b}while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;d=d-4|0;F[d>>2]=b;if((c|0)!=(g|0)){continue}break}F[a+8>>2]=e;b=F[a+4>>2];F[a+4>>2]=f;c=F[a>>2];F[a>>2]=d;if((b|0)==(c|0)){break a}while(1){b=b-4|0;a=F[b>>2];F[b>>2]=0;if(a){$[F[F[a>>2]+4>>2]](a)}if((b|0)!=(c|0)){continue}break}break a}na();v()}oa();v()}F[a+8>>2]=e;F[a+4>>2]=f;F[a>>2]=b}if(c){ja(c)}}function Yd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;e=F[b+8>>2];d=F[b+12>>2];g=d;d=F[b+20>>2];k=d;h=F[b+16>>2];c=h+4|0;d=c>>>0<4?d+1|0:d;i=c;a:{if(c>>>0>e>>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}j=F[b>>2];c=j+h|0;f=G[c|0]|G[c+1|0]<<8|(G[c+2|0]<<16|G[c+3|0]<<24);F[b+16>>2]=i;F[b+20>>2]=d;c=e;e=k;d=h+8|0;e=d>>>0<8?e+1|0:e;if(c>>>0>>0&(e|0)>=(g|0)|(e|0)>(g|0)){break a}c=i+j|0;c=G[c|0]|G[c+1|0]<<8|(G[c+2|0]<<16|G[c+3|0]<<24);F[b+16>>2]=d;F[b+20>>2]=e;if((c|0)<(f|0)){break a}F[a+16>>2]=c;F[a+12>>2]=f;d=(c>>31)-((f>>31)+(c>>>0>>0)|0)|0;e=c-f|0;if(!d&e>>>0>2147483646|d){break a}d=e+1|0;F[a+20>>2]=d;e=d>>>1|0;F[a+24>>2]=e;F[a+28>>2]=0-e;if(!(d&1)){F[a+24>>2]=e-1}l=Aa(a+112|0,b)}return l|0}function Wc(a,b){var c=0,d=0,e=0,f=0;d=-1;e=-1;f=-1;a:{b:{if((b|0)==-1){break b}e=F[F[F[a+4>>2]+12>>2]+(b<<2)>>2];c=b+1|0;c=(c>>>0)%3|0?c:b-2|0;if((c|0)>=0){f=(c>>>0)/3|0;f=F[(F[F[a>>2]+96>>2]+L(f,12)|0)+(c-L(f,3)<<2)>>2]}c:{if((e|0)==-1){break c}c=((e>>>0)%3|0?-1:2)+e|0;if((c|0)<0){break c}d=(c>>>0)/3|0;d=F[(F[F[a>>2]+96>>2]+L(d,12)|0)+(c-L(d,3)<<2)>>2]}c=-1;if((d|0)!=(f|0)){break a}f=-1;d:{b=((b>>>0)%3|0?-1:2)+b|0;if((b|0)>=0){d=(b>>>0)/3|0;d=F[(F[F[a>>2]+96>>2]+L(d,12)|0)+(b-L(d,3)<<2)>>2];if((e|0)==-1){break b}break d}d=-1;if((e|0)!=-1){break d}break b}b=e+1|0;b=(b>>>0)%3|0?b:e-2|0;if((b|0)<0){break b}c=F[F[a>>2]+96>>2];a=(b>>>0)/3|0;f=F[(c+L(a,12)|0)+(b-L(a,3)<<2)>>2]}c=(d|0)!=(f|0)?-1:e}return c}function Fc(a,b){var c=0,d=0,e=0;c=Z+-64|0;Z=c;d=F[a>>2];e=F[d-4>>2];d=F[d-8>>2];F[c+32>>2]=0;F[c+36>>2]=0;F[c+40>>2]=0;F[c+44>>2]=0;F[c+48>>2]=0;F[c+52>>2]=0;D[c+55|0]=0;D[c+56|0]=0;D[c+57|0]=0;D[c+58|0]=0;D[c+59|0]=0;D[c+60|0]=0;D[c+61|0]=0;D[c+62|0]=0;F[c+24>>2]=0;F[c+28>>2]=0;F[c+20>>2]=0;F[c+16>>2]=11020;F[c+12>>2]=a;F[c+8>>2]=b;a=a+d|0;d=0;a:{if(La(e,b,0)){F[c+56>>2]=1;$[F[F[e>>2]+20>>2]](e,c+8|0,a,a,1,0);d=F[c+32>>2]==1?a:0;break a}$[F[F[e>>2]+24>>2]](e,c+8|0,a,1,0);b:{switch(F[c+44>>2]){case 0:d=F[c+48>>2]==1?F[c+36>>2]==1?F[c+40>>2]==1?F[c+28>>2]:0:0:0;break a;case 1:break b;default:break a}}if(F[c+32>>2]!=1){if(F[c+48>>2]|F[c+36>>2]!=1|F[c+40>>2]!=1){break a}}d=F[c+24>>2]}Z=c- -64|0;return d}function ma(a,b,c){var d=0,e=0,f=0,g=0;a:{if(!c){break a}D[a|0]=b;d=a+c|0;D[d-1|0]=b;if(c>>>0<3){break a}D[a+2|0]=b;D[a+1|0]=b;D[d-3|0]=b;D[d-2|0]=b;if(c>>>0<7){break a}D[a+3|0]=b;D[d-4|0]=b;if(c>>>0<9){break a}d=0-a&3;e=d+a|0;b=L(b&255,16843009);F[e>>2]=b;d=c-d&-4;c=d+e|0;F[c-4>>2]=b;if(d>>>0<9){break a}F[e+8>>2]=b;F[e+4>>2]=b;F[c-8>>2]=b;F[c-12>>2]=b;if(d>>>0<25){break a}F[e+24>>2]=b;F[e+20>>2]=b;F[e+16>>2]=b;F[e+12>>2]=b;F[c-16>>2]=b;F[c-20>>2]=b;F[c-24>>2]=b;F[c-28>>2]=b;g=e&4|24;c=d-g|0;if(c>>>0<32){break a}d=ki(b,0,1,1);f=_;b=e+g|0;while(1){F[b+24>>2]=d;F[b+28>>2]=f;F[b+16>>2]=d;F[b+20>>2]=f;F[b+8>>2]=d;F[b+12>>2]=f;F[b>>2]=d;F[b+4>>2]=f;b=b+32|0;c=c-32|0;if(c>>>0>31){continue}break}}return a}function ie(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;d=F[b+8>>2];e=F[b+12>>2];g=e;e=F[b+20>>2];k=e;h=F[b+16>>2];c=h+4|0;e=c>>>0<4?e+1|0:e;i=c;a:{if(c>>>0>d>>>0&(e|0)>=(g|0)|(e|0)>(g|0)){break a}j=F[b>>2];c=j+h|0;f=G[c|0]|G[c+1|0]<<8|(G[c+2|0]<<16|G[c+3|0]<<24);F[b+16>>2]=i;F[b+20>>2]=e;c=d;d=k;e=h+8|0;d=e>>>0<8?d+1|0:d;if(c>>>0>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}c=i+j|0;c=G[c|0]|G[c+1|0]<<8|(G[c+2|0]<<16|G[c+3|0]<<24);F[b+16>>2]=e;F[b+20>>2]=d;if((c|0)<(f|0)){break a}F[a+16>>2]=c;F[a+12>>2]=f;d=(c>>31)-((f>>31)+(c>>>0>>0)|0)|0;b=c-f|0;if(!d&b>>>0>2147483646|d){break a}l=1;d=b+1|0;F[a+20>>2]=d;b=d>>>1|0;F[a+24>>2]=b;F[a+28>>2]=0-b;if(d&1){break a}F[a+24>>2]=b-1}return l|0}function Uc(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;d=Z-16|0;Z=d;f=F[a+24>>2];k=F[a+28>>2];a:{if((f|0)!=(k|0)){while(1){F[d+8>>2]=0;F[d>>2]=0;F[d+4>>2]=0;a=Sc(F[f>>2],b,d);g=G[d+11|0];h=g<<24>>24;i=3;b:{c:{d:{if(!a){break d}i=0;a=G[c+11|0];e=a<<24>>24;j=(h|0)<0?F[d+4>>2]:g;if((j|0)!=(((e|0)<0?F[c+4>>2]:a)|0)){break d}a=(e|0)<0?F[c>>2]:c;e=(h|0)<0;e:{if(!e){e=d;if(!h){break e}while(1){if(G[e|0]!=G[a|0]){break d}a=a+1|0;e=e+1|0;g=g-1|0;if(g){continue}break}break e}if(!j){break e}if(sa(e?F[d>>2]:d,a,j)){break c}}l=F[f>>2];i=1}if((h|0)>=0){break b}}ja(F[d>>2])}f:{switch(i|0){case 0:case 3:break f;default:break a}}f=f+4|0;if((k|0)!=(f|0)){continue}break}}l=0}Z=d+16|0;return l}function gb(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0;f=c-b|0;h=f>>2;d=F[a+8>>2];e=F[a>>2];if(h>>>0<=d-e>>2>>>0){d=F[a+4>>2];g=d-e|0;f=g+b|0;i=g>>2;g=i>>>0>>0?f:c;if((g|0)!=(b|0)){while(1){F[e>>2]=F[b>>2];e=e+4|0;b=b+4|0;if((g|0)!=(b|0)){continue}break}}if(h>>>0>i>>>0){if((c|0)!=(g|0)){while(1){F[d>>2]=F[f>>2];d=d+4|0;f=f+4|0;if((f|0)!=(c|0)){continue}break}}F[a+4>>2]=d;return}F[a+4>>2]=e;return}if(e){F[a+4>>2]=e;ja(e);F[a+8>>2]=0;F[a>>2]=0;F[a+4>>2]=0;d=0}a:{if((f|0)<0){break a}e=d>>>1|0;d=d>>>0>=2147483644?1073741823:e>>>0>h>>>0?e:h;if(d>>>0>=1073741824){break a}e=d<<2;d=ka(e);F[a>>2]=d;F[a+8>>2]=d+e;if((b|0)!=(c|0)){c=b;b=(f-4&-4)+4|0;d=la(d,c,b)+b|0}F[a+4>>2]=d;return}na();v()}function Ea(a,b,c){var d=0,e=0,f=0;e=Z-16|0;Z=e;F[a+4>>2]=0;a:{b:{if(!b){break b}f=F[a+8>>2];d=f<<5;c:{if(d>>>0>=b>>>0){F[a+4>>2]=b;break c}F[e+8>>2]=0;F[e>>2]=0;F[e+4>>2]=0;if((b|0)<0){break a}if(d>>>0<=1073741822){f=f<<6;d=b+31&-32;d=d>>>0>>0?f:d}else{d=2147483647}$a(e,d);f=F[a>>2];F[a>>2]=F[e>>2];F[e>>2]=f;d=F[a+4>>2];F[a+4>>2]=b;F[e+4>>2]=d;d=F[a+8>>2];F[a+8>>2]=F[e+8>>2];F[e+8>>2]=d;if(!f){break c}ja(f)}d=b>>>5|0;a=F[a>>2];if(G[c|0]){if(b>>>0>=32){ma(a,255,d<<2)}if((b&-32)==(b|0)){break b}a=a+(d<<2)|0;F[a>>2]=F[a>>2]|-1>>>32-(b&31);break b}if(b>>>0>=32){ma(a,0,d<<2)}if((b&-32)==(b|0)){break b}a=a+(d<<2)|0;F[a>>2]=F[a>>2]&(-1>>>32-(b&31)^-1)}Z=e+16|0;return}na();v()}function If(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=Z-32|0;Z=e;a:{b:{f=ya(c);if(f>>>0<2147483632){c:{d:{if(f>>>0>=11){a=(f|15)+1|0;g=ka(a);F[e+24>>2]=a|-2147483648;F[e+16>>2]=g;F[e+20>>2]=f;a=f+g|0;break d}D[e+27|0]=f;g=e+16|0;a=f+g|0;if(!f){break c}}la(g,c,f)}D[a|0]=0;c=ya(d);if(c>>>0>=2147483632){break b}e:{f:{if(c>>>0>=11){f=(c|15)+1|0;a=ka(f);F[e+8>>2]=f|-2147483648;F[e>>2]=a;F[e+4>>2]=c;g=a+c|0;break f}D[e+11|0]=c;g=c+e|0;a=e;if(!c){break e}}la(a,d,c)}D[g|0]=0;c=F[b+4>>2];a=-1;g:{if(!c){break g}c=Uc(c,e+16|0,e);a=-1;if(!c){break g}a=Pc(b,F[c+24>>2])}if(D[e+11|0]<0){ja(F[e>>2])}if(D[e+27|0]<0){ja(F[e+16>>2])}Z=e+32|0;break a}za();v()}za();v()}return a|0}function se(a,b){a=a|0;b=b|0;a=0;a:{switch(b|0){case 0:a=ka(20);F[a+12>>2]=-1;F[a+16>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a>>2]=1920;return a|0;case 1:a=ka(24);F[a+12>>2]=-1;F[a+16>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a>>2]=1920;F[a+20>>2]=0;F[a>>2]=2136;return a|0;case 2:a=ka(48);F[a+12>>2]=-1;F[a+16>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a>>2]=1920;F[a+20>>2]=0;F[a>>2]=2136;F[a+24>>2]=1624;F[a>>2]=7948;F[a+32>>2]=0;F[a+36>>2]=0;F[a+28>>2]=-1;F[a+40>>2]=0;F[a+44>>2]=0;return a|0;case 3:a=ka(32);F[a+12>>2]=-1;F[a+16>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a>>2]=1920;F[a+20>>2]=0;F[a>>2]=2136;F[a+24>>2]=1032;F[a>>2]=5812;F[a+28>>2]=-1;break;default:break a}}return a|0}function Be(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;f=F[b>>2];b=F[b+4>>2];d=F[F[a+8>>2]+40>>2];j=d;m=ka((d|0)<0?-1:d);i=b-f|0;e=1;a:{if((i|0)<4){break a}b=0;g=F[c+16>>2];k=d;f=g+d|0;d=0+F[c+20>>2]|0;d=f>>>0>>0?d+1|0:d;h=F[c+12>>2];e=0;if(I[c+8>>2]>>0&(d|0)>=(h|0)|(d|0)>(h|0)){break a}e=i>>2;i=(e|0)<=1?1:e;while(1){b:{g=la(m,F[c>>2]+g|0,j);F[c+16>>2]=f;F[c+20>>2]=d;la(F[F[F[a+8>>2]+64>>2]>>2]+b|0,g,j);l=l+1|0;if((i|0)==(l|0)){break b}b=b+j|0;d=n+F[c+20>>2]|0;g=F[c+16>>2];f=k+g|0;d=f>>>0>>0?d+1|0:d;h=F[c+12>>2];if((d|0)<=(h|0)&I[c+8>>2]>=f>>>0|(d|0)<(h|0)){continue}}break}e=(e|0)<=(l|0)}ja(m);return e|0}function mh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;F[b>>2]=1;f=b+8|0;c=F[b+8>>2];d=F[b+12>>2]-c|0;if(d>>>0<=4294967291){Db(f,d+4|0);c=F[f>>2]}c=c+d|0;d=F[a+4>>2];D[c|0]=d;D[c+1|0]=d>>>8;D[c+2|0]=d>>>16;D[c+3|0]=d>>>24;c=F[a+8>>2];if((c|0)!=F[a+12>>2]){d=0;while(1){g=(d<<2)+c|0;c=F[b+8>>2];e=F[b+12>>2]-c|0;if(e>>>0<=4294967291){Db(f,e+4|0);c=F[f>>2]}c=c+e|0;e=F[g>>2];D[c|0]=e;D[c+1|0]=e>>>8;D[c+2|0]=e>>>16;D[c+3|0]=e>>>24;d=d+1|0;c=F[a+8>>2];if(d>>>0>2]-c>>2>>>0){continue}break}}c=F[b+12>>2];b=F[b+8>>2];c=c-b|0;if(c>>>0<=4294967291){Db(f,c+4|0);b=F[f>>2]}b=b+c|0;a=F[a+20>>2];D[b|0]=a;D[b+1|0]=a>>>8;D[b+2|0]=a>>>16;D[b+3|0]=a>>>24}function mb(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;c=F[a+4>>2];if((c|0)!=F[a+8>>2]){e=F[b+4>>2];F[c>>2]=F[b>>2];F[c+4>>2]=e;F[c+8>>2]=F[b+8>>2];F[a+4>>2]=c+12;return}a:{g=F[a>>2];d=(c-g|0)/12|0;e=d+1|0;if(e>>>0<357913942){f=d<<1;f=d>>>0>=178956970?357913941:e>>>0>>0?f:e;if(f){if(f>>>0>=357913942){break a}e=ka(L(f,12))}else{e=0}d=e+L(d,12)|0;h=F[b+4>>2];F[d>>2]=F[b>>2];F[d+4>>2]=h;F[d+8>>2]=F[b+8>>2];b=d+12|0;if((c|0)!=(g|0)){while(1){c=c-12|0;h=F[c+4>>2];d=d-12|0;F[d>>2]=F[c>>2];F[d+4>>2]=h;F[d+8>>2]=F[c+8>>2];if((c|0)!=(g|0)){continue}break}c=F[a>>2]}F[a+8>>2]=e+L(f,12);F[a+4>>2]=b;F[a>>2]=d;if(c){ja(c)}return}na();v()}oa();v()}function ne(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0;h=F[c+12>>2];f=h;e=F[c+20>>2];i=F[c+8>>2];g=F[c+16>>2];a:{if((f|0)<=(e|0)&i>>>0<=g>>>0|(e|0)>(f|0)){break a}j=F[c>>2];k=D[j+g|0];d=e;f=g+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;b:{if((k|0)==-2){break b}if((d|0)>=(h|0)&f>>>0>=i>>>0|(d|0)>(h|0)){break a}d=D[f+j|0];g=g+2|0;e=g>>>0<2?e+1|0:e;F[c+16>>2]=g;F[c+20>>2]=e;if((d-4&255)>>>0<251){break a}e=$[F[F[a>>2]+40>>2]](a,k,d)|0;d=F[a+20>>2];F[a+20>>2]=e;if(!d){break b}$[F[F[d>>2]+4>>2]](d)}d=F[a+20>>2];if(d){if(!($[F[F[a>>2]+28>>2]](a,d)|0)){break a}}l=$[F[F[a>>2]+36>>2]](a,b,c)|0}return l|0}function Bf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0;a:{if(I[b+80>>2]>65535){break a}a=F[b+100>>2];b=F[b+96>>2];e=(a-b|0)/12|0;f=L(e,6);g=(f|0)==(c|0);if((a|0)==(b|0)|(c|0)!=(f|0)){break a}g=1;c=e>>>0<=1?1:e;i=c&1;a=0;if(e>>>0>=2){j=c&-2;c=0;while(1){f=L(a,6);h=f+d|0;e=b+L(a,12)|0;E[h>>1]=F[e>>2];E[(f|2)+d>>1]=F[e+4>>2];E[h+4>>1]=F[e+8>>2];f=a|1;e=L(f,6)+d|0;f=b+L(f,12)|0;E[e>>1]=F[f>>2];E[e+2>>1]=F[f+4>>2];E[e+4>>1]=F[f+8>>2];a=a+2|0;c=c+2|0;if((j|0)!=(c|0)){continue}break}}if(!i){break a}c=L(a,6)+d|0;a=b+L(a,12)|0;E[c>>1]=F[a>>2];E[c+2>>1]=F[a+4>>2];E[c+4>>1]=F[a+8>>2]}return g|0}function Gh(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;var g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0;f=Z-32|0;Z=f;h=e>>>0>1073741823?-1:e<<2;h=ma(ka(h),0,h);g=F[b>>2];i=F[b+4>>2];k=F[h+4>>2];F[f+16>>2]=F[h>>2];F[f+20>>2]=k;F[f+8>>2]=g;F[f+12>>2]=i;i=a+8|0;Jb(f+24|0,i,f+16|0,f+8|0);F[c>>2]=F[f+24>>2];F[c+4>>2]=F[f+28>>2];if((d|0)>(e|0)){k=0-e<<2;a=e;while(1){g=a<<2;j=g+b|0;m=F[j>>2];j=F[j+4>>2];g=c+g|0;l=g+k|0;n=F[l+4>>2];F[f+16>>2]=F[l>>2];F[f+20>>2]=n;F[f+8>>2]=m;F[f+12>>2]=j;Jb(f+24|0,i,f+16|0,f+8|0);F[g>>2]=F[f+24>>2];F[g+4>>2]=F[f+28>>2];a=a+e|0;if((d|0)>(a|0)){continue}break}}ja(h);Z=f+32|0;return 1}function Sf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;a=Z-32|0;Z=a;F[a+24>>2]=0;F[a+28>>2]=0;a:{d=ya(c);if(d>>>0<2147483632){b:{c:{if(d>>>0>=11){e=(d|15)+1|0;f=ka(e);F[a+16>>2]=e|-2147483648;F[a+8>>2]=f;F[a+12>>2]=d;e=d+f|0;break c}D[a+19|0]=d;f=a+8|0;e=f+d|0;if(!d){break b}}la(f,c,d)}D[e|0]=0;c=b+4|0;b=Ya(b,a+8|0);d:{if((c|0)==(b|0)){break d}c=F[b+32>>2];b=F[b+28>>2];if((c-b|0)!=8){break d}c=G[b+4|0]|G[b+5|0]<<8|(G[b+6|0]<<16|G[b+7|0]<<24);F[a+24>>2]=G[b|0]|G[b+1|0]<<8|(G[b+2|0]<<16|G[b+3|0]<<24);F[a+28>>2]=c}g=K[a+24>>3];if(D[a+19|0]<0){ja(F[a+8>>2])}Z=a+32|0;break a}za();v()}return+g}function Gc(a,b,c,d,e,f,g){var h=0,i=0,j=0;h=Z-16|0;Z=h;if((b^-1)+2147483631>>>0>=c>>>0){if(G[a+11|0]>>>7|0){i=F[a>>2]}else{i=a}if(b>>>0<1073741799){F[h+12>>2]=b<<1;F[h>>2]=b+c;c=Z-16|0;Z=c;Z=c+16|0;c=h+12|0;c=F[(I[h>>2]>2]?c:h)>>2];if(c>>>0>=11){j=c+16&-16;c=j-1|0;c=(c|0)==11?j:c}else{c=10}c=c+1|0}else{c=2147483631}sb(h,c);c=F[h>>2];if(f){db(c,g,f)}g=d-e|0;if((d|0)!=(e|0)){db(c+f|0,e+i|0,g)}if((b|0)!=10){ja(i)}F[a>>2]=c;F[a+8>>2]=F[a+8>>2]&-2147483648|F[h+4>>2]&2147483647;F[a+8>>2]=F[a+8>>2]|-2147483648;b=a;a=f+g|0;F[b+4>>2]=a;D[h+12|0]=0;D[a+c|0]=G[h+12|0];Z=h+16|0;return}za();v()}function _c(a,b,c){var d=0,e=0,f=0,g=0;a:{f=b>>>0<1431655766&(b|c)>=0;b:{if(!f){break b}b=L(b,3);Xb(a,b,10224);Xb(a+12|0,b,10228);d=F[a+24>>2];c:{if(F[a+32>>2]-d>>2>>>0>=c>>>0){break c}if(c>>>0>=1073741824){break a}b=F[a+28>>2];e=c<<2;c=ka(e);e=c+e|0;g=c+(b-d&-4)|0;c=g;if((b|0)!=(d|0)){while(1){c=c-4|0;b=b-4|0;F[c>>2]=F[b>>2];if((b|0)!=(d|0)){continue}break}}F[a+32>>2]=e;F[a+28>>2]=g;F[a+24>>2]=c;if(!d){break c}ja(d)}F[a+80>>2]=0;F[a+84>>2]=0;b=F[a+76>>2];F[a+76>>2]=0;if(b){ja(b)}F[a+68>>2]=0;F[a+72>>2]=0;b=a- -64|0;a=F[b>>2];F[b>>2]=0;if(!a){break b}ja(a)}return f}na();v()}function yd(a){var b=0,c=0,d=0,e=0,f=0;f=1;c=F[a+140>>2];a:{if((c|0)<=0){break a}b=c<<4;d=ka(c>>>0>268435455?-1:b|4);F[d>>2]=c;d=d+4|0;c=d+b|0;b=d;while(1){F[b>>2]=0;F[b+4>>2]=0;D[b+5|0]=0;D[b+6|0]=0;D[b+7|0]=0;D[b+8|0]=0;D[b+9|0]=0;D[b+10|0]=0;D[b+11|0]=0;D[b+12|0]=0;b=b+16|0;if((c|0)!=(b|0)){continue}break}e=F[a+136>>2];F[a+136>>2]=d;if(e){c=e-4|0;d=F[c>>2];if(d){b=(d<<4)+e|0;while(1){b=b-16|0;if((e|0)!=(b|0)){continue}break}}ja(c)}b=0;if(F[a+140>>2]<=0){break a}while(1){f=Aa(F[a+136>>2]+(b<<4)|0,a);if(!f){break a}b=b+1|0;if((b|0)>2]){continue}break}}return f} +function Sd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;d=F[b+8>>2];c=F[b+12>>2];g=c;c=F[b+20>>2];i=c;h=F[b+16>>2];f=h+4|0;c=f>>>0<4?c+1|0:c;a:{if(d>>>0>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break a}e=h+F[b>>2]|0;e=G[e|0]|G[e+1|0]<<8|(G[e+2|0]<<16|G[e+3|0]<<24);F[b+16>>2]=f;F[b+20>>2]=c;f=d;d=i;c=h+8|0;d=c>>>0<8?d+1|0:d;if(c>>>0>f>>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}F[b+16>>2]=c;F[b+20>>2]=d;if(!(e&1)){break a}d=O(e)^31;if(d-1>>>0>28){break a}F[a+8>>2]=d+1;d=-2<>2]=c;F[a+12>>2]=d^-1;F[a+24>>2]=c>>1;J[a+20>>2]=M(2)/M(c|0);j=Aa(a+96|0,b)}return j|0}function bc(a,b){var c=0;c=F[b+4>>2];F[a>>2]=F[b>>2];F[a+4>>2]=c;c=F[b+60>>2];F[a+56>>2]=F[b+56>>2];F[a+60>>2]=c;c=F[b+52>>2];F[a+48>>2]=F[b+48>>2];F[a+52>>2]=c;c=F[b+44>>2];F[a+40>>2]=F[b+40>>2];F[a+44>>2]=c;c=F[b+36>>2];F[a+32>>2]=F[b+32>>2];F[a+36>>2]=c;c=F[b+28>>2];F[a+24>>2]=F[b+24>>2];F[a+28>>2]=c;c=F[b+20>>2];F[a+16>>2]=F[b+16>>2];F[a+20>>2]=c;c=F[b+12>>2];F[a+8>>2]=F[b+8>>2];F[a+12>>2]=c;F[a+88>>2]=0;F[a+64>>2]=0;F[a+68>>2]=0;F[a+72>>2]=0;F[a+76>>2]=0;D[a+77|0]=0;D[a+78|0]=0;D[a+79|0]=0;D[a+80|0]=0;D[a+81|0]=0;D[a+82|0]=0;D[a+83|0]=0;D[a+84|0]=0;return a}function ac(a,b){var c=0,d=0,e=0,f=0,g=0;a:{if(F[a+64>>2]){break a}c=ka(32);F[c+16>>2]=0;F[c+20>>2]=0;F[c+8>>2]=0;F[c>>2]=0;F[c+4>>2]=0;F[c+24>>2]=0;F[c+28>>2]=0;d=F[a+64>>2];F[a+64>>2]=c;if(!d){break a}c=F[d>>2];if(c){F[d+4>>2]=c;ja(c)}ja(d)}d=F[a+64>>2];c=F[a+28>>2]-1|0;if(c>>>0<=10){c=F[(c<<2)+10148>>2]}else{c=-1}c=L(c,G[a+24|0]);f=c>>31;g=md(d,0,ki(c,f,b,0),_);if(g){d=F[a+64>>2];F[a>>2]=d;e=F[d+20>>2];F[a+8>>2]=F[d+16>>2];F[a+12>>2]=e;e=F[d+24>>2];d=F[d+28>>2];F[a+48>>2]=0;F[a+52>>2]=0;F[a+40>>2]=c;F[a+44>>2]=f;F[a+16>>2]=e;F[a+20>>2]=d;F[a+80>>2]=b}return g}function Af(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0,i=0,j=0,k=0;a=F[b+100>>2];b=F[b+96>>2];h=a-b|0;a:{if((h|0)!=(c|0)|(a|0)==(b|0)){break a}g=(c|0)/12|0;e=g>>>0<=1?1:g;j=e&1;a=0;if(g>>>0>=2){k=e&-2;g=0;while(1){e=L(a,12);i=e+d|0;f=b+e|0;F[i>>2]=F[f>>2];F[(e|4)+d>>2]=F[f+4>>2];F[i+8>>2]=F[f+8>>2];f=L(a|1,12);e=f+d|0;f=b+f|0;F[e>>2]=F[f>>2];F[e+4>>2]=F[f+4>>2];F[e+8>>2]=F[f+8>>2];a=a+2|0;g=g+2|0;if((k|0)!=(g|0)){continue}break}}if(!j){break a}e=d;d=L(a,12);a=e+d|0;b=b+d|0;F[a>>2]=F[b>>2];F[a+4>>2]=F[b+4>>2];F[a+8>>2]=F[b+8>>2]}return(c|0)==(h|0)|0}function Kh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0;c=F[b+8>>2];d=F[b+12>>2];g=d;d=F[b+20>>2];i=d;h=F[b+16>>2];f=h+4|0;d=f>>>0<4?d+1|0:d;a:{if(c>>>0>>0&(d|0)>=(g|0)|(d|0)>(g|0)){break a}e=h+F[b>>2]|0;e=G[e|0]|G[e+1|0]<<8|(G[e+2|0]<<16|G[e+3|0]<<24);F[b+16>>2]=f;F[b+20>>2]=d;f=c;c=i;d=h+8|0;c=d>>>0<8?c+1|0:c;if(d>>>0>f>>>0&(c|0)>=(g|0)|(c|0)>(g|0)){break a}F[b+16>>2]=d;F[b+20>>2]=c;if(!(e&1)){break a}b=O(e)^31;if(b-1>>>0>28){break a}j=1;F[a+8>>2]=b+1;b=-2<>2]=c;F[a+12>>2]=b^-1;F[a+24>>2]=c>>1;J[a+20>>2]=M(2)/M(c|0)}return j|0}function Ya(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;f=a+4|0;a=F[a+4>>2];a:{b:{if(!a){break b}d=G[b+11|0];c=d<<24>>24<0;g=c?F[b>>2]:b;d=c?F[b+4>>2]:d;b=f;while(1){e=G[a+27|0];c=e<<24>>24<0;e=c?F[a+20>>2]:e;h=e>>>0>d>>>0;i=h?d:e;c:{if(i){c=sa(c?F[a+16>>2]:a+16|0,g,i);if(c){break c}}c=d>>>0>e>>>0?-1:h}c=(c|0)<0;b=c?b:a;a=F[(c?a+4|0:a)>>2];if(a){continue}break}if((b|0)==(f|0)){break b}c=G[b+27|0];a=c<<24>>24<0;d:{c=a?F[b+20>>2]:c;e=c>>>0>>0?c:d;if(e){a=sa(g,a?F[b+16>>2]:b+16|0,e);if(a){break d}}if(c>>>0>d>>>0){break b}break a}if((a|0)>=0){break a}}b=f}return b}function Oe(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;if(La(a,F[b+8>>2],e)){if(!(F[b+28>>2]==1|F[b+4>>2]!=(c|0))){F[b+28>>2]=d}return}a:{if(La(a,F[b>>2],e)){if(!(F[b+16>>2]!=(c|0)&F[b+20>>2]!=(c|0))){if((d|0)!=1){break a}F[b+32>>2]=1;return}F[b+32>>2]=d;b:{if(F[b+44>>2]==4){break b}E[b+52>>1]=0;a=F[a+8>>2];$[F[F[a>>2]+20>>2]](a,b,c,c,1,e);if(G[b+53|0]){F[b+44>>2]=3;if(!G[b+52|0]){break b}break a}F[b+44>>2]=4}F[b+20>>2]=c;F[b+40>>2]=F[b+40>>2]+1;if(F[b+36>>2]!=1|F[b+24>>2]!=2){break a}D[b+54|0]=1;return}a=F[a+8>>2];$[F[F[a>>2]+24>>2]](a,b,c,d,e)}}function Ig(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;f=ka(64);c=ka(12);F[c+8>>2]=F[F[a+4>>2]+80>>2];F[c>>2]=9968;F[c+4>>2]=0;f=yc(f,c);a:{b:{if((b|0)<0){c=f;break b}h=a+8|0;c=F[a+12>>2];e=F[a+8>>2];g=c-e>>2;c:{if((g|0)>(b|0)){break c}d=b+1|0;if(b>>>0>=g>>>0){Pb(h,d-g|0);break c}if(d>>>0>=g>>>0){break c}e=e+(d<<2)|0;if((e|0)!=(c|0)){while(1){c=c-4|0;d=F[c>>2];F[c>>2]=0;if(d){$[F[F[d>>2]+4>>2]](d)}if((c|0)!=(e|0)){continue}break}}F[a+12>>2]=e}a=F[h>>2]+(b<<2)|0;c=F[a>>2];F[a>>2]=f;if(!c){break a}}$[F[F[c>>2]+4>>2]](c)}return(b^-1)>>>31|0}function we(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;c=F[a+60>>2];a:{if(!c){break a}F[c+4>>2]=a+48;if(!($[F[F[c>>2]+12>>2]](c)|0)){break a}b:{c=$[F[F[a>>2]+24>>2]](a)|0;if((c|0)<=0){break b}while(1){c:{f=F[($[F[F[a>>2]+28>>2]](a)|0)+4>>2];g=$[F[F[a>>2]+20>>2]](a,d)|0;e=F[a+60>>2];if(!($[F[F[e>>2]+8>>2]](e,F[F[f+8>>2]+(g<<2)>>2])|0)){break c}d=d+1|0;if((c|0)!=(d|0)){continue}break b}break}return 0}d=0;if(!($[F[F[a>>2]+36>>2]](a,b)|0)){break a}if(!($[F[F[a>>2]+40>>2]](a,b)|0)){break a}d=$[F[F[a>>2]+44>>2]](a)|0}return d|0}function Id(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;c=F[a+216>>2];if((c|0)!=F[a+220>>2]){while(1){a:{c=F[L(e,144)+c>>2];if((c|0)<0){break a}d=F[a+4>>2];f=F[d+8>>2];if((c|0)>=F[d+12>>2]-f>>2){break a}d=0;c=F[(c<<2)+f>>2];if(($[F[F[c>>2]+24>>2]](c)|0)<=0){break a}while(1){if(($[F[F[c>>2]+20>>2]](c,d)|0)!=(b|0)){d=d+1|0;if(($[F[F[c>>2]+24>>2]](c)|0)>(d|0)){continue}break a}break}a=F[a+216>>2]+L(e,144)|0;return(G[a+100|0]?a+4|0:0)|0}e=e+1|0;c=F[a+216>>2];if(e>>>0<(F[a+220>>2]-c|0)/144>>>0){continue}break}}return 0}function nd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;c=F[a+8>>2];d=F[a+4>>2];if(c-d>>2>>>0>=b>>>0){if(b){b=b<<2;d=ma(d,0,b)+b|0}F[a+4>>2]=d;return}a:{f=F[a>>2];g=d-f>>2;e=g+b|0;if(e>>>0<1073741824){c=c-f|0;h=c>>>1|0;e=c>>>0>=2147483644?1073741823:e>>>0>>0?h:e;if(e){if(e>>>0>=1073741824){break a}i=ka(e<<2)}c=(g<<2)+i|0;b=b<<2;b=ma(c,0,b)+b|0;if((d|0)!=(f|0)){while(1){c=c-4|0;d=d-4|0;F[c>>2]=F[d>>2];if((d|0)!=(f|0)){continue}break}}F[a+8>>2]=(e<<2)+i;F[a+4>>2]=b;F[a>>2]=c;if(f){ja(f)}return}na();v()}oa();v()}function bb(a){var b=0,c=0,d=0,e=0,f=0;d=F[a+8>>2];a:{if(G[d+84|0]){break a}b=F[a+16>>2];if(!b|!G[b+84|0]){break a}c=F[d+72>>2];e=F[d+68>>2];D[b+84|0]=0;c=c-e>>2;f=F[b+68>>2];e=F[b+72>>2]-f>>2;b:{if(c>>>0>e>>>0){ab(b+68|0,c-e|0,2004);d=F[a+8>>2];break b}if(c>>>0>=e>>>0){break b}F[b+72>>2]=f+(c<<2)}if(G[d+84|0]){break a}c=F[d+68>>2];if((c|0)==F[d+72>>2]){break a}e=F[F[a+16>>2]+68>>2];b=0;while(1){f=b<<2;F[f+e>>2]=F[c+f>>2];b=b+1|0;c=F[d+68>>2];if(b>>>0>2]-c>>2>>>0){continue}break}}return F[a+16>>2]}function Lf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=Z+-64|0;Z=e;f=Ja(e+8|0);F[f+16>>2]=0;F[f+20>>2]=0;F[f>>2]=b;F[f+8>>2]=c;F[f+12>>2]=0;b=e+48|0;Pd(b,a,f,d);F[a+24>>2]=F[e+48>>2];f=a+24|0;a:{if((f|0)==(b|0)){break a}b=a+28|0;c=e+48|4;g=G[e+63|0];d=g<<24>>24;if(D[a+39|0]>=0){if((d|0)>=0){a=F[c+4>>2];F[b>>2]=F[c>>2];F[b+4>>2]=a;F[b+8>>2]=F[c+8>>2];break a}qb(b,F[e+52>>2],F[e+56>>2]);break a}a=(d|0)<0;rb(b,a?F[e+52>>2]:c,a?F[e+56>>2]:g)}if(D[e+63|0]<0){ja(F[e+52>>2])}Z=e- -64|0;return f|0}function Jf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;a=Z-32|0;Z=a;a:{d=ya(c);if(d>>>0<2147483632){b:{c:{if(d>>>0>=11){e=(d|15)+1|0;f=ka(e);F[a+24>>2]=e|-2147483648;F[a+16>>2]=f;F[a+20>>2]=d;e=d+f|0;break c}D[a+27|0]=d;f=a+16|0;e=f+d|0;if(!d){break b}}la(f,c,d)}D[e|0]=0;D[a+4|0]=0;F[a>>2]=1701667182;D[a+11|0]=4;d=F[b+4>>2];c=-1;d:{if(!d){break d}d=Uc(d,a,a+16|0);c=-1;if(!d){break d}c=Pc(b,F[d+24>>2])}b=c;if(D[a+11|0]<0){ja(F[a>>2])}if(D[a+27|0]<0){ja(F[a+16>>2])}Z=a+32|0;break a}za();v()}return b|0}function Hd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;c=F[a+216>>2];if((c|0)!=F[a+220>>2]){while(1){a:{c=F[L(e,144)+c>>2];if((c|0)<0){break a}d=F[a+4>>2];f=F[d+8>>2];if((c|0)>=F[d+12>>2]-f>>2){break a}d=0;c=F[(c<<2)+f>>2];if(($[F[F[c>>2]+24>>2]](c)|0)<=0){break a}while(1){if(($[F[F[c>>2]+20>>2]](c,d)|0)!=(b|0)){d=d+1|0;if(($[F[F[c>>2]+24>>2]](c)|0)>(d|0)){continue}break a}break}return(F[a+216>>2]+L(e,144)|0)+104|0}e=e+1|0;c=F[a+216>>2];if(e>>>0<(F[a+220>>2]-c|0)/144>>>0){continue}break}}return a+184|0}function Uf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0;d=Z-16|0;Z=d;F[d+12>>2]=0;a:{e=ya(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){f=(e|15)+1|0;a=ka(f);F[d+8>>2]=f|-2147483648;F[d>>2]=a;F[d+4>>2]=e;f=a+e|0;break c}D[d+11|0]=e;f=d+e|0;a=d;if(!e){break b}}la(a,c,e)}D[f|0]=0;a=Ya(b,d);d:{if((a|0)==(b+4|0)){break d}b=F[a+32>>2];a=F[a+28>>2];if((b-a|0)!=4){break d}F[d+12>>2]=G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24)}a=F[d+12>>2];if(D[d+11|0]<0){ja(F[d>>2])}Z=d+16|0;break a}za();v()}return a|0}function Mf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;d=Z+-64|0;Z=d;e=Ja(d+8|0);F[e+16>>2]=0;F[e+20>>2]=0;F[e>>2]=b;F[e+8>>2]=c;F[e+12>>2]=0;b=d+48|0;Od(b);F[a+24>>2]=F[d+48>>2];f=a+24|0;a:{if((b|0)==(f|0)){break a}b=a+28|0;c=d+48|4;g=G[d+63|0];e=g<<24>>24;if(D[a+39|0]>=0){if((e|0)>=0){a=F[c+4>>2];F[b>>2]=F[c>>2];F[b+4>>2]=a;F[b+8>>2]=F[c+8>>2];break a}qb(b,F[d+52>>2],F[d+56>>2]);break a}a=(e|0)<0;rb(b,a?F[d+52>>2]:c,a?F[d+56>>2]:g)}if(D[d+63|0]<0){ja(F[d+52>>2])}Z=d- -64|0;return f|0}function Ce(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;e=1;a:{if(($[F[F[b>>2]+20>>2]](b)|0)<=0){break a}while(1){e=0;d=Qc(F[F[a+4>>2]+4>>2],$[F[F[b>>2]+24>>2]](b,f)|0);if((d|0)==-1){break a}g=F[a+4>>2];c=0;b:{if((d|0)<0){break b}h=F[g+4>>2];if((d|0)>=F[h+12>>2]-F[h+8>>2]>>2){break b}c=F[F[g+8>>2]+(F[F[g+20>>2]+(d<<2)>>2]<<2)>>2];c=$[F[F[c>>2]+32>>2]](c,d)|0}if(!c){break a}if(!($[F[F[b>>2]+28>>2]](b,c)|0)){break a}e=1;f=f+1|0;if(($[F[F[b>>2]+20>>2]](b)|0)>(f|0)){continue}break}}return e|0}function Db(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;a:{c=F[a+4>>2];e=F[a>>2];d=c-e|0;b:{if(d>>>0>>0){g=b-d|0;f=F[a+8>>2];if(g>>>0<=f-c>>>0){h=a,i=ma(c,0,g)+g|0,F[h+4>>2]=i;break b}if((b|0)<0){break a}c=f-e|0;f=c<<1;c=c>>>0>=1073741823?2147483647:b>>>0>>0?f:b;f=ka(c);ma(f+d|0,0,g);d=pa(f,e,d);F[a+8>>2]=d+c;F[a+4>>2]=b+d;F[a>>2]=d;if(!e){break b}ja(e);break b}if(b>>>0>=d>>>0){break b}F[a+4>>2]=b+e}b=F[a+28>>2];c=b;d=b+1|0;b=F[a+24>>2]+1|0;e=b?c:d;F[a+24>>2]=b;F[a+28>>2]=e;return}na();v()}function Ma(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;e=F[a+4>>2];if((e|0)!=F[a+8>>2]){F[e>>2]=F[b>>2];F[a+4>>2]=e+4;return}a:{g=F[a>>2];f=e-g|0;c=f>>2;d=c+1|0;if(d>>>0<1073741824){h=c<<2;c=f>>>1|0;c=f>>>0>=2147483644?1073741823:c>>>0>d>>>0?c:d;if(c){if(c>>>0>=1073741824){break a}f=ka(c<<2)}else{f=0}d=h+f|0;F[d>>2]=F[b>>2];b=d+4|0;if((e|0)!=(g|0)){while(1){d=d-4|0;e=e-4|0;F[d>>2]=F[e>>2];if((e|0)!=(g|0)){continue}break}}F[a+8>>2]=f+(c<<2);F[a+4>>2]=b;F[a>>2]=d;if(g){ja(g)}return}na();v()}oa();v()}function va(a){F[a>>2]=-1;F[a+4>>2]=0;F[a+8>>2]=0;F[a+32>>2]=0;F[a+36>>2]=0;D[a+28|0]=1;F[a+20>>2]=0;F[a+24>>2]=0;F[a+12>>2]=0;F[a+16>>2]=0;F[a+40>>2]=0;F[a+44>>2]=0;F[a+48>>2]=0;F[a+52>>2]=0;F[a+56>>2]=0;F[a+60>>2]=0;F[a+64>>2]=0;F[a+68>>2]=0;F[a+76>>2]=0;F[a+80>>2]=0;F[a+84>>2]=0;F[a+88>>2]=0;F[a+92>>2]=0;F[a+96>>2]=0;F[a+72>>2]=a+4;F[a+104>>2]=0;F[a+108>>2]=0;D[a+100|0]=1;F[a+112>>2]=0;F[a+116>>2]=0;F[a+120>>2]=0;F[a+124>>2]=0;F[a+128>>2]=0;F[a+132>>2]=0;F[a+136>>2]=0;F[a+140>>2]=0}function Hb(a,b){var c=0,d=0,e=0,f=0;d=F[a+12>>2];c=F[a+16>>2]-d>>2;a:{if(c>>>0>>0){qa(a+12|0,b-c|0);break a}if(b>>>0>=c>>>0){break a}F[a+16>>2]=d+(b<<2)}b:{c=F[a>>2];c:{if(F[a+8>>2]-c>>2>>>0>=b>>>0){break c}if(b>>>0>=1073741824){break b}d=F[a+4>>2];e=b<<2;b=ka(e);e=b+e|0;f=b+(d-c&-4)|0;b=f;if((c|0)!=(d|0)){while(1){b=b-4|0;d=d-4|0;F[b>>2]=F[d>>2];if((c|0)!=(d|0)){continue}break}}F[a+8>>2]=e;F[a+4>>2]=f;F[a>>2]=b;if(!c){break c}ja(c)}return}na();v()}function tb(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=10300;b=F[a+68>>2];if(b){F[a+72>>2]=b;ja(b)}b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}b=F[a+44>>2];if(b){F[a+48>>2]=b;ja(b)}b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}b=F[a+20>>2];if(b){F[a+24>>2]=b;ja(b)}b=F[a+8>>2];if(b){d=b;c=F[a+12>>2];if((b|0)!=(c|0)){while(1){c=c-4|0;d=F[c>>2];F[c>>2]=0;if(d){xa(d)}if((b|0)!=(c|0)){continue}break}d=F[a+8>>2]}F[a+12>>2]=b;ja(d)}b=F[a+4>>2];F[a+4>>2]=0;if(b){ic(b)}return a|0}function qa(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;e=F[a+8>>2];c=F[a+4>>2];if(e-c>>2>>>0>=b>>>0){if(b){b=b<<2;c=ma(c,0,b)+b|0}F[a+4>>2]=c;return}a:{f=c;c=F[a>>2];g=f-c|0;h=g>>2;d=h+b|0;if(d>>>0<1073741824){e=e-c|0;f=e>>>1|0;d=e>>>0>=2147483644?1073741823:d>>>0>>0?f:d;if(d){if(d>>>0>=1073741824){break a}i=ka(d<<2)}b=b<<2;e=ma((h<<2)+i|0,0,b);f=d<<2;d=pa(i,c,g);F[a+8>>2]=f+d;F[a+4>>2]=b+e;F[a>>2]=d;if(c){ja(c)}return}na();v()}oa();v()}function gc(a,b){var c=0,d=0,e=0,f=0;c=a+4|0;a=Ya(a,b);a:{if((c|0)==(a|0)){break a}b=a+28|0;b=D[a+39|0]<0?F[b>>2]:b;while(1){a=b;b=a+1|0;c=D[a|0];if((c|0)==32|c-9>>>0<5){continue}break}b:{c:{d:{c=D[a|0];switch(c-43|0){case 0:break c;case 2:break d;default:break b}}e=1}c=D[b|0];a=b}if(c-48>>>0<10){while(1){d=(L(d,10)-D[a|0]|0)+48|0;b=D[a+1|0];a=a+1|0;if(b-48>>>0<10){continue}break}}a=e?d:0-d|0;if((a|0)==-1){break a}f=(a|0)!=0}return f}function Qa(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;a=F[a>>2];c=F[a+4>>2];e=F[a+8>>2];if(c>>>0>>0){F[c>>2]=F[b>>2];F[a+4>>2]=c+4;return}a:{d=c;c=F[a>>2];g=d-c|0;d=g>>2;f=d+1|0;if(f>>>0<1073741824){h=d<<2;e=e-c|0;d=e>>>1|0;f=e>>>0>=2147483644?1073741823:f>>>0>>0?d:f;if(f){if(f>>>0>=1073741824){break a}e=ka(f<<2)}else{e=0}d=h+e|0;F[d>>2]=F[b>>2];b=pa(e,c,g);F[a+8>>2]=b+(f<<2);F[a+4>>2]=d+4;F[a>>2]=b;if(c){ja(c)}return}na();v()}oa();v()}function db(a,b,c){var d=0,e=0,f=0,g=0,h=0;f=Z-16|0;Z=f;d=Z-32|0;Z=d;e=Z-16|0;Z=e;F[e+12>>2]=b;F[e+8>>2]=b+c;F[d+24>>2]=F[e+12>>2];F[d+28>>2]=F[e+8>>2];Z=e+16|0;c=Z-16|0;Z=c;h=F[d+28>>2];e=F[d+24>>2];g=h-e|0;if((e|0)!=(h|0)){pa(a,e,g)}F[c+12>>2]=e+g;F[c+8>>2]=a+g;F[d+16>>2]=F[c+12>>2];F[d+20>>2]=F[c+8>>2];Z=c+16|0;F[d+12>>2]=(F[d+16>>2]-b|0)+b;F[d+8>>2]=(F[d+20>>2]-a|0)+a;F[f+8>>2]=F[d+12>>2];F[f+12>>2]=F[d+8>>2];Z=d+32|0;Z=f+16|0}function _a(a,b){var c=0,d=0,e=0,f=0,g=0,h=0,i=0;e=F[a+8>>2];c=F[a+4>>2];if(e-c>>3>>>0>=b>>>0){if(b){b=b<<3;c=ma(c,0,b)+b|0}F[a+4>>2]=c;return}a:{f=c;c=F[a>>2];g=f-c|0;h=g>>3;d=h+b|0;if(d>>>0<536870912){e=e-c|0;f=e>>>2|0;d=e>>>0>=2147483640?536870911:d>>>0>>0?f:d;if(d){if(d>>>0>=536870912){break a}i=ka(d<<3)}b=b<<3;e=ma((h<<3)+i|0,0,b);f=d<<3;d=pa(i,c,g);F[a+8>>2]=f+d;F[a+4>>2]=b+e;F[a>>2]=d;if(c){ja(c)}return}na();v()}oa();v()}function re(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=2016;b=F[a+60>>2];F[a+60>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}d=F[a+36>>2];if(d){c=F[a+40>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=F[a+36>>2]}F[a+40>>2]=d;ja(b)}F[a>>2]=1776;b=F[a+16>>2];if(b){F[a+20>>2]=b;ja(b)}b=F[a+4>>2];if(b){F[a+8>>2]=b;ja(b)}return a|0}function qe(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=2016;b=F[a+60>>2];F[a+60>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}d=F[a+36>>2];if(d){c=F[a+40>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=F[a+36>>2]}F[a+40>>2]=d;ja(b)}F[a>>2]=1776;b=F[a+16>>2];if(b){F[a+20>>2]=b;ja(b)}b=F[a+4>>2];if(b){F[a+8>>2]=b;ja(b)}ja(a)}function Eg(a){a=a|0;var b=0,c=0,d=0,e=0,f=0;a:{b=F[a+8>>2];b:{if((b|0)<0){break b}c=F[a+4>>2];e=F[c>>2];d=F[c+4>>2]-e>>2;c:{if(d>>>0>>0){nd(c,b-d|0);f=F[a+8>>2];break c}f=b;if(b>>>0>=d>>>0){break c}F[c+4>>2]=e+(b<<2);f=b}d=f;if((d|0)<=0){break b}a=F[a+4>>2];c=F[a>>2];e=F[a+4>>2]-c>>2;a=0;while(1){if((a|0)==(e|0)){break a}F[c+(a<<2)>>2]=a;a=a+1|0;if((d|0)!=(a|0)){continue}break}}return(b^-1)>>>31|0}ta();v()}function fh(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;d=Z-16|0;Z=d;e=F[a+4>>2];a:{if((e|0)==-1){break a}c=F[b+20>>2];if(!!F[b+16>>2]&(c|0)>=0|(c|0)>0){break a}pb(b,F[b+4>>2],F[a+8>>2],F[a+12>>2]);c=F[b+20>>2];if(!!F[b+16>>2]&(c|0)>=0|(c|0)>0){break a}pb(b,F[b+4>>2],a+20|0,a+24|0);c=F[b+20>>2];f=F[b+16>>2];D[d+15|0]=F[a+4>>2];if(!!f&(c|0)>=0|(c|0)>0){break a}pb(b,F[b+4>>2],d+15|0,d+16|0)}Z=d+16|0;return(e|0)!=-1|0}function kd(a,b){var c=0,d=0,e=0,f=0,g=0,h=0;e=F[a+8>>2];c=F[a+4>>2];if(e-c>>1>>>0>=b>>>0){if(b){b=b<<1;c=ma(c,0,b)+b|0}F[a+4>>2]=c;return}a:{f=c;c=F[a>>2];g=f-c|0;f=g>>1;d=f+b|0;if((d|0)>=0){e=e-c|0;d=e>>>0>=2147483646?2147483647:d>>>0>>0?e:d;if(d){if((d|0)<0){break a}h=ka(d<<1)}b=b<<1;e=ma((f<<1)+h|0,0,b);f=d<<1;d=pa(h,c,g);F[a+8>>2]=f+d;F[a+4>>2]=b+e;F[a>>2]=d;if(c){ja(c)}return}na();v()}oa();v()}function of(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;d=Z-16|0;Z=d;Pd(d,a,b,c);F[a+24>>2]=F[d>>2];e=a+24|0;a:{if((e|0)==(d|0)){break a}b=a+28|0;c=d|4;f=G[d+15|0];g=f<<24>>24;if(D[a+39|0]>=0){if((g|0)>=0){a=F[c+4>>2];F[b>>2]=F[c>>2];F[b+4>>2]=a;F[b+8>>2]=F[c+8>>2];break a}qb(b,F[d+4>>2],F[d+8>>2]);break a}a=(g|0)<0;rb(b,a?F[d+4>>2]:c,a?F[d+8>>2]:f)}if(D[d+15|0]<0){ja(F[d+4>>2])}Z=d+16|0;return e|0}function ra(a,b,c){var d=0,e=0,f=0,g=0;e=Z-16|0;Z=e;a:{b:{if(c>>>0<11){d=a;D[a+11|0]=G[a+11|0]&128|c;D[a+11|0]=G[a+11|0]&127;break b}if(c>>>0>2147483631){break a}g=e+8|0;if(c>>>0>=11){f=c+16&-16;d=f-1|0;d=(d|0)==11?f:d}else{d=10}sb(g,d+1|0);d=F[e+8>>2];F[a>>2]=d;F[a+8>>2]=F[a+8>>2]&-2147483648|F[e+12>>2]&2147483647;F[a+8>>2]=F[a+8>>2]|-2147483648;F[a+4>>2]=c}db(d,b,c+1|0);Z=e+16|0;return}za();v()}function pf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;b=Z-16|0;Z=b;Od(b);F[a+24>>2]=F[b>>2];e=a+24|0;a:{if((e|0)==(b|0)){break a}c=a+28|0;d=b|4;f=G[b+15|0];g=f<<24>>24;if(D[a+39|0]>=0){if((g|0)>=0){a=F[d+4>>2];F[c>>2]=F[d>>2];F[c+4>>2]=a;F[c+8>>2]=F[d+8>>2];break a}qb(c,F[b+4>>2],F[b+8>>2]);break a}a=(g|0)<0;rb(c,a?F[b+4>>2]:d,a?F[b+8>>2]:f)}if(D[b+15|0]<0){ja(F[b+4>>2])}Z=b+16|0;return e|0}function Rf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0;d=Z-16|0;Z=d;a:{e=ya(c);if(e>>>0<2147483632){b:{c:{if(e>>>0>=11){g=(e|15)+1|0;f=ka(g);F[d+8>>2]=g|-2147483648;F[d>>2]=f;F[d+4>>2]=e;g=e+f|0;break c}D[d+11|0]=e;g=d+e|0;f=d;if(!e){break b}}la(f,c,e)}D[g|0]=0;f=a+16|0;c=Sc(b,d,f);b=F[a+16>>2];a=D[a+27|0];if(D[d+11|0]<0){ja(F[d>>2])}Z=d+16|0;a=c?(a|0)<0?b:f:0;break a}za();v()}return a|0}function Yb(a,b){var c=0,d=0,e=0;c=F[a+4>>2];d=c+b|0;F[a+4>>2]=d;if(!((d-1^c-1)>>>0<32?c:0)){F[F[a>>2]+((d>>>0>=33?d-1>>>5|0:0)<<2)>>2]=0}a:{if(!b){break a}a=F[a>>2]+(c>>>3&536870908)|0;c=c&31;if(c){d=32-c|0;e=b>>>0>d>>>0?d:b;F[a>>2]=F[a>>2]&(-1<>>d-e^-1);b=b-e|0;a=a+4|0}c=b>>>5|0;if(b>>>0>=32){ma(a,0,c<<2)}if((b&-32)==(b|0)){break a}a=(c<<2)+a|0;F[a>>2]=F[a>>2]&(-1>>>32-(b&31)^-1)}}function ld(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>10){break a}d=F[c+20>>2];f=F[c+12>>2];e=F[c+16>>2];if((d|0)>=(f|0)&e>>>0>=I[c+8>>2]|(d|0)>(f|0)){break a}f=D[e+F[c>>2]|0];e=e+1|0;d=e?d:d+1|0;F[c+16>>2]=e;F[c+20>>2]=d;d=f;b:{if((d|0)<0){if(!ld(a+1|0,b,c)){break a}a=F[b>>2];d=d&127|a<<7;a=F[b+4>>2]<<7|a>>>25;break b}d=d&255;a=0}F[b>>2]=d;F[b+4>>2]=a;g=1}return g}function Sa(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>10){break a}d=F[c+20>>2];f=F[c+12>>2];e=F[c+16>>2];if((d|0)>=(f|0)&e>>>0>=I[c+8>>2]|(d|0)>(f|0)){break a}f=D[e+F[c>>2]|0];e=e+1|0;d=e?d:d+1|0;F[c+16>>2]=e;F[c+20>>2]=d;d=f;b:{if((d|0)<0){if(!Sa(a+1|0,b,c)){break a}a=F[b>>2];d=d&127|a<<7;a=F[b+4>>2]<<7|a>>>25;break b}d=d&255;a=0}F[b>>2]=d;F[b+4>>2]=a;g=1}return g}function Ne(a,b,c,d,e){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;if(La(a,F[b+8>>2],e)){if(!(F[b+28>>2]==1|F[b+4>>2]!=(c|0))){F[b+28>>2]=d}return}a:{if(!La(a,F[b>>2],e)){break a}if(!(F[b+16>>2]!=(c|0)&F[b+20>>2]!=(c|0))){if((d|0)!=1){break a}F[b+32>>2]=1;return}F[b+20>>2]=c;F[b+32>>2]=d;F[b+40>>2]=F[b+40>>2]+1;if(!(F[b+36>>2]!=1|F[b+24>>2]!=2)){D[b+54|0]=1}F[b+44>>2]=4}}function jg(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;e=Z+-64|0;Z=e;d=$[F[F[a>>2]+44>>2]](a,b)|0;a=$[F[F[a>>2]+40>>2]](a,b)|0;f=kb(e);g=F[b+56>>2];h=d&255;i=a;a=a-1|0;if(a>>>0<=10){a=F[(a<<2)+10148>>2]}else{a=-1}d=L(a,d);cc(f,g,h,i,0,d,d>>31);a=bc(ka(96),f);ac(a,c);D[a+84|0]=1;F[a+72>>2]=F[a+68>>2];F[a+60>>2]=F[b+60>>2];Z=e- -64|0;return a|0}function rh(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=8176;b=F[a+48>>2];F[a+48>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}F[a>>2]=10032;b=F[a+20>>2];if(b){F[a+24>>2]=b;ja(b)}d=F[a+8>>2];if(d){c=F[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=F[a+8>>2]}F[a+12>>2]=d;ja(b)}return a|0}function Dc(a,b,c,d){D[a+53|0]=1;a:{if(F[a+4>>2]!=(c|0)){break a}D[a+52|0]=1;c=F[a+16>>2];b:{if(!c){F[a+36>>2]=1;F[a+24>>2]=d;F[a+16>>2]=b;if((d|0)!=1){break a}if(F[a+48>>2]==1){break b}break a}if((b|0)==(c|0)){c=F[a+24>>2];if((c|0)==2){F[a+24>>2]=d;c=d}if(F[a+48>>2]!=1){break a}if((c|0)==1){break b}break a}F[a+36>>2]=F[a+36>>2]+1}D[a+54|0]=1}}function qh(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=8176;b=F[a+48>>2];F[a+48>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}F[a>>2]=10032;b=F[a+20>>2];if(b){F[a+24>>2]=b;ja(b)}d=F[a+8>>2];if(d){c=F[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=F[a+8>>2]}F[a+12>>2]=d;ja(b)}ja(a)}function Se(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;e=Z+-64|0;Z=e;d=1;a:{if(La(a,b,0)){break a}d=0;if(!b){break a}b=Fc(b,11068);d=0;if(!b){break a}d=e+8|0;ma(d|4,0,52);F[e+56>>2]=1;F[e+20>>2]=-1;F[e+16>>2]=a;F[e+8>>2]=b;$[F[F[b>>2]+28>>2]](b,d,F[c>>2],1);a=F[e+32>>2];if((a|0)==1){F[c>>2]=F[e+24>>2]}d=(a|0)==1}Z=e- -64|0;return d|0}function Fd(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=Z-16|0;Z=d;F[a+4>>2]=b;b=F[b+64>>2];e=F[b>>2];b=F[b+4>>2];D[d+15|0]=0;Ea(a+24|0,(b-e>>2>>>0)/3|0,d+15|0);b=F[a+4>>2];e=F[b+56>>2];b=F[b+52>>2];D[d+14|0]=0;Ea(a+36|0,e-b>>2,d+14|0);b=F[c+12>>2];F[a+16>>2]=F[c+8>>2];F[a+20>>2]=b;b=F[c+4>>2];F[a+8>>2]=F[c>>2];F[a+12>>2]=b;Z=d+16|0}function zf(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;a=Z-16|0;Z=a;f=D[b+24|0];e=F[2555];F[a+8>>2]=F[2554];F[a+12>>2]=e;e=F[2553];F[a>>2]=F[2552];F[a+4>>2]=e;e=lb(b,c,f,a);if(e){b=0;if(f){c=(f&255)<<2;b=ka(c);g=la(b,a,c)+c|0}c=F[d>>2];if(c){F[d+4>>2]=c;ja(c)}F[d+8>>2]=g;F[d+4>>2]=g;F[d>>2]=b}Z=a+16|0;return e|0}function wd(a,b){var c=0,d=0;a:{c=F[a+4>>2];d=F[a+8>>2];if((c|0)==d<<5){if((c+1|0)<0){break a}if(c>>>0<=1073741822){d=d<<6;c=(c&-32)+32|0;c=c>>>0>>0?d:c}else{c=2147483647}$a(a,c);c=F[a+4>>2]}F[a+4>>2]=c+1;d=1<>2]+(c>>>3&536870908)|0;if(G[b|0]){F[a>>2]=d|F[a>>2];return}F[a>>2]=F[a>>2]&(d^-1);return}na();v()}function Zb(a){var b=0;F[a>>2]=0;F[a+4>>2]=0;F[a+56>>2]=0;F[a+48>>2]=0;F[a+52>>2]=0;F[a+40>>2]=0;F[a+44>>2]=0;F[a+32>>2]=0;F[a+36>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+8>>2]=0;F[a+12>>2]=0;b=a- -64|0;F[b>>2]=0;F[b+4>>2]=0;F[a+72>>2]=0;F[a+76>>2]=0;F[a+80>>2]=0;F[a+84>>2]=0;F[a+60>>2]=a;return a}function ve(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;f=$[F[F[a>>2]+24>>2]](a)|0;c=1;a:{if((f|0)<=0){break a}d=F[F[a+36>>2]>>2];g=a+48|0;c=0;if(!($[F[F[d>>2]+16>>2]](d,g,b)|0)){break a}while(1){e=e+1|0;if((f|0)!=(e|0)){d=F[F[a+36>>2]+(e<<2)>>2];if($[F[F[d>>2]+16>>2]](d,g,b)|0){continue}}break}c=(e|0)>=(f|0)}return c|0}function ue(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0;f=$[F[F[a>>2]+24>>2]](a)|0;c=1;a:{if((f|0)<=0){break a}d=F[F[a+36>>2]>>2];g=a+48|0;c=0;if(!($[F[F[d>>2]+20>>2]](d,g,b)|0)){break a}while(1){e=e+1|0;if((f|0)!=(e|0)){d=F[F[a+36>>2]+(e<<2)>>2];if($[F[F[d>>2]+20>>2]](d,g,b)|0){continue}}break}c=(e|0)>=(f|0)}return c|0}function bh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=Z-16|0;Z=d;F[a+4>>2]=b;e=F[b>>2];b=F[b+4>>2];D[d+15|0]=0;Ea(a+24|0,(b-e>>2>>>0)/3|0,d+15|0);b=F[a+4>>2];e=F[b+28>>2];b=F[b+24>>2];D[d+14|0]=0;Ea(a+36|0,e-b>>2,d+14|0);b=F[c+12>>2];F[a+16>>2]=F[c+8>>2];F[a+20>>2]=b;b=F[c+4>>2];F[a+8>>2]=F[c>>2];F[a+12>>2]=b;Z=d+16|0}function hb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!hb(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function fb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!fb(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function Wb(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Wb(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function Ta(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Ta(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function Qd(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Qd(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function Oa(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Oa(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function Da(a,b,c){var d=0,e=0,f=0,g=0;a:{if(a>>>0>5){break a}d=F[c+20>>2];e=F[c+12>>2];f=F[c+16>>2];if((d|0)>=(e|0)&f>>>0>=I[c+8>>2]|(d|0)>(e|0)){break a}e=G[F[c>>2]+f|0];f=f+1|0;d=f?d:d+1|0;F[c+16>>2]=f;F[c+20>>2]=d;d=e<<24>>24;if((d|0)<0){if(!Da(a+1|0,b,c)){break a}e=d&127|F[b>>2]<<7}F[b>>2]=e;g=1}return g}function sa(a,b,c){var d=0,e=0;a:{b:{if(c>>>0>=4){if((a|b)&3){break b}while(1){if(F[a>>2]!=F[b>>2]){break b}b=b+4|0;a=a+4|0;c=c-4|0;if(c>>>0>3){continue}break}}if(!c){break a}}while(1){d=G[a|0];e=G[b|0];if((d|0)==(e|0)){b=b+1|0;a=a+1|0;c=c-1|0;if(c){continue}break a}break}return d-e|0}return 0}function td(a){var b=0,c=0,d=0,e=0;d=F[a>>2];if(d){e=d;c=F[a+4>>2];if((d|0)!=(c|0)){while(1){e=c-144|0;b=F[e+132>>2];if(b){F[c-8>>2]=b;ja(b)}b=F[c-28>>2];if(b){F[c-24>>2]=b;ja(b)}b=F[c-40>>2];if(b){F[c-36>>2]=b;ja(b)}Gb(c-140|0);c=e;if((d|0)!=(c|0)){continue}break}e=F[a>>2]}F[a+4>>2]=d;ja(e)}}function Ef(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=F[b+4>>2];a:{if(!d){break a}b=F[F[F[b+8>>2]+(c<<2)>>2]+60>>2];if((b|0)<0){break a}a=F[d+24>>2];c=F[d+28>>2];if((a|0)==(c|0)){break a}b:{while(1){e=F[a>>2];if((b|0)==F[e+24>>2]){break b}a=a+4|0;if((c|0)!=(a|0)){continue}break}e=0}}return e|0}function ic(a){var b=0,c=0,d=0;if(a){d=F[a+24>>2];if(d){b=d;c=F[a+28>>2];if((b|0)!=(c|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){Ca(b+12|0,F[b+16>>2]);Ba(b,F[b+4>>2]);ja(b)}if((c|0)!=(d|0)){continue}break}b=F[a+24>>2]}F[a+28>>2]=d;ja(b)}Ca(a+12|0,F[a+16>>2]);Ba(a,F[a+4>>2]);ja(a)}}function $g(a){a=a|0;var b=0;F[a+8>>2]=9136;F[a>>2]=8924;b=F[a+96>>2];if(b){F[a+100>>2]=b;ja(b)}b=F[a+80>>2];if(b){F[a+84>>2]=b;ja(b)}b=F[a+68>>2];if(b){F[a+72>>2]=b;ja(b)}b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}F[a+8>>2]=9372;b=F[a+44>>2];if(b){ja(b)}b=F[a+32>>2];if(b){ja(b)}return a|0}function _g(a){a=a|0;var b=0;F[a+8>>2]=9136;F[a>>2]=8924;b=F[a+96>>2];if(b){F[a+100>>2]=b;ja(b)}b=F[a+80>>2];if(b){F[a+84>>2]=b;ja(b)}b=F[a+68>>2];if(b){F[a+72>>2]=b;ja(b)}b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}F[a+8>>2]=9372;b=F[a+44>>2];if(b){ja(b)}b=F[a+32>>2];if(b){ja(b)}ja(a)}function wh(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=10032;b=F[a+20>>2];if(b){F[a+24>>2]=b;ja(b)}d=F[a+8>>2];if(d){c=F[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=F[a+8>>2]}F[a+12>>2]=d;ja(b)}return a|0}function uc(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0,f=0,g=0,h=0,i=0;h=F[c+8>>2];e=F[c+16>>2];g=F[c+12>>2];f=g;d=F[c+20>>2];if(h>>>0>e>>>0&(f|0)>=(d|0)|(d|0)<(f|0)){b=G[F[c>>2]+e|0];i=e+1|0;f=i?d:d+1|0;F[c+16>>2]=i;F[c+20>>2]=f;F[a+4>>2]=b}return e>>>0>>0&(d|0)<=(g|0)|(d|0)<(g|0)}function La(a,b,c){var d=0;if(!c){return F[a+4>>2]==F[b+4>>2]}if((a|0)==(b|0)){return 1}d=F[a+4>>2];a=G[d|0];c=F[b+4>>2];b=G[c|0];a:{if(!a|(b|0)!=(a|0)){break a}while(1){b=G[c+1|0];a=G[d+1|0];if(!a){break a}c=c+1|0;d=d+1|0;if((a|0)==(b|0)){continue}break}}return(a|0)==(b|0)}function Gg(a){a=a|0;var b=0,c=0,d=0;F[a>>2]=10032;b=F[a+20>>2];if(b){F[a+24>>2]=b;ja(b)}d=F[a+8>>2];if(d){c=F[a+12>>2];b=d;if((c|0)!=(b|0)){while(1){c=c-4|0;b=F[c>>2];F[c>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}if((c|0)!=(d|0)){continue}break}b=F[a+8>>2]}F[a+12>>2]=d;ja(b)}ja(a)}function Gf(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=F[b+12>>2];b=F[b+8>>2];a=0;a:{if((d|0)==(b|0)){break a}a=d-b>>2;d=a>>>0<=1?1:a;a=0;b:{while(1){e=F[b+(a<<2)>>2];if(F[e+60>>2]==(c|0)){break b}a=a+1|0;if((d|0)!=(a|0)){continue}break}a=0;break a}a=(a|0)!=-1?e:0}return a|0}function ah(a){a=a|0;var b=0;F[a>>2]=9136;b=F[a+88>>2];if(b){F[a+92>>2]=b;ja(b)}b=F[a+72>>2];if(b){F[a+76>>2]=b;ja(b)}b=F[a+60>>2];if(b){F[a- -64>>2]=b;ja(b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}F[a>>2]=9372;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}return a|0}function Tc(a,b){var c=0,d=0,e=0;F[a+8>>2]=0;F[a>>2]=0;F[a+4>>2]=0;a:{c=F[b+4>>2];d=F[b>>2];b:{if((c|0)==(d|0)){a=c;break b}c=c-d|0;if((c|0)<0){break a}d=c;e=ka(c);c=ma(e,0,c);d=d+c|0;F[a+8>>2]=d;F[a+4>>2]=d;F[a>>2]=c;c=F[b>>2];a=F[b+4>>2]}la(e,c,a-c|0);return}na();v()}function Dd(a){var b=0,c=0,d=0,e=0;c=F[a+4>>2];d=F[a>>2];if((c|0)!=(d|0)){while(1){e=c-144|0;b=F[e+132>>2];if(b){F[c-8>>2]=b;ja(b)}b=F[c-28>>2];if(b){F[c-24>>2]=b;ja(b)}b=F[c-40>>2];if(b){F[c-36>>2]=b;ja(b)}Gb(c-140|0);c=e;if((d|0)!=(c|0)){continue}break}}F[a+4>>2]=d}function Xg(a){a=a|0;var b=0;F[a>>2]=9136;b=F[a+88>>2];if(b){F[a+92>>2]=b;ja(b)}b=F[a+72>>2];if(b){F[a+76>>2]=b;ja(b)}b=F[a+60>>2];if(b){F[a- -64>>2]=b;ja(b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}F[a>>2]=9372;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}ja(a)}function Za(a){var b=0;if(a){b=F[a+76>>2];if(b){F[a+80>>2]=b;ja(b)}b=F[a- -64>>2];if(b){F[a+68>>2]=b;ja(b)}b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}b=F[a+24>>2];if(b){F[a+28>>2]=b;ja(b)}b=F[a+12>>2];if(b){F[a+16>>2]=b;ja(b)}b=F[a>>2];if(b){F[a+4>>2]=b;ja(b)}ja(a)}}function Gb(a){var b=0;b=F[a+84>>2];if(b){F[a+88>>2]=b;ja(b)}b=F[a+72>>2];if(b){F[a+76>>2]=b;ja(b)}b=F[a+52>>2];if(b){F[a+56>>2]=b;ja(b)}b=F[a+40>>2];if(b){F[a+44>>2]=b;ja(b)}b=F[a+28>>2];if(b){F[a+32>>2]=b;ja(b)}b=F[a+12>>2];if(b){ja(b)}a=F[a>>2];if(a){ja(a)}}function Lc(a,b,c){var d=0,e=0,f=0,g=0;f=Z-16|0;Z=f;d=Z-16|0;Z=d;b=b-a>>2;while(1){if(b){F[d+12>>2]=a;e=b>>>1|0;F[d+12>>2]=F[d+12>>2]+(e<<2);g=(e^-1)+b|0;b=e;e=I[F[d+12>>2]>>2]>2];b=e?g:b;a=e?F[d+12>>2]+4|0:a;continue}break}Z=d+16|0;Z=f+16|0;return a}function id(a,b){var c=0,d=0;d=ka(40);F[d>>2]=-1;c=d+8|0;F[c+16>>2]=0;F[c+20>>2]=0;F[c+8>>2]=0;F[c>>2]=0;F[c+4>>2]=0;F[c+24>>2]=0;F[c+28>>2]=0;$[F[F[a>>2]+16>>2]](a,d);a=F[b+88>>2];F[b+88>>2]=d;if(a){b=F[a+8>>2];if(b){F[a+12>>2]=b;ja(b)}ja(a)}return 1}function ya(a){var b=0,c=0,d=0;b=a;a:{if(b&3){while(1){if(!G[b|0]){break a}b=b+1|0;if(b&3){continue}break}}while(1){c=b;b=b+4|0;d=F[c>>2];if(!((d^-1)&d-16843009&-2139062144)){continue}break}while(1){b=c;c=b+1|0;if(G[b|0]){continue}break}}return b-a|0}function wa(a){var b=0,c=0,d=0,e=0,f=0;d=G[a+12|0];c=F[a+8>>2];a:{if(c>>>0>4095){break a}b=F[a+4>>2];if((b|0)<=0){break a}b=b-1|0;F[a+4>>2]=b;c=G[b+F[a>>2]|0]|c<<8}d=0-d&255;b=L(d,c>>>8|0);e=c&255;f=e>>>0>>0;F[a+8>>2]=f?b+e|0:c-(b+d|0)|0;return f}function yc(a,b){F[a+4>>2]=0;F[a+8>>2]=0;F[a>>2]=1776;F[a+12>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;F[a+32>>2]=0;F[a+36>>2]=0;F[a+40>>2]=0;F[a>>2]=2016;F[a+60>>2]=b;F[a+44>>2]=0;F[a+48>>2]=0;F[a+52>>2]=0;F[a+56>>2]=0;return a}function Eb(a,b){var c=0,d=0,e=0;c=ya(b);if(c>>>0<2147483632){a:{b:{if(c>>>0>=11){d=(c|15)+1|0;e=ka(d);F[a+8>>2]=d|-2147483648;F[a>>2]=e;F[a+4>>2]=c;d=c+e|0;break b}D[a+11|0]=c;d=a+c|0;e=a;if(!c){break a}}pa(e,b,c)}D[d|0]=0;return a}za();v()}function Of(a){a=a|0;var b=0,c=0,d=0;if(a){if(D[a+27|0]<0){ja(F[a+16>>2])}b=F[a>>2];if(b){c=b;d=F[a+4>>2];if((b|0)!=(d|0)){while(1){c=d-12|0;if(D[d-1|0]<0){ja(F[c>>2])}d=c;if((d|0)!=(b|0)){continue}break}c=F[a>>2]}F[a+4>>2]=b;ja(c)}ja(a)}}function xa(a){a=a|0;var b=0,c=0;if(a){b=F[a+88>>2];F[a+88>>2]=0;if(b){c=F[b+8>>2];if(c){F[b+12>>2]=c;ja(c)}ja(b)}b=F[a+68>>2];if(b){F[a+72>>2]=b;ja(b)}b=F[a+64>>2];F[a+64>>2]=0;if(b){c=F[b>>2];if(c){F[b+4>>2]=c;ja(c)}ja(b)}ja(a)}}function Ib(a,b){var c=0,d=0,e=0;a:{c=F[a>>2];b:{if(F[a+8>>2]-c>>2>>>0>=b>>>0){break b}if(b>>>0>=1073741824){break a}d=F[a+4>>2]-c|0;e=b<<2;b=pa(ka(e),c,d);F[a+8>>2]=b+e;F[a+4>>2]=b+d;F[a>>2]=b;if(!c){break b}ja(c)}return}na();v()}function Df(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;b=F[b+96>>2];a=ka(12);b=b+L(c,12)|0;c=F[b+4>>2];F[a>>2]=F[b>>2];F[a+4>>2]=c;F[a+8>>2]=F[b+8>>2];b=F[d>>2];if(b){F[d+4>>2]=b;ja(b)}F[d>>2]=a;a=a+12|0;F[d+8>>2]=a;F[d+4>>2]=a;return 1}function Ah(a){a=a|0;var b=0;F[a+24>>2]=1624;F[a>>2]=7948;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}F[a>>2]=2136;b=F[a+20>>2];F[a+20>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}F[a>>2]=1920;b=F[a+16>>2];F[a+16>>2]=0;if(b){xa(b)}return a|0}function li(a,b,c,d){var e=0,f=0,g=0,h=0;f=b^d;g=f>>31;e=b>>31;a=a^e;h=a-e|0;e=(b^e)-((a>>>0>>0)+e|0)|0;a=d>>31;b=c^a;f=f>>31;a=mi(h,e,b-a|0,(a^d)-((a>>>0>b>>>0)+a|0)|0)^f;b=a-f|0;_=(g^_)-((a>>>0>>0)+g|0)|0;return b}function zh(a){a=a|0;var b=0;F[a+24>>2]=1624;F[a>>2]=7948;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}F[a>>2]=2136;b=F[a+20>>2];F[a+20>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}F[a>>2]=1920;b=F[a+16>>2];F[a+16>>2]=0;if(b){xa(b)}ja(a)}function rb(a,b,c){var d=0,e=0,f=0;e=Z-16|0;Z=e;d=F[a+8>>2]&2147483647;a:{if(d>>>0>c>>>0){d=F[a>>2];F[a+4>>2]=c;db(d,b,c);D[e+15|0]=0;D[c+d|0]=G[e+15|0];break a}f=a;a=F[a+4>>2];Gc(f,d-1|0,(c-d|0)+1|0,a,a,c,b)}Z=e+16|0}function xe(a,b){a=a|0;b=b|0;var c=0,d=0;c=Z-16|0;Z=c;a=F[a+4>>2];a:{if((a|0)==-1){break a}D[c+15|0]=a;d=F[b+20>>2];if(!!F[b+16>>2]&(d|0)>=0|(d|0)>0){break a}pb(b,F[b+4>>2],c+15|0,c+16|0)}Z=c+16|0;return(a|0)!=-1|0}function ki(a,b,c,d){var e=0,f=0,g=0,h=0,i=0,j=0;e=c>>>16|0;f=a>>>16|0;j=L(e,f);g=c&65535;h=a&65535;i=L(g,h);f=(i>>>16|0)+L(f,g)|0;e=(f&65535)+L(e,h)|0;_=(L(b,c)+j|0)+L(a,d)+(f>>>16)+(e>>>16)|0;return i&65535|e<<16}function qb(a,b,c){var d=0,e=0;d=Z-16|0;Z=d;a:{if(c>>>0<=10){D[a+11|0]=G[a+11|0]&128|c;D[a+11|0]=G[a+11|0]&127;db(a,b,c);D[d+15|0]=0;D[a+c|0]=G[d+15|0];break a}e=a;a=G[a+11|0]&127;Gc(e,10,c-10|0,a,a,c,b)}Z=d+16|0}function Ec(a,b,c){var d=0;d=F[a+16>>2];if(!d){F[a+36>>2]=1;F[a+24>>2]=c;F[a+16>>2]=b;return}a:{if((b|0)==(d|0)){if(F[a+24>>2]!=2){break a}F[a+24>>2]=c;return}D[a+54|0]=1;F[a+24>>2]=2;F[a+36>>2]=F[a+36>>2]+1}}function vg(){var a=0;a=kb(ka(96));F[a+64>>2]=0;F[a+68>>2]=0;F[a+88>>2]=0;F[a+72>>2]=0;F[a+76>>2]=0;D[a+77|0]=0;D[a+78|0]=0;D[a+79|0]=0;D[a+80|0]=0;D[a+81|0]=0;D[a+82|0]=0;D[a+83|0]=0;D[a+84|0]=0;return a|0}function jh(a,b){a=a|0;b=b|0;var c=0,d=0;F[b>>2]=2;c=F[b+8>>2];d=F[b+12>>2]-c|0;if(d>>>0<=4294967291){Db(b+8|0,d+4|0);c=F[b+8>>2]}b=c+d|0;a=F[a+4>>2];D[b|0]=a;D[b+1|0]=a>>>8;D[b+2|0]=a>>>16;D[b+3|0]=a>>>24}function ge(a){a=a|0;var b=0;F[a>>2]=3016;b=F[a+96>>2];if(b){ja(b)}b=F[a+84>>2];if(b){ja(b)}b=F[a+72>>2];if(b){ja(b)}b=F[a+60>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function ci(a){a=a|0;var b=0;F[a>>2]=4580;b=F[a+96>>2];if(b){ja(b)}b=F[a+84>>2];if(b){ja(b)}b=F[a+72>>2];if(b){ja(b)}b=F[a+60>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function Cg(a){a=a|0;var b=0,c=0,d=0;b=F[a+8>>2];d=F[a+12>>2];if((b|0)==(d|0)){return 1}while(1){c=F[b>>2];c=$[F[F[c>>2]+16>>2]](c,F[a+32>>2])|0;if(c){b=b+4|0;if((d|0)!=(b|0)){continue}}break}return c|0}function Pc(a,b){var c=0,d=0;c=F[a+8>>2];a=F[a+12>>2];if((c|0)!=(a|0)){a=a-c>>2;d=a>>>0<=1?1:a;a=0;while(1){if(F[F[(a<<2)+c>>2]+60>>2]==(b|0)){return a}a=a+1|0;if((d|0)!=(a|0)){continue}break}}return-1}function fe(a){a=a|0;var b=0;F[a>>2]=3016;b=F[a+96>>2];if(b){ja(b)}b=F[a+84>>2];if(b){ja(b)}b=F[a+72>>2];if(b){ja(b)}b=F[a+60>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function bi(a){a=a|0;var b=0;F[a>>2]=4580;b=F[a+96>>2];if(b){ja(b)}b=F[a+84>>2];if(b){ja(b)}b=F[a+72>>2];if(b){ja(b)}b=F[a+60>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function Sc(a,b,c){var d=0,e=0;d=a+4|0;a=Ya(a,b);a:{if((d|0)==(a|0)){break a}b=F[a+32>>2];d=F[a+28>>2];if((b|0)==(d|0)){break a}Sb(c,b-d|0);c=Tb(c);b=F[a+28>>2];la(c,b,F[a+32>>2]-b|0);e=1}return e}function Kd(a){F[a+40>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;F[a>>2]=10032;F[a+12>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;F[a+32>>2]=0;E[a+36>>1]=0;F[a+44>>2]=0;F[a>>2]=8080;return a}function kb(a){F[a+8>>2]=0;F[a+12>>2]=0;F[a>>2]=0;F[a+40>>2]=0;F[a+44>>2]=0;F[a+28>>2]=9;D[a+24|0]=1;F[a+56>>2]=-1;F[a+60>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+48>>2]=0;F[a+52>>2]=0;return a}function pe(a,b){a=a|0;b=b|0;var c=0,d=0;d=F[a+16>>2];c=0;a:{if(F[a+20>>2]-d>>2<=(b|0)){break a}b=F[(b<<2)+d>>2];c=0;if((b|0)<0){break a}c=bb(F[F[a+36>>2]+(b<<2)>>2])}return c|0}function Nf(){var a=0,b=0;a=ka(40);F[a+4>>2]=0;F[a+8>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;b=a+16|0;F[b>>2]=0;F[b+4>>2]=0;F[a>>2]=a+4;F[a+12>>2]=b;F[a+32>>2]=0;F[a+36>>2]=0;return a|0}function Xe(a,b){a=a|0;b=b|0;var c=0,d=0;Nc(a,b);a:{if((b|0)<0){break a}d=F[a+88>>2];c=F[a+84>>2];if(d-c>>2<=(b|0)){break a}c=(b<<2)+c|0;b=c+4|0;pa(c,b,d-b|0);F[a+88>>2]=d-4}}function eb(a){var b=0,c=0;b=F[2909];c=a+7&-8;a=b+c|0;a:{if(a>>>0<=b>>>0?c:0){break a}if(a>>>0>aa()<<16>>>0){if(!(X(a|0)|0)){break a}}F[2909]=a;return b}F[2940]=48;return-1}function Th(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;F[a+4>>2]=b;b=F[F[F[b+4>>2]+8>>2]+(c<<2)>>2];F[a+12>>2]=c;F[a+8>>2]=b;a=F[a+8>>2];if(G[a+24|0]==3){d=F[a+28>>2]==9}return d|0}function Tg(a){a=a|0;var b=0;F[a+8>>2]=9556;F[a>>2]=9392;b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}F[a+8>>2]=9372;b=F[a+44>>2];if(b){ja(b)}b=F[a+32>>2];if(b){ja(b)}return a|0}function Ng(a){a=a|0;var b=0;F[a+8>>2]=8624;F[a>>2]=9684;b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}F[a+8>>2]=8876;b=F[a+44>>2];if(b){ja(b)}b=F[a+32>>2];if(b){ja(b)}return a|0}function Ee(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0;d=F[a+8>>2];a:{if(!G[d+24|0]){break a}if(!ac(d,F[b+4>>2]-F[b>>2]>>2)){break a}e=$[F[F[a>>2]+32>>2]](a,b,c)|0}return e|0}function Fh(a,b,c){a=a|0;b=b|0;c=c|0;var d=0;F[a+4>>2]=b;d=F[F[F[b+4>>2]+8>>2]+(c<<2)>>2];F[a+12>>2]=c;F[a+8>>2]=d;return F[F[F[F[b+4>>2]+8>>2]+(c<<2)>>2]+28>>2]==9|0}function Ca(a,b){if(b){Ca(a,F[b>>2]);Ca(a,F[b+4>>2]);a=F[b+28>>2];F[b+28>>2]=0;if(a){Ca(a+12|0,F[a+16>>2]);Ba(a,F[a+4>>2]);ja(a)}if(D[b+27|0]<0){ja(F[b+16>>2])}ja(b)}}function Sg(a){a=a|0;var b=0;F[a+8>>2]=9556;F[a>>2]=9392;b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}F[a+8>>2]=9372;b=F[a+44>>2];if(b){ja(b)}b=F[a+32>>2];if(b){ja(b)}ja(a)}function Mg(a){a=a|0;var b=0;F[a+8>>2]=8624;F[a>>2]=9684;b=F[a+56>>2];if(b){F[a+60>>2]=b;ja(b)}F[a+8>>2]=8876;b=F[a+44>>2];if(b){ja(b)}b=F[a+32>>2];if(b){ja(b)}ja(a)}function Hc(a,b){var c=0,d=0,e=0,f=0;F[a>>2]=11356;F[a>>2]=11468;c=ya(b);d=ka(c+13|0);F[d+8>>2]=0;F[d+4>>2]=c;F[d>>2]=c;e=a,f=la(d+12|0,b,c+1|0),F[e+4>>2]=f;return a}function hc(a,b,c){a:{if(b){b=0;if(!ld(1,c,a)){break a}}D[a+36|0]=1;F[a+32>>2]=0;b=F[a+16>>2];c=b+F[a>>2]|0;F[a+24>>2]=c;F[a+28>>2]=c+(F[a+8>>2]-b|0);b=1}return b}function Ue(a,b){a=a|0;b=b|0;var c=0;a:{if(!($[F[F[a>>2]+36>>2]](a,b)|0)){break a}if(!($[F[F[a>>2]+40>>2]](a,b)|0)){break a}c=$[F[F[a>>2]+44>>2]](a)|0}return c|0}function _d(a){a=a|0;var b=0;a:{if(!F[a- -64>>2]|!F[a+68>>2]|(!F[a+44>>2]|!F[a+48>>2])){break a}if(!F[a+52>>2]|!F[a+56>>2]){break a}b=F[a+92>>2]!=-1}return b|0}function ii(a,b){a=a|0;b=b|0;var c=0;b=F[b+88>>2];if(!(!b|F[b>>2]!=2)){c=a;a=F[b+8>>2];F[c+4>>2]=G[a|0]|G[a+1|0]<<8|(G[a+2|0]<<16|G[a+3|0]<<24);c=1}return c|0}function wc(a){a=a|0;var b=0;F[a>>2]=2136;b=F[a+20>>2];F[a+20>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}F[a>>2]=1920;b=F[a+16>>2];F[a+16>>2]=0;if(b){xa(b)}return a|0}function Ud(a){a=a|0;var b=0;a:{if(!F[a+48>>2]|!F[a+52>>2]|(!F[a+28>>2]|!F[a+32>>2])){break a}if(!F[a+36>>2]|!F[a+40>>2]){break a}b=F[a+76>>2]!=-1}return b|0}function Ug(a){a=a|0;var b=0;F[a>>2]=9556;b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}F[a>>2]=9372;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}return a|0}function Ed(a){a=a|0;var b=0;F[a>>2]=8624;b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}F[a>>2]=8876;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}return a|0}function vc(a){a=a|0;var b=0;F[a>>2]=2136;b=F[a+20>>2];F[a+20>>2]=0;if(b){$[F[F[b>>2]+4>>2]](b)}F[a>>2]=1920;b=F[a+16>>2];F[a+16>>2]=0;if(b){xa(b)}ja(a)}function yg(){var a=0,b=0;b=ka(40);F[b>>2]=-1;a=b+8|0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+8>>2]=0;F[a>>2]=0;F[a+4>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;return b|0}function eh(a){a=a|0;var b=0;F[a>>2]=8624;b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}F[a>>2]=8876;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}ja(a)}function Og(a){a=a|0;var b=0;F[a>>2]=9556;b=F[a+48>>2];if(b){F[a+52>>2]=b;ja(b)}F[a>>2]=9372;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}ja(a)}function Ja(a){F[a+8>>2]=0;F[a+12>>2]=0;F[a>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+32>>2]=0;F[a+24>>2]=0;F[a+28>>2]=0;E[a+38>>1]=0;D[a+36|0]=0;return a}function Me(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;if(La(a,F[b+8>>2],f)){Dc(b,c,d,e);return}a=F[a+8>>2];$[F[F[a>>2]+20>>2]](a,b,c,d,e,f)}function Eh(a,b,c){a=a|0;b=b|0;c=c|0;a:{if(G[F[a+4>>2]+36|0]>=2){b=0;if(!($[F[F[a>>2]+52>>2]](a)|0)){break a}}b=id(a+24|0,F[a+16>>2])}return b|0}function hg(){var a=0;a=Rc(ka(108));F[a+84>>2]=0;F[a+88>>2]=0;F[a>>2]=10240;F[a+92>>2]=0;F[a+96>>2]=0;F[a+100>>2]=0;F[a+104>>2]=0;return a|0}function Qc(a,b){var c=0;c=-1;a:{if((b|0)==-1|(b|0)>4){break a}b=L(b,12)+a|0;a=F[b+20>>2];if((F[b+24>>2]-a|0)<=0){break a}c=F[a>>2]}return c}function cc(a,b,c,d,e,f,g){F[a>>2]=0;F[a+56>>2]=b;F[a+48>>2]=0;F[a+52>>2]=0;F[a+40>>2]=f;F[a+44>>2]=g;D[a+32|0]=e;F[a+28>>2]=d;D[a+24|0]=c}function Sh(a,b,c){a=a|0;b=b|0;c=c|0;a:{if(G[F[a+4>>2]+36|0]>=2){b=0;if(!uc(a+24|0,bb(a),c)){break a}}b=id(a+24|0,F[a+16>>2])}return b|0}function _e(a){a=a|0;var b=0;F[a>>2]=10240;b=F[a+96>>2];if(b){F[a+100>>2]=b;ja(b)}b=F[a+84>>2];if(b){F[a+88>>2]=b;ja(b)}return tb(a)|0}function Tb(a){var b=0;if(G[a+11|0]>>>7|0){b=F[a+4>>2]}else{b=G[a+11|0]&127}if(!b){sc(1222);v()}if(G[a+11|0]>>>7|0){a=F[a>>2]}return a}function Ze(a){a=a|0;var b=0;F[a>>2]=10240;b=F[a+96>>2];if(b){F[a+100>>2]=b;ja(b)}b=F[a+84>>2];if(b){F[a+88>>2]=b;ja(b)}ja(tb(a))}function ce(a){a=a|0;var b=0;F[a>>2]=3264;b=F[a+76>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function _h(a){a=a|0;var b=0;F[a>>2]=4816;b=F[a+76>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function Ba(a,b){if(b){Ba(a,F[b>>2]);Ba(a,F[b+4>>2]);a=F[b+28>>2];if(a){F[b+32>>2]=a;ja(a)}if(D[b+27|0]<0){ja(F[b+16>>2])}ja(b)}}function Wf(){var a=0;a=ka(28);F[a>>2]=0;F[a+4>>2]=0;F[a+24>>2]=0;F[a+16>>2]=0;F[a+20>>2]=0;F[a+8>>2]=0;F[a+12>>2]=0;return a|0}function We(a){a=a|0;var b=0;F[a>>2]=1776;b=F[a+16>>2];if(b){F[a+20>>2]=b;ja(b)}b=F[a+4>>2];if(b){F[a+8>>2]=b;ja(b)}return a|0}function fg(){var a=0,b=0;a=ka(24);F[a+4>>2]=0;F[a+8>>2]=0;b=a+16|0;F[b>>2]=0;F[b+4>>2]=0;F[a>>2]=a+4;F[a+12>>2]=b;return a|0}function Pe(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;if(La(a,F[b+8>>2],0)){Ec(b,c,d);return}a=F[a+8>>2];$[F[F[a>>2]+28>>2]](a,b,c,d)}function be(a){a=a|0;var b=0;F[a>>2]=3264;b=F[a+76>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function Zh(a){a=a|0;var b=0;F[a>>2]=4816;b=F[a+76>>2];if(b){ja(b)}F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function ka(a){var b=0;a=a?a:1;a:{while(1){b=Ub(a);if(b){break a}b=F[3065];if(b){$[b|0]();continue}break}V();v()}return b}function ib(a,b){if(b){ib(a,F[b>>2]);ib(a,F[b+4>>2]);if(D[b+39|0]<0){ja(F[b+28>>2])}if(D[b+27|0]<0){ja(F[b+16>>2])}ja(b)}}function Cc(a){a=a|0;var b=0,c=0;F[a>>2]=11468;b=F[a+4>>2]-12|0;c=F[b+8>>2]-1|0;F[b+8>>2]=c;if((c|0)<0){ja(b)}return a|0}function ng(){var a=0;a=ka(24);F[a+8>>2]=0;F[a+12>>2]=0;F[a+4>>2]=-1;F[a>>2]=1624;F[a+16>>2]=0;F[a+20>>2]=0;return a|0}function Ac(a,b,c){a=a|0;b=b|0;c=c|0;F[a+4>>2]=b;b=F[F[F[b+4>>2]+8>>2]+(c<<2)>>2];F[a+12>>2]=c;F[a+8>>2]=b;return 1}function pc(a){a=a|0;var b=0;if(!(!F[a+60>>2]|!F[a+44>>2]|(!F[a+48>>2]|!F[a+52>>2]))){b=F[a+56>>2]!=0}return b|0}function Ic(a,b){if(G[a+11|0]>>>7|0){F[a+4>>2]=b;return}D[a+11|0]=G[a+11|0]&128|b;D[a+11|0]=G[a+11|0]&127}function gi(a){a=a|0;var b=0;F[a>>2]=3500;F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function Xh(a){a=a|0;var b=0;F[a>>2]=5040;F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function nf(a){a=a|0;if(a){if(D[a+39|0]<0){ja(F[a+28>>2])}$b(a+12|0,F[a+16>>2]);ib(a,F[a+4>>2]);ja(a)}}function dh(a){a=a|0;var b=0;F[a>>2]=8876;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}return a|0}function Wg(a){a=a|0;var b=0;F[a>>2]=9372;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}return a|0}function ob(a){a=a|0;var b=0;if(!(!F[a+52>>2]|(!F[a+44>>2]|!F[a+48>>2]))){b=F[a+56>>2]!=0}return b|0}function oc(a,b){a=a|0;b=b|0;var c=0;if(!(F[b+56>>2]|!b|G[b+24|0]!=3)){F[a+60>>2]=b;c=1}return c|0}function fi(a){a=a|0;var b=0;F[a>>2]=3500;F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function Wh(a){a=a|0;var b=0;F[a>>2]=5040;F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function zg(a,b,c){a=a|0;b=b|0;c=c|0;F[a+16>>2]=0;F[a+20>>2]=0;F[a>>2]=b;F[a+8>>2]=c;F[a+12>>2]=0}function ch(a){a=a|0;var b=0;F[a>>2]=8876;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}ja(a)}function Zd(a,b){a=a|0;b=b|0;var c=0;if(!(F[b+56>>2]|G[b+24|0]!=3)){F[a- -64>>2]=b;c=1}return c|0}function Vg(a){a=a|0;var b=0;F[a>>2]=9372;b=F[a+36>>2];if(b){ja(b)}b=F[a+24>>2];if(b){ja(b)}ja(a)}function Td(a,b){a=a|0;b=b|0;var c=0;if(!(F[b+56>>2]|G[b+24|0]!=3)){F[a+48>>2]=b;c=1}return c|0}function Le(a,b,c,d,e,f){a=a|0;b=b|0;c=c|0;d=d|0;e=e|0;f=f|0;if(La(a,F[b+8>>2],f)){Dc(b,c,d,e)}}function oa(){var a=0;a=Rb(4);F[a>>2]=11356;F[a>>2]=11316;F[a>>2]=11336;W(a|0,11448,14);v()}function je(a){a=a|0;var b=0;F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}return a|0}function Ae(a){a=a|0;var b=0;F[a>>2]=1920;b=F[a+16>>2];F[a+16>>2]=0;if(b){xa(b)}return a|0}function Pg(a){a=a|0;var b=0;F[a>>2]=1624;b=F[a+8>>2];if(b){F[a+12>>2]=b;ja(b)}return a|0}function Ch(a){a=a|0;var b=0;b=bb(a);return qd(a+24|0,b?b:F[a+8>>2],F[F[a+4>>2]+32>>2])|0}function ze(a){a=a|0;var b=0;F[a>>2]=1920;b=F[a+16>>2];F[a+16>>2]=0;if(b){xa(b)}ja(a)}function Ob(a){a=a|0;var b=0;F[a>>2]=2960;b=F[a+32>>2];if(b){F[a+36>>2]=b;ja(b)}ja(a)}function Hg(a){a=a|0;var b=0;F[a>>2]=1624;b=F[a+8>>2];if(b){F[a+12>>2]=b;ja(b)}ja(a)}function oe(a,b){a=a|0;b=b|0;return $[F[F[a>>2]+48>>2]](a,F[b+4>>2]-F[b>>2]>>2)|0}function $b(a,b){if(b){$b(a,F[b>>2]);$b(a,F[b+4>>2]);ib(b+20|0,F[b+24>>2]);ja(b)}}function xg(a){a=a|0;var b=0;if(a){b=F[a+8>>2];if(b){F[a+12>>2]=b;ja(b)}ja(a)}}function xh(a){a=a|0;if(!F[a+44>>2]){return 0}return $[F[F[a>>2]+48>>2]](a)|0}function ni(a){var b=0;while(1){if(a){a=a-1&a;b=b+1|0;continue}break}return b}function Qe(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;if(La(a,F[b+8>>2],0)){Ec(b,c,d)}}function vh(a,b){a=a|0;b=b|0;a=F[a+48>>2];return $[F[F[a>>2]+20>>2]](a,b)|0}function oi(a){var b=0;b=a&31;a=0-a&31;return(-1>>>b&-2)<>>a} +function oh(a,b){a=a|0;b=b|0;a=F[a+48>>2];return $[F[F[a>>2]+12>>2]](a,b)|0}function nh(a,b){a=a|0;b=b|0;a=F[a+48>>2];return $[F[F[a>>2]+16>>2]](a,b)|0}function Xa(){var a=0;a=ka(12);F[a>>2]=0;F[a+4>>2]=0;F[a+8>>2]=0;return a|0}function Wa(a){a=a|0;var b=0;if(a){b=F[a>>2];if(b){F[a+4>>2]=b;ja(b)}ja(a)}}function mf(a,b,c){a=a|0;b=b|0;c=c|0;F[a+32>>2]=c;F[a+28>>2]=b;return 1}function eg(a){a=a|0;if(a){Ca(a+12|0,F[a+16>>2]);Ba(a,F[a+4>>2]);ja(a)}}function Lb(a,b){a=a|0;b=b|0;if(b>>>0<=1){F[a+28>>2]=b}return b>>>0<2|0}function Fg(a,b){a=a|0;b=b|0;D[b+84|0]=1;F[b+72>>2]=F[b+68>>2];return 1}function kg(){var a=0;a=ka(8);F[a+4>>2]=-1;F[a>>2]=1032;return a|0}function Hf(a,b,c){a=a|0;b=b|0;c=c|0;return F[F[b+8>>2]+(c<<2)>>2]}function th(a){a=a|0;a=F[a+48>>2];return $[F[F[a>>2]+24>>2]](a)|0}function sh(a){a=a|0;a=F[a+48>>2];return $[F[F[a>>2]+28>>2]](a)|0}function ph(a){a=a|0;a=F[a+48>>2];return $[F[F[a>>2]+36>>2]](a)|0}function Rh(a,b){a=a|0;b=b|0;return zc(a+24|0,bb(a),F[a+8>>2])|0}function Bh(a,b){a=a|0;b=b|0;return xd(a+24|0,bb(a),F[a+8>>2])|0}function bg(a){a=a|0;if(a){if(D[a+15|0]<0){ja(F[a+4>>2])}ja(a)}}function Ke(a){a=a|0;if(!a){return 0}return(Fc(a,11164)|0)!=0|0}function Fe(a,b){a=a|0;b=b|0;F[a+12>>2]=-1;F[a+8>>2]=b;return 1}function hd(a,b){a=a|0;b=b|0;return $[F[F[a>>2]+12>>2]](a,b)|0}function Dh(a,b){a=a|0;b=b|0;return $[F[F[a>>2]+56>>2]](a,b)|0}function sc(a){a=Hc(Rb(8),a);F[a>>2]=11568;W(a|0,11600,1);v()}function mg(a,b){a=a|0;b=b|0;return M(J[F[a+8>>2]+(b<<2)>>2])}function Rd(a){a=Hc(Rb(8),a);F[a>>2]=11516;W(a|0,11548,1);v()}function $f(a,b){a=a|0;b=b|0;return M(J[F[a>>2]+(b<<2)>>2])}function gg(a){a=a|0;return(F[a+100>>2]-F[a+96>>2]|0)/12|0}function cg(a){a=a|0;return(D[a+15|0]<0?F[a+4>>2]:a+4|0)|0}function Re(a,b){a=a|0;b=b|0;return F[F[a+4>>2]+(b<<2)>>2]}function dd(a,b){a=a|0;b=b|0;return F[F[a>>2]+(b<<2)>>2]}function Yf(a,b){a=a|0;b=b|0;return E[F[a>>2]+(b<<1)>>1]}function Xf(a,b){a=a|0;b=b|0;return H[F[a>>2]+(b<<1)>>1]}function Vd(a,b,c){a=a|0;b=b|0;c=c|0;return xc(a,b,c)|0}function sb(a,b){var c=0;c=ka(b);F[a+4>>2]=b;F[a>>2]=c}function Kf(a,b,c){a=a|0;b=b|0;c=c|0;return Qc(b,c)|0}function Rc(a){F[a>>2]=10300;ma(a+4|0,0,80);return a}function ji(a){if(a){return 31-O(a-1^a)|0}return 32}function gd(a){a=a|0;return F[a+12>>2]-F[a+8>>2]>>2}function _f(a,b){a=a|0;b=b|0;return D[F[a>>2]+b|0]}function Zf(a,b){a=a|0;b=b|0;return G[F[a>>2]+b|0]}function Ie(a){a=a|0;return F[a+8>>2]-F[a+4>>2]>>2}function wb(a){a=a|0;if(a){$[F[F[a>>2]+4>>2]](a)}}function Jd(a,b){a=a|0;b=b|0;F[a+4>>2]=b;return 1}function ed(a){a=a|0;return F[a+4>>2]-F[a>>2]>>1}function dc(a){a=a|0;return F[a+4>>2]-F[a>>2]>>2}function fd(a){a=a|0;return F[a+4>>2]-F[a>>2]|0}function ke(a){a=a|0;return G[F[a+8>>2]+24|0]}function Qf(a,b){a=a|0;b=b|0;return F[b+8>>2]}function Ff(a,b){a=a|0;b=b|0;return F[b+4>>2]}function De(a,b,c){a=a|0;b=b|0;c=c|0;return 1}function Bg(a,b){a=a|0;b=b|0;return G[b+24|0]}function Oh(a){a=a|0;F[a>>2]=5928;return a|0}function Jh(a){a=a|0;F[a>>2]=6932;return a|0}function lg(a){a=a|0;return M(J[a+20>>2])}function Nh(a){a=a|0;F[a>>2]=5928;ja(a)}function Ih(a){a=a|0;F[a>>2]=6932;ja(a)}function ug(a){a=a|0;return F[a+88>>2]}function tg(a){a=a|0;return F[a+56>>2]}function qg(a){a=a|0;return F[a+40>>2]}function pg(a){a=a|0;return F[a+48>>2]}function og(a){a=a|0;return F[a+60>>2]}function ec(a){a=a|0;return F[a+80>>2]}function cb(a){a=a|0;return F[a+28>>2]}function vd(a){a=a|0;return F[a+8>>2]}function tc(a,b){a=a|0;b=b|0;return-1}function sg(a){a=a|0;return D[a+24|0]}function rg(a){a=a|0;return G[a+32|0]}function dg(a){a=a|0;return!F[a>>2]|0}function Wd(a,b){a=a|0;b=b|0;return 6}function Va(a){a=a|0;return F[a+4>>2]}function Rb(a){return Ub(a+80|0)+80|0}function Qh(a,b){a=a|0;b=b|0;return 2}function Ia(a,b){a=a|0;b=b|0;return 0}function Bc(a,b){a=a|0;b=b|0;return 1}function jd(a){a=a|0;return F[a>>2]}function wg(){return kb(ka(64))|0}function ig(){return Rc(ka(84))|0}function fc(a){a=a|0;if(a){ja(a)}}function Ag(){return Ja(ka(40))|0}function Qb(a){a=a|0;Cc(a);ja(a)}function Je(a){a=a|0;return 1161}function He(a){a=a|0;return 1235}function Ge(a){a=a|0;return 1201}function Pa(a){a=a|0;return a|0}function hh(a){a=a|0;ja(ud(a))}function gh(a){a=a|0;ja(sd(a))}function Ve(a){a=a|0;ja(tb(a))}function ua(a){a=a|0;return 1}function rc(a){a=a|0;return 4}function qc(a){a=a|0;return 5}function Xd(a){a=a|0;return 2}function Ua(a){a=a|0;return 0}function Nb(a){a=a|0;return 6}function Mh(a){a=a|0;return 3}function za(){Rd(1222);v()}function ta(){sc(1154);v()}function na(){Rd(1154);v()}function Ha(a){a=a|0;ja(a)}function Ra(a){a=a|0;v()}function ff(){return 10}function ef(){return 11}function df(){return 12}function vb(){return-1}function ub(){return 1}function lf(){return 5}function kf(){return 6}function jf(){return 7}function jb(){return 0}function hf(){return 8}function gf(){return 9}function cf(){return-2}function bf(){return-3}function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Gg,Ig,Jg,Pa,Ha,Fg,Eg,Ra,Ua,ua,_e,Ze,Ye,Xe,tb,Ve,Oc,Nc,Pa,Ha,Jc,Jc,Se,Le,Ne,Qe,Ha,Me,Oe,Pe,Ha,He,Ha,Ge,Ha,Je,Qb,Va,Qb,Qb]);function aa(){return C.byteLength/65536|0}function fa(ga){ga=ga|0;var ba=aa()|0;var ca=ba+ga|0;if(ba=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}function stringToUTF8Array(str,heap,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx}function lengthBytesUTF8(str){var len=0;for(var i=0;i=55296&&c<=57343){len+=4;++i}else{len+=3}}return len}var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var INITIAL_MEMORY=Module["INITIAL_MEMORY"]||16777216;assert(INITIAL_MEMORY>=65536,"INITIAL_MEMORY should be larger than STACK_SIZE, was "+INITIAL_MEMORY+"! (STACK_SIZE="+65536+")");if(Module["wasmMemory"]){wasmMemory=Module["wasmMemory"]}else{wasmMemory=new WebAssembly.Memory({"initial":INITIAL_MEMORY/65536,"maximum":2147483648/65536})}updateMemoryViews();INITIAL_MEMORY=wasmMemory.buffer.byteLength;var wasmTable;var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function keepRuntimeAlive(){return noExitRuntime}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}what="Aborted("+what+")";err(what);ABORT=true;EXITSTATUS=1;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject(e);throw e}var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return filename.startsWith(dataURIPrefix)}function isFileURI(filename){return filename.startsWith("file://")}var wasmBinaryFile;wasmBinaryFile="draco_decoder_gltf.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}function getBinary(file){try{if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}var binary=tryParseAsDataURI(file);if(binary){return binary}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}catch(err){abort(err)}}function getBinaryPromise(){if(!wasmBinary&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)){if(typeof fetch=="function"&&!isFileURI(wasmBinaryFile)){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw"failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary(wasmBinaryFile)})}else{if(readAsync){return new Promise(function(resolve,reject){readAsync(wasmBinaryFile,function(response){resolve(new Uint8Array(response))},reject)})}}}return Promise.resolve().then(function(){return getBinary(wasmBinaryFile)})}function createWasm(){var info={"a":wasmImports};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;wasmTable=Module["asm"]["g"];addOnInit(Module["asm"]["f"]);removeRunDependency("wasm-instantiate")}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}function instantiateArrayBuffer(receiver){return getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(function(instance){return instance}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason)})}function instantiateAsync(){if(!wasmBinary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(wasmBinaryFile)&&!isFileURI(wasmBinaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){var result=WebAssembly.instantiateStreaming(response,info);return result.then(receiveInstantiationResult,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(receiveInstantiationResult)})})}else{return instantiateArrayBuffer(receiveInstantiationResult)}}if(Module["instantiateWasm"]){try{var exports=Module["instantiateWasm"](info,receiveInstance);return exports}catch(e){err("Module.instantiateWasm callback failed with error: "+e);readyPromiseReject(e)}}instantiateAsync().catch(readyPromiseReject);return{}}function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}function callRuntimeCallbacks(callbacks){while(callbacks.length>0){callbacks.shift()(Module)}}function intArrayToString(array){var ret=[];for(var i=0;i255){chr&=255}ret.push(String.fromCharCode(chr))}return ret.join("")}function ExceptionInfo(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24;this.set_type=function(type){HEAPU32[this.ptr+4>>2]=type};this.get_type=function(){return HEAPU32[this.ptr+4>>2]};this.set_destructor=function(destructor){HEAPU32[this.ptr+8>>2]=destructor};this.get_destructor=function(){return HEAPU32[this.ptr+8>>2]};this.set_refcount=function(refcount){HEAP32[this.ptr>>2]=refcount};this.set_caught=function(caught){caught=caught?1:0;HEAP8[this.ptr+12>>0]=caught};this.get_caught=function(){return HEAP8[this.ptr+12>>0]!=0};this.set_rethrown=function(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13>>0]=rethrown};this.get_rethrown=function(){return HEAP8[this.ptr+13>>0]!=0};this.init=function(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor);this.set_refcount(0);this.set_caught(false);this.set_rethrown(false)};this.add_ref=function(){var value=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=value+1};this.release_ref=function(){var prev=HEAP32[this.ptr>>2];HEAP32[this.ptr>>2]=prev-1;return prev===1};this.set_adjusted_ptr=function(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr};this.get_adjusted_ptr=function(){return HEAPU32[this.ptr+16>>2]};this.get_exception_ptr=function(){var isPointer=___cxa_is_pointer_type(this.get_type());if(isPointer){return HEAPU32[this.excPtr>>2]}var adjusted=this.get_adjusted_ptr();if(adjusted!==0)return adjusted;return this.excPtr}}var exceptionLast=0;var uncaughtExceptionCount=0;function ___cxa_throw(ptr,type,destructor){var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw ptr}function _abort(){abort("")}function _emscripten_memcpy_big(dest,src,num){HEAPU8.copyWithin(dest,src,src+num)}function getHeapMax(){return 2147483648}function emscripten_realloc_buffer(size){var b=wasmMemory.buffer;try{wasmMemory.grow(size-b.byteLength+65535>>>16);updateMemoryViews();return 1}catch(e){}}function _emscripten_resize_heap(requestedSize){var oldSize=HEAPU8.length;requestedSize=requestedSize>>>0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}let alignUp=(x,multiple)=>x+(multiple-x%multiple)%multiple;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignUp(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=emscripten_realloc_buffer(newSize);if(replacement){return true}}return false}function intArrayFromString(stringy,dontAddNull,length){var len=length>0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array}var decodeBase64=typeof atob=="function"?atob:function(input){var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{enc1=keyStr.indexOf(input.charAt(i++));enc2=keyStr.indexOf(input.charAt(i++));enc3=keyStr.indexOf(input.charAt(i++));enc4=keyStr.indexOf(input.charAt(i++));chr1=enc1<<2|enc2>>4;chr2=(enc2&15)<<4|enc3>>2;chr3=(enc3&3)<<6|enc4;output=output+String.fromCharCode(chr1);if(enc3!==64){output=output+String.fromCharCode(chr2)}if(enc4!==64){output=output+String.fromCharCode(chr3)}}while(i0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve(Module);if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();function WrapperObject(){}WrapperObject.prototype=Object.create(WrapperObject.prototype);WrapperObject.prototype.constructor=WrapperObject;WrapperObject.prototype.__class__=WrapperObject;WrapperObject.__cache__={};Module["WrapperObject"]=WrapperObject;function getCache(__class__){return(__class__||WrapperObject).__cache__}Module["getCache"]=getCache;function wrapPointer(ptr,__class__){var cache=getCache(__class__);var ret=cache[ptr];if(ret)return ret;ret=Object.create((__class__||WrapperObject).prototype);ret.ptr=ptr;return cache[ptr]=ret}Module["wrapPointer"]=wrapPointer;function castObject(obj,__class__){return wrapPointer(obj.ptr,__class__)}Module["castObject"]=castObject;Module["NULL"]=wrapPointer(0);function destroy(obj){if(!obj["__destroy__"])throw"Error: Cannot destroy object. (Did you create it yourself?)";obj["__destroy__"]();delete getCache(obj.__class__)[obj.ptr]}Module["destroy"]=destroy;function compare(obj1,obj2){return obj1.ptr===obj2.ptr}Module["compare"]=compare;function getPointer(obj){return obj.ptr}Module["getPointer"]=getPointer;function getClass(obj){return obj.__class__}Module["getClass"]=getClass;var ensureCache={buffer:0,size:0,pos:0,temps:[],needed:0,prepare:function(){if(ensureCache.needed){for(var i=0;i=ensureCache.size){assert(len>0);ensureCache.needed+=len;ret=Module["_malloc"](len);ensureCache.temps.push(ret)}else{ret=ensureCache.buffer+ensureCache.pos;ensureCache.pos+=len}return ret},copy:function(array,view,offset){offset>>>=0;var bytes=view.BYTES_PER_ELEMENT;switch(bytes){case 2:offset>>>=1;break;case 4:offset>>>=2;break;case 8:offset>>>=3;break}for(var i=0;iR=dRaow_U3hI`+>x-y=(}?b|No!R6%5+PQ1x-p^5i&q6!TJ7Gr1(JzR&I)+Ejk29!*yutDAJQ)IA;UDVo6b<&q2j_$9+W&Nt+Ib~S z|1{0fxGRc&zt{8GjG)Ndfj*4?$>^`oyRlFF%{qd!!+)Jt;PuR2mbFylYzJ^ci^5s! zakDK|%s-%`)ovN!0UQb-vhmljt0(ORA85Ga=#{?mo&V?)ux44e%S)GZz>mL3uuj=C z@A#Yjz2V*fdi>#V_;6@<8R+_<2lArx1MRnZ|IL(tiM!Rmlo(_bx-jJ-2Vvv74D-=O4YlY9-y&vCyJ{Bzwe2mg(N^IG>` zf`6X-rQrXqyD#_`xvhS)`-Kqp>~V`>?;iIx;rcypYk2V<_n$-f<~{C5e0YgcU#irX z?QuUJ!pkjnQK?HxyzgkNfvN+^WV7 zDDf3ayv-6{sl-<)vEJkUQwTfuxStK-l0EJ}hH&W~_a8#IY>)ey5H8>2?hWCJJ?;Y` z?A+ttAHuFZ?x#a|#vb>+5U$+gekz2k_PC!6;p#o^o)Dh7$Gta%-Fw_mgz&6A?mZ!V z{T}z@A$-Fg_wEp$y~o`h!Zmx`kA?7@J?=+Cc!G+bi|b>rb;B2qE6P)dJ-vQ3{x^D+(d)hQ4tTmO_N9uBYdbARFg+`q>Ewf`&skbkZJjQ>mjhyH*2|KtDE|AGIs{}cbm z{*U~@J6_}emw(V7dcgml|9yYIf8N}aE}5`NngeH+S(*W#{~4c2D-oi{G35 zME0KS$F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Vj+69QasD2kk@8Yvv zJi2XY@X(>dr%zAaJ#+ui(D(knZH4e6{SD-CYH0VfeV)9pWxfM zsl~1xt4c!$Bw;!LY18ctrIUe&F?hbg;<>zgR!Ye@Qg zIy~FS{Wam)>G14Y?%zzhV`*2@caLu*%kCo&&zqijJXf2~^IYHGu{1o`(wi^jdz3ta zM}N<8Rn>$1Gi3D*4dI%D)8F*M0^Wlv_w(dYx%wmao8=#F<{x%n!SDfj^bLpRSlRmK wVEASv^UeIJr9<=g9K!qXUWpw0=DP3=ZEFyi-l@&+y#^`x`$P|T{>{1n3!i-vWB>pF literal 0 HcmV?d00001 diff --git a/libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js b/libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js new file mode 100644 index 000000000..43f155683 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js @@ -0,0 +1,116 @@ +var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(h){var n=0;return function(){return n>>0,$jscomp.propertyToPolyfillSymbol[l]=$jscomp.IS_SYMBOL_NATIVE? +$jscomp.global.Symbol(l):$jscomp.POLYFILL_PREFIX+k+"$"+l),$jscomp.defineProperty(p,$jscomp.propertyToPolyfillSymbol[l],{configurable:!0,writable:!0,value:n})))}; +$jscomp.polyfill("Promise",function(h){function n(){this.batch_=null}function k(f){return f instanceof l?f:new l(function(q,u){q(f)})}if(h&&(!($jscomp.FORCE_POLYFILL_PROMISE||$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION&&"undefined"===typeof $jscomp.global.PromiseRejectionEvent)||!$jscomp.global.Promise||-1===$jscomp.global.Promise.toString().indexOf("[native code]")))return h;n.prototype.asyncExecute=function(f){if(null==this.batch_){this.batch_=[];var q=this;this.asyncExecuteFunction(function(){q.executeBatch_()})}this.batch_.push(f)}; +var p=$jscomp.global.setTimeout;n.prototype.asyncExecuteFunction=function(f){p(f,0)};n.prototype.executeBatch_=function(){for(;this.batch_&&this.batch_.length;){var f=this.batch_;this.batch_=[];for(var q=0;q=y}},"es6","es3"); +$jscomp.polyfill("Array.prototype.copyWithin",function(h){function n(k){k=Number(k);return Infinity===k||-Infinity===k?k:k|0}return h?h:function(k,p,l){var y=this.length;k=n(k);p=n(p);l=void 0===l?y:n(l);k=0>k?Math.max(y+k,0):Math.min(k,y);p=0>p?Math.max(y+p,0):Math.min(p,y);l=0>l?Math.max(y+l,0):Math.min(l,y);if(kp;)--l in this?this[--k]=this[l]:delete this[--k];return this}},"es6","es3"); +$jscomp.typedArrayCopyWithin=function(h){return h?h:Array.prototype.copyWithin};$jscomp.polyfill("Int8Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Uint8Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Uint8ClampedArray.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Int16Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5"); +$jscomp.polyfill("Uint16Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Int32Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Uint32Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Float32Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5");$jscomp.polyfill("Float64Array.prototype.copyWithin",$jscomp.typedArrayCopyWithin,"es6","es5"); +var DracoDecoderModule=function(){var h="undefined"!==typeof document&&document.currentScript?document.currentScript.src:void 0;"undefined"!==typeof __filename&&(h=h||__filename);return function(n){function k(e){return a.locateFile?a.locateFile(e,U):U+e}function p(e,b){if(e){var c=ia;var d=e+b;for(b=e;c[b]&&!(b>=d);)++b;if(16g?d+=String.fromCharCode(g):(g-=65536,d+=String.fromCharCode(55296|g>>10,56320|g&1023))}}else d+=String.fromCharCode(g)}c=d}}else c="";return c}function l(){var e=ja.buffer;a.HEAP8=W=new Int8Array(e);a.HEAP16=new Int16Array(e);a.HEAP32=ca=new Int32Array(e);a.HEAPU8=ia=new Uint8Array(e);a.HEAPU16=new Uint16Array(e);a.HEAPU32=Y=new Uint32Array(e);a.HEAPF32=new Float32Array(e);a.HEAPF64=new Float64Array(e)}function y(e){if(a.onAbort)a.onAbort(e); +e="Aborted("+e+")";da(e);sa=!0;e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info.");ka(e);throw e;}function f(e){try{if(e==P&&ea)return new Uint8Array(ea);if(ma)return ma(e);throw"both async and sync fetching of the wasm failed";}catch(b){y(b)}}function q(){if(!ea&&(ta||fa)){if("function"==typeof fetch&&!P.startsWith("file://"))return fetch(P,{credentials:"same-origin"}).then(function(e){if(!e.ok)throw"failed to load wasm binary file at '"+P+"'";return e.arrayBuffer()}).catch(function(){return f(P)}); +if(na)return new Promise(function(e,b){na(P,function(c){e(new Uint8Array(c))},b)})}return Promise.resolve().then(function(){return f(P)})}function u(e){for(;0>2]=b};this.get_type=function(){return Y[this.ptr+4>>2]};this.set_destructor=function(b){Y[this.ptr+8>>2]=b};this.get_destructor=function(){return Y[this.ptr+8>>2]};this.set_refcount=function(b){ca[this.ptr>>2]=b};this.set_caught=function(b){W[this.ptr+ +12>>0]=b?1:0};this.get_caught=function(){return 0!=W[this.ptr+12>>0]};this.set_rethrown=function(b){W[this.ptr+13>>0]=b?1:0};this.get_rethrown=function(){return 0!=W[this.ptr+13>>0]};this.init=function(b,c){this.set_adjusted_ptr(0);this.set_type(b);this.set_destructor(c);this.set_refcount(0);this.set_caught(!1);this.set_rethrown(!1)};this.add_ref=function(){ca[this.ptr>>2]+=1};this.release_ref=function(){var b=ca[this.ptr>>2];ca[this.ptr>>2]=b-1;return 1===b};this.set_adjusted_ptr=function(b){Y[this.ptr+ +16>>2]=b};this.get_adjusted_ptr=function(){return Y[this.ptr+16>>2]};this.get_exception_ptr=function(){if(ua(this.get_type()))return Y[this.excPtr>>2];var b=this.get_adjusted_ptr();return 0!==b?b:this.excPtr}}function F(){function e(){if(!la&&(la=!0,a.calledRun=!0,!sa)){va=!0;u(oa);wa(a);if(a.onRuntimeInitialized)a.onRuntimeInitialized();if(a.postRun)for("function"==typeof a.postRun&&(a.postRun=[a.postRun]);a.postRun.length;)xa.unshift(a.postRun.shift());u(xa)}}if(!(0=d?b++:2047>=d?b+=2:55296<=d&&57343>= +d?(b+=4,++c):b+=3}b=Array(b+1);c=0;d=b.length;if(0=t){var aa=e.charCodeAt(++g);t=65536+((t&1023)<<10)|aa&1023}if(127>=t){if(c>=d)break;b[c++]=t}else{if(2047>=t){if(c+1>=d)break;b[c++]=192|t>>6}else{if(65535>=t){if(c+2>=d)break;b[c++]=224|t>>12}else{if(c+3>=d)break;b[c++]=240|t>>18;b[c++]=128|t>>12&63}b[c++]=128|t>>6&63}b[c++]=128|t&63}}b[c]=0}e=r.alloc(b,W);r.copy(b,W,e);return e}return e}function Z(e){if("object"=== +typeof e){var b=r.alloc(e,W);r.copy(e,W,b);return b}return e}function X(){throw"cannot construct a VoidPtr, no constructor in IDL";}function S(){this.ptr=za();w(S)[this.ptr]=this}function Q(){this.ptr=Aa();w(Q)[this.ptr]=this}function V(){this.ptr=Ba();w(V)[this.ptr]=this}function x(){this.ptr=Ca();w(x)[this.ptr]=this}function D(){this.ptr=Da();w(D)[this.ptr]=this}function G(){this.ptr=Ea();w(G)[this.ptr]=this}function H(){this.ptr=Fa();w(H)[this.ptr]=this}function E(){this.ptr=Ga();w(E)[this.ptr]= +this}function T(){this.ptr=Ha();w(T)[this.ptr]=this}function C(){throw"cannot construct a Status, no constructor in IDL";}function I(){this.ptr=Ia();w(I)[this.ptr]=this}function J(){this.ptr=Ja();w(J)[this.ptr]=this}function K(){this.ptr=Ka();w(K)[this.ptr]=this}function L(){this.ptr=La();w(L)[this.ptr]=this}function M(){this.ptr=Ma();w(M)[this.ptr]=this}function N(){this.ptr=Na();w(N)[this.ptr]=this}function O(){this.ptr=Oa();w(O)[this.ptr]=this}function z(){this.ptr=Pa();w(z)[this.ptr]=this}function m(){this.ptr= +Qa();w(m)[this.ptr]=this}n=void 0===n?{}:n;var a="undefined"!=typeof n?n:{},wa,ka;a.ready=new Promise(function(e,b){wa=e;ka=b});var Ra=!1,Sa=!1;a.onRuntimeInitialized=function(){Ra=!0;if(Sa&&"function"===typeof a.onModuleLoaded)a.onModuleLoaded(a)};a.onModuleParsed=function(){Sa=!0;if(Ra&&"function"===typeof a.onModuleLoaded)a.onModuleLoaded(a)};a.isVersionSupported=function(e){if("string"!==typeof e)return!1;e=e.split(".");return 2>e.length||3=e[1]?!0:0!=e[0]||10< +e[1]?!1:!0};var Ta=Object.assign({},a),ta="object"==typeof window,fa="function"==typeof importScripts,Ua="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,U="";if(Ua){var Va=require("fs"),pa=require("path");U=fa?pa.dirname(U)+"/":__dirname+"/";var Wa=function(e,b){e=e.startsWith("file://")?new URL(e):pa.normalize(e);return Va.readFileSync(e,b?void 0:"utf8")};var ma=function(e){e=Wa(e,!0);e.buffer||(e=new Uint8Array(e));return e};var na=function(e, +b,c){e=e.startsWith("file://")?new URL(e):pa.normalize(e);Va.readFile(e,function(d,g){d?c(d):b(g.buffer)})};1>>=0;if(2147483648=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,e+100663296);var g=Math;d=Math.max(e,d);g=g.min.call(g,2147483648,d+(65536-d%65536)%65536);a:{d=ja.buffer;try{ja.grow(g-d.byteLength+65535>>>16);l();var t=1;break a}catch(aa){}t=void 0}if(t)return!0}return!1}};(function(){function e(g,t){a.asm=g.exports;ja=a.asm.e;l();oa.unshift(a.asm.f);ba--;a.monitorRunDependencies&&a.monitorRunDependencies(ba);0==ba&&(null!==qa&&(clearInterval(qa),qa=null),ha&&(g=ha,ha=null,g()))}function b(g){e(g.instance)} +function c(g){return q().then(function(t){return WebAssembly.instantiate(t,d)}).then(function(t){return t}).then(g,function(t){da("failed to asynchronously prepare wasm: "+t);y(t)})}var d={a:qd};ba++;a.monitorRunDependencies&&a.monitorRunDependencies(ba);if(a.instantiateWasm)try{return a.instantiateWasm(d,e)}catch(g){da("Module.instantiateWasm callback failed with error: "+g),ka(g)}(function(){return ea||"function"!=typeof WebAssembly.instantiateStreaming||P.startsWith("data:application/octet-stream;base64,")|| +P.startsWith("file://")||Ua||"function"!=typeof fetch?c(b):fetch(P,{credentials:"same-origin"}).then(function(g){return WebAssembly.instantiateStreaming(g,d).then(b,function(t){da("wasm streaming compile failed: "+t);da("falling back to ArrayBuffer instantiation");return c(b)})})})().catch(ka);return{}})();var Xa=a._emscripten_bind_VoidPtr___destroy___0=function(){return(Xa=a._emscripten_bind_VoidPtr___destroy___0=a.asm.h).apply(null,arguments)},za=a._emscripten_bind_DecoderBuffer_DecoderBuffer_0= +function(){return(za=a._emscripten_bind_DecoderBuffer_DecoderBuffer_0=a.asm.i).apply(null,arguments)},Ya=a._emscripten_bind_DecoderBuffer_Init_2=function(){return(Ya=a._emscripten_bind_DecoderBuffer_Init_2=a.asm.j).apply(null,arguments)},Za=a._emscripten_bind_DecoderBuffer___destroy___0=function(){return(Za=a._emscripten_bind_DecoderBuffer___destroy___0=a.asm.k).apply(null,arguments)},Aa=a._emscripten_bind_AttributeTransformData_AttributeTransformData_0=function(){return(Aa=a._emscripten_bind_AttributeTransformData_AttributeTransformData_0= +a.asm.l).apply(null,arguments)},$a=a._emscripten_bind_AttributeTransformData_transform_type_0=function(){return($a=a._emscripten_bind_AttributeTransformData_transform_type_0=a.asm.m).apply(null,arguments)},ab=a._emscripten_bind_AttributeTransformData___destroy___0=function(){return(ab=a._emscripten_bind_AttributeTransformData___destroy___0=a.asm.n).apply(null,arguments)},Ba=a._emscripten_bind_GeometryAttribute_GeometryAttribute_0=function(){return(Ba=a._emscripten_bind_GeometryAttribute_GeometryAttribute_0= +a.asm.o).apply(null,arguments)},bb=a._emscripten_bind_GeometryAttribute___destroy___0=function(){return(bb=a._emscripten_bind_GeometryAttribute___destroy___0=a.asm.p).apply(null,arguments)},Ca=a._emscripten_bind_PointAttribute_PointAttribute_0=function(){return(Ca=a._emscripten_bind_PointAttribute_PointAttribute_0=a.asm.q).apply(null,arguments)},cb=a._emscripten_bind_PointAttribute_size_0=function(){return(cb=a._emscripten_bind_PointAttribute_size_0=a.asm.r).apply(null,arguments)},db=a._emscripten_bind_PointAttribute_GetAttributeTransformData_0= +function(){return(db=a._emscripten_bind_PointAttribute_GetAttributeTransformData_0=a.asm.s).apply(null,arguments)},eb=a._emscripten_bind_PointAttribute_attribute_type_0=function(){return(eb=a._emscripten_bind_PointAttribute_attribute_type_0=a.asm.t).apply(null,arguments)},fb=a._emscripten_bind_PointAttribute_data_type_0=function(){return(fb=a._emscripten_bind_PointAttribute_data_type_0=a.asm.u).apply(null,arguments)},gb=a._emscripten_bind_PointAttribute_num_components_0=function(){return(gb=a._emscripten_bind_PointAttribute_num_components_0= +a.asm.v).apply(null,arguments)},hb=a._emscripten_bind_PointAttribute_normalized_0=function(){return(hb=a._emscripten_bind_PointAttribute_normalized_0=a.asm.w).apply(null,arguments)},ib=a._emscripten_bind_PointAttribute_byte_stride_0=function(){return(ib=a._emscripten_bind_PointAttribute_byte_stride_0=a.asm.x).apply(null,arguments)},jb=a._emscripten_bind_PointAttribute_byte_offset_0=function(){return(jb=a._emscripten_bind_PointAttribute_byte_offset_0=a.asm.y).apply(null,arguments)},kb=a._emscripten_bind_PointAttribute_unique_id_0= +function(){return(kb=a._emscripten_bind_PointAttribute_unique_id_0=a.asm.z).apply(null,arguments)},lb=a._emscripten_bind_PointAttribute___destroy___0=function(){return(lb=a._emscripten_bind_PointAttribute___destroy___0=a.asm.A).apply(null,arguments)},Da=a._emscripten_bind_AttributeQuantizationTransform_AttributeQuantizationTransform_0=function(){return(Da=a._emscripten_bind_AttributeQuantizationTransform_AttributeQuantizationTransform_0=a.asm.B).apply(null,arguments)},mb=a._emscripten_bind_AttributeQuantizationTransform_InitFromAttribute_1= +function(){return(mb=a._emscripten_bind_AttributeQuantizationTransform_InitFromAttribute_1=a.asm.C).apply(null,arguments)},nb=a._emscripten_bind_AttributeQuantizationTransform_quantization_bits_0=function(){return(nb=a._emscripten_bind_AttributeQuantizationTransform_quantization_bits_0=a.asm.D).apply(null,arguments)},ob=a._emscripten_bind_AttributeQuantizationTransform_min_value_1=function(){return(ob=a._emscripten_bind_AttributeQuantizationTransform_min_value_1=a.asm.E).apply(null,arguments)},pb= +a._emscripten_bind_AttributeQuantizationTransform_range_0=function(){return(pb=a._emscripten_bind_AttributeQuantizationTransform_range_0=a.asm.F).apply(null,arguments)},qb=a._emscripten_bind_AttributeQuantizationTransform___destroy___0=function(){return(qb=a._emscripten_bind_AttributeQuantizationTransform___destroy___0=a.asm.G).apply(null,arguments)},Ea=a._emscripten_bind_AttributeOctahedronTransform_AttributeOctahedronTransform_0=function(){return(Ea=a._emscripten_bind_AttributeOctahedronTransform_AttributeOctahedronTransform_0= +a.asm.H).apply(null,arguments)},rb=a._emscripten_bind_AttributeOctahedronTransform_InitFromAttribute_1=function(){return(rb=a._emscripten_bind_AttributeOctahedronTransform_InitFromAttribute_1=a.asm.I).apply(null,arguments)},sb=a._emscripten_bind_AttributeOctahedronTransform_quantization_bits_0=function(){return(sb=a._emscripten_bind_AttributeOctahedronTransform_quantization_bits_0=a.asm.J).apply(null,arguments)},tb=a._emscripten_bind_AttributeOctahedronTransform___destroy___0=function(){return(tb= +a._emscripten_bind_AttributeOctahedronTransform___destroy___0=a.asm.K).apply(null,arguments)},Fa=a._emscripten_bind_PointCloud_PointCloud_0=function(){return(Fa=a._emscripten_bind_PointCloud_PointCloud_0=a.asm.L).apply(null,arguments)},ub=a._emscripten_bind_PointCloud_num_attributes_0=function(){return(ub=a._emscripten_bind_PointCloud_num_attributes_0=a.asm.M).apply(null,arguments)},vb=a._emscripten_bind_PointCloud_num_points_0=function(){return(vb=a._emscripten_bind_PointCloud_num_points_0=a.asm.N).apply(null, +arguments)},wb=a._emscripten_bind_PointCloud___destroy___0=function(){return(wb=a._emscripten_bind_PointCloud___destroy___0=a.asm.O).apply(null,arguments)},Ga=a._emscripten_bind_Mesh_Mesh_0=function(){return(Ga=a._emscripten_bind_Mesh_Mesh_0=a.asm.P).apply(null,arguments)},xb=a._emscripten_bind_Mesh_num_faces_0=function(){return(xb=a._emscripten_bind_Mesh_num_faces_0=a.asm.Q).apply(null,arguments)},yb=a._emscripten_bind_Mesh_num_attributes_0=function(){return(yb=a._emscripten_bind_Mesh_num_attributes_0= +a.asm.R).apply(null,arguments)},zb=a._emscripten_bind_Mesh_num_points_0=function(){return(zb=a._emscripten_bind_Mesh_num_points_0=a.asm.S).apply(null,arguments)},Ab=a._emscripten_bind_Mesh___destroy___0=function(){return(Ab=a._emscripten_bind_Mesh___destroy___0=a.asm.T).apply(null,arguments)},Ha=a._emscripten_bind_Metadata_Metadata_0=function(){return(Ha=a._emscripten_bind_Metadata_Metadata_0=a.asm.U).apply(null,arguments)},Bb=a._emscripten_bind_Metadata___destroy___0=function(){return(Bb=a._emscripten_bind_Metadata___destroy___0= +a.asm.V).apply(null,arguments)},Cb=a._emscripten_bind_Status_code_0=function(){return(Cb=a._emscripten_bind_Status_code_0=a.asm.W).apply(null,arguments)},Db=a._emscripten_bind_Status_ok_0=function(){return(Db=a._emscripten_bind_Status_ok_0=a.asm.X).apply(null,arguments)},Eb=a._emscripten_bind_Status_error_msg_0=function(){return(Eb=a._emscripten_bind_Status_error_msg_0=a.asm.Y).apply(null,arguments)},Fb=a._emscripten_bind_Status___destroy___0=function(){return(Fb=a._emscripten_bind_Status___destroy___0= +a.asm.Z).apply(null,arguments)},Ia=a._emscripten_bind_DracoFloat32Array_DracoFloat32Array_0=function(){return(Ia=a._emscripten_bind_DracoFloat32Array_DracoFloat32Array_0=a.asm._).apply(null,arguments)},Gb=a._emscripten_bind_DracoFloat32Array_GetValue_1=function(){return(Gb=a._emscripten_bind_DracoFloat32Array_GetValue_1=a.asm.$).apply(null,arguments)},Hb=a._emscripten_bind_DracoFloat32Array_size_0=function(){return(Hb=a._emscripten_bind_DracoFloat32Array_size_0=a.asm.aa).apply(null,arguments)},Ib= +a._emscripten_bind_DracoFloat32Array___destroy___0=function(){return(Ib=a._emscripten_bind_DracoFloat32Array___destroy___0=a.asm.ba).apply(null,arguments)},Ja=a._emscripten_bind_DracoInt8Array_DracoInt8Array_0=function(){return(Ja=a._emscripten_bind_DracoInt8Array_DracoInt8Array_0=a.asm.ca).apply(null,arguments)},Jb=a._emscripten_bind_DracoInt8Array_GetValue_1=function(){return(Jb=a._emscripten_bind_DracoInt8Array_GetValue_1=a.asm.da).apply(null,arguments)},Kb=a._emscripten_bind_DracoInt8Array_size_0= +function(){return(Kb=a._emscripten_bind_DracoInt8Array_size_0=a.asm.ea).apply(null,arguments)},Lb=a._emscripten_bind_DracoInt8Array___destroy___0=function(){return(Lb=a._emscripten_bind_DracoInt8Array___destroy___0=a.asm.fa).apply(null,arguments)},Ka=a._emscripten_bind_DracoUInt8Array_DracoUInt8Array_0=function(){return(Ka=a._emscripten_bind_DracoUInt8Array_DracoUInt8Array_0=a.asm.ga).apply(null,arguments)},Mb=a._emscripten_bind_DracoUInt8Array_GetValue_1=function(){return(Mb=a._emscripten_bind_DracoUInt8Array_GetValue_1= +a.asm.ha).apply(null,arguments)},Nb=a._emscripten_bind_DracoUInt8Array_size_0=function(){return(Nb=a._emscripten_bind_DracoUInt8Array_size_0=a.asm.ia).apply(null,arguments)},Ob=a._emscripten_bind_DracoUInt8Array___destroy___0=function(){return(Ob=a._emscripten_bind_DracoUInt8Array___destroy___0=a.asm.ja).apply(null,arguments)},La=a._emscripten_bind_DracoInt16Array_DracoInt16Array_0=function(){return(La=a._emscripten_bind_DracoInt16Array_DracoInt16Array_0=a.asm.ka).apply(null,arguments)},Pb=a._emscripten_bind_DracoInt16Array_GetValue_1= +function(){return(Pb=a._emscripten_bind_DracoInt16Array_GetValue_1=a.asm.la).apply(null,arguments)},Qb=a._emscripten_bind_DracoInt16Array_size_0=function(){return(Qb=a._emscripten_bind_DracoInt16Array_size_0=a.asm.ma).apply(null,arguments)},Rb=a._emscripten_bind_DracoInt16Array___destroy___0=function(){return(Rb=a._emscripten_bind_DracoInt16Array___destroy___0=a.asm.na).apply(null,arguments)},Ma=a._emscripten_bind_DracoUInt16Array_DracoUInt16Array_0=function(){return(Ma=a._emscripten_bind_DracoUInt16Array_DracoUInt16Array_0= +a.asm.oa).apply(null,arguments)},Sb=a._emscripten_bind_DracoUInt16Array_GetValue_1=function(){return(Sb=a._emscripten_bind_DracoUInt16Array_GetValue_1=a.asm.pa).apply(null,arguments)},Tb=a._emscripten_bind_DracoUInt16Array_size_0=function(){return(Tb=a._emscripten_bind_DracoUInt16Array_size_0=a.asm.qa).apply(null,arguments)},Ub=a._emscripten_bind_DracoUInt16Array___destroy___0=function(){return(Ub=a._emscripten_bind_DracoUInt16Array___destroy___0=a.asm.ra).apply(null,arguments)},Na=a._emscripten_bind_DracoInt32Array_DracoInt32Array_0= +function(){return(Na=a._emscripten_bind_DracoInt32Array_DracoInt32Array_0=a.asm.sa).apply(null,arguments)},Vb=a._emscripten_bind_DracoInt32Array_GetValue_1=function(){return(Vb=a._emscripten_bind_DracoInt32Array_GetValue_1=a.asm.ta).apply(null,arguments)},Wb=a._emscripten_bind_DracoInt32Array_size_0=function(){return(Wb=a._emscripten_bind_DracoInt32Array_size_0=a.asm.ua).apply(null,arguments)},Xb=a._emscripten_bind_DracoInt32Array___destroy___0=function(){return(Xb=a._emscripten_bind_DracoInt32Array___destroy___0= +a.asm.va).apply(null,arguments)},Oa=a._emscripten_bind_DracoUInt32Array_DracoUInt32Array_0=function(){return(Oa=a._emscripten_bind_DracoUInt32Array_DracoUInt32Array_0=a.asm.wa).apply(null,arguments)},Yb=a._emscripten_bind_DracoUInt32Array_GetValue_1=function(){return(Yb=a._emscripten_bind_DracoUInt32Array_GetValue_1=a.asm.xa).apply(null,arguments)},Zb=a._emscripten_bind_DracoUInt32Array_size_0=function(){return(Zb=a._emscripten_bind_DracoUInt32Array_size_0=a.asm.ya).apply(null,arguments)},$b=a._emscripten_bind_DracoUInt32Array___destroy___0= +function(){return($b=a._emscripten_bind_DracoUInt32Array___destroy___0=a.asm.za).apply(null,arguments)},Pa=a._emscripten_bind_MetadataQuerier_MetadataQuerier_0=function(){return(Pa=a._emscripten_bind_MetadataQuerier_MetadataQuerier_0=a.asm.Aa).apply(null,arguments)},ac=a._emscripten_bind_MetadataQuerier_HasEntry_2=function(){return(ac=a._emscripten_bind_MetadataQuerier_HasEntry_2=a.asm.Ba).apply(null,arguments)},bc=a._emscripten_bind_MetadataQuerier_GetIntEntry_2=function(){return(bc=a._emscripten_bind_MetadataQuerier_GetIntEntry_2= +a.asm.Ca).apply(null,arguments)},cc=a._emscripten_bind_MetadataQuerier_GetIntEntryArray_3=function(){return(cc=a._emscripten_bind_MetadataQuerier_GetIntEntryArray_3=a.asm.Da).apply(null,arguments)},dc=a._emscripten_bind_MetadataQuerier_GetDoubleEntry_2=function(){return(dc=a._emscripten_bind_MetadataQuerier_GetDoubleEntry_2=a.asm.Ea).apply(null,arguments)},ec=a._emscripten_bind_MetadataQuerier_GetStringEntry_2=function(){return(ec=a._emscripten_bind_MetadataQuerier_GetStringEntry_2=a.asm.Fa).apply(null, +arguments)},fc=a._emscripten_bind_MetadataQuerier_NumEntries_1=function(){return(fc=a._emscripten_bind_MetadataQuerier_NumEntries_1=a.asm.Ga).apply(null,arguments)},gc=a._emscripten_bind_MetadataQuerier_GetEntryName_2=function(){return(gc=a._emscripten_bind_MetadataQuerier_GetEntryName_2=a.asm.Ha).apply(null,arguments)},hc=a._emscripten_bind_MetadataQuerier___destroy___0=function(){return(hc=a._emscripten_bind_MetadataQuerier___destroy___0=a.asm.Ia).apply(null,arguments)},Qa=a._emscripten_bind_Decoder_Decoder_0= +function(){return(Qa=a._emscripten_bind_Decoder_Decoder_0=a.asm.Ja).apply(null,arguments)},ic=a._emscripten_bind_Decoder_DecodeArrayToPointCloud_3=function(){return(ic=a._emscripten_bind_Decoder_DecodeArrayToPointCloud_3=a.asm.Ka).apply(null,arguments)},jc=a._emscripten_bind_Decoder_DecodeArrayToMesh_3=function(){return(jc=a._emscripten_bind_Decoder_DecodeArrayToMesh_3=a.asm.La).apply(null,arguments)},kc=a._emscripten_bind_Decoder_GetAttributeId_2=function(){return(kc=a._emscripten_bind_Decoder_GetAttributeId_2= +a.asm.Ma).apply(null,arguments)},lc=a._emscripten_bind_Decoder_GetAttributeIdByName_2=function(){return(lc=a._emscripten_bind_Decoder_GetAttributeIdByName_2=a.asm.Na).apply(null,arguments)},mc=a._emscripten_bind_Decoder_GetAttributeIdByMetadataEntry_3=function(){return(mc=a._emscripten_bind_Decoder_GetAttributeIdByMetadataEntry_3=a.asm.Oa).apply(null,arguments)},nc=a._emscripten_bind_Decoder_GetAttribute_2=function(){return(nc=a._emscripten_bind_Decoder_GetAttribute_2=a.asm.Pa).apply(null,arguments)}, +oc=a._emscripten_bind_Decoder_GetAttributeByUniqueId_2=function(){return(oc=a._emscripten_bind_Decoder_GetAttributeByUniqueId_2=a.asm.Qa).apply(null,arguments)},pc=a._emscripten_bind_Decoder_GetMetadata_1=function(){return(pc=a._emscripten_bind_Decoder_GetMetadata_1=a.asm.Ra).apply(null,arguments)},qc=a._emscripten_bind_Decoder_GetAttributeMetadata_2=function(){return(qc=a._emscripten_bind_Decoder_GetAttributeMetadata_2=a.asm.Sa).apply(null,arguments)},rc=a._emscripten_bind_Decoder_GetFaceFromMesh_3= +function(){return(rc=a._emscripten_bind_Decoder_GetFaceFromMesh_3=a.asm.Ta).apply(null,arguments)},sc=a._emscripten_bind_Decoder_GetTriangleStripsFromMesh_2=function(){return(sc=a._emscripten_bind_Decoder_GetTriangleStripsFromMesh_2=a.asm.Ua).apply(null,arguments)},tc=a._emscripten_bind_Decoder_GetTrianglesUInt16Array_3=function(){return(tc=a._emscripten_bind_Decoder_GetTrianglesUInt16Array_3=a.asm.Va).apply(null,arguments)},uc=a._emscripten_bind_Decoder_GetTrianglesUInt32Array_3=function(){return(uc= +a._emscripten_bind_Decoder_GetTrianglesUInt32Array_3=a.asm.Wa).apply(null,arguments)},vc=a._emscripten_bind_Decoder_GetAttributeFloat_3=function(){return(vc=a._emscripten_bind_Decoder_GetAttributeFloat_3=a.asm.Xa).apply(null,arguments)},wc=a._emscripten_bind_Decoder_GetAttributeFloatForAllPoints_3=function(){return(wc=a._emscripten_bind_Decoder_GetAttributeFloatForAllPoints_3=a.asm.Ya).apply(null,arguments)},xc=a._emscripten_bind_Decoder_GetAttributeIntForAllPoints_3=function(){return(xc=a._emscripten_bind_Decoder_GetAttributeIntForAllPoints_3= +a.asm.Za).apply(null,arguments)},yc=a._emscripten_bind_Decoder_GetAttributeInt8ForAllPoints_3=function(){return(yc=a._emscripten_bind_Decoder_GetAttributeInt8ForAllPoints_3=a.asm._a).apply(null,arguments)},zc=a._emscripten_bind_Decoder_GetAttributeUInt8ForAllPoints_3=function(){return(zc=a._emscripten_bind_Decoder_GetAttributeUInt8ForAllPoints_3=a.asm.$a).apply(null,arguments)},Ac=a._emscripten_bind_Decoder_GetAttributeInt16ForAllPoints_3=function(){return(Ac=a._emscripten_bind_Decoder_GetAttributeInt16ForAllPoints_3= +a.asm.ab).apply(null,arguments)},Bc=a._emscripten_bind_Decoder_GetAttributeUInt16ForAllPoints_3=function(){return(Bc=a._emscripten_bind_Decoder_GetAttributeUInt16ForAllPoints_3=a.asm.bb).apply(null,arguments)},Cc=a._emscripten_bind_Decoder_GetAttributeInt32ForAllPoints_3=function(){return(Cc=a._emscripten_bind_Decoder_GetAttributeInt32ForAllPoints_3=a.asm.cb).apply(null,arguments)},Dc=a._emscripten_bind_Decoder_GetAttributeUInt32ForAllPoints_3=function(){return(Dc=a._emscripten_bind_Decoder_GetAttributeUInt32ForAllPoints_3= +a.asm.db).apply(null,arguments)},Ec=a._emscripten_bind_Decoder_GetAttributeDataArrayForAllPoints_5=function(){return(Ec=a._emscripten_bind_Decoder_GetAttributeDataArrayForAllPoints_5=a.asm.eb).apply(null,arguments)},Fc=a._emscripten_bind_Decoder_SkipAttributeTransform_1=function(){return(Fc=a._emscripten_bind_Decoder_SkipAttributeTransform_1=a.asm.fb).apply(null,arguments)},Gc=a._emscripten_bind_Decoder_GetEncodedGeometryType_Deprecated_1=function(){return(Gc=a._emscripten_bind_Decoder_GetEncodedGeometryType_Deprecated_1= +a.asm.gb).apply(null,arguments)},Hc=a._emscripten_bind_Decoder_DecodeBufferToPointCloud_2=function(){return(Hc=a._emscripten_bind_Decoder_DecodeBufferToPointCloud_2=a.asm.hb).apply(null,arguments)},Ic=a._emscripten_bind_Decoder_DecodeBufferToMesh_2=function(){return(Ic=a._emscripten_bind_Decoder_DecodeBufferToMesh_2=a.asm.ib).apply(null,arguments)},Jc=a._emscripten_bind_Decoder___destroy___0=function(){return(Jc=a._emscripten_bind_Decoder___destroy___0=a.asm.jb).apply(null,arguments)},Kc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_INVALID_TRANSFORM= +function(){return(Kc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_INVALID_TRANSFORM=a.asm.kb).apply(null,arguments)},Lc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_NO_TRANSFORM=function(){return(Lc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_NO_TRANSFORM=a.asm.lb).apply(null,arguments)},Mc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_QUANTIZATION_TRANSFORM=function(){return(Mc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_QUANTIZATION_TRANSFORM= +a.asm.mb).apply(null,arguments)},Nc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_OCTAHEDRON_TRANSFORM=function(){return(Nc=a._emscripten_enum_draco_AttributeTransformType_ATTRIBUTE_OCTAHEDRON_TRANSFORM=a.asm.nb).apply(null,arguments)},Oc=a._emscripten_enum_draco_GeometryAttribute_Type_INVALID=function(){return(Oc=a._emscripten_enum_draco_GeometryAttribute_Type_INVALID=a.asm.ob).apply(null,arguments)},Pc=a._emscripten_enum_draco_GeometryAttribute_Type_POSITION=function(){return(Pc=a._emscripten_enum_draco_GeometryAttribute_Type_POSITION= +a.asm.pb).apply(null,arguments)},Qc=a._emscripten_enum_draco_GeometryAttribute_Type_NORMAL=function(){return(Qc=a._emscripten_enum_draco_GeometryAttribute_Type_NORMAL=a.asm.qb).apply(null,arguments)},Rc=a._emscripten_enum_draco_GeometryAttribute_Type_COLOR=function(){return(Rc=a._emscripten_enum_draco_GeometryAttribute_Type_COLOR=a.asm.rb).apply(null,arguments)},Sc=a._emscripten_enum_draco_GeometryAttribute_Type_TEX_COORD=function(){return(Sc=a._emscripten_enum_draco_GeometryAttribute_Type_TEX_COORD= +a.asm.sb).apply(null,arguments)},Tc=a._emscripten_enum_draco_GeometryAttribute_Type_GENERIC=function(){return(Tc=a._emscripten_enum_draco_GeometryAttribute_Type_GENERIC=a.asm.tb).apply(null,arguments)},Uc=a._emscripten_enum_draco_EncodedGeometryType_INVALID_GEOMETRY_TYPE=function(){return(Uc=a._emscripten_enum_draco_EncodedGeometryType_INVALID_GEOMETRY_TYPE=a.asm.ub).apply(null,arguments)},Vc=a._emscripten_enum_draco_EncodedGeometryType_POINT_CLOUD=function(){return(Vc=a._emscripten_enum_draco_EncodedGeometryType_POINT_CLOUD= +a.asm.vb).apply(null,arguments)},Wc=a._emscripten_enum_draco_EncodedGeometryType_TRIANGULAR_MESH=function(){return(Wc=a._emscripten_enum_draco_EncodedGeometryType_TRIANGULAR_MESH=a.asm.wb).apply(null,arguments)},Xc=a._emscripten_enum_draco_DataType_DT_INVALID=function(){return(Xc=a._emscripten_enum_draco_DataType_DT_INVALID=a.asm.xb).apply(null,arguments)},Yc=a._emscripten_enum_draco_DataType_DT_INT8=function(){return(Yc=a._emscripten_enum_draco_DataType_DT_INT8=a.asm.yb).apply(null,arguments)},Zc= +a._emscripten_enum_draco_DataType_DT_UINT8=function(){return(Zc=a._emscripten_enum_draco_DataType_DT_UINT8=a.asm.zb).apply(null,arguments)},$c=a._emscripten_enum_draco_DataType_DT_INT16=function(){return($c=a._emscripten_enum_draco_DataType_DT_INT16=a.asm.Ab).apply(null,arguments)},ad=a._emscripten_enum_draco_DataType_DT_UINT16=function(){return(ad=a._emscripten_enum_draco_DataType_DT_UINT16=a.asm.Bb).apply(null,arguments)},bd=a._emscripten_enum_draco_DataType_DT_INT32=function(){return(bd=a._emscripten_enum_draco_DataType_DT_INT32= +a.asm.Cb).apply(null,arguments)},cd=a._emscripten_enum_draco_DataType_DT_UINT32=function(){return(cd=a._emscripten_enum_draco_DataType_DT_UINT32=a.asm.Db).apply(null,arguments)},dd=a._emscripten_enum_draco_DataType_DT_INT64=function(){return(dd=a._emscripten_enum_draco_DataType_DT_INT64=a.asm.Eb).apply(null,arguments)},ed=a._emscripten_enum_draco_DataType_DT_UINT64=function(){return(ed=a._emscripten_enum_draco_DataType_DT_UINT64=a.asm.Fb).apply(null,arguments)},fd=a._emscripten_enum_draco_DataType_DT_FLOAT32= +function(){return(fd=a._emscripten_enum_draco_DataType_DT_FLOAT32=a.asm.Gb).apply(null,arguments)},gd=a._emscripten_enum_draco_DataType_DT_FLOAT64=function(){return(gd=a._emscripten_enum_draco_DataType_DT_FLOAT64=a.asm.Hb).apply(null,arguments)},hd=a._emscripten_enum_draco_DataType_DT_BOOL=function(){return(hd=a._emscripten_enum_draco_DataType_DT_BOOL=a.asm.Ib).apply(null,arguments)},id=a._emscripten_enum_draco_DataType_DT_TYPES_COUNT=function(){return(id=a._emscripten_enum_draco_DataType_DT_TYPES_COUNT= +a.asm.Jb).apply(null,arguments)},jd=a._emscripten_enum_draco_StatusCode_OK=function(){return(jd=a._emscripten_enum_draco_StatusCode_OK=a.asm.Kb).apply(null,arguments)},kd=a._emscripten_enum_draco_StatusCode_DRACO_ERROR=function(){return(kd=a._emscripten_enum_draco_StatusCode_DRACO_ERROR=a.asm.Lb).apply(null,arguments)},ld=a._emscripten_enum_draco_StatusCode_IO_ERROR=function(){return(ld=a._emscripten_enum_draco_StatusCode_IO_ERROR=a.asm.Mb).apply(null,arguments)},md=a._emscripten_enum_draco_StatusCode_INVALID_PARAMETER= +function(){return(md=a._emscripten_enum_draco_StatusCode_INVALID_PARAMETER=a.asm.Nb).apply(null,arguments)},nd=a._emscripten_enum_draco_StatusCode_UNSUPPORTED_VERSION=function(){return(nd=a._emscripten_enum_draco_StatusCode_UNSUPPORTED_VERSION=a.asm.Ob).apply(null,arguments)},od=a._emscripten_enum_draco_StatusCode_UNKNOWN_VERSION=function(){return(od=a._emscripten_enum_draco_StatusCode_UNKNOWN_VERSION=a.asm.Pb).apply(null,arguments)};a._malloc=function(){return(a._malloc=a.asm.Qb).apply(null,arguments)}; +a._free=function(){return(a._free=a.asm.Rb).apply(null,arguments)};var ua=function(){return(ua=a.asm.Sb).apply(null,arguments)};a.___start_em_js=11660;a.___stop_em_js=11758;var la;ha=function b(){la||F();la||(ha=b)};if(a.preInit)for("function"==typeof a.preInit&&(a.preInit=[a.preInit]);0=r.size?(0>>=0;switch(c.BYTES_PER_ELEMENT){case 2:d>>>=1;break;case 4:d>>>=2;break;case 8:d>>>=3}for(var g=0;gb.byteLength)return a.INVALID_GEOMETRY_TYPE;switch(b[7]){case 0:return a.POINT_CLOUD;case 1:return a.TRIANGULAR_MESH;default:return a.INVALID_GEOMETRY_TYPE}};return n.ready}}();"object"===typeof exports&&"object"===typeof module?module.exports=DracoDecoderModule:"function"===typeof define&&define.amd?define([],function(){return DracoDecoderModule}):"object"===typeof exports&&(exports.DracoDecoderModule=DracoDecoderModule); diff --git a/libs/three.js/r171/examples/jsm/libs/ktx-parse.module.js b/libs/three.js/r171/examples/jsm/libs/ktx-parse.module.js new file mode 100644 index 000000000..3593d4378 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/ktx-parse.module.js @@ -0,0 +1 @@ +const t=0,e=1,n=2,i=3,s=0,a=0,r=2,o=0,l=1,f=160,h=161,U=162,c=163,_=166,p=0,g=1,y=0,x=1,u=2,b=3,d=4,w=5,m=6,D=7,B=8,L=9,v=10,A=11,k=12,V=13,I=14,S=15,F=16,O=17,E=18,T=0,C=1,M=2,P=3,z=4,W=5,H=6,N=7,K=8,X=9,R=10,Y=11,j=0,q=1,G=2,J=13,Q=14,Z=15,$=128,tt=64,et=32,nt=16,it=0,st=1,at=2,rt=3,ot=4,lt=5,ft=6,ht=7,Ut=8,ct=9,_t=10,pt=13,gt=14,yt=15,xt=16,ut=17,bt=20,dt=21,wt=22,mt=23,Dt=24,Bt=27,Lt=28,vt=29,At=30,kt=31,Vt=34,It=35,St=36,Ft=37,Ot=38,Et=41,Tt=42,Ct=43,Mt=44,Pt=45,zt=48,Wt=49,Ht=50,Nt=58,Kt=59,Xt=62,Rt=63,Yt=64,jt=65,qt=68,Gt=69,Jt=70,Qt=71,Zt=74,$t=75,te=76,ee=77,ne=78,ie=81,se=82,ae=83,re=84,oe=85,le=88,fe=89,he=90,Ue=91,ce=92,_e=95,pe=96,ge=97,ye=98,xe=99,ue=100,be=101,de=102,we=103,me=104,De=105,Be=106,Le=107,ve=108,Ae=109,ke=110,Ve=111,Ie=112,Se=113,Fe=114,Oe=115,Ee=116,Te=117,Ce=118,Me=119,Pe=120,ze=121,We=122,He=123,Ne=124,Ke=125,Xe=126,Re=127,Ye=128,je=129,qe=130,Ge=131,Je=132,Qe=133,Ze=134,$e=135,tn=136,en=137,nn=138,sn=139,an=140,rn=141,on=142,ln=143,fn=144,hn=145,Un=146,cn=147,_n=148,pn=149,gn=150,yn=151,xn=152,un=153,bn=154,dn=155,wn=156,mn=157,Dn=158,Bn=159,Ln=160,vn=161,An=162,kn=163,Vn=164,In=165,Sn=166,Fn=167,On=168,En=169,Tn=170,Cn=171,Mn=172,Pn=173,zn=174,Wn=175,Hn=176,Nn=177,Kn=178,Xn=179,Rn=180,Yn=181,jn=182,qn=183,Gn=184,Jn=1000156007,Qn=1000156008,Zn=1000156009,$n=1000156010,ti=1000156011,ei=1000156017,ni=1000156018,ii=1000156019,si=1000156020,ai=1000156021,ri=1000054e3,oi=1000054001,li=1000054002,fi=1000054003,hi=1000054004,Ui=1000054005,ci=1000054006,_i=1000054007,pi=1000066e3,gi=1000066001,yi=1000066002,xi=1000066003,ui=1000066004,bi=1000066005,di=1000066006,wi=1000066007,mi=1000066008,Di=1000066009,Bi=1000066010,Li=1000066011,vi=1000066012,Ai=1000066013,ki=100034e4,Vi=1000340001;class Ii{constructor(){this.vkFormat=0,this.typeSize=1,this.pixelWidth=0,this.pixelHeight=0,this.pixelDepth=0,this.layerCount=0,this.faceCount=1,this.supercompressionScheme=0,this.levels=[],this.dataFormatDescriptor=[{vendorId:0,descriptorType:0,descriptorBlockSize:0,versionNumber:2,colorModel:0,colorPrimaries:1,transferFunction:2,flags:0,texelBlockDimension:[0,0,0,0],bytesPlane:[0,0,0,0,0,0,0,0],samples:[]}],this.keyValue={},this.globalData=null}}class Si{constructor(t,e,n,i){this._dataView=void 0,this._littleEndian=void 0,this._offset=void 0,this._dataView=new DataView(t.buffer,t.byteOffset+e,n),this._littleEndian=i,this._offset=0}_nextUint8(){const t=this._dataView.getUint8(this._offset);return this._offset+=1,t}_nextUint16(){const t=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,t}_nextUint32(){const t=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,t}_nextUint64(){const t=this._dataView.getUint32(this._offset,this._littleEndian)+2**32*this._dataView.getUint32(this._offset+4,this._littleEndian);return this._offset+=8,t}_nextInt32(){const t=this._dataView.getInt32(this._offset,this._littleEndian);return this._offset+=4,t}_nextUint8Array(t){const e=new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+this._offset,t);return this._offset+=t,e}_skip(t){return this._offset+=t,this}_scan(t,e){void 0===e&&(e=0);const n=this._offset;let i=0;for(;this._dataView.getUint8(this._offset)!==e&&i0?U+a.byteLength:0;c%8&&(c+=8-c%8);const _=[],p=new DataView(new ArrayBuffer(3*t.levels.length*8)),g=new Uint32Array(t.levels.length);let y=0;0===t.supercompressionScheme&&(y=function(t,e){const n=Math.max(t,4),i=Math.min(t,4);let s=n;for(;s%i!=0;)s+=n;return s}(function(t){return t.levels[0].levelData.byteLength/function(t,e){let n=1;const i=[t.pixelWidth,t.pixelHeight,t.pixelDepth],s=function(t){const[e,n,i]=t.dataFormatDescriptor[0].texelBlockDimension;return[e+1,n+1,i+1]}(t);for(let t=0;t<3;t++)if(i[t]>0){const e=Math.ceil(Math.floor(i[t]*Math.pow(2,-0))/s[t]);n*=Math.max(1,e)}return t.layerCount>0&&(n*=t.layerCount),t.faceCount>0&&(n*=t.faceCount),n}(t)}(t)));let x=(c||U+a.byteLength)+n.byteLength;for(let e=t.levels.length-1;e>=0;e--){if(x%y){const t=Mi(x,y);_.push(new Uint8Array(t)),x+=t}const n=t.levels[e];_.push(n.levelData),g[e]=x,x+=n.levelData.byteLength}for(let e=0;e0?c:0),!0),b.setBigUint64(60,BigInt(n.byteLength),!0),new Uint8Array(Ci([new Uint8Array(Oi).buffer,u,p.buffer,o,a,c>0?new ArrayBuffer(c-(U+a.byteLength)):new ArrayBuffer(0),n,..._]))}export{Z as KHR_DF_CHANNEL_RGBSDA_ALPHA,G as KHR_DF_CHANNEL_RGBSDA_BLUE,Q as KHR_DF_CHANNEL_RGBSDA_DEPTH,q as KHR_DF_CHANNEL_RGBSDA_GREEN,j as KHR_DF_CHANNEL_RGBSDA_RED,J as KHR_DF_CHANNEL_RGBSDA_STENCIL,g as KHR_DF_FLAG_ALPHA_PREMULTIPLIED,p as KHR_DF_FLAG_ALPHA_STRAIGHT,s as KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT,U as KHR_DF_MODEL_ASTC,f as KHR_DF_MODEL_ETC1,c as KHR_DF_MODEL_ETC1S,h as KHR_DF_MODEL_ETC2,l as KHR_DF_MODEL_RGBSDA,_ as KHR_DF_MODEL_UASTC,o as KHR_DF_MODEL_UNSPECIFIED,H as KHR_DF_PRIMARIES_ACES,N as KHR_DF_PRIMARIES_ACESCC,Y as KHR_DF_PRIMARIES_ADOBERGB,z as KHR_DF_PRIMARIES_BT2020,M as KHR_DF_PRIMARIES_BT601_EBU,P as KHR_DF_PRIMARIES_BT601_SMPTE,C as KHR_DF_PRIMARIES_BT709,W as KHR_DF_PRIMARIES_CIEXYZ,R as KHR_DF_PRIMARIES_DISPLAYP3,K as KHR_DF_PRIMARIES_NTSC1953,X as KHR_DF_PRIMARIES_PAL525,T as KHR_DF_PRIMARIES_UNSPECIFIED,et as KHR_DF_SAMPLE_DATATYPE_EXPONENT,$ as KHR_DF_SAMPLE_DATATYPE_FLOAT,nt as KHR_DF_SAMPLE_DATATYPE_LINEAR,tt as KHR_DF_SAMPLE_DATATYPE_SIGNED,F as KHR_DF_TRANSFER_ACESCC,O as KHR_DF_TRANSFER_ACESCCT,E as KHR_DF_TRANSFER_ADOBERGB,D as KHR_DF_TRANSFER_BT1886,k as KHR_DF_TRANSFER_DCIP3,L as KHR_DF_TRANSFER_HLG_EOTF,B as KHR_DF_TRANSFER_HLG_OETF,b as KHR_DF_TRANSFER_ITU,x as KHR_DF_TRANSFER_LINEAR,d as KHR_DF_TRANSFER_NTSC,I as KHR_DF_TRANSFER_PAL625_EOTF,V as KHR_DF_TRANSFER_PAL_OETF,v as KHR_DF_TRANSFER_PQ_EOTF,A as KHR_DF_TRANSFER_PQ_OETF,w as KHR_DF_TRANSFER_SLOG,m as KHR_DF_TRANSFER_SLOG2,u as KHR_DF_TRANSFER_SRGB,S as KHR_DF_TRANSFER_ST240,y as KHR_DF_TRANSFER_UNSPECIFIED,a as KHR_DF_VENDORID_KHRONOS,r as KHR_DF_VERSION,e as KHR_SUPERCOMPRESSION_BASISLZ,t as KHR_SUPERCOMPRESSION_NONE,i as KHR_SUPERCOMPRESSION_ZLIB,n as KHR_SUPERCOMPRESSION_ZSTD,Ii as KTX2Container,Ut as VK_FORMAT_A1R5G5B5_UNORM_PACK16,Gt as VK_FORMAT_A2B10G10R10_SINT_PACK32,jt as VK_FORMAT_A2B10G10R10_SNORM_PACK32,qt as VK_FORMAT_A2B10G10R10_UINT_PACK32,Yt as VK_FORMAT_A2B10G10R10_UNORM_PACK32,Rt as VK_FORMAT_A2R10G10B10_SINT_PACK32,Kt as VK_FORMAT_A2R10G10B10_SNORM_PACK32,Xt as VK_FORMAT_A2R10G10B10_UINT_PACK32,Nt as VK_FORMAT_A2R10G10B10_UNORM_PACK32,Vi as VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT,ki as VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT,Li as VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK_EXT,Rn as VK_FORMAT_ASTC_10x10_SRGB_BLOCK,Xn as VK_FORMAT_ASTC_10x10_UNORM_BLOCK,mi as VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK_EXT,zn as VK_FORMAT_ASTC_10x5_SRGB_BLOCK,Pn as VK_FORMAT_ASTC_10x5_UNORM_BLOCK,Di as VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK_EXT,Hn as VK_FORMAT_ASTC_10x6_SRGB_BLOCK,Wn as VK_FORMAT_ASTC_10x6_UNORM_BLOCK,Bi as VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK_EXT,Kn as VK_FORMAT_ASTC_10x8_SRGB_BLOCK,Nn as VK_FORMAT_ASTC_10x8_UNORM_BLOCK,vi as VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK_EXT,jn as VK_FORMAT_ASTC_12x10_SRGB_BLOCK,Yn as VK_FORMAT_ASTC_12x10_UNORM_BLOCK,Ai as VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK_EXT,Gn as VK_FORMAT_ASTC_12x12_SRGB_BLOCK,qn as VK_FORMAT_ASTC_12x12_UNORM_BLOCK,pi as VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT,Dn as VK_FORMAT_ASTC_4x4_SRGB_BLOCK,mn as VK_FORMAT_ASTC_4x4_UNORM_BLOCK,gi as VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK_EXT,Ln as VK_FORMAT_ASTC_5x4_SRGB_BLOCK,Bn as VK_FORMAT_ASTC_5x4_UNORM_BLOCK,yi as VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK_EXT,An as VK_FORMAT_ASTC_5x5_SRGB_BLOCK,vn as VK_FORMAT_ASTC_5x5_UNORM_BLOCK,xi as VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK_EXT,Vn as VK_FORMAT_ASTC_6x5_SRGB_BLOCK,kn as VK_FORMAT_ASTC_6x5_UNORM_BLOCK,ui as VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK_EXT,Sn as VK_FORMAT_ASTC_6x6_SRGB_BLOCK,In as VK_FORMAT_ASTC_6x6_UNORM_BLOCK,bi as VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK_EXT,On as VK_FORMAT_ASTC_8x5_SRGB_BLOCK,Fn as VK_FORMAT_ASTC_8x5_UNORM_BLOCK,di as VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK_EXT,Tn as VK_FORMAT_ASTC_8x6_SRGB_BLOCK,En as VK_FORMAT_ASTC_8x6_UNORM_BLOCK,wi as VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK_EXT,Mn as VK_FORMAT_ASTC_8x8_SRGB_BLOCK,Cn as VK_FORMAT_ASTC_8x8_UNORM_BLOCK,We as VK_FORMAT_B10G11R11_UFLOAT_PACK32,ti as VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,ai as VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,rt as VK_FORMAT_B4G4R4A4_UNORM_PACK16,ht as VK_FORMAT_B5G5R5A1_UNORM_PACK16,lt as VK_FORMAT_B5G6R5_UNORM_PACK16,Wt as VK_FORMAT_B8G8R8A8_SINT,Pt as VK_FORMAT_B8G8R8A8_SNORM,Ht as VK_FORMAT_B8G8R8A8_SRGB,zt as VK_FORMAT_B8G8R8A8_UINT,Mt as VK_FORMAT_B8G8R8A8_UNORM,It as VK_FORMAT_B8G8R8_SINT,kt as VK_FORMAT_B8G8R8_SNORM,St as VK_FORMAT_B8G8R8_SRGB,Vt as VK_FORMAT_B8G8R8_UINT,At as VK_FORMAT_B8G8R8_UNORM,Ze as VK_FORMAT_BC1_RGBA_SRGB_BLOCK,Qe as VK_FORMAT_BC1_RGBA_UNORM_BLOCK,Je as VK_FORMAT_BC1_RGB_SRGB_BLOCK,Ge as VK_FORMAT_BC1_RGB_UNORM_BLOCK,tn as VK_FORMAT_BC2_SRGB_BLOCK,$e as VK_FORMAT_BC2_UNORM_BLOCK,nn as VK_FORMAT_BC3_SRGB_BLOCK,en as VK_FORMAT_BC3_UNORM_BLOCK,an as VK_FORMAT_BC4_SNORM_BLOCK,sn as VK_FORMAT_BC4_UNORM_BLOCK,on as VK_FORMAT_BC5_SNORM_BLOCK,rn as VK_FORMAT_BC5_UNORM_BLOCK,fn as VK_FORMAT_BC6H_SFLOAT_BLOCK,ln as VK_FORMAT_BC6H_UFLOAT_BLOCK,Un as VK_FORMAT_BC7_SRGB_BLOCK,hn as VK_FORMAT_BC7_UNORM_BLOCK,Ne as VK_FORMAT_D16_UNORM,Ye as VK_FORMAT_D16_UNORM_S8_UINT,je as VK_FORMAT_D24_UNORM_S8_UINT,Xe as VK_FORMAT_D32_SFLOAT,qe as VK_FORMAT_D32_SFLOAT_S8_UINT,He as VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,wn as VK_FORMAT_EAC_R11G11_SNORM_BLOCK,dn as VK_FORMAT_EAC_R11G11_UNORM_BLOCK,bn as VK_FORMAT_EAC_R11_SNORM_BLOCK,un as VK_FORMAT_EAC_R11_UNORM_BLOCK,gn as VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,pn as VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,xn as VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,yn as VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,_n as VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,cn as VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,$n as VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,si as VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,hi as VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG,ri as VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG,Ui as VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG,oi as VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG,ci as VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG,li as VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG,_i as VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG,fi as VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG,Zn as VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16,Qn as VK_FORMAT_R10X6G10X6_UNORM_2PACK16,Jn as VK_FORMAT_R10X6_UNORM_PACK16,ii as VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,ni as VK_FORMAT_R12X4G12X4_UNORM_2PACK16,ei as VK_FORMAT_R12X4_UNORM_PACK16,ge as VK_FORMAT_R16G16B16A16_SFLOAT,pe as VK_FORMAT_R16G16B16A16_SINT,ce as VK_FORMAT_R16G16B16A16_SNORM,_e as VK_FORMAT_R16G16B16A16_UINT,Ue as VK_FORMAT_R16G16B16A16_UNORM,he as VK_FORMAT_R16G16B16_SFLOAT,fe as VK_FORMAT_R16G16B16_SINT,oe as VK_FORMAT_R16G16B16_SNORM,le as VK_FORMAT_R16G16B16_UINT,re as VK_FORMAT_R16G16B16_UNORM,ae as VK_FORMAT_R16G16_SFLOAT,se as VK_FORMAT_R16G16_SINT,ne as VK_FORMAT_R16G16_SNORM,ie as VK_FORMAT_R16G16_UINT,ee as VK_FORMAT_R16G16_UNORM,te as VK_FORMAT_R16_SFLOAT,$t as VK_FORMAT_R16_SINT,Qt as VK_FORMAT_R16_SNORM,Zt as VK_FORMAT_R16_UINT,Jt as VK_FORMAT_R16_UNORM,Ae as VK_FORMAT_R32G32B32A32_SFLOAT,ve as VK_FORMAT_R32G32B32A32_SINT,Le as VK_FORMAT_R32G32B32A32_UINT,Be as VK_FORMAT_R32G32B32_SFLOAT,De as VK_FORMAT_R32G32B32_SINT,me as VK_FORMAT_R32G32B32_UINT,we as VK_FORMAT_R32G32_SFLOAT,de as VK_FORMAT_R32G32_SINT,be as VK_FORMAT_R32G32_UINT,ue as VK_FORMAT_R32_SFLOAT,xe as VK_FORMAT_R32_SINT,ye as VK_FORMAT_R32_UINT,at as VK_FORMAT_R4G4B4A4_UNORM_PACK16,st as VK_FORMAT_R4G4_UNORM_PACK8,ft as VK_FORMAT_R5G5B5A1_UNORM_PACK16,ot as VK_FORMAT_R5G6B5_UNORM_PACK16,ze as VK_FORMAT_R64G64B64A64_SFLOAT,Pe as VK_FORMAT_R64G64B64A64_SINT,Me as VK_FORMAT_R64G64B64A64_UINT,Ce as VK_FORMAT_R64G64B64_SFLOAT,Te as VK_FORMAT_R64G64B64_SINT,Ee as VK_FORMAT_R64G64B64_UINT,Oe as VK_FORMAT_R64G64_SFLOAT,Fe as VK_FORMAT_R64G64_SINT,Se as VK_FORMAT_R64G64_UINT,Ie as VK_FORMAT_R64_SFLOAT,Ve as VK_FORMAT_R64_SINT,ke as VK_FORMAT_R64_UINT,Tt as VK_FORMAT_R8G8B8A8_SINT,Ot as VK_FORMAT_R8G8B8A8_SNORM,Ct as VK_FORMAT_R8G8B8A8_SRGB,Et as VK_FORMAT_R8G8B8A8_UINT,Ft as VK_FORMAT_R8G8B8A8_UNORM,Lt as VK_FORMAT_R8G8B8_SINT,Dt as VK_FORMAT_R8G8B8_SNORM,vt as VK_FORMAT_R8G8B8_SRGB,Bt as VK_FORMAT_R8G8B8_UINT,mt as VK_FORMAT_R8G8B8_UNORM,dt as VK_FORMAT_R8G8_SINT,ut as VK_FORMAT_R8G8_SNORM,wt as VK_FORMAT_R8G8_SRGB,bt as VK_FORMAT_R8G8_UINT,xt as VK_FORMAT_R8G8_UNORM,gt as VK_FORMAT_R8_SINT,_t as VK_FORMAT_R8_SNORM,yt as VK_FORMAT_R8_SRGB,pt as VK_FORMAT_R8_UINT,ct as VK_FORMAT_R8_UNORM,Re as VK_FORMAT_S8_UINT,it as VK_FORMAT_UNDEFINED,Ke as VK_FORMAT_X8_D24_UNORM_PACK32,Pi as read,Wi as write}; diff --git a/libs/three.js/r171/examples/jsm/libs/lil-gui.module.min.js b/libs/three.js/r171/examples/jsm/libs/lil-gui.module.min.js new file mode 100644 index 000000000..c76a5ef8a --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/lil-gui.module.min.js @@ -0,0 +1,8 @@ +/** + * lil-gui + * https://lil-gui.georgealways.com + * @version 0.17.0 + * @author George Michael Brower + * @license MIT + */ +class t{constructor(i,e,s,n,l="div"){this.parent=i,this.object=e,this.property=s,this._disabled=!1,this._hidden=!1,this.initialValue=this.getValue(),this.domElement=document.createElement("div"),this.domElement.classList.add("controller"),this.domElement.classList.add(n),this.$name=document.createElement("div"),this.$name.classList.add("name"),t.nextNameID=t.nextNameID||0,this.$name.id="lil-gui-name-"+ ++t.nextNameID,this.$widget=document.createElement(l),this.$widget.classList.add("widget"),this.$disable=this.$widget,this.domElement.appendChild(this.$name),this.domElement.appendChild(this.$widget),this.parent.children.push(this),this.parent.controllers.push(this),this.parent.$children.appendChild(this.domElement),this._listenCallback=this._listenCallback.bind(this),this.name(s)}name(t){return this._name=t,this.$name.innerHTML=t,this}onChange(t){return this._onChange=t,this}_callOnChange(){this.parent._callOnChange(this),void 0!==this._onChange&&this._onChange.call(this,this.getValue()),this._changed=!0}onFinishChange(t){return this._onFinishChange=t,this}_callOnFinishChange(){this._changed&&(this.parent._callOnFinishChange(this),void 0!==this._onFinishChange&&this._onFinishChange.call(this,this.getValue())),this._changed=!1}reset(){return this.setValue(this.initialValue),this._callOnFinishChange(),this}enable(t=!0){return this.disable(!t)}disable(t=!0){return t===this._disabled||(this._disabled=t,this.domElement.classList.toggle("disabled",t),this.$disable.toggleAttribute("disabled",t)),this}show(t=!0){return this._hidden=!t,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}options(t){const i=this.parent.add(this.object,this.property,t);return i.name(this._name),this.destroy(),i}min(t){return this}max(t){return this}step(t){return this}decimals(t){return this}listen(t=!0){return this._listening=t,void 0!==this._listenCallbackID&&(cancelAnimationFrame(this._listenCallbackID),this._listenCallbackID=void 0),this._listening&&this._listenCallback(),this}_listenCallback(){this._listenCallbackID=requestAnimationFrame(this._listenCallback);const t=this.save();t!==this._listenPrevValue&&this.updateDisplay(),this._listenPrevValue=t}getValue(){return this.object[this.property]}setValue(t){return this.object[this.property]=t,this._callOnChange(),this.updateDisplay(),this}updateDisplay(){return this}load(t){return this.setValue(t),this._callOnFinishChange(),this}save(){return this.getValue()}destroy(){this.listen(!1),this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.controllers.splice(this.parent.controllers.indexOf(this),1),this.parent.$children.removeChild(this.domElement)}}class i extends t{constructor(t,i,e){super(t,i,e,"boolean","label"),this.$input=document.createElement("input"),this.$input.setAttribute("type","checkbox"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$widget.appendChild(this.$input),this.$input.addEventListener("change",()=>{this.setValue(this.$input.checked),this._callOnFinishChange()}),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.checked=this.getValue(),this}}function e(t){let i,e;return(i=t.match(/(#|0x)?([a-f0-9]{6})/i))?e=i[2]:(i=t.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/))?e=parseInt(i[1]).toString(16).padStart(2,0)+parseInt(i[2]).toString(16).padStart(2,0)+parseInt(i[3]).toString(16).padStart(2,0):(i=t.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i))&&(e=i[1]+i[1]+i[2]+i[2]+i[3]+i[3]),!!e&&"#"+e}const s={isPrimitive:!0,match:t=>"string"==typeof t,fromHexString:e,toHexString:e},n={isPrimitive:!0,match:t=>"number"==typeof t,fromHexString:t=>parseInt(t.substring(1),16),toHexString:t=>"#"+t.toString(16).padStart(6,0)},l={isPrimitive:!1,match:Array.isArray,fromHexString(t,i,e=1){const s=n.fromHexString(t);i[0]=(s>>16&255)/255*e,i[1]=(s>>8&255)/255*e,i[2]=(255&s)/255*e},toHexString:([t,i,e],s=1)=>n.toHexString(t*(s=255/s)<<16^i*s<<8^e*s<<0)},r={isPrimitive:!1,match:t=>Object(t)===t,fromHexString(t,i,e=1){const s=n.fromHexString(t);i.r=(s>>16&255)/255*e,i.g=(s>>8&255)/255*e,i.b=(255&s)/255*e},toHexString:({r:t,g:i,b:e},s=1)=>n.toHexString(t*(s=255/s)<<16^i*s<<8^e*s<<0)},o=[s,n,l,r];class a extends t{constructor(t,i,s,n){var l;super(t,i,s,"color"),this.$input=document.createElement("input"),this.$input.setAttribute("type","color"),this.$input.setAttribute("tabindex",-1),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$text=document.createElement("input"),this.$text.setAttribute("type","text"),this.$text.setAttribute("spellcheck","false"),this.$text.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this.$display.appendChild(this.$input),this.$widget.appendChild(this.$display),this.$widget.appendChild(this.$text),this._format=(l=this.initialValue,o.find(t=>t.match(l))),this._rgbScale=n,this._initialValueHexString=this.save(),this._textFocused=!1,this.$input.addEventListener("input",()=>{this._setValueFromHexString(this.$input.value)}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$text.addEventListener("input",()=>{const t=e(this.$text.value);t&&this._setValueFromHexString(t)}),this.$text.addEventListener("focus",()=>{this._textFocused=!0,this.$text.select()}),this.$text.addEventListener("blur",()=>{this._textFocused=!1,this.updateDisplay(),this._callOnFinishChange()}),this.$disable=this.$text,this.updateDisplay()}reset(){return this._setValueFromHexString(this._initialValueHexString),this}_setValueFromHexString(t){if(this._format.isPrimitive){const i=this._format.fromHexString(t);this.setValue(i)}else this._format.fromHexString(t,this.getValue(),this._rgbScale),this._callOnChange(),this.updateDisplay()}save(){return this._format.toHexString(this.getValue(),this._rgbScale)}load(t){return this._setValueFromHexString(t),this._callOnFinishChange(),this}updateDisplay(){return this.$input.value=this._format.toHexString(this.getValue(),this._rgbScale),this._textFocused||(this.$text.value=this.$input.value.substring(1)),this.$display.style.backgroundColor=this.$input.value,this}}class h extends t{constructor(t,i,e){super(t,i,e,"function"),this.$button=document.createElement("button"),this.$button.appendChild(this.$name),this.$widget.appendChild(this.$button),this.$button.addEventListener("click",t=>{t.preventDefault(),this.getValue().call(this.object)}),this.$button.addEventListener("touchstart",()=>{},{passive:!0}),this.$disable=this.$button}}class d extends t{constructor(t,i,e,s,n,l){super(t,i,e,"number"),this._initInput(),this.min(s),this.max(n);const r=void 0!==l;this.step(r?l:this._getImplicitStep(),r),this.updateDisplay()}decimals(t){return this._decimals=t,this.updateDisplay(),this}min(t){return this._min=t,this._onUpdateMinMax(),this}max(t){return this._max=t,this._onUpdateMinMax(),this}step(t,i=!0){return this._step=t,this._stepExplicit=i,this}updateDisplay(){const t=this.getValue();if(this._hasSlider){let i=(t-this._min)/(this._max-this._min);i=Math.max(0,Math.min(i,1)),this.$fill.style.width=100*i+"%"}return this._inputFocused||(this.$input.value=void 0===this._decimals?t:t.toFixed(this._decimals)),this}_initInput(){this.$input=document.createElement("input"),this.$input.setAttribute("type","number"),this.$input.setAttribute("step","any"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$widget.appendChild(this.$input),this.$disable=this.$input;const t=t=>{const i=parseFloat(this.$input.value);isNaN(i)||(this._snapClampSetValue(i+t),this.$input.value=this.getValue())};let i,e,s,n,l,r=!1;const o=t=>{if(r){const s=t.clientX-i,n=t.clientY-e;Math.abs(n)>5?(t.preventDefault(),this.$input.blur(),r=!1,this._setDraggingStyle(!0,"vertical")):Math.abs(s)>5&&a()}if(!r){const i=t.clientY-s;l-=i*this._step*this._arrowKeyMultiplier(t),n+l>this._max?l=this._max-n:n+l{this._setDraggingStyle(!1,"vertical"),this._callOnFinishChange(),window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",a)};this.$input.addEventListener("input",()=>{let t=parseFloat(this.$input.value);isNaN(t)||(this._stepExplicit&&(t=this._snap(t)),this.setValue(this._clamp(t)))}),this.$input.addEventListener("keydown",i=>{"Enter"===i.code&&this.$input.blur(),"ArrowUp"===i.code&&(i.preventDefault(),t(this._step*this._arrowKeyMultiplier(i))),"ArrowDown"===i.code&&(i.preventDefault(),t(this._step*this._arrowKeyMultiplier(i)*-1))}),this.$input.addEventListener("wheel",i=>{this._inputFocused&&(i.preventDefault(),t(this._step*this._normalizeMouseWheel(i)))},{passive:!1}),this.$input.addEventListener("mousedown",t=>{i=t.clientX,e=s=t.clientY,r=!0,n=this.getValue(),l=0,window.addEventListener("mousemove",o),window.addEventListener("mouseup",a)}),this.$input.addEventListener("focus",()=>{this._inputFocused=!0}),this.$input.addEventListener("blur",()=>{this._inputFocused=!1,this.updateDisplay(),this._callOnFinishChange()})}_initSlider(){this._hasSlider=!0,this.$slider=document.createElement("div"),this.$slider.classList.add("slider"),this.$fill=document.createElement("div"),this.$fill.classList.add("fill"),this.$slider.appendChild(this.$fill),this.$widget.insertBefore(this.$slider,this.$input),this.domElement.classList.add("hasSlider");const t=t=>{const i=this.$slider.getBoundingClientRect();let e=(s=t,n=i.left,l=i.right,r=this._min,o=this._max,(s-n)/(l-n)*(o-r)+r);var s,n,l,r,o;this._snapClampSetValue(e)},i=i=>{t(i.clientX)},e=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",e)};let s,n,l=!1;const r=i=>{i.preventDefault(),this._setDraggingStyle(!0),t(i.touches[0].clientX),l=!1},o=i=>{if(l){const t=i.touches[0].clientX-s,e=i.touches[0].clientY-n;Math.abs(t)>Math.abs(e)?r(i):(window.removeEventListener("touchmove",o),window.removeEventListener("touchend",a))}else i.preventDefault(),t(i.touches[0].clientX)},a=()=>{this._callOnFinishChange(),this._setDraggingStyle(!1),window.removeEventListener("touchmove",o),window.removeEventListener("touchend",a)},h=this._callOnFinishChange.bind(this);let d;this.$slider.addEventListener("mousedown",s=>{this._setDraggingStyle(!0),t(s.clientX),window.addEventListener("mousemove",i),window.addEventListener("mouseup",e)}),this.$slider.addEventListener("touchstart",t=>{t.touches.length>1||(this._hasScrollBar?(s=t.touches[0].clientX,n=t.touches[0].clientY,l=!0):r(t),window.addEventListener("touchmove",o,{passive:!1}),window.addEventListener("touchend",a))},{passive:!1}),this.$slider.addEventListener("wheel",t=>{if(Math.abs(t.deltaX)this._max&&(t=this._max),t}_snapClampSetValue(t){this.setValue(this._clamp(this._snap(t)))}get _hasScrollBar(){const t=this.parent.root.$children;return t.scrollHeight>t.clientHeight}get _hasMin(){return void 0!==this._min}get _hasMax(){return void 0!==this._max}}class c extends t{constructor(t,i,e,s){super(t,i,e,"option"),this.$select=document.createElement("select"),this.$select.setAttribute("aria-labelledby",this.$name.id),this.$display=document.createElement("div"),this.$display.classList.add("display"),this._values=Array.isArray(s)?s:Object.values(s),this._names=Array.isArray(s)?s:Object.keys(s),this._names.forEach(t=>{const i=document.createElement("option");i.innerHTML=t,this.$select.appendChild(i)}),this.$select.addEventListener("change",()=>{this.setValue(this._values[this.$select.selectedIndex]),this._callOnFinishChange()}),this.$select.addEventListener("focus",()=>{this.$display.classList.add("focus")}),this.$select.addEventListener("blur",()=>{this.$display.classList.remove("focus")}),this.$widget.appendChild(this.$select),this.$widget.appendChild(this.$display),this.$disable=this.$select,this.updateDisplay()}updateDisplay(){const t=this.getValue(),i=this._values.indexOf(t);return this.$select.selectedIndex=i,this.$display.innerHTML=-1===i?t:this._names[i],this}}class u extends t{constructor(t,i,e){super(t,i,e,"string"),this.$input=document.createElement("input"),this.$input.setAttribute("type","text"),this.$input.setAttribute("aria-labelledby",this.$name.id),this.$input.addEventListener("input",()=>{this.setValue(this.$input.value)}),this.$input.addEventListener("keydown",t=>{"Enter"===t.code&&this.$input.blur()}),this.$input.addEventListener("blur",()=>{this._callOnFinishChange()}),this.$widget.appendChild(this.$input),this.$disable=this.$input,this.updateDisplay()}updateDisplay(){return this.$input.value=this.getValue(),this}}let p=!1;class g{constructor({parent:t,autoPlace:i=void 0===t,container:e,width:s,title:n="Controls",injectStyles:l=!0,touchStyles:r=!0}={}){if(this.parent=t,this.root=t?t.root:this,this.children=[],this.controllers=[],this.folders=[],this._closed=!1,this._hidden=!1,this.domElement=document.createElement("div"),this.domElement.classList.add("lil-gui"),this.$title=document.createElement("div"),this.$title.classList.add("title"),this.$title.setAttribute("role","button"),this.$title.setAttribute("aria-expanded",!0),this.$title.setAttribute("tabindex",0),this.$title.addEventListener("click",()=>this.openAnimated(this._closed)),this.$title.addEventListener("keydown",t=>{"Enter"!==t.code&&"Space"!==t.code||(t.preventDefault(),this.$title.click())}),this.$title.addEventListener("touchstart",()=>{},{passive:!0}),this.$children=document.createElement("div"),this.$children.classList.add("children"),this.domElement.appendChild(this.$title),this.domElement.appendChild(this.$children),this.title(n),r&&this.domElement.classList.add("allow-touch-styles"),this.parent)return this.parent.children.push(this),this.parent.folders.push(this),void this.parent.$children.appendChild(this.domElement);this.domElement.classList.add("root"),!p&&l&&(!function(t){const i=document.createElement("style");i.innerHTML=t;const e=document.querySelector("head link[rel=stylesheet], head style");e?document.head.insertBefore(i,e):document.head.appendChild(i)}('.lil-gui{--background-color:#1f1f1f;--text-color:#ebebeb;--title-background-color:#111;--title-text-color:#ebebeb;--widget-color:#424242;--hover-color:#4f4f4f;--focus-color:#595959;--number-color:#2cc9ff;--string-color:#a2db3c;--font-size:11px;--input-font-size:11px;--font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;--font-family-mono:Menlo,Monaco,Consolas,"Droid Sans Mono",monospace;--padding:4px;--spacing:4px;--widget-height:20px;--name-width:45%;--slider-knob-width:2px;--slider-input-width:27%;--color-input-width:27%;--slider-input-min-width:45px;--color-input-min-width:45px;--folder-indent:7px;--widget-padding:0 0 0 3px;--widget-border-radius:2px;--checkbox-size:calc(var(--widget-height)*0.75);--scrollbar-width:5px;background-color:var(--background-color);color:var(--text-color);font-family:var(--font-family);font-size:var(--font-size);font-style:normal;font-weight:400;line-height:1;text-align:left;touch-action:manipulation;user-select:none;-webkit-user-select:none}.lil-gui,.lil-gui *{box-sizing:border-box;margin:0;padding:0}.lil-gui.root{display:flex;flex-direction:column;width:var(--width,245px)}.lil-gui.root>.title{background:var(--title-background-color);color:var(--title-text-color)}.lil-gui.root>.children{overflow-x:hidden;overflow-y:auto}.lil-gui.root>.children::-webkit-scrollbar{background:var(--background-color);height:var(--scrollbar-width);width:var(--scrollbar-width)}.lil-gui.root>.children::-webkit-scrollbar-thumb{background:var(--focus-color);border-radius:var(--scrollbar-width)}.lil-gui.force-touch-styles{--widget-height:28px;--padding:6px;--spacing:6px;--font-size:13px;--input-font-size:16px;--folder-indent:10px;--scrollbar-width:7px;--slider-input-min-width:50px;--color-input-min-width:65px}.lil-gui.autoPlace{max-height:100%;position:fixed;right:15px;top:0;z-index:1001}.lil-gui .controller{align-items:center;display:flex;margin:var(--spacing) 0;padding:0 var(--padding)}.lil-gui .controller.disabled{opacity:.5}.lil-gui .controller.disabled,.lil-gui .controller.disabled *{pointer-events:none!important}.lil-gui .controller>.name{flex-shrink:0;line-height:var(--widget-height);min-width:var(--name-width);padding-right:var(--spacing);white-space:pre}.lil-gui .controller .widget{align-items:center;display:flex;min-height:var(--widget-height);position:relative;width:100%}.lil-gui .controller.string input{color:var(--string-color)}.lil-gui .controller.boolean .widget{cursor:pointer}.lil-gui .controller.color .display{border-radius:var(--widget-border-radius);height:var(--widget-height);position:relative;width:100%}.lil-gui .controller.color input[type=color]{cursor:pointer;height:100%;opacity:0;width:100%}.lil-gui .controller.color input[type=text]{flex-shrink:0;font-family:var(--font-family-mono);margin-left:var(--spacing);min-width:var(--color-input-min-width);width:var(--color-input-width)}.lil-gui .controller.option select{max-width:100%;opacity:0;position:absolute;width:100%}.lil-gui .controller.option .display{background:var(--widget-color);border-radius:var(--widget-border-radius);height:var(--widget-height);line-height:var(--widget-height);max-width:100%;overflow:hidden;padding-left:.55em;padding-right:1.75em;pointer-events:none;position:relative;word-break:break-all}.lil-gui .controller.option .display.active{background:var(--focus-color)}.lil-gui .controller.option .display:after{bottom:0;content:"↕";font-family:lil-gui;padding-right:.375em;position:absolute;right:0;top:0}.lil-gui .controller.option .widget,.lil-gui .controller.option select{cursor:pointer}.lil-gui .controller.number input{color:var(--number-color)}.lil-gui .controller.number.hasSlider input{flex-shrink:0;margin-left:var(--spacing);min-width:var(--slider-input-min-width);width:var(--slider-input-width)}.lil-gui .controller.number .slider{background-color:var(--widget-color);border-radius:var(--widget-border-radius);cursor:ew-resize;height:var(--widget-height);overflow:hidden;padding-right:var(--slider-knob-width);touch-action:pan-y;width:100%}.lil-gui .controller.number .slider.active{background-color:var(--focus-color)}.lil-gui .controller.number .slider.active .fill{opacity:.95}.lil-gui .controller.number .fill{border-right:var(--slider-knob-width) solid var(--number-color);box-sizing:content-box;height:100%}.lil-gui-dragging .lil-gui{--hover-color:var(--widget-color)}.lil-gui-dragging *{cursor:ew-resize!important}.lil-gui-dragging.lil-gui-vertical *{cursor:ns-resize!important}.lil-gui .title{--title-height:calc(var(--widget-height) + var(--spacing)*1.25);-webkit-tap-highlight-color:transparent;text-decoration-skip:objects;cursor:pointer;font-weight:600;height:var(--title-height);line-height:calc(var(--title-height) - 4px);outline:none;padding:0 var(--padding)}.lil-gui .title:before{content:"▾";display:inline-block;font-family:lil-gui;padding-right:2px}.lil-gui .title:active{background:var(--title-background-color);opacity:.75}.lil-gui.root>.title:focus{text-decoration:none!important}.lil-gui.closed>.title:before{content:"▸"}.lil-gui.closed>.children{opacity:0;transform:translateY(-7px)}.lil-gui.closed:not(.transition)>.children{display:none}.lil-gui.transition>.children{overflow:hidden;pointer-events:none;transition-duration:.3s;transition-property:height,opacity,transform;transition-timing-function:cubic-bezier(.2,.6,.35,1)}.lil-gui .children:empty:before{content:"Empty";display:block;font-style:italic;height:var(--widget-height);line-height:var(--widget-height);margin:var(--spacing) 0;opacity:.5;padding:0 var(--padding)}.lil-gui.root>.children>.lil-gui>.title{border-width:0;border-bottom:1px solid var(--widget-color);border-left:0 solid var(--widget-color);border-right:0 solid var(--widget-color);border-top:1px solid var(--widget-color);transition:border-color .3s}.lil-gui.root>.children>.lil-gui.closed>.title{border-bottom-color:transparent}.lil-gui+.controller{border-top:1px solid var(--widget-color);margin-top:0;padding-top:var(--spacing)}.lil-gui .lil-gui .lil-gui>.title{border:none}.lil-gui .lil-gui .lil-gui>.children{border:none;border-left:2px solid var(--widget-color);margin-left:var(--folder-indent)}.lil-gui .lil-gui .controller{border:none}.lil-gui input{-webkit-tap-highlight-color:transparent;background:var(--widget-color);border:0;border-radius:var(--widget-border-radius);color:var(--text-color);font-family:var(--font-family);font-size:var(--input-font-size);height:var(--widget-height);outline:none;width:100%}.lil-gui input:disabled{opacity:1}.lil-gui input[type=number],.lil-gui input[type=text]{padding:var(--widget-padding)}.lil-gui input[type=number]:focus,.lil-gui input[type=text]:focus{background:var(--focus-color)}.lil-gui input::-webkit-inner-spin-button,.lil-gui input::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.lil-gui input[type=number]{-moz-appearance:textfield}.lil-gui input[type=checkbox]{appearance:none;-webkit-appearance:none;border-radius:var(--widget-border-radius);cursor:pointer;height:var(--checkbox-size);text-align:center;width:var(--checkbox-size)}.lil-gui input[type=checkbox]:checked:before{content:"✓";font-family:lil-gui;font-size:var(--checkbox-size);line-height:var(--checkbox-size)}.lil-gui button{-webkit-tap-highlight-color:transparent;background:var(--widget-color);border:1px solid var(--widget-color);border-radius:var(--widget-border-radius);color:var(--text-color);cursor:pointer;font-family:var(--font-family);font-size:var(--font-size);height:var(--widget-height);line-height:calc(var(--widget-height) - 4px);outline:none;text-align:center;text-transform:none;width:100%}.lil-gui button:active{background:var(--focus-color)}@font-face{font-family:lil-gui;src:url("data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAUsAAsAAAAACJwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAAH4AAADAImwmYE9TLzIAAAGIAAAAPwAAAGBKqH5SY21hcAAAAcgAAAD0AAACrukyyJBnbHlmAAACvAAAAF8AAACEIZpWH2hlYWQAAAMcAAAAJwAAADZfcj2zaGhlYQAAA0QAAAAYAAAAJAC5AHhobXR4AAADXAAAABAAAABMAZAAAGxvY2EAAANsAAAAFAAAACgCEgIybWF4cAAAA4AAAAAeAAAAIAEfABJuYW1lAAADoAAAASIAAAIK9SUU/XBvc3QAAATEAAAAZgAAAJCTcMc2eJxVjbEOgjAURU+hFRBK1dGRL+ALnAiToyMLEzFpnPz/eAshwSa97517c/MwwJmeB9kwPl+0cf5+uGPZXsqPu4nvZabcSZldZ6kfyWnomFY/eScKqZNWupKJO6kXN3K9uCVoL7iInPr1X5baXs3tjuMqCtzEuagm/AAlzQgPAAB4nGNgYRBlnMDAysDAYM/gBiT5oLQBAwuDJAMDEwMrMwNWEJDmmsJwgCFeXZghBcjlZMgFCzOiKOIFAB71Bb8AeJy1kjFuwkAQRZ+DwRAwBtNQRUGKQ8OdKCAWUhAgKLhIuAsVSpWz5Bbkj3dEgYiUIszqWdpZe+Z7/wB1oCYmIoboiwiLT2WjKl/jscrHfGg/pKdMkyklC5Zs2LEfHYpjcRoPzme9MWWmk3dWbK9ObkWkikOetJ554fWyoEsmdSlt+uR0pCJR34b6t/TVg1SY3sYvdf8vuiKrpyaDXDISiegp17p7579Gp3p++y7HPAiY9pmTibljrr85qSidtlg4+l25GLCaS8e6rRxNBmsnERunKbaOObRz7N72ju5vdAjYpBXHgJylOAVsMseDAPEP8LYoUHicY2BiAAEfhiAGJgZWBgZ7RnFRdnVJELCQlBSRlATJMoLV2DK4glSYs6ubq5vbKrJLSbGrgEmovDuDJVhe3VzcXFwNLCOILB/C4IuQ1xTn5FPilBTj5FPmBAB4WwoqAHicY2BkYGAA4sk1sR/j+W2+MnAzpDBgAyEMQUCSg4EJxAEAwUgFHgB4nGNgZGBgSGFggJMhDIwMqEAYAByHATJ4nGNgAIIUNEwmAABl3AGReJxjYAACIQYlBiMGJ3wQAEcQBEV4nGNgZGBgEGZgY2BiAAEQyQWEDAz/wXwGAAsPATIAAHicXdBNSsNAHAXwl35iA0UQXYnMShfS9GPZA7T7LgIu03SSpkwzYTIt1BN4Ak/gKTyAeCxfw39jZkjymzcvAwmAW/wgwHUEGDb36+jQQ3GXGot79L24jxCP4gHzF/EIr4jEIe7wxhOC3g2TMYy4Q7+Lu/SHuEd/ivt4wJd4wPxbPEKMX3GI5+DJFGaSn4qNzk8mcbKSR6xdXdhSzaOZJGtdapd4vVPbi6rP+cL7TGXOHtXKll4bY1Xl7EGnPtp7Xy2n00zyKLVHfkHBa4IcJ2oD3cgggWvt/V/FbDrUlEUJhTn/0azVWbNTNr0Ens8de1tceK9xZmfB1CPjOmPH4kitmvOubcNpmVTN3oFJyjzCvnmrwhJTzqzVj9jiSX911FjeAAB4nG3HMRKCMBBA0f0giiKi4DU8k0V2GWbIZDOh4PoWWvq6J5V8If9NVNQcaDhyouXMhY4rPTcG7jwYmXhKq8Wz+p762aNaeYXom2n3m2dLTVgsrCgFJ7OTmIkYbwIbC6vIB7WmFfAAAA==") format("woff")}@media (pointer:coarse){.lil-gui.allow-touch-styles{--widget-height:28px;--padding:6px;--spacing:6px;--font-size:13px;--input-font-size:16px;--folder-indent:10px;--scrollbar-width:7px;--slider-input-min-width:50px;--color-input-min-width:65px}}@media (hover:hover){.lil-gui .controller.color .display:hover:before{border:1px solid #fff9;border-radius:var(--widget-border-radius);bottom:0;content:" ";display:block;left:0;position:absolute;right:0;top:0}.lil-gui .controller.option .display.focus{background:var(--focus-color)}.lil-gui .controller.option .widget:hover .display{background:var(--hover-color)}.lil-gui .controller.number .slider:hover{background-color:var(--hover-color)}body:not(.lil-gui-dragging) .lil-gui .title:hover{background:var(--title-background-color);opacity:.85}.lil-gui .title:focus{text-decoration:underline var(--focus-color)}.lil-gui input:hover{background:var(--hover-color)}.lil-gui input:active{background:var(--focus-color)}.lil-gui input[type=checkbox]:focus{box-shadow:inset 0 0 0 1px var(--focus-color)}.lil-gui button:hover{background:var(--hover-color);border-color:var(--hover-color)}.lil-gui button:focus{border-color:var(--focus-color)}}'),p=!0),e?e.appendChild(this.domElement):i&&(this.domElement.classList.add("autoPlace"),document.body.appendChild(this.domElement)),s&&this.domElement.style.setProperty("--width",s+"px"),this.domElement.addEventListener("keydown",t=>t.stopPropagation()),this.domElement.addEventListener("keyup",t=>t.stopPropagation())}add(t,e,s,n,l){if(Object(s)===s)return new c(this,t,e,s);const r=t[e];switch(typeof r){case"number":return new d(this,t,e,s,n,l);case"boolean":return new i(this,t,e);case"string":return new u(this,t,e);case"function":return new h(this,t,e)}console.error("gui.add failed\n\tproperty:",e,"\n\tobject:",t,"\n\tvalue:",r)}addColor(t,i,e=1){return new a(this,t,i,e)}addFolder(t){return new g({parent:this,title:t})}load(t,i=!0){return t.controllers&&this.controllers.forEach(i=>{i instanceof h||i._name in t.controllers&&i.load(t.controllers[i._name])}),i&&t.folders&&this.folders.forEach(i=>{i._title in t.folders&&i.load(t.folders[i._title])}),this}save(t=!0){const i={controllers:{},folders:{}};return this.controllers.forEach(t=>{if(!(t instanceof h)){if(t._name in i.controllers)throw new Error(`Cannot save GUI with duplicate property "${t._name}"`);i.controllers[t._name]=t.save()}}),t&&this.folders.forEach(t=>{if(t._title in i.folders)throw new Error(`Cannot save GUI with duplicate folder "${t._title}"`);i.folders[t._title]=t.save()}),i}open(t=!0){return this._closed=!t,this.$title.setAttribute("aria-expanded",!this._closed),this.domElement.classList.toggle("closed",this._closed),this}close(){return this.open(!1)}show(t=!0){return this._hidden=!t,this.domElement.style.display=this._hidden?"none":"",this}hide(){return this.show(!1)}openAnimated(t=!0){return this._closed=!t,this.$title.setAttribute("aria-expanded",!this._closed),requestAnimationFrame(()=>{const i=this.$children.clientHeight;this.$children.style.height=i+"px",this.domElement.classList.add("transition");const e=t=>{t.target===this.$children&&(this.$children.style.height="",this.domElement.classList.remove("transition"),this.$children.removeEventListener("transitionend",e))};this.$children.addEventListener("transitionend",e);const s=t?this.$children.scrollHeight:0;this.domElement.classList.toggle("closed",!t),requestAnimationFrame(()=>{this.$children.style.height=s+"px"})}),this}title(t){return this._title=t,this.$title.innerHTML=t,this}reset(t=!0){return(t?this.controllersRecursive():this.controllers).forEach(t=>t.reset()),this}onChange(t){return this._onChange=t,this}_callOnChange(t){this.parent&&this.parent._callOnChange(t),void 0!==this._onChange&&this._onChange.call(this,{object:t.object,property:t.property,value:t.getValue(),controller:t})}onFinishChange(t){return this._onFinishChange=t,this}_callOnFinishChange(t){this.parent&&this.parent._callOnFinishChange(t),void 0!==this._onFinishChange&&this._onFinishChange.call(this,{object:t.object,property:t.property,value:t.getValue(),controller:t})}destroy(){this.parent&&(this.parent.children.splice(this.parent.children.indexOf(this),1),this.parent.folders.splice(this.parent.folders.indexOf(this),1)),this.domElement.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Array.from(this.children).forEach(t=>t.destroy())}controllersRecursive(){let t=Array.from(this.controllers);return this.folders.forEach(i=>{t=t.concat(i.controllersRecursive())}),t}foldersRecursive(){let t=Array.from(this.folders);return this.folders.forEach(i=>{t=t.concat(i.foldersRecursive())}),t}}export default g;export{i as BooleanController,a as ColorController,t as Controller,h as FunctionController,g as GUI,d as NumberController,c as OptionController,u as StringController}; diff --git a/libs/three.js/r171/examples/jsm/libs/meshopt_decoder.module.js b/libs/three.js/r171/examples/jsm/libs/meshopt_decoder.module.js new file mode 100644 index 000000000..d0933a940 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/meshopt_decoder.module.js @@ -0,0 +1,178 @@ +// This file is part of meshoptimizer library and is distributed under the terms of MIT License. +// Copyright (C) 2016-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) +var MeshoptDecoder = (function() { + "use strict"; + + // Built with clang version 14.0.4 + // Built from meshoptimizer 0.18 + var wasm_base = "b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuikqbeeedddillviebeoweuec:q;iekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbol79IV9Rbrq:P8Yqdbk;3sezu8Jjjjjbcj;eb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Radz1jjjbhwcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhDcbhqinaqae9pmeaDaeaq9RaqaDfae6Egkcsfgocl4cifcd4hxdndndndnaoc9WGgmTmbcbhPcehsawcjdfhzalhHinaraH9Rax6midnaraHaxfgl9RcK6mbczhoinawcj;cbfaogifgoc9WfhOdndndndndnaHaic9WfgAco4fRbbaAci4coG4ciGPlbedibkaO9cb83ibaOcwf9cb83ibxikaOalRblalRbbgAco4gCaCciSgCE86bbaocGfalclfaCfgORbbaAcl4ciGgCaCciSgCE86bbaocVfaOaCfgORbbaAcd4ciGgCaCciSgCE86bbaoc7faOaCfgORbbaAciGgAaAciSgAE86bbaoctfaOaAfgARbbalRbegOco4gCaCciSgCE86bbaoc91faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc4faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc93faAaCfgARbbaOciGgOaOciSgOE86bbaoc94faAaOfgARbbalRbdgOco4gCaCciSgCE86bbaoc95faAaCfgARbbaOcl4ciGgCaCciSgCE86bbaoc96faAaCfgARbbaOcd4ciGgCaCciSgCE86bbaoc97faAaCfgARbbaOciGgOaOciSgOE86bbaoc98faAaOfgORbbalRbiglco4gAaAciSgAE86bbaoc99faOaAfgORbbalcl4ciGgAaAciSgAE86bbaoc9:faOaAfgORbbalcd4ciGgAaAciSgAE86bbaocufaOaAfgoRbbalciGglalciSglE86bbaoalfhlxdkaOalRbwalRbbgAcl4gCaCcsSgCE86bbaocGfalcwfaCfgORbbaAcsGgAaAcsSgAE86bbaocVfaOaAfgORbbalRbegAcl4gCaCcsSgCE86bbaoc7faOaCfgORbbaAcsGgAaAcsSgAE86bbaoctfaOaAfgORbbalRbdgAcl4gCaCcsSgCE86bbaoc91faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc4faOaAfgORbbalRbigAcl4gCaCcsSgCE86bbaoc93faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc94faOaAfgORbbalRblgAcl4gCaCcsSgCE86bbaoc95faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc96faOaAfgORbbalRbvgAcl4gCaCcsSgCE86bbaoc97faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc98faOaAfgORbbalRbogAcl4gCaCcsSgCE86bbaoc99faOaCfgORbbaAcsGgAaAcsSgAE86bbaoc9:faOaAfgORbbalRbrglcl4gAaAcsSgAE86bbaocufaOaAfgoRbbalcsGglalcsSglE86bbaoalfhlxekaOal8Pbb83bbaOcwfalcwf8Pbb83bbalczfhlkdnaiam9pmbaiczfhoaral9RcL0mekkaiam6mialTmidnakTmbawaPfRbbhOcbhoazhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkkazcefhzaPcefgPad6hsalhHaPad9hmexvkkcbhlasceGmdxikalaxad2fhCdnakTmbcbhHcehsawcjdfhminaral9Rax6mialTmdalaxfhlawaHfRbbhOcbhoamhiinaiawcj;cbfaofRbbgAce4cbaAceG9R7aOfgO86bbaiadfhiaocefgoak9hmbkamcefhmaHcefgHad6hsaHad9hmbkaChlxikcbhocehsinaral9Rax6mdalTmealaxfhlaocefgoad6hsadao9hmbkaChlxdkcbhlasceGTmekc9:hoxikabaqad2fawcjdfakad2z1jjjb8Aawawcjdfakcufad2fadz1jjjb8Aakaqfhqalmbkc9:hoxekcbc99aral9Radcaadca0ESEhokavcj;ebf8Kjjjjbaok;yzeHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:jjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk;siliui99iue99dnaeTmbcbhiabhlindndnJ;Zl81Zalcof8UebgvciV:Y:vgoal8Ueb:YNgrJb;:FSNJbbbZJbbb:;arJbbbb9GEMgw:lJbbb9p9DTmbaw:OhDxekcjjjj94hDkalclf8Uebhqalcdf8UebhkabavcefciGaiVcetfaD87ebdndnaoak:YNgwJb;:FSNJbbbZJbbb:;awJbbbb9GEMgx:lJbbb9p9DTmbax:Ohkxekcjjjj94hkkabavcdfciGaiVcetfak87ebdndnaoaq:YNgoJb;:FSNJbbbZJbbb:;aoJbbbb9GEMgx:lJbbb9p9DTmbax:Ohqxekcjjjj94hqkabavcufciGaiVcetfaq87ebdndnJbbjZararN:tawawN:taoaoN:tgrJbbbbarJbbbb9GE:rJb;:FSNJbbbZMgr:lJbbb9p9DTmbar:Ohqxekcjjjj94hqkabavciGaiVcetfaq87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2geTmbinababydbgdcwtcw91:Yadce91cjjj;8ifcjjj98G::NUdbabclfhbaecufgembkkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;LeeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiclfaeclfydbBdbaicwfaecwfydbBdbaicxfaecxfydbBdbaiczfhiaeczfheadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk;aeedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdbaicxfalBdbaicwfalBdbaiclfalBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkkkebcjwklz9Kbb"; + var wasm_simd = "b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuikqbbebeedddilve9Weeeviebeoweuec:q;Aekr;leDo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949Wbwl79IV9RbDq;t9tqlbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk;h8JlHud97euo978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnadcefal0mbcuhoaiRbbc:Ge9hmbavaialfgrad9Rad;8qbbcj;abad9UhoaicefhldnadTmbaoc;WFbGgocjdaocjd6EhwcbhDinaDae9pmeawaeaD9RaDawfae6Egqcsfgoc9WGgkci2hxakcethmaocl4cifcd4hPabaDad2fhscbhzdnincehHalhOcbhAdninaraO9RaP6miavcj;cbfaAak2fhCaOaPfhlcbhidnakc;ab6mbaral9Rc;Gb6mbcbhoinaCaofhidndndndndnaOaoco4fRbbgXciGPlbedibkaipxbbbbbbbbbbbbbbbbpklbxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklbalczfhlkdndndndndnaXcd4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklzxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklzalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklzalczfhlkdndndndndnaXcl4ciGPlbedibkaipxbbbbbbbbbbbbbbbbpklaxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklaalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaialpbbbpklaalczfhlkdndndndndnaXco4Plbedibkaipxbbbbbbbbbbbbbbbbpkl8WxikaialpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalclfaYpQbfaXc:q:yjjbfRbbfhlxdkaialpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibaXc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgXcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spkl8WalcwfaYpQbfaXc:q:yjjbfRbbfhlxekaialpbbbpkl8Walczfhlkaoc;abfhiaocjefak0meaihoaral9Rc;Fb0mbkkdndnaiak9pmbaici4hoinaral9RcK6mdaCaifhXdndndndndnaOaico4fRbbaocoG4ciGPlbedibkaXpxbbbbbbbbbbbbbbbbpklbxikaXalpbblalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLgQcdp:meaQpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9ogLpxiiiiiiiiiiiiiiiip8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalclfaYpQbfaKc:q:yjjbfRbbfhlxdkaXalpbbwalpbbbgQclp:meaQpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9ogLpxssssssssssssssssp8JgQp5b9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibaKc:q:yjjbfpbbbgYaYpmbbbbbbbbbbbbbbbbaQp5e9cjF;8;4;W;G;ab9:9cU1:NgKcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPaLaQp9spklbalcwfaYpQbfaKc:q:yjjbfRbbfhlxekaXalpbbbpklbalczfhlkaocdfhoaiczfgiak6mbkkalTmbaAci6hHalhOaAcefgohAaoclSmdxekkcbhlaHceGmdkdnakTmbavcjdfazfhiavazfpbdbhYcbhXinaiavcj;cbfaXfgopblbgLcep9TaLpxeeeeeeeeeeeeeeeegQp9op9Hp9rgLaoakfpblb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jjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhodnaeTmbcmcsaDceSEhkcbhxcbhmcbhDcbhicbhlindnaoaq9nmbc9:hoxikdndnawRbbgrc;Ve0mbavc;abfalarcl4cu7fcsGcitfgPydlhsaPydbhzdnarcsGgPak9pmbavaiarcu7fcsGcdtfydbaxaPEhraPThPdndnadcd9hmbabaDcetfgHaz87ebaHcdfas87ebaHclfar87ebxekabaDcdtfgHazBdbaHclfasBdbaHcwfarBdbkaxaPfhxavc;abfalcitfgHarBdbaHasBdlavaicdtfarBdbavc;abfalcefcsGglcitfgHazBdbaHarBdlaiaPfhialcefhlxdkdndnaPcsSmbamaPfaPc987fcefhmxekaocefhrao8SbbgPcFeGhHdndnaPcu9mmbarhoxekaocvfhoaHcFbGhHcrhPdninar8SbbgOcFbGaPtaHVhHaOcu9kmearcefhraPcrfgPc8J9hmbxdkkarcefhokaHce4cbaHceG9R7amfhmkdndnadcd9hmbabaDcetfgraz87ebarcdfas87ebarclfam87ebxekabaDcdtfgrazBdbarclfasBdbarcwfamBdbkavc;abfalcitfgramBdbarasBdlavaicdtfamBdbavc;abfalcefcsGglcitfgrazBdbaramBdlaicefhialcefhlxekdnarcpe0mbaxcefgOavaiaqarcsGfRbbgPcl49RcsGcdtfydbaPcz6gHEhravaiaP9RcsGcdtfydbaOaHfgsaPcsGgOEhPaOThOdndnadcd9hmbabaDcetfgzax87ebazcdfar87ebazclfaP87ebxekabaDcdtfgzaxBdbazclfarBdbazcwfaPBdbkavaicdtfaxBdbavc;abfalcitfgzarBdbazaxBdlavaicefgicsGcdtfarBdbavc;abfalcefcsGcitfgzaPBdbazarBdlavaiaHfcsGgicdtfaPBdbavc;abfalcdfcsGglcitfgraxBdbaraPBdlalcefhlaiaOfhiasaOfhxxekaxcbaoRbbgzEgAarc;:eSgrfhsazcsGhCazcl4hXdndnazcs0mbascefhOxekashOavaiaX9RcsGcdtfydbhskdndnaCmbaOcefhxxekaOhxavaiaz9RcsGcdtfydbhOkdndnarTmbaocefhrxekaocdfhrao8SbegHcFeGhPdnaHcu9kmbaocofhAaPcFbGhPcrhodninar8SbbgHcFbGaotaPVhPaHcu9kmearcefhraocrfgoc8J9hmbkaAhrxekarcefhrkaPce4cbaPceG9R7amfgmhAkdndnaXcsSmbarhPxekarcefhPar8SbbgocFeGhHdnaocu9kmbarcvfhsaHcFbGhHcrhodninaP8SbbgrcFbGaotaHVhHarcu9kmeaPcefhPaocrfgoc8J9hmbkashPxekaPcefhPkaHce4cbaHceG9R7amfgmhskdndnaCcsSmbaPhoxekaPcefhoaP8SbbgrcFeGhHdnarcu9kmbaPcvfhOaHcFbGhHcrhrdninao8SbbgPcFbGartaHVhHaPcu9kmeaocefhoarcrfgrc8J9hmbkaOhoxekaocefhokaHce4cbaHceG9R7amfgmhOkdndnadcd9hmbabaDcetfgraA87ebarcdfas87ebarclfaO87ebxekabaDcdtfgraABdbarclfasBdbarcwfaOBdbkavc;abfalcitfgrasBdbaraABdlavaicdtfaABdbavc;abfalcefcsGcitfgraOBdbarasBdlavaicefgicsGcdtfasBdbavc;abfalcdfcsGcitfgraABdbaraOBdlavaiazcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhialcifhlkawcefhwalcsGhlaicsGhiaDcifgDae6mbkkcbc99aoaqSEhokavc;aef8Kjjjjbaok:llevu8Jjjjjbcz9Rhvc9:hodnaecvfal0mbcuhoaiRbbc;:eGc;qe9hmbav9cb83iwaicefhraialfc98fhwdnaeTmbdnadcdSmbcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcdtfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfglBdbaoalBdbaDcefgDae9hmbxdkkcbhDindnaraw6mbc9:skarcefhoar8SbbglcFeGhidndnalcu9mmbaohrxekarcvfhraicFbGhicrhldninao8SbbgdcFbGaltaiVhiadcu9kmeaocefhoalcrfglc8J9hmbxdkkaocefhrkabaDcetfaicd4cbaice4ceG9R7avcwfaiceGcdtVgoydbfgl87ebaoalBdbaDcefgDae9hmbkkcbc99arawSEhokaok:EPliuo97eue978Jjjjjbca9Rhidndnadcl9hmbdnaec98GglTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalae9pmeaiaeciGgvcdtgdVcbczad9R;8kbaiabalcdtfglad;8qbbdnavTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkalaiad;8qbbskdnaec98GgxTmbcbhvabhdinadczfglalpbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oawaopmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgvax6mbkkaxae9pmbaiaeciGgvcitgdfcbcaad9R;8kbaiabaxcitfglad;8qbbdnavTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmlvorxmPsCXQL358E8FpxFubbFubbFubbFubbp9op;6eaDaopmbediwDqkzHOAKY8AEgoczp:Sep;6egrp;Geaoczp:Reczp:Sep;6egwp;Gep;Kep;Legopxb;:FSb;:FSb;:FSb;:FSawaopxbbbbbbbbbbbbbbbbp:2egqawpxbbbjbbbjbbbjbbbjgmp9op9rp;Kegwawp;Meaoaop;Mearaqaramp9op9rp;Kegoaop;Mep;Kep;Kep;Jep;Negrp;Mepxbbn0bbn0bbn0bbn0gqp;Keczp:Reawarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9op9qgwaoarp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogopmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oawaopmbezHdiOAlvCXorQLp9qpklbkalaiad;8qbbkk;4wllue97euv978Jjjjjbc8W9Rhidnaec98GglTmbcbhvabhoinaiaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklbaopxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblbpEb:T:j83ibaocwfarp5eaipblbpEe:T:j83ibawaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblbpEd:T:j83ibaocKfakp5eaipblbpEi:T:j83ibaocafhoavclfgval6mbkkdnalae9pmbaiaeciGgvcitgofcbcaao9R;8kbaiabalcitfgwao;8qbbdnavTmbaiaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkclp:RepklaaipxbbjZbbjZbbjZbbjZpx;Zl81Z;Zl81Z;Zl81Z;Zl81Zakpxibbbibbbibbbibbbp9qp;6ep;NegkaraDpmbediwDqkzHOAKY8AEgrczp:Reczp:Sep;6ep;MegDaDp;Meakarczp:Sep;6ep;Megxaxp;Meakaqczp:Reczp:Sep;6ep;Megqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jepxb;:FSb;:FSb;:FSb;:FSgkp;Mepxbbn0bbn0bbn0bbn0grp;KepxFFbbFFbbFFbbFFbbgmp9oaxakp;Mearp;Keczp:Rep9qgxaqakp;Mearp;Keczp:ReaDakp;Mearp;Keamp9op9qgkpmbezHdiOAlvCXorQLgrp5baipblapEb:T:j83ibaiarp5eaipblapEe:T:j83iwaiaxakpmwDKYqk8AExm35Ps8E8Fgkp5baipblapEd:T:j83izaiakp5eaipblapEi:T:j83iKkawaiao;8qbbkk:Pddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbhdabheinaeaepbbbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepkbbaeczfheadclfgdav6mbkkdnaval9pmbaialciGgdcdtgeVcbc;abae9R;8kbaiabavcdtfgvae;8qbbdnadTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjZbbjZbbjZbbjZp:UepxbbjFbbjFbbjFbbjFp9op;Mepklbkavaiae;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz9Tbb"; + + var detector = new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]); + var wasmpack = new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]); + + if (typeof WebAssembly !== 'object') { + return { + supported: false, + }; + } + + var wasm = WebAssembly.validate(detector) ? wasm_simd : wasm_base; + + var instance; + + var ready = + WebAssembly.instantiate(unpack(wasm), {}) + .then(function(result) { + instance = result.instance; + instance.exports.__wasm_call_ctors(); + }); + + function unpack(data) { + var result = new Uint8Array(data.length); + for (var i = 0; i < data.length; ++i) { + var ch = data.charCodeAt(i); + result[i] = ch > 96 ? ch - 97 : ch > 64 ? ch - 39 : ch + 4; + } + var write = 0; + for (var i = 0; i < data.length; ++i) { + result[write++] = (result[i] < 60) ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i]; + } + return result.buffer.slice(0, write); + } + + function decode(fun, target, count, size, source, filter) { + var sbrk = instance.exports.sbrk; + var count4 = (count + 3) & ~3; + var tp = sbrk(count4 * size); + var sp = sbrk(source.length); + var heap = new Uint8Array(instance.exports.memory.buffer); + heap.set(source, sp); + var res = fun(tp, count, size, sp, source.length); + if (res == 0 && filter) { + filter(tp, count4, size); + } + target.set(heap.subarray(tp, tp + count * size)); + sbrk(tp - sbrk(0)); + if (res != 0) { + throw new Error("Malformed buffer data: " + res); + } + } + + var filters = { + NONE: "", + OCTAHEDRAL: "meshopt_decodeFilterOct", + QUATERNION: "meshopt_decodeFilterQuat", + EXPONENTIAL: "meshopt_decodeFilterExp", + }; + + var decoders = { + ATTRIBUTES: "meshopt_decodeVertexBuffer", + TRIANGLES: "meshopt_decodeIndexBuffer", + INDICES: "meshopt_decodeIndexSequence", + }; + + var workers = []; + var requestId = 0; + + function createWorker(url) { + var worker = { + object: new Worker(url), + pending: 0, + requests: {} + }; + + worker.object.onmessage = function(event) { + var data = event.data; + + worker.pending -= data.count; + worker.requests[data.id][data.action](data.value); + + delete worker.requests[data.id]; + }; + + return worker; + } + + function initWorkers(count) { + var source = + "var instance; var ready = WebAssembly.instantiate(new Uint8Array([" + new Uint8Array(unpack(wasm)) + "]), {})" + + ".then(function(result) { instance = result.instance; instance.exports.__wasm_call_ctors(); });" + + "self.onmessage = workerProcess;" + + decode.toString() + workerProcess.toString(); + + var blob = new Blob([source], {type: 'text/javascript'}); + var url = URL.createObjectURL(blob); + + for (var i = 0; i < count; ++i) { + workers[i] = createWorker(url); + } + + URL.revokeObjectURL(url); + } + + function decodeWorker(count, size, source, mode, filter) { + var worker = workers[0]; + + for (var i = 1; i < workers.length; ++i) { + if (workers[i].pending < worker.pending) { + worker = workers[i]; + } + } + + return new Promise(function (resolve, reject) { + var data = new Uint8Array(source); + var id = requestId++; + + worker.pending += count; + worker.requests[id] = { resolve: resolve, reject: reject }; + worker.object.postMessage({ id: id, count: count, size: size, source: data, mode: mode, filter: filter }, [ data.buffer ]); + }); + } + + function workerProcess(event) { + ready.then(function() { + var data = event.data; + try { + var target = new Uint8Array(data.count * data.size); + decode(instance.exports[data.mode], target, data.count, data.size, data.source, instance.exports[data.filter]); + self.postMessage({ id: data.id, count: data.count, action: "resolve", value: target }, [ target.buffer ]); + } catch (error) { + self.postMessage({ id: data.id, count: data.count, action: "reject", value: error }); + } + }); + } + + return { + ready: ready, + supported: true, + useWorkers: function(count) { + initWorkers(count); + }, + decodeVertexBuffer: function(target, count, size, source, filter) { + decode(instance.exports.meshopt_decodeVertexBuffer, target, count, size, source, instance.exports[filters[filter]]); + }, + decodeIndexBuffer: function(target, count, size, source) { + decode(instance.exports.meshopt_decodeIndexBuffer, target, count, size, source); + }, + decodeIndexSequence: function(target, count, size, source) { + decode(instance.exports.meshopt_decodeIndexSequence, target, count, size, source); + }, + decodeGltfBuffer: function(target, count, size, source, mode, filter) { + decode(instance.exports[decoders[mode]], target, count, size, source, instance.exports[filters[filter]]); + }, + decodeGltfBufferAsync: function(count, size, source, mode, filter) { + if (workers.length > 0) { + return decodeWorker(count, size, source, decoders[mode], filters[filter]); + } + + return ready.then(function() { + var target = new Uint8Array(count * size); + decode(instance.exports[decoders[mode]], target, count, size, source, instance.exports[filters[filter]]); + return target; + }); + } + }; +})(); + +export { MeshoptDecoder }; diff --git a/libs/three.js/r171/examples/jsm/libs/zstddec.module.js b/libs/three.js/r171/examples/jsm/libs/zstddec.module.js new file mode 100644 index 000000000..ed19f9116 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/libs/zstddec.module.js @@ -0,0 +1 @@ +let A,I,B;const g={env:{emscripten_notify_memory_growth:function(A){B=new Uint8Array(I.exports.memory.buffer)}}};class Q{init(){return A||(A="undefined"!=typeof fetch?fetch("data:application/wasm;base64,"+C).then(A=>A.arrayBuffer()).then(A=>WebAssembly.instantiate(A,g)).then(this._init):WebAssembly.instantiate(Buffer.from(C,"base64"),g).then(this._init),A)}_init(A){I=A.instance,g.env.emscripten_notify_memory_growth(0)}decode(A,g=0){if(!I)throw new Error("ZSTDDecoder: Await .init() before decoding.");const Q=A.byteLength,C=I.exports.malloc(Q);B.set(A,C),g=g||Number(I.exports.ZSTD_findDecompressedSize(C,Q));const E=I.exports.malloc(g),i=I.exports.ZSTD_decompress(E,g,C,Q),D=B.slice(E,E+i);return I.exports.free(C),I.exports.free(E),D}}const C="AGFzbQEAAAABpQEVYAF/AX9gAn9/AGADf39/AX9gBX9/f39/AX9gAX8AYAJ/fwF/YAR/f39/AX9gA39/fwBgBn9/f39/fwF/YAd/f39/f39/AX9gAn9/AX5gAn5+AX5gAABgBX9/f39/AGAGf39/f39/AGAIf39/f39/f38AYAl/f39/f39/f38AYAABf2AIf39/f39/f38Bf2ANf39/f39/f39/f39/fwF/YAF/AX4CJwEDZW52H2Vtc2NyaXB0ZW5fbm90aWZ5X21lbW9yeV9ncm93dGgABANpaAEFAAAFAgEFCwACAQABAgIFBQcAAwABDgsBAQcAEhMHAAUBDAQEAAANBwQCAgYCBAgDAwMDBgEACQkHBgICAAYGAgQUBwYGAwIGAAMCAQgBBwUGCgoEEQAEBAEIAwgDBQgDEA8IAAcABAUBcAECAgUEAQCAAgYJAX8BQaCgwAILB2AHBm1lbW9yeQIABm1hbGxvYwAoBGZyZWUAJgxaU1REX2lzRXJyb3IAaBlaU1REX2ZpbmREZWNvbXByZXNzZWRTaXplAFQPWlNURF9kZWNvbXByZXNzAEoGX3N0YXJ0ACQJBwEAQQELASQKussBaA8AIAAgACgCBCABajYCBAsZACAAKAIAIAAoAgRBH3F0QQAgAWtBH3F2CwgAIABBiH9LC34BBH9BAyEBIAAoAgQiA0EgTQRAIAAoAggiASAAKAIQTwRAIAAQDQ8LIAAoAgwiAiABRgRAQQFBAiADQSBJGw8LIAAgASABIAJrIANBA3YiBCABIARrIAJJIgEbIgJrIgQ2AgggACADIAJBA3RrNgIEIAAgB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AoAgw2AgALIAAoAggiAQRAIAEgACgCDDYCBAsgACgCDCIBBEAgASAAKAIINgIACyACECchAkEAIQFBhCAoAgAhACACDQEgACAAKAIAQX5xNgIAQQAPCyACQQ9qQXhxIgMQHSICQX9GDQIgAkEHakF4cSIAIAJHBEAgACACaxAdQX9GDQMLAkBBhCAoAgAiAUUEQEGAICAANgIADAELIAAgATYCBAtBhCAgADYCACAAIANBAXRBAXI2AgAMAQsgAEUNAQsgAEEIaiEBCyABC7kDAQJ/IAAgA2ohBQJAIANBB0wEQANAIAAgBU8NAiAAIAItAAA6AAAgAEEBaiEAIAJBAWohAgwAAAsACyAEQQFGBEACQCAAIAJrIgZBB00EQCAAIAItAAA6AAAgACACLQABOgABIAAgAi0AAjoAAiAAIAItAAM6AAMgAEEEaiACIAZBAnQiBkHAHmooAgBqIgIQFyACIAZB4B5qKAIAayECDAELIAAgAhAMCyACQQhqIQIgAEEIaiEACwJAAkACQAJAIAUgAU0EQCAAIANqIQEgBEEBRyAAIAJrQQ9Kcg0BA0AgACACEAwgAkEIaiECIABBCGoiACABSQ0ACwwFCyAAIAFLBEAgACEBDAQLIARBAUcgACACa0EPSnINASAAIQMgAiEEA0AgAyAEEAwgBEEIaiEEIANBCGoiAyABSQ0ACwwCCwNAIAAgAhAHIAJBEGohAiAAQRBqIgAgAUkNAAsMAwsgACEDIAIhBANAIAMgBBAHIARBEGohBCADQRBqIgMgAUkNAAsLIAIgASAAa2ohAgsDQCABIAVPDQEgASACLQAAOgAAIAFBAWohASACQQFqIQIMAAALAAsLQQECfyAAIAAoArjgASIDNgLE4AEgACgCvOABIQQgACABNgK84AEgACABIAJqNgK44AEgACABIAQgA2tqNgLA4AELpgEBAX8gACAAKALs4QEQFjYCyOABIABCADcD+OABIABCADcDuOABIABBwOABakIANwMAIABBqNAAaiIBQYyAgOAANgIAIABBADYCmOIBIABCADcDiOEBIABCAzcDgOEBIABBrNABakHgEikCADcCACAAQbTQAWpB6BIoAgA2AgAgACABNgIMIAAg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GogBEEYahASOgAAIAMgBEEIaiAEQRhqEBI6AAEgBEEYahAERQ0BIANBAmohAwsgBUF+aiEFAn8DQEG6fyECIAMiASAFSw0FIAEgBEEQaiAEQRhqEBI6AAAgAUEBaiEDIARBGGoQBEEDRgRAQQIhAiAEQQhqDAILIAMgBUsNBSABIARBCGogBEEYahASOgABIAFBAmohA0EDIQIgBEEYahAEQQNHDQALIARBEGoLIQUgAyAFIARBGGoQEjoAACABIAJqIABrIQIMAwsgAyAEQRBqIARBGGoQEjoAAiADIARBCGogBEEYahASOgADIANBBGohAwwAAAsACyAEQRhqIAEgAhAGIgIQAw0AIARBEGogBEEYaiADEBwgBEEIaiAEQRhqIAMQHCAAIQMDQAJAIARBGGoQBCADIAZPckUEQCADIARBEGogBEEYahAROgAAIAMgBEEIaiAEQRhqEBE6AAEgBEEYahAERQ0BIANBAmohAwsgBUF+aiEFAn8DQEG6fyECIAMiASAFSw0EIAEgBEEQaiAEQRhqEBE6AAAgAUEBaiEDIARBGGoQBEEDRgRAQQIhAiAEQQhqDAILIAMgBUsNBCABIARBCGogBEEYahAROgABIAFBAmohA0EDIQIgBEEYahAEQQNHDQALIARBEGoLIQUgAyAFIARBGGoQEToAACABIAJqIABrIQIMAgsgAyAEQRBqIARBGGoQEToAAiADIARBCGogBEEYahAROgADIANBBGohAwwAAAsACyAEQTBqJAAgAgtpAQF/An8CQAJAIAJBB00NACABKAAAQbfIwuF+Rw0AIAAgASgABDYCmOIBQWIgAEEQaiABIAIQPiIDEAMNAhogAEKBgICAEDcDiOEBIAAgASADaiACIANrECoMAQsgACABIAIQKgtBAAsLrQMBBn8jAEGAAWsiAyQAQWIhCAJAIAJBCUkNACAAQZjQAGogAUEIaiIEIAJBeGogAEGY0AAQMyIFEAMiBg0AIANBHzYCfCADIANB/ABqIANB+ABqIAQgBCAFaiAGGyIEIAEgAmoiAiAEaxAVIgUQAw0AIAMoAnwiBkEfSw0AIAMoAngiB0EJTw0AIABBiCBqIAMgBkGAC0GADCAH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PwIBfwF+IwBBMGsiAiQAAn5CfiACQQhqIAAgARAtDQAaQgAgAigCHEEBRg0AGiACKQMICyEDIAJBMGokACADC40BAQJ/IwBBMGsiASQAAkAgAEUNACAAKAKI4gENACABIABB/OEBaigCADYCKCABIAApAvThATcDICAAEDAgACgCqOIBIQIgASABKAIoNgIYIAEgASkDIDcDECACIAFBEGoQGyAAQQA2AqjiASABIAEoAig2AgggASABKQMgNwMAIAAgARAbCyABQTBqJAALKgECfyMAQRBrIgAkACAAQQA2AgggAEIANwMAIAAQWCEBIABBEGokACABC4cBAQN/IwBBEGsiAiQAAkAgACgCAEUgACgCBEVzDQAgAiAAKAIINgIIIAIgACkCADcDAAJ/IAIoAgAiAQRAIAIoAghBqOMJIAERBQAMAQtBqOMJECgLIgFFDQAgASAAKQIANwL04QEgAUH84QFqIAAoAgg2AgAgARBZIAEhAwsgAkEQaiQAIAMLywEBAn8jAEEgayIBJAAgAEGBgIDAADYCtOIBIABBADYCiOIBIABBADYC7OEBIABCADcDkOIBIABBADYCpOMJIABBADYC3OIBIABCADcCzOIBIABBADYCvOIBIABBADYCxOABIABCADcCnOIBIABBpOIBakIANwIAIABBrOIBakEANgIAIAFCADcCECABQgA3AhggASABKQMYNwMIIAEgASkDEDcDACABKAIIQQh2QQFxIQIgAEEANgLg4gEgACACNgKM4gEgAUEgaiQAC3YBA38jAEEwayIBJAAgAARAIAEgAEHE0AFqIgIoAgA2AiggASAAKQK80AE3AyAgACgCACEDIAEgAigCADYCGCABIAApArzQATcDECADIAFBEGoQGyABIAEoAig2AgggASABKQMgNwMAIAAgARAbCyABQTBqJAALzAEBAX8gACABKAK00AE2ApjiASAAIAEoAgQiAjYCwOABIAAgAjYCvOABIAAgAiABKAIIaiICNgK44AEgACACNgLE4AEgASgCuNABBEAgAEKBgICAEDcDiOEBIAAgAUGk0ABqNgIMIAAgAUGUIGo2AgggACABQZwwajYCBCAAIAFBDGo2AgAgAEGs0AFqIAFBqNABaigCADYCACAAQbDQAWogAUG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IAAAAAAMBgMQAAAAAAsGAwgAAAAACgYDBABBpB0L2QEBAAAAAwAAAAcAAAAPAAAAHwAAAD8AAAB/AAAA/wAAAP8BAAD/AwAA/wcAAP8PAAD/HwAA/z8AAP9/AAD//wAA//8BAP//AwD//wcA//8PAP//HwD//z8A//9/AP///wD///8B////A////wf///8P////H////z////9/AAAAAAEAAAACAAAABAAAAAAAAAACAAAABAAAAAgAAAAAAAAAAQAAAAIAAAABAAAABAAAAAQAAAAEAAAABAAAAAgAAAAIAAAACAAAAAcAAAAIAAAACQAAAAoAAAALAEGgIAsDwBBQ";export{Q as ZSTDDecoder}; diff --git a/libs/three.js/r171/examples/jsm/loaders/BasisTextureLoader.js b/libs/three.js/r171/examples/jsm/loaders/BasisTextureLoader.js new file mode 100644 index 000000000..b9ca9b70c --- /dev/null +++ b/libs/three.js/r171/examples/jsm/loaders/BasisTextureLoader.js @@ -0,0 +1,790 @@ +import { + CompressedTexture, + FileLoader, + LinearFilter, + LinearMipmapLinearFilter, + Loader, + RGBAFormat, + RGBA_ASTC_4x4_Format, + RGBA_BPTC_Format, + RGBA_ETC2_EAC_Format, + RGBA_PVRTC_4BPPV1_Format, + RGBA_S3TC_DXT5_Format, + RGB_ETC1_Format, + RGB_ETC2_Format, + RGB_PVRTC_4BPPV1_Format, + RGB_S3TC_DXT1_Format, + UnsignedByteType +} from 'three'; + +/** + * Loader for Basis Universal GPU Texture Codec. + * + * Basis Universal is a "supercompressed" GPU texture and texture video + * compression system that outputs a highly compressed intermediate file format + * (.basis) that can be quickly transcoded to a wide variety of GPU texture + * compression formats. + * + * This loader parallelizes the transcoding process across a configurable number + * of web workers, before transferring the transcoded compressed texture back + * to the main thread. + */ + +const _taskCache = new WeakMap(); + +class BasisTextureLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.transcoderPath = ''; + this.transcoderBinary = null; + this.transcoderPending = null; + + this.workerLimit = 4; + this.workerPool = []; + this.workerNextTaskID = 1; + this.workerSourceURL = ''; + this.workerConfig = null; + + console.warn( + + 'THREE.BasisTextureLoader: This loader is deprecated, and will be removed in a future release. ' + + 'Instead, use Basis Universal compression in KTX2 (.ktx2) files with THREE.KTX2Loader.' + + ); + + } + + setTranscoderPath( path ) { + + this.transcoderPath = path; + + return this; + + } + + setWorkerLimit( workerLimit ) { + + this.workerLimit = workerLimit; + + return this; + + } + + detectSupport( renderer ) { + + this.workerConfig = { + astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ), + etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ), + etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ), + dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ), + bptcSupported: renderer.extensions.has( 'EXT_texture_compression_bptc' ), + pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' ) + || renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' ) + }; + + return this; + + } + + load( url, onLoad, onProgress, onError ) { + + const loader = new FileLoader( this.manager ); + + loader.setResponseType( 'arraybuffer' ); + loader.setWithCredentials( this.withCredentials ); + + const texture = new CompressedTexture(); + + loader.load( url, ( buffer ) => { + + // Check for an existing task using this buffer. A transferred buffer cannot be transferred + // again from this thread. + if ( _taskCache.has( buffer ) ) { + + const cachedTask = _taskCache.get( buffer ); + + return cachedTask.promise.then( onLoad ).catch( onError ); + + } + + this._createTexture( [ buffer ] ) + .then( function ( _texture ) { + + texture.copy( _texture ); + texture.needsUpdate = true; + + if ( onLoad ) onLoad( texture ); + + } ) + .catch( onError ); + + }, onProgress, onError ); + + return texture; + + } + + /** Low-level transcoding API, exposed for use by KTX2Loader. */ + parseInternalAsync( options ) { + + const { levels } = options; + + const buffers = new Set(); + + for ( let i = 0; i < levels.length; i ++ ) { + + buffers.add( levels[ i ].data.buffer ); + + } + + return this._createTexture( Array.from( buffers ), { ...options, lowLevel: true } ); + + } + + /** + * @param {ArrayBuffer[]} buffers + * @param {object?} config + * @return {Promise} + */ + _createTexture( buffers, config = {} ) { + + let worker; + let taskID; + + const taskConfig = config; + let taskCost = 0; + + for ( let i = 0; i < buffers.length; i ++ ) { + + taskCost += buffers[ i ].byteLength; + + } + + const texturePending = this._allocateWorker( taskCost ) + .then( ( _worker ) => { + + worker = _worker; + taskID = this.workerNextTaskID ++; + + return new Promise( ( resolve, reject ) => { + + worker._callbacks[ taskID ] = { resolve, reject }; + + worker.postMessage( { type: 'transcode', id: taskID, buffers: buffers, taskConfig: taskConfig }, buffers ); + + } ); + + } ) + .then( ( message ) => { + + const { mipmaps, width, height, format } = message; + + const texture = new CompressedTexture( mipmaps, width, height, format, UnsignedByteType ); + texture.minFilter = mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter; + texture.magFilter = LinearFilter; + texture.generateMipmaps = false; + texture.needsUpdate = true; + + return texture; + + } ); + + // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416) + texturePending + .catch( () => true ) + .then( () => { + + if ( worker && taskID ) { + + worker._taskLoad -= taskCost; + delete worker._callbacks[ taskID ]; + + } + + } ); + + // Cache the task result. + _taskCache.set( buffers[ 0 ], { promise: texturePending } ); + + return texturePending; + + } + + _initTranscoder() { + + if ( ! this.transcoderPending ) { + + // Load transcoder wrapper. + const jsLoader = new FileLoader( this.manager ); + jsLoader.setPath( this.transcoderPath ); + jsLoader.setWithCredentials( this.withCredentials ); + const jsContent = new Promise( ( resolve, reject ) => { + + jsLoader.load( 'basis_transcoder.js', resolve, undefined, reject ); + + } ); + + // Load transcoder WASM binary. + const binaryLoader = new FileLoader( this.manager ); + binaryLoader.setPath( this.transcoderPath ); + binaryLoader.setResponseType( 'arraybuffer' ); + binaryLoader.setWithCredentials( this.withCredentials ); + const binaryContent = new Promise( ( resolve, reject ) => { + + binaryLoader.load( 'basis_transcoder.wasm', resolve, undefined, reject ); + + } ); + + this.transcoderPending = Promise.all( [ jsContent, binaryContent ] ) + .then( ( [ jsContent, binaryContent ] ) => { + + const fn = BasisTextureLoader.BasisWorker.toString(); + + const body = [ + '/* constants */', + 'let _EngineFormat = ' + JSON.stringify( BasisTextureLoader.EngineFormat ), + 'let _TranscoderFormat = ' + JSON.stringify( BasisTextureLoader.TranscoderFormat ), + 'let _BasisFormat = ' + JSON.stringify( BasisTextureLoader.BasisFormat ), + '/* basis_transcoder.js */', + jsContent, + '/* worker */', + fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) + ].join( '\n' ); + + this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) ); + this.transcoderBinary = binaryContent; + + } ); + + } + + return this.transcoderPending; + + } + + _allocateWorker( taskCost ) { + + return this._initTranscoder().then( () => { + + if ( this.workerPool.length < this.workerLimit ) { + + const worker = new Worker( this.workerSourceURL ); + + worker._callbacks = {}; + worker._taskLoad = 0; + + worker.postMessage( { + type: 'init', + config: this.workerConfig, + transcoderBinary: this.transcoderBinary, + } ); + + worker.onmessage = function ( e ) { + + const message = e.data; + + switch ( message.type ) { + + case 'transcode': + worker._callbacks[ message.id ].resolve( message ); + break; + + case 'error': + worker._callbacks[ message.id ].reject( message ); + break; + + default: + console.error( 'THREE.BasisTextureLoader: Unexpected message, "' + message.type + '"' ); + + } + + }; + + this.workerPool.push( worker ); + + } else { + + this.workerPool.sort( function ( a, b ) { + + return a._taskLoad > b._taskLoad ? - 1 : 1; + + } ); + + } + + const worker = this.workerPool[ this.workerPool.length - 1 ]; + + worker._taskLoad += taskCost; + + return worker; + + } ); + + } + + dispose() { + + for ( let i = 0; i < this.workerPool.length; i ++ ) { + + this.workerPool[ i ].terminate(); + + } + + this.workerPool.length = 0; + + return this; + + } + +} + +/* CONSTANTS */ + +BasisTextureLoader.BasisFormat = { + ETC1S: 0, + UASTC_4x4: 1, +}; + +BasisTextureLoader.TranscoderFormat = { + ETC1: 0, + ETC2: 1, + BC1: 2, + BC3: 3, + BC4: 4, + BC5: 5, + BC7_M6_OPAQUE_ONLY: 6, + BC7_M5: 7, + PVRTC1_4_RGB: 8, + PVRTC1_4_RGBA: 9, + ASTC_4x4: 10, + ATC_RGB: 11, + ATC_RGBA_INTERPOLATED_ALPHA: 12, + RGBA32: 13, + RGB565: 14, + BGR565: 15, + RGBA4444: 16, +}; + +BasisTextureLoader.EngineFormat = { + RGBAFormat: RGBAFormat, + RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format, + RGBA_BPTC_Format: RGBA_BPTC_Format, + RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format, + RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format, + RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format, + RGB_ETC1_Format: RGB_ETC1_Format, + RGB_ETC2_Format: RGB_ETC2_Format, + RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format, + RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format, +}; + + +/* WEB WORKER */ + +BasisTextureLoader.BasisWorker = function () { + + let config; + let transcoderPending; + let BasisModule; + + const EngineFormat = _EngineFormat; // eslint-disable-line no-undef + const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef + const BasisFormat = _BasisFormat; // eslint-disable-line no-undef + + onmessage = function ( e ) { + + const message = e.data; + + switch ( message.type ) { + + case 'init': + config = message.config; + init( message.transcoderBinary ); + break; + + case 'transcode': + transcoderPending.then( () => { + + try { + + const { width, height, hasAlpha, mipmaps, format } = message.taskConfig.lowLevel + ? transcodeLowLevel( message.taskConfig ) + : transcode( message.buffers[ 0 ] ); + + const buffers = []; + + for ( let i = 0; i < mipmaps.length; ++ i ) { + + buffers.push( mipmaps[ i ].data.buffer ); + + } + + self.postMessage( { type: 'transcode', id: message.id, width, height, hasAlpha, mipmaps, format }, buffers ); + + } catch ( error ) { + + console.error( error ); + + self.postMessage( { type: 'error', id: message.id, error: error.message } ); + + } + + } ); + break; + + } + + }; + + function init( wasmBinary ) { + + transcoderPending = new Promise( ( resolve ) => { + + BasisModule = { wasmBinary, onRuntimeInitialized: resolve }; + BASIS( BasisModule ); // eslint-disable-line no-undef + + } ).then( () => { + + BasisModule.initializeBasis(); + + } ); + + } + + function transcodeLowLevel( taskConfig ) { + + const { basisFormat, width, height, hasAlpha } = taskConfig; + + const { transcoderFormat, engineFormat } = getTranscoderFormat( basisFormat, width, height, hasAlpha ); + + const blockByteLength = BasisModule.getBytesPerBlockOrPixel( transcoderFormat ); + + assert( BasisModule.isFormatSupported( transcoderFormat ), 'THREE.BasisTextureLoader: Unsupported format.' ); + + const mipmaps = []; + + if ( basisFormat === BasisFormat.ETC1S ) { + + const transcoder = new BasisModule.LowLevelETC1SImageTranscoder(); + + const { endpointCount, endpointsData, selectorCount, selectorsData, tablesData } = taskConfig.globalData; + + try { + + let ok; + + ok = transcoder.decodePalettes( endpointCount, endpointsData, selectorCount, selectorsData ); + + assert( ok, 'THREE.BasisTextureLoader: decodePalettes() failed.' ); + + ok = transcoder.decodeTables( tablesData ); + + assert( ok, 'THREE.BasisTextureLoader: decodeTables() failed.' ); + + for ( let i = 0; i < taskConfig.levels.length; i ++ ) { + + const level = taskConfig.levels[ i ]; + const imageDesc = taskConfig.globalData.imageDescs[ i ]; + + const dstByteLength = getTranscodedImageByteLength( transcoderFormat, level.width, level.height ); + const dst = new Uint8Array( dstByteLength ); + + ok = transcoder.transcodeImage( + transcoderFormat, + dst, dstByteLength / blockByteLength, + level.data, + getWidthInBlocks( transcoderFormat, level.width ), + getHeightInBlocks( transcoderFormat, level.height ), + level.width, level.height, level.index, + imageDesc.rgbSliceByteOffset, imageDesc.rgbSliceByteLength, + imageDesc.alphaSliceByteOffset, imageDesc.alphaSliceByteLength, + imageDesc.imageFlags, + hasAlpha, + false, + 0, 0 + ); + + assert( ok, 'THREE.BasisTextureLoader: transcodeImage() failed for level ' + level.index + '.' ); + + mipmaps.push( { data: dst, width: level.width, height: level.height } ); + + } + + } finally { + + transcoder.delete(); + + } + + } else { + + for ( let i = 0; i < taskConfig.levels.length; i ++ ) { + + const level = taskConfig.levels[ i ]; + + const dstByteLength = getTranscodedImageByteLength( transcoderFormat, level.width, level.height ); + const dst = new Uint8Array( dstByteLength ); + + const ok = BasisModule.transcodeUASTCImage( + transcoderFormat, + dst, dstByteLength / blockByteLength, + level.data, + getWidthInBlocks( transcoderFormat, level.width ), + getHeightInBlocks( transcoderFormat, level.height ), + level.width, level.height, level.index, + 0, + level.data.byteLength, + 0, + hasAlpha, + false, + 0, 0, + - 1, - 1 + ); + + assert( ok, 'THREE.BasisTextureLoader: transcodeUASTCImage() failed for level ' + level.index + '.' ); + + mipmaps.push( { data: dst, width: level.width, height: level.height } ); + + } + + } + + return { width, height, hasAlpha, mipmaps, format: engineFormat }; + + } + + function transcode( buffer ) { + + const basisFile = new BasisModule.BasisFile( new Uint8Array( buffer ) ); + + const basisFormat = basisFile.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S; + const width = basisFile.getImageWidth( 0, 0 ); + const height = basisFile.getImageHeight( 0, 0 ); + const levels = basisFile.getNumLevels( 0 ); + const hasAlpha = basisFile.getHasAlpha(); + + function cleanup() { + + basisFile.close(); + basisFile.delete(); + + } + + const { transcoderFormat, engineFormat } = getTranscoderFormat( basisFormat, width, height, hasAlpha ); + + if ( ! width || ! height || ! levels ) { + + cleanup(); + throw new Error( 'THREE.BasisTextureLoader: Invalid texture' ); + + } + + if ( ! basisFile.startTranscoding() ) { + + cleanup(); + throw new Error( 'THREE.BasisTextureLoader: .startTranscoding failed' ); + + } + + const mipmaps = []; + + for ( let mip = 0; mip < levels; mip ++ ) { + + const mipWidth = basisFile.getImageWidth( 0, mip ); + const mipHeight = basisFile.getImageHeight( 0, mip ); + const dst = new Uint8Array( basisFile.getImageTranscodedSizeInBytes( 0, mip, transcoderFormat ) ); + + const status = basisFile.transcodeImage( + dst, + 0, + mip, + transcoderFormat, + 0, + hasAlpha + ); + + if ( ! status ) { + + cleanup(); + throw new Error( 'THREE.BasisTextureLoader: .transcodeImage failed.' ); + + } + + mipmaps.push( { data: dst, width: mipWidth, height: mipHeight } ); + + } + + cleanup(); + + return { width, height, hasAlpha, mipmaps, format: engineFormat }; + + } + + // + + // Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC), + // device capabilities, and texture dimensions. The list below ranks the formats separately + // for ETC1S and UASTC. + // + // In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at + // significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently + // chooses RGBA32 only as a last resort and does not expose that option to the caller. + const FORMAT_OPTIONS = [ + { + if: 'astcSupported', + basisFormat: [ BasisFormat.UASTC_4x4 ], + transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ], + engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ], + priorityETC1S: Infinity, + priorityUASTC: 1, + needsPowerOfTwo: false, + }, + { + if: 'bptcSupported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ], + transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ], + engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ], + priorityETC1S: 3, + priorityUASTC: 2, + needsPowerOfTwo: false, + }, + { + if: 'dxtSupported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ], + transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ], + engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ], + priorityETC1S: 4, + priorityUASTC: 5, + needsPowerOfTwo: false, + }, + { + if: 'etc2Supported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ], + transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ], + engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ], + priorityETC1S: 1, + priorityUASTC: 3, + needsPowerOfTwo: false, + }, + { + if: 'etc1Supported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ], + transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC1 ], + engineFormat: [ EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format ], + priorityETC1S: 2, + priorityUASTC: 4, + needsPowerOfTwo: false, + }, + { + if: 'pvrtcSupported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ], + transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ], + engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ], + priorityETC1S: 5, + priorityUASTC: 6, + needsPowerOfTwo: true, + }, + ]; + + const ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { + + return a.priorityETC1S - b.priorityETC1S; + + } ); + const UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { + + return a.priorityUASTC - b.priorityUASTC; + + } ); + + function getTranscoderFormat( basisFormat, width, height, hasAlpha ) { + + let transcoderFormat; + let engineFormat; + + const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS; + + for ( let i = 0; i < options.length; i ++ ) { + + const opt = options[ i ]; + + if ( ! config[ opt.if ] ) continue; + if ( ! opt.basisFormat.includes( basisFormat ) ) continue; + if ( opt.needsPowerOfTwo && ! ( isPowerOfTwo( width ) && isPowerOfTwo( height ) ) ) continue; + + transcoderFormat = opt.transcoderFormat[ hasAlpha ? 1 : 0 ]; + engineFormat = opt.engineFormat[ hasAlpha ? 1 : 0 ]; + + return { transcoderFormat, engineFormat }; + + } + + console.warn( 'THREE.BasisTextureLoader: No suitable compressed texture format found. Decoding to RGBA32.' ); + + transcoderFormat = TranscoderFormat.RGBA32; + engineFormat = EngineFormat.RGBAFormat; + + return { transcoderFormat, engineFormat }; + + } + + function assert( ok, message ) { + + if ( ! ok ) throw new Error( message ); + + } + + function getWidthInBlocks( transcoderFormat, width ) { + + return Math.ceil( width / BasisModule.getFormatBlockWidth( transcoderFormat ) ); + + } + + function getHeightInBlocks( transcoderFormat, height ) { + + return Math.ceil( height / BasisModule.getFormatBlockHeight( transcoderFormat ) ); + + } + + function getTranscodedImageByteLength( transcoderFormat, width, height ) { + + const blockByteLength = BasisModule.getBytesPerBlockOrPixel( transcoderFormat ); + + if ( BasisModule.formatIsUncompressed( transcoderFormat ) ) { + + return width * height * blockByteLength; + + } + + if ( transcoderFormat === TranscoderFormat.PVRTC1_4_RGB + || transcoderFormat === TranscoderFormat.PVRTC1_4_RGBA ) { + + // GL requires extra padding for very small textures: + // https://www.khronos.org/registry/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt + const paddedWidth = ( width + 3 ) & ~ 3; + const paddedHeight = ( height + 3 ) & ~ 3; + + return ( Math.max( 8, paddedWidth ) * Math.max( 8, paddedHeight ) * 4 + 7 ) / 8; + + } + + return ( getWidthInBlocks( transcoderFormat, width ) + * getHeightInBlocks( transcoderFormat, height ) + * blockByteLength ); + + } + + function isPowerOfTwo( value ) { + + if ( value <= 2 ) return true; + + return ( value & ( value - 1 ) ) === 0 && value !== 0; + + } + +}; + +export { BasisTextureLoader }; diff --git a/libs/three.js/r171/examples/jsm/loaders/DRACOLoader.js b/libs/three.js/r171/examples/jsm/loaders/DRACOLoader.js new file mode 100644 index 000000000..ca111d712 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/loaders/DRACOLoader.js @@ -0,0 +1,615 @@ +import { + BufferAttribute, + BufferGeometry, + Color, + ColorManagement, + FileLoader, + Loader, + LinearSRGBColorSpace, + SRGBColorSpace +} from 'three'; + +const _taskCache = new WeakMap(); + +class DRACOLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.decoderPath = ''; + this.decoderConfig = {}; + this.decoderBinary = null; + this.decoderPending = null; + + this.workerLimit = 4; + this.workerPool = []; + this.workerNextTaskID = 1; + this.workerSourceURL = ''; + + this.defaultAttributeIDs = { + position: 'POSITION', + normal: 'NORMAL', + color: 'COLOR', + uv: 'TEX_COORD' + }; + this.defaultAttributeTypes = { + position: 'Float32Array', + normal: 'Float32Array', + color: 'Float32Array', + uv: 'Float32Array' + }; + + } + + setDecoderPath( path ) { + + this.decoderPath = path; + + return this; + + } + + setDecoderConfig( config ) { + + this.decoderConfig = config; + + return this; + + } + + setWorkerLimit( workerLimit ) { + + this.workerLimit = workerLimit; + + return this; + + } + + load( url, onLoad, onProgress, onError ) { + + const loader = new FileLoader( this.manager ); + + loader.setPath( this.path ); + loader.setResponseType( 'arraybuffer' ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + + loader.load( url, ( buffer ) => { + + this.parse( buffer, onLoad, onError ); + + }, onProgress, onError ); + + } + + + parse( buffer, onLoad, onError = ()=>{} ) { + + this.decodeDracoFile( buffer, onLoad, null, null, SRGBColorSpace, onError ).catch( onError ); + + } + + decodeDracoFile( buffer, callback, attributeIDs, attributeTypes, vertexColorSpace = LinearSRGBColorSpace, onError = () => {} ) { + + const taskConfig = { + attributeIDs: attributeIDs || this.defaultAttributeIDs, + attributeTypes: attributeTypes || this.defaultAttributeTypes, + useUniqueIDs: !! attributeIDs, + vertexColorSpace: vertexColorSpace, + }; + + return this.decodeGeometry( buffer, taskConfig ).then( callback ).catch( onError ); + + } + + decodeGeometry( buffer, taskConfig ) { + + const taskKey = JSON.stringify( taskConfig ); + + // Check for an existing task using this buffer. A transferred buffer cannot be transferred + // again from this thread. + if ( _taskCache.has( buffer ) ) { + + const cachedTask = _taskCache.get( buffer ); + + if ( cachedTask.key === taskKey ) { + + return cachedTask.promise; + + } else if ( buffer.byteLength === 0 ) { + + // Technically, it would be possible to wait for the previous task to complete, + // transfer the buffer back, and decode again with the second configuration. That + // is complex, and I don't know of any reason to decode a Draco buffer twice in + // different ways, so this is left unimplemented. + throw new Error( + + 'THREE.DRACOLoader: Unable to re-decode a buffer with different ' + + 'settings. Buffer has already been transferred.' + + ); + + } + + } + + // + + let worker; + const taskID = this.workerNextTaskID ++; + const taskCost = buffer.byteLength; + + // Obtain a worker and assign a task, and construct a geometry instance + // when the task completes. + const geometryPending = this._getWorker( taskID, taskCost ) + .then( ( _worker ) => { + + worker = _worker; + + return new Promise( ( resolve, reject ) => { + + worker._callbacks[ taskID ] = { resolve, reject }; + + worker.postMessage( { type: 'decode', id: taskID, taskConfig, buffer }, [ buffer ] ); + + // this.debug(); + + } ); + + } ) + .then( ( message ) => this._createGeometry( message.geometry ) ); + + // Remove task from the task list. + // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416) + geometryPending + .catch( () => true ) + .then( () => { + + if ( worker && taskID ) { + + this._releaseTask( worker, taskID ); + + // this.debug(); + + } + + } ); + + // Cache the task result. + _taskCache.set( buffer, { + + key: taskKey, + promise: geometryPending + + } ); + + return geometryPending; + + } + + _createGeometry( geometryData ) { + + const geometry = new BufferGeometry(); + + if ( geometryData.index ) { + + geometry.setIndex( new BufferAttribute( geometryData.index.array, 1 ) ); + + } + + for ( let i = 0; i < geometryData.attributes.length; i ++ ) { + + const result = geometryData.attributes[ i ]; + const name = result.name; + const array = result.array; + const itemSize = result.itemSize; + + const attribute = new BufferAttribute( array, itemSize ); + + if ( name === 'color' ) { + + this._assignVertexColorSpace( attribute, result.vertexColorSpace ); + + attribute.normalized = ( array instanceof Float32Array ) === false; + + } + + geometry.setAttribute( name, attribute ); + + } + + return geometry; + + } + + _assignVertexColorSpace( attribute, inputColorSpace ) { + + // While .drc files do not specify colorspace, the only 'official' tooling + // is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc + // file is passed into .load() or .parse(). GLTFLoader uses internal APIs + // to decode geometry, and vertex colors are already Linear-sRGB in there. + + if ( inputColorSpace !== SRGBColorSpace ) return; + + const _color = new Color(); + + for ( let i = 0, il = attribute.count; i < il; i ++ ) { + + _color.fromBufferAttribute( attribute, i ); + ColorManagement.toWorkingColorSpace( _color, SRGBColorSpace ); + attribute.setXYZ( i, _color.r, _color.g, _color.b ); + + } + + } + + _loadLibrary( url, responseType ) { + + const loader = new FileLoader( this.manager ); + loader.setPath( this.decoderPath ); + loader.setResponseType( responseType ); + loader.setWithCredentials( this.withCredentials ); + + return new Promise( ( resolve, reject ) => { + + loader.load( url, resolve, undefined, reject ); + + } ); + + } + + preload() { + + this._initDecoder(); + + return this; + + } + + _initDecoder() { + + if ( this.decoderPending ) return this.decoderPending; + + const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js'; + const librariesPending = []; + + if ( useJS ) { + + librariesPending.push( this._loadLibrary( 'draco_decoder.js', 'text' ) ); + + } else { + + librariesPending.push( this._loadLibrary( 'draco_wasm_wrapper.js', 'text' ) ); + librariesPending.push( this._loadLibrary( 'draco_decoder.wasm', 'arraybuffer' ) ); + + } + + this.decoderPending = Promise.all( librariesPending ) + .then( ( libraries ) => { + + const jsContent = libraries[ 0 ]; + + if ( ! useJS ) { + + this.decoderConfig.wasmBinary = libraries[ 1 ]; + + } + + const fn = DRACOWorker.toString(); + + const body = [ + '/* draco decoder */', + jsContent, + '', + '/* worker */', + fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) + ].join( '\n' ); + + this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) ); + + } ); + + return this.decoderPending; + + } + + _getWorker( taskID, taskCost ) { + + return this._initDecoder().then( () => { + + if ( this.workerPool.length < this.workerLimit ) { + + const worker = new Worker( this.workerSourceURL ); + + worker._callbacks = {}; + worker._taskCosts = {}; + worker._taskLoad = 0; + + worker.postMessage( { type: 'init', decoderConfig: this.decoderConfig } ); + + worker.onmessage = function ( e ) { + + const message = e.data; + + switch ( message.type ) { + + case 'decode': + worker._callbacks[ message.id ].resolve( message ); + break; + + case 'error': + worker._callbacks[ message.id ].reject( message ); + break; + + default: + console.error( 'THREE.DRACOLoader: Unexpected message, "' + message.type + '"' ); + + } + + }; + + this.workerPool.push( worker ); + + } else { + + this.workerPool.sort( function ( a, b ) { + + return a._taskLoad > b._taskLoad ? - 1 : 1; + + } ); + + } + + const worker = this.workerPool[ this.workerPool.length - 1 ]; + worker._taskCosts[ taskID ] = taskCost; + worker._taskLoad += taskCost; + return worker; + + } ); + + } + + _releaseTask( worker, taskID ) { + + worker._taskLoad -= worker._taskCosts[ taskID ]; + delete worker._callbacks[ taskID ]; + delete worker._taskCosts[ taskID ]; + + } + + debug() { + + console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) ); + + } + + dispose() { + + for ( let i = 0; i < this.workerPool.length; ++ i ) { + + this.workerPool[ i ].terminate(); + + } + + this.workerPool.length = 0; + + if ( this.workerSourceURL !== '' ) { + + URL.revokeObjectURL( this.workerSourceURL ); + + } + + return this; + + } + +} + +/* WEB WORKER */ + +function DRACOWorker() { + + let decoderConfig; + let decoderPending; + + onmessage = function ( e ) { + + const message = e.data; + + switch ( message.type ) { + + case 'init': + decoderConfig = message.decoderConfig; + decoderPending = new Promise( function ( resolve/*, reject*/ ) { + + decoderConfig.onModuleLoaded = function ( draco ) { + + // Module is Promise-like. Wrap before resolving to avoid loop. + resolve( { draco: draco } ); + + }; + + DracoDecoderModule( decoderConfig ); // eslint-disable-line no-undef + + } ); + break; + + case 'decode': + const buffer = message.buffer; + const taskConfig = message.taskConfig; + decoderPending.then( ( module ) => { + + const draco = module.draco; + const decoder = new draco.Decoder(); + + try { + + const geometry = decodeGeometry( draco, decoder, new Int8Array( buffer ), taskConfig ); + + const buffers = geometry.attributes.map( ( attr ) => attr.array.buffer ); + + if ( geometry.index ) buffers.push( geometry.index.array.buffer ); + + self.postMessage( { type: 'decode', id: message.id, geometry }, buffers ); + + } catch ( error ) { + + console.error( error ); + + self.postMessage( { type: 'error', id: message.id, error: error.message } ); + + } finally { + + draco.destroy( decoder ); + + } + + } ); + break; + + } + + }; + + function decodeGeometry( draco, decoder, array, taskConfig ) { + + const attributeIDs = taskConfig.attributeIDs; + const attributeTypes = taskConfig.attributeTypes; + + let dracoGeometry; + let decodingStatus; + + const geometryType = decoder.GetEncodedGeometryType( array ); + + if ( geometryType === draco.TRIANGULAR_MESH ) { + + dracoGeometry = new draco.Mesh(); + decodingStatus = decoder.DecodeArrayToMesh( array, array.byteLength, dracoGeometry ); + + } else if ( geometryType === draco.POINT_CLOUD ) { + + dracoGeometry = new draco.PointCloud(); + decodingStatus = decoder.DecodeArrayToPointCloud( array, array.byteLength, dracoGeometry ); + + } else { + + throw new Error( 'THREE.DRACOLoader: Unexpected geometry type.' ); + + } + + if ( ! decodingStatus.ok() || dracoGeometry.ptr === 0 ) { + + throw new Error( 'THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg() ); + + } + + const geometry = { index: null, attributes: [] }; + + // Gather all vertex attributes. + for ( const attributeName in attributeIDs ) { + + const attributeType = self[ attributeTypes[ attributeName ] ]; + + let attribute; + let attributeID; + + // A Draco file may be created with default vertex attributes, whose attribute IDs + // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively, + // a Draco file may contain a custom set of attributes, identified by known unique + // IDs. glTF files always do the latter, and `.drc` files typically do the former. + if ( taskConfig.useUniqueIDs ) { + + attributeID = attributeIDs[ attributeName ]; + attribute = decoder.GetAttributeByUniqueId( dracoGeometry, attributeID ); + + } else { + + attributeID = decoder.GetAttributeId( dracoGeometry, draco[ attributeIDs[ attributeName ] ] ); + + if ( attributeID === - 1 ) continue; + + attribute = decoder.GetAttribute( dracoGeometry, attributeID ); + + } + + const attributeResult = decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ); + + if ( attributeName === 'color' ) { + + attributeResult.vertexColorSpace = taskConfig.vertexColorSpace; + + } + + geometry.attributes.push( attributeResult ); + + } + + // Add index. + if ( geometryType === draco.TRIANGULAR_MESH ) { + + geometry.index = decodeIndex( draco, decoder, dracoGeometry ); + + } + + draco.destroy( dracoGeometry ); + + return geometry; + + } + + function decodeIndex( draco, decoder, dracoGeometry ) { + + const numFaces = dracoGeometry.num_faces(); + const numIndices = numFaces * 3; + const byteLength = numIndices * 4; + + const ptr = draco._malloc( byteLength ); + decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr ); + const index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice(); + draco._free( ptr ); + + return { array: index, itemSize: 1 }; + + } + + function decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ) { + + const numComponents = attribute.num_components(); + const numPoints = dracoGeometry.num_points(); + const numValues = numPoints * numComponents; + const byteLength = numValues * attributeType.BYTES_PER_ELEMENT; + const dataType = getDracoDataType( draco, attributeType ); + + const ptr = draco._malloc( byteLength ); + decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr ); + const array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice(); + draco._free( ptr ); + + return { + name: attributeName, + array: array, + itemSize: numComponents + }; + + } + + function getDracoDataType( draco, attributeType ) { + + switch ( attributeType ) { + + case Float32Array: return draco.DT_FLOAT32; + case Int8Array: return draco.DT_INT8; + case Int16Array: return draco.DT_INT16; + case Int32Array: return draco.DT_INT32; + case Uint8Array: return draco.DT_UINT8; + case Uint16Array: return draco.DT_UINT16; + case Uint32Array: return draco.DT_UINT32; + + } + + } + +} + +export { DRACOLoader }; diff --git a/libs/three.js/r171/examples/jsm/loaders/GLTFLoader.js b/libs/three.js/r171/examples/jsm/loaders/GLTFLoader.js new file mode 100644 index 000000000..af826a55d --- /dev/null +++ b/libs/three.js/r171/examples/jsm/loaders/GLTFLoader.js @@ -0,0 +1,4727 @@ +import { + AnimationClip, + Bone, + Box3, + BufferAttribute, + BufferGeometry, + ClampToEdgeWrapping, + Color, + ColorManagement, + DirectionalLight, + DoubleSide, + FileLoader, + FrontSide, + Group, + ImageBitmapLoader, + InstancedMesh, + InterleavedBuffer, + InterleavedBufferAttribute, + Interpolant, + InterpolateDiscrete, + InterpolateLinear, + Line, + LineBasicMaterial, + LineLoop, + LineSegments, + LinearFilter, + LinearMipmapLinearFilter, + LinearMipmapNearestFilter, + LinearSRGBColorSpace, + Loader, + LoaderUtils, + Material, + MathUtils, + Matrix4, + Mesh, + MeshBasicMaterial, + MeshPhysicalMaterial, + MeshStandardMaterial, + MirroredRepeatWrapping, + NearestFilter, + NearestMipmapLinearFilter, + NearestMipmapNearestFilter, + NumberKeyframeTrack, + Object3D, + OrthographicCamera, + PerspectiveCamera, + PointLight, + Points, + PointsMaterial, + PropertyBinding, + Quaternion, + QuaternionKeyframeTrack, + RepeatWrapping, + Skeleton, + SkinnedMesh, + Sphere, + SpotLight, + Texture, + TextureLoader, + TriangleFanDrawMode, + TriangleStripDrawMode, + Vector2, + Vector3, + VectorKeyframeTrack, + SRGBColorSpace, + InstancedBufferAttribute +} from 'three'; +import { toTrianglesDrawMode } from '../utils/BufferGeometryUtils.js'; + +class GLTFLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.dracoLoader = null; + this.ktx2Loader = null; + this.meshoptDecoder = null; + + this.pluginCallbacks = []; + + this.register( function ( parser ) { + + return new GLTFMaterialsClearcoatExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsDispersionExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFTextureBasisUExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFTextureWebPExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFTextureAVIFExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsSheenExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsTransmissionExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsVolumeExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsIorExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsEmissiveStrengthExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsSpecularExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsIridescenceExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsAnisotropyExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMaterialsBumpExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFLightsExtension( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMeshoptCompression( parser ); + + } ); + + this.register( function ( parser ) { + + return new GLTFMeshGpuInstancing( parser ); + + } ); + + } + + load( url, onLoad, onProgress, onError ) { + + const scope = this; + + let resourcePath; + + if ( this.resourcePath !== '' ) { + + resourcePath = this.resourcePath; + + } else if ( this.path !== '' ) { + + // If a base path is set, resources will be relative paths from that plus the relative path of the gltf file + // Example path = 'https://my-cnd-server.com/', url = 'assets/models/model.gltf' + // resourcePath = 'https://my-cnd-server.com/assets/models/' + // referenced resource 'model.bin' will be loaded from 'https://my-cnd-server.com/assets/models/model.bin' + // referenced resource '../textures/texture.png' will be loaded from 'https://my-cnd-server.com/assets/textures/texture.png' + const relativeUrl = LoaderUtils.extractUrlBase( url ); + resourcePath = LoaderUtils.resolveURL( relativeUrl, this.path ); + + } else { + + resourcePath = LoaderUtils.extractUrlBase( url ); + + } + + // Tells the LoadingManager to track an extra item, which resolves after + // the model is fully loaded. This means the count of items loaded will + // be incorrect, but ensures manager.onLoad() does not fire early. + this.manager.itemStart( url ); + + const _onError = function ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + }; + + const loader = new FileLoader( this.manager ); + + loader.setPath( this.path ); + loader.setResponseType( 'arraybuffer' ); + loader.setRequestHeader( this.requestHeader ); + loader.setWithCredentials( this.withCredentials ); + + loader.load( url, function ( data ) { + + try { + + scope.parse( data, resourcePath, function ( gltf ) { + + onLoad( gltf ); + + scope.manager.itemEnd( url ); + + }, _onError ); + + } catch ( e ) { + + _onError( e ); + + } + + }, onProgress, _onError ); + + } + + setDRACOLoader( dracoLoader ) { + + this.dracoLoader = dracoLoader; + return this; + + } + + setKTX2Loader( ktx2Loader ) { + + this.ktx2Loader = ktx2Loader; + return this; + + } + + setMeshoptDecoder( meshoptDecoder ) { + + this.meshoptDecoder = meshoptDecoder; + return this; + + } + + register( callback ) { + + if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) { + + this.pluginCallbacks.push( callback ); + + } + + return this; + + } + + unregister( callback ) { + + if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) { + + this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 ); + + } + + return this; + + } + + parse( data, path, onLoad, onError ) { + + let json; + const extensions = {}; + const plugins = {}; + const textDecoder = new TextDecoder(); + + if ( typeof data === 'string' ) { + + json = JSON.parse( data ); + + } else if ( data instanceof ArrayBuffer ) { + + const magic = textDecoder.decode( new Uint8Array( data, 0, 4 ) ); + + if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) { + + try { + + extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data ); + + } catch ( error ) { + + if ( onError ) onError( error ); + return; + + } + + json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content ); + + } else { + + json = JSON.parse( textDecoder.decode( data ) ); + + } + + } else { + + json = data; + + } + + if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) { + + if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) ); + return; + + } + + const parser = new GLTFParser( json, { + + path: path || this.resourcePath || '', + crossOrigin: this.crossOrigin, + requestHeader: this.requestHeader, + manager: this.manager, + ktx2Loader: this.ktx2Loader, + meshoptDecoder: this.meshoptDecoder + + } ); + + parser.fileLoader.setRequestHeader( this.requestHeader ); + + for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) { + + const plugin = this.pluginCallbacks[ i ]( parser ); + + if ( ! plugin.name ) console.error( 'THREE.GLTFLoader: Invalid plugin found: missing name' ); + + plugins[ plugin.name ] = plugin; + + // Workaround to avoid determining as unknown extension + // in addUnknownExtensionsToUserData(). + // Remove this workaround if we move all the existing + // extension handlers to plugin system + extensions[ plugin.name ] = true; + + } + + if ( json.extensionsUsed ) { + + for ( let i = 0; i < json.extensionsUsed.length; ++ i ) { + + const extensionName = json.extensionsUsed[ i ]; + const extensionsRequired = json.extensionsRequired || []; + + switch ( extensionName ) { + + case EXTENSIONS.KHR_MATERIALS_UNLIT: + extensions[ extensionName ] = new GLTFMaterialsUnlitExtension(); + break; + + case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION: + extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader ); + break; + + case EXTENSIONS.KHR_TEXTURE_TRANSFORM: + extensions[ extensionName ] = new GLTFTextureTransformExtension(); + break; + + case EXTENSIONS.KHR_MESH_QUANTIZATION: + extensions[ extensionName ] = new GLTFMeshQuantizationExtension(); + break; + + default: + + if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) { + + console.warn( 'THREE.GLTFLoader: Unknown extension "' + extensionName + '".' ); + + } + + } + + } + + } + + parser.setExtensions( extensions ); + parser.setPlugins( plugins ); + parser.parse( onLoad, onError ); + + } + + parseAsync( data, path ) { + + const scope = this; + + return new Promise( function ( resolve, reject ) { + + scope.parse( data, path, resolve, reject ); + + } ); + + } + +} + +/* GLTFREGISTRY */ + +function GLTFRegistry() { + + let objects = {}; + + return { + + get: function ( key ) { + + return objects[ key ]; + + }, + + add: function ( key, object ) { + + objects[ key ] = object; + + }, + + remove: function ( key ) { + + delete objects[ key ]; + + }, + + removeAll: function () { + + objects = {}; + + } + + }; + +} + +/*********************************/ +/********** EXTENSIONS ***********/ +/*********************************/ + +const EXTENSIONS = { + KHR_BINARY_GLTF: 'KHR_binary_glTF', + KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression', + KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual', + KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat', + KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion', + KHR_MATERIALS_IOR: 'KHR_materials_ior', + KHR_MATERIALS_SHEEN: 'KHR_materials_sheen', + KHR_MATERIALS_SPECULAR: 'KHR_materials_specular', + KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission', + KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence', + KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy', + KHR_MATERIALS_UNLIT: 'KHR_materials_unlit', + KHR_MATERIALS_VOLUME: 'KHR_materials_volume', + KHR_TEXTURE_BASISU: 'KHR_texture_basisu', + KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform', + KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization', + KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength', + EXT_MATERIALS_BUMP: 'EXT_materials_bump', + EXT_TEXTURE_WEBP: 'EXT_texture_webp', + EXT_TEXTURE_AVIF: 'EXT_texture_avif', + EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression', + EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing' +}; + +/** + * Punctual Lights Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual + */ +class GLTFLightsExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL; + + // Object3D instance caches + this.cache = { refs: {}, uses: {} }; + + } + + _markDefs() { + + const parser = this.parser; + const nodeDefs = this.parser.json.nodes || []; + + for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) { + + const nodeDef = nodeDefs[ nodeIndex ]; + + if ( nodeDef.extensions + && nodeDef.extensions[ this.name ] + && nodeDef.extensions[ this.name ].light !== undefined ) { + + parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light ); + + } + + } + + } + + _loadLight( lightIndex ) { + + const parser = this.parser; + const cacheKey = 'light:' + lightIndex; + let dependency = parser.cache.get( cacheKey ); + + if ( dependency ) return dependency; + + const json = parser.json; + const extensions = ( json.extensions && json.extensions[ this.name ] ) || {}; + const lightDefs = extensions.lights || []; + const lightDef = lightDefs[ lightIndex ]; + let lightNode; + + const color = new Color( 0xffffff ); + + if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace ); + + const range = lightDef.range !== undefined ? lightDef.range : 0; + + switch ( lightDef.type ) { + + case 'directional': + lightNode = new DirectionalLight( color ); + lightNode.target.position.set( 0, 0, - 1 ); + lightNode.add( lightNode.target ); + break; + + case 'point': + lightNode = new PointLight( color ); + lightNode.distance = range; + break; + + case 'spot': + lightNode = new SpotLight( color ); + lightNode.distance = range; + // Handle spotlight properties. + lightDef.spot = lightDef.spot || {}; + lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0; + lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0; + lightNode.angle = lightDef.spot.outerConeAngle; + lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle; + lightNode.target.position.set( 0, 0, - 1 ); + lightNode.add( lightNode.target ); + break; + + default: + throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type ); + + } + + // Some lights (e.g. spot) default to a position other than the origin. Reset the position + // here, because node-level parsing will only override position if explicitly specified. + lightNode.position.set( 0, 0, 0 ); + + lightNode.decay = 2; + + assignExtrasToUserData( lightNode, lightDef ); + + if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity; + + lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) ); + + dependency = Promise.resolve( lightNode ); + + parser.cache.add( cacheKey, dependency ); + + return dependency; + + } + + getDependency( type, index ) { + + if ( type !== 'light' ) return; + + return this._loadLight( index ); + + } + + createNodeAttachment( nodeIndex ) { + + const self = this; + const parser = this.parser; + const json = parser.json; + const nodeDef = json.nodes[ nodeIndex ]; + const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {}; + const lightIndex = lightDef.light; + + if ( lightIndex === undefined ) return null; + + return this._loadLight( lightIndex ).then( function ( light ) { + + return parser._getNodeRef( self.cache, lightIndex, light ); + + } ); + + } + +} + +/** + * Unlit Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit + */ +class GLTFMaterialsUnlitExtension { + + constructor() { + + this.name = EXTENSIONS.KHR_MATERIALS_UNLIT; + + } + + getMaterialType() { + + return MeshBasicMaterial; + + } + + extendParams( materialParams, materialDef, parser ) { + + const pending = []; + + materialParams.color = new Color( 1.0, 1.0, 1.0 ); + materialParams.opacity = 1.0; + + const metallicRoughness = materialDef.pbrMetallicRoughness; + + if ( metallicRoughness ) { + + if ( Array.isArray( metallicRoughness.baseColorFactor ) ) { + + const array = metallicRoughness.baseColorFactor; + + materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace ); + materialParams.opacity = array[ 3 ]; + + } + + if ( metallicRoughness.baseColorTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) ); + + } + + } + + return Promise.all( pending ); + + } + +} + +/** + * Materials Emissive Strength Extension + * + * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md + */ +class GLTFMaterialsEmissiveStrengthExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength; + + if ( emissiveStrength !== undefined ) { + + materialParams.emissiveIntensity = emissiveStrength; + + } + + return Promise.resolve(); + + } + +} + +/** + * Clearcoat Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat + */ +class GLTFMaterialsClearcoatExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + if ( extension.clearcoatFactor !== undefined ) { + + materialParams.clearcoat = extension.clearcoatFactor; + + } + + if ( extension.clearcoatTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) ); + + } + + if ( extension.clearcoatRoughnessFactor !== undefined ) { + + materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor; + + } + + if ( extension.clearcoatRoughnessTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) ); + + } + + if ( extension.clearcoatNormalTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) ); + + if ( extension.clearcoatNormalTexture.scale !== undefined ) { + + const scale = extension.clearcoatNormalTexture.scale; + + materialParams.clearcoatNormalScale = new Vector2( scale, scale ); + + } + + } + + return Promise.all( pending ); + + } + +} + +/** + * Materials dispersion Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_dispersion + */ +class GLTFMaterialsDispersionExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const extension = materialDef.extensions[ this.name ]; + + materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0; + + return Promise.resolve(); + + } + +} + +/** + * Iridescence Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence + */ +class GLTFMaterialsIridescenceExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + if ( extension.iridescenceFactor !== undefined ) { + + materialParams.iridescence = extension.iridescenceFactor; + + } + + if ( extension.iridescenceTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) ); + + } + + if ( extension.iridescenceIor !== undefined ) { + + materialParams.iridescenceIOR = extension.iridescenceIor; + + } + + if ( materialParams.iridescenceThicknessRange === undefined ) { + + materialParams.iridescenceThicknessRange = [ 100, 400 ]; + + } + + if ( extension.iridescenceThicknessMinimum !== undefined ) { + + materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum; + + } + + if ( extension.iridescenceThicknessMaximum !== undefined ) { + + materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum; + + } + + if ( extension.iridescenceThicknessTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) ); + + } + + return Promise.all( pending ); + + } + +} + +/** + * Sheen Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen + */ +class GLTFMaterialsSheenExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_SHEEN; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + materialParams.sheenColor = new Color( 0, 0, 0 ); + materialParams.sheenRoughness = 0; + materialParams.sheen = 1; + + const extension = materialDef.extensions[ this.name ]; + + if ( extension.sheenColorFactor !== undefined ) { + + const colorFactor = extension.sheenColorFactor; + materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor[ 2 ], LinearSRGBColorSpace ); + + } + + if ( extension.sheenRoughnessFactor !== undefined ) { + + materialParams.sheenRoughness = extension.sheenRoughnessFactor; + + } + + if ( extension.sheenColorTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace ) ); + + } + + if ( extension.sheenRoughnessTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) ); + + } + + return Promise.all( pending ); + + } + +} + +/** + * Transmission Materials Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission + * Draft: https://github.com/KhronosGroup/glTF/pull/1698 + */ +class GLTFMaterialsTransmissionExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + if ( extension.transmissionFactor !== undefined ) { + + materialParams.transmission = extension.transmissionFactor; + + } + + if ( extension.transmissionTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) ); + + } + + return Promise.all( pending ); + + } + +} + +/** + * Materials Volume Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume + */ +class GLTFMaterialsVolumeExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_VOLUME; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0; + + if ( extension.thicknessTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) ); + + } + + materialParams.attenuationDistance = extension.attenuationDistance || Infinity; + + const colorArray = extension.attenuationColor || [ 1, 1, 1 ]; + materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace ); + + return Promise.all( pending ); + + } + +} + +/** + * Materials ior Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior + */ +class GLTFMaterialsIorExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_IOR; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const extension = materialDef.extensions[ this.name ]; + + materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5; + + return Promise.resolve(); + + } + +} + +/** + * Materials specular Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular + */ +class GLTFMaterialsSpecularExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0; + + if ( extension.specularTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) ); + + } + + const colorArray = extension.specularColorFactor || [ 1, 1, 1 ]; + materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace ); + + if ( extension.specularColorTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace ) ); + + } + + return Promise.all( pending ); + + } + +} + + +/** + * Materials bump Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump + */ +class GLTFMaterialsBumpExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.EXT_MATERIALS_BUMP; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + materialParams.bumpScale = extension.bumpFactor !== undefined ? extension.bumpFactor : 1.0; + + if ( extension.bumpTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'bumpMap', extension.bumpTexture ) ); + + } + + return Promise.all( pending ); + + } + +} + +/** + * Materials anisotropy Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_anisotropy + */ +class GLTFMaterialsAnisotropyExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY; + + } + + getMaterialType( materialIndex ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null; + + return MeshPhysicalMaterial; + + } + + extendMaterialParams( materialIndex, materialParams ) { + + const parser = this.parser; + const materialDef = parser.json.materials[ materialIndex ]; + + if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) { + + return Promise.resolve(); + + } + + const pending = []; + + const extension = materialDef.extensions[ this.name ]; + + if ( extension.anisotropyStrength !== undefined ) { + + materialParams.anisotropy = extension.anisotropyStrength; + + } + + if ( extension.anisotropyRotation !== undefined ) { + + materialParams.anisotropyRotation = extension.anisotropyRotation; + + } + + if ( extension.anisotropyTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'anisotropyMap', extension.anisotropyTexture ) ); + + } + + return Promise.all( pending ); + + } + +} + +/** + * BasisU Texture Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu + */ +class GLTFTextureBasisUExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.KHR_TEXTURE_BASISU; + + } + + loadTexture( textureIndex ) { + + const parser = this.parser; + const json = parser.json; + + const textureDef = json.textures[ textureIndex ]; + + if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) { + + return null; + + } + + const extension = textureDef.extensions[ this.name ]; + const loader = parser.options.ktx2Loader; + + if ( ! loader ) { + + if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) { + + throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' ); + + } else { + + // Assumes that the extension is optional and that a fallback texture is present + return null; + + } + + } + + return parser.loadTextureImage( textureIndex, extension.source, loader ); + + } + +} + +/** + * WebP Texture Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp + */ +class GLTFTextureWebPExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.EXT_TEXTURE_WEBP; + this.isSupported = null; + + } + + loadTexture( textureIndex ) { + + const name = this.name; + const parser = this.parser; + const json = parser.json; + + const textureDef = json.textures[ textureIndex ]; + + if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) { + + return null; + + } + + const extension = textureDef.extensions[ name ]; + const source = json.images[ extension.source ]; + + let loader = parser.textureLoader; + if ( source.uri ) { + + const handler = parser.options.manager.getHandler( source.uri ); + if ( handler !== null ) loader = handler; + + } + + return this.detectSupport().then( function ( isSupported ) { + + if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader ); + + if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) { + + throw new Error( 'THREE.GLTFLoader: WebP required by asset but unsupported.' ); + + } + + // Fall back to PNG or JPEG. + return parser.loadTexture( textureIndex ); + + } ); + + } + + detectSupport() { + + if ( ! this.isSupported ) { + + this.isSupported = new Promise( function ( resolve ) { + + const image = new Image(); + + // Lossy test image. Support for lossy images doesn't guarantee support for all + // WebP images, unfortunately. + image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'; + + image.onload = image.onerror = function () { + + resolve( image.height === 1 ); + + }; + + } ); + + } + + return this.isSupported; + + } + +} + +/** + * AVIF Texture Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_avif + */ +class GLTFTextureAVIFExtension { + + constructor( parser ) { + + this.parser = parser; + this.name = EXTENSIONS.EXT_TEXTURE_AVIF; + this.isSupported = null; + + } + + loadTexture( textureIndex ) { + + const name = this.name; + const parser = this.parser; + const json = parser.json; + + const textureDef = json.textures[ textureIndex ]; + + if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) { + + return null; + + } + + const extension = textureDef.extensions[ name ]; + const source = json.images[ extension.source ]; + + let loader = parser.textureLoader; + if ( source.uri ) { + + const handler = parser.options.manager.getHandler( source.uri ); + if ( handler !== null ) loader = handler; + + } + + return this.detectSupport().then( function ( isSupported ) { + + if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader ); + + if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) { + + throw new Error( 'THREE.GLTFLoader: AVIF required by asset but unsupported.' ); + + } + + // Fall back to PNG or JPEG. + return parser.loadTexture( textureIndex ); + + } ); + + } + + detectSupport() { + + if ( ! this.isSupported ) { + + this.isSupported = new Promise( function ( resolve ) { + + const image = new Image(); + + // Lossy test image. + image.src = 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI='; + image.onload = image.onerror = function () { + + resolve( image.height === 1 ); + + }; + + } ); + + } + + return this.isSupported; + + } + +} + +/** + * meshopt BufferView Compression Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression + */ +class GLTFMeshoptCompression { + + constructor( parser ) { + + this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION; + this.parser = parser; + + } + + loadBufferView( index ) { + + const json = this.parser.json; + const bufferView = json.bufferViews[ index ]; + + if ( bufferView.extensions && bufferView.extensions[ this.name ] ) { + + const extensionDef = bufferView.extensions[ this.name ]; + + const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer ); + const decoder = this.parser.options.meshoptDecoder; + + if ( ! decoder || ! decoder.supported ) { + + if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) { + + throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' ); + + } else { + + // Assumes that the extension is optional and that fallback buffer data is present + return null; + + } + + } + + return buffer.then( function ( res ) { + + const byteOffset = extensionDef.byteOffset || 0; + const byteLength = extensionDef.byteLength || 0; + + const count = extensionDef.count; + const stride = extensionDef.byteStride; + + const source = new Uint8Array( res, byteOffset, byteLength ); + + if ( decoder.decodeGltfBufferAsync ) { + + return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) { + + return res.buffer; + + } ); + + } else { + + // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync + return decoder.ready.then( function () { + + const result = new ArrayBuffer( count * stride ); + decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter ); + return result; + + } ); + + } + + } ); + + } else { + + return null; + + } + + } + +} + +/** + * GPU Instancing Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing + * + */ +class GLTFMeshGpuInstancing { + + constructor( parser ) { + + this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING; + this.parser = parser; + + } + + createNodeMesh( nodeIndex ) { + + const json = this.parser.json; + const nodeDef = json.nodes[ nodeIndex ]; + + if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] || + nodeDef.mesh === undefined ) { + + return null; + + } + + const meshDef = json.meshes[ nodeDef.mesh ]; + + // No Points or Lines + Instancing support yet + + for ( const primitive of meshDef.primitives ) { + + if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES && + primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP && + primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN && + primitive.mode !== undefined ) { + + return null; + + } + + } + + const extensionDef = nodeDef.extensions[ this.name ]; + const attributesDef = extensionDef.attributes; + + // @TODO: Can we support InstancedMesh + SkinnedMesh? + + const pending = []; + const attributes = {}; + + for ( const key in attributesDef ) { + + pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => { + + attributes[ key ] = accessor; + return attributes[ key ]; + + } ) ); + + } + + if ( pending.length < 1 ) { + + return null; + + } + + pending.push( this.parser.createNodeMesh( nodeIndex ) ); + + return Promise.all( pending ).then( results => { + + const nodeObject = results.pop(); + const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ]; + const count = results[ 0 ].count; // All attribute counts should be same + const instancedMeshes = []; + + for ( const mesh of meshes ) { + + // Temporal variables + const m = new Matrix4(); + const p = new Vector3(); + const q = new Quaternion(); + const s = new Vector3( 1, 1, 1 ); + + const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count ); + + for ( let i = 0; i < count; i ++ ) { + + if ( attributes.TRANSLATION ) { + + p.fromBufferAttribute( attributes.TRANSLATION, i ); + + } + + if ( attributes.ROTATION ) { + + q.fromBufferAttribute( attributes.ROTATION, i ); + + } + + if ( attributes.SCALE ) { + + s.fromBufferAttribute( attributes.SCALE, i ); + + } + + instancedMesh.setMatrixAt( i, m.compose( p, q, s ) ); + + } + + // Add instance attributes to the geometry, excluding TRS. + for ( const attributeName in attributes ) { + + if ( attributeName === '_COLOR_0' ) { + + const attr = attributes[ attributeName ]; + instancedMesh.instanceColor = new InstancedBufferAttribute( attr.array, attr.itemSize, attr.normalized ); + + } else if ( attributeName !== 'TRANSLATION' && + attributeName !== 'ROTATION' && + attributeName !== 'SCALE' ) { + + mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] ); + + } + + } + + // Just in case + Object3D.prototype.copy.call( instancedMesh, mesh ); + + this.parser.assignFinalMaterial( instancedMesh ); + + instancedMeshes.push( instancedMesh ); + + } + + if ( nodeObject.isGroup ) { + + nodeObject.clear(); + + nodeObject.add( ... instancedMeshes ); + + return nodeObject; + + } + + return instancedMeshes[ 0 ]; + + } ); + + } + +} + +/* BINARY EXTENSION */ +const BINARY_EXTENSION_HEADER_MAGIC = 'glTF'; +const BINARY_EXTENSION_HEADER_LENGTH = 12; +const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 }; + +class GLTFBinaryExtension { + + constructor( data ) { + + this.name = EXTENSIONS.KHR_BINARY_GLTF; + this.content = null; + this.body = null; + + const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH ); + const textDecoder = new TextDecoder(); + + this.header = { + magic: textDecoder.decode( new Uint8Array( data.slice( 0, 4 ) ) ), + version: headerView.getUint32( 4, true ), + length: headerView.getUint32( 8, true ) + }; + + if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) { + + throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' ); + + } else if ( this.header.version < 2.0 ) { + + throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' ); + + } + + const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH; + const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH ); + let chunkIndex = 0; + + while ( chunkIndex < chunkContentsLength ) { + + const chunkLength = chunkView.getUint32( chunkIndex, true ); + chunkIndex += 4; + + const chunkType = chunkView.getUint32( chunkIndex, true ); + chunkIndex += 4; + + if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) { + + const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength ); + this.content = textDecoder.decode( contentArray ); + + } else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) { + + const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex; + this.body = data.slice( byteOffset, byteOffset + chunkLength ); + + } + + // Clients must ignore chunks with unknown types. + + chunkIndex += chunkLength; + + } + + if ( this.content === null ) { + + throw new Error( 'THREE.GLTFLoader: JSON content not found.' ); + + } + + } + +} + +/** + * DRACO Mesh Compression Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression + */ +class GLTFDracoMeshCompressionExtension { + + constructor( json, dracoLoader ) { + + if ( ! dracoLoader ) { + + throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' ); + + } + + this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION; + this.json = json; + this.dracoLoader = dracoLoader; + this.dracoLoader.preload(); + + } + + decodePrimitive( primitive, parser ) { + + const json = this.json; + const dracoLoader = this.dracoLoader; + const bufferViewIndex = primitive.extensions[ this.name ].bufferView; + const gltfAttributeMap = primitive.extensions[ this.name ].attributes; + const threeAttributeMap = {}; + const attributeNormalizedMap = {}; + const attributeTypeMap = {}; + + for ( const attributeName in gltfAttributeMap ) { + + const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase(); + + threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ]; + + } + + for ( const attributeName in primitive.attributes ) { + + const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase(); + + if ( gltfAttributeMap[ attributeName ] !== undefined ) { + + const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ]; + const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ]; + + attributeTypeMap[ threeAttributeName ] = componentType.name; + attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true; + + } + + } + + return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) { + + return new Promise( function ( resolve, reject ) { + + dracoLoader.decodeDracoFile( bufferView, function ( geometry ) { + + for ( const attributeName in geometry.attributes ) { + + const attribute = geometry.attributes[ attributeName ]; + const normalized = attributeNormalizedMap[ attributeName ]; + + if ( normalized !== undefined ) attribute.normalized = normalized; + + } + + resolve( geometry ); + + }, threeAttributeMap, attributeTypeMap, LinearSRGBColorSpace, reject ); + + } ); + + } ); + + } + +} + +/** + * Texture Transform Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform + */ +class GLTFTextureTransformExtension { + + constructor() { + + this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM; + + } + + extendTexture( texture, transform ) { + + if ( ( transform.texCoord === undefined || transform.texCoord === texture.channel ) + && transform.offset === undefined + && transform.rotation === undefined + && transform.scale === undefined ) { + + // See https://github.com/mrdoob/three.js/issues/21819. + return texture; + + } + + texture = texture.clone(); + + if ( transform.texCoord !== undefined ) { + + texture.channel = transform.texCoord; + + } + + if ( transform.offset !== undefined ) { + + texture.offset.fromArray( transform.offset ); + + } + + if ( transform.rotation !== undefined ) { + + texture.rotation = transform.rotation; + + } + + if ( transform.scale !== undefined ) { + + texture.repeat.fromArray( transform.scale ); + + } + + texture.needsUpdate = true; + + return texture; + + } + +} + +/** + * Mesh Quantization Extension + * + * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization + */ +class GLTFMeshQuantizationExtension { + + constructor() { + + this.name = EXTENSIONS.KHR_MESH_QUANTIZATION; + + } + +} + +/*********************************/ +/********** INTERPOLATION ********/ +/*********************************/ + +// Spline Interpolation +// Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation +class GLTFCubicSplineInterpolant extends Interpolant { + + constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + super( parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + copySampleValue_( index ) { + + // Copies a sample value to the result buffer. See description of glTF + // CUBICSPLINE values layout in interpolate_() function below. + + const result = this.resultBuffer, + values = this.sampleValues, + valueSize = this.valueSize, + offset = index * valueSize * 3 + valueSize; + + for ( let i = 0; i !== valueSize; i ++ ) { + + result[ i ] = values[ offset + i ]; + + } + + return result; + + } + + interpolate_( i1, t0, t, t1 ) { + + const result = this.resultBuffer; + const values = this.sampleValues; + const stride = this.valueSize; + + const stride2 = stride * 2; + const stride3 = stride * 3; + + const td = t1 - t0; + + const p = ( t - t0 ) / td; + const pp = p * p; + const ppp = pp * p; + + const offset1 = i1 * stride3; + const offset0 = offset1 - stride3; + + const s2 = - 2 * ppp + 3 * pp; + const s3 = ppp - pp; + const s0 = 1 - s2; + const s1 = s3 - pp + p; + + // Layout of keyframe output values for CUBICSPLINE animations: + // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ] + for ( let i = 0; i !== stride; i ++ ) { + + const p0 = values[ offset0 + i + stride ]; // splineVertex_k + const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k) + const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1 + const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k) + + result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1; + + } + + return result; + + } + +} + +const _q = new Quaternion(); + +class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant { + + interpolate_( i1, t0, t, t1 ) { + + const result = super.interpolate_( i1, t0, t, t1 ); + + _q.fromArray( result ).normalize().toArray( result ); + + return result; + + } + +} + + +/*********************************/ +/********** INTERNALS ************/ +/*********************************/ + +/* CONSTANTS */ + +const WEBGL_CONSTANTS = { + FLOAT: 5126, + //FLOAT_MAT2: 35674, + FLOAT_MAT3: 35675, + FLOAT_MAT4: 35676, + FLOAT_VEC2: 35664, + FLOAT_VEC3: 35665, + FLOAT_VEC4: 35666, + LINEAR: 9729, + REPEAT: 10497, + SAMPLER_2D: 35678, + POINTS: 0, + LINES: 1, + LINE_LOOP: 2, + LINE_STRIP: 3, + TRIANGLES: 4, + TRIANGLE_STRIP: 5, + TRIANGLE_FAN: 6, + UNSIGNED_BYTE: 5121, + UNSIGNED_SHORT: 5123 +}; + +const WEBGL_COMPONENT_TYPES = { + 5120: Int8Array, + 5121: Uint8Array, + 5122: Int16Array, + 5123: Uint16Array, + 5125: Uint32Array, + 5126: Float32Array +}; + +const WEBGL_FILTERS = { + 9728: NearestFilter, + 9729: LinearFilter, + 9984: NearestMipmapNearestFilter, + 9985: LinearMipmapNearestFilter, + 9986: NearestMipmapLinearFilter, + 9987: LinearMipmapLinearFilter +}; + +const WEBGL_WRAPPINGS = { + 33071: ClampToEdgeWrapping, + 33648: MirroredRepeatWrapping, + 10497: RepeatWrapping +}; + +const WEBGL_TYPE_SIZES = { + 'SCALAR': 1, + 'VEC2': 2, + 'VEC3': 3, + 'VEC4': 4, + 'MAT2': 4, + 'MAT3': 9, + 'MAT4': 16 +}; + +const ATTRIBUTES = { + POSITION: 'position', + NORMAL: 'normal', + TANGENT: 'tangent', + TEXCOORD_0: 'uv', + TEXCOORD_1: 'uv1', + TEXCOORD_2: 'uv2', + TEXCOORD_3: 'uv3', + COLOR_0: 'color', + WEIGHTS_0: 'skinWeight', + JOINTS_0: 'skinIndex', +}; + +const PATH_PROPERTIES = { + scale: 'scale', + translation: 'position', + rotation: 'quaternion', + weights: 'morphTargetInfluences' +}; + +const INTERPOLATION = { + CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each + // keyframe track will be initialized with a default interpolation type, then modified. + LINEAR: InterpolateLinear, + STEP: InterpolateDiscrete +}; + +const ALPHA_MODES = { + OPAQUE: 'OPAQUE', + MASK: 'MASK', + BLEND: 'BLEND' +}; + +/** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material + */ +function createDefaultMaterial( cache ) { + + if ( cache[ 'DefaultMaterial' ] === undefined ) { + + cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( { + color: 0xFFFFFF, + emissive: 0x000000, + metalness: 1, + roughness: 1, + transparent: false, + depthTest: true, + side: FrontSide + } ); + + } + + return cache[ 'DefaultMaterial' ]; + +} + +function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) { + + // Add unknown glTF extensions to an object's userData. + + for ( const name in objectDef.extensions ) { + + if ( knownExtensions[ name ] === undefined ) { + + object.userData.gltfExtensions = object.userData.gltfExtensions || {}; + object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ]; + + } + + } + +} + +/** + * @param {Object3D|Material|BufferGeometry} object + * @param {GLTF.definition} gltfDef + */ +function assignExtrasToUserData( object, gltfDef ) { + + if ( gltfDef.extras !== undefined ) { + + if ( typeof gltfDef.extras === 'object' ) { + + Object.assign( object.userData, gltfDef.extras ); + + } else { + + console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras ); + + } + + } + +} + +/** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets + * + * @param {BufferGeometry} geometry + * @param {Array} targets + * @param {GLTFParser} parser + * @return {Promise} + */ +function addMorphTargets( geometry, targets, parser ) { + + let hasMorphPosition = false; + let hasMorphNormal = false; + let hasMorphColor = false; + + for ( let i = 0, il = targets.length; i < il; i ++ ) { + + const target = targets[ i ]; + + if ( target.POSITION !== undefined ) hasMorphPosition = true; + if ( target.NORMAL !== undefined ) hasMorphNormal = true; + if ( target.COLOR_0 !== undefined ) hasMorphColor = true; + + if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break; + + } + + if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry ); + + const pendingPositionAccessors = []; + const pendingNormalAccessors = []; + const pendingColorAccessors = []; + + for ( let i = 0, il = targets.length; i < il; i ++ ) { + + const target = targets[ i ]; + + if ( hasMorphPosition ) { + + const pendingAccessor = target.POSITION !== undefined + ? parser.getDependency( 'accessor', target.POSITION ) + : geometry.attributes.position; + + pendingPositionAccessors.push( pendingAccessor ); + + } + + if ( hasMorphNormal ) { + + const pendingAccessor = target.NORMAL !== undefined + ? parser.getDependency( 'accessor', target.NORMAL ) + : geometry.attributes.normal; + + pendingNormalAccessors.push( pendingAccessor ); + + } + + if ( hasMorphColor ) { + + const pendingAccessor = target.COLOR_0 !== undefined + ? parser.getDependency( 'accessor', target.COLOR_0 ) + : geometry.attributes.color; + + pendingColorAccessors.push( pendingAccessor ); + + } + + } + + return Promise.all( [ + Promise.all( pendingPositionAccessors ), + Promise.all( pendingNormalAccessors ), + Promise.all( pendingColorAccessors ) + ] ).then( function ( accessors ) { + + const morphPositions = accessors[ 0 ]; + const morphNormals = accessors[ 1 ]; + const morphColors = accessors[ 2 ]; + + if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions; + if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals; + if ( hasMorphColor ) geometry.morphAttributes.color = morphColors; + geometry.morphTargetsRelative = true; + + return geometry; + + } ); + +} + +/** + * @param {Mesh} mesh + * @param {GLTF.Mesh} meshDef + */ +function updateMorphTargets( mesh, meshDef ) { + + mesh.updateMorphTargets(); + + if ( meshDef.weights !== undefined ) { + + for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) { + + mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ]; + + } + + } + + // .extras has user-defined data, so check that .extras.targetNames is an array. + if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) { + + const targetNames = meshDef.extras.targetNames; + + if ( mesh.morphTargetInfluences.length === targetNames.length ) { + + mesh.morphTargetDictionary = {}; + + for ( let i = 0, il = targetNames.length; i < il; i ++ ) { + + mesh.morphTargetDictionary[ targetNames[ i ] ] = i; + + } + + } else { + + console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' ); + + } + + } + +} + +function createPrimitiveKey( primitiveDef ) { + + let geometryKey; + + const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]; + + if ( dracoExtension ) { + + geometryKey = 'draco:' + dracoExtension.bufferView + + ':' + dracoExtension.indices + + ':' + createAttributesKey( dracoExtension.attributes ); + + } else { + + geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode; + + } + + if ( primitiveDef.targets !== undefined ) { + + for ( let i = 0, il = primitiveDef.targets.length; i < il; i ++ ) { + + geometryKey += ':' + createAttributesKey( primitiveDef.targets[ i ] ); + + } + + } + + return geometryKey; + +} + +function createAttributesKey( attributes ) { + + let attributesKey = ''; + + const keys = Object.keys( attributes ).sort(); + + for ( let i = 0, il = keys.length; i < il; i ++ ) { + + attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';'; + + } + + return attributesKey; + +} + +function getNormalizedComponentScale( constructor ) { + + // Reference: + // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data + + switch ( constructor ) { + + case Int8Array: + return 1 / 127; + + case Uint8Array: + return 1 / 255; + + case Int16Array: + return 1 / 32767; + + case Uint16Array: + return 1 / 65535; + + default: + throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' ); + + } + +} + +function getImageURIMimeType( uri ) { + + if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg'; + if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp'; + if ( uri.search( /\.ktx2($|\?)/i ) > 0 || uri.search( /^data\:image\/ktx2/ ) === 0 ) return 'image/ktx2'; + + return 'image/png'; + +} + +const _identityMatrix = new Matrix4(); + +/* GLTF PARSER */ + +class GLTFParser { + + constructor( json = {}, options = {} ) { + + this.json = json; + this.extensions = {}; + this.plugins = {}; + this.options = options; + + // loader object cache + this.cache = new GLTFRegistry(); + + // associations between Three.js objects and glTF elements + this.associations = new Map(); + + // BufferGeometry caching + this.primitiveCache = {}; + + // Node cache + this.nodeCache = {}; + + // Object3D instance caches + this.meshCache = { refs: {}, uses: {} }; + this.cameraCache = { refs: {}, uses: {} }; + this.lightCache = { refs: {}, uses: {} }; + + this.sourceCache = {}; + this.textureCache = {}; + + // Track node names, to ensure no duplicates + this.nodeNamesUsed = {}; + + // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the + // expensive work of uploading a texture to the GPU off the main thread. + + let isSafari = false; + let safariVersion = - 1; + let isFirefox = false; + let firefoxVersion = - 1; + + if ( typeof navigator !== 'undefined' ) { + + const userAgent = navigator.userAgent; + + isSafari = /^((?!chrome|android).)*safari/i.test( userAgent ) === true; + const safariMatch = userAgent.match( /Version\/(\d+)/ ); + safariVersion = isSafari && safariMatch ? parseInt( safariMatch[ 1 ], 10 ) : - 1; + + isFirefox = userAgent.indexOf( 'Firefox' ) > - 1; + firefoxVersion = isFirefox ? userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1; + + } + + if ( typeof createImageBitmap === 'undefined' || ( isSafari && safariVersion < 17 ) || ( isFirefox && firefoxVersion < 98 ) ) { + + this.textureLoader = new TextureLoader( this.options.manager ); + + } else { + + this.textureLoader = new ImageBitmapLoader( this.options.manager ); + + } + + this.textureLoader.setCrossOrigin( this.options.crossOrigin ); + this.textureLoader.setRequestHeader( this.options.requestHeader ); + + this.fileLoader = new FileLoader( this.options.manager ); + this.fileLoader.setResponseType( 'arraybuffer' ); + + if ( this.options.crossOrigin === 'use-credentials' ) { + + this.fileLoader.setWithCredentials( true ); + + } + + } + + setExtensions( extensions ) { + + this.extensions = extensions; + + } + + setPlugins( plugins ) { + + this.plugins = plugins; + + } + + parse( onLoad, onError ) { + + const parser = this; + const json = this.json; + const extensions = this.extensions; + + // Clear the loader cache + this.cache.removeAll(); + this.nodeCache = {}; + + // Mark the special nodes/meshes in json for efficient parse + this._invokeAll( function ( ext ) { + + return ext._markDefs && ext._markDefs(); + + } ); + + Promise.all( this._invokeAll( function ( ext ) { + + return ext.beforeRoot && ext.beforeRoot(); + + } ) ).then( function () { + + return Promise.all( [ + + parser.getDependencies( 'scene' ), + parser.getDependencies( 'animation' ), + parser.getDependencies( 'camera' ), + + ] ); + + } ).then( function ( dependencies ) { + + const result = { + scene: dependencies[ 0 ][ json.scene || 0 ], + scenes: dependencies[ 0 ], + animations: dependencies[ 1 ], + cameras: dependencies[ 2 ], + asset: json.asset, + parser: parser, + userData: {} + }; + + addUnknownExtensionsToUserData( extensions, result, json ); + + assignExtrasToUserData( result, json ); + + return Promise.all( parser._invokeAll( function ( ext ) { + + return ext.afterRoot && ext.afterRoot( result ); + + } ) ).then( function () { + + for ( const scene of result.scenes ) { + + scene.updateMatrixWorld(); + + } + + onLoad( result ); + + } ); + + } ).catch( onError ); + + } + + /** + * Marks the special nodes/meshes in json for efficient parse. + */ + _markDefs() { + + const nodeDefs = this.json.nodes || []; + const skinDefs = this.json.skins || []; + const meshDefs = this.json.meshes || []; + + // Nothing in the node definition indicates whether it is a Bone or an + // Object3D. Use the skins' joint references to mark bones. + for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) { + + const joints = skinDefs[ skinIndex ].joints; + + for ( let i = 0, il = joints.length; i < il; i ++ ) { + + nodeDefs[ joints[ i ] ].isBone = true; + + } + + } + + // Iterate over all nodes, marking references to shared resources, + // as well as skeleton joints. + for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) { + + const nodeDef = nodeDefs[ nodeIndex ]; + + if ( nodeDef.mesh !== undefined ) { + + this._addNodeRef( this.meshCache, nodeDef.mesh ); + + // Nothing in the mesh definition indicates whether it is + // a SkinnedMesh or Mesh. Use the node's mesh reference + // to mark SkinnedMesh if node has skin. + if ( nodeDef.skin !== undefined ) { + + meshDefs[ nodeDef.mesh ].isSkinnedMesh = true; + + } + + } + + if ( nodeDef.camera !== undefined ) { + + this._addNodeRef( this.cameraCache, nodeDef.camera ); + + } + + } + + } + + /** + * Counts references to shared node / Object3D resources. These resources + * can be reused, or "instantiated", at multiple nodes in the scene + * hierarchy. Mesh, Camera, and Light instances are instantiated and must + * be marked. Non-scenegraph resources (like Materials, Geometries, and + * Textures) can be reused directly and are not marked here. + * + * Example: CesiumMilkTruck sample model reuses "Wheel" meshes. + */ + _addNodeRef( cache, index ) { + + if ( index === undefined ) return; + + if ( cache.refs[ index ] === undefined ) { + + cache.refs[ index ] = cache.uses[ index ] = 0; + + } + + cache.refs[ index ] ++; + + } + + /** Returns a reference to a shared resource, cloning it if necessary. */ + _getNodeRef( cache, index, object ) { + + if ( cache.refs[ index ] <= 1 ) return object; + + const ref = object.clone(); + + // Propagates mappings to the cloned object, prevents mappings on the + // original object from being lost. + const updateMappings = ( original, clone ) => { + + const mappings = this.associations.get( original ); + if ( mappings != null ) { + + this.associations.set( clone, mappings ); + + } + + for ( const [ i, child ] of original.children.entries() ) { + + updateMappings( child, clone.children[ i ] ); + + } + + }; + + updateMappings( object, ref ); + + ref.name += '_instance_' + ( cache.uses[ index ] ++ ); + + return ref; + + } + + _invokeOne( func ) { + + const extensions = Object.values( this.plugins ); + extensions.push( this ); + + for ( let i = 0; i < extensions.length; i ++ ) { + + const result = func( extensions[ i ] ); + + if ( result ) return result; + + } + + return null; + + } + + _invokeAll( func ) { + + const extensions = Object.values( this.plugins ); + extensions.unshift( this ); + + const pending = []; + + for ( let i = 0; i < extensions.length; i ++ ) { + + const result = func( extensions[ i ] ); + + if ( result ) pending.push( result ); + + } + + return pending; + + } + + /** + * Requests the specified dependency asynchronously, with caching. + * @param {string} type + * @param {number} index + * @return {Promise} + */ + getDependency( type, index ) { + + const cacheKey = type + ':' + index; + let dependency = this.cache.get( cacheKey ); + + if ( ! dependency ) { + + switch ( type ) { + + case 'scene': + dependency = this.loadScene( index ); + break; + + case 'node': + dependency = this._invokeOne( function ( ext ) { + + return ext.loadNode && ext.loadNode( index ); + + } ); + break; + + case 'mesh': + dependency = this._invokeOne( function ( ext ) { + + return ext.loadMesh && ext.loadMesh( index ); + + } ); + break; + + case 'accessor': + dependency = this.loadAccessor( index ); + break; + + case 'bufferView': + dependency = this._invokeOne( function ( ext ) { + + return ext.loadBufferView && ext.loadBufferView( index ); + + } ); + break; + + case 'buffer': + dependency = this.loadBuffer( index ); + break; + + case 'material': + dependency = this._invokeOne( function ( ext ) { + + return ext.loadMaterial && ext.loadMaterial( index ); + + } ); + break; + + case 'texture': + dependency = this._invokeOne( function ( ext ) { + + return ext.loadTexture && ext.loadTexture( index ); + + } ); + break; + + case 'skin': + dependency = this.loadSkin( index ); + break; + + case 'animation': + dependency = this._invokeOne( function ( ext ) { + + return ext.loadAnimation && ext.loadAnimation( index ); + + } ); + break; + + case 'camera': + dependency = this.loadCamera( index ); + break; + + default: + dependency = this._invokeOne( function ( ext ) { + + return ext != this && ext.getDependency && ext.getDependency( type, index ); + + } ); + + if ( ! dependency ) { + + throw new Error( 'Unknown type: ' + type ); + + } + + break; + + } + + this.cache.add( cacheKey, dependency ); + + } + + return dependency; + + } + + /** + * Requests all dependencies of the specified type asynchronously, with caching. + * @param {string} type + * @return {Promise>} + */ + getDependencies( type ) { + + let dependencies = this.cache.get( type ); + + if ( ! dependencies ) { + + const parser = this; + const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || []; + + dependencies = Promise.all( defs.map( function ( def, index ) { + + return parser.getDependency( type, index ); + + } ) ); + + this.cache.add( type, dependencies ); + + } + + return dependencies; + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views + * @param {number} bufferIndex + * @return {Promise} + */ + loadBuffer( bufferIndex ) { + + const bufferDef = this.json.buffers[ bufferIndex ]; + const loader = this.fileLoader; + + if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) { + + throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' ); + + } + + // If present, GLB container is required to be the first buffer. + if ( bufferDef.uri === undefined && bufferIndex === 0 ) { + + return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body ); + + } + + const options = this.options; + + return new Promise( function ( resolve, reject ) { + + loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () { + + reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) ); + + } ); + + } ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views + * @param {number} bufferViewIndex + * @return {Promise} + */ + loadBufferView( bufferViewIndex ) { + + const bufferViewDef = this.json.bufferViews[ bufferViewIndex ]; + + return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) { + + const byteLength = bufferViewDef.byteLength || 0; + const byteOffset = bufferViewDef.byteOffset || 0; + return buffer.slice( byteOffset, byteOffset + byteLength ); + + } ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors + * @param {number} accessorIndex + * @return {Promise} + */ + loadAccessor( accessorIndex ) { + + const parser = this; + const json = this.json; + + const accessorDef = this.json.accessors[ accessorIndex ]; + + if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) { + + const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ]; + const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ]; + const normalized = accessorDef.normalized === true; + + const array = new TypedArray( accessorDef.count * itemSize ); + return Promise.resolve( new BufferAttribute( array, itemSize, normalized ) ); + + } + + const pendingBufferViews = []; + + if ( accessorDef.bufferView !== undefined ) { + + pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) ); + + } else { + + pendingBufferViews.push( null ); + + } + + if ( accessorDef.sparse !== undefined ) { + + pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) ); + pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) ); + + } + + return Promise.all( pendingBufferViews ).then( function ( bufferViews ) { + + const bufferView = bufferViews[ 0 ]; + + const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ]; + const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ]; + + // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12. + const elementBytes = TypedArray.BYTES_PER_ELEMENT; + const itemBytes = elementBytes * itemSize; + const byteOffset = accessorDef.byteOffset || 0; + const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined; + const normalized = accessorDef.normalized === true; + let array, bufferAttribute; + + // The buffer is not interleaved if the stride is the item size in bytes. + if ( byteStride && byteStride !== itemBytes ) { + + // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer + // This makes sure that IBA.count reflects accessor.count properly + const ibSlice = Math.floor( byteOffset / byteStride ); + const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count; + let ib = parser.cache.get( ibCacheKey ); + + if ( ! ib ) { + + array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes ); + + // Integer parameters to IB/IBA are in array elements, not bytes. + ib = new InterleavedBuffer( array, byteStride / elementBytes ); + + parser.cache.add( ibCacheKey, ib ); + + } + + bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized ); + + } else { + + if ( bufferView === null ) { + + array = new TypedArray( accessorDef.count * itemSize ); + + } else { + + array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize ); + + } + + bufferAttribute = new BufferAttribute( array, itemSize, normalized ); + + } + + // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors + if ( accessorDef.sparse !== undefined ) { + + const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR; + const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ]; + + const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0; + const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0; + + const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices ); + const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize ); + + if ( bufferView !== null ) { + + // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes. + bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized ); + + } + + // Ignore normalized since we copy from sparse + bufferAttribute.normalized = false; + + for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) { + + const index = sparseIndices[ i ]; + + bufferAttribute.setX( index, sparseValues[ i * itemSize ] ); + if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] ); + if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] ); + if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] ); + if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' ); + + } + + bufferAttribute.normalized = normalized; + + } + + return bufferAttribute; + + } ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures + * @param {number} textureIndex + * @return {Promise} + */ + loadTexture( textureIndex ) { + + const json = this.json; + const options = this.options; + const textureDef = json.textures[ textureIndex ]; + const sourceIndex = textureDef.source; + const sourceDef = json.images[ sourceIndex ]; + + let loader = this.textureLoader; + + if ( sourceDef.uri ) { + + const handler = options.manager.getHandler( sourceDef.uri ); + if ( handler !== null ) loader = handler; + + } + + return this.loadTextureImage( textureIndex, sourceIndex, loader ); + + } + + loadTextureImage( textureIndex, sourceIndex, loader ) { + + const parser = this; + const json = this.json; + + const textureDef = json.textures[ textureIndex ]; + const sourceDef = json.images[ sourceIndex ]; + + const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler; + + if ( this.textureCache[ cacheKey ] ) { + + // See https://github.com/mrdoob/three.js/issues/21559. + return this.textureCache[ cacheKey ]; + + } + + const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) { + + texture.flipY = false; + + texture.name = textureDef.name || sourceDef.name || ''; + + if ( texture.name === '' && typeof sourceDef.uri === 'string' && sourceDef.uri.startsWith( 'data:image/' ) === false ) { + + texture.name = sourceDef.uri; + + } + + const samplers = json.samplers || {}; + const sampler = samplers[ textureDef.sampler ] || {}; + + texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter; + texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter; + texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping; + texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping; + texture.generateMipmaps = ! texture.isCompressedTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter; + + parser.associations.set( texture, { textures: textureIndex } ); + + return texture; + + } ).catch( function () { + + return null; + + } ); + + this.textureCache[ cacheKey ] = promise; + + return promise; + + } + + loadImageSource( sourceIndex, loader ) { + + const parser = this; + const json = this.json; + const options = this.options; + + if ( this.sourceCache[ sourceIndex ] !== undefined ) { + + return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() ); + + } + + const sourceDef = json.images[ sourceIndex ]; + + const URL = self.URL || self.webkitURL; + + let sourceURI = sourceDef.uri || ''; + let isObjectURL = false; + + if ( sourceDef.bufferView !== undefined ) { + + // Load binary image data from bufferView, if provided. + + sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) { + + isObjectURL = true; + const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } ); + sourceURI = URL.createObjectURL( blob ); + return sourceURI; + + } ); + + } else if ( sourceDef.uri === undefined ) { + + throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' ); + + } + + const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) { + + return new Promise( function ( resolve, reject ) { + + let onLoad = resolve; + + if ( loader.isImageBitmapLoader === true ) { + + onLoad = function ( imageBitmap ) { + + const texture = new Texture( imageBitmap ); + texture.needsUpdate = true; + + resolve( texture ); + + }; + + } + + loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject ); + + } ); + + } ).then( function ( texture ) { + + // Clean up resources and configure Texture. + + if ( isObjectURL === true ) { + + URL.revokeObjectURL( sourceURI ); + + } + + assignExtrasToUserData( texture, sourceDef ); + + texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri ); + + return texture; + + } ).catch( function ( error ) { + + console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI ); + throw error; + + } ); + + this.sourceCache[ sourceIndex ] = promise; + return promise; + + } + + /** + * Asynchronously assigns a texture to the given material parameters. + * @param {Object} materialParams + * @param {string} mapName + * @param {Object} mapDef + * @return {Promise} + */ + assignTexture( materialParams, mapName, mapDef, colorSpace ) { + + const parser = this; + + return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) { + + if ( ! texture ) return null; + + if ( mapDef.texCoord !== undefined && mapDef.texCoord > 0 ) { + + texture = texture.clone(); + texture.channel = mapDef.texCoord; + + } + + if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) { + + const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined; + + if ( transform ) { + + const gltfReference = parser.associations.get( texture ); + texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform ); + parser.associations.set( texture, gltfReference ); + + } + + } + + if ( colorSpace !== undefined ) { + + texture.colorSpace = colorSpace; + + } + + materialParams[ mapName ] = texture; + + return texture; + + } ); + + } + + /** + * Assigns final material to a Mesh, Line, or Points instance. The instance + * already has a material (generated from the glTF material options alone) + * but reuse of the same glTF material may require multiple threejs materials + * to accommodate different primitive types, defines, etc. New materials will + * be created if necessary, and reused from a cache. + * @param {Object3D} mesh Mesh, Line, or Points instance. + */ + assignFinalMaterial( mesh ) { + + const geometry = mesh.geometry; + let material = mesh.material; + + const useDerivativeTangents = geometry.attributes.tangent === undefined; + const useVertexColors = geometry.attributes.color !== undefined; + const useFlatShading = geometry.attributes.normal === undefined; + + if ( mesh.isPoints ) { + + const cacheKey = 'PointsMaterial:' + material.uuid; + + let pointsMaterial = this.cache.get( cacheKey ); + + if ( ! pointsMaterial ) { + + pointsMaterial = new PointsMaterial(); + Material.prototype.copy.call( pointsMaterial, material ); + pointsMaterial.color.copy( material.color ); + pointsMaterial.map = material.map; + pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px + + this.cache.add( cacheKey, pointsMaterial ); + + } + + material = pointsMaterial; + + } else if ( mesh.isLine ) { + + const cacheKey = 'LineBasicMaterial:' + material.uuid; + + let lineMaterial = this.cache.get( cacheKey ); + + if ( ! lineMaterial ) { + + lineMaterial = new LineBasicMaterial(); + Material.prototype.copy.call( lineMaterial, material ); + lineMaterial.color.copy( material.color ); + lineMaterial.map = material.map; + + this.cache.add( cacheKey, lineMaterial ); + + } + + material = lineMaterial; + + } + + // Clone the material if it will be modified + if ( useDerivativeTangents || useVertexColors || useFlatShading ) { + + let cacheKey = 'ClonedMaterial:' + material.uuid + ':'; + + if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:'; + if ( useVertexColors ) cacheKey += 'vertex-colors:'; + if ( useFlatShading ) cacheKey += 'flat-shading:'; + + let cachedMaterial = this.cache.get( cacheKey ); + + if ( ! cachedMaterial ) { + + cachedMaterial = material.clone(); + + if ( useVertexColors ) cachedMaterial.vertexColors = true; + if ( useFlatShading ) cachedMaterial.flatShading = true; + + if ( useDerivativeTangents ) { + + // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995 + if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1; + if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= - 1; + + } + + this.cache.add( cacheKey, cachedMaterial ); + + this.associations.set( cachedMaterial, this.associations.get( material ) ); + + } + + material = cachedMaterial; + + } + + mesh.material = material; + + } + + getMaterialType( /* materialIndex */ ) { + + return MeshStandardMaterial; + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials + * @param {number} materialIndex + * @return {Promise} + */ + loadMaterial( materialIndex ) { + + const parser = this; + const json = this.json; + const extensions = this.extensions; + const materialDef = json.materials[ materialIndex ]; + + let materialType; + const materialParams = {}; + const materialExtensions = materialDef.extensions || {}; + + const pending = []; + + if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) { + + const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ]; + materialType = kmuExtension.getMaterialType(); + pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) ); + + } else { + + // Specification: + // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material + + const metallicRoughness = materialDef.pbrMetallicRoughness || {}; + + materialParams.color = new Color( 1.0, 1.0, 1.0 ); + materialParams.opacity = 1.0; + + if ( Array.isArray( metallicRoughness.baseColorFactor ) ) { + + const array = metallicRoughness.baseColorFactor; + + materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace ); + materialParams.opacity = array[ 3 ]; + + } + + if ( metallicRoughness.baseColorTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) ); + + } + + materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0; + materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0; + + if ( metallicRoughness.metallicRoughnessTexture !== undefined ) { + + pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) ); + pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) ); + + } + + materialType = this._invokeOne( function ( ext ) { + + return ext.getMaterialType && ext.getMaterialType( materialIndex ); + + } ); + + pending.push( Promise.all( this._invokeAll( function ( ext ) { + + return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams ); + + } ) ) ); + + } + + if ( materialDef.doubleSided === true ) { + + materialParams.side = DoubleSide; + + } + + const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE; + + if ( alphaMode === ALPHA_MODES.BLEND ) { + + materialParams.transparent = true; + + // See: https://github.com/mrdoob/three.js/issues/17706 + materialParams.depthWrite = false; + + } else { + + materialParams.transparent = false; + + if ( alphaMode === ALPHA_MODES.MASK ) { + + materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5; + + } + + } + + if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) { + + pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) ); + + materialParams.normalScale = new Vector2( 1, 1 ); + + if ( materialDef.normalTexture.scale !== undefined ) { + + const scale = materialDef.normalTexture.scale; + + materialParams.normalScale.set( scale, scale ); + + } + + } + + if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) { + + pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) ); + + if ( materialDef.occlusionTexture.strength !== undefined ) { + + materialParams.aoMapIntensity = materialDef.occlusionTexture.strength; + + } + + } + + if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) { + + const emissiveFactor = materialDef.emissiveFactor; + materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace ); + + } + + if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) { + + pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, SRGBColorSpace ) ); + + } + + return Promise.all( pending ).then( function () { + + const material = new materialType( materialParams ); + + if ( materialDef.name ) material.name = materialDef.name; + + assignExtrasToUserData( material, materialDef ); + + parser.associations.set( material, { materials: materialIndex } ); + + if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef ); + + return material; + + } ); + + } + + /** When Object3D instances are targeted by animation, they need unique names. */ + createUniqueName( originalName ) { + + const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' ); + + if ( sanitizedName in this.nodeNamesUsed ) { + + return sanitizedName + '_' + ( ++ this.nodeNamesUsed[ sanitizedName ] ); + + } else { + + this.nodeNamesUsed[ sanitizedName ] = 0; + + return sanitizedName; + + } + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry + * + * Creates BufferGeometries from primitives. + * + * @param {Array} primitives + * @return {Promise>} + */ + loadGeometries( primitives ) { + + const parser = this; + const extensions = this.extensions; + const cache = this.primitiveCache; + + function createDracoPrimitive( primitive ) { + + return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] + .decodePrimitive( primitive, parser ) + .then( function ( geometry ) { + + return addPrimitiveAttributes( geometry, primitive, parser ); + + } ); + + } + + const pending = []; + + for ( let i = 0, il = primitives.length; i < il; i ++ ) { + + const primitive = primitives[ i ]; + const cacheKey = createPrimitiveKey( primitive ); + + // See if we've already created this geometry + const cached = cache[ cacheKey ]; + + if ( cached ) { + + // Use the cached geometry if it exists + pending.push( cached.promise ); + + } else { + + let geometryPromise; + + if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) { + + // Use DRACO geometry if available + geometryPromise = createDracoPrimitive( primitive ); + + } else { + + // Otherwise create a new geometry + geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser ); + + } + + // Cache this geometry + cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise }; + + pending.push( geometryPromise ); + + } + + } + + return Promise.all( pending ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes + * @param {number} meshIndex + * @return {Promise} + */ + loadMesh( meshIndex ) { + + const parser = this; + const json = this.json; + const extensions = this.extensions; + + const meshDef = json.meshes[ meshIndex ]; + const primitives = meshDef.primitives; + + const pending = []; + + for ( let i = 0, il = primitives.length; i < il; i ++ ) { + + const material = primitives[ i ].material === undefined + ? createDefaultMaterial( this.cache ) + : this.getDependency( 'material', primitives[ i ].material ); + + pending.push( material ); + + } + + pending.push( parser.loadGeometries( primitives ) ); + + return Promise.all( pending ).then( function ( results ) { + + const materials = results.slice( 0, results.length - 1 ); + const geometries = results[ results.length - 1 ]; + + const meshes = []; + + for ( let i = 0, il = geometries.length; i < il; i ++ ) { + + const geometry = geometries[ i ]; + const primitive = primitives[ i ]; + + // 1. create Mesh + + let mesh; + + const material = materials[ i ]; + + if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES || + primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || + primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || + primitive.mode === undefined ) { + + // .isSkinnedMesh isn't in glTF spec. See ._markDefs() + mesh = meshDef.isSkinnedMesh === true + ? new SkinnedMesh( geometry, material ) + : new Mesh( geometry, material ); + + if ( mesh.isSkinnedMesh === true ) { + + // normalize skin weights to fix malformed assets (see #15319) + mesh.normalizeSkinWeights(); + + } + + if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) { + + mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode ); + + } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) { + + mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode ); + + } + + } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) { + + mesh = new LineSegments( geometry, material ); + + } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) { + + mesh = new Line( geometry, material ); + + } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) { + + mesh = new LineLoop( geometry, material ); + + } else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) { + + mesh = new Points( geometry, material ); + + } else { + + throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode ); + + } + + if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) { + + updateMorphTargets( mesh, meshDef ); + + } + + mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) ); + + assignExtrasToUserData( mesh, meshDef ); + + if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive ); + + parser.assignFinalMaterial( mesh ); + + meshes.push( mesh ); + + } + + for ( let i = 0, il = meshes.length; i < il; i ++ ) { + + parser.associations.set( meshes[ i ], { + meshes: meshIndex, + primitives: i + } ); + + } + + if ( meshes.length === 1 ) { + + if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, meshes[ 0 ], meshDef ); + + return meshes[ 0 ]; + + } + + const group = new Group(); + + if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, group, meshDef ); + + parser.associations.set( group, { meshes: meshIndex } ); + + for ( let i = 0, il = meshes.length; i < il; i ++ ) { + + group.add( meshes[ i ] ); + + } + + return group; + + } ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras + * @param {number} cameraIndex + * @return {Promise} + */ + loadCamera( cameraIndex ) { + + let camera; + const cameraDef = this.json.cameras[ cameraIndex ]; + const params = cameraDef[ cameraDef.type ]; + + if ( ! params ) { + + console.warn( 'THREE.GLTFLoader: Missing camera parameters.' ); + return; + + } + + if ( cameraDef.type === 'perspective' ) { + + camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 ); + + } else if ( cameraDef.type === 'orthographic' ) { + + camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar ); + + } + + if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name ); + + assignExtrasToUserData( camera, cameraDef ); + + return Promise.resolve( camera ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins + * @param {number} skinIndex + * @return {Promise} + */ + loadSkin( skinIndex ) { + + const skinDef = this.json.skins[ skinIndex ]; + + const pending = []; + + for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) { + + pending.push( this._loadNodeShallow( skinDef.joints[ i ] ) ); + + } + + if ( skinDef.inverseBindMatrices !== undefined ) { + + pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) ); + + } else { + + pending.push( null ); + + } + + return Promise.all( pending ).then( function ( results ) { + + const inverseBindMatrices = results.pop(); + const jointNodes = results; + + // Note that bones (joint nodes) may or may not be in the + // scene graph at this time. + + const bones = []; + const boneInverses = []; + + for ( let i = 0, il = jointNodes.length; i < il; i ++ ) { + + const jointNode = jointNodes[ i ]; + + if ( jointNode ) { + + bones.push( jointNode ); + + const mat = new Matrix4(); + + if ( inverseBindMatrices !== null ) { + + mat.fromArray( inverseBindMatrices.array, i * 16 ); + + } + + boneInverses.push( mat ); + + } else { + + console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] ); + + } + + } + + return new Skeleton( bones, boneInverses ); + + } ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations + * @param {number} animationIndex + * @return {Promise} + */ + loadAnimation( animationIndex ) { + + const json = this.json; + const parser = this; + + const animationDef = json.animations[ animationIndex ]; + const animationName = animationDef.name ? animationDef.name : 'animation_' + animationIndex; + + const pendingNodes = []; + const pendingInputAccessors = []; + const pendingOutputAccessors = []; + const pendingSamplers = []; + const pendingTargets = []; + + for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) { + + const channel = animationDef.channels[ i ]; + const sampler = animationDef.samplers[ channel.sampler ]; + const target = channel.target; + const name = target.node; + const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input; + const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output; + + if ( target.node === undefined ) continue; + + pendingNodes.push( this.getDependency( 'node', name ) ); + pendingInputAccessors.push( this.getDependency( 'accessor', input ) ); + pendingOutputAccessors.push( this.getDependency( 'accessor', output ) ); + pendingSamplers.push( sampler ); + pendingTargets.push( target ); + + } + + return Promise.all( [ + + Promise.all( pendingNodes ), + Promise.all( pendingInputAccessors ), + Promise.all( pendingOutputAccessors ), + Promise.all( pendingSamplers ), + Promise.all( pendingTargets ) + + ] ).then( function ( dependencies ) { + + const nodes = dependencies[ 0 ]; + const inputAccessors = dependencies[ 1 ]; + const outputAccessors = dependencies[ 2 ]; + const samplers = dependencies[ 3 ]; + const targets = dependencies[ 4 ]; + + const tracks = []; + + for ( let i = 0, il = nodes.length; i < il; i ++ ) { + + const node = nodes[ i ]; + const inputAccessor = inputAccessors[ i ]; + const outputAccessor = outputAccessors[ i ]; + const sampler = samplers[ i ]; + const target = targets[ i ]; + + if ( node === undefined ) continue; + + if ( node.updateMatrix ) { + + node.updateMatrix(); + + } + + const createdTracks = parser._createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ); + + if ( createdTracks ) { + + for ( let k = 0; k < createdTracks.length; k ++ ) { + + tracks.push( createdTracks[ k ] ); + + } + + } + + } + + return new AnimationClip( animationName, undefined, tracks ); + + } ); + + } + + createNodeMesh( nodeIndex ) { + + const json = this.json; + const parser = this; + const nodeDef = json.nodes[ nodeIndex ]; + + if ( nodeDef.mesh === undefined ) return null; + + return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) { + + const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh ); + + // if weights are provided on the node, override weights on the mesh. + if ( nodeDef.weights !== undefined ) { + + node.traverse( function ( o ) { + + if ( ! o.isMesh ) return; + + for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) { + + o.morphTargetInfluences[ i ] = nodeDef.weights[ i ]; + + } + + } ); + + } + + return node; + + } ); + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy + * @param {number} nodeIndex + * @return {Promise} + */ + loadNode( nodeIndex ) { + + const json = this.json; + const parser = this; + + const nodeDef = json.nodes[ nodeIndex ]; + + const nodePending = parser._loadNodeShallow( nodeIndex ); + + const childPending = []; + const childrenDef = nodeDef.children || []; + + for ( let i = 0, il = childrenDef.length; i < il; i ++ ) { + + childPending.push( parser.getDependency( 'node', childrenDef[ i ] ) ); + + } + + const skeletonPending = nodeDef.skin === undefined + ? Promise.resolve( null ) + : parser.getDependency( 'skin', nodeDef.skin ); + + return Promise.all( [ + nodePending, + Promise.all( childPending ), + skeletonPending + ] ).then( function ( results ) { + + const node = results[ 0 ]; + const children = results[ 1 ]; + const skeleton = results[ 2 ]; + + if ( skeleton !== null ) { + + // This full traverse should be fine because + // child glTF nodes have not been added to this node yet. + node.traverse( function ( mesh ) { + + if ( ! mesh.isSkinnedMesh ) return; + + mesh.bind( skeleton, _identityMatrix ); + + } ); + + } + + for ( let i = 0, il = children.length; i < il; i ++ ) { + + node.add( children[ i ] ); + + } + + return node; + + } ); + + } + + // ._loadNodeShallow() parses a single node. + // skin and child nodes are created and added in .loadNode() (no '_' prefix). + _loadNodeShallow( nodeIndex ) { + + const json = this.json; + const extensions = this.extensions; + const parser = this; + + // This method is called from .loadNode() and .loadSkin(). + // Cache a node to avoid duplication. + + if ( this.nodeCache[ nodeIndex ] !== undefined ) { + + return this.nodeCache[ nodeIndex ]; + + } + + const nodeDef = json.nodes[ nodeIndex ]; + + // reserve node's name before its dependencies, so the root has the intended name. + const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : ''; + + const pending = []; + + const meshPromise = parser._invokeOne( function ( ext ) { + + return ext.createNodeMesh && ext.createNodeMesh( nodeIndex ); + + } ); + + if ( meshPromise ) { + + pending.push( meshPromise ); + + } + + if ( nodeDef.camera !== undefined ) { + + pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) { + + return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera ); + + } ) ); + + } + + parser._invokeAll( function ( ext ) { + + return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex ); + + } ).forEach( function ( promise ) { + + pending.push( promise ); + + } ); + + this.nodeCache[ nodeIndex ] = Promise.all( pending ).then( function ( objects ) { + + let node; + + // .isBone isn't in glTF spec. See ._markDefs + if ( nodeDef.isBone === true ) { + + node = new Bone(); + + } else if ( objects.length > 1 ) { + + node = new Group(); + + } else if ( objects.length === 1 ) { + + node = objects[ 0 ]; + + } else { + + node = new Object3D(); + + } + + if ( node !== objects[ 0 ] ) { + + for ( let i = 0, il = objects.length; i < il; i ++ ) { + + node.add( objects[ i ] ); + + } + + } + + if ( nodeDef.name ) { + + node.userData.name = nodeDef.name; + node.name = nodeName; + + } + + assignExtrasToUserData( node, nodeDef ); + + if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef ); + + if ( nodeDef.matrix !== undefined ) { + + const matrix = new Matrix4(); + matrix.fromArray( nodeDef.matrix ); + node.applyMatrix4( matrix ); + + } else { + + if ( nodeDef.translation !== undefined ) { + + node.position.fromArray( nodeDef.translation ); + + } + + if ( nodeDef.rotation !== undefined ) { + + node.quaternion.fromArray( nodeDef.rotation ); + + } + + if ( nodeDef.scale !== undefined ) { + + node.scale.fromArray( nodeDef.scale ); + + } + + } + + if ( ! parser.associations.has( node ) ) { + + parser.associations.set( node, {} ); + + } + + parser.associations.get( node ).nodes = nodeIndex; + + return node; + + } ); + + return this.nodeCache[ nodeIndex ]; + + } + + /** + * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes + * @param {number} sceneIndex + * @return {Promise} + */ + loadScene( sceneIndex ) { + + const extensions = this.extensions; + const sceneDef = this.json.scenes[ sceneIndex ]; + const parser = this; + + // Loader returns Group, not Scene. + // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172 + const scene = new Group(); + if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name ); + + assignExtrasToUserData( scene, sceneDef ); + + if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef ); + + const nodeIds = sceneDef.nodes || []; + + const pending = []; + + for ( let i = 0, il = nodeIds.length; i < il; i ++ ) { + + pending.push( parser.getDependency( 'node', nodeIds[ i ] ) ); + + } + + return Promise.all( pending ).then( function ( nodes ) { + + for ( let i = 0, il = nodes.length; i < il; i ++ ) { + + scene.add( nodes[ i ] ); + + } + + // Removes dangling associations, associations that reference a node that + // didn't make it into the scene. + const reduceAssociations = ( node ) => { + + const reducedAssociations = new Map(); + + for ( const [ key, value ] of parser.associations ) { + + if ( key instanceof Material || key instanceof Texture ) { + + reducedAssociations.set( key, value ); + + } + + } + + node.traverse( ( node ) => { + + const mappings = parser.associations.get( node ); + + if ( mappings != null ) { + + reducedAssociations.set( node, mappings ); + + } + + } ); + + return reducedAssociations; + + }; + + parser.associations = reduceAssociations( scene ); + + return scene; + + } ); + + } + + _createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ) { + + const tracks = []; + + const targetName = node.name ? node.name : node.uuid; + const targetNames = []; + + if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) { + + node.traverse( function ( object ) { + + if ( object.morphTargetInfluences ) { + + targetNames.push( object.name ? object.name : object.uuid ); + + } + + } ); + + } else { + + targetNames.push( targetName ); + + } + + let TypedKeyframeTrack; + + switch ( PATH_PROPERTIES[ target.path ] ) { + + case PATH_PROPERTIES.weights: + + TypedKeyframeTrack = NumberKeyframeTrack; + break; + + case PATH_PROPERTIES.rotation: + + TypedKeyframeTrack = QuaternionKeyframeTrack; + break; + + case PATH_PROPERTIES.position: + case PATH_PROPERTIES.scale: + + TypedKeyframeTrack = VectorKeyframeTrack; + break; + + default: + + switch ( outputAccessor.itemSize ) { + + case 1: + TypedKeyframeTrack = NumberKeyframeTrack; + break; + case 2: + case 3: + default: + TypedKeyframeTrack = VectorKeyframeTrack; + break; + + } + + break; + + } + + const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear; + + + const outputArray = this._getArrayFromAccessor( outputAccessor ); + + for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) { + + const track = new TypedKeyframeTrack( + targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ], + inputAccessor.array, + outputArray, + interpolation + ); + + // Override interpolation with custom factory method. + if ( sampler.interpolation === 'CUBICSPLINE' ) { + + this._createCubicSplineTrackInterpolant( track ); + + } + + tracks.push( track ); + + } + + return tracks; + + } + + _getArrayFromAccessor( accessor ) { + + let outputArray = accessor.array; + + if ( accessor.normalized ) { + + const scale = getNormalizedComponentScale( outputArray.constructor ); + const scaled = new Float32Array( outputArray.length ); + + for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) { + + scaled[ j ] = outputArray[ j ] * scale; + + } + + outputArray = scaled; + + } + + return outputArray; + + } + + _createCubicSplineTrackInterpolant( track ) { + + track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) { + + // A CUBICSPLINE keyframe in glTF has three output values for each input value, + // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize() + // must be divided by three to get the interpolant's sampleSize argument. + + const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant; + + return new interpolantType( this.times, this.values, this.getValueSize() / 3, result ); + + }; + + // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants. + track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true; + + } + +} + +/** + * @param {BufferGeometry} geometry + * @param {GLTF.Primitive} primitiveDef + * @param {GLTFParser} parser + */ +function computeBounds( geometry, primitiveDef, parser ) { + + const attributes = primitiveDef.attributes; + + const box = new Box3(); + + if ( attributes.POSITION !== undefined ) { + + const accessor = parser.json.accessors[ attributes.POSITION ]; + + const min = accessor.min; + const max = accessor.max; + + // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement. + + if ( min !== undefined && max !== undefined ) { + + box.set( + new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ), + new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) + ); + + if ( accessor.normalized ) { + + const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] ); + box.min.multiplyScalar( boxScale ); + box.max.multiplyScalar( boxScale ); + + } + + } else { + + console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' ); + + return; + + } + + } else { + + return; + + } + + const targets = primitiveDef.targets; + + if ( targets !== undefined ) { + + const maxDisplacement = new Vector3(); + const vector = new Vector3(); + + for ( let i = 0, il = targets.length; i < il; i ++ ) { + + const target = targets[ i ]; + + if ( target.POSITION !== undefined ) { + + const accessor = parser.json.accessors[ target.POSITION ]; + const min = accessor.min; + const max = accessor.max; + + // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement. + + if ( min !== undefined && max !== undefined ) { + + // we need to get max of absolute components because target weight is [-1,1] + vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) ); + vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) ); + vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) ); + + + if ( accessor.normalized ) { + + const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] ); + vector.multiplyScalar( boxScale ); + + } + + // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative + // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets + // are used to implement key-frame animations and as such only two are active at a time - this results in very large + // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size. + maxDisplacement.max( vector ); + + } else { + + console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' ); + + } + + } + + } + + // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets. + box.expandByVector( maxDisplacement ); + + } + + geometry.boundingBox = box; + + const sphere = new Sphere(); + + box.getCenter( sphere.center ); + sphere.radius = box.min.distanceTo( box.max ) / 2; + + geometry.boundingSphere = sphere; + +} + +/** + * @param {BufferGeometry} geometry + * @param {GLTF.Primitive} primitiveDef + * @param {GLTFParser} parser + * @return {Promise} + */ +function addPrimitiveAttributes( geometry, primitiveDef, parser ) { + + const attributes = primitiveDef.attributes; + + const pending = []; + + function assignAttributeAccessor( accessorIndex, attributeName ) { + + return parser.getDependency( 'accessor', accessorIndex ) + .then( function ( accessor ) { + + geometry.setAttribute( attributeName, accessor ); + + } ); + + } + + for ( const gltfAttributeName in attributes ) { + + const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase(); + + // Skip attributes already provided by e.g. Draco extension. + if ( threeAttributeName in geometry.attributes ) continue; + + pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) ); + + } + + if ( primitiveDef.indices !== undefined && ! geometry.index ) { + + const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) { + + geometry.setIndex( accessor ); + + } ); + + pending.push( accessor ); + + } + + if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) { + + console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` ); + + } + + assignExtrasToUserData( geometry, primitiveDef ); + + computeBounds( geometry, primitiveDef, parser ); + + return Promise.all( pending ).then( function () { + + return primitiveDef.targets !== undefined + ? addMorphTargets( geometry, primitiveDef.targets, parser ) + : geometry; + + } ); + +} + +export { GLTFLoader }; diff --git a/libs/three.js/r171/examples/jsm/loaders/HDRCubeTextureLoader.js b/libs/three.js/r171/examples/jsm/loaders/HDRCubeTextureLoader.js new file mode 100644 index 000000000..771912500 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/loaders/HDRCubeTextureLoader.js @@ -0,0 +1,115 @@ +import { + CubeTexture, + DataTexture, + FileLoader, + FloatType, + HalfFloatType, + LinearFilter, + LinearSRGBColorSpace, + Loader +} from 'three'; +import { RGBELoader } from '../loaders/RGBELoader.js'; + +class HDRCubeTextureLoader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.hdrLoader = new RGBELoader(); + this.type = HalfFloatType; + + } + + load( urls, onLoad, onProgress, onError ) { + + const texture = new CubeTexture(); + + texture.type = this.type; + + switch ( texture.type ) { + + case FloatType: + + texture.colorSpace = LinearSRGBColorSpace; + texture.minFilter = LinearFilter; + texture.magFilter = LinearFilter; + texture.generateMipmaps = false; + break; + + case HalfFloatType: + + texture.colorSpace = LinearSRGBColorSpace; + texture.minFilter = LinearFilter; + texture.magFilter = LinearFilter; + texture.generateMipmaps = false; + break; + + } + + const scope = this; + + let loaded = 0; + + function loadHDRData( i, onLoad, onProgress, onError ) { + + new FileLoader( scope.manager ) + .setPath( scope.path ) + .setResponseType( 'arraybuffer' ) + .setWithCredentials( scope.withCredentials ) + .load( urls[ i ], function ( buffer ) { + + loaded ++; + + const texData = scope.hdrLoader.parse( buffer ); + + if ( ! texData ) return; + + if ( texData.data !== undefined ) { + + const dataTexture = new DataTexture( texData.data, texData.width, texData.height ); + + dataTexture.type = texture.type; + dataTexture.colorSpace = texture.colorSpace; + dataTexture.format = texture.format; + dataTexture.minFilter = texture.minFilter; + dataTexture.magFilter = texture.magFilter; + dataTexture.generateMipmaps = texture.generateMipmaps; + + texture.images[ i ] = dataTexture; + + } + + if ( loaded === 6 ) { + + texture.needsUpdate = true; + if ( onLoad ) onLoad( texture ); + + } + + }, onProgress, onError ); + + } + + for ( let i = 0; i < urls.length; i ++ ) { + + loadHDRData( i, onLoad, onProgress, onError ); + + } + + return texture; + + } + + setDataType( value ) { + + this.type = value; + this.hdrLoader.setDataType( value ); + + return this; + + } + +} + +export { HDRCubeTextureLoader }; diff --git a/libs/three.js/r171/examples/jsm/loaders/KTX2Loader.js b/libs/three.js/r171/examples/jsm/loaders/KTX2Loader.js new file mode 100644 index 000000000..d329cd753 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/loaders/KTX2Loader.js @@ -0,0 +1,1031 @@ +/** + * Loader for KTX 2.0 GPU Texture containers. + * + * KTX 2.0 is a container format for various GPU texture formats. The loader + * supports Basis Universal GPU textures, which can be quickly transcoded to + * a wide variety of GPU texture compression formats, as well as some + * uncompressed DataTexture and Data3DTexture formats. + * + * References: + * - KTX: http://github.khronos.org/KTX-Specification/ + * - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor + * - BasisU HDR: https://github.com/BinomialLLC/basis_universal/wiki/UASTC-HDR-Texture-Specification-v1.0 + */ + +import { + CompressedTexture, + CompressedArrayTexture, + CompressedCubeTexture, + Data3DTexture, + DataTexture, + FileLoader, + FloatType, + HalfFloatType, + NoColorSpace, + LinearFilter, + LinearMipmapLinearFilter, + LinearSRGBColorSpace, + Loader, + RedFormat, + RGB_BPTC_UNSIGNED_Format, + RGB_ETC1_Format, + RGB_ETC2_Format, + RGB_PVRTC_4BPPV1_Format, + RGBA_ASTC_4x4_Format, + RGBA_ASTC_6x6_Format, + RGBA_BPTC_Format, + RGBA_ETC2_EAC_Format, + RGBA_PVRTC_4BPPV1_Format, + RGBA_S3TC_DXT5_Format, + RGBA_S3TC_DXT1_Format, + RGBAFormat, + RGFormat, + SRGBColorSpace, + UnsignedByteType, +} from 'three'; +import { WorkerPool } from '../utils/WorkerPool.js'; +import { + read, + KHR_DF_FLAG_ALPHA_PREMULTIPLIED, + KHR_DF_TRANSFER_SRGB, + KHR_SUPERCOMPRESSION_NONE, + KHR_SUPERCOMPRESSION_ZSTD, + VK_FORMAT_UNDEFINED, + VK_FORMAT_R16_SFLOAT, + VK_FORMAT_R16G16_SFLOAT, + VK_FORMAT_R16G16B16A16_SFLOAT, + VK_FORMAT_R32_SFLOAT, + VK_FORMAT_R32G32_SFLOAT, + VK_FORMAT_R32G32B32A32_SFLOAT, + VK_FORMAT_R8_SRGB, + VK_FORMAT_R8_UNORM, + VK_FORMAT_R8G8_SRGB, + VK_FORMAT_R8G8_UNORM, + VK_FORMAT_R8G8B8A8_SRGB, + VK_FORMAT_R8G8B8A8_UNORM, + VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT, + VK_FORMAT_ASTC_6x6_SRGB_BLOCK, + VK_FORMAT_ASTC_6x6_UNORM_BLOCK, + KHR_DF_PRIMARIES_UNSPECIFIED, + KHR_DF_PRIMARIES_BT709, + KHR_DF_PRIMARIES_DISPLAYP3 +} from '../libs/ktx-parse.module.js'; +import { ZSTDDecoder } from '../libs/zstddec.module.js'; +import { DisplayP3ColorSpace, LinearDisplayP3ColorSpace } from '../math/ColorSpaces.js'; + +const _taskCache = new WeakMap(); + +let _activeLoaders = 0; + +let _zstd; + +class KTX2Loader extends Loader { + + constructor( manager ) { + + super( manager ); + + this.transcoderPath = ''; + this.transcoderBinary = null; + this.transcoderPending = null; + + this.workerPool = new WorkerPool(); + this.workerSourceURL = ''; + this.workerConfig = null; + + if ( typeof MSC_TRANSCODER !== 'undefined' ) { + + console.warn( + + 'THREE.KTX2Loader: Please update to latest "basis_transcoder".' + + ' "msc_basis_transcoder" is no longer supported in three.js r125+.' + + ); + + } + + } + + setTranscoderPath( path ) { + + this.transcoderPath = path; + + return this; + + } + + setWorkerLimit( num ) { + + this.workerPool.setWorkerLimit( num ); + + return this; + + } + + async detectSupportAsync( renderer ) { + + this.workerConfig = { + astcSupported: await renderer.hasFeatureAsync( 'texture-compression-astc' ), + astcHDRSupported: false, // https://github.com/gpuweb/gpuweb/issues/3856 + etc1Supported: await renderer.hasFeatureAsync( 'texture-compression-etc1' ), + etc2Supported: await renderer.hasFeatureAsync( 'texture-compression-etc2' ), + dxtSupported: await renderer.hasFeatureAsync( 'texture-compression-bc' ), + bptcSupported: await renderer.hasFeatureAsync( 'texture-compression-bptc' ), + pvrtcSupported: await renderer.hasFeatureAsync( 'texture-compression-pvrtc' ) + }; + + return this; + + } + + detectSupport( renderer ) { + + if ( renderer.isWebGPURenderer === true ) { + + this.workerConfig = { + astcSupported: renderer.hasFeature( 'texture-compression-astc' ), + astcHDRSupported: false, // https://github.com/gpuweb/gpuweb/issues/3856 + etc1Supported: renderer.hasFeature( 'texture-compression-etc1' ), + etc2Supported: renderer.hasFeature( 'texture-compression-etc2' ), + dxtSupported: renderer.hasFeature( 'texture-compression-bc' ), + bptcSupported: renderer.hasFeature( 'texture-compression-bptc' ), + pvrtcSupported: renderer.hasFeature( 'texture-compression-pvrtc' ) + }; + + } else { + + this.workerConfig = { + astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ), + astcHDRSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ) + && renderer.extensions.get( 'WEBGL_compressed_texture_astc' ).getSupportedProfiles().includes( 'hdr' ), + etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ), + etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ), + dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ), + bptcSupported: renderer.extensions.has( 'EXT_texture_compression_bptc' ), + pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' ) + || renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' ) + }; + + } + + return this; + + } + + init() { + + if ( ! this.transcoderPending ) { + + // Load transcoder wrapper. + const jsLoader = new FileLoader( this.manager ); + jsLoader.setPath( this.transcoderPath ); + jsLoader.setWithCredentials( this.withCredentials ); + const jsContent = jsLoader.loadAsync( 'basis_transcoder.js' ); + + // Load transcoder WASM binary. + const binaryLoader = new FileLoader( this.manager ); + binaryLoader.setPath( this.transcoderPath ); + binaryLoader.setResponseType( 'arraybuffer' ); + binaryLoader.setWithCredentials( this.withCredentials ); + const binaryContent = binaryLoader.loadAsync( 'basis_transcoder.wasm' ); + + this.transcoderPending = Promise.all( [ jsContent, binaryContent ] ) + .then( ( [ jsContent, binaryContent ] ) => { + + const fn = KTX2Loader.BasisWorker.toString(); + + const body = [ + '/* constants */', + 'let _EngineFormat = ' + JSON.stringify( KTX2Loader.EngineFormat ), + 'let _EngineType = ' + JSON.stringify( KTX2Loader.EngineType ), + 'let _TranscoderFormat = ' + JSON.stringify( KTX2Loader.TranscoderFormat ), + 'let _BasisFormat = ' + JSON.stringify( KTX2Loader.BasisFormat ), + '/* basis_transcoder.js */', + jsContent, + '/* worker */', + fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) + ].join( '\n' ); + + this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) ); + this.transcoderBinary = binaryContent; + + this.workerPool.setWorkerCreator( () => { + + const worker = new Worker( this.workerSourceURL ); + const transcoderBinary = this.transcoderBinary.slice( 0 ); + + worker.postMessage( { type: 'init', config: this.workerConfig, transcoderBinary }, [ transcoderBinary ] ); + + return worker; + + } ); + + } ); + + if ( _activeLoaders > 0 ) { + + // Each instance loads a transcoder and allocates workers, increasing network and memory cost. + + console.warn( + + 'THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.' + + ' Use a single KTX2Loader instance, or call .dispose() on old instances.' + + ); + + } + + _activeLoaders ++; + + } + + return this.transcoderPending; + + } + + load( url, onLoad, onProgress, onError ) { + + if ( this.workerConfig === null ) { + + throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' ); + + } + + const loader = new FileLoader( this.manager ); + + loader.setResponseType( 'arraybuffer' ); + loader.setWithCredentials( this.withCredentials ); + + loader.load( url, ( buffer ) => { + + this.parse( buffer, onLoad, onError ); + + }, onProgress, onError ); + + } + + parse( buffer, onLoad, onError ) { + + if ( this.workerConfig === null ) { + + throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' ); + + } + + // Check for an existing task using this buffer. A transferred buffer cannot be transferred + // again from this thread. + if ( _taskCache.has( buffer ) ) { + + const cachedTask = _taskCache.get( buffer ); + + return cachedTask.promise.then( onLoad ).catch( onError ); + + } + + this._createTexture( buffer ) + .then( ( texture ) => onLoad ? onLoad( texture ) : null ) + .catch( onError ); + + } + + _createTextureFrom( transcodeResult, container ) { + + const { type: messageType, error, data: { faces, width, height, format, type, dfdFlags } } = transcodeResult; + + if ( messageType === 'error' ) return Promise.reject( error ); + + let texture; + + if ( container.faceCount === 6 ) { + + texture = new CompressedCubeTexture( faces, format, type ); + + } else { + + const mipmaps = faces[ 0 ].mipmaps; + + texture = container.layerCount > 1 + ? new CompressedArrayTexture( mipmaps, width, height, container.layerCount, format, type ) + : new CompressedTexture( mipmaps, width, height, format, type ); + + } + + texture.minFilter = faces[ 0 ].mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter; + texture.magFilter = LinearFilter; + texture.generateMipmaps = false; + + texture.needsUpdate = true; + texture.colorSpace = parseColorSpace( container ); + texture.premultiplyAlpha = !! ( dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED ); + + return texture; + + } + + /** + * @param {ArrayBuffer} buffer + * @param {object?} config + * @return {Promise} + */ + async _createTexture( buffer, config = {} ) { + + const container = read( new Uint8Array( buffer ) ); + + // Basis UASTC HDR is a subset of ASTC, which can be transcoded efficiently + // to BC6H. To detect whether a KTX2 file uses Basis UASTC HDR, or default + // ASTC, inspect the DFD color model. + // + // Source: https://github.com/BinomialLLC/basis_universal/issues/381 + const isBasisHDR = container.vkFormat === VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT + && container.dataFormatDescriptor[ 0 ].colorModel === 0xA7; + + // If the device supports ASTC, Basis UASTC HDR requires no transcoder. + const needsTranscoder = container.vkFormat === VK_FORMAT_UNDEFINED + || isBasisHDR && ! this.workerConfig.astcHDRSupported; + + if ( ! needsTranscoder ) { + + return createRawTexture( container ); + + } + + // + const taskConfig = config; + const texturePending = this.init().then( () => { + + return this.workerPool.postMessage( { type: 'transcode', buffer, taskConfig: taskConfig }, [ buffer ] ); + + } ).then( ( e ) => this._createTextureFrom( e.data, container ) ); + + // Cache the task result. + _taskCache.set( buffer, { promise: texturePending } ); + + return texturePending; + + } + + dispose() { + + this.workerPool.dispose(); + if ( this.workerSourceURL ) URL.revokeObjectURL( this.workerSourceURL ); + + _activeLoaders --; + + return this; + + } + +} + + +/* CONSTANTS */ + +KTX2Loader.BasisFormat = { + ETC1S: 0, + UASTC: 1, + UASTC_HDR: 2, +}; + +// Source: https://github.com/BinomialLLC/basis_universal/blob/master/webgl/texture_test/index.html +KTX2Loader.TranscoderFormat = { + ETC1: 0, + ETC2: 1, + BC1: 2, + BC3: 3, + BC4: 4, + BC5: 5, + BC7_M6_OPAQUE_ONLY: 6, + BC7_M5: 7, + PVRTC1_4_RGB: 8, + PVRTC1_4_RGBA: 9, + ASTC_4x4: 10, + ATC_RGB: 11, + ATC_RGBA_INTERPOLATED_ALPHA: 12, + RGBA32: 13, + RGB565: 14, + BGR565: 15, + RGBA4444: 16, + BC6H: 22, + RGB_HALF: 24, + RGBA_HALF: 25, +}; + +KTX2Loader.EngineFormat = { + RGBAFormat: RGBAFormat, + RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format, + RGB_BPTC_UNSIGNED_Format: RGB_BPTC_UNSIGNED_Format, + RGBA_BPTC_Format: RGBA_BPTC_Format, + RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format, + RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format, + RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format, + RGB_ETC1_Format: RGB_ETC1_Format, + RGB_ETC2_Format: RGB_ETC2_Format, + RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format, + RGBA_S3TC_DXT1_Format: RGBA_S3TC_DXT1_Format, +}; + +KTX2Loader.EngineType = { + UnsignedByteType: UnsignedByteType, + HalfFloatType: HalfFloatType, + FloatType: FloatType, +}; + +/* WEB WORKER */ + +KTX2Loader.BasisWorker = function () { + + let config; + let transcoderPending; + let BasisModule; + + const EngineFormat = _EngineFormat; // eslint-disable-line no-undef + const EngineType = _EngineType; // eslint-disable-line no-undef + const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef + const BasisFormat = _BasisFormat; // eslint-disable-line no-undef + + self.addEventListener( 'message', function ( e ) { + + const message = e.data; + + switch ( message.type ) { + + case 'init': + config = message.config; + init( message.transcoderBinary ); + break; + + case 'transcode': + transcoderPending.then( () => { + + try { + + const { faces, buffers, width, height, hasAlpha, format, type, dfdFlags } = transcode( message.buffer ); + + self.postMessage( { type: 'transcode', id: message.id, data: { faces, width, height, hasAlpha, format, type, dfdFlags } }, buffers ); + + } catch ( error ) { + + console.error( error ); + + self.postMessage( { type: 'error', id: message.id, error: error.message } ); + + } + + } ); + break; + + } + + } ); + + function init( wasmBinary ) { + + transcoderPending = new Promise( ( resolve ) => { + + BasisModule = { wasmBinary, onRuntimeInitialized: resolve }; + BASIS( BasisModule ); // eslint-disable-line no-undef + + } ).then( () => { + + BasisModule.initializeBasis(); + + if ( BasisModule.KTX2File === undefined ) { + + console.warn( 'THREE.KTX2Loader: Please update Basis Universal transcoder.' ); + + } + + } ); + + } + + function transcode( buffer ) { + + const ktx2File = new BasisModule.KTX2File( new Uint8Array( buffer ) ); + + function cleanup() { + + ktx2File.close(); + ktx2File.delete(); + + } + + if ( ! ktx2File.isValid() ) { + + cleanup(); + throw new Error( 'THREE.KTX2Loader: Invalid or unsupported .ktx2 file' ); + + } + + let basisFormat; + + if ( ktx2File.isUASTC() ) { + + basisFormat = BasisFormat.UASTC; + + } else if ( ktx2File.isETC1S() ) { + + basisFormat = BasisFormat.ETC1S; + + } else if ( ktx2File.isHDR() ) { + + basisFormat = BasisFormat.UASTC_HDR; + + } else { + + throw new Error( 'THREE.KTX2Loader: Unknown Basis encoding' ); + + } + + const width = ktx2File.getWidth(); + const height = ktx2File.getHeight(); + const layerCount = ktx2File.getLayers() || 1; + const levelCount = ktx2File.getLevels(); + const faceCount = ktx2File.getFaces(); + const hasAlpha = ktx2File.getHasAlpha(); + const dfdFlags = ktx2File.getDFDFlags(); + + const { transcoderFormat, engineFormat, engineType } = getTranscoderFormat( basisFormat, width, height, hasAlpha ); + + if ( ! width || ! height || ! levelCount ) { + + cleanup(); + throw new Error( 'THREE.KTX2Loader: Invalid texture' ); + + } + + if ( ! ktx2File.startTranscoding() ) { + + cleanup(); + throw new Error( 'THREE.KTX2Loader: .startTranscoding failed' ); + + } + + const faces = []; + const buffers = []; + + for ( let face = 0; face < faceCount; face ++ ) { + + const mipmaps = []; + + for ( let mip = 0; mip < levelCount; mip ++ ) { + + const layerMips = []; + + let mipWidth, mipHeight; + + for ( let layer = 0; layer < layerCount; layer ++ ) { + + const levelInfo = ktx2File.getImageLevelInfo( mip, layer, face ); + + if ( face === 0 && mip === 0 && layer === 0 && ( levelInfo.origWidth % 4 !== 0 || levelInfo.origHeight % 4 !== 0 ) ) { + + console.warn( 'THREE.KTX2Loader: ETC1S and UASTC textures should use multiple-of-four dimensions.' ); + + } + + if ( levelCount > 1 ) { + + mipWidth = levelInfo.origWidth; + mipHeight = levelInfo.origHeight; + + } else { + + // Handles non-multiple-of-four dimensions in textures without mipmaps. Textures with + // mipmaps must use multiple-of-four dimensions, for some texture formats and APIs. + // See mrdoob/three.js#25908. + mipWidth = levelInfo.width; + mipHeight = levelInfo.height; + + } + + let dst = new Uint8Array( ktx2File.getImageTranscodedSizeInBytes( mip, layer, 0, transcoderFormat ) ); + const status = ktx2File.transcodeImage( dst, mip, layer, face, transcoderFormat, 0, - 1, - 1 ); + + if ( engineType === EngineType.HalfFloatType ) { + + dst = new Uint16Array( dst.buffer, dst.byteOffset, dst.byteLength / Uint16Array.BYTES_PER_ELEMENT ); + + } + + if ( ! status ) { + + cleanup(); + throw new Error( 'THREE.KTX2Loader: .transcodeImage failed.' ); + + } + + layerMips.push( dst ); + + } + + const mipData = concat( layerMips ); + + mipmaps.push( { data: mipData, width: mipWidth, height: mipHeight } ); + buffers.push( mipData.buffer ); + + } + + faces.push( { mipmaps, width, height, format: engineFormat, type: engineType } ); + + } + + cleanup(); + + return { faces, buffers, width, height, hasAlpha, dfdFlags, format: engineFormat, type: engineType }; + + } + + // + + // Optimal choice of a transcoder target format depends on the Basis format (ETC1S, UASTC, or + // UASTC HDR), device capabilities, and texture dimensions. The list below ranks the formats + // separately for each format. Currently, priority is assigned based on: + // + // high quality > low quality > uncompressed + // + // Prioritization may be revisited, or exposed for configuration, in the future. + // + // Reference: https://github.com/KhronosGroup/3D-Formats-Guidelines/blob/main/KTXDeveloperGuide.md + const FORMAT_OPTIONS = [ + { + if: 'astcSupported', + basisFormat: [ BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ], + engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ], + engineType: [ EngineType.UnsignedByteType ], + priorityETC1S: Infinity, + priorityUASTC: 1, + needsPowerOfTwo: false, + }, + { + if: 'bptcSupported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ], + engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ], + engineType: [ EngineType.UnsignedByteType ], + priorityETC1S: 3, + priorityUASTC: 2, + needsPowerOfTwo: false, + }, + { + if: 'dxtSupported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ], + engineFormat: [ EngineFormat.RGBA_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ], + engineType: [ EngineType.UnsignedByteType ], + priorityETC1S: 4, + priorityUASTC: 5, + needsPowerOfTwo: false, + }, + { + if: 'etc2Supported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ], + engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ], + engineType: [ EngineType.UnsignedByteType ], + priorityETC1S: 1, + priorityUASTC: 3, + needsPowerOfTwo: false, + }, + { + if: 'etc1Supported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.ETC1 ], + engineFormat: [ EngineFormat.RGB_ETC1_Format ], + engineType: [ EngineType.UnsignedByteType ], + priorityETC1S: 2, + priorityUASTC: 4, + needsPowerOfTwo: false, + }, + { + if: 'pvrtcSupported', + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ], + engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ], + engineType: [ EngineType.UnsignedByteType ], + priorityETC1S: 5, + priorityUASTC: 6, + needsPowerOfTwo: true, + }, + { + if: 'bptcSupported', + basisFormat: [ BasisFormat.UASTC_HDR ], + transcoderFormat: [ TranscoderFormat.BC6H ], + engineFormat: [ EngineFormat.RGB_BPTC_UNSIGNED_Format ], + engineType: [ EngineType.HalfFloatType ], + priorityHDR: 1, + needsPowerOfTwo: false, + }, + + // Uncompressed fallbacks. + + { + basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC ], + transcoderFormat: [ TranscoderFormat.RGBA32, TranscoderFormat.RGBA32 ], + engineFormat: [ EngineFormat.RGBAFormat, EngineFormat.RGBAFormat ], + engineType: [ EngineType.UnsignedByteType, EngineType.UnsignedByteType ], + priorityETC1S: 100, + priorityUASTC: 100, + needsPowerOfTwo: false, + }, + { + basisFormat: [ BasisFormat.UASTC_HDR ], + transcoderFormat: [ TranscoderFormat.RGBA_HALF ], + engineFormat: [ EngineFormat.RGBAFormat ], + engineType: [ EngineType.HalfFloatType ], + priorityHDR: 100, + needsPowerOfTwo: false, + } + ]; + + const OPTIONS = { + // TODO: For ETC1S we intentionally sort by _UASTC_ priority, preserving + // a historical accident shown to avoid performance pitfalls for Linux with + // Firefox & AMD GPU (RadeonSI). Further work needed. + // See https://github.com/mrdoob/three.js/pull/29730. + [ BasisFormat.ETC1S ]: FORMAT_OPTIONS + .filter( ( opt ) => opt.basisFormat.includes( BasisFormat.ETC1S ) ) + .sort( ( a, b ) => a.priorityUASTC - b.priorityUASTC ), + + [ BasisFormat.UASTC ]: FORMAT_OPTIONS + .filter( ( opt ) => opt.basisFormat.includes( BasisFormat.UASTC ) ) + .sort( ( a, b ) => a.priorityUASTC - b.priorityUASTC ), + + [ BasisFormat.UASTC_HDR ]: FORMAT_OPTIONS + .filter( ( opt ) => opt.basisFormat.includes( BasisFormat.UASTC_HDR ) ) + .sort( ( a, b ) => a.priorityHDR - b.priorityHDR ), + }; + + function getTranscoderFormat( basisFormat, width, height, hasAlpha ) { + + const options = OPTIONS[ basisFormat ]; + + for ( let i = 0; i < options.length; i ++ ) { + + const opt = options[ i ]; + + if ( opt.if && ! config[ opt.if ] ) continue; + if ( ! opt.basisFormat.includes( basisFormat ) ) continue; + if ( hasAlpha && opt.transcoderFormat.length < 2 ) continue; + if ( opt.needsPowerOfTwo && ! ( isPowerOfTwo( width ) && isPowerOfTwo( height ) ) ) continue; + + const transcoderFormat = opt.transcoderFormat[ hasAlpha ? 1 : 0 ]; + const engineFormat = opt.engineFormat[ hasAlpha ? 1 : 0 ]; + const engineType = opt.engineType[ 0 ]; + + return { transcoderFormat, engineFormat, engineType }; + + } + + throw new Error( 'THREE.KTX2Loader: Failed to identify transcoding target.' ); + + } + + function isPowerOfTwo( value ) { + + if ( value <= 2 ) return true; + + return ( value & ( value - 1 ) ) === 0 && value !== 0; + + } + + /** Concatenates N byte arrays. */ + function concat( arrays ) { + + if ( arrays.length === 1 ) return arrays[ 0 ]; + + let totalByteLength = 0; + + for ( let i = 0; i < arrays.length; i ++ ) { + + const array = arrays[ i ]; + totalByteLength += array.byteLength; + + } + + const result = new Uint8Array( totalByteLength ); + + let byteOffset = 0; + + for ( let i = 0; i < arrays.length; i ++ ) { + + const array = arrays[ i ]; + result.set( array, byteOffset ); + + byteOffset += array.byteLength; + + } + + return result; + + } + +}; + +// Parsing for non-Basis textures. These textures may have supercompression +// like Zstd, but they do not require transcoding. + +const UNCOMPRESSED_FORMATS = new Set( [ RGBAFormat, RGFormat, RedFormat ] ); + +const FORMAT_MAP = { + + [ VK_FORMAT_R32G32B32A32_SFLOAT ]: RGBAFormat, + [ VK_FORMAT_R16G16B16A16_SFLOAT ]: RGBAFormat, + [ VK_FORMAT_R8G8B8A8_UNORM ]: RGBAFormat, + [ VK_FORMAT_R8G8B8A8_SRGB ]: RGBAFormat, + + [ VK_FORMAT_R32G32_SFLOAT ]: RGFormat, + [ VK_FORMAT_R16G16_SFLOAT ]: RGFormat, + [ VK_FORMAT_R8G8_UNORM ]: RGFormat, + [ VK_FORMAT_R8G8_SRGB ]: RGFormat, + + [ VK_FORMAT_R32_SFLOAT ]: RedFormat, + [ VK_FORMAT_R16_SFLOAT ]: RedFormat, + [ VK_FORMAT_R8_SRGB ]: RedFormat, + [ VK_FORMAT_R8_UNORM ]: RedFormat, + + [ VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT ]: RGBA_ASTC_4x4_Format, + [ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: RGBA_ASTC_6x6_Format, + [ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: RGBA_ASTC_6x6_Format, + +}; + +const TYPE_MAP = { + + [ VK_FORMAT_R32G32B32A32_SFLOAT ]: FloatType, + [ VK_FORMAT_R16G16B16A16_SFLOAT ]: HalfFloatType, + [ VK_FORMAT_R8G8B8A8_UNORM ]: UnsignedByteType, + [ VK_FORMAT_R8G8B8A8_SRGB ]: UnsignedByteType, + + [ VK_FORMAT_R32G32_SFLOAT ]: FloatType, + [ VK_FORMAT_R16G16_SFLOAT ]: HalfFloatType, + [ VK_FORMAT_R8G8_UNORM ]: UnsignedByteType, + [ VK_FORMAT_R8G8_SRGB ]: UnsignedByteType, + + [ VK_FORMAT_R32_SFLOAT ]: FloatType, + [ VK_FORMAT_R16_SFLOAT ]: HalfFloatType, + [ VK_FORMAT_R8_SRGB ]: UnsignedByteType, + [ VK_FORMAT_R8_UNORM ]: UnsignedByteType, + + [ VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT ]: HalfFloatType, + [ VK_FORMAT_ASTC_6x6_SRGB_BLOCK ]: UnsignedByteType, + [ VK_FORMAT_ASTC_6x6_UNORM_BLOCK ]: UnsignedByteType, + +}; + +async function createRawTexture( container ) { + + const { vkFormat } = container; + + if ( FORMAT_MAP[ vkFormat ] === undefined ) { + + throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' ); + + } + + // + + let zstd; + + if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) { + + if ( ! _zstd ) { + + _zstd = new Promise( async ( resolve ) => { + + const zstd = new ZSTDDecoder(); + await zstd.init(); + resolve( zstd ); + + } ); + + } + + zstd = await _zstd; + + } + + // + + const mipmaps = []; + + + for ( let levelIndex = 0; levelIndex < container.levels.length; levelIndex ++ ) { + + const levelWidth = Math.max( 1, container.pixelWidth >> levelIndex ); + const levelHeight = Math.max( 1, container.pixelHeight >> levelIndex ); + const levelDepth = container.pixelDepth ? Math.max( 1, container.pixelDepth >> levelIndex ) : 0; + + const level = container.levels[ levelIndex ]; + + let levelData; + + if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE ) { + + levelData = level.levelData; + + } else if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) { + + levelData = zstd.decode( level.levelData, level.uncompressedByteLength ); + + } else { + + throw new Error( 'THREE.KTX2Loader: Unsupported supercompressionScheme.' ); + + } + + let data; + + if ( TYPE_MAP[ vkFormat ] === FloatType ) { + + data = new Float32Array( + + levelData.buffer, + levelData.byteOffset, + levelData.byteLength / Float32Array.BYTES_PER_ELEMENT + + ); + + } else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) { + + data = new Uint16Array( + + levelData.buffer, + levelData.byteOffset, + levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT + + ); + + } else { + + data = levelData; + + } + + mipmaps.push( { + + data: data, + width: levelWidth, + height: levelHeight, + depth: levelDepth, + + } ); + + } + + let texture; + + if ( UNCOMPRESSED_FORMATS.has( FORMAT_MAP[ vkFormat ] ) ) { + + texture = container.pixelDepth === 0 + ? new DataTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight ) + : new Data3DTexture( mipmaps[ 0 ].data, container.pixelWidth, container.pixelHeight, container.pixelDepth ); + + } else { + + if ( container.pixelDepth > 0 ) throw new Error( 'THREE.KTX2Loader: Unsupported pixelDepth.' ); + + texture = new CompressedTexture( mipmaps, container.pixelWidth, container.pixelHeight ); + + } + + texture.mipmaps = mipmaps; + + texture.type = TYPE_MAP[ vkFormat ]; + texture.format = FORMAT_MAP[ vkFormat ]; + texture.colorSpace = parseColorSpace( container ); + texture.needsUpdate = true; + + // + + return Promise.resolve( texture ); + +} + +function parseColorSpace( container ) { + + const dfd = container.dataFormatDescriptor[ 0 ]; + + if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_BT709 ) { + + return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? SRGBColorSpace : LinearSRGBColorSpace; + + } else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_DISPLAYP3 ) { + + return dfd.transferFunction === KHR_DF_TRANSFER_SRGB ? DisplayP3ColorSpace : LinearDisplayP3ColorSpace; + + } else if ( dfd.colorPrimaries === KHR_DF_PRIMARIES_UNSPECIFIED ) { + + return NoColorSpace; + + } else { + + console.warn( `THREE.KTX2Loader: Unsupported color primaries, "${ dfd.colorPrimaries }"` ); + return NoColorSpace; + + } + +} + +export { KTX2Loader }; diff --git a/libs/three.js/r171/examples/jsm/loaders/RGBELoader.js b/libs/three.js/r171/examples/jsm/loaders/RGBELoader.js new file mode 100644 index 000000000..f2ac6e15f --- /dev/null +++ b/libs/three.js/r171/examples/jsm/loaders/RGBELoader.js @@ -0,0 +1,450 @@ +import { + DataTextureLoader, + DataUtils, + FloatType, + HalfFloatType, + LinearFilter, + LinearSRGBColorSpace +} from 'three'; + +// https://github.com/mrdoob/three.js/issues/5552 +// http://en.wikipedia.org/wiki/RGBE_image_format + +class RGBELoader extends DataTextureLoader { + + constructor( manager ) { + + super( manager ); + + this.type = HalfFloatType; + + } + + // adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html + + parse( buffer ) { + + const + /* default error routine. change this to change error handling */ + rgbe_read_error = 1, + rgbe_write_error = 2, + rgbe_format_error = 3, + rgbe_memory_error = 4, + rgbe_error = function ( rgbe_error_code, msg ) { + + switch ( rgbe_error_code ) { + + case rgbe_read_error: throw new Error( 'THREE.RGBELoader: Read Error: ' + ( msg || '' ) ); + case rgbe_write_error: throw new Error( 'THREE.RGBELoader: Write Error: ' + ( msg || '' ) ); + case rgbe_format_error: throw new Error( 'THREE.RGBELoader: Bad File Format: ' + ( msg || '' ) ); + default: + case rgbe_memory_error: throw new Error( 'THREE.RGBELoader: Memory Error: ' + ( msg || '' ) ); + + } + + }, + + /* offsets to red, green, and blue components in a data (float) pixel */ + //RGBE_DATA_RED = 0, + //RGBE_DATA_GREEN = 1, + //RGBE_DATA_BLUE = 2, + + /* number of floats per pixel, use 4 since stored in rgba image format */ + //RGBE_DATA_SIZE = 4, + + /* flags indicating which fields in an rgbe_header_info are valid */ + RGBE_VALID_PROGRAMTYPE = 1, + RGBE_VALID_FORMAT = 2, + RGBE_VALID_DIMENSIONS = 4, + + NEWLINE = '\n', + + fgets = function ( buffer, lineLimit, consume ) { + + const chunkSize = 128; + + lineLimit = ! lineLimit ? 1024 : lineLimit; + let p = buffer.pos, + i = - 1, len = 0, s = '', + chunk = String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) ); + + while ( ( 0 > ( i = chunk.indexOf( NEWLINE ) ) ) && ( len < lineLimit ) && ( p < buffer.byteLength ) ) { + + s += chunk; len += chunk.length; + p += chunkSize; + chunk += String.fromCharCode.apply( null, new Uint16Array( buffer.subarray( p, p + chunkSize ) ) ); + + } + + if ( - 1 < i ) { + + /*for (i=l-1; i>=0; i--) { + byteCode = m.charCodeAt(i); + if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++; + else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2; + if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate + }*/ + if ( false !== consume ) buffer.pos += len + i + 1; + return s + chunk.slice( 0, i ); + + } + + return false; + + }, + + /* minimal header reading. modify if you want to parse more information */ + RGBE_ReadHeader = function ( buffer ) { + + + // regexes to parse header info fields + const magic_token_re = /^#\?(\S+)/, + gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/, + exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/, + format_re = /^\s*FORMAT=(\S+)\s*$/, + dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/, + + // RGBE format header struct + header = { + + valid: 0, /* indicate which fields are valid */ + + string: '', /* the actual header string */ + + comments: '', /* comments found in header */ + + programtype: 'RGBE', /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */ + + format: '', /* RGBE format, default 32-bit_rle_rgbe */ + + gamma: 1.0, /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */ + + exposure: 1.0, /* a value of 1.0 in an image corresponds to watts/steradian/m^2. defaults to 1.0 */ + + width: 0, height: 0 /* image dimensions, width/height */ + + }; + + let line, match; + + if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) { + + rgbe_error( rgbe_read_error, 'no header found' ); + + } + + /* if you want to require the magic token then uncomment the next line */ + if ( ! ( match = line.match( magic_token_re ) ) ) { + + rgbe_error( rgbe_format_error, 'bad initial token' ); + + } + + header.valid |= RGBE_VALID_PROGRAMTYPE; + header.programtype = match[ 1 ]; + header.string += line + '\n'; + + while ( true ) { + + line = fgets( buffer ); + if ( false === line ) break; + header.string += line + '\n'; + + if ( '#' === line.charAt( 0 ) ) { + + header.comments += line + '\n'; + continue; // comment line + + } + + if ( match = line.match( gamma_re ) ) { + + header.gamma = parseFloat( match[ 1 ] ); + + } + + if ( match = line.match( exposure_re ) ) { + + header.exposure = parseFloat( match[ 1 ] ); + + } + + if ( match = line.match( format_re ) ) { + + header.valid |= RGBE_VALID_FORMAT; + header.format = match[ 1 ];//'32-bit_rle_rgbe'; + + } + + if ( match = line.match( dimensions_re ) ) { + + header.valid |= RGBE_VALID_DIMENSIONS; + header.height = parseInt( match[ 1 ], 10 ); + header.width = parseInt( match[ 2 ], 10 ); + + } + + if ( ( header.valid & RGBE_VALID_FORMAT ) && ( header.valid & RGBE_VALID_DIMENSIONS ) ) break; + + } + + if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) { + + rgbe_error( rgbe_format_error, 'missing format specifier' ); + + } + + if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) { + + rgbe_error( rgbe_format_error, 'missing image size specifier' ); + + } + + return header; + + }, + + RGBE_ReadPixels_RLE = function ( buffer, w, h ) { + + const scanline_width = w; + + if ( + // run length encoding is not allowed so read flat + ( ( scanline_width < 8 ) || ( scanline_width > 0x7fff ) ) || + // this file is not run length encoded + ( ( 2 !== buffer[ 0 ] ) || ( 2 !== buffer[ 1 ] ) || ( buffer[ 2 ] & 0x80 ) ) + ) { + + // return the flat buffer + return new Uint8Array( buffer ); + + } + + if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) { + + rgbe_error( rgbe_format_error, 'wrong scanline width' ); + + } + + const data_rgba = new Uint8Array( 4 * w * h ); + + if ( ! data_rgba.length ) { + + rgbe_error( rgbe_memory_error, 'unable to allocate buffer space' ); + + } + + let offset = 0, pos = 0; + + const ptr_end = 4 * scanline_width; + const rgbeStart = new Uint8Array( 4 ); + const scanline_buffer = new Uint8Array( ptr_end ); + let num_scanlines = h; + + // read in each successive scanline + while ( ( num_scanlines > 0 ) && ( pos < buffer.byteLength ) ) { + + if ( pos + 4 > buffer.byteLength ) { + + rgbe_error( rgbe_read_error ); + + } + + rgbeStart[ 0 ] = buffer[ pos ++ ]; + rgbeStart[ 1 ] = buffer[ pos ++ ]; + rgbeStart[ 2 ] = buffer[ pos ++ ]; + rgbeStart[ 3 ] = buffer[ pos ++ ]; + + if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) { + + rgbe_error( rgbe_format_error, 'bad rgbe scanline format' ); + + } + + // read each of the four channels for the scanline into the buffer + // first red, then green, then blue, then exponent + let ptr = 0, count; + + while ( ( ptr < ptr_end ) && ( pos < buffer.byteLength ) ) { + + count = buffer[ pos ++ ]; + const isEncodedRun = count > 128; + if ( isEncodedRun ) count -= 128; + + if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) { + + rgbe_error( rgbe_format_error, 'bad scanline data' ); + + } + + if ( isEncodedRun ) { + + // a (encoded) run of the same value + const byteValue = buffer[ pos ++ ]; + for ( let i = 0; i < count; i ++ ) { + + scanline_buffer[ ptr ++ ] = byteValue; + + } + //ptr += count; + + } else { + + // a literal-run + scanline_buffer.set( buffer.subarray( pos, pos + count ), ptr ); + ptr += count; pos += count; + + } + + } + + + // now convert data from buffer into rgba + // first red, then green, then blue, then exponent (alpha) + const l = scanline_width; //scanline_buffer.byteLength; + for ( let i = 0; i < l; i ++ ) { + + let off = 0; + data_rgba[ offset ] = scanline_buffer[ i + off ]; + off += scanline_width; //1; + data_rgba[ offset + 1 ] = scanline_buffer[ i + off ]; + off += scanline_width; //1; + data_rgba[ offset + 2 ] = scanline_buffer[ i + off ]; + off += scanline_width; //1; + data_rgba[ offset + 3 ] = scanline_buffer[ i + off ]; + offset += 4; + + } + + num_scanlines --; + + } + + return data_rgba; + + }; + + const RGBEByteToRGBFloat = function ( sourceArray, sourceOffset, destArray, destOffset ) { + + const e = sourceArray[ sourceOffset + 3 ]; + const scale = Math.pow( 2.0, e - 128.0 ) / 255.0; + + destArray[ destOffset + 0 ] = sourceArray[ sourceOffset + 0 ] * scale; + destArray[ destOffset + 1 ] = sourceArray[ sourceOffset + 1 ] * scale; + destArray[ destOffset + 2 ] = sourceArray[ sourceOffset + 2 ] * scale; + destArray[ destOffset + 3 ] = 1; + + }; + + const RGBEByteToRGBHalf = function ( sourceArray, sourceOffset, destArray, destOffset ) { + + const e = sourceArray[ sourceOffset + 3 ]; + const scale = Math.pow( 2.0, e - 128.0 ) / 255.0; + + // clamping to 65504, the maximum representable value in float16 + destArray[ destOffset + 0 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 0 ] * scale, 65504 ) ); + destArray[ destOffset + 1 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 1 ] * scale, 65504 ) ); + destArray[ destOffset + 2 ] = DataUtils.toHalfFloat( Math.min( sourceArray[ sourceOffset + 2 ] * scale, 65504 ) ); + destArray[ destOffset + 3 ] = DataUtils.toHalfFloat( 1 ); + + }; + + const byteArray = new Uint8Array( buffer ); + byteArray.pos = 0; + const rgbe_header_info = RGBE_ReadHeader( byteArray ); + + const w = rgbe_header_info.width, + h = rgbe_header_info.height, + image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h ); + + + let data, type; + let numElements; + + switch ( this.type ) { + + case FloatType: + + numElements = image_rgba_data.length / 4; + const floatArray = new Float32Array( numElements * 4 ); + + for ( let j = 0; j < numElements; j ++ ) { + + RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 4 ); + + } + + data = floatArray; + type = FloatType; + break; + + case HalfFloatType: + + numElements = image_rgba_data.length / 4; + const halfArray = new Uint16Array( numElements * 4 ); + + for ( let j = 0; j < numElements; j ++ ) { + + RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 4 ); + + } + + data = halfArray; + type = HalfFloatType; + break; + + default: + + throw new Error( 'THREE.RGBELoader: Unsupported type: ' + this.type ); + break; + + } + + return { + width: w, height: h, + data: data, + header: rgbe_header_info.string, + gamma: rgbe_header_info.gamma, + exposure: rgbe_header_info.exposure, + type: type + }; + + } + + setDataType( value ) { + + this.type = value; + return this; + + } + + load( url, onLoad, onProgress, onError ) { + + function onLoadCallback( texture, texData ) { + + switch ( texture.type ) { + + case FloatType: + case HalfFloatType: + + texture.colorSpace = LinearSRGBColorSpace; + texture.minFilter = LinearFilter; + texture.magFilter = LinearFilter; + texture.generateMipmaps = false; + texture.flipY = true; + + break; + + } + + if ( onLoad ) onLoad( texture, texData ); + + } + + return super.load( url, onLoadCallback, onProgress, onError ); + + } + +} + +export { RGBELoader }; diff --git a/libs/three.js/r171/examples/jsm/math/ColorSpaces.js b/libs/three.js/r171/examples/jsm/math/ColorSpaces.js new file mode 100644 index 000000000..be48ef906 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/math/ColorSpaces.js @@ -0,0 +1,76 @@ +import { LinearTransfer, Matrix3, SRGBTransfer } from 'three'; + +// Reference: http://www.russellcottrell.com/photo/matrixCalculator.htm + +const P3_PRIMARIES = [ 0.680, 0.320, 0.265, 0.690, 0.150, 0.060 ]; +const P3_LUMINANCE_COEFFICIENTS = [ 0.2289, 0.6917, 0.0793 ]; +const REC2020_PRIMARIES = [ 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 ]; +const REC2020_LUMINANCE_COEFFICIENTS = [ 0.2627, 0.6780, 0.0593 ]; +const D65 = [ 0.3127, 0.3290 ]; + +/****************************************************************************** + * Display P3 definitions + */ + +const LINEAR_DISPLAY_P3_TO_XYZ = /*@__PURE__*/ new Matrix3().set( + 0.4865709, 0.2656677, 0.1982173, + 0.2289746, 0.6917385, 0.0792869, + 0.0000000, 0.0451134, 1.0439444 +); + +const XYZ_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set( + 2.4934969, - 0.9313836, - 0.4027108, + - 0.8294890, 1.7626641, 0.0236247, + 0.0358458, - 0.0761724, 0.9568845 +); + +export const DisplayP3ColorSpace = 'display-p3'; +export const LinearDisplayP3ColorSpace = 'display-p3-linear'; + +export const DisplayP3ColorSpaceImpl = { + primaries: P3_PRIMARIES, + whitePoint: D65, + transfer: SRGBTransfer, + toXYZ: LINEAR_DISPLAY_P3_TO_XYZ, + fromXYZ: XYZ_TO_LINEAR_DISPLAY_P3, + luminanceCoefficients: P3_LUMINANCE_COEFFICIENTS, + outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace } +}; + +export const LinearDisplayP3ColorSpaceImpl = { + primaries: P3_PRIMARIES, + whitePoint: D65, + transfer: LinearTransfer, + toXYZ: LINEAR_DISPLAY_P3_TO_XYZ, + fromXYZ: XYZ_TO_LINEAR_DISPLAY_P3, + luminanceCoefficients: P3_LUMINANCE_COEFFICIENTS, + workingColorSpaceConfig: { unpackColorSpace: DisplayP3ColorSpace }, + outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace } +}; + +/****************************************************************************** + * Rec. 2020 definitions + */ + +const LINEAR_REC2020_TO_XYZ = /*@__PURE__*/ new Matrix3().set( + 0.6369580, 0.1446169, 0.1688810, + 0.2627002, 0.6779981, 0.0593017, + 0.0000000, 0.0280727, 1.0609851 +); + +const XYZ_TO_LINEAR_REC2020 = /*@__PURE__*/ new Matrix3().set( + 1.7166512, - 0.3556708, - 0.2533663, + - 0.6666844, 1.6164812, 0.0157685, + 0.0176399, - 0.0427706, 0.9421031 +); + +export const LinearRec2020ColorSpace = 'rec2020-linear'; + +export const LinearRec2020ColorSpaceImpl = { + primaries: REC2020_PRIMARIES, + whitePoint: D65, + transfer: LinearTransfer, + toXYZ: LINEAR_REC2020_TO_XYZ, + fromXYZ: XYZ_TO_LINEAR_REC2020, + luminanceCoefficients: REC2020_LUMINANCE_COEFFICIENTS, +}; diff --git a/libs/three.js/r171/examples/jsm/physics/AmmoPhysics.js b/libs/three.js/r171/examples/jsm/physics/AmmoPhysics.js new file mode 100644 index 000000000..387420673 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/physics/AmmoPhysics.js @@ -0,0 +1,306 @@ +async function AmmoPhysics() { + + if ( 'Ammo' in window === false ) { + + console.error( 'AmmoPhysics: Couldn\'t find Ammo.js' ); + return; + + } + + const AmmoLib = await Ammo(); // eslint-disable-line no-undef + + const frameRate = 60; + + const collisionConfiguration = new AmmoLib.btDefaultCollisionConfiguration(); + const dispatcher = new AmmoLib.btCollisionDispatcher( collisionConfiguration ); + const broadphase = new AmmoLib.btDbvtBroadphase(); + const solver = new AmmoLib.btSequentialImpulseConstraintSolver(); + const world = new AmmoLib.btDiscreteDynamicsWorld( dispatcher, broadphase, solver, collisionConfiguration ); + world.setGravity( new AmmoLib.btVector3( 0, - 9.8, 0 ) ); + + const worldTransform = new AmmoLib.btTransform(); + + // + + function getShape( geometry ) { + + const parameters = geometry.parameters; + + // TODO change type to is* + + if ( geometry.type === 'BoxGeometry' ) { + + const sx = parameters.width !== undefined ? parameters.width / 2 : 0.5; + const sy = parameters.height !== undefined ? parameters.height / 2 : 0.5; + const sz = parameters.depth !== undefined ? parameters.depth / 2 : 0.5; + + const shape = new AmmoLib.btBoxShape( new AmmoLib.btVector3( sx, sy, sz ) ); + shape.setMargin( 0.05 ); + + return shape; + + } else if ( geometry.type === 'SphereGeometry' || geometry.type === 'IcosahedronGeometry' ) { + + const radius = parameters.radius !== undefined ? parameters.radius : 1; + + const shape = new AmmoLib.btSphereShape( radius ); + shape.setMargin( 0.05 ); + + return shape; + + } + + return null; + + } + + const meshes = []; + const meshMap = new WeakMap(); + + function addScene( scene ) { + + scene.traverse( function ( child ) { + + if ( child.isMesh ) { + + const physics = child.userData.physics; + + if ( physics ) { + + addMesh( child, physics.mass ); + + } + + } + + } ); + + } + + function addMesh( mesh, mass = 0 ) { + + const shape = getShape( mesh.geometry ); + + if ( shape !== null ) { + + if ( mesh.isInstancedMesh ) { + + handleInstancedMesh( mesh, mass, shape ); + + } else if ( mesh.isMesh ) { + + handleMesh( mesh, mass, shape ); + + } + + } + + } + + function handleMesh( mesh, mass, shape ) { + + const position = mesh.position; + const quaternion = mesh.quaternion; + + const transform = new AmmoLib.btTransform(); + transform.setIdentity(); + transform.setOrigin( new AmmoLib.btVector3( position.x, position.y, position.z ) ); + transform.setRotation( new AmmoLib.btQuaternion( quaternion.x, quaternion.y, quaternion.z, quaternion.w ) ); + + const motionState = new AmmoLib.btDefaultMotionState( transform ); + + const localInertia = new AmmoLib.btVector3( 0, 0, 0 ); + shape.calculateLocalInertia( mass, localInertia ); + + const rbInfo = new AmmoLib.btRigidBodyConstructionInfo( mass, motionState, shape, localInertia ); + + const body = new AmmoLib.btRigidBody( rbInfo ); + // body.setFriction( 4 ); + world.addRigidBody( body ); + + if ( mass > 0 ) { + + meshes.push( mesh ); + meshMap.set( mesh, body ); + + } + + + } + + function handleInstancedMesh( mesh, mass, shape ) { + + const array = mesh.instanceMatrix.array; + + const bodies = []; + + for ( let i = 0; i < mesh.count; i ++ ) { + + const index = i * 16; + + const transform = new AmmoLib.btTransform(); + transform.setFromOpenGLMatrix( array.slice( index, index + 16 ) ); + + const motionState = new AmmoLib.btDefaultMotionState( transform ); + + const localInertia = new AmmoLib.btVector3( 0, 0, 0 ); + shape.calculateLocalInertia( mass, localInertia ); + + const rbInfo = new AmmoLib.btRigidBodyConstructionInfo( mass, motionState, shape, localInertia ); + + const body = new AmmoLib.btRigidBody( rbInfo ); + world.addRigidBody( body ); + + bodies.push( body ); + + } + + if ( mass > 0 ) { + + meshes.push( mesh ); + + meshMap.set( mesh, bodies ); + + } + + } + + // + + function setMeshPosition( mesh, position, index = 0 ) { + + if ( mesh.isInstancedMesh ) { + + const bodies = meshMap.get( mesh ); + const body = bodies[ index ]; + + body.setAngularVelocity( new AmmoLib.btVector3( 0, 0, 0 ) ); + body.setLinearVelocity( new AmmoLib.btVector3( 0, 0, 0 ) ); + + worldTransform.setIdentity(); + worldTransform.setOrigin( new AmmoLib.btVector3( position.x, position.y, position.z ) ); + body.setWorldTransform( worldTransform ); + + } else if ( mesh.isMesh ) { + + const body = meshMap.get( mesh ); + + body.setAngularVelocity( new AmmoLib.btVector3( 0, 0, 0 ) ); + body.setLinearVelocity( new AmmoLib.btVector3( 0, 0, 0 ) ); + + worldTransform.setIdentity(); + worldTransform.setOrigin( new AmmoLib.btVector3( position.x, position.y, position.z ) ); + body.setWorldTransform( worldTransform ); + + } + + } + + // + + let lastTime = 0; + + function step() { + + const time = performance.now(); + + if ( lastTime > 0 ) { + + const delta = ( time - lastTime ) / 1000; + + world.stepSimulation( delta, 10 ); + + // + + for ( let i = 0, l = meshes.length; i < l; i ++ ) { + + const mesh = meshes[ i ]; + + if ( mesh.isInstancedMesh ) { + + const array = mesh.instanceMatrix.array; + const bodies = meshMap.get( mesh ); + + for ( let j = 0; j < bodies.length; j ++ ) { + + const body = bodies[ j ]; + + const motionState = body.getMotionState(); + motionState.getWorldTransform( worldTransform ); + + const position = worldTransform.getOrigin(); + const quaternion = worldTransform.getRotation(); + + compose( position, quaternion, array, j * 16 ); + + } + + mesh.instanceMatrix.needsUpdate = true; + mesh.computeBoundingSphere(); + + } else if ( mesh.isMesh ) { + + const body = meshMap.get( mesh ); + + const motionState = body.getMotionState(); + motionState.getWorldTransform( worldTransform ); + + const position = worldTransform.getOrigin(); + const quaternion = worldTransform.getRotation(); + mesh.position.set( position.x(), position.y(), position.z() ); + mesh.quaternion.set( quaternion.x(), quaternion.y(), quaternion.z(), quaternion.w() ); + + } + + } + + } + + lastTime = time; + + } + + // animate + + setInterval( step, 1000 / frameRate ); + + return { + addScene: addScene, + addMesh: addMesh, + setMeshPosition: setMeshPosition + // addCompoundMesh + }; + +} + +function compose( position, quaternion, array, index ) { + + const x = quaternion.x(), y = quaternion.y(), z = quaternion.z(), w = quaternion.w(); + const x2 = x + x, y2 = y + y, z2 = z + z; + const xx = x * x2, xy = x * y2, xz = x * z2; + const yy = y * y2, yz = y * z2, zz = z * z2; + const wx = w * x2, wy = w * y2, wz = w * z2; + + array[ index + 0 ] = ( 1 - ( yy + zz ) ); + array[ index + 1 ] = ( xy + wz ); + array[ index + 2 ] = ( xz - wy ); + array[ index + 3 ] = 0; + + array[ index + 4 ] = ( xy - wz ); + array[ index + 5 ] = ( 1 - ( xx + zz ) ); + array[ index + 6 ] = ( yz + wx ); + array[ index + 7 ] = 0; + + array[ index + 8 ] = ( xz + wy ); + array[ index + 9 ] = ( yz - wx ); + array[ index + 10 ] = ( 1 - ( xx + yy ) ); + array[ index + 11 ] = 0; + + array[ index + 12 ] = position.x(); + array[ index + 13 ] = position.y(); + array[ index + 14 ] = position.z(); + array[ index + 15 ] = 1; + +} + +export { AmmoPhysics }; diff --git a/libs/three.js/r171/examples/jsm/physics/RapierPhysics.js b/libs/three.js/r171/examples/jsm/physics/RapierPhysics.js new file mode 100644 index 000000000..e31ca9fcc --- /dev/null +++ b/libs/three.js/r171/examples/jsm/physics/RapierPhysics.js @@ -0,0 +1,240 @@ +import { Clock, Vector3, Quaternion, Matrix4 } from 'three'; + +const RAPIER_PATH = 'https://cdn.skypack.dev/@dimforge/rapier3d-compat@0.12.0'; + +const frameRate = 60; + +const _scale = new Vector3( 1, 1, 1 ); +const ZERO = new Vector3(); + +let RAPIER = null; + +function getShape( geometry ) { + + const parameters = geometry.parameters; + + // TODO change type to is* + + if ( geometry.type === 'BoxGeometry' ) { + + const sx = parameters.width !== undefined ? parameters.width / 2 : 0.5; + const sy = parameters.height !== undefined ? parameters.height / 2 : 0.5; + const sz = parameters.depth !== undefined ? parameters.depth / 2 : 0.5; + + return RAPIER.ColliderDesc.cuboid( sx, sy, sz ); + + } else if ( geometry.type === 'SphereGeometry' || geometry.type === 'IcosahedronGeometry' ) { + + const radius = parameters.radius !== undefined ? parameters.radius : 1; + return RAPIER.ColliderDesc.ball( radius ); + + } else if ( geometry.type === 'BufferGeometry' ) { + + const vertices = []; + const vertex = new Vector3(); + const position = geometry.getAttribute( 'position' ); + + for ( let i = 0; i < position.count; i ++ ) { + + vertex.fromBufferAttribute( position, i ); + vertices.push( vertex.x, vertex.y, vertex.z ); + + } + + // if the buffer is non-indexed, generate an index buffer + const indices = geometry.getIndex() === null + ? Uint32Array.from( Array( parseInt( vertices.length / 3 ) ).keys() ) + : geometry.getIndex().array; + + return RAPIER.ColliderDesc.trimesh( vertices, indices ); + + } + + return null; + +} + +async function RapierPhysics() { + + if ( RAPIER === null ) { + + RAPIER = await import( `${RAPIER_PATH}` ); + await RAPIER.init(); + + } + + // Docs: https://rapier.rs/docs/api/javascript/JavaScript3D/ + + const gravity = new Vector3( 0.0, - 9.81, 0.0 ); + const world = new RAPIER.World( gravity ); + + const meshes = []; + const meshMap = new WeakMap(); + + const _vector = new Vector3(); + const _quaternion = new Quaternion(); + const _matrix = new Matrix4(); + + function addScene( scene ) { + + scene.traverse( function ( child ) { + + if ( child.isMesh ) { + + const physics = child.userData.physics; + + if ( physics ) { + + addMesh( child, physics.mass, physics.restitution ); + + } + + } + + } ); + + } + + function addMesh( mesh, mass = 0, restitution = 0 ) { + + const shape = getShape( mesh.geometry ); + + if ( shape === null ) return; + + shape.setMass( mass ); + shape.setRestitution( restitution ); + + const body = mesh.isInstancedMesh + ? createInstancedBody( mesh, mass, shape ) + : createBody( mesh.position, mesh.quaternion, mass, shape ); + + if ( mass > 0 ) { + + meshes.push( mesh ); + meshMap.set( mesh, body ); + + } + + } + + function createInstancedBody( mesh, mass, shape ) { + + const array = mesh.instanceMatrix.array; + + const bodies = []; + + for ( let i = 0; i < mesh.count; i ++ ) { + + const position = _vector.fromArray( array, i * 16 + 12 ); + bodies.push( createBody( position, null, mass, shape ) ); + + } + + return bodies; + + } + + function createBody( position, quaternion, mass, shape ) { + + const desc = mass > 0 ? RAPIER.RigidBodyDesc.dynamic() : RAPIER.RigidBodyDesc.fixed(); + desc.setTranslation( ...position ); + if ( quaternion !== null ) desc.setRotation( quaternion ); + + const body = world.createRigidBody( desc ); + world.createCollider( shape, body ); + + return body; + + } + + function setMeshPosition( mesh, position, index = 0 ) { + + let body = meshMap.get( mesh ); + + if ( mesh.isInstancedMesh ) { + + body = body[ index ]; + + } + + body.setAngvel( ZERO ); + body.setLinvel( ZERO ); + body.setTranslation( position ); + + } + + function setMeshVelocity( mesh, velocity, index = 0 ) { + + let body = meshMap.get( mesh ); + + if ( mesh.isInstancedMesh ) { + + body = body[ index ]; + + } + + body.setLinvel( velocity ); + + } + + // + + const clock = new Clock(); + + function step() { + + world.timestep = clock.getDelta(); + world.step(); + + // + + for ( let i = 0, l = meshes.length; i < l; i ++ ) { + + const mesh = meshes[ i ]; + + if ( mesh.isInstancedMesh ) { + + const array = mesh.instanceMatrix.array; + const bodies = meshMap.get( mesh ); + + for ( let j = 0; j < bodies.length; j ++ ) { + + const body = bodies[ j ]; + + const position = body.translation(); + _quaternion.copy( body.rotation() ); + + _matrix.compose( position, _quaternion, _scale ).toArray( array, j * 16 ); + + } + + mesh.instanceMatrix.needsUpdate = true; + mesh.computeBoundingSphere(); + + } else { + + const body = meshMap.get( mesh ); + + mesh.position.copy( body.translation() ); + mesh.quaternion.copy( body.rotation() ); + + } + + } + + } + + // animate + + setInterval( step, 1000 / frameRate ); + + return { + addScene: addScene, + addMesh: addMesh, + setMeshPosition: setMeshPosition, + setMeshVelocity: setMeshVelocity + }; + +} + +export { RapierPhysics }; diff --git a/libs/three.js/r171/examples/jsm/postprocessing/EffectComposer.js b/libs/three.js/r171/examples/jsm/postprocessing/EffectComposer.js new file mode 100644 index 000000000..110eabc8e --- /dev/null +++ b/libs/three.js/r171/examples/jsm/postprocessing/EffectComposer.js @@ -0,0 +1,231 @@ +import { + Clock, + HalfFloatType, + NoBlending, + Vector2, + WebGLRenderTarget +} from 'three'; +import { CopyShader } from '../shaders/CopyShader.js'; +import { ShaderPass } from './ShaderPass.js'; +import { MaskPass } from './MaskPass.js'; +import { ClearMaskPass } from './MaskPass.js'; + +class EffectComposer { + + constructor( renderer, renderTarget ) { + + this.renderer = renderer; + + this._pixelRatio = renderer.getPixelRatio(); + + if ( renderTarget === undefined ) { + + const size = renderer.getSize( new Vector2() ); + this._width = size.width; + this._height = size.height; + + renderTarget = new WebGLRenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType } ); + renderTarget.texture.name = 'EffectComposer.rt1'; + + } else { + + this._width = renderTarget.width; + this._height = renderTarget.height; + + } + + this.renderTarget1 = renderTarget; + this.renderTarget2 = renderTarget.clone(); + this.renderTarget2.texture.name = 'EffectComposer.rt2'; + + this.writeBuffer = this.renderTarget1; + this.readBuffer = this.renderTarget2; + + this.renderToScreen = true; + + this.passes = []; + + this.copyPass = new ShaderPass( CopyShader ); + this.copyPass.material.blending = NoBlending; + + this.clock = new Clock(); + + } + + swapBuffers() { + + const tmp = this.readBuffer; + this.readBuffer = this.writeBuffer; + this.writeBuffer = tmp; + + } + + addPass( pass ) { + + this.passes.push( pass ); + pass.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio ); + + } + + insertPass( pass, index ) { + + this.passes.splice( index, 0, pass ); + pass.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio ); + + } + + removePass( pass ) { + + const index = this.passes.indexOf( pass ); + + if ( index !== - 1 ) { + + this.passes.splice( index, 1 ); + + } + + } + + isLastEnabledPass( passIndex ) { + + for ( let i = passIndex + 1; i < this.passes.length; i ++ ) { + + if ( this.passes[ i ].enabled ) { + + return false; + + } + + } + + return true; + + } + + render( deltaTime ) { + + // deltaTime value is in seconds + + if ( deltaTime === undefined ) { + + deltaTime = this.clock.getDelta(); + + } + + const currentRenderTarget = this.renderer.getRenderTarget(); + + let maskActive = false; + + for ( let i = 0, il = this.passes.length; i < il; i ++ ) { + + const pass = this.passes[ i ]; + + if ( pass.enabled === false ) continue; + + pass.renderToScreen = ( this.renderToScreen && this.isLastEnabledPass( i ) ); + pass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime, maskActive ); + + if ( pass.needsSwap ) { + + if ( maskActive ) { + + const context = this.renderer.getContext(); + const stencil = this.renderer.state.buffers.stencil; + + //context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff ); + stencil.setFunc( context.NOTEQUAL, 1, 0xffffffff ); + + this.copyPass.render( this.renderer, this.writeBuffer, this.readBuffer, deltaTime ); + + //context.stencilFunc( context.EQUAL, 1, 0xffffffff ); + stencil.setFunc( context.EQUAL, 1, 0xffffffff ); + + } + + this.swapBuffers(); + + } + + if ( MaskPass !== undefined ) { + + if ( pass instanceof MaskPass ) { + + maskActive = true; + + } else if ( pass instanceof ClearMaskPass ) { + + maskActive = false; + + } + + } + + } + + this.renderer.setRenderTarget( currentRenderTarget ); + + } + + reset( renderTarget ) { + + if ( renderTarget === undefined ) { + + const size = this.renderer.getSize( new Vector2() ); + this._pixelRatio = this.renderer.getPixelRatio(); + this._width = size.width; + this._height = size.height; + + renderTarget = this.renderTarget1.clone(); + renderTarget.setSize( this._width * this._pixelRatio, this._height * this._pixelRatio ); + + } + + this.renderTarget1.dispose(); + this.renderTarget2.dispose(); + this.renderTarget1 = renderTarget; + this.renderTarget2 = renderTarget.clone(); + + this.writeBuffer = this.renderTarget1; + this.readBuffer = this.renderTarget2; + + } + + setSize( width, height ) { + + this._width = width; + this._height = height; + + const effectiveWidth = this._width * this._pixelRatio; + const effectiveHeight = this._height * this._pixelRatio; + + this.renderTarget1.setSize( effectiveWidth, effectiveHeight ); + this.renderTarget2.setSize( effectiveWidth, effectiveHeight ); + + for ( let i = 0; i < this.passes.length; i ++ ) { + + this.passes[ i ].setSize( effectiveWidth, effectiveHeight ); + + } + + } + + setPixelRatio( pixelRatio ) { + + this._pixelRatio = pixelRatio; + + this.setSize( this._width, this._height ); + + } + + dispose() { + + this.renderTarget1.dispose(); + this.renderTarget2.dispose(); + + this.copyPass.dispose(); + + } + +} + +export { EffectComposer }; diff --git a/libs/three.js/r171/examples/jsm/postprocessing/MaskPass.js b/libs/three.js/r171/examples/jsm/postprocessing/MaskPass.js new file mode 100644 index 000000000..c51eb00f0 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/postprocessing/MaskPass.js @@ -0,0 +1,101 @@ +import { Pass } from './Pass.js'; + +class MaskPass extends Pass { + + constructor( scene, camera ) { + + super(); + + this.scene = scene; + this.camera = camera; + + this.clear = true; + this.needsSwap = false; + + this.inverse = false; + + } + + render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) { + + const context = renderer.getContext(); + const state = renderer.state; + + // don't update color or depth + + state.buffers.color.setMask( false ); + state.buffers.depth.setMask( false ); + + // lock buffers + + state.buffers.color.setLocked( true ); + state.buffers.depth.setLocked( true ); + + // set up stencil + + let writeValue, clearValue; + + if ( this.inverse ) { + + writeValue = 0; + clearValue = 1; + + } else { + + writeValue = 1; + clearValue = 0; + + } + + state.buffers.stencil.setTest( true ); + state.buffers.stencil.setOp( context.REPLACE, context.REPLACE, context.REPLACE ); + state.buffers.stencil.setFunc( context.ALWAYS, writeValue, 0xffffffff ); + state.buffers.stencil.setClear( clearValue ); + state.buffers.stencil.setLocked( true ); + + // draw into the stencil buffer + + renderer.setRenderTarget( readBuffer ); + if ( this.clear ) renderer.clear(); + renderer.render( this.scene, this.camera ); + + renderer.setRenderTarget( writeBuffer ); + if ( this.clear ) renderer.clear(); + renderer.render( this.scene, this.camera ); + + // unlock color and depth buffer for subsequent rendering + + state.buffers.color.setLocked( false ); + state.buffers.depth.setLocked( false ); + + // only render where stencil is set to 1 + + state.buffers.stencil.setLocked( false ); + state.buffers.stencil.setFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1 + state.buffers.stencil.setOp( context.KEEP, context.KEEP, context.KEEP ); + state.buffers.stencil.setLocked( true ); + + } + +} + +class ClearMaskPass extends Pass { + + constructor() { + + super(); + + this.needsSwap = false; + + } + + render( renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */ ) { + + renderer.state.buffers.stencil.setLocked( false ); + renderer.state.buffers.stencil.setTest( false ); + + } + +} + +export { MaskPass, ClearMaskPass }; diff --git a/libs/three.js/r171/examples/jsm/postprocessing/Pass.js b/libs/three.js/r171/examples/jsm/postprocessing/Pass.js new file mode 100644 index 000000000..a81582d13 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/postprocessing/Pass.js @@ -0,0 +1,95 @@ +import { + BufferGeometry, + Float32BufferAttribute, + OrthographicCamera, + Mesh +} from 'three'; + +class Pass { + + constructor() { + + this.isPass = true; + + // if set to true, the pass is processed by the composer + this.enabled = true; + + // if set to true, the pass indicates to swap read and write buffer after rendering + this.needsSwap = true; + + // if set to true, the pass clears its buffer before rendering + this.clear = false; + + // if set to true, the result of the pass is rendered to screen. This is set automatically by EffectComposer. + this.renderToScreen = false; + + } + + setSize( /* width, height */ ) {} + + render( /* renderer, writeBuffer, readBuffer, deltaTime, maskActive */ ) { + + console.error( 'THREE.Pass: .render() must be implemented in derived pass.' ); + + } + + dispose() {} + +} + +// Helper for passes that need to fill the viewport with a single quad. + +const _camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 ); + +// https://github.com/mrdoob/three.js/pull/21358 + +class FullscreenTriangleGeometry extends BufferGeometry { + + constructor() { + + super(); + + this.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) ); + + } + +} + +const _geometry = new FullscreenTriangleGeometry(); + +class FullScreenQuad { + + constructor( material ) { + + this._mesh = new Mesh( _geometry, material ); + + } + + dispose() { + + this._mesh.geometry.dispose(); + + } + + render( renderer ) { + + renderer.render( this._mesh, _camera ); + + } + + get material() { + + return this._mesh.material; + + } + + set material( value ) { + + this._mesh.material = value; + + } + +} + +export { Pass, FullScreenQuad }; diff --git a/libs/three.js/r171/examples/jsm/postprocessing/RenderPass.js b/libs/three.js/r171/examples/jsm/postprocessing/RenderPass.js new file mode 100644 index 000000000..c60e92d33 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/postprocessing/RenderPass.js @@ -0,0 +1,99 @@ +import { + Color +} from 'three'; +import { Pass } from './Pass.js'; + +class RenderPass extends Pass { + + constructor( scene, camera, overrideMaterial = null, clearColor = null, clearAlpha = null ) { + + super(); + + this.scene = scene; + this.camera = camera; + + this.overrideMaterial = overrideMaterial; + + this.clearColor = clearColor; + this.clearAlpha = clearAlpha; + + this.clear = true; + this.clearDepth = false; + this.needsSwap = false; + this._oldClearColor = new Color(); + + } + + render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) { + + const oldAutoClear = renderer.autoClear; + renderer.autoClear = false; + + let oldClearAlpha, oldOverrideMaterial; + + if ( this.overrideMaterial !== null ) { + + oldOverrideMaterial = this.scene.overrideMaterial; + + this.scene.overrideMaterial = this.overrideMaterial; + + } + + if ( this.clearColor !== null ) { + + renderer.getClearColor( this._oldClearColor ); + renderer.setClearColor( this.clearColor, renderer.getClearAlpha() ); + + } + + if ( this.clearAlpha !== null ) { + + oldClearAlpha = renderer.getClearAlpha(); + renderer.setClearAlpha( this.clearAlpha ); + + } + + if ( this.clearDepth == true ) { + + renderer.clearDepth(); + + } + + renderer.setRenderTarget( this.renderToScreen ? null : readBuffer ); + + if ( this.clear === true ) { + + // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600 + renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); + + } + + renderer.render( this.scene, this.camera ); + + // restore + + if ( this.clearColor !== null ) { + + renderer.setClearColor( this._oldClearColor ); + + } + + if ( this.clearAlpha !== null ) { + + renderer.setClearAlpha( oldClearAlpha ); + + } + + if ( this.overrideMaterial !== null ) { + + this.scene.overrideMaterial = oldOverrideMaterial; + + } + + renderer.autoClear = oldAutoClear; + + } + +} + +export { RenderPass }; diff --git a/libs/three.js/r171/examples/jsm/postprocessing/ShaderPass.js b/libs/three.js/r171/examples/jsm/postprocessing/ShaderPass.js new file mode 100644 index 000000000..597016c99 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/postprocessing/ShaderPass.js @@ -0,0 +1,77 @@ +import { + ShaderMaterial, + UniformsUtils +} from 'three'; +import { Pass, FullScreenQuad } from './Pass.js'; + +class ShaderPass extends Pass { + + constructor( shader, textureID ) { + + super(); + + this.textureID = ( textureID !== undefined ) ? textureID : 'tDiffuse'; + + if ( shader instanceof ShaderMaterial ) { + + this.uniforms = shader.uniforms; + + this.material = shader; + + } else if ( shader ) { + + this.uniforms = UniformsUtils.clone( shader.uniforms ); + + this.material = new ShaderMaterial( { + + name: ( shader.name !== undefined ) ? shader.name : 'unspecified', + defines: Object.assign( {}, shader.defines ), + uniforms: this.uniforms, + vertexShader: shader.vertexShader, + fragmentShader: shader.fragmentShader + + } ); + + } + + this.fsQuad = new FullScreenQuad( this.material ); + + } + + render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) { + + if ( this.uniforms[ this.textureID ] ) { + + this.uniforms[ this.textureID ].value = readBuffer.texture; + + } + + this.fsQuad.material = this.material; + + if ( this.renderToScreen ) { + + renderer.setRenderTarget( null ); + this.fsQuad.render( renderer ); + + } else { + + renderer.setRenderTarget( writeBuffer ); + // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600 + if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); + this.fsQuad.render( renderer ); + + } + + } + + dispose() { + + this.material.dispose(); + + this.fsQuad.dispose(); + + } + +} + +export { ShaderPass }; diff --git a/libs/three.js/r171/examples/jsm/postprocessing/UnrealBloomPass.js b/libs/three.js/r171/examples/jsm/postprocessing/UnrealBloomPass.js new file mode 100644 index 000000000..48a244051 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/postprocessing/UnrealBloomPass.js @@ -0,0 +1,415 @@ +import { + AdditiveBlending, + Color, + HalfFloatType, + MeshBasicMaterial, + ShaderMaterial, + UniformsUtils, + Vector2, + Vector3, + WebGLRenderTarget +} from 'three'; +import { Pass, FullScreenQuad } from './Pass.js'; +import { CopyShader } from '../shaders/CopyShader.js'; +import { LuminosityHighPassShader } from '../shaders/LuminosityHighPassShader.js'; + +/** + * UnrealBloomPass is inspired by the bloom pass of Unreal Engine. It creates a + * mip map chain of bloom textures and blurs them with different radii. Because + * of the weighted combination of mips, and because larger blurs are done on + * higher mips, this effect provides good quality and performance. + * + * Reference: + * - https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/Bloom/ + */ +class UnrealBloomPass extends Pass { + + constructor( resolution, strength, radius, threshold ) { + + super(); + + this.strength = ( strength !== undefined ) ? strength : 1; + this.radius = radius; + this.threshold = threshold; + this.resolution = ( resolution !== undefined ) ? new Vector2( resolution.x, resolution.y ) : new Vector2( 256, 256 ); + + // create color only once here, reuse it later inside the render function + this.clearColor = new Color( 0, 0, 0 ); + + // render targets + this.renderTargetsHorizontal = []; + this.renderTargetsVertical = []; + this.nMips = 5; + let resx = Math.round( this.resolution.x / 2 ); + let resy = Math.round( this.resolution.y / 2 ); + + this.renderTargetBright = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } ); + this.renderTargetBright.texture.name = 'UnrealBloomPass.bright'; + this.renderTargetBright.texture.generateMipmaps = false; + + for ( let i = 0; i < this.nMips; i ++ ) { + + const renderTargetHorizontal = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } ); + + renderTargetHorizontal.texture.name = 'UnrealBloomPass.h' + i; + renderTargetHorizontal.texture.generateMipmaps = false; + + this.renderTargetsHorizontal.push( renderTargetHorizontal ); + + const renderTargetVertical = new WebGLRenderTarget( resx, resy, { type: HalfFloatType } ); + + renderTargetVertical.texture.name = 'UnrealBloomPass.v' + i; + renderTargetVertical.texture.generateMipmaps = false; + + this.renderTargetsVertical.push( renderTargetVertical ); + + resx = Math.round( resx / 2 ); + + resy = Math.round( resy / 2 ); + + } + + // luminosity high pass material + + const highPassShader = LuminosityHighPassShader; + this.highPassUniforms = UniformsUtils.clone( highPassShader.uniforms ); + + this.highPassUniforms[ 'luminosityThreshold' ].value = threshold; + this.highPassUniforms[ 'smoothWidth' ].value = 0.01; + + this.materialHighPassFilter = new ShaderMaterial( { + uniforms: this.highPassUniforms, + vertexShader: highPassShader.vertexShader, + fragmentShader: highPassShader.fragmentShader + } ); + + // gaussian blur materials + + this.separableBlurMaterials = []; + const kernelSizeArray = [ 3, 5, 7, 9, 11 ]; + resx = Math.round( this.resolution.x / 2 ); + resy = Math.round( this.resolution.y / 2 ); + + for ( let i = 0; i < this.nMips; i ++ ) { + + this.separableBlurMaterials.push( this.getSeperableBlurMaterial( kernelSizeArray[ i ] ) ); + + this.separableBlurMaterials[ i ].uniforms[ 'invSize' ].value = new Vector2( 1 / resx, 1 / resy ); + + resx = Math.round( resx / 2 ); + + resy = Math.round( resy / 2 ); + + } + + // composite material + + this.compositeMaterial = this.getCompositeMaterial( this.nMips ); + this.compositeMaterial.uniforms[ 'blurTexture1' ].value = this.renderTargetsVertical[ 0 ].texture; + this.compositeMaterial.uniforms[ 'blurTexture2' ].value = this.renderTargetsVertical[ 1 ].texture; + this.compositeMaterial.uniforms[ 'blurTexture3' ].value = this.renderTargetsVertical[ 2 ].texture; + this.compositeMaterial.uniforms[ 'blurTexture4' ].value = this.renderTargetsVertical[ 3 ].texture; + this.compositeMaterial.uniforms[ 'blurTexture5' ].value = this.renderTargetsVertical[ 4 ].texture; + this.compositeMaterial.uniforms[ 'bloomStrength' ].value = strength; + this.compositeMaterial.uniforms[ 'bloomRadius' ].value = 0.1; + + const bloomFactors = [ 1.0, 0.8, 0.6, 0.4, 0.2 ]; + this.compositeMaterial.uniforms[ 'bloomFactors' ].value = bloomFactors; + this.bloomTintColors = [ new Vector3( 1, 1, 1 ), new Vector3( 1, 1, 1 ), new Vector3( 1, 1, 1 ), new Vector3( 1, 1, 1 ), new Vector3( 1, 1, 1 ) ]; + this.compositeMaterial.uniforms[ 'bloomTintColors' ].value = this.bloomTintColors; + + // blend material + + const copyShader = CopyShader; + + this.copyUniforms = UniformsUtils.clone( copyShader.uniforms ); + + this.blendMaterial = new ShaderMaterial( { + uniforms: this.copyUniforms, + vertexShader: copyShader.vertexShader, + fragmentShader: copyShader.fragmentShader, + blending: AdditiveBlending, + depthTest: false, + depthWrite: false, + transparent: true + } ); + + this.enabled = true; + this.needsSwap = false; + + this._oldClearColor = new Color(); + this.oldClearAlpha = 1; + + this.basic = new MeshBasicMaterial(); + + this.fsQuad = new FullScreenQuad( null ); + + } + + dispose() { + + for ( let i = 0; i < this.renderTargetsHorizontal.length; i ++ ) { + + this.renderTargetsHorizontal[ i ].dispose(); + + } + + for ( let i = 0; i < this.renderTargetsVertical.length; i ++ ) { + + this.renderTargetsVertical[ i ].dispose(); + + } + + this.renderTargetBright.dispose(); + + // + + for ( let i = 0; i < this.separableBlurMaterials.length; i ++ ) { + + this.separableBlurMaterials[ i ].dispose(); + + } + + this.compositeMaterial.dispose(); + this.blendMaterial.dispose(); + this.basic.dispose(); + + // + + this.fsQuad.dispose(); + + } + + setSize( width, height ) { + + let resx = Math.round( width / 2 ); + let resy = Math.round( height / 2 ); + + this.renderTargetBright.setSize( resx, resy ); + + for ( let i = 0; i < this.nMips; i ++ ) { + + this.renderTargetsHorizontal[ i ].setSize( resx, resy ); + this.renderTargetsVertical[ i ].setSize( resx, resy ); + + this.separableBlurMaterials[ i ].uniforms[ 'invSize' ].value = new Vector2( 1 / resx, 1 / resy ); + + resx = Math.round( resx / 2 ); + resy = Math.round( resy / 2 ); + + } + + } + + render( renderer, writeBuffer, readBuffer, deltaTime, maskActive ) { + + renderer.getClearColor( this._oldClearColor ); + this.oldClearAlpha = renderer.getClearAlpha(); + const oldAutoClear = renderer.autoClear; + renderer.autoClear = false; + + renderer.setClearColor( this.clearColor, 0 ); + + if ( maskActive ) renderer.state.buffers.stencil.setTest( false ); + + // Render input to screen + + if ( this.renderToScreen ) { + + this.fsQuad.material = this.basic; + this.basic.map = readBuffer.texture; + + renderer.setRenderTarget( null ); + renderer.clear(); + this.fsQuad.render( renderer ); + + } + + // 1. Extract Bright Areas + + this.highPassUniforms[ 'tDiffuse' ].value = readBuffer.texture; + this.highPassUniforms[ 'luminosityThreshold' ].value = this.threshold; + this.fsQuad.material = this.materialHighPassFilter; + + renderer.setRenderTarget( this.renderTargetBright ); + renderer.clear(); + this.fsQuad.render( renderer ); + + // 2. Blur All the mips progressively + + let inputRenderTarget = this.renderTargetBright; + + for ( let i = 0; i < this.nMips; i ++ ) { + + this.fsQuad.material = this.separableBlurMaterials[ i ]; + + this.separableBlurMaterials[ i ].uniforms[ 'colorTexture' ].value = inputRenderTarget.texture; + this.separableBlurMaterials[ i ].uniforms[ 'direction' ].value = UnrealBloomPass.BlurDirectionX; + renderer.setRenderTarget( this.renderTargetsHorizontal[ i ] ); + renderer.clear(); + this.fsQuad.render( renderer ); + + this.separableBlurMaterials[ i ].uniforms[ 'colorTexture' ].value = this.renderTargetsHorizontal[ i ].texture; + this.separableBlurMaterials[ i ].uniforms[ 'direction' ].value = UnrealBloomPass.BlurDirectionY; + renderer.setRenderTarget( this.renderTargetsVertical[ i ] ); + renderer.clear(); + this.fsQuad.render( renderer ); + + inputRenderTarget = this.renderTargetsVertical[ i ]; + + } + + // Composite All the mips + + this.fsQuad.material = this.compositeMaterial; + this.compositeMaterial.uniforms[ 'bloomStrength' ].value = this.strength; + this.compositeMaterial.uniforms[ 'bloomRadius' ].value = this.radius; + this.compositeMaterial.uniforms[ 'bloomTintColors' ].value = this.bloomTintColors; + + renderer.setRenderTarget( this.renderTargetsHorizontal[ 0 ] ); + renderer.clear(); + this.fsQuad.render( renderer ); + + // Blend it additively over the input texture + + this.fsQuad.material = this.blendMaterial; + this.copyUniforms[ 'tDiffuse' ].value = this.renderTargetsHorizontal[ 0 ].texture; + + if ( maskActive ) renderer.state.buffers.stencil.setTest( true ); + + if ( this.renderToScreen ) { + + renderer.setRenderTarget( null ); + this.fsQuad.render( renderer ); + + } else { + + renderer.setRenderTarget( readBuffer ); + this.fsQuad.render( renderer ); + + } + + // Restore renderer settings + + renderer.setClearColor( this._oldClearColor, this.oldClearAlpha ); + renderer.autoClear = oldAutoClear; + + } + + getSeperableBlurMaterial( kernelRadius ) { + + const coefficients = []; + + for ( let i = 0; i < kernelRadius; i ++ ) { + + coefficients.push( 0.39894 * Math.exp( - 0.5 * i * i / ( kernelRadius * kernelRadius ) ) / kernelRadius ); + + } + + return new ShaderMaterial( { + + defines: { + 'KERNEL_RADIUS': kernelRadius + }, + + uniforms: { + 'colorTexture': { value: null }, + 'invSize': { value: new Vector2( 0.5, 0.5 ) }, // inverse texture size + 'direction': { value: new Vector2( 0.5, 0.5 ) }, + 'gaussianCoefficients': { value: coefficients } // precomputed Gaussian coefficients + }, + + vertexShader: + `varying vec2 vUv; + void main() { + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + }`, + + fragmentShader: + `#include + varying vec2 vUv; + uniform sampler2D colorTexture; + uniform vec2 invSize; + uniform vec2 direction; + uniform float gaussianCoefficients[KERNEL_RADIUS]; + + void main() { + float weightSum = gaussianCoefficients[0]; + vec3 diffuseSum = texture2D( colorTexture, vUv ).rgb * weightSum; + for( int i = 1; i < KERNEL_RADIUS; i ++ ) { + float x = float(i); + float w = gaussianCoefficients[i]; + vec2 uvOffset = direction * invSize * x; + vec3 sample1 = texture2D( colorTexture, vUv + uvOffset ).rgb; + vec3 sample2 = texture2D( colorTexture, vUv - uvOffset ).rgb; + diffuseSum += (sample1 + sample2) * w; + weightSum += 2.0 * w; + } + gl_FragColor = vec4(diffuseSum/weightSum, 1.0); + }` + } ); + + } + + getCompositeMaterial( nMips ) { + + return new ShaderMaterial( { + + defines: { + 'NUM_MIPS': nMips + }, + + uniforms: { + 'blurTexture1': { value: null }, + 'blurTexture2': { value: null }, + 'blurTexture3': { value: null }, + 'blurTexture4': { value: null }, + 'blurTexture5': { value: null }, + 'bloomStrength': { value: 1.0 }, + 'bloomFactors': { value: null }, + 'bloomTintColors': { value: null }, + 'bloomRadius': { value: 0.0 } + }, + + vertexShader: + `varying vec2 vUv; + void main() { + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + }`, + + fragmentShader: + `varying vec2 vUv; + uniform sampler2D blurTexture1; + uniform sampler2D blurTexture2; + uniform sampler2D blurTexture3; + uniform sampler2D blurTexture4; + uniform sampler2D blurTexture5; + uniform float bloomStrength; + uniform float bloomRadius; + uniform float bloomFactors[NUM_MIPS]; + uniform vec3 bloomTintColors[NUM_MIPS]; + + float lerpBloomFactor(const in float factor) { + float mirrorFactor = 1.2 - factor; + return mix(factor, mirrorFactor, bloomRadius); + } + + void main() { + gl_FragColor = bloomStrength * ( lerpBloomFactor(bloomFactors[0]) * vec4(bloomTintColors[0], 1.0) * texture2D(blurTexture1, vUv) + + lerpBloomFactor(bloomFactors[1]) * vec4(bloomTintColors[1], 1.0) * texture2D(blurTexture2, vUv) + + lerpBloomFactor(bloomFactors[2]) * vec4(bloomTintColors[2], 1.0) * texture2D(blurTexture3, vUv) + + lerpBloomFactor(bloomFactors[3]) * vec4(bloomTintColors[3], 1.0) * texture2D(blurTexture4, vUv) + + lerpBloomFactor(bloomFactors[4]) * vec4(bloomTintColors[4], 1.0) * texture2D(blurTexture5, vUv) ); + }` + } ); + + } + +} + +UnrealBloomPass.BlurDirectionX = new Vector2( 1.0, 0.0 ); +UnrealBloomPass.BlurDirectionY = new Vector2( 0.0, 1.0 ); + +export { UnrealBloomPass }; diff --git a/libs/three.js/r171/examples/jsm/shaders/CopyShader.js b/libs/three.js/r171/examples/jsm/shaders/CopyShader.js new file mode 100644 index 000000000..8c3f2cd44 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/shaders/CopyShader.js @@ -0,0 +1,45 @@ +/** + * Full-screen textured quad shader + */ + +const CopyShader = { + + name: 'CopyShader', + + uniforms: { + + 'tDiffuse': { value: null }, + 'opacity': { value: 1.0 } + + }, + + vertexShader: /* glsl */` + + varying vec2 vUv; + + void main() { + + vUv = uv; + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + }`, + + fragmentShader: /* glsl */` + + uniform float opacity; + + uniform sampler2D tDiffuse; + + varying vec2 vUv; + + void main() { + + vec4 texel = texture2D( tDiffuse, vUv ); + gl_FragColor = opacity * texel; + + + }` + +}; + +export { CopyShader }; diff --git a/libs/three.js/r171/examples/jsm/shaders/LuminosityHighPassShader.js b/libs/three.js/r171/examples/jsm/shaders/LuminosityHighPassShader.js new file mode 100644 index 000000000..0df9f3e7b --- /dev/null +++ b/libs/three.js/r171/examples/jsm/shaders/LuminosityHighPassShader.js @@ -0,0 +1,64 @@ +import { + Color +} from 'three'; + +/** + * Luminosity + * http://en.wikipedia.org/wiki/Luminosity + */ + +const LuminosityHighPassShader = { + + name: 'LuminosityHighPassShader', + + shaderID: 'luminosityHighPass', + + uniforms: { + + 'tDiffuse': { value: null }, + 'luminosityThreshold': { value: 1.0 }, + 'smoothWidth': { value: 1.0 }, + 'defaultColor': { value: new Color( 0x000000 ) }, + 'defaultOpacity': { value: 0.0 } + + }, + + vertexShader: /* glsl */` + + varying vec2 vUv; + + void main() { + + vUv = uv; + + gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + + }`, + + fragmentShader: /* glsl */` + + uniform sampler2D tDiffuse; + uniform vec3 defaultColor; + uniform float defaultOpacity; + uniform float luminosityThreshold; + uniform float smoothWidth; + + varying vec2 vUv; + + void main() { + + vec4 texel = texture2D( tDiffuse, vUv ); + + float v = luminance( texel.xyz ); + + vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity ); + + float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v ); + + gl_FragColor = mix( outputColor, texel, alpha ); + + }` + +}; + +export { LuminosityHighPassShader }; diff --git a/libs/three.js/r171/examples/jsm/utils/BufferGeometryUtils.js b/libs/three.js/r171/examples/jsm/utils/BufferGeometryUtils.js new file mode 100644 index 000000000..cc3e4ef8e --- /dev/null +++ b/libs/three.js/r171/examples/jsm/utils/BufferGeometryUtils.js @@ -0,0 +1,1373 @@ +import { + BufferAttribute, + BufferGeometry, + Float32BufferAttribute, + InstancedBufferAttribute, + InterleavedBuffer, + InterleavedBufferAttribute, + TriangleFanDrawMode, + TriangleStripDrawMode, + TrianglesDrawMode, + Vector3, +} from 'three'; + +function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) { + + if ( ! MikkTSpace || ! MikkTSpace.isReady ) { + + throw new Error( 'BufferGeometryUtils: Initialized MikkTSpace library required.' ); + + } + + if ( ! geometry.hasAttribute( 'position' ) || ! geometry.hasAttribute( 'normal' ) || ! geometry.hasAttribute( 'uv' ) ) { + + throw new Error( 'BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.' ); + + } + + function getAttributeArray( attribute ) { + + if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) { + + const dstArray = new Float32Array( attribute.count * attribute.itemSize ); + + for ( let i = 0, j = 0; i < attribute.count; i ++ ) { + + dstArray[ j ++ ] = attribute.getX( i ); + dstArray[ j ++ ] = attribute.getY( i ); + + if ( attribute.itemSize > 2 ) { + + dstArray[ j ++ ] = attribute.getZ( i ); + + } + + } + + return dstArray; + + } + + if ( attribute.array instanceof Float32Array ) { + + return attribute.array; + + } + + return new Float32Array( attribute.array ); + + } + + // MikkTSpace algorithm requires non-indexed input. + + const _geometry = geometry.index ? geometry.toNonIndexed() : geometry; + + // Compute vertex tangents. + + const tangents = MikkTSpace.generateTangents( + + getAttributeArray( _geometry.attributes.position ), + getAttributeArray( _geometry.attributes.normal ), + getAttributeArray( _geometry.attributes.uv ) + + ); + + // Texture coordinate convention of glTF differs from the apparent + // default of the MikkTSpace library; .w component must be flipped. + + if ( negateSign ) { + + for ( let i = 3; i < tangents.length; i += 4 ) { + + tangents[ i ] *= - 1; + + } + + } + + // + + _geometry.setAttribute( 'tangent', new BufferAttribute( tangents, 4 ) ); + + if ( geometry !== _geometry ) { + + geometry.copy( _geometry ); + + } + + return geometry; + +} + +/** + * @param {Array} geometries + * @param {Boolean} useGroups + * @return {BufferGeometry} + */ +function mergeGeometries( geometries, useGroups = false ) { + + const isIndexed = geometries[ 0 ].index !== null; + + const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) ); + const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) ); + + const attributes = {}; + const morphAttributes = {}; + + const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative; + + const mergedGeometry = new BufferGeometry(); + + let offset = 0; + + for ( let i = 0; i < geometries.length; ++ i ) { + + const geometry = geometries[ i ]; + let attributesCount = 0; + + // ensure that all geometries are indexed, or none + + if ( isIndexed !== ( geometry.index !== null ) ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' ); + return null; + + } + + // gather attributes, exit early if they're different + + for ( const name in geometry.attributes ) { + + if ( ! attributesUsed.has( name ) ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' ); + return null; + + } + + if ( attributes[ name ] === undefined ) attributes[ name ] = []; + + attributes[ name ].push( geometry.attributes[ name ] ); + + attributesCount ++; + + } + + // ensure geometries have the same number of attributes + + if ( attributesCount !== attributesUsed.size ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' ); + return null; + + } + + // gather morph attributes, exit early if they're different + + if ( morphTargetsRelative !== geometry.morphTargetsRelative ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' ); + return null; + + } + + for ( const name in geometry.morphAttributes ) { + + if ( ! morphAttributesUsed.has( name ) ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' ); + return null; + + } + + if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = []; + + morphAttributes[ name ].push( geometry.morphAttributes[ name ] ); + + } + + if ( useGroups ) { + + let count; + + if ( isIndexed ) { + + count = geometry.index.count; + + } else if ( geometry.attributes.position !== undefined ) { + + count = geometry.attributes.position.count; + + } else { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' ); + return null; + + } + + mergedGeometry.addGroup( offset, count, i ); + + offset += count; + + } + + } + + // merge indices + + if ( isIndexed ) { + + let indexOffset = 0; + const mergedIndex = []; + + for ( let i = 0; i < geometries.length; ++ i ) { + + const index = geometries[ i ].index; + + for ( let j = 0; j < index.count; ++ j ) { + + mergedIndex.push( index.getX( j ) + indexOffset ); + + } + + indexOffset += geometries[ i ].attributes.position.count; + + } + + mergedGeometry.setIndex( mergedIndex ); + + } + + // merge attributes + + for ( const name in attributes ) { + + const mergedAttribute = mergeAttributes( attributes[ name ] ); + + if ( ! mergedAttribute ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.' ); + return null; + + } + + mergedGeometry.setAttribute( name, mergedAttribute ); + + } + + // merge morph attributes + + for ( const name in morphAttributes ) { + + const numMorphTargets = morphAttributes[ name ][ 0 ].length; + + if ( numMorphTargets === 0 ) break; + + mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {}; + mergedGeometry.morphAttributes[ name ] = []; + + for ( let i = 0; i < numMorphTargets; ++ i ) { + + const morphAttributesToMerge = []; + + for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) { + + morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] ); + + } + + const mergedMorphAttribute = mergeAttributes( morphAttributesToMerge ); + + if ( ! mergedMorphAttribute ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.' ); + return null; + + } + + mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute ); + + } + + } + + return mergedGeometry; + +} + +/** + * @param {Array} attributes + * @return {BufferAttribute} + */ +function mergeAttributes( attributes ) { + + let TypedArray; + let itemSize; + let normalized; + let gpuType = - 1; + let arrayLength = 0; + + for ( let i = 0; i < attributes.length; ++ i ) { + + const attribute = attributes[ i ]; + + if ( TypedArray === undefined ) TypedArray = attribute.array.constructor; + if ( TypedArray !== attribute.array.constructor ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' ); + return null; + + } + + if ( itemSize === undefined ) itemSize = attribute.itemSize; + if ( itemSize !== attribute.itemSize ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' ); + return null; + + } + + if ( normalized === undefined ) normalized = attribute.normalized; + if ( normalized !== attribute.normalized ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' ); + return null; + + } + + if ( gpuType === - 1 ) gpuType = attribute.gpuType; + if ( gpuType !== attribute.gpuType ) { + + console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.' ); + return null; + + } + + arrayLength += attribute.count * itemSize; + + } + + const array = new TypedArray( arrayLength ); + const result = new BufferAttribute( array, itemSize, normalized ); + let offset = 0; + + for ( let i = 0; i < attributes.length; ++ i ) { + + const attribute = attributes[ i ]; + if ( attribute.isInterleavedBufferAttribute ) { + + const tupleOffset = offset / itemSize; + for ( let j = 0, l = attribute.count; j < l; j ++ ) { + + for ( let c = 0; c < itemSize; c ++ ) { + + const value = attribute.getComponent( j, c ); + result.setComponent( j + tupleOffset, c, value ); + + } + + } + + } else { + + array.set( attribute.array, offset ); + + } + + offset += attribute.count * itemSize; + + } + + if ( gpuType !== undefined ) { + + result.gpuType = gpuType; + + } + + return result; + +} + +/** + * @param {BufferAttribute} + * @return {BufferAttribute} + */ +export function deepCloneAttribute( attribute ) { + + if ( attribute.isInstancedInterleavedBufferAttribute || attribute.isInterleavedBufferAttribute ) { + + return deinterleaveAttribute( attribute ); + + } + + if ( attribute.isInstancedBufferAttribute ) { + + return new InstancedBufferAttribute().copy( attribute ); + + } + + return new BufferAttribute().copy( attribute ); + +} + +/** + * @param {Array} attributes + * @return {Array} + */ +function interleaveAttributes( attributes ) { + + // Interleaves the provided attributes into an InterleavedBuffer and returns + // a set of InterleavedBufferAttributes for each attribute + let TypedArray; + let arrayLength = 0; + let stride = 0; + + // calculate the length and type of the interleavedBuffer + for ( let i = 0, l = attributes.length; i < l; ++ i ) { + + const attribute = attributes[ i ]; + + if ( TypedArray === undefined ) TypedArray = attribute.array.constructor; + if ( TypedArray !== attribute.array.constructor ) { + + console.error( 'AttributeBuffers of different types cannot be interleaved' ); + return null; + + } + + arrayLength += attribute.array.length; + stride += attribute.itemSize; + + } + + // Create the set of buffer attributes + const interleavedBuffer = new InterleavedBuffer( new TypedArray( arrayLength ), stride ); + let offset = 0; + const res = []; + const getters = [ 'getX', 'getY', 'getZ', 'getW' ]; + const setters = [ 'setX', 'setY', 'setZ', 'setW' ]; + + for ( let j = 0, l = attributes.length; j < l; j ++ ) { + + const attribute = attributes[ j ]; + const itemSize = attribute.itemSize; + const count = attribute.count; + const iba = new InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized ); + res.push( iba ); + + offset += itemSize; + + // Move the data for each attribute into the new interleavedBuffer + // at the appropriate offset + for ( let c = 0; c < count; c ++ ) { + + for ( let k = 0; k < itemSize; k ++ ) { + + iba[ setters[ k ] ]( c, attribute[ getters[ k ] ]( c ) ); + + } + + } + + } + + return res; + +} + +// returns a new, non-interleaved version of the provided attribute +export function deinterleaveAttribute( attribute ) { + + const cons = attribute.data.array.constructor; + const count = attribute.count; + const itemSize = attribute.itemSize; + const normalized = attribute.normalized; + + const array = new cons( count * itemSize ); + let newAttribute; + if ( attribute.isInstancedInterleavedBufferAttribute ) { + + newAttribute = new InstancedBufferAttribute( array, itemSize, normalized, attribute.meshPerAttribute ); + + } else { + + newAttribute = new BufferAttribute( array, itemSize, normalized ); + + } + + for ( let i = 0; i < count; i ++ ) { + + newAttribute.setX( i, attribute.getX( i ) ); + + if ( itemSize >= 2 ) { + + newAttribute.setY( i, attribute.getY( i ) ); + + } + + if ( itemSize >= 3 ) { + + newAttribute.setZ( i, attribute.getZ( i ) ); + + } + + if ( itemSize >= 4 ) { + + newAttribute.setW( i, attribute.getW( i ) ); + + } + + } + + return newAttribute; + +} + +// deinterleaves all attributes on the geometry +export function deinterleaveGeometry( geometry ) { + + const attributes = geometry.attributes; + const morphTargets = geometry.morphTargets; + const attrMap = new Map(); + + for ( const key in attributes ) { + + const attr = attributes[ key ]; + if ( attr.isInterleavedBufferAttribute ) { + + if ( ! attrMap.has( attr ) ) { + + attrMap.set( attr, deinterleaveAttribute( attr ) ); + + } + + attributes[ key ] = attrMap.get( attr ); + + } + + } + + for ( const key in morphTargets ) { + + const attr = morphTargets[ key ]; + if ( attr.isInterleavedBufferAttribute ) { + + if ( ! attrMap.has( attr ) ) { + + attrMap.set( attr, deinterleaveAttribute( attr ) ); + + } + + morphTargets[ key ] = attrMap.get( attr ); + + } + + } + +} + +/** + * @param {BufferGeometry} geometry + * @return {number} + */ +function estimateBytesUsed( geometry ) { + + // Return the estimated memory used by this geometry in bytes + // Calculate using itemSize, count, and BYTES_PER_ELEMENT to account + // for InterleavedBufferAttributes. + let mem = 0; + for ( const name in geometry.attributes ) { + + const attr = geometry.getAttribute( name ); + mem += attr.count * attr.itemSize * attr.array.BYTES_PER_ELEMENT; + + } + + const indices = geometry.getIndex(); + mem += indices ? indices.count * indices.itemSize * indices.array.BYTES_PER_ELEMENT : 0; + return mem; + +} + +/** + * @param {BufferGeometry} geometry + * @param {number} tolerance + * @return {BufferGeometry} + */ +function mergeVertices( geometry, tolerance = 1e-4 ) { + + tolerance = Math.max( tolerance, Number.EPSILON ); + + // Generate an index buffer if the geometry doesn't have one, or optimize it + // if it's already available. + const hashToIndex = {}; + const indices = geometry.getIndex(); + const positions = geometry.getAttribute( 'position' ); + const vertexCount = indices ? indices.count : positions.count; + + // next value for triangle indices + let nextIndex = 0; + + // attributes and new attribute arrays + const attributeNames = Object.keys( geometry.attributes ); + const tmpAttributes = {}; + const tmpMorphAttributes = {}; + const newIndices = []; + const getters = [ 'getX', 'getY', 'getZ', 'getW' ]; + const setters = [ 'setX', 'setY', 'setZ', 'setW' ]; + + // Initialize the arrays, allocating space conservatively. Extra + // space will be trimmed in the last step. + for ( let i = 0, l = attributeNames.length; i < l; i ++ ) { + + const name = attributeNames[ i ]; + const attr = geometry.attributes[ name ]; + + tmpAttributes[ name ] = new attr.constructor( + new attr.array.constructor( attr.count * attr.itemSize ), + attr.itemSize, + attr.normalized + ); + + const morphAttributes = geometry.morphAttributes[ name ]; + if ( morphAttributes ) { + + if ( ! tmpMorphAttributes[ name ] ) tmpMorphAttributes[ name ] = []; + morphAttributes.forEach( ( morphAttr, i ) => { + + const array = new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ); + tmpMorphAttributes[ name ][ i ] = new morphAttr.constructor( array, morphAttr.itemSize, morphAttr.normalized ); + + } ); + + } + + } + + // convert the error tolerance to an amount of decimal places to truncate to + const halfTolerance = tolerance * 0.5; + const exponent = Math.log10( 1 / tolerance ); + const hashMultiplier = Math.pow( 10, exponent ); + const hashAdditive = halfTolerance * hashMultiplier; + for ( let i = 0; i < vertexCount; i ++ ) { + + const index = indices ? indices.getX( i ) : i; + + // Generate a hash for the vertex attributes at the current index 'i' + let hash = ''; + for ( let j = 0, l = attributeNames.length; j < l; j ++ ) { + + const name = attributeNames[ j ]; + const attribute = geometry.getAttribute( name ); + const itemSize = attribute.itemSize; + + for ( let k = 0; k < itemSize; k ++ ) { + + // double tilde truncates the decimal value + hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * hashMultiplier + hashAdditive ) },`; + + } + + } + + // Add another reference to the vertex if it's already + // used by another index + if ( hash in hashToIndex ) { + + newIndices.push( hashToIndex[ hash ] ); + + } else { + + // copy data to the new index in the temporary attributes + for ( let j = 0, l = attributeNames.length; j < l; j ++ ) { + + const name = attributeNames[ j ]; + const attribute = geometry.getAttribute( name ); + const morphAttributes = geometry.morphAttributes[ name ]; + const itemSize = attribute.itemSize; + const newArray = tmpAttributes[ name ]; + const newMorphArrays = tmpMorphAttributes[ name ]; + + for ( let k = 0; k < itemSize; k ++ ) { + + const getterFunc = getters[ k ]; + const setterFunc = setters[ k ]; + newArray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) ); + + if ( morphAttributes ) { + + for ( let m = 0, ml = morphAttributes.length; m < ml; m ++ ) { + + newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttributes[ m ][ getterFunc ]( index ) ); + + } + + } + + } + + } + + hashToIndex[ hash ] = nextIndex; + newIndices.push( nextIndex ); + nextIndex ++; + + } + + } + + // generate result BufferGeometry + const result = geometry.clone(); + for ( const name in geometry.attributes ) { + + const tmpAttribute = tmpAttributes[ name ]; + + result.setAttribute( name, new tmpAttribute.constructor( + tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ), + tmpAttribute.itemSize, + tmpAttribute.normalized, + ) ); + + if ( ! ( name in tmpMorphAttributes ) ) continue; + + for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) { + + const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ]; + + result.morphAttributes[ name ][ j ] = new tmpMorphAttribute.constructor( + tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ), + tmpMorphAttribute.itemSize, + tmpMorphAttribute.normalized, + ); + + } + + } + + // indices + + result.setIndex( newIndices ); + + return result; + +} + +/** + * @param {BufferGeometry} geometry + * @param {number} drawMode + * @return {BufferGeometry} + */ +function toTrianglesDrawMode( geometry, drawMode ) { + + if ( drawMode === TrianglesDrawMode ) { + + console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' ); + return geometry; + + } + + if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) { + + let index = geometry.getIndex(); + + // generate index if not present + + if ( index === null ) { + + const indices = []; + + const position = geometry.getAttribute( 'position' ); + + if ( position !== undefined ) { + + for ( let i = 0; i < position.count; i ++ ) { + + indices.push( i ); + + } + + geometry.setIndex( indices ); + index = geometry.getIndex(); + + } else { + + console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' ); + return geometry; + + } + + } + + // + + const numberOfTriangles = index.count - 2; + const newIndices = []; + + if ( drawMode === TriangleFanDrawMode ) { + + // gl.TRIANGLE_FAN + + for ( let i = 1; i <= numberOfTriangles; i ++ ) { + + newIndices.push( index.getX( 0 ) ); + newIndices.push( index.getX( i ) ); + newIndices.push( index.getX( i + 1 ) ); + + } + + } else { + + // gl.TRIANGLE_STRIP + + for ( let i = 0; i < numberOfTriangles; i ++ ) { + + if ( i % 2 === 0 ) { + + newIndices.push( index.getX( i ) ); + newIndices.push( index.getX( i + 1 ) ); + newIndices.push( index.getX( i + 2 ) ); + + } else { + + newIndices.push( index.getX( i + 2 ) ); + newIndices.push( index.getX( i + 1 ) ); + newIndices.push( index.getX( i ) ); + + } + + } + + } + + if ( ( newIndices.length / 3 ) !== numberOfTriangles ) { + + console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' ); + + } + + // build final geometry + + const newGeometry = geometry.clone(); + newGeometry.setIndex( newIndices ); + newGeometry.clearGroups(); + + return newGeometry; + + } else { + + console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode ); + return geometry; + + } + +} + +/** + * Calculates the morphed attributes of a morphed/skinned BufferGeometry. + * Helpful for Raytracing or Decals. + * @param {Mesh | Line | Points} object An instance of Mesh, Line or Points. + * @return {Object} An Object with original position/normal attributes and morphed ones. + */ +function computeMorphedAttributes( object ) { + + const _vA = new Vector3(); + const _vB = new Vector3(); + const _vC = new Vector3(); + + const _tempA = new Vector3(); + const _tempB = new Vector3(); + const _tempC = new Vector3(); + + const _morphA = new Vector3(); + const _morphB = new Vector3(); + const _morphC = new Vector3(); + + function _calculateMorphedAttributeData( + object, + attribute, + morphAttribute, + morphTargetsRelative, + a, + b, + c, + modifiedAttributeArray + ) { + + _vA.fromBufferAttribute( attribute, a ); + _vB.fromBufferAttribute( attribute, b ); + _vC.fromBufferAttribute( attribute, c ); + + const morphInfluences = object.morphTargetInfluences; + + if ( morphAttribute && morphInfluences ) { + + _morphA.set( 0, 0, 0 ); + _morphB.set( 0, 0, 0 ); + _morphC.set( 0, 0, 0 ); + + for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) { + + const influence = morphInfluences[ i ]; + const morph = morphAttribute[ i ]; + + if ( influence === 0 ) continue; + + _tempA.fromBufferAttribute( morph, a ); + _tempB.fromBufferAttribute( morph, b ); + _tempC.fromBufferAttribute( morph, c ); + + if ( morphTargetsRelative ) { + + _morphA.addScaledVector( _tempA, influence ); + _morphB.addScaledVector( _tempB, influence ); + _morphC.addScaledVector( _tempC, influence ); + + } else { + + _morphA.addScaledVector( _tempA.sub( _vA ), influence ); + _morphB.addScaledVector( _tempB.sub( _vB ), influence ); + _morphC.addScaledVector( _tempC.sub( _vC ), influence ); + + } + + } + + _vA.add( _morphA ); + _vB.add( _morphB ); + _vC.add( _morphC ); + + } + + if ( object.isSkinnedMesh ) { + + object.applyBoneTransform( a, _vA ); + object.applyBoneTransform( b, _vB ); + object.applyBoneTransform( c, _vC ); + + } + + modifiedAttributeArray[ a * 3 + 0 ] = _vA.x; + modifiedAttributeArray[ a * 3 + 1 ] = _vA.y; + modifiedAttributeArray[ a * 3 + 2 ] = _vA.z; + modifiedAttributeArray[ b * 3 + 0 ] = _vB.x; + modifiedAttributeArray[ b * 3 + 1 ] = _vB.y; + modifiedAttributeArray[ b * 3 + 2 ] = _vB.z; + modifiedAttributeArray[ c * 3 + 0 ] = _vC.x; + modifiedAttributeArray[ c * 3 + 1 ] = _vC.y; + modifiedAttributeArray[ c * 3 + 2 ] = _vC.z; + + } + + const geometry = object.geometry; + const material = object.material; + + let a, b, c; + const index = geometry.index; + const positionAttribute = geometry.attributes.position; + const morphPosition = geometry.morphAttributes.position; + const morphTargetsRelative = geometry.morphTargetsRelative; + const normalAttribute = geometry.attributes.normal; + const morphNormal = geometry.morphAttributes.position; + + const groups = geometry.groups; + const drawRange = geometry.drawRange; + let i, j, il, jl; + let group; + let start, end; + + const modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize ); + const modifiedNormal = new Float32Array( normalAttribute.count * normalAttribute.itemSize ); + + if ( index !== null ) { + + // indexed buffer geometry + + if ( Array.isArray( material ) ) { + + for ( i = 0, il = groups.length; i < il; i ++ ) { + + group = groups[ i ]; + + start = Math.max( group.start, drawRange.start ); + end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ); + + for ( j = start, jl = end; j < jl; j += 3 ) { + + a = index.getX( j ); + b = index.getX( j + 1 ); + c = index.getX( j + 2 ); + + _calculateMorphedAttributeData( + object, + positionAttribute, + morphPosition, + morphTargetsRelative, + a, b, c, + modifiedPosition + ); + + _calculateMorphedAttributeData( + object, + normalAttribute, + morphNormal, + morphTargetsRelative, + a, b, c, + modifiedNormal + ); + + } + + } + + } else { + + start = Math.max( 0, drawRange.start ); + end = Math.min( index.count, ( drawRange.start + drawRange.count ) ); + + for ( i = start, il = end; i < il; i += 3 ) { + + a = index.getX( i ); + b = index.getX( i + 1 ); + c = index.getX( i + 2 ); + + _calculateMorphedAttributeData( + object, + positionAttribute, + morphPosition, + morphTargetsRelative, + a, b, c, + modifiedPosition + ); + + _calculateMorphedAttributeData( + object, + normalAttribute, + morphNormal, + morphTargetsRelative, + a, b, c, + modifiedNormal + ); + + } + + } + + } else { + + // non-indexed buffer geometry + + if ( Array.isArray( material ) ) { + + for ( i = 0, il = groups.length; i < il; i ++ ) { + + group = groups[ i ]; + + start = Math.max( group.start, drawRange.start ); + end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ); + + for ( j = start, jl = end; j < jl; j += 3 ) { + + a = j; + b = j + 1; + c = j + 2; + + _calculateMorphedAttributeData( + object, + positionAttribute, + morphPosition, + morphTargetsRelative, + a, b, c, + modifiedPosition + ); + + _calculateMorphedAttributeData( + object, + normalAttribute, + morphNormal, + morphTargetsRelative, + a, b, c, + modifiedNormal + ); + + } + + } + + } else { + + start = Math.max( 0, drawRange.start ); + end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) ); + + for ( i = start, il = end; i < il; i += 3 ) { + + a = i; + b = i + 1; + c = i + 2; + + _calculateMorphedAttributeData( + object, + positionAttribute, + morphPosition, + morphTargetsRelative, + a, b, c, + modifiedPosition + ); + + _calculateMorphedAttributeData( + object, + normalAttribute, + morphNormal, + morphTargetsRelative, + a, b, c, + modifiedNormal + ); + + } + + } + + } + + const morphedPositionAttribute = new Float32BufferAttribute( modifiedPosition, 3 ); + const morphedNormalAttribute = new Float32BufferAttribute( modifiedNormal, 3 ); + + return { + + positionAttribute: positionAttribute, + normalAttribute: normalAttribute, + morphedPositionAttribute: morphedPositionAttribute, + morphedNormalAttribute: morphedNormalAttribute + + }; + +} + +function mergeGroups( geometry ) { + + if ( geometry.groups.length === 0 ) { + + console.warn( 'THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge.' ); + return geometry; + + } + + let groups = geometry.groups; + + // sort groups by material index + + groups = groups.sort( ( a, b ) => { + + if ( a.materialIndex !== b.materialIndex ) return a.materialIndex - b.materialIndex; + + return a.start - b.start; + + } ); + + // create index for non-indexed geometries + + if ( geometry.getIndex() === null ) { + + const positionAttribute = geometry.getAttribute( 'position' ); + const indices = []; + + for ( let i = 0; i < positionAttribute.count; i += 3 ) { + + indices.push( i, i + 1, i + 2 ); + + } + + geometry.setIndex( indices ); + + } + + // sort index + + const index = geometry.getIndex(); + + const newIndices = []; + + for ( let i = 0; i < groups.length; i ++ ) { + + const group = groups[ i ]; + + const groupStart = group.start; + const groupLength = groupStart + group.count; + + for ( let j = groupStart; j < groupLength; j ++ ) { + + newIndices.push( index.getX( j ) ); + + } + + } + + geometry.dispose(); // Required to force buffer recreation + geometry.setIndex( newIndices ); + + // update groups indices + + let start = 0; + + for ( let i = 0; i < groups.length; i ++ ) { + + const group = groups[ i ]; + + group.start = start; + start += group.count; + + } + + // merge groups + + let currentGroup = groups[ 0 ]; + + geometry.groups = [ currentGroup ]; + + for ( let i = 1; i < groups.length; i ++ ) { + + const group = groups[ i ]; + + if ( currentGroup.materialIndex === group.materialIndex ) { + + currentGroup.count += group.count; + + } else { + + currentGroup = group; + geometry.groups.push( currentGroup ); + + } + + } + + return geometry; + +} + + +/** + * Modifies the supplied geometry if it is non-indexed, otherwise creates a new, + * non-indexed geometry. Returns the geometry with smooth normals everywhere except + * faces that meet at an angle greater than the crease angle. + * + * @param {BufferGeometry} geometry + * @param {number} [creaseAngle] + * @return {BufferGeometry} + */ +function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */ ) { + + const creaseDot = Math.cos( creaseAngle ); + const hashMultiplier = ( 1 + 1e-10 ) * 1e2; + + // reusable vectors + const verts = [ new Vector3(), new Vector3(), new Vector3() ]; + const tempVec1 = new Vector3(); + const tempVec2 = new Vector3(); + const tempNorm = new Vector3(); + const tempNorm2 = new Vector3(); + + // hashes a vector + function hashVertex( v ) { + + const x = ~ ~ ( v.x * hashMultiplier ); + const y = ~ ~ ( v.y * hashMultiplier ); + const z = ~ ~ ( v.z * hashMultiplier ); + return `${x},${y},${z}`; + + } + + // BufferGeometry.toNonIndexed() warns if the geometry is non-indexed + // and returns the original geometry + const resultGeometry = geometry.index ? geometry.toNonIndexed() : geometry; + const posAttr = resultGeometry.attributes.position; + const vertexMap = {}; + + // find all the normals shared by commonly located vertices + for ( let i = 0, l = posAttr.count / 3; i < l; i ++ ) { + + const i3 = 3 * i; + const a = verts[ 0 ].fromBufferAttribute( posAttr, i3 + 0 ); + const b = verts[ 1 ].fromBufferAttribute( posAttr, i3 + 1 ); + const c = verts[ 2 ].fromBufferAttribute( posAttr, i3 + 2 ); + + tempVec1.subVectors( c, b ); + tempVec2.subVectors( a, b ); + + // add the normal to the map for all vertices + const normal = new Vector3().crossVectors( tempVec1, tempVec2 ).normalize(); + for ( let n = 0; n < 3; n ++ ) { + + const vert = verts[ n ]; + const hash = hashVertex( vert ); + if ( ! ( hash in vertexMap ) ) { + + vertexMap[ hash ] = []; + + } + + vertexMap[ hash ].push( normal ); + + } + + } + + // average normals from all vertices that share a common location if they are within the + // provided crease threshold + const normalArray = new Float32Array( posAttr.count * 3 ); + const normAttr = new BufferAttribute( normalArray, 3, false ); + for ( let i = 0, l = posAttr.count / 3; i < l; i ++ ) { + + // get the face normal for this vertex + const i3 = 3 * i; + const a = verts[ 0 ].fromBufferAttribute( posAttr, i3 + 0 ); + const b = verts[ 1 ].fromBufferAttribute( posAttr, i3 + 1 ); + const c = verts[ 2 ].fromBufferAttribute( posAttr, i3 + 2 ); + + tempVec1.subVectors( c, b ); + tempVec2.subVectors( a, b ); + + tempNorm.crossVectors( tempVec1, tempVec2 ).normalize(); + + // average all normals that meet the threshold and set the normal value + for ( let n = 0; n < 3; n ++ ) { + + const vert = verts[ n ]; + const hash = hashVertex( vert ); + const otherNormals = vertexMap[ hash ]; + tempNorm2.set( 0, 0, 0 ); + + for ( let k = 0, lk = otherNormals.length; k < lk; k ++ ) { + + const otherNorm = otherNormals[ k ]; + if ( tempNorm.dot( otherNorm ) > creaseDot ) { + + tempNorm2.add( otherNorm ); + + } + + } + + tempNorm2.normalize(); + normAttr.setXYZ( i3 + n, tempNorm2.x, tempNorm2.y, tempNorm2.z ); + + } + + } + + resultGeometry.setAttribute( 'normal', normAttr ); + return resultGeometry; + +} + +export { + computeMikkTSpaceTangents, + mergeGeometries, + mergeAttributes, + interleaveAttributes, + estimateBytesUsed, + mergeVertices, + toTrianglesDrawMode, + computeMorphedAttributes, + mergeGroups, + toCreasedNormals +}; diff --git a/libs/three.js/r171/examples/jsm/utils/WebGLTextureUtils.js b/libs/three.js/r171/examples/jsm/utils/WebGLTextureUtils.js new file mode 100644 index 000000000..625c7354d --- /dev/null +++ b/libs/three.js/r171/examples/jsm/utils/WebGLTextureUtils.js @@ -0,0 +1,99 @@ +import { + PlaneGeometry, + ShaderMaterial, + Uniform, + Mesh, + PerspectiveCamera, + Scene, + WebGLRenderer, + CanvasTexture, + SRGBColorSpace +} from 'three'; + +let _renderer; +let fullscreenQuadGeometry; +let fullscreenQuadMaterial; +let fullscreenQuad; + +export function decompress( texture, maxTextureSize = Infinity, renderer = null ) { + + if ( ! fullscreenQuadGeometry ) fullscreenQuadGeometry = new PlaneGeometry( 2, 2, 1, 1 ); + if ( ! fullscreenQuadMaterial ) fullscreenQuadMaterial = new ShaderMaterial( { + uniforms: { blitTexture: new Uniform( texture ) }, + vertexShader: ` + varying vec2 vUv; + void main(){ + vUv = uv; + gl_Position = vec4(position.xy * 1.0,0.,.999999); + }`, + fragmentShader: ` + uniform sampler2D blitTexture; + varying vec2 vUv; + + void main(){ + gl_FragColor = vec4(vUv.xy, 0, 1); + + #ifdef IS_SRGB + gl_FragColor = sRGBTransferOETF( texture2D( blitTexture, vUv) ); + #else + gl_FragColor = texture2D( blitTexture, vUv); + #endif + }` + } ); + + fullscreenQuadMaterial.uniforms.blitTexture.value = texture; + fullscreenQuadMaterial.defines.IS_SRGB = texture.colorSpace == SRGBColorSpace; + fullscreenQuadMaterial.needsUpdate = true; + + if ( ! fullscreenQuad ) { + + fullscreenQuad = new Mesh( fullscreenQuadGeometry, fullscreenQuadMaterial ); + fullscreenQuad.frustumCulled = false; + + } + + const _camera = new PerspectiveCamera(); + const _scene = new Scene(); + _scene.add( fullscreenQuad ); + + if ( renderer === null ) { + + renderer = _renderer = new WebGLRenderer( { antialias: false } ); + + } + + const width = Math.min( texture.image.width, maxTextureSize ); + const height = Math.min( texture.image.height, maxTextureSize ); + + renderer.setSize( width, height ); + renderer.clear(); + renderer.render( _scene, _camera ); + + const canvas = document.createElement( 'canvas' ); + const context = canvas.getContext( '2d' ); + + canvas.width = width; + canvas.height = height; + + context.drawImage( renderer.domElement, 0, 0, width, height ); + + const readableTexture = new CanvasTexture( canvas ); + + readableTexture.minFilter = texture.minFilter; + readableTexture.magFilter = texture.magFilter; + readableTexture.wrapS = texture.wrapS; + readableTexture.wrapT = texture.wrapT; + readableTexture.colorSpace = texture.colorSpace; + readableTexture.name = texture.name; + + if ( _renderer ) { + + _renderer.forceContextLoss(); + _renderer.dispose(); + _renderer = null; + + } + + return readableTexture; + +} diff --git a/libs/three.js/r171/examples/jsm/utils/WebGPUTextureUtils.js b/libs/three.js/r171/examples/jsm/utils/WebGPUTextureUtils.js new file mode 100644 index 000000000..2da2ae994 --- /dev/null +++ b/libs/three.js/r171/examples/jsm/utils/WebGPUTextureUtils.js @@ -0,0 +1,64 @@ +import { + QuadMesh, + NodeMaterial, + WebGPURenderer, + CanvasTexture +} from 'three'; +import { texture, uv } from 'three/tsl'; + +let _renderer; +const _quadMesh = /*@__PURE__*/ new QuadMesh(); + +export async function decompress( blitTexture, maxTextureSize = Infinity, renderer = null ) { + + if ( renderer === null ) { + + renderer = _renderer = new WebGPURenderer(); + await renderer.init(); + + } + + const material = new NodeMaterial(); + + material.fragmentNode = texture( blitTexture, uv().flipY() ); + + const width = Math.min( blitTexture.image.width, maxTextureSize ); + const height = Math.min( blitTexture.image.height, maxTextureSize ); + + const currentOutputColorSpace = renderer.outputColorSpace; + + renderer.setSize( width, height ); + renderer.outputColorSpace = blitTexture.colorSpace; + + _quadMesh.material = material; + _quadMesh.render( renderer ); + + renderer.outputColorSpace = currentOutputColorSpace; + + const canvas = document.createElement( 'canvas' ); + const context = canvas.getContext( '2d' ); + + canvas.width = width; + canvas.height = height; + + context.drawImage( renderer.domElement, 0, 0, width, height ); + + const readableTexture = new CanvasTexture( canvas ); + + readableTexture.minFilter = blitTexture.minFilter; + readableTexture.magFilter = blitTexture.magFilter; + readableTexture.wrapS = blitTexture.wrapS; + readableTexture.wrapT = blitTexture.wrapT; + readableTexture.colorSpace = blitTexture.colorSpace; + readableTexture.name = blitTexture.name; + + if ( _renderer !== null ) { + + _renderer.dispose(); + _renderer = null; + + } + + return readableTexture; + +} diff --git a/libs/three.js/r171/examples/jsm/utils/WorkerPool.js b/libs/three.js/r171/examples/jsm/utils/WorkerPool.js new file mode 100644 index 000000000..7c4e288af --- /dev/null +++ b/libs/three.js/r171/examples/jsm/utils/WorkerPool.js @@ -0,0 +1,102 @@ +/** + * @author Deepkolos / https://github.com/deepkolos + */ + +export class WorkerPool { + + constructor ( pool = 4 ) { + + this.pool = pool; + this.queue = []; + this.workers = []; + this.workersResolve = []; + this.workerStatus = 0; + + } + + _initWorker ( workerId ) { + + if ( !this.workers[ workerId ] ) { + + const worker = this.workerCreator(); + worker.addEventListener( 'message', this._onMessage.bind( this, workerId ) ); + this.workers[ workerId ] = worker; + + } + + } + + _getIdleWorker () { + + for ( let i = 0 ; i < this.pool ; i ++ ) + if ( ! ( this.workerStatus & ( 1 << i ) ) ) return i; + + return -1; + + } + + _onMessage( workerId, msg ) { + + const resolve = this.workersResolve[ workerId ]; + resolve && resolve( msg ); + + if ( this.queue.length ) { + + const { resolve, msg, transfer } = this.queue.shift(); + this.workersResolve[ workerId ] = resolve; + this.workers[ workerId ].postMessage( msg, transfer ); + + } else { + + this.workerStatus ^= 1 << workerId; + + } + + } + + setWorkerCreator ( workerCreator ) { + + this.workerCreator = workerCreator; + + } + + setWorkerLimit ( pool ) { + + this.pool = pool; + + } + + postMessage ( msg, transfer ) { + + return new Promise( ( resolve ) => { + + const workerId = this._getIdleWorker(); + + if ( workerId !== -1 ) { + + this._initWorker( workerId ); + this.workerStatus |= 1 << workerId; + this.workersResolve[ workerId ] = resolve; + this.workers[ workerId ].postMessage( msg, transfer ); + + } else { + + this.queue.push( { resolve, msg, transfer } ); + + } + + } ); + + } + + dispose () { + + this.workers.forEach( ( worker ) => worker.terminate() ); + this.workersResolve.length = 0; + this.workers.length = 0; + this.queue.length = 0; + this.workerStatus = 0; + + } + +}