From b4528cf40fe4ca65c2c93cedc6040c959a6a8dab Mon Sep 17 00:00:00 2001 From: George Hastings Date: Wed, 26 Jun 2024 22:06:57 -0400 Subject: [PATCH 1/7] made updates --- dist/curtains.umd.js | 1322 ++++++++++++----------- dist/curtains.umd.min.js | 2 +- src/core/Curtains.js | 816 +++++++-------- src/core/Renderer.js | 1312 ++++++++++++----------- src/core/Texture.js | 2142 +++++++++++++++++++++----------------- 5 files changed, 2938 insertions(+), 2656 deletions(-) diff --git a/dist/curtains.umd.js b/dist/curtains.umd.js index e2718ce..47cfa71 100644 --- a/dist/curtains.umd.js +++ b/dist/curtains.umd.js @@ -69,7 +69,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Check whether a number is power of 2 - params: + params: @value (float): number to check ***/ @@ -79,7 +79,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Linear interpolation between two numbers - params: + params: @start (float): value to lerp @end (float): end value to use for lerp @amount (float): amount of lerp @@ -92,9 +92,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Here we create our Scene object The Scene will stack all the objects that will be drawn (planes and shader passes) in different arrays, and call them in the right order to be drawn. - Based on the concept exposed here https://webgl2fundamentals.org/webgl/lessons/webgl-drawing-multiple-things.html + Based on the concept exposed here https://webgl2fundamentals.org/webgl/lessons/webgl-drawing-multiple-things.html The idea is to optimize the order of the rendered object so that the WebGL calls are kept to a strict minimum - Here's the whole draw process order: + Here's the whole draw process order: - first we draw the ping pong planes - if needed, we bind the first scene pass frame buffer - draw all the planes that are rendered onto a render target (render pass) @@ -104,9 +104,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi - draw the transparent planes ordered by renderOrder, Z positions, geometry IDs and then indexes (first added first drawn) - draw the opaque planes ordered by renderOrder, geometry IDs and then indexes (first added first drawn) - draw the scene passes content - params: + params: @renderer (Renderer class object): our renderer class object - returns : + returns : @this: our Scene ***/ @@ -198,7 +198,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Add a plane to our renderTargets stack - params: + params: @plane (Plane object): plane to add to our stack ***/ @@ -255,9 +255,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Rebuilds our regular stack (transparent or opaque) with our plane added, geometry IDs and then indexes (first added first drawn) - params: + params: @plane (Plane object): plane to add to our stack - returns: + returns: @planeStack (array): our transparent or opaque stack ready to be applied custom sorting filter ***/ @@ -294,8 +294,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi - renderTargets array is ordered by render target creation order, planes renderOrder value and then planes indexes (order of creation) - transparent array is ordered by renderOrder, Z positions, geometry IDs and then indexes (first added first drawn) - opaque array is ordered by renderOrder, geometry IDs and then indexes (first added first drawn) - This is done to improve speed and reduce GL calls - params: + This is done to improve speed and reduce GL calls + params: @plane (Plane object): plane to add to our scene ***/ @@ -335,7 +335,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This function will remove a plane from our scene. This just reset the plane stacks for now. Useful if we'd want to change the way our draw stacks work and keep the logic separated from our renderer - params: + params: @plane (Plane object): plane to remove from our scene ***/ @@ -364,7 +364,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Changing the position of a plane inside the correct plane stack to render it on above or behind the other planes - params: + params: @plane (Plane object): the plane that had its renderOrder property updated ***/ @@ -450,7 +450,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Add a shader pass to the stack - params: + params: @shaderPass (ShaderPass object): shaderPass to add to our scene ***/ @@ -468,7 +468,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This function will remove a shader pass from our scene. This just reset the shaderPass stacks for now. Useful if we'd want to change the way our draw stacks work and keep the logic separated from our renderer - params: + params: @shaderPass (ShaderPass object): shader pass to remove from our scene ***/ @@ -479,7 +479,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sorts the shader pass stack by index then by renderOrder property - params: + params: @passStack (array): which shader pass stack (scenePasses or renderPasses) to sort ***/ @@ -608,7 +608,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create a CacheManager class object This will store geometries attributes arrays, textures and WebGL programs in arrays This helps speed up slow synchronous CPU operations such as WebGL shaders compilations, images decoding, etc. - returns : + returns : @this: our CacheManager class object ***/ @@ -638,7 +638,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Check if this geometry is already in our cached geometries array - params: + params: @definitionID (integer): the geometry ID ***/ @@ -651,7 +651,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Add a geometry to our cache if not already in it - params: + params: @definitionID (integer): the geometry ID to add to our cache @vertices (array): vertices coordinates array to add to our cache @uvs (array): uvs coordinates array to add to our cache @@ -670,10 +670,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Compare two shaders strings to detect whether they are equal or not - params: + params: @firstShader (string): shader code @secondShader (string): shader code - returns: + returns: @isSameShader (bool): whether both shaders are equal or not ***/ @@ -684,10 +684,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Returns a program from our cache if this program's vertex and fragment shaders code are the same as the one provided - params: + params: @vsCode (string): vertex shader code @fsCode (string): fragment shader code - returns: + returns: @program (Program class object or null): our program if it has been found ***/ @@ -702,7 +702,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Add a program to our cache - params : + params : @program (Program class object) : program to add to our cache ***/ @@ -715,7 +715,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Check if this source is already in our cached textures array - params : + params : @source (HTML element) : html image, video or canvas element (only images for now) ***/ @@ -730,7 +730,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Add a texture to our cache if not already in it - params : + params : @texture (Texture class object) : texture to add to our cache ***/ @@ -745,7 +745,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Removes a texture from the cache array - params : + params : @texture (Texture class object) : texture to remove from our cache ***/ @@ -764,7 +764,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Here we create a CallbackQueueManager class object This allows to store callbacks in a queue array with a timeout of 0 to be executed on next render call - returns: + returns: @this: our CallbackQueueManager class object ***/ @@ -787,10 +787,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Adds a callback to our queue list with a timeout of 0 - params: + params: @callback (function): the callback to execute on next render call @keep (bool): whether to keep calling that callback on each rendering call or not (act as a setInterval). Default to false - returns: + returns: @queueItem: the queue item. Allows to keep a track of it and set its keep property to false when needed ***/ @@ -846,14 +846,14 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Will create a Scene class object that will keep tracks of all added objects Will also handle all global WebGL commands, like clearing scene, binding frame buffers, setting depth, blend func, etc. Will use a state object to handle all those commands and keep a track of what is being drawned to avoid redundant WebGL calls. - params: + params: @Curtainsparams see Curtains class object - @onError (function): called when there has been an error while initiating the WebGL context + @onError (function): called when there has been an error while initiating the WebGL context @onSuccess (function): called when the WebGL context has been successfully created @onContextLost (function): called when the WebGL context is lost @onContextRestored (function): called when the WebGL context is restored @onSceneChange (function): called every time an object has been added/removed from the scene - returns : + returns : @this: our Renderer ***/ @@ -940,8 +940,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.initRenderer(); } /*** - Set/reset our context state object - ***/ + Set/reset our context state object + ***/ _createClass(Renderer, [{ @@ -977,8 +977,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }; } /*** - Add a callback queueing manager (execute functions on the next render call, see CallbackQueueManager class object) - ***/ + Add a callback queueing manager (execute functions on the next render call, see CallbackQueueManager class object) + ***/ }, { key: "initCallbackQueueManager", @@ -986,8 +986,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.nextRender = new CallbackQueueManager(); } /*** - Init our renderer - ***/ + Init our renderer + ***/ }, { key: "initRenderer", @@ -1018,9 +1018,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.canvas.addEventListener("webglcontextrestored", this._contextRestoredHandler, false); } /*** - Get all available WebGL extensions based on WebGL used version - Called on init and on context restoration - ***/ + Get all available WebGL extensions based on WebGL used version + Called on init and on context restoration + ***/ }, { key: "getExtensions", @@ -1028,30 +1028,30 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.extensions = []; if (this._isWebGL2) { - this.extensions['EXT_color_buffer_float'] = this.gl.getExtension('EXT_color_buffer_float'); - this.extensions['OES_texture_float_linear'] = this.gl.getExtension('OES_texture_float_linear'); - this.extensions['EXT_texture_filter_anisotropic'] = this.gl.getExtension('EXT_texture_filter_anisotropic'); - this.extensions['WEBGL_lose_context'] = this.gl.getExtension('WEBGL_lose_context'); + this.extensions["EXT_color_buffer_float"] = this.gl.getExtension("EXT_color_buffer_float"); + this.extensions["OES_texture_float_linear"] = this.gl.getExtension("OES_texture_float_linear"); + this.extensions["EXT_texture_filter_anisotropic"] = this.gl.getExtension("EXT_texture_filter_anisotropic"); + this.extensions["WEBGL_lose_context"] = this.gl.getExtension("WEBGL_lose_context"); } else { - this.extensions['OES_vertex_array_object'] = this.gl.getExtension('OES_vertex_array_object'); - this.extensions['OES_texture_float'] = this.gl.getExtension('OES_texture_float'); - this.extensions['OES_texture_float_linear'] = this.gl.getExtension('OES_texture_float_linear'); - this.extensions['OES_texture_half_float'] = this.gl.getExtension('OES_texture_half_float'); - this.extensions['OES_texture_half_float_linear'] = this.gl.getExtension('OES_texture_half_float_linear'); - this.extensions['EXT_texture_filter_anisotropic'] = this.gl.getExtension('EXT_texture_filter_anisotropic'); - this.extensions['OES_element_index_uint'] = this.gl.getExtension('OES_element_index_uint'); - this.extensions['OES_standard_derivatives'] = this.gl.getExtension('OES_standard_derivatives'); - this.extensions['EXT_sRGB'] = this.gl.getExtension('EXT_sRGB'); - this.extensions['WEBGL_depth_texture'] = this.gl.getExtension('WEBGL_depth_texture'); - this.extensions['WEBGL_draw_buffers'] = this.gl.getExtension('WEBGL_draw_buffers'); - this.extensions['WEBGL_lose_context'] = this.gl.getExtension('WEBGL_lose_context'); + this.extensions["OES_vertex_array_object"] = this.gl.getExtension("OES_vertex_array_object"); + this.extensions["OES_texture_float"] = this.gl.getExtension("OES_texture_float"); + this.extensions["OES_texture_float_linear"] = this.gl.getExtension("OES_texture_float_linear"); + this.extensions["OES_texture_half_float"] = this.gl.getExtension("OES_texture_half_float"); + this.extensions["OES_texture_half_float_linear"] = this.gl.getExtension("OES_texture_half_float_linear"); + this.extensions["EXT_texture_filter_anisotropic"] = this.gl.getExtension("EXT_texture_filter_anisotropic"); + this.extensions["OES_element_index_uint"] = this.gl.getExtension("OES_element_index_uint"); + this.extensions["OES_standard_derivatives"] = this.gl.getExtension("OES_standard_derivatives"); + this.extensions["EXT_sRGB"] = this.gl.getExtension("EXT_sRGB"); + this.extensions["WEBGL_depth_texture"] = this.gl.getExtension("WEBGL_depth_texture"); + this.extensions["WEBGL_draw_buffers"] = this.gl.getExtension("WEBGL_draw_buffers"); + this.extensions["WEBGL_lose_context"] = this.gl.getExtension("WEBGL_lose_context"); } } /*** HANDLING CONTEXT LOST/RESTORE ***/ /*** - Called when the WebGL context is lost - ***/ + Called when the WebGL context is lost + ***/ }, { key: "contextLost", @@ -1067,8 +1067,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }); } /*** - Call this method to restore your context - ***/ + Call this method to restore your context + ***/ }, { key: "restoreContext", @@ -1077,12 +1077,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (!this.state.isActive) return; this.initState(); - if (this.gl && this.extensions['WEBGL_lose_context']) { - this.extensions['WEBGL_lose_context'].restoreContext(); + if (this.gl && this.extensions["WEBGL_lose_context"]) { + this.extensions["WEBGL_lose_context"].restoreContext(); } else { if (!this.gl && !this.production) { throwWarning(this.type + ": Could not restore the context because the context is not defined"); - } else if (!this.extensions['WEBGL_lose_context'] && !this.production) { + } else if (!this.extensions["WEBGL_lose_context"] && !this.production) { throwWarning(this.type + ": Could not restore the context because the restore context extension is not defined"); } @@ -1092,10 +1092,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Check that all objects and textures have been restored - returns: - @isRestored (bool): whether everything has been restored or not - ***/ + Check that all objects and textures have been restored + returns: + @isRestored (bool): whether everything has been restored or not + ***/ }, { key: "isContextexFullyRestored", @@ -1145,8 +1145,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return isRestored; } /*** - Called when the WebGL context is restored - ***/ + Called when the WebGL context is restored + ***/ }, { key: "contextRestored", @@ -1201,8 +1201,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** SIZING ***/ /*** - Updates pixelRatio property - ***/ + Updates pixelRatio property + ***/ }, { key: "setPixelRatio", @@ -1210,8 +1210,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.pixelRatio = pixelRatio; } /*** - Set/reset container sizes and WebGL viewport sizes - ***/ + Set/reset container sizes and WebGL viewport sizes + ***/ }, { key: "setSize", @@ -1229,26 +1229,21 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi // this causes wrong bounding client rect calculations, especially negative top value when it shouldn't // to fix this we'll use a dirty but useful workaround // first we check if we're on iOS Safari - - var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/); - var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; - - if (isSafari && iOS) { - // if we are on iOS Safari we'll need a custom function to retrieve our container absolute top position - var getTopOffset = function getTopOffset(el) { - var topOffset = 0; - - while (el && !isNaN(el.offsetTop)) { - topOffset += el.offsetTop - el.scrollTop; - el = el.offsetParent; - } - - return topOffset; - }; // use it to update our top value - - - this._boundingRect.top = getTopOffset(this.container) * this.pixelRatio; - } + // const isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/); + // const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; + // if(isSafari && iOS) { + // // if we are on iOS Safari we'll need a custom function to retrieve our container absolute top position + // function getTopOffset(el) { + // let topOffset = 0; + // while(el && !isNaN(el.offsetTop)) { + // topOffset += el.offsetTop - el.scrollTop; + // el = el.offsetParent; + // } + // return topOffset; + // } + // // use it to update our top value + // this._boundingRect.top = getTopOffset(this.container) * this.pixelRatio; + // } this.canvas.style.width = Math.floor(this._boundingRect.width / this.pixelRatio) + "px"; this.canvas.style.height = Math.floor(this._boundingRect.height / this.pixelRatio) + "px"; @@ -1257,9 +1252,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight); } /*** - Resize all our elements: planes, shader passes and render targets - Their textures will be resized as well - ***/ + Resize all our elements: planes, shader passes and render targets + Their textures will be resized as well + ***/ }, { key: "resize", @@ -1289,8 +1284,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** CLEAR SCENE ***/ /*** - Clear our WebGL scene colors and depth - ***/ + Clear our WebGL scene colors and depth + ***/ }, { key: "clear", @@ -1298,8 +1293,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT); } /*** - Clear our WebGL scene depth - ***/ + Clear our WebGL scene depth + ***/ }, { key: "clearDepth", @@ -1307,8 +1302,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.gl.clear(this.gl.DEPTH_BUFFER_BIT); } /*** - Clear our WebGL scene colors and depth - ***/ + Clear our WebGL scene colors and depth + ***/ }, { key: "clearColor", @@ -1318,11 +1313,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** FRAME BUFFER OBJECTS ***/ /*** - Called to bind or unbind a FBO - params: - @frameBuffer (frameBuffer): if frameBuffer is not null, bind it, unbind it otherwise - @cancelClear (bool / undefined): if we should cancel clearing the frame buffer (typically on init & resize) - ***/ + Called to bind or unbind a FBO + params: + @frameBuffer (frameBuffer): if frameBuffer is not null, bind it, unbind it otherwise + @cancelClear (bool / undefined): if we should cancel clearing the frame buffer (typically on init & resize) + ***/ }, { key: "bindFrameBuffer", @@ -1350,11 +1345,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** DEPTH ***/ /*** - Called to set whether the renderer will handle depth test or not - Depth test is enabled by default - params: - @setDepth (boolean): if we should enable or disable the depth test - ***/ + Called to set whether the renderer will handle depth test or not + Depth test is enabled by default + params: + @setDepth (boolean): if we should enable or disable the depth test + ***/ }, { key: "setDepthTest", @@ -1370,10 +1365,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Called to set the depth buffer behavior - Only available option is gl.LEQUAL at the moment - (see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc) - ***/ + Called to set the depth buffer behavior + Only available option is gl.LEQUAL at the moment + (see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc) + ***/ }, { key: "setDepthFunc", @@ -1383,11 +1378,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** BLENDING ***/ /*** - Whether we should enable or disable the blending state - Used to draw transparent planes - params: - @enableBlending (boolean): if we should enable or disable the blending (default to false) - ***/ + Whether we should enable or disable the blending state + Used to draw transparent planes + params: + @enableBlending (boolean): if we should enable or disable the blending (default to false) + ***/ }, { key: "setBlending", @@ -1405,8 +1400,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Called to set the blending function (transparency) - ***/ + Called to set the blending function (transparency) + ***/ }, { key: "setBlendFunc", @@ -1424,10 +1419,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** FACE CULLING ***/ /*** - Called to set whether we should cull an object face or not - params: - @cullFace (boolean): what face we should cull - ***/ + Called to set whether we should cull an object face or not + params: + @cullFace (boolean): what face we should cull + ***/ }, { key: "setFaceCulling", @@ -1446,10 +1441,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Tell WebGL to use the specified program if it's not already in use - params: - @program (object): a program object - ***/ + Tell WebGL to use the specified program if it's not already in use + params: + @program (object): a program object + ***/ }, { key: "useProgram", @@ -1462,10 +1457,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** PLANES ***/ /*** - Removes a Plane element (that has already been disposed) from the scene and the planes array - params: - @plane (Plane object): the plane to remove - ***/ + Removes a Plane element (that has already been disposed) from the scene and the planes array + params: + @plane (Plane object): the plane to remove + ***/ }, { key: "removePlane", @@ -1486,10 +1481,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** POST PROCESSING ***/ /*** - Completely remove a RenderTarget element - params: - @renderTarget (RenderTarget object): the render target to remove - ***/ + Completely remove a RenderTarget element + params: + @renderTarget (RenderTarget object): the render target to remove + ***/ }, { key: "removeRenderTarget", @@ -1528,10 +1523,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** SHADER PASSES ***/ /*** - Removes a ShaderPass element (that has already been disposed) from the scene and the shaderPasses array - params: - @shaderPass (ShaderPass object): the shader pass to remove - ***/ + Removes a ShaderPass element (that has already been disposed) from the scene and the shaderPasses array + params: + @shaderPass (ShaderPass object): the shader pass to remove + ***/ }, { key: "removeShaderPass", @@ -1550,8 +1545,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.onSceneChange(); } /*** - Enables the render loop - ***/ + Enables the render loop + ***/ }, { key: "enableDrawing", @@ -1559,8 +1554,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.state.drawingEnabled = true; } /*** - Disables the render loop - ***/ + Disables the render loop + ***/ }, { key: "disableDrawing", @@ -1568,8 +1563,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.state.drawingEnabled = false; } /*** - Forces the rendering of the next frame, even if disabled - ***/ + Forces the rendering of the next frame, even if disabled + ***/ }, { key: "needRender", @@ -1577,9 +1572,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.state.forceRender = true; } /*** - Called at each draw call to render our scene and its content - Also execute our nextRender callback queue - ***/ + Called at each draw call to render our scene and its content + Also execute our nextRender callback queue + ***/ }, { key: "render", @@ -1595,8 +1590,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** DISPOSING ***/ /*** - Delete all cached programs - ***/ + Delete all cached programs + ***/ }, { key: "deletePrograms", @@ -1608,8 +1603,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Dispose our WebGL context and all its objects - ***/ + Dispose our WebGL context and all its objects + ***/ }, { key: "dispose", @@ -1649,8 +1644,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi _this6.canvas.removeEventListener("webglrestored", _this6._contextRestoredHandler, false); // lose context - if (_this6.gl && _this6.extensions['WEBGL_lose_context']) { - _this6.extensions['WEBGL_lose_context'].loseContext(); + if (_this6.gl && _this6.extensions["WEBGL_lose_context"]) { + _this6.extensions["WEBGL_lose_context"].loseContext(); } // clear canvas state @@ -1673,14 +1668,14 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create a ScrollManager class object This keeps track of our scroll position, scroll deltas and triggers an onScroll callback Could either listen to the native scroll event or be hooked to any scroll (natural or virtual) scroll event - params: + params: @xOffset (float): scroll along X axis @yOffset (float): scroll along Y axis @lastXDelta (float): last scroll delta along X axis @lastYDelta (float): last scroll delta along Y axis - @shouldWatch (bool): if the scroll manager should listen to the scroll event or not. Default to true. - @onScroll (function): callback to execute each time the scroll values changed - returns: + @shouldWatch (bool): if the scroll manager should listen to the scroll event or not. Default to true. + @onScroll (function): callback to execute each time the scroll values changed + returns: @this: our ScrollManager class object ***/ @@ -1732,7 +1727,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Updates the scroll manager X and Y scroll values as well as last X and Y deltas Internally called by the scroll handler Could be called externally as well if the user wants to handle the scroll by himself - params: + params: @x (float): scroll value along X axis @y (float): scroll value along Y axis ***/ @@ -1769,13 +1764,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return ScrollManager; }(); - - var version = "8.1.6"; /*** Here we create our Curtains object - params: + params: @container (HTML element or string, optional): the container HTML element or ID that will hold our canvas. Could be set later if not passed as parameter here - (WebGL context parameters) + (WebGL context parameters) @alpha (bool, optional): whether the WebGL context should handle transparency. Default to true. @premultipliedAlpha (bool, optional): whether the WebGL context should handle premultiplied alpha. Default to false. @antialias (bool, optional): whether the WebGL context should use the default antialiasing. When using render targets, WebGL disables antialiasing, so you can safely set this to false to improve the performance. Default to true. @@ -1783,16 +1776,17 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi @failIfMajorPerformanceCaveat (bool, optional): whether the WebGL context creation should fail in case of major performance caveat. Default to true. @preserveDrawingBuffer (bool, optional): whether the WebGL context should preserve the drawing buffer. Default to false. @stencil (bool, optional): whether the WebGL context should handle stencil. Default to false. - @autoResize (bool, optional): Whether the library should listen to the window resize event and actually resize the scene. Set it to false if you want to handle this by yourself using the resize() method. Default to true. + @autoResize (bool, optional): Whether the library should listen to the window resize event and actually resize the scene. Set it to false if you want to handle this by yourself using the resize() method. Default to true. @autoRender (bool, optional): Whether the library should create a request animation frame loop to render the scene. Set it to false if you want to handle this by yourself using the render() method. Default to true. @watchScroll (bool, optional): Whether the library should listen to the window scroll event. Set it to false if you want to handle this by yourself. Default to true. - @pixelRatio (float, optional): Defines the pixel ratio value. Use it to limit it on init to increase performance. Default to window.devicePixelRatio. + @pixelRatio (float, optional): Defines the pixel ratio value. Use it to limit it on init to increase performance. Default to window.devicePixelRatio. @renderingScale (float, optional): Use it to downscale your rendering canvas. May improve performance but will decrease quality. Default to 1 (minimum: 0.25, maximum: 1). - @production (bool, optional): Whether the library should throw useful console warnings and errors and check shaders and programs compilation status. Default to false. - returns : + @production (bool, optional): Whether the library should throw useful console warnings and errors and check shaders and programs compilation status. Default to false. + returns : @this: our Renderer ***/ + var Curtains = /*#__PURE__*/function () { function Curtains() { var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, @@ -1856,12 +1850,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Set up our Curtains container and start initializing everything - Called on Curtains instancing if a params container has been provided, could be call afterwards else - Useful with JS frameworks to init our Curtains class globally and then set the container in a canvas component afterwards to fully instantiate everything - params: - @container (HTML element or string): the container HTML element or ID that will hold our canvas - ***/ + Set up our Curtains container and start initializing everything + Called on Curtains instancing if a params container has been provided, could be call afterwards else + Useful with JS frameworks to init our Curtains class globally and then set the container in a canvas component afterwards to fully instantiate everything + params: + @container (HTML element or string): the container HTML element or ID that will hold our canvas + ***/ _createClass(Curtains, [{ @@ -1898,9 +1892,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._initCurtains(); } /*** - Initialize everything that the class will need: WebGL renderer, scroll manager, sizes, listeners - Then starts our animation frame loop if needed - ***/ + Initialize everything that the class will need: WebGL renderer, scroll manager, sizes, listeners + Then starts our animation frame loop if needed + ***/ }, { key: "_initCurtains", @@ -1923,8 +1917,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.container.appendChild(this.canvas); // watermark - - console.log("curtains.js - v" + version); // start rendering + //console.log("curtains.js - v" + version); + // start rendering this._animationFrameID = null; @@ -1935,8 +1929,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** WEBGL CONTEXT ***/ /*** - Initialize the Renderer class object - ***/ + Initialize the Renderer class object + ***/ }, { key: "_initRenderer", @@ -1979,8 +1973,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.canvas = this.renderer.canvas; } /*** - Force our renderer to restore the WebGL context - ***/ + Force our renderer to restore the WebGL context + ***/ }, { key: "restoreContext", @@ -1988,8 +1982,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.restoreContext(); } /*** - This just handles our drawing animation frame - ***/ + This just handles our drawing animation frame + ***/ }, { key: "_animate", @@ -2000,8 +1994,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** RENDERING ***/ /*** - Enables rendering - ***/ + Enables rendering + ***/ }, { key: "enableDrawing", @@ -2009,8 +2003,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.enableDrawing(); } /*** - Disables rendering - ***/ + Disables rendering + ***/ }, { key: "disableDrawing", @@ -2018,8 +2012,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.disableDrawing(); } /*** - Forces the rendering of the next frame, even if disabled - ***/ + Forces the rendering of the next frame, even if disabled + ***/ }, { key: "needRender", @@ -2027,13 +2021,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.needRender(); } /*** - Executes a callback on next frame - params: - @callback (function): callback to execute on next frame - @keep (bool): whether to keep calling that callback on each rendering call or not (act as a setInterval). Default to false - returns: - @queueItem: the queue item. Allows to keep a track of it and set its keep property to false when needed - ***/ + Executes a callback on next frame + params: + @callback (function): callback to execute on next frame + @keep (bool): whether to keep calling that callback on each rendering call or not (act as a setInterval). Default to false + returns: + @queueItem: the queue item. Allows to keep a track of it and set its keep property to false when needed + ***/ }, { key: "nextRender", @@ -2042,8 +2036,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this.renderer.nextRender.add(callback, keep); } /*** - Clear our WebGL renderer colors and depth buffers - ***/ + Clear our WebGL renderer colors and depth buffers + ***/ }, { key: "clear", @@ -2051,8 +2045,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer && this.renderer.clear(); } /*** - Clear our WebGL renderer depth buffer - ***/ + Clear our WebGL renderer depth buffer + ***/ }, { key: "clearDepth", @@ -2060,8 +2054,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer && this.renderer.clearDepth(); } /*** - Clear our WebGL renderer color buffer - ***/ + Clear our WebGL renderer color buffer + ***/ }, { key: "clearColor", @@ -2069,10 +2063,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer && this.renderer.clearColor(); } /*** - Check whether the created context is WebGL2 - return: - @isWebGL2 (bool): whether the created WebGL context is 2.0 or not - ***/ + Check whether the created context is WebGL2 + return: + @isWebGL2 (bool): whether the created WebGL context is 2.0 or not + ***/ }, { key: "isWebGL2", @@ -2080,8 +2074,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this.gl ? this.renderer._isWebGL2 : false; } /*** - Tells our renderer to render the scene if the drawing is enabled - ***/ + Tells our renderer to render the scene if the drawing is enabled + ***/ }, { key: "render", @@ -2109,8 +2103,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** LISTENERS ***/ /*** - Adds our resize event listener if needed - ***/ + Adds our resize event listener if needed + ***/ }, { key: "_addListeners", @@ -2126,8 +2120,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** SIZING ***/ /*** - Set the pixel ratio property and update everything by calling the resize() method - ***/ + Set the pixel ratio property and update everything by calling the resize() method + ***/ }, { key: "setPixelRatio", @@ -2138,8 +2132,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.resize(triggerCallback); } /*** - Set our renderer container and canvas sizes and update the scroll values - ***/ + Set our renderer container and canvas sizes and update the scroll values + ***/ }, { key: "_setSize", @@ -2152,10 +2146,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Useful to get our container bounding rectangle without triggering a reflow/layout - returns : - @boundingRectangle (object): an object containing our container bounding rectangle (width, height, top and left properties) - ***/ + Useful to get our container bounding rectangle without triggering a reflow/layout + returns : + @boundingRectangle (object): an object containing our container bounding rectangle (width, height, top and left properties) + ***/ }, { key: "getBoundingRect", @@ -2163,10 +2157,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this.renderer._boundingRect; } /*** - Resize our container and the renderer - params: - @triggerCallback (bool): Whether we should trigger onAfterResize callback - ***/ + Resize our container and the renderer + params: + @triggerCallback (bool): Whether we should trigger onAfterResize callback + ***/ }, { key: "resize", @@ -2187,8 +2181,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** SCROLL ***/ /*** - Init our ScrollManager class object - ***/ + Init our ScrollManager class object + ***/ }, { key: "_initScroll", @@ -2208,11 +2202,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }); } /*** - Handles the different values associated with a scroll event (scroll and delta values) - If no plane watch the scroll then those values won't be retrieved to avoid unnecessary reflow calls - If at least a plane is watching, update all watching planes positions based on the scroll values - And force render for at least one frame to actually update the scene - ***/ + Handles the different values associated with a scroll event (scroll and delta values) + If no plane watch the scroll then those values won't be retrieved to avoid unnecessary reflow calls + If at least a plane is watching, update all watching planes positions based on the scroll values + And force render for at least one frame to actually update the scene + ***/ }, { key: "_updateScroll", @@ -2229,13 +2223,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._onScrollCallback && this._onScrollCallback(); } /*** - Updates the scroll manager X and Y scroll values as well as last X and Y deltas - Internally called by the scroll handler if at least one plane is watching the scroll - Could be called externally as well if the user wants to handle the scroll by himself - params: - @x (float): scroll value along X axis - @y (float): scroll value along Y axis - ***/ + Updates the scroll manager X and Y scroll values as well as last X and Y deltas + Internally called by the scroll handler if at least one plane is watching the scroll + Could be called externally as well if the user wants to handle the scroll by himself + params: + @x (float): scroll value along X axis + @y (float): scroll value along Y axis + ***/ }, { key: "updateScrollValues", @@ -2243,10 +2237,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._scrollManager.updateScrollValues(x, y); } /*** - Returns last delta scroll values - returns: - @delta (object): an object containing X and Y last delta values - ***/ + Returns last delta scroll values + returns: + @delta (object): an object containing X and Y last delta values + ***/ }, { key: "getScrollDeltas", @@ -2257,10 +2251,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }; } /*** - Returns last window scroll values - returns: - @scrollValues (object): an object containing X and Y last scroll values - ***/ + Returns last window scroll values + returns: + @scrollValues (object): an object containing X and Y last scroll values + ***/ }, { key: "getScrollValues", @@ -2273,8 +2267,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** ADDING / REMOVING OBJECTS TO THE RENDERER ***/ /*** - Always keep sync between renderer and Curtains scene objects when adding/removing objects - ***/ + Always keep sync between renderer and Curtains scene objects when adding/removing objects + ***/ }, { key: "_keepSync", @@ -2286,8 +2280,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** UTILS ***/ /*** - Linear interpolation helper defined in utils - ***/ + Linear interpolation helper defined in utils + ***/ }, { key: "lerp", @@ -2297,12 +2291,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** EVENTS ***/ /*** - This is called each time our container has been resized - params : - @callback (function) : a function to execute - returns : - @this: our Curtains element to handle chaining - ***/ + This is called each time our container has been resized + params : + @callback (function) : a function to execute + returns : + @this: our Curtains element to handle chaining + ***/ }, { key: "onAfterResize", @@ -2314,12 +2308,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This is called when an error has been detected - params: - @callback (function): a function to execute - returns: - @this: our Curtains element to handle chaining - ***/ + This is called when an error has been detected + params: + @callback (function): a function to execute + returns: + @this: our Curtains element to handle chaining + ***/ }, { key: "onError", @@ -2331,8 +2325,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This triggers the onError callback and is called by the renderer when an error has been detected - ***/ + This triggers the onError callback and is called by the renderer when an error has been detected + ***/ }, { key: "_onRendererError", @@ -2349,12 +2343,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }, 0); } /*** - This is called when the WebGL context has been successfully created - params: - @callback (function): a function to execute - returns: - @this: our Curtains element to handle chaining - ***/ + This is called when the WebGL context has been successfully created + params: + @callback (function): a function to execute + returns: + @this: our Curtains element to handle chaining + ***/ }, { key: "onSuccess", @@ -2366,8 +2360,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This triggers the onSuccess callback and is called by the renderer when the context has been successfully created - ***/ + This triggers the onSuccess callback and is called by the renderer when the context has been successfully created + ***/ }, { key: "_onRendererSuccess", @@ -2379,12 +2373,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }, 0); } /*** - This is called once our context has been lost - params: - @callback (function): a function to execute - returns: - @this: our Curtains element to handle chaining - ***/ + This is called once our context has been lost + params: + @callback (function): a function to execute + returns: + @this: our Curtains element to handle chaining + ***/ }, { key: "onContextLost", @@ -2396,8 +2390,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This triggers the onContextLost callback and is called by the renderer when the context has been lost - ***/ + This triggers the onContextLost callback and is called by the renderer when the context has been lost + ***/ }, { key: "_onRendererContextLost", @@ -2405,12 +2399,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._onContextLostCallback && this._onContextLostCallback(); } /*** - This is called once our context has been restored - params: - @callback (function): a function to execute - returns: - @this: our Curtains element to handle chaining - ***/ + This is called once our context has been restored + params: + @callback (function): a function to execute + returns: + @this: our Curtains element to handle chaining + ***/ }, { key: "onContextRestored", @@ -2422,8 +2416,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This triggers the onContextRestored callback and is called by the renderer when the context has been restored - ***/ + This triggers the onContextRestored callback and is called by the renderer when the context has been restored + ***/ }, { key: "_onRendererContextRestored", @@ -2431,12 +2425,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._onContextRestoredCallback && this._onContextRestoredCallback(); } /*** - This is called once at each request animation frame call - params: - @callback (function): a function to execute - returns: - @this: our Curtains element to handle chaining - ***/ + This is called once at each request animation frame call + params: + @callback (function): a function to execute + returns: + @this: our Curtains element to handle chaining + ***/ }, { key: "onRender", @@ -2448,12 +2442,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This is called each time window is scrolled and if our scrollManager is active - params : - @callback (function) : a function to execute - returns : - @this: our Curtains element to handle chaining - ***/ + This is called each time window is scrolled and if our scrollManager is active + params : + @callback (function) : a function to execute + returns : + @this: our Curtains element to handle chaining + ***/ }, { key: "onScroll", @@ -2467,8 +2461,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** DESTROYING ***/ /*** - Dispose everything - ***/ + Dispose everything + ***/ }, { key: "dispose", @@ -2476,8 +2470,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.dispose(); } /*** - This is called when the renderer has finished disposing all the WebGL stuff - ***/ + This is called when the renderer has finished disposing all the WebGL stuff + ***/ }, { key: "_onRendererDisposed", @@ -2494,14 +2488,14 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }(); /*** Uniforms class manages uniforms setting and updating - params: + params: @renderer (Renderer class object): our renderer class object @program (object): our mesh's Program (see Program class object) - @uniforms (object): our uniforms object: + @uniforms (object): our uniforms object: - name (string): uniform name to use in your shaders - type (uniform type): uniform type. Will try to detect it if not set (see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/uniform) - value (float / int / Vec2 / Vec3 / Mat4 / array): initial value of the uniform - returns: + returns: @this: our Uniforms manager ***/ @@ -2541,7 +2535,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Set uniforms WebGL function based on their types - params : + params : @uniform (object): the uniform ***/ @@ -2633,7 +2627,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Auto detect the format of the uniform (check if its a float, an integer, a Vector, a Matrix, an array...) Also set a lastValue property that we'll use to compare to our value property and update the uniform if it changed - params : + params : @uniform (object): the uniform ***/ @@ -2773,7 +2767,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Use appropriate WebGL uniform setting function based on the uniform type - params : + params : @uniform (object): the uniform ***/ @@ -2895,12 +2889,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Program class that creates, compiles and links the shaders Use a cache system to get already compiled shaders and save some CPU Also responsible for the creation, setting and updating of the uniforms (see Uniforms class object) - params: + params: @renderer (Renderer class object): our renderer class object - @parent (Plane/ShaderPass class object): the mesh that will use that program + @parent (Plane/ShaderPass class object): the mesh that will use that program @vertexShader (string): vertex shader as a string @fragmentShader (string): fragment shader as a string - returns: + returns: @this: our newly created Program ***/ // store programs id @@ -2958,10 +2952,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Compile our WebGL shaders based on our written shaders - params: + params: @shaderCode (string): shader code @shaderType (shaderType): WebGL shader type (vertex or fragment) - returns: + returns: @shader (compiled shader): our compiled shader ***/ @@ -3112,7 +3106,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Creates and attach the uniform handlers to our program - params: + params: @uniforms (object): an object describing our uniforms (see Uniforms class object) ***/ @@ -3151,13 +3145,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }(); /*** Geometry class handles attributes, VertexArrayObjects (if available) and vertices/UVs set up - params: + params: @renderer (Renderer class object): our renderer class object - @program (object): our mesh's Program (see Program class object) + @program (object): our mesh's Program (see Program class object) @width (int): number of vertices along width @height (int): number of vertices along height @id (int): an integer based on geometry's width and height and used to avoid redundant buffer binding calls - returns: + returns: @this: our newly created Geometry ***/ @@ -3455,9 +3449,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create a Mat4 class object This is a really basic Matrix4 class used for matrix calculations Highly based on https://github.com/mrdoob/three.js/blob/dev/src/math/Matrix4.js and http://glmatrix.net/docs/mat4.js.html - params : + params : @elements (Float32Array of length 16): our matrix array. Default to identity matrix. - returns : + returns : @this: our Mat4 class object ***/ // TODO lot of (unused at the time) methods are missing @@ -3474,9 +3468,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sets the matrix values from an array - params: + params: @array (array): an array of at least 16 elements - returns: + returns: @this (Mat4 class object): this matrix after being set ***/ @@ -3492,9 +3486,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Copy another Mat4 - params: + params: @matrix (Mat4 class object): matrix to copy - returns: + returns: @this (Mat4 class object): this matrix after copy ***/ @@ -3522,7 +3516,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Clone a matrix - returns: + returns: @clonedMatrix (Mat4 object): cloned matrix ***/ @@ -3533,9 +3527,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Simple matrix multiplication helper - params: + params: @matrix (Mat4 class object): Mat4 to multiply with - returns: + returns: @result (Mat4 class object): Mat4 after multiplication ***/ @@ -3565,7 +3559,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Get matrix inverse - returns: + returns: @result (Mat4 class object): inverted Mat4 ***/ @@ -3631,9 +3625,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Simple Mat4 scaling helper - params : + params : @vector (Vec3 class object): Vec3 representing scale along X, Y and Z axis - returns : + returns : @result (Mat4 class object): Mat4 after scaling ***/ @@ -3659,11 +3653,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Creates a matrix from a quaternion rotation, vector translation and vector scale Equivalent for applying translation, rotation and scale matrices but much faster Source code from: http://glmatrix.net/docs/mat4.js.html - params : + params : @translation (Vec3 class object): translation vector @quaternion (Quat class object): rotation quaternion @scale (Vec3 class object): scale vector - returns : + returns : @this (Mat4 class object): matrix after transformations ***/ @@ -3713,12 +3707,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin Equivalent for applying translation, rotation and scale matrices but much faster Source code from: http://glmatrix.net/docs/mat4.js.html - params : + params : @translation (Vec3 class object): translation vector @quaternion (Quat class object): rotation quaternion @scale (Vec3 class object): scale vector @origin (Vec3 class object): origin vector around which to scale and rotate - returns : + returns : @this (Mat4 class object): matrix after transformations ***/ @@ -3785,10 +3779,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create a Vec2 class object This is a really basic Vector2 class used for vector calculations Highly based on https://github.com/mrdoob/three.js/blob/dev/src/math/Vector2.js and http://glmatrix.net/docs/vec2.js.html - params : + params : @x (float): X component of our vector @y (float): Y component of our vector - returns : + returns : @this: our Vec2 class object ***/ // TODO lot of (unused at the time) methods are missing @@ -3841,10 +3835,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sets the vector from values - params: + params: @x (float): X component of our vector @y (float): Y component of our vector - returns: + returns: @this (Vec2): this vector after being set ***/ @@ -3857,9 +3851,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Adds a vector to this vector - params: + params: @vector (Vec2): vector to add - returns: + returns: @this (Vec2): this vector after addition ***/ @@ -3872,9 +3866,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Adds a scalar to this vector - params: + params: @value (float): number to add - returns: + returns: @this (Vec2): this vector after addition ***/ @@ -3887,9 +3881,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Subtracts a vector from this vector - params: + params: @vector (Vec2): vector to use for subtraction - returns: + returns: @this (Vec2): this vector after subtraction ***/ @@ -3902,9 +3896,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Subtracts a scalar to this vector - params: + params: @value (float): number to use for subtraction - returns: + returns: @this (Vec2): this vector after subtraction ***/ @@ -3917,9 +3911,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Multiplies a vector with this vector - params: + params: @vector (Vec2): vector to use for multiplication - returns: + returns: @this (Vec2): this vector after multiplication ***/ @@ -3932,9 +3926,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Multiplies a scalar with this vector - params: + params: @value (float): number to use for multiplication - returns: + returns: @this (Vec2): this vector after multiplication ***/ @@ -3947,9 +3941,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Copy a vector into this vector - params: + params: @vector (Vec2): vector to copy - returns: + returns: @this (Vec2): this vector after copy ***/ @@ -3962,7 +3956,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Clone this vector - returns: + returns: @vector (Vec2): cloned vector ***/ @@ -3973,9 +3967,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Merges this vector with a vector when values are NaN. Mostly used internally. - params: + params: @vector (Vec2): vector to use for sanitization - returns: + returns: @vector (Vec2): sanitized vector ***/ @@ -3988,9 +3982,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Apply max values to this vector - params: + params: @vector (Vec2): vector representing max values - returns: + returns: @vector (Vec2): vector with max values applied ***/ @@ -4003,9 +3997,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Apply min values to this vector - params: + params: @vector (Vec2): vector representing min values - returns: + returns: @vector (Vec2): vector with min values applied ***/ @@ -4018,9 +4012,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Checks if 2 vectors are equal - params: + params: @vector (Vec2): vector to compare - returns: + returns: @isEqual (bool): whether the vectors are equals or not ***/ @@ -4031,7 +4025,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Normalize this vector - returns: + returns: @this (Vec2): normalized vector ***/ @@ -4051,9 +4045,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Calculates the dot product of 2 vectors - params: + params: @vector (Vec2): vector to use for dot product - returns: + returns: @dotProduct (float): dot product of the 2 vectors ***/ @@ -4070,11 +4064,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create a Vec3 class object This is a really basic Vector3 class used for vector calculations Highly based on https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js and http://glmatrix.net/docs/vec3.js.html - params : + params : @x (float): X component of our vector @y (float): Y component of our vector @z (float): Z component of our vector - returns : + returns : @this: our Vec3 class object ***/ // TODO lot of (unused at the time) methods are missing @@ -4139,11 +4133,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sets the vector from values - params: + params: @x (float): X component of our vector @y (float): Y component of our vector @z (float): Z component of our vector - returns: + returns: @this (Vec2): this vector after being set ***/ @@ -4157,9 +4151,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Adds a vector to this vector - params: + params: @vector (Vec3): vector to add - returns: + returns: @this (Vec3): this vector after addition ***/ @@ -4173,9 +4167,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Adds a scalar to this vector - params: + params: @value (float): number to add - returns: + returns: @this (Vec3): this vector after addition ***/ @@ -4189,9 +4183,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Subtracts a vector from this vector - params: + params: @vector (Vec3): vector to use for subtraction - returns: + returns: @this (Vec3): this vector after subtraction ***/ @@ -4205,9 +4199,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Subtracts a scalar to this vector - params: + params: @value (float): number to use for subtraction - returns: + returns: @this (Vec3): this vector after subtraction ***/ @@ -4221,9 +4215,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Multiplies a vector with this vector - params: + params: @vector (Vec3): vector to use for multiplication - returns: + returns: @this (Vec3): this vector after multiplication ***/ @@ -4237,9 +4231,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Multiplies a scalar with this vector - params: + params: @value (float): number to use for multiplication - returns: + returns: @this (Vec3): this vector after multiplication ***/ @@ -4253,9 +4247,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Copy a vector into this vector - params: + params: @vector (Vec3): vector to copy - returns: + returns: @this (Vec3): this vector after copy ***/ @@ -4269,7 +4263,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Clone this vector - returns: + returns: @vector (Vec3): cloned vector ***/ @@ -4280,9 +4274,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Merges this vector with a vector when values are NaN. Mostly used internally. - params: + params: @vector (Vec3): vector to use for sanitization - returns: + returns: @vector (Vec3): sanitized vector ***/ @@ -4296,9 +4290,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Apply max values to this vector - params: + params: @vector (Vec3): vector representing max values - returns: + returns: @vector (Vec3): vector with max values applied ***/ @@ -4312,9 +4306,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Apply min values to this vector - params: + params: @vector (Vec3): vector representing min values - returns: + returns: @vector (Vec3): vector with min values applied ***/ @@ -4328,7 +4322,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Checks if 2 vectors are equal - returns: + returns: @isEqual (bool): whether the vectors are equals or not ***/ @@ -4339,7 +4333,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Normalize this vector - returns: + returns: @this (Vec3): normalized vector ***/ @@ -4360,7 +4354,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Calculates the dot product of 2 vectors - returns: + returns: @dotProduct (float): dot product of the 2 vectors ***/ @@ -4373,9 +4367,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Apply a matrix 4 to a point (vec3) Useful to convert a point position from plane local world to webgl space using projection view matrix for example Source code from: http://glmatrix.net/docs/vec3.js.html - params : + params : @matrix (array): 4x4 matrix used - returns : + returns : @this (Vec3): this vector after matrix application ***/ @@ -4395,9 +4389,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Apply a quaternion (rotation in 3D space) to this vector - params : + params : @quaternion (Quat): quaternion to use - returns : + returns : @this (Vec3): this vector after applying the transformation ***/ @@ -4424,7 +4418,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Project 3D coordinate to 2D point - params: + params: @camera (Camera): camera to use for projection ***/ @@ -4436,7 +4430,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Unproject 2D point to 3D coordinate - params: + params: @camera (Camera): camera to use for projection ***/ @@ -4452,22 +4446,22 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }(); /*** Texture class objects used by render targets, shader passes and planes. - params: + params: @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object - @isFBOTexture (bool): Whether this texture is used by a render target/frame buffer object. Default to false + @isFBOTexture (bool): Whether this texture is used by a render target/frame buffer object. Default to false @fromTexture (bool): Whether this texture should copy another texture right from init (and avoid creating a new webgl texture). Default to false @loader (TextureLoader class object): loader used to create that texture and load its source. Default to null - @sampler (string): the texture sampler's name that will be used in the shaders - @floatingPoint (string): texture floating point to apply. Could be "float", "half-float" or "none". Default to "none" - @premultiplyAlpha (bool): Whether this texture should handle premultiplied alpha. Default to false + @sampler (string): the texture sampler's name that will be used in the shaders + @floatingPoint (string): texture floating point to apply. Could be "float", "half-float" or "none". Default to "none" + @premultiplyAlpha (bool): Whether this texture should handle premultiplied alpha. Default to false @anisotropy (int): Texture anisotropy (see https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_filter_anisotropic). Default to 1 @generateMipmap (bool): Whether to generate texture mipmaps (see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/generateMipmap). Default to true except for frame buffer objects textures. - see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter + see https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/samplerParameter @wrapS (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate S @wrapT (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate T @minFilter (GLenum): WebGL constant specifying the texture minification filter @magFilter (GLenum): WebGL constant specifying the texture magnification filter - returns: + returns: @this: our newly created Texture class object ***/ // avoid reinstancing those during runtime @@ -4602,9 +4596,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._initTexture(); } /*** - Init per-texture parameters state - Called on init and on context restoration to force parameters settings - ***/ + Init per-texture parameters state + Called on init and on context restoration to force parameters settings + ***/ _createClass(Texture, [{ @@ -4621,8 +4615,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }; } /*** - Init our texture object - ***/ + Init our texture object + ***/ }, { key: "_initTexture", @@ -4644,10 +4638,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** RESTORING CONTEXT ***/ /*** - Restore a WebGL texture that is a copy - Depending on whether it's a copy from start or not, just reset its uniforms or run the full init - And finally copy our original texture back again - ***/ + Restore a WebGL texture that is a copy + Depending on whether it's a copy from start or not, just reset its uniforms or run the full init + And finally copy our original texture back again + ***/ }, { key: "_restoreFromTexture", @@ -4672,10 +4666,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._canDraw = true; } /*** - Restore our WebGL texture - If it is an original texture, just re run the init function and eventually reset its source - If it is a texture set from another texture, wait for the original texture to be ready first - ***/ + Restore our WebGL texture + If it is an original texture, just re run the init function and eventually reset its source + If it is a texture set from another texture, wait for the original texture to be ready first + ***/ }, { key: "_restoreContext", @@ -4731,10 +4725,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** ADD PARENT ***/ /*** - Adds a parent to a texture - Sets its index, its parent and add it to the parent textures array as well - Then runs _setParent() to set the size and uniforms if needed - ***/ + Adds a parent to a texture + Sets its index, its parent and add it to the parent textures array as well + Then runs _setParent() to set the size and uniforms if needed + ***/ }, { key: "addParent", @@ -4758,9 +4752,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._setParent(); } /*** - Sets the parent - Basically sets the uniforms names and locations and sizes - ***/ + Sets the parent + Basically sets the uniforms names and locations and sizes + ***/ }, { key: "_setParent", @@ -4827,10 +4821,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Checks if this texture has a parent - return: - @hasParent (bool): whether this texture has a parent or not - ***/ + Checks if this texture has a parent + return: + @hasParent (bool): whether this texture has a parent or not + ***/ }, { key: "hasParent", @@ -4840,9 +4834,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** SEND DATA TO THE GPU ***/ /*** - Check if our textures is effectively used in our shaders - If so, set it to active, get its uniform locations and bind it to our texture unit - ***/ + Check if our textures is effectively used in our shaders + If so, set it to active, get its uniform locations and bind it to our texture unit + ***/ }, { key: "_setTextureUniforms", @@ -4877,10 +4871,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This copies an already existing Texture object to our texture - params: - @texture (Texture): texture to set from - ***/ + This copies an already existing Texture object to our texture + params: + @texture (Texture): texture to set from + ***/ }, { key: "copy", @@ -4935,10 +4929,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** LOADING SOURCES ***/ /*** - This uses our source as texture - params: - @source (images/video/canvas): either an image, a video or a canvas - ***/ + This uses our source as texture + params: + @source (images/video/canvas): either an image, a video or a canvas + ***/ }, { key: "setSource", @@ -5034,10 +5028,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** TEXTURE PARAMETERS ***/ /*** - Updates textures parameters that depends on global WebGL context state - Typically unpacking, flipY and premultiplied alpha - Usually called before uploading a texture to the GPU - ***/ + Updates textures parameters that depends on global WebGL context state + Typically unpacking, flipY and premultiplied alpha + Usually called before uploading a texture to the GPU + ***/ }, { key: "_updateGlobalTexParameters", @@ -5062,30 +5056,30 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (this._globalParameters.floatingPoint === "half-float") { - if (this.renderer._isWebGL2 && this.renderer.extensions['EXT_color_buffer_float']) { + if (this.renderer._isWebGL2 && this.renderer.extensions["EXT_color_buffer_float"]) { this._globalParameters.internalFormat = this.gl.RGBA16F; this._globalParameters.type = this.gl.HALF_FLOAT; - } else if (this.renderer.extensions['OES_texture_half_float']) { - this._globalParameters.type = this.renderer.extensions['OES_texture_half_float'].HALF_FLOAT_OES; + } else if (this.renderer.extensions["OES_texture_half_float"]) { + this._globalParameters.type = this.renderer.extensions["OES_texture_half_float"].HALF_FLOAT_OES; } else if (!this.renderer.production) { throwWarning(this.type + ": could not use half-float textures because the extension is not available"); } } else if (this._globalParameters.floatingPoint === "float") { - if (this.renderer._isWebGL2 && this.renderer.extensions['EXT_color_buffer_float']) { + if (this.renderer._isWebGL2 && this.renderer.extensions["EXT_color_buffer_float"]) { this._globalParameters.internalFormat = this.gl.RGBA16F; this._globalParameters.type = this.gl.FLOAT; - } else if (this.renderer.extensions['OES_texture_float']) { - this._globalParameters.type = this.renderer.extensions['OES_texture_half_float'].FLOAT; + } else if (this.renderer.extensions["OES_texture_float"]) { + this._globalParameters.type = this.renderer.extensions["OES_texture_half_float"].FLOAT; } else if (!this.renderer.production) { throwWarning(this.type + ": could not use float textures because the extension is not available"); } } } /*** - Updates per-textures parameters - Wrapping, filters, anisotropy and mipmaps generation - Usually called after uploading a texture to the GPU - ***/ + Updates per-textures parameters + Wrapping, filters, anisotropy and mipmaps generation + Usually called after uploading a texture to the GPU + ***/ }, { key: "_updateTexParameters", @@ -5189,7 +5183,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } // anisotropy - var anisotropyExt = this.renderer.extensions['EXT_texture_filter_anisotropic']; + var anisotropyExt = this.renderer.extensions["EXT_texture_filter_anisotropic"]; if (anisotropyExt && this.parameters.anisotropy !== this._state.anisotropy) { var max = this.gl.getParameter(anisotropyExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT); @@ -5199,10 +5193,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Sets the texture wrapping for the texture coordinate S - params: - @wrapS (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate S - ***/ + Sets the texture wrapping for the texture coordinate S + params: + @wrapS (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate S + ***/ }, { key: "setWrapS", @@ -5213,10 +5207,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Sets the texture wrapping for the texture coordinate T - params: - @wrapT (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate T - ***/ + Sets the texture wrapping for the texture coordinate T + params: + @wrapT (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate T + ***/ }, { key: "setWrapT", @@ -5227,10 +5221,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Sets the texture minifaction filter value - params: - @minFilter (GLenum): WebGL constant specifying the texture minification filter - ***/ + Sets the texture minifaction filter value + params: + @minFilter (GLenum): WebGL constant specifying the texture minification filter + ***/ }, { key: "setMinFilter", @@ -5241,10 +5235,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Sets the texture magnifaction filter value - params: - @magFilter (GLenum): WebGL constant specifying the texture magnifaction filter - ***/ + Sets the texture magnifaction filter value + params: + @magFilter (GLenum): WebGL constant specifying the texture magnifaction filter + ***/ }, { key: "setMagFilter", @@ -5255,10 +5249,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Sets the texture anisotropy - params: - @anisotropy (int): Texture anisotropy value - ***/ + Sets the texture anisotropy + params: + @anisotropy (int): Texture anisotropy value + ***/ }, { key: "setAnisotropy", @@ -5271,8 +5265,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This forces a texture to be updated on the next draw call - ***/ + This forces a texture to be updated on the next draw call + ***/ }, { key: "needUpdate", @@ -5280,8 +5274,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._forceUpdate = true; } /*** - This uses the requestVideoFrameCallback API to update the texture each time a new frame is displayed - ***/ + This uses the requestVideoFrameCallback API to update the texture each time a new frame is displayed + ***/ }, { key: "_videoFrameCallback", @@ -5309,10 +5303,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This updloads our texture to the GPU - Called on init or inside our drawing loop if shouldUpdate property is set to true - Typically used by videos or canvas - ***/ + This updloads our texture to the GPU + Called on init or inside our drawing loop if shouldUpdate property is set to true + Typically used by videos or canvas + ***/ }, { key: "_upload", @@ -5340,10 +5334,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** TEXTURE SIZINGS ***/ /*** - This is used to calculate how to crop/center an texture - returns: - @sizes (obj): an object containing plane sizes, source sizes and x and y offset to center the source in the plane - ***/ + This is used to calculate how to crop/center an texture + returns: + @sizes (obj): an object containing plane sizes, source sizes and x and y offset to center the source in the plane + ***/ }, { key: "_getSizes", @@ -5390,10 +5384,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }; } /*** - Set the texture scale and then update its matrix - params: - @scale (Vec2 object): scale to apply on X and Y axes - ***/ + Set the texture scale and then update its matrix + params: + @scale (Vec2 object): scale to apply on X and Y axes + ***/ }, { key: "setScale", @@ -5432,8 +5426,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Gets our texture and parent sizes and tells our texture matrix to update based on those values - ***/ + Gets our texture and parent sizes and tells our texture matrix to update based on those values + ***/ }, { key: "_setSize", @@ -5447,10 +5441,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This is used to crop/center a texture - If the texture is using texture matrix then we just have to update its matrix - If it is a render pass texture we also upload the texture with its new size on the GPU - ***/ + This is used to crop/center a texture + If the texture is using texture matrix then we just have to update its matrix + If it is a render pass texture we also upload the texture with its new size on the GPU + ***/ }, { key: "resize", @@ -5477,10 +5471,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._setSize(); } /*** - This updates our textures matrix uniform based on plane and sources sizes - params: - @sizes (object): object containing plane sizes, source sizes and x and y offset to center the source in the plane - ***/ + This updates our textures matrix uniform based on plane and sources sizes + params: + @sizes (object): object containing plane sizes, source sizes and x and y offset to center the source in the plane + ***/ }, { key: "_updateTextureMatrix", @@ -5499,8 +5493,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this._updateMatrixUniform(); } /*** - This updates our textures matrix GL uniform - ***/ + This updates our textures matrix GL uniform + ***/ }, { key: "_updateMatrixUniform", @@ -5511,8 +5505,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This calls our loading callback and set our media as texture source - ***/ + This calls our loading callback and set our media as texture source + ***/ }, { key: "_onSourceLoaded", @@ -5527,10 +5521,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** DRAWING ***/ /*** - This is used to set the WebGL context active texture and bind it - params: - @texture (texture object): Our texture object containing our WebGL texture and its index - ***/ + This is used to set the WebGL context active texture and bind it + params: + @texture (texture object): Our texture object containing our WebGL texture and its index + ***/ }, { key: "_bindTexture", @@ -5553,8 +5547,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This is called to draw the texture - ***/ + This is called to draw the texture + ***/ }, { key: "_draw", @@ -5594,13 +5588,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** EVENTS ***/ /*** - This is called each time a source has been loaded for the first time - TODO useless? - params : - @callback (function) : a function to execute - returns : - @this: our texture to handle chaining - ***/ + This is called each time a source has been loaded for the first time + TODO useless? + params : + @callback (function) : a function to execute + returns : + @this: our texture to handle chaining + ***/ }, { key: "onSourceLoaded", @@ -5612,12 +5606,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return this; } /*** - This is called each time a texture has been uploaded to the GPU for the first time - params : - @callback (function) : a function to execute - returns : - @this: our texture to handle chaining - ***/ + This is called each time a texture has been uploaded to the GPU for the first time + params : + @callback (function) : a function to execute + returns : + @this: our texture to handle chaining + ***/ }, { key: "onSourceUploaded", @@ -5631,11 +5625,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** DESTROYING ***/ /*** - This is used to destroy a texture and free the memory space - Usually used on a plane/shader pass/render target removal - params: - @force (bool, optional): force the texture to be deleted even if cached - ***/ + This is used to destroy a texture and free the memory space + Usually used on a plane/shader pass/render target removal + params: + @force (bool, optional): force the texture to be deleted even if cached + ***/ }, { key: "_dispose", @@ -5650,9 +5644,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.source = null; - } else if (this.sourceType === "canvas") { + } else if (this.sourceType === "canvas" && this.source) { + var _this$source; + // clear all canvas states - this.source.width = this.source.width; // clear source + this.source.width = (_this$source = this.source) === null || _this$source === void 0 ? void 0 : _this$source.width; // clear source this.source = null; } // remove its parent @@ -5680,10 +5676,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** An asset loader that handles images, videos and canvas loading Load the assets and create a Texture class object that will use those assets as sources - params: + params: @renderer (Curtains or Renderer class object): our curtains object OR our curtains renderer object @crossOrigin (string, optional): crossorigin policy to use - returns : + returns : @this: our TextureLoader element ***/ // TODO load assets with a web worker? @@ -5718,7 +5714,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Keep a track of all sources loaded via this loader with an els array This allows to get clean refs to the event listeners to be able to remove them later - params: + params: @source (html element): html image, video or canvas element that has been loaded @texture (Texture class object): our newly created texture that will use that source @successCallback (function): reference to our success callback @@ -5740,7 +5736,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Handles media loading errors - params: + params: @source (html element): html image or video element that has failed to load @callback (function): function to execute @error (object): loading error @@ -5756,7 +5752,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Handles media loading success - params: + params: @source (html element): html image, video or canvas element that has been loaded @texture (Texture class object): our newly created texture that will use that source @callback (function): function to execute @@ -5788,9 +5784,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Get the source type based on its file extension if it's a string or it's tag name if its a HTML element - params: + params: @source (html element or string): html image, video, canvas element or source url - returns : + returns : @sourceType (string): either "image", "video", "canvas" or null if source type cannot be determined ***/ @@ -5820,9 +5816,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Create an image HTML element based on an image source url - params: + params: @source (string): source url - returns : + returns : @image (HTML image element): an HTML image element ***/ @@ -5850,9 +5846,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Create a video HTML element based on a video source url - params: + params: @source (string): source url - returns : + returns : @video (HTML video element): an HTML video element ***/ @@ -5881,7 +5877,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This method loads one source It checks what type of source it is then use the right loader - params: + params: @source (html element): html image, video or canvas element @textureOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when the source has been loaded @@ -5915,7 +5911,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads an array of sources by calling loadSource() for each one of them - params: + params: @sources (array of html elements / sources url): array of html images, videos, canvases element or sources url @texturesOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when each source has been loaded @@ -5932,7 +5928,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This method loads an image Creates a new texture object right away and once the image is loaded it uses it as our WebGL texture - params: + params: @source (image): html image element @textureOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when the source has been loaded @@ -5999,7 +5995,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads an array of images by calling loadImage() for each one of them - params: + params: @sources (array of images / images url): array of html images elements or images url @texturesOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when each source has been loaded @@ -6016,7 +6012,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This method loads a video Creates a new texture object right away and once the video has enough data it uses it as our WebGL texture - params: + params: @source (video): html video element @textureOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when the source has been loaded @@ -6072,7 +6068,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads an array of images by calling loadVideo() for each one of them - params: + params: @sources (array of videos / videos url): array of html videos elements or videos url @texturesOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when each source has been loaded @@ -6089,7 +6085,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This method loads a canvas Creates a new texture object right away and uses the canvas as our WebGL texture - params: + params: @source (canvas): html canvas element @textureOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when the source has been loaded @@ -6121,7 +6117,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads an array of images by calling loadCanvas() for each one of them - params: + params: @sources (array of canvas): array of html canvases elements @texturesOptions (object): parameters to apply to the textures, such as sampler name, repeat wrapping, filters, anisotropy... @successCallback (function): function to execute when each source has been loaded @@ -6138,7 +6134,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Cleanly removes a texture source by removing its associated event listeners - params: + params: @texture (Texture class object): The texture that contains our source ***/ @@ -6178,14 +6174,14 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Extends our TextureLoader class to add sources loaded count, handle onComplete event Also adds the sources and textures to its defined parent - params: + params: @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object @parent (Plane or ShaderPass class object): The plane or shader pass that will use this loader - @sourcesLoaded (int): Number of sources loaded + @sourcesLoaded (int): Number of sources loaded @sourcesToLoad (int): Number of initial sources to load @complete (bool): Whether the loader has loaded all the initial sources @onComplete (function): Callback to execute when all the initial sources have been loaded - returns : + returns : @this: our PlaneTextureLoader element ***/ @@ -6229,7 +6225,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the total number of assets to load before firing the onComplete event - params: + params: @size (int): our curtains object OR our curtains renderer object ***/ @@ -6270,7 +6266,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Adds the source to the correct parent assets array - params: + params: @source (html element): html image, video or canvas element that has been loaded @sourceType (string): either "image", "video" or "canvas" ***/ @@ -6306,7 +6302,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Adds the loader parent to the newly created texture Also adds the source to the correct parent assets array - params: + params: @texture (Texture class object): our newly created texture @source (html element): html image, video or canvas element that has been loaded @sourceType (string): either "image", "video" or "canvas" @@ -6328,10 +6324,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create our Mesh object We will create an object containing the program that handles shaders and uniforms, a geometry that handles attributes Also handles anything that relates to textures creation and basic drawing operations - params: + params: @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object @type (string): Object type (should be either "Plane" or "ShaderPass") - @vertexShaderID (string, optional): the vertex shader script ID. If not specified, will look for a data attribute data-vs-id on the plane HTML element. + @vertexShaderID (string, optional): the vertex shader script ID. If not specified, will look for a data attribute data-vs-id on the plane HTML element. @fragmentShaderID (string, optional): the fragment shader script ID. If not specified, will look for a data attribute data-fs-id on the plane HTML element. @vertexShader (string, optional): the vertex shader as a string. Will look for a vertexShaderID if not specified. @fragmentShader (string, optional): the fragment shader as a string. Will look for a fragmentShaderID if not specified. @@ -6343,7 +6339,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi @cullFace (string, optional): which face of the mesh should be culled. Could either be "back", "front" or "none". Default to "back". @texturesOptions (object, optional): options and parameters to apply to the textures loaded by the mesh's loader. See the Texture class object. @crossorigin (string, optional): defines the crossOrigin process to load images if any (default to "anonymous"). - returns: + returns: @this: our Mesh element ***/ @@ -6541,7 +6537,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This function adds a render target to a mesh - params : + params : @renderTarger (RenderTarget): the render target to add to that mesh ***/ @@ -6570,7 +6566,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Set the mesh render order to draw it above or behind other meshes - params : + params : @renderOrder (int): new render order to apply: higher number means a mesh is drawn on top of others ***/ @@ -6589,9 +6585,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This method creates a new Texture and adds it to the mesh - params : + params : @textureOptions (object, optional) : Parameters to apply to that texture (see Texture class). Will be merged with the mesh default textures options - returns : + returns : @texture: our newly created texture ***/ @@ -6624,7 +6620,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method handles the sources loading process - params : + params : @sourcesArray (array): array of html images, videos or canvases elements @texturesOptions (object, optional) : Parameters to apply to those textures (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6644,7 +6640,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads one source using our mesh loader (see PlaneTextureLoader class) - params : + params : @source (html element) : html image, video or canvas element @textureOptions (object, optional) : Parameters to apply to that texture (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6671,7 +6667,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads an image using our mesh loader (see PlaneTextureLoader class) - params : + params : @source (image) : html image element @textureOptions (object, optional) : Parameters to apply to that texture (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6698,7 +6694,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads a video using the mesh loader (see PlaneTextureLoader class) - params : + params : @source (video) : html video element @textureOptions (object, optional) : Parameters to apply to that texture (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6725,7 +6721,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This method loads a canvas using the mesh loader (see PlaneTextureLoader class) - params : + params : @source (canvas) : html canvas element @textureOptions (object, optional) : Parameters to apply to that texture (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6744,7 +6740,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Loads an array of images - params : + params : @imagesArray (array) : array of html image elements @texturesOptions (object, optional) : Parameters to apply to those textures (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6764,7 +6760,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Loads an array of videos - params : + params : @videosArray (array) : array of html video elements @texturesOptions (object, optional) : Parameters to apply to those textures (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6784,7 +6780,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Loads an array of canvases - params : + params : @canvasesArray (array) : array of html canvas elements @texturesOptions (object, optional) : Parameters to apply to those textures (see Texture class). Will be merged with the mesh default textures options @successCallback (function): callback to execute on source loading success @@ -6875,9 +6871,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This is called each time a mesh can't be instanciated - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -6892,9 +6888,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called each time a mesh's image has been loaded. Useful to handle a loader - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -6909,9 +6905,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called when a mesh is ready to be drawn - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -6926,9 +6922,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called at each requestAnimationFrame call - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -6943,9 +6939,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called at each requestAnimationFrame call for each mesh after the draw call - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -7022,7 +7018,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Here we create our DOMGLObject object We will extend our Mesh class object by adding HTML sizes helpers (bounding boxes getter/setter and mouse to mesh positioning) - params: + params: @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object @plane (html element): the html element that we will use for our DOMMesh object @type (string): Object type (should be either "Plane" or "ShaderPass") @@ -7126,7 +7122,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Useful to get our plane HTML element bounding rectangle without triggering a reflow/layout - returns : + returns : @boundingRectangle (obj): an object containing our plane HTML element bounding rectangle (width, height, top, bottom, right and left properties) ***/ function getBoundingRect() { @@ -7178,9 +7174,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This function takes the mouse position relative to the document and returns it relative to our plane It ranges from -1 to 1 on both axis - params : + params : @mouseCoordinates (Vec2 object): coordinates of the mouse - returns : + returns : @mousePosition (Vec2 object): the mouse position relative to our plane in WebGL space coordinates ***/ @@ -7205,9 +7201,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This is called each time a plane has been resized - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -7228,14 +7224,14 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create our Camera object Creates a perspective camera and its projection matrix (which is used by Plane's class objects) Uses a dirty _shouldUpdate flag used to determine if we should update the matrix - params: + params: @fov (float, optional): the perspective field of view. Should be greater than 0 and lower than 180. Default to 50. @near (float, optional): near plane, the closest point where a mesh vertex is drawn. Default to 0.1. @far (float, optional): far plane, farthest point where a mesh vertex is drawn. Default to 150. @width (float, optional): width used to calculate the camera aspect ratio. Default to the renderer container's width. @height (float, optional): height used to calculate the camera aspect ratio. Default to the renderer container's height. @pixelRatio (float, optional): pixel ratio used to calculate the camera aspect ratio. Default to the renderer's pixel ratio. - returns: + returns: @this: our Mesh element ***/ @@ -7267,7 +7263,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the camera field of view Update the camera projection matrix only if the fov actually changed - params: + params: @fov (float, optional): field of view to use ***/ @@ -7290,7 +7286,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the camera near plane value Update the camera projection matrix only if the near plane actually changed - params: + params: @near (float, optional): near plane value to use ***/ @@ -7308,7 +7304,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the camera far plane value Update the camera projection matrix only if the far plane actually changed - params: + params: @far (float, optional): far plane value to use ***/ @@ -7326,7 +7322,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the camera pixel ratio value Update the camera projection matrix only if the pixel ratio actually changed - params: + params: @pixelRatio (float, optional): pixelRatio value to use ***/ @@ -7342,7 +7338,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the camera width and height Update the camera projection matrix only if the width or height actually changed - params: + params: @width (float, optional): width value to use @height (float, optional): height value to use ***/ @@ -7360,7 +7356,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Sets the camera perspective Update the camera projection matrix if our _shouldUpdate flag is true - params: + params: @fov (float, optional): field of view to use @near (float, optional): near plane value to use @far (float, optional): far plane value to use @@ -7408,7 +7404,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Returns visible width / height at a given z-depth from our camera parameters - Taken from: https://discourse.threejs.org/t/functions-to-calculate-the-visible-width-height-at-a-given-z-depth-from-a-perspective-camera/269 + Taken from: https://discourse.threejs.org/t/functions-to-calculate-the-visible-width-height-at-a-given-z-depth-from-a-perspective-camera/269 ***/ }, { @@ -7481,9 +7477,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create a Quat class object This is a really basic Quaternion class used for rotation calculations Highly based on https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js - params : + params : @elements (Float32Array of length 4): our quaternion array. Default to identity quaternion. - returns : + returns : @this: our Quat class object ***/ // TODO lot of (unused at the time) methods are missing @@ -7503,9 +7499,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sets the quaternion values from an array - params: + params: @array (array): an array of at least 4 elements - returns: + returns: @this (Quat class object): this quaternion after being set ***/ @@ -7521,9 +7517,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sets the quaternion axis order - params: + params: @axisOrder (string): an array of at least 4 elements - returns: + returns: @this (Quat class object): this quaternion after axis order has been set ***/ @@ -7552,9 +7548,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Copy a quaternion into this quaternion - params: + params: @vector (Quat): quaternion to copy - returns: + returns: @this (Quat): this quaternion after copy ***/ @@ -7567,7 +7563,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Clone a quaternion - returns: + returns: @clonedQuaternion (Quat): cloned quaternion ***/ @@ -7578,7 +7574,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Checks if 2 quaternions are equal - returns: + returns: @isEqual (bool): whether the quaternions are equals or not ***/ @@ -7589,9 +7585,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Sets a rotation quaternion using Euler angles and its axis order - params: + params: @vector (Vec3 class object): rotation vector to set our quaternion from - returns : + returns : @this (Quat class object): quaternion after having applied the rotation ***/ @@ -7649,21 +7645,21 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Here we create our Plane object We will extend our DOMMesh class that handles all the WebGL part and basic HTML sizings - Plane class will add: + Plane class will add: - sizing and positioning and everything that relates to the DOM like draw checks (frustum culling) and reenter/leave events - projection (using Camera class object) and view matrices and everything that is related like perspective, scale, rotation... - params : + params : @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object @plane (html element): the html element that we will use for our Plane object - @Meshparams (object): see Mesh class object - @alwaysDraw (boolean, optionnal): if the plane should always be drawn or if it should use frustum culling. Default to false. + @Meshparams (object): see Mesh class object + @alwaysDraw (boolean, optionnal): if the plane should always be drawn or if it should use frustum culling. Default to false. @visible (boolean, optional): if the plane should be drawn or not. Default to true. @transparent (boolean, optional): if the plane should handle transparency. Default to false. @drawCheckMargins (object, optional): defines the margins in pixels to add to the frustum culling check to determine if the plane should be drawn. Default to 0. @autoloadSources (boolean, optional): if the sources should be loaded on init automatically. Default to true @watchScroll (boolean, optional): if the plane should auto update its position based on the scroll value. Default to true. @fov (float, optional): defines the perspective field of view used by the camera. Default to 50. - returns : + returns : @this: our Plane ***/ // avoid reinstancing those during runtime @@ -7886,7 +7882,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Reset our plane transformation values and HTML element if specified (and valid) - params : + params : @htmlElement (HTML element, optional) : if provided, new HTML element to use as a reference for sizes and position syncing. ***/ @@ -7988,7 +7984,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This will set our perspective matrix new parameters (fov, near plane and far plane) used internally but can be used externally as well to change fov for example - params : + params : @fov (float): the field of view @near (float): the nearest point where object are displayed @far (float): the farthest point where object are displayed @@ -8075,9 +8071,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This function takes pixel values along X and Y axis and convert them to world space coordinates - params : + params : @vector (Vec3): position to convert on X, Y and Z axes - returns : + returns : @worldPosition: plane's position in WebGL space ***/ @@ -8131,7 +8127,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This will set our plane scale used internally but can be used externally as well - params : + params : @scale (Vec2 object): scale to apply on X and Y axes ***/ @@ -8172,7 +8168,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This will set our plane rotation used internally but can be used externally as well - params : + params : @rotation (Vec3 object): rotation to apply on X, Y and Z axes (in radians) ***/ @@ -8211,7 +8207,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi (0, 0, 0) means plane's top left corner (1, 1, 0) means plane's bottom right corner (0.5, 0.5, -1) means behind plane's center - params : + params : @origin (Vec3 object): coordinate of transformation origin X, Y and Z axes ***/ @@ -8258,7 +8254,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This function takes pixel values along X and Y axis and convert them to clip space coordinates, and then apply the corresponding translation - params : + params : @translation (Vec3): translation to apply on X, Y and Z axes ***/ @@ -8310,7 +8306,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This function updates the plane position based on the Curtains class scroll manager values - params: + params: @lastXDelta (float): last scroll value along X axis @lastYDelta (float): last scroll value along Y axis ***/ @@ -8331,10 +8327,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Find the intersection point by adding a vector starting from a corner till we reach the near plane - params: + params: @refPoint (Vec3 class object): corner of the plane from which we start to iterate from @secondPoint (Vec3 class object): second point near the refPoint to get a direction to use for iteration - returns: + returns: @intersection (Vec3 class object): intersection between our plane and the camera near plane ***/ @@ -8358,11 +8354,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi We need to find the intersection points using another approach Here I chose to use non clipped corners projected coords and a really small vector parallel to the plane's side We're adding that vector again and again to our corner projected coords until the Z coordinate matches the near plane: we got our intersection - params: + params: @corners (array): our original corners vertices coordinates @mvpCorners (array): the projected corners of our plane @clippedCorners (array): index of the corners that are clipped - returns: + returns: @mvpCorners (array): the corrected projected corners of our plane ***/ @@ -8472,7 +8468,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Useful to get our WebGL plane bounding box in the world space Takes all transformations into account Used internally for frustum culling - returns : + returns : @boundingRectangle (obj): an object containing our plane WebGL element 4 corners coordinates: top left corner is [-1, 1] and bottom right corner is [1, -1] ***/ function _getWorldCoords() { @@ -8568,7 +8564,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Returns our plane WebGL bounding rect relative to document - returns : + returns : @boundingRectangle (obj): an object containing our plane WebGL element bounding rectangle (width, height, top, bottom, right and left properties) ***/ @@ -8585,7 +8581,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** Returns our plane WebGL bounding rectangle in document coordinates including additional drawCheckMargins - returns : + returns : @boundingRectangle (obj): an object containing our plane WebGL element bounding rectangle including the draw check margins (top, bottom, right and left properties) ***/ @@ -8648,7 +8644,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This function set/unset the depth test for that plane - params : + params : @shouldEnableDepthTest (bool): enable/disable depth test for that plane ***/ @@ -8738,9 +8734,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This function takes the mouse position relative to the document and returns it relative to our plane It ranges from -1 to 1 on both axis - params : + params : @mouseCoordinates (Vec2 object): coordinates of the mouse - returns : + returns : @mousePosition (Vec2 object): the mouse position relative to our plane in WebGL space coordinates ***/ @@ -8800,9 +8796,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This is called each time a plane is entering again the view bounding box - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -8817,9 +8813,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called each time a plane is leaving the view bounding box - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -8838,15 +8834,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }(DOMMesh); /*** Here we create a RenderTarget class object - params : + params : @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object - @shaderPass (ShaderPass class object): shader pass that will use that render target. Default to null + @shaderPass (ShaderPass class object): shader pass that will use that render target. Default to null @depth (bool, optional): whether to create a depth buffer (handle depth inside your render target). Default to false. @clear (bool, optional): whether the content of the render target should be cleared before being drawn. Should be set to false to handle ping-pong shading. Default to true. - @minWidth (float, optional): minimum width of the render target + @minWidth (float, optional): minimum width of the render target @minHeight (float, optional): minimum height of the render target - @texturesOptions (object, optional): options and parameters to apply to the render target texture. See the Texture class object. - returns : + @texturesOptions (object, optional): options and parameters to apply to the render target texture. See the Texture class object. + returns : @this: our RenderTarget class object ***/ @@ -9048,7 +9044,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Returns the render target's texture - returns : + returns : @texture (Texture class object): our RenderTarget's texture ***/ @@ -9110,13 +9106,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi Here we create our ShaderPass object We will extend our DOMMesh class that handles all the WebGL part and basic HTML sizings ShaderPass class will add the frame buffer by creating a new RenderTarget class object - params : + params : @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object - @Meshparams (object): see Mesh class object - @depth (boolean, optionnal): whether the shader pass render target should use a depth buffer (see RenderTarget class object). Default to false. + @Meshparams (object): see Mesh class object + @depth (boolean, optionnal): whether the shader pass render target should use a depth buffer (see RenderTarget class object). Default to false. @clear (boolean, optional): whether the shader pass render target content should be cleared before being drawn (see RenderTarget class object). Default to true. @renderTarget (RenderTarget class object, optional): an already existing render target to use. Default to null. - returns : + returns : @this: our ShaderPass element ***/ @@ -9322,10 +9318,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi - create a texture onto which we'll draw - before drawing our plane (onRender callback), apply the write pass as our plane render target - after drawing our plane (onAfterRender callback), swap the read and write pass and copy the read pass texture again - params: + params: @sampler (string): sampler name used to create our texture and that will be used inside your shader @planeParams: see Plane class object - returns : + returns : @this: our PingPongPlane element ***/ @@ -9501,9 +9497,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** This is called at each requestAnimationFrame call - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -9518,9 +9514,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called at each requestAnimationFrame call - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our plane to handle chaining ***/ @@ -9568,8 +9564,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** Here we create our FXAAPass object This is just a regular ShaderPass with preset shaders and a resolution uniform - params: see ShaderPas class object - returns : + params: see ShaderPas class object + returns : @this: our FXAAPass element ***/ @@ -9633,9 +9629,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } /*** This is called each time the FXAAPass has been resized - params : + params : @callback (function) : a function to execute - returns : + returns : @this: our FXAAPass to handle chaining ***/ diff --git a/dist/curtains.umd.min.js b/dist/curtains.umd.min.js index f6feedd..ff62188 100644 --- a/dist/curtains.umd.min.js +++ b/dist/curtains.umd.min.js @@ -1 +1 @@ -function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),console.log("curtains.js - v8.1.6"),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:window.pageYOffset,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];"video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive?(this._loader&&this._loader._removeSource(this),this.source=null):"canvas"===this.sourceType&&(this.source.width=this.source.width,this.source=null),this._parent=null;var t=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);t&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,V=new w,B=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); +function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:window.pageYOffset,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,V=new w,B=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/src/core/Curtains.js b/src/core/Curtains.js index e4371c1..30ca12d 100644 --- a/src/core/Curtains.js +++ b/src/core/Curtains.js @@ -1,7 +1,6 @@ -import {Renderer} from "./Renderer.js"; -import {ScrollManager} from "../utils/ScrollManager.js"; -import {throwWarning, lerp} from "../utils/utils.js"; - +import { Renderer } from "./Renderer.js"; +import { ScrollManager } from "../utils/ScrollManager.js"; +import { throwWarning, lerp } from "../utils/utils.js"; const version = "8.1.6"; @@ -34,66 +33,68 @@ const version = "8.1.6"; @this: our Renderer ***/ export class Curtains { - constructor({ - // renderer container - container, - - // webgl params - alpha = true, - premultipliedAlpha = false, - antialias = true, - depth = true, - failIfMajorPerformanceCaveat = true, - preserveDrawingBuffer = false, - stencil = false, - - autoResize = true, - autoRender = true, - watchScroll = true, - - pixelRatio = window.devicePixelRatio || 1, - renderingScale = 1, - - production = false, - } = {}) { - this.type = "Curtains"; - - // if we should use auto resize (default to true) - this._autoResize = autoResize; - // if we should use auto render (default to true) - this._autoRender = autoRender; - // if we should watch the scroll (default to true) - this._watchScroll = watchScroll; - - // pixel ratio and rendering scale - this.pixelRatio = pixelRatio; - // rendering scale - renderingScale = isNaN(renderingScale) ? 1 : parseFloat(renderingScale); - this._renderingScale = Math.max(0.25, Math.min(1, renderingScale)); - - // webgl context parameters - this.premultipliedAlpha = premultipliedAlpha; - this.alpha = alpha; - this.antialias = antialias; - this.depth = depth; - this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat; - this.preserveDrawingBuffer = preserveDrawingBuffer; - this.stencil = stencil; - - this.production = production; - - this.errors = false; - - // if a container has been provided, proceed to init - if(container) { - this.setContainer(container); - } - else if(!this.production) { - throwWarning(this.type + ": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context") - } - } - - /*** + constructor({ + // renderer container + container, + + // webgl params + alpha = true, + premultipliedAlpha = false, + antialias = true, + depth = true, + failIfMajorPerformanceCaveat = true, + preserveDrawingBuffer = false, + stencil = false, + + autoResize = true, + autoRender = true, + watchScroll = true, + + pixelRatio = window.devicePixelRatio || 1, + renderingScale = 1, + + production = false, + } = {}) { + this.type = "Curtains"; + + // if we should use auto resize (default to true) + this._autoResize = autoResize; + // if we should use auto render (default to true) + this._autoRender = autoRender; + // if we should watch the scroll (default to true) + this._watchScroll = watchScroll; + + // pixel ratio and rendering scale + this.pixelRatio = pixelRatio; + // rendering scale + renderingScale = isNaN(renderingScale) ? 1 : parseFloat(renderingScale); + this._renderingScale = Math.max(0.25, Math.min(1, renderingScale)); + + // webgl context parameters + this.premultipliedAlpha = premultipliedAlpha; + this.alpha = alpha; + this.antialias = antialias; + this.depth = depth; + this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat; + this.preserveDrawingBuffer = preserveDrawingBuffer; + this.stencil = stencil; + + this.production = production; + + this.errors = false; + + // if a container has been provided, proceed to init + if (container) { + this.setContainer(container); + } else if (!this.production) { + throwWarning( + this.type + + ": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context" + ); + } + } + + /*** Set up our Curtains container and start initializing everything Called on Curtains instancing if a params container has been provided, could be call afterwards else Useful with JS frameworks to init our Curtains class globally and then set the container in a canvas component afterwards to fully instantiate everything @@ -101,151 +102,151 @@ export class Curtains { params: @container (HTML element or string): the container HTML element or ID that will hold our canvas ***/ - setContainer(container) { - if(!container) { - let container = document.createElement("div"); - container.setAttribute("id", "curtains-canvas"); - document.body.appendChild(container); - this.container = container; - if(!this.production) throwWarning('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead'); - } - else { - if(typeof container === "string") { - container = document.getElementById(container); - - if(!container) { - let container = document.createElement("div"); - container.setAttribute("id", "curtains-canvas"); - document.body.appendChild(container); - this.container = container; - if(!this.production) throwWarning('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead'); - } - else { - this.container = container; - } - } - else if(container instanceof Element) { - this.container = container; - } + setContainer(container) { + if (!container) { + let container = document.createElement("div"); + container.setAttribute("id", "curtains-canvas"); + document.body.appendChild(container); + this.container = container; + if (!this.production) + throwWarning( + 'Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead' + ); + } else { + if (typeof container === "string") { + container = document.getElementById(container); + + if (!container) { + let container = document.createElement("div"); + container.setAttribute("id", "curtains-canvas"); + document.body.appendChild(container); + this.container = container; + if (!this.production) + throwWarning( + 'Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead' + ); + } else { + this.container = container; } - - this._initCurtains(); + } else if (container instanceof Element) { + this.container = container; + } } + this._initCurtains(); + } - /*** + /*** Initialize everything that the class will need: WebGL renderer, scroll manager, sizes, listeners Then starts our animation frame loop if needed ***/ - _initCurtains() { - this.planes = []; - this.renderTargets = []; - this.shaderPasses = []; + _initCurtains() { + this.planes = []; + this.renderTargets = []; + this.shaderPasses = []; - // init webgl context - this._initRenderer(); + // init webgl context + this._initRenderer(); - if(!this.gl) return; + if (!this.gl) return; - // scroll - this._initScroll(); + // scroll + this._initScroll(); - // sizes - this._setSize(); + // sizes + this._setSize(); - // event listeners - this._addListeners(); + // event listeners + this._addListeners(); - // we are ready to go - this.container.appendChild(this.canvas); + // we are ready to go + this.container.appendChild(this.canvas); - // watermark - console.log("curtains.js - v" + version); + // watermark + //console.log("curtains.js - v" + version); - // start rendering - this._animationFrameID = null; - if(this._autoRender) { - this._animate(); - } + // start rendering + this._animationFrameID = null; + if (this._autoRender) { + this._animate(); } + } + /*** WEBGL CONTEXT ***/ - /*** WEBGL CONTEXT ***/ - - /*** + /*** Initialize the Renderer class object ***/ - _initRenderer() { - this.renderer = new Renderer({ - alpha: this.alpha, - antialias: this.antialias, - premultipliedAlpha: this.premultipliedAlpha, - depth: this.depth, - failIfMajorPerformanceCaveat: this.failIfMajorPerformanceCaveat, - preserveDrawingBuffer: this.preserveDrawingBuffer, - stencil: this.stencil, - - container: this.container, - pixelRatio: this.pixelRatio, - renderingScale: this._renderingScale, - - production: this.production, - - onError: () => this._onRendererError(), - onSuccess: () => this._onRendererSuccess(), - onContextLost: () => this._onRendererContextLost(), - onContextRestored: () => this._onRendererContextRestored(), - onDisposed: () => this._onRendererDisposed(), - // keep sync between renderer planes, shader passes and render targets arrays and the Curtains ones - onSceneChange: () => this._keepSync(), - }); - - this.gl = this.renderer.gl; - this.canvas = this.renderer.canvas; - } - - - /*** + _initRenderer() { + this.renderer = new Renderer({ + alpha: this.alpha, + antialias: this.antialias, + premultipliedAlpha: this.premultipliedAlpha, + depth: this.depth, + failIfMajorPerformanceCaveat: this.failIfMajorPerformanceCaveat, + preserveDrawingBuffer: this.preserveDrawingBuffer, + stencil: this.stencil, + + container: this.container, + pixelRatio: this.pixelRatio, + renderingScale: this._renderingScale, + + production: this.production, + + onError: () => this._onRendererError(), + onSuccess: () => this._onRendererSuccess(), + onContextLost: () => this._onRendererContextLost(), + onContextRestored: () => this._onRendererContextRestored(), + onDisposed: () => this._onRendererDisposed(), + // keep sync between renderer planes, shader passes and render targets arrays and the Curtains ones + onSceneChange: () => this._keepSync(), + }); + + this.gl = this.renderer.gl; + this.canvas = this.renderer.canvas; + } + + /*** Force our renderer to restore the WebGL context ***/ - restoreContext() { - this.renderer.restoreContext(); - } - + restoreContext() { + this.renderer.restoreContext(); + } - /*** + /*** This just handles our drawing animation frame ***/ - _animate() { - this.render(); - this._animationFrameID = window.requestAnimationFrame(this._animate.bind(this)); - } - + _animate() { + this.render(); + this._animationFrameID = window.requestAnimationFrame( + this._animate.bind(this) + ); + } - /*** RENDERING ***/ + /*** RENDERING ***/ - /*** + /*** Enables rendering ***/ - enableDrawing() { - this.renderer.enableDrawing(); - } + enableDrawing() { + this.renderer.enableDrawing(); + } - /*** + /*** Disables rendering ***/ - disableDrawing() { - this.renderer.disableDrawing(); - } + disableDrawing() { + this.renderer.disableDrawing(); + } - /*** + /*** Forces the rendering of the next frame, even if disabled ***/ - needRender() { - this.renderer.needRender(); - } + needRender() { + this.renderer.needRender(); + } - /*** + /*** Executes a callback on next frame params: @@ -255,182 +256,179 @@ export class Curtains { returns: @queueItem: the queue item. Allows to keep a track of it and set its keep property to false when needed ***/ - nextRender(callback, keep = false) { - return this.renderer.nextRender.add(callback, keep); - } + nextRender(callback, keep = false) { + return this.renderer.nextRender.add(callback, keep); + } - /*** + /*** Clear our WebGL renderer colors and depth buffers ***/ - clear() { - this.renderer && this.renderer.clear(); - } + clear() { + this.renderer && this.renderer.clear(); + } - /*** + /*** Clear our WebGL renderer depth buffer ***/ - clearDepth() { - this.renderer && this.renderer.clearDepth(); - } + clearDepth() { + this.renderer && this.renderer.clearDepth(); + } - /*** + /*** Clear our WebGL renderer color buffer ***/ - clearColor() { - this.renderer && this.renderer.clearColor(); - } - + clearColor() { + this.renderer && this.renderer.clearColor(); + } - /*** + /*** Check whether the created context is WebGL2 return: @isWebGL2 (bool): whether the created WebGL context is 2.0 or not ***/ - isWebGL2() { - return this.gl ? this.renderer._isWebGL2 : false; - } + isWebGL2() { + return this.gl ? this.renderer._isWebGL2 : false; + } - - /*** + /*** Tells our renderer to render the scene if the drawing is enabled ***/ - render() { - // always execute callback queue - this.renderer.nextRender.execute(); - - // If forceRender is true, force rendering this frame even if drawing is not enabled. - // If not, only render if enabled. - if(!this.renderer.state.drawingEnabled && !this.renderer.state.forceRender) { - return; - } + render() { + // always execute callback queue + this.renderer.nextRender.execute(); - // reset forceRender - if(this.renderer.state.forceRender) { - this.renderer.state.forceRender = false; - } + // If forceRender is true, force rendering this frame even if drawing is not enabled. + // If not, only render if enabled. + if ( + !this.renderer.state.drawingEnabled && + !this.renderer.state.forceRender + ) { + return; + } - // Curtains onRender callback - if(this._onRenderCallback) { - this._onRenderCallback(); - } + // reset forceRender + if (this.renderer.state.forceRender) { + this.renderer.state.forceRender = false; + } - this.renderer.render(); + // Curtains onRender callback + if (this._onRenderCallback) { + this._onRenderCallback(); } + this.renderer.render(); + } - /*** LISTENERS ***/ + /*** LISTENERS ***/ - /*** + /*** Adds our resize event listener if needed ***/ - _addListeners() { - // handling window resize event - this._resizeHandler = null; - if(this._autoResize) { - this._resizeHandler = this.resize.bind(this, true); - window.addEventListener("resize", this._resizeHandler, false); - } + _addListeners() { + // handling window resize event + this._resizeHandler = null; + if (this._autoResize) { + this._resizeHandler = this.resize.bind(this, true); + window.addEventListener("resize", this._resizeHandler, false); } + } + /*** SIZING ***/ - /*** SIZING ***/ - - /*** + /*** Set the pixel ratio property and update everything by calling the resize() method ***/ - setPixelRatio(pixelRatio, triggerCallback) { - this.pixelRatio = parseFloat(Math.max(pixelRatio, 1)) || 1; - this.renderer.setPixelRatio(pixelRatio); - // apply new pixel ratio to all our elements but don't trigger onAfterResize callback - this.resize(triggerCallback); - } - + setPixelRatio(pixelRatio, triggerCallback) { + this.pixelRatio = parseFloat(Math.max(pixelRatio, 1)) || 1; + this.renderer.setPixelRatio(pixelRatio); + // apply new pixel ratio to all our elements but don't trigger onAfterResize callback + this.resize(triggerCallback); + } - /*** + /*** Set our renderer container and canvas sizes and update the scroll values ***/ - _setSize() { - this.renderer.setSize(); + _setSize() { + this.renderer.setSize(); - // update scroll values ass well - if(this._scrollManager.shouldWatch) { - this._scrollManager.xOffset = window.pageXOffset; - this._scrollManager.yOffset = window.pageYOffset; - } + // update scroll values ass well + if (this._scrollManager.shouldWatch) { + this._scrollManager.xOffset = window.pageXOffset; + this._scrollManager.yOffset = window.pageYOffset; } + } - /*** + /*** Useful to get our container bounding rectangle without triggering a reflow/layout returns : @boundingRectangle (object): an object containing our container bounding rectangle (width, height, top and left properties) ***/ - getBoundingRect() { - return this.renderer._boundingRect; - } - + getBoundingRect() { + return this.renderer._boundingRect; + } - /*** + /*** Resize our container and the renderer params: @triggerCallback (bool): Whether we should trigger onAfterResize callback ***/ - resize(triggerCallback) { - if(!this.gl) return; + resize(triggerCallback) { + if (!this.gl) return; - this._setSize(); + this._setSize(); - this.renderer.resize(); + this.renderer.resize(); - this.nextRender(() => { - if(this._onAfterResizeCallback && triggerCallback) { - this._onAfterResizeCallback(); - } - }); - } + this.nextRender(() => { + if (this._onAfterResizeCallback && triggerCallback) { + this._onAfterResizeCallback(); + } + }); + } - /*** SCROLL ***/ + /*** SCROLL ***/ - /*** + /*** Init our ScrollManager class object ***/ - _initScroll() { - this._scrollManager = new ScrollManager({ - // init values - xOffset: window.pageXOffset, - yOffset: window.pageYOffset, - lastXDelta: 0, - lastYDelta: 0, - shouldWatch: this._watchScroll, - - onScroll: (lastXDelta, lastYDelta) => this._updateScroll(lastXDelta, lastYDelta), - }); - } - - /*** + _initScroll() { + this._scrollManager = new ScrollManager({ + // init values + xOffset: window.pageXOffset, + yOffset: window.pageYOffset, + lastXDelta: 0, + lastYDelta: 0, + shouldWatch: this._watchScroll, + + onScroll: (lastXDelta, lastYDelta) => + this._updateScroll(lastXDelta, lastYDelta), + }); + } + + /*** Handles the different values associated with a scroll event (scroll and delta values) If no plane watch the scroll then those values won't be retrieved to avoid unnecessary reflow calls If at least a plane is watching, update all watching planes positions based on the scroll values And force render for at least one frame to actually update the scene ***/ - _updateScroll(lastXDelta, lastYDelta) { - for(let i = 0; i < this.planes.length; i++) { - // if our plane is watching the scroll, update its position - if(this.planes[i].watchScroll) { - this.planes[i].updateScrollPosition(lastXDelta, lastYDelta); - } - } - - // be sure we'll update the scene even if drawing is disabled - this.renderer.needRender(); - - this._onScrollCallback && this._onScrollCallback(); + _updateScroll(lastXDelta, lastYDelta) { + for (let i = 0; i < this.planes.length; i++) { + // if our plane is watching the scroll, update its position + if (this.planes[i].watchScroll) { + this.planes[i].updateScrollPosition(lastXDelta, lastYDelta); + } } + // be sure we'll update the scene even if drawing is disabled + this.renderer.needRender(); + + this._onScrollCallback && this._onScrollCallback(); + } - /*** + /*** Updates the scroll manager X and Y scroll values as well as last X and Y deltas Internally called by the scroll handler if at least one plane is watching the scroll Could be called externally as well if the user wants to handle the scroll by himself @@ -439,63 +437,59 @@ export class Curtains { @x (float): scroll value along X axis @y (float): scroll value along Y axis ***/ - updateScrollValues(x, y) { - this._scrollManager.updateScrollValues(x, y); - } + updateScrollValues(x, y) { + this._scrollManager.updateScrollValues(x, y); + } - - /*** + /*** Returns last delta scroll values returns: @delta (object): an object containing X and Y last delta values ***/ - getScrollDeltas() { - return { - x: this._scrollManager.lastXDelta, - y: this._scrollManager.lastYDelta, - }; - } - + getScrollDeltas() { + return { + x: this._scrollManager.lastXDelta, + y: this._scrollManager.lastYDelta, + }; + } - /*** + /*** Returns last window scroll values returns: @scrollValues (object): an object containing X and Y last scroll values ***/ - getScrollValues() { - return { - x: this._scrollManager.xOffset, - y: this._scrollManager.yOffset, - }; - } + getScrollValues() { + return { + x: this._scrollManager.xOffset, + y: this._scrollManager.yOffset, + }; + } - /*** ADDING / REMOVING OBJECTS TO THE RENDERER ***/ + /*** ADDING / REMOVING OBJECTS TO THE RENDERER ***/ - /*** + /*** Always keep sync between renderer and Curtains scene objects when adding/removing objects ***/ - _keepSync() { - this.planes = this.renderer.planes; - this.shaderPasses = this.renderer.shaderPasses; - this.renderTargets = this.renderer.renderTargets; - } - + _keepSync() { + this.planes = this.renderer.planes; + this.shaderPasses = this.renderer.shaderPasses; + this.renderTargets = this.renderer.renderTargets; + } - /*** UTILS ***/ + /*** UTILS ***/ - /*** + /*** Linear interpolation helper defined in utils ***/ - lerp(start, end, amount) { - return lerp(start, end, amount); - } - + lerp(start, end, amount) { + return lerp(start, end, amount); + } - /*** EVENTS ***/ + /*** EVENTS ***/ - /*** + /*** This is called each time our container has been resized params : @@ -504,15 +498,15 @@ export class Curtains { returns : @this: our Curtains element to handle chaining ***/ - onAfterResize(callback) { - if(callback) { - this._onAfterResizeCallback = callback; - } - - return this; + onAfterResize(callback) { + if (callback) { + this._onAfterResizeCallback = callback; } - /*** + return this; + } + + /*** This is called when an error has been detected params: @@ -521,29 +515,28 @@ export class Curtains { returns: @this: our Curtains element to handle chaining ***/ - onError(callback) { - if(callback) { - this._onErrorCallback = callback; - } - - return this; + onError(callback) { + if (callback) { + this._onErrorCallback = callback; } - /*** + return this; + } + + /*** This triggers the onError callback and is called by the renderer when an error has been detected ***/ - _onRendererError() { - // be sure that the callback has been registered and only call the global error callback once - setTimeout(() => { - if(this._onErrorCallback && !this.errors) { - this._onErrorCallback(); - } - this.errors = true; - }, 0); - } - - - /*** + _onRendererError() { + // be sure that the callback has been registered and only call the global error callback once + setTimeout(() => { + if (this._onErrorCallback && !this.errors) { + this._onErrorCallback(); + } + this.errors = true; + }, 0); + } + + /*** This is called when the WebGL context has been successfully created params: @@ -552,25 +545,24 @@ export class Curtains { returns: @this: our Curtains element to handle chaining ***/ - onSuccess(callback) { - if(callback) { - this._onSuccessCallback = callback; - } - - return this; + onSuccess(callback) { + if (callback) { + this._onSuccessCallback = callback; } - /*** + return this; + } + + /*** This triggers the onSuccess callback and is called by the renderer when the context has been successfully created ***/ - _onRendererSuccess() { - setTimeout(() => { - this._onSuccessCallback && this._onSuccessCallback(); - }, 0); - } - + _onRendererSuccess() { + setTimeout(() => { + this._onSuccessCallback && this._onSuccessCallback(); + }, 0); + } - /*** + /*** This is called once our context has been lost params: @@ -579,23 +571,22 @@ export class Curtains { returns: @this: our Curtains element to handle chaining ***/ - onContextLost(callback) { - if(callback) { - this._onContextLostCallback = callback; - } - - return this; + onContextLost(callback) { + if (callback) { + this._onContextLostCallback = callback; } - /*** + return this; + } + + /*** This triggers the onContextLost callback and is called by the renderer when the context has been lost ***/ - _onRendererContextLost() { - this._onContextLostCallback && this._onContextLostCallback(); - } - + _onRendererContextLost() { + this._onContextLostCallback && this._onContextLostCallback(); + } - /*** + /*** This is called once our context has been restored params: @@ -604,23 +595,22 @@ export class Curtains { returns: @this: our Curtains element to handle chaining ***/ - onContextRestored(callback) { - if(callback) { - this._onContextRestoredCallback = callback; - } - - return this; + onContextRestored(callback) { + if (callback) { + this._onContextRestoredCallback = callback; } - /*** + return this; + } + + /*** This triggers the onContextRestored callback and is called by the renderer when the context has been restored ***/ - _onRendererContextRestored() { - this._onContextRestoredCallback && this._onContextRestoredCallback(); - } - + _onRendererContextRestored() { + this._onContextRestoredCallback && this._onContextRestoredCallback(); + } - /*** + /*** This is called once at each request animation frame call params: @@ -629,16 +619,15 @@ export class Curtains { returns: @this: our Curtains element to handle chaining ***/ - onRender(callback) { - if(callback) { - this._onRenderCallback = callback; - } - - return this; + onRender(callback) { + if (callback) { + this._onRenderCallback = callback; } + return this; + } - /*** + /*** This is called each time window is scrolled and if our scrollManager is active params : @@ -647,35 +636,34 @@ export class Curtains { returns : @this: our Curtains element to handle chaining ***/ - onScroll(callback) { - if(callback) { - this._onScrollCallback = callback; - } - - return this; + onScroll(callback) { + if (callback) { + this._onScrollCallback = callback; } + return this; + } - /*** DESTROYING ***/ + /*** DESTROYING ***/ - /*** + /*** Dispose everything ***/ - dispose() { - this.renderer.dispose(); - } - + dispose() { + this.renderer.dispose(); + } - /*** + /*** This is called when the renderer has finished disposing all the WebGL stuff ***/ - _onRendererDisposed() { - // cancel animation frame - this._animationFrameID && window.cancelAnimationFrame(this._animationFrameID); - - // remove event listeners - this._resizeHandler && window.removeEventListener("resize", this._resizeHandler, false); - this._scrollManager && this._scrollManager.dispose(); - } - -} \ No newline at end of file + _onRendererDisposed() { + // cancel animation frame + this._animationFrameID && + window.cancelAnimationFrame(this._animationFrameID); + + // remove event listeners + this._resizeHandler && + window.removeEventListener("resize", this._resizeHandler, false); + this._scrollManager && this._scrollManager.dispose(); + } +} diff --git a/src/core/Renderer.js b/src/core/Renderer.js index c684f2b..ece0a0d 100644 --- a/src/core/Renderer.js +++ b/src/core/Renderer.js @@ -1,8 +1,7 @@ -import {Scene} from "./Scene.js"; -import {CacheManager} from "../utils/CacheManager.js"; -import {CallbackQueueManager} from "../utils/CallbackQueueManager.js"; -import {throwWarning} from '../utils/utils.js'; - +import { Scene } from "./Scene.js"; +import { CacheManager } from "../utils/CacheManager.js"; +import { CallbackQueueManager } from "../utils/CallbackQueueManager.js"; +import { throwWarning } from "../utils/utils.js"; /*** Here we create our Renderer object @@ -26,825 +25,900 @@ import {throwWarning} from '../utils/utils.js'; ***/ export class Renderer { - constructor({ - // inherited from Curtains class object - alpha, - antialias, - premultipliedAlpha, - depth, - failIfMajorPerformanceCaveat, - preserveDrawingBuffer, - stencil, - container, - pixelRatio, - renderingScale, - production, - - // callbacks passed by the Curtains class object on instantiation - onError, - onSuccess, - onContextLost, - onContextRestored, - onDisposed, - onSceneChange, - }) { - this.type = "Renderer"; - // context attributes - this.alpha = alpha; - this.antialias = antialias; - this.premultipliedAlpha = premultipliedAlpha; - this.depth = depth; - this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat; - this.preserveDrawingBuffer = preserveDrawingBuffer; - this.stencil = stencil; - - this.container = container; - - this.pixelRatio = pixelRatio; - this._renderingScale = renderingScale; - - this.production = production; - - // callbacks - this.onError = onError; - this.onSuccess = onSuccess; - this.onContextLost = onContextLost; - this.onContextRestored = onContextRestored; - this.onDisposed = onDisposed; - - // keep sync between Curtains objects arrays and renderer objects arrays - this.onSceneChange = onSceneChange; - - // managing our webgl draw states - this.initState(); - - // create the canvas - this.canvas = document.createElement("canvas"); - - // set our webgl context - const glAttributes = { - alpha: this.alpha, - premultipliedAlpha: this.premultipliedAlpha, - antialias: this.antialias, - depth: this.depth, - failIfMajorPerformanceCaveat: this.failIfMajorPerformanceCaveat, - preserveDrawingBuffer: this.preserveDrawingBuffer, - stencil: this.stencil, - }; - - // try webgl2 context first - this.gl = this.canvas.getContext("webgl2", glAttributes); - this._isWebGL2 = !!this.gl; - // fallback to webgl1 - if(!this.gl) { - this.gl = this.canvas.getContext("webgl", glAttributes) || this.canvas.getContext("experimental-webgl", glAttributes); - } + constructor({ + // inherited from Curtains class object + alpha, + antialias, + premultipliedAlpha, + depth, + failIfMajorPerformanceCaveat, + preserveDrawingBuffer, + stencil, + container, + pixelRatio, + renderingScale, + production, + + // callbacks passed by the Curtains class object on instantiation + onError, + onSuccess, + onContextLost, + onContextRestored, + onDisposed, + onSceneChange, + }) { + this.type = "Renderer"; + // context attributes + this.alpha = alpha; + this.antialias = antialias; + this.premultipliedAlpha = premultipliedAlpha; + this.depth = depth; + this.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat; + this.preserveDrawingBuffer = preserveDrawingBuffer; + this.stencil = stencil; + + this.container = container; + + this.pixelRatio = pixelRatio; + this._renderingScale = renderingScale; + + this.production = production; + + // callbacks + this.onError = onError; + this.onSuccess = onSuccess; + this.onContextLost = onContextLost; + this.onContextRestored = onContextRestored; + this.onDisposed = onDisposed; + + // keep sync between Curtains objects arrays and renderer objects arrays + this.onSceneChange = onSceneChange; + + // managing our webgl draw states + this.initState(); + + // create the canvas + this.canvas = document.createElement("canvas"); + + // set our webgl context + const glAttributes = { + alpha: this.alpha, + premultipliedAlpha: this.premultipliedAlpha, + antialias: this.antialias, + depth: this.depth, + failIfMajorPerformanceCaveat: this.failIfMajorPerformanceCaveat, + preserveDrawingBuffer: this.preserveDrawingBuffer, + stencil: this.stencil, + }; + + // try webgl2 context first + this.gl = this.canvas.getContext("webgl2", glAttributes); + this._isWebGL2 = !!this.gl; + // fallback to webgl1 + if (!this.gl) { + this.gl = + this.canvas.getContext("webgl", glAttributes) || + this.canvas.getContext("experimental-webgl", glAttributes); + } - // WebGL context could not be created - if(!this.gl) { - if(!this.production) throwWarning(this.type + ": WebGL context could not be created"); + // WebGL context could not be created + if (!this.gl) { + if (!this.production) + throwWarning(this.type + ": WebGL context could not be created"); - this.state.isActive = false; + this.state.isActive = false; - if(this.onError) { - this.onError(); - } + if (this.onError) { + this.onError(); + } - return; - } - else if(this.onSuccess) { - this.onSuccess(); - } - - this.initRenderer(); + return; + } else if (this.onSuccess) { + this.onSuccess(); } - /*** + this.initRenderer(); + } + + /*** Set/reset our context state object ***/ - initState() { - this.state = { - // if we are currently rendering - isActive: true, - isContextLost: true, - drawingEnabled: true, - forceRender: false, - - // current program ID - currentProgramID: null, - - // current geometry drawn - currentGeometryID: null, - // whether we should force buffer bindings update - forceBufferUpdate: false, - - // if we're using depth test or not - depthTest: null, - // blending - blending: null, - // face culling - cullFace: null, - - // current frame buffer ID - frameBufferID: null, - // current scene pass ID - scenePassIndex: null, - - // textures - activeTexture: null, - unpackAlignment: null, - flipY: null, - premultiplyAlpha: null, - }; - } - - /*** + initState() { + this.state = { + // if we are currently rendering + isActive: true, + isContextLost: true, + drawingEnabled: true, + forceRender: false, + + // current program ID + currentProgramID: null, + + // current geometry drawn + currentGeometryID: null, + // whether we should force buffer bindings update + forceBufferUpdate: false, + + // if we're using depth test or not + depthTest: null, + // blending + blending: null, + // face culling + cullFace: null, + + // current frame buffer ID + frameBufferID: null, + // current scene pass ID + scenePassIndex: null, + + // textures + activeTexture: null, + unpackAlignment: null, + flipY: null, + premultiplyAlpha: null, + }; + } + + /*** Add a callback queueing manager (execute functions on the next render call, see CallbackQueueManager class object) ***/ - initCallbackQueueManager() { - this.nextRender = new CallbackQueueManager(); - } + initCallbackQueueManager() { + this.nextRender = new CallbackQueueManager(); + } - /*** + /*** Init our renderer ***/ - initRenderer() { - this.planes = []; - this.renderTargets = []; - this.shaderPasses = []; - - // context is not lost - this.state.isContextLost = false; - this.state.maxTextureSize = this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE); - - // callback queue - this.initCallbackQueueManager(); - - // set blend func - this.setBlendFunc(); - - // enable depth by default - this.setDepthFunc(); - this.setDepthTest(true); - - // texture cache - this.cache = new CacheManager(); - - // init our scene - this.scene = new Scene(this); - - // get webgl extensions - this.getExtensions(); - - // handling context - this._contextLostHandler = this.contextLost.bind(this); - this.canvas.addEventListener("webglcontextlost", this._contextLostHandler, false); - - this._contextRestoredHandler = this.contextRestored.bind(this); - this.canvas.addEventListener("webglcontextrestored", this._contextRestoredHandler, false); - } - - /*** + initRenderer() { + this.planes = []; + this.renderTargets = []; + this.shaderPasses = []; + + // context is not lost + this.state.isContextLost = false; + this.state.maxTextureSize = this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE); + + // callback queue + this.initCallbackQueueManager(); + + // set blend func + this.setBlendFunc(); + + // enable depth by default + this.setDepthFunc(); + this.setDepthTest(true); + + // texture cache + this.cache = new CacheManager(); + + // init our scene + this.scene = new Scene(this); + + // get webgl extensions + this.getExtensions(); + + // handling context + this._contextLostHandler = this.contextLost.bind(this); + this.canvas.addEventListener( + "webglcontextlost", + this._contextLostHandler, + false + ); + + this._contextRestoredHandler = this.contextRestored.bind(this); + this.canvas.addEventListener( + "webglcontextrestored", + this._contextRestoredHandler, + false + ); + } + + /*** Get all available WebGL extensions based on WebGL used version Called on init and on context restoration ***/ - getExtensions() { - this.extensions = []; - if(this._isWebGL2) { - this.extensions['EXT_color_buffer_float'] = this.gl.getExtension('EXT_color_buffer_float'); - this.extensions['OES_texture_float_linear'] = this.gl.getExtension('OES_texture_float_linear'); - this.extensions['EXT_texture_filter_anisotropic'] = this.gl.getExtension('EXT_texture_filter_anisotropic'); - this.extensions['WEBGL_lose_context'] = this.gl.getExtension('WEBGL_lose_context'); - } else { - this.extensions['OES_vertex_array_object'] = this.gl.getExtension('OES_vertex_array_object'); - this.extensions['OES_texture_float'] = this.gl.getExtension('OES_texture_float'); - this.extensions['OES_texture_float_linear'] = this.gl.getExtension('OES_texture_float_linear'); - this.extensions['OES_texture_half_float'] = this.gl.getExtension('OES_texture_half_float'); - this.extensions['OES_texture_half_float_linear'] = this.gl.getExtension('OES_texture_half_float_linear'); - this.extensions['EXT_texture_filter_anisotropic'] = this.gl.getExtension('EXT_texture_filter_anisotropic'); - this.extensions['OES_element_index_uint'] = this.gl.getExtension('OES_element_index_uint'); - this.extensions['OES_standard_derivatives'] = this.gl.getExtension('OES_standard_derivatives'); - this.extensions['EXT_sRGB'] = this.gl.getExtension('EXT_sRGB'); - this.extensions['WEBGL_depth_texture'] = this.gl.getExtension('WEBGL_depth_texture'); - this.extensions['WEBGL_draw_buffers'] = this.gl.getExtension('WEBGL_draw_buffers'); - this.extensions['WEBGL_lose_context'] = this.gl.getExtension('WEBGL_lose_context'); - } + getExtensions() { + this.extensions = []; + if (this._isWebGL2) { + this.extensions["EXT_color_buffer_float"] = this.gl.getExtension( + "EXT_color_buffer_float" + ); + this.extensions["OES_texture_float_linear"] = this.gl.getExtension( + "OES_texture_float_linear" + ); + this.extensions["EXT_texture_filter_anisotropic"] = this.gl.getExtension( + "EXT_texture_filter_anisotropic" + ); + this.extensions["WEBGL_lose_context"] = + this.gl.getExtension("WEBGL_lose_context"); + } else { + this.extensions["OES_vertex_array_object"] = this.gl.getExtension( + "OES_vertex_array_object" + ); + this.extensions["OES_texture_float"] = + this.gl.getExtension("OES_texture_float"); + this.extensions["OES_texture_float_linear"] = this.gl.getExtension( + "OES_texture_float_linear" + ); + this.extensions["OES_texture_half_float"] = this.gl.getExtension( + "OES_texture_half_float" + ); + this.extensions["OES_texture_half_float_linear"] = this.gl.getExtension( + "OES_texture_half_float_linear" + ); + this.extensions["EXT_texture_filter_anisotropic"] = this.gl.getExtension( + "EXT_texture_filter_anisotropic" + ); + this.extensions["OES_element_index_uint"] = this.gl.getExtension( + "OES_element_index_uint" + ); + this.extensions["OES_standard_derivatives"] = this.gl.getExtension( + "OES_standard_derivatives" + ); + this.extensions["EXT_sRGB"] = this.gl.getExtension("EXT_sRGB"); + this.extensions["WEBGL_depth_texture"] = this.gl.getExtension( + "WEBGL_depth_texture" + ); + this.extensions["WEBGL_draw_buffers"] = + this.gl.getExtension("WEBGL_draw_buffers"); + this.extensions["WEBGL_lose_context"] = + this.gl.getExtension("WEBGL_lose_context"); } + } + /*** HANDLING CONTEXT LOST/RESTORE ***/ - /*** HANDLING CONTEXT LOST/RESTORE ***/ - - /*** + /*** Called when the WebGL context is lost ***/ - contextLost(event) { - this.state.isContextLost = true; - - // do not try to restore the context if we're disposing everything! - if(!this.state.isActive) return; + contextLost(event) { + this.state.isContextLost = true; - event.preventDefault(); + // do not try to restore the context if we're disposing everything! + if (!this.state.isActive) return; - this.nextRender.add(() => this.onContextLost && this.onContextLost()); - } + event.preventDefault(); + this.nextRender.add(() => this.onContextLost && this.onContextLost()); + } - /*** + /*** Call this method to restore your context ***/ - restoreContext() { - // do not try to restore the context if we're disposing everything! - if(!this.state.isActive) return; - - this.initState(); - - if(this.gl && this.extensions['WEBGL_lose_context']) { - this.extensions['WEBGL_lose_context'].restoreContext(); - } - else { - if(!this.gl && !this.production) { - throwWarning(this.type + ": Could not restore the context because the context is not defined"); - } - else if(!this.extensions['WEBGL_lose_context'] && !this.production) { - throwWarning(this.type + ": Could not restore the context because the restore context extension is not defined"); - } - - if(this.onError) { - this.onError(); - } - } + restoreContext() { + // do not try to restore the context if we're disposing everything! + if (!this.state.isActive) return; + + this.initState(); + + if (this.gl && this.extensions["WEBGL_lose_context"]) { + this.extensions["WEBGL_lose_context"].restoreContext(); + } else { + if (!this.gl && !this.production) { + throwWarning( + this.type + + ": Could not restore the context because the context is not defined" + ); + } else if (!this.extensions["WEBGL_lose_context"] && !this.production) { + throwWarning( + this.type + + ": Could not restore the context because the restore context extension is not defined" + ); + } + + if (this.onError) { + this.onError(); + } } + } - /*** + /*** Check that all objects and textures have been restored returns: @isRestored (bool): whether everything has been restored or not ***/ - isContextexFullyRestored() { - let isRestored = true; - for(let i = 0; i < this.renderTargets.length; i++) { - if(!this.renderTargets[i].textures[0]._canDraw) { - isRestored = false; - } - break; - } + isContextexFullyRestored() { + let isRestored = true; + for (let i = 0; i < this.renderTargets.length; i++) { + if (!this.renderTargets[i].textures[0]._canDraw) { + isRestored = false; + } + break; + } - if(isRestored) { - for(let i = 0; i < this.planes.length; i++) { - if(!this.planes[i]._canDraw) { - isRestored = false; - break; - } - else { - for(let j = 0; j < this.planes[i].textures.length; j++) { - if(!this.planes[i].textures[j]._canDraw) { - isRestored = false; - break; - } - } - } + if (isRestored) { + for (let i = 0; i < this.planes.length; i++) { + if (!this.planes[i]._canDraw) { + isRestored = false; + break; + } else { + for (let j = 0; j < this.planes[i].textures.length; j++) { + if (!this.planes[i].textures[j]._canDraw) { + isRestored = false; + break; } + } } + } + } - if(isRestored) { - for(let i = 0; i < this.shaderPasses.length; i++) { - if(!this.shaderPasses[i]._canDraw) { - isRestored = false; - break; - } - else { - for(let j = 0; j < this.shaderPasses[i].textures.length; j++) { - if(!this.shaderPasses[i].textures[j]._canDraw) { - isRestored = false; - break; - } - } - } + if (isRestored) { + for (let i = 0; i < this.shaderPasses.length; i++) { + if (!this.shaderPasses[i]._canDraw) { + isRestored = false; + break; + } else { + for (let j = 0; j < this.shaderPasses[i].textures.length; j++) { + if (!this.shaderPasses[i].textures[j]._canDraw) { + isRestored = false; + break; } + } } - - return isRestored; + } } - /*** + return isRestored; + } + + /*** Called when the WebGL context is restored ***/ - contextRestored() { - this.getExtensions(); - - // set blend func - this.setBlendFunc(); + contextRestored() { + this.getExtensions(); - // enable depth by default - this.setDepthFunc(); - this.setDepthTest(true); + // set blend func + this.setBlendFunc(); - // clear texture and programs cache - this.cache.clear(); + // enable depth by default + this.setDepthFunc(); + this.setDepthTest(true); - // reset draw stacks - this.scene.initStacks(); + // clear texture and programs cache + this.cache.clear(); - // we need to reset everything : planes programs, shaders, buffers and textures ! - for(let i = 0; i < this.renderTargets.length; i++) { - this.renderTargets[i]._restoreContext(); - } + // reset draw stacks + this.scene.initStacks(); - for(let i = 0; i < this.planes.length; i++) { - this.planes[i]._restoreContext(); - } + // we need to reset everything : planes programs, shaders, buffers and textures ! + for (let i = 0; i < this.renderTargets.length; i++) { + this.renderTargets[i]._restoreContext(); + } - // same goes for shader passes - for(let i = 0; i < this.shaderPasses.length; i++) { - this.shaderPasses[i]._restoreContext(); - } + for (let i = 0; i < this.planes.length; i++) { + this.planes[i]._restoreContext(); + } - // callback if everything is restored - const isRestoredQueue = this.nextRender.add(() => { - const isRestored = this.isContextexFullyRestored(); - if(isRestored) { - isRestoredQueue.keep = false; + // same goes for shader passes + for (let i = 0; i < this.shaderPasses.length; i++) { + this.shaderPasses[i]._restoreContext(); + } - // start drawing again - this.state.isContextLost = false; + // callback if everything is restored + const isRestoredQueue = this.nextRender.add(() => { + const isRestored = this.isContextexFullyRestored(); + if (isRestored) { + isRestoredQueue.keep = false; - if(this.onContextRestored) { - this.onContextRestored(); - } + // start drawing again + this.state.isContextLost = false; - // we've changed the objects, keep Curtains class in sync with our renderer - this.onSceneChange(); + if (this.onContextRestored) { + this.onContextRestored(); + } - // force next frame render whatever our drawing flag value - this.needRender(); - } - }, true); - } + // we've changed the objects, keep Curtains class in sync with our renderer + this.onSceneChange(); + // force next frame render whatever our drawing flag value + this.needRender(); + } + }, true); + } - /*** SIZING ***/ + /*** SIZING ***/ - /*** + /*** Updates pixelRatio property ***/ - setPixelRatio(pixelRatio) { - this.pixelRatio = pixelRatio; - } + setPixelRatio(pixelRatio) { + this.pixelRatio = pixelRatio; + } - /*** + /*** Set/reset container sizes and WebGL viewport sizes ***/ - setSize() { - if(!this.gl) return; - - // get our container bounding client rectangle - const containerBoundingRect = this.container.getBoundingClientRect(); - - // use the bounding rect values - this._boundingRect = { - width: containerBoundingRect.width * this.pixelRatio, - height: containerBoundingRect.height * this.pixelRatio, - top: containerBoundingRect.top * this.pixelRatio, - left: containerBoundingRect.left * this.pixelRatio, - }; - - // iOS Safari > 8+ has a known bug due to navigation bar appearing/disappearing - // this causes wrong bounding client rect calculations, especially negative top value when it shouldn't - // to fix this we'll use a dirty but useful workaround - - // first we check if we're on iOS Safari - const isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/); - const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; - - if(isSafari && iOS) { - // if we are on iOS Safari we'll need a custom function to retrieve our container absolute top position - function getTopOffset(el) { - let topOffset = 0; - while(el && !isNaN(el.offsetTop)) { - topOffset += el.offsetTop - el.scrollTop; - el = el.offsetParent; - } - return topOffset; - } - - // use it to update our top value - this._boundingRect.top = getTopOffset(this.container) * this.pixelRatio; - } - - this.canvas.style.width = Math.floor(this._boundingRect.width / this.pixelRatio) + "px"; - this.canvas.style.height = Math.floor(this._boundingRect.height / this.pixelRatio) + "px"; - - this.canvas.width = Math.floor(this._boundingRect.width * this._renderingScale); - this.canvas.height = Math.floor(this._boundingRect.height * this._renderingScale); - - this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight); - } - - /*** + setSize() { + if (!this.gl) return; + + // get our container bounding client rectangle + const containerBoundingRect = this.container.getBoundingClientRect(); + + // use the bounding rect values + this._boundingRect = { + width: containerBoundingRect.width * this.pixelRatio, + height: containerBoundingRect.height * this.pixelRatio, + top: containerBoundingRect.top * this.pixelRatio, + left: containerBoundingRect.left * this.pixelRatio, + }; + + // iOS Safari > 8+ has a known bug due to navigation bar appearing/disappearing + // this causes wrong bounding client rect calculations, especially negative top value when it shouldn't + // to fix this we'll use a dirty but useful workaround + + // first we check if we're on iOS Safari + // const isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/); + // const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; + + // if(isSafari && iOS) { + // // if we are on iOS Safari we'll need a custom function to retrieve our container absolute top position + // function getTopOffset(el) { + // let topOffset = 0; + // while(el && !isNaN(el.offsetTop)) { + // topOffset += el.offsetTop - el.scrollTop; + // el = el.offsetParent; + // } + // return topOffset; + // } + + // // use it to update our top value + // this._boundingRect.top = getTopOffset(this.container) * this.pixelRatio; + // } + + this.canvas.style.width = + Math.floor(this._boundingRect.width / this.pixelRatio) + "px"; + this.canvas.style.height = + Math.floor(this._boundingRect.height / this.pixelRatio) + "px"; + + this.canvas.width = Math.floor( + this._boundingRect.width * this._renderingScale + ); + this.canvas.height = Math.floor( + this._boundingRect.height * this._renderingScale + ); + + this.gl.viewport( + 0, + 0, + this.gl.drawingBufferWidth, + this.gl.drawingBufferHeight + ); + } + + /*** Resize all our elements: planes, shader passes and render targets Their textures will be resized as well ***/ - resize() { - // resize the planes only if they are fully initiated - for(let i = 0; i < this.planes.length; i++) { - if(this.planes[i]._canDraw) { - this.planes[i].resize(); - } - } - - // resize the shader passes only if they are fully initiated - for(let i = 0; i < this.shaderPasses.length; i++) { - if(this.shaderPasses[i]._canDraw) { - this.shaderPasses[i].resize(); - } - } + resize() { + // resize the planes only if they are fully initiated + for (let i = 0; i < this.planes.length; i++) { + if (this.planes[i]._canDraw) { + this.planes[i].resize(); + } + } - // resize the render targets - for(let i = 0; i < this.renderTargets.length; i++) { - this.renderTargets[i].resize(); - } + // resize the shader passes only if they are fully initiated + for (let i = 0; i < this.shaderPasses.length; i++) { + if (this.shaderPasses[i]._canDraw) { + this.shaderPasses[i].resize(); + } + } - // be sure we'll update the scene even if drawing is disabled - this.needRender(); + // resize the render targets + for (let i = 0; i < this.renderTargets.length; i++) { + this.renderTargets[i].resize(); } + // be sure we'll update the scene even if drawing is disabled + this.needRender(); + } - /*** CLEAR SCENE ***/ + /*** CLEAR SCENE ***/ - /*** + /*** Clear our WebGL scene colors and depth ***/ - clear() { - this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT); - } + clear() { + this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT); + } - /*** + /*** Clear our WebGL scene depth ***/ - clearDepth() { - this.gl.clear(this.gl.DEPTH_BUFFER_BIT); - } + clearDepth() { + this.gl.clear(this.gl.DEPTH_BUFFER_BIT); + } - /*** + /*** Clear our WebGL scene colors and depth ***/ - clearColor() { - this.gl.clear(this.gl.COLOR_BUFFER_BIT); - } + clearColor() { + this.gl.clear(this.gl.COLOR_BUFFER_BIT); + } + /*** FRAME BUFFER OBJECTS ***/ - /*** FRAME BUFFER OBJECTS ***/ - - /*** + /*** Called to bind or unbind a FBO params: @frameBuffer (frameBuffer): if frameBuffer is not null, bind it, unbind it otherwise @cancelClear (bool / undefined): if we should cancel clearing the frame buffer (typically on init & resize) ***/ - bindFrameBuffer(frameBuffer, cancelClear) { - let bufferId = null; - if(frameBuffer) { - bufferId = frameBuffer.index; - - // new frame buffer, bind it - if(bufferId !== this.state.frameBufferID) { - this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, frameBuffer._frameBuffer); - - this.gl.viewport(0, 0, frameBuffer._size.width, frameBuffer._size.height); - - // if we should clear the buffer content - if(frameBuffer._shouldClear && !cancelClear) { - this.clear(); - } - } - } - else if(this.state.frameBufferID !== null) { - this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null); - this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight); - } - - this.state.frameBufferID = bufferId; + bindFrameBuffer(frameBuffer, cancelClear) { + let bufferId = null; + if (frameBuffer) { + bufferId = frameBuffer.index; + + // new frame buffer, bind it + if (bufferId !== this.state.frameBufferID) { + this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, frameBuffer._frameBuffer); + + this.gl.viewport( + 0, + 0, + frameBuffer._size.width, + frameBuffer._size.height + ); + + // if we should clear the buffer content + if (frameBuffer._shouldClear && !cancelClear) { + this.clear(); + } + } + } else if (this.state.frameBufferID !== null) { + this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null); + this.gl.viewport( + 0, + 0, + this.gl.drawingBufferWidth, + this.gl.drawingBufferHeight + ); } + this.state.frameBufferID = bufferId; + } - /*** DEPTH ***/ + /*** DEPTH ***/ - /*** + /*** Called to set whether the renderer will handle depth test or not Depth test is enabled by default params: @setDepth (boolean): if we should enable or disable the depth test ***/ - setDepthTest(depthTest) { - if(depthTest && !this.state.depthTest) { - this.state.depthTest = depthTest; - // enable depth test - this.gl.enable(this.gl.DEPTH_TEST); - } - else if(!depthTest && this.state.depthTest) { - this.state.depthTest = depthTest; - // disable depth test - this.gl.disable(this.gl.DEPTH_TEST); - } + setDepthTest(depthTest) { + if (depthTest && !this.state.depthTest) { + this.state.depthTest = depthTest; + // enable depth test + this.gl.enable(this.gl.DEPTH_TEST); + } else if (!depthTest && this.state.depthTest) { + this.state.depthTest = depthTest; + // disable depth test + this.gl.disable(this.gl.DEPTH_TEST); } + } - /*** + /*** Called to set the depth buffer behavior Only available option is gl.LEQUAL at the moment (see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/depthFunc) ***/ - setDepthFunc() { - this.gl.depthFunc(this.gl.LEQUAL); - } + setDepthFunc() { + this.gl.depthFunc(this.gl.LEQUAL); + } + /*** BLENDING ***/ - /*** BLENDING ***/ - - /*** + /*** Whether we should enable or disable the blending state Used to draw transparent planes params: @enableBlending (boolean): if we should enable or disable the blending (default to false) ***/ - setBlending(enableBlending = false) { - if(enableBlending && !this.state.blending) { - this.state.blending = enableBlending; - // enable blending - this.gl.enable(this.gl.BLEND); - } - else if(!enableBlending && this.state.blending) { - this.state.blending = enableBlending; - // disable blending - this.gl.disable(this.gl.BLEND); - } + setBlending(enableBlending = false) { + if (enableBlending && !this.state.blending) { + this.state.blending = enableBlending; + // enable blending + this.gl.enable(this.gl.BLEND); + } else if (!enableBlending && this.state.blending) { + this.state.blending = enableBlending; + // disable blending + this.gl.disable(this.gl.BLEND); } + } - /*** + /*** Called to set the blending function (transparency) ***/ - setBlendFunc() { - // allows transparency - // based on how three.js solves this - this.gl.enable(this.gl.BLEND); - if(this.premultipliedAlpha) { - this.gl.blendFuncSeparate(this.gl.ONE, this.gl.ONE_MINUS_SRC_ALPHA, this.gl.ONE, this.gl.ONE_MINUS_SRC_ALPHA); - } - else { - this.gl.blendFuncSeparate(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA, this.gl.ONE, this.gl.ONE_MINUS_SRC_ALPHA); - } + setBlendFunc() { + // allows transparency + // based on how three.js solves this + this.gl.enable(this.gl.BLEND); + if (this.premultipliedAlpha) { + this.gl.blendFuncSeparate( + this.gl.ONE, + this.gl.ONE_MINUS_SRC_ALPHA, + this.gl.ONE, + this.gl.ONE_MINUS_SRC_ALPHA + ); + } else { + this.gl.blendFuncSeparate( + this.gl.SRC_ALPHA, + this.gl.ONE_MINUS_SRC_ALPHA, + this.gl.ONE, + this.gl.ONE_MINUS_SRC_ALPHA + ); } + } + /*** FACE CULLING ***/ - /*** FACE CULLING ***/ - - /*** + /*** Called to set whether we should cull an object face or not params: @cullFace (boolean): what face we should cull ***/ - setFaceCulling(cullFace) { - if(this.state.cullFace !== cullFace) { - this.state.cullFace = cullFace; - - if(cullFace === "none") { - this.gl.disable(this.gl.CULL_FACE); - } - else { - // default to back face culling - const faceCulling = cullFace === "front" ? this.gl.FRONT : this.gl.BACK; - - this.gl.enable(this.gl.CULL_FACE); - this.gl.cullFace(faceCulling); - } - } + setFaceCulling(cullFace) { + if (this.state.cullFace !== cullFace) { + this.state.cullFace = cullFace; + + if (cullFace === "none") { + this.gl.disable(this.gl.CULL_FACE); + } else { + // default to back face culling + const faceCulling = cullFace === "front" ? this.gl.FRONT : this.gl.BACK; + + this.gl.enable(this.gl.CULL_FACE); + this.gl.cullFace(faceCulling); + } } + } - /*** + /*** Tell WebGL to use the specified program if it's not already in use params: @program (object): a program object ***/ - useProgram(program) { - if(this.state.currentProgramID === null || this.state.currentProgramID !== program.id) { - this.gl.useProgram(program.program); - this.state.currentProgramID = program.id; - } + useProgram(program) { + if ( + this.state.currentProgramID === null || + this.state.currentProgramID !== program.id + ) { + this.gl.useProgram(program.program); + this.state.currentProgramID = program.id; } + } + /*** PLANES ***/ - /*** PLANES ***/ - - - /*** + /*** Removes a Plane element (that has already been disposed) from the scene and the planes array params: @plane (Plane object): the plane to remove ***/ - removePlane(plane) { - if(!this.gl) return; + removePlane(plane) { + if (!this.gl) return; - // remove from our planes array - this.planes = this.planes.filter(element => element.uuid !== plane.uuid); + // remove from our planes array + this.planes = this.planes.filter((element) => element.uuid !== plane.uuid); - // remove from scene stacks - this.scene.removePlane(plane); + // remove from scene stacks + this.scene.removePlane(plane); - plane = null; + plane = null; - // clear the buffer to clean scene - if(this.gl) this.clear(); - - // we've removed an object, keep Curtains class in sync with our renderer - this.onSceneChange(); - } + // clear the buffer to clean scene + if (this.gl) this.clear(); + // we've removed an object, keep Curtains class in sync with our renderer + this.onSceneChange(); + } - /*** POST PROCESSING ***/ + /*** POST PROCESSING ***/ - - /*** + /*** Completely remove a RenderTarget element params: @renderTarget (RenderTarget object): the render target to remove ***/ - removeRenderTarget(renderTarget) { - if(!this.gl) return; - - let hasPlane = this.planes.find(plane => plane.type !== "PingPongPlane" && plane.target && plane.target.uuid === renderTarget.uuid); - - // loop through all planes that might use that render target and reset it - for(let i = 0; i < this.planes.length; i++) { - if(this.planes[i].target && this.planes[i].target.uuid === renderTarget.uuid) { - this.planes[i].target = null; - } - } - - this.renderTargets = this.renderTargets.filter(element => element.uuid !== renderTarget.uuid); + removeRenderTarget(renderTarget) { + if (!this.gl) return; + + let hasPlane = this.planes.find( + (plane) => + plane.type !== "PingPongPlane" && + plane.target && + plane.target.uuid === renderTarget.uuid + ); + + // loop through all planes that might use that render target and reset it + for (let i = 0; i < this.planes.length; i++) { + if ( + this.planes[i].target && + this.planes[i].target.uuid === renderTarget.uuid + ) { + this.planes[i].target = null; + } + } - // update render target indexes - for(let i = 0; i < this.renderTargets.length; i++) { - this.renderTargets[i].index = i; - } + this.renderTargets = this.renderTargets.filter( + (element) => element.uuid !== renderTarget.uuid + ); - renderTarget = null; + // update render target indexes + for (let i = 0; i < this.renderTargets.length; i++) { + this.renderTargets[i].index = i; + } - // clear the buffer to clean scene - if(this.gl) this.clear(); + renderTarget = null; - // we had at least a plane that was rendered in this render targets stack - // re init stacks - if(hasPlane) { - this.scene.resetPlaneStacks(); - } + // clear the buffer to clean scene + if (this.gl) this.clear(); - // we've removed an object, keep Curtains class in sync with our renderer - this.onSceneChange(); + // we had at least a plane that was rendered in this render targets stack + // re init stacks + if (hasPlane) { + this.scene.resetPlaneStacks(); } + // we've removed an object, keep Curtains class in sync with our renderer + this.onSceneChange(); + } - /*** SHADER PASSES ***/ + /*** SHADER PASSES ***/ - - /*** + /*** Removes a ShaderPass element (that has already been disposed) from the scene and the shaderPasses array params: @shaderPass (ShaderPass object): the shader pass to remove ***/ - removeShaderPass(shaderPass) { - if(!this.gl) return; + removeShaderPass(shaderPass) { + if (!this.gl) return; - // remove from shaderPasses our array - this.shaderPasses = this.shaderPasses.filter(element => element.uuid !== shaderPass.uuid); + // remove from shaderPasses our array + this.shaderPasses = this.shaderPasses.filter( + (element) => element.uuid !== shaderPass.uuid + ); - // remove from scene stacks - this.scene.removeShaderPass(shaderPass); + // remove from scene stacks + this.scene.removeShaderPass(shaderPass); - shaderPass = null; + shaderPass = null; - // clear the buffer to clean scene - if(this.gl) this.clear(); + // clear the buffer to clean scene + if (this.gl) this.clear(); - // we've removed an object, keep Curtains class in sync with our renderer - this.onSceneChange(); - } + // we've removed an object, keep Curtains class in sync with our renderer + this.onSceneChange(); + } - - /*** + /*** Enables the render loop ***/ - enableDrawing() { - this.state.drawingEnabled = true; - } + enableDrawing() { + this.state.drawingEnabled = true; + } - /*** + /*** Disables the render loop ***/ - disableDrawing() { - this.state.drawingEnabled = false; - } + disableDrawing() { + this.state.drawingEnabled = false; + } - /*** + /*** Forces the rendering of the next frame, even if disabled ***/ - needRender() { - this.state.forceRender = true; - } + needRender() { + this.state.forceRender = true; + } - /*** + /*** Called at each draw call to render our scene and its content Also execute our nextRender callback queue ***/ - render() { - if(!this.gl) return; + render() { + if (!this.gl) return; - // clear scene first - this.clear(); + // clear scene first + this.clear(); - // reset attributes buffer state - this.state.currentGeometryID = null; - - // draw our scene content - this.scene.draw(); - } + // reset attributes buffer state + this.state.currentGeometryID = null; + // draw our scene content + this.scene.draw(); + } - /*** DISPOSING ***/ + /*** DISPOSING ***/ - /*** + /*** Delete all cached programs ***/ - deletePrograms() { - // delete all programs from manager - for(let i = 0; i < this.cache.programs.length; i++) { - const program = this.cache.programs[i]; - this.gl.deleteProgram(program.program); - } + deletePrograms() { + // delete all programs from manager + for (let i = 0; i < this.cache.programs.length; i++) { + const program = this.cache.programs[i]; + this.gl.deleteProgram(program.program); } + } - /*** + /*** Dispose our WebGL context and all its objects ***/ - dispose() { - if(!this.gl) return; + dispose() { + if (!this.gl) return; - this.state.isActive = false; + this.state.isActive = false; - // be sure to delete all planes - while(this.planes.length > 0) { - this.removePlane(this.planes[0]); - } + // be sure to delete all planes + while (this.planes.length > 0) { + this.removePlane(this.planes[0]); + } - // we need to delete the shader passes also - while(this.shaderPasses.length > 0) { - this.removeShaderPass(this.shaderPasses[0]); - } + // we need to delete the shader passes also + while (this.shaderPasses.length > 0) { + this.removeShaderPass(this.shaderPasses[0]); + } - // finally we need to delete the render targets - while(this.renderTargets.length > 0) { - this.removeRenderTarget(this.renderTargets[0]); - } + // finally we need to delete the render targets + while (this.renderTargets.length > 0) { + this.removeRenderTarget(this.renderTargets[0]); + } - // wait for all planes to be deleted before stopping everything - let disposeQueue = this.nextRender.add(() => { - if(this.planes.length === 0 && this.shaderPasses.length === 0 && this.renderTargets.length === 0) { - // clear from callback queue - disposeQueue.keep = false; + // wait for all planes to be deleted before stopping everything + let disposeQueue = this.nextRender.add(() => { + if ( + this.planes.length === 0 && + this.shaderPasses.length === 0 && + this.renderTargets.length === 0 + ) { + // clear from callback queue + disposeQueue.keep = false; - this.deletePrograms(); + this.deletePrograms(); - // clear the buffer to clean scene - this.clear(); + // clear the buffer to clean scene + this.clear(); - this.canvas.removeEventListener("webgllost", this._contextLostHandler, false); - this.canvas.removeEventListener("webglrestored", this._contextRestoredHandler, false); + this.canvas.removeEventListener( + "webgllost", + this._contextLostHandler, + false + ); + this.canvas.removeEventListener( + "webglrestored", + this._contextRestoredHandler, + false + ); - // lose context - if(this.gl && this.extensions['WEBGL_lose_context']) { - this.extensions['WEBGL_lose_context'].loseContext(); - } + // lose context + if (this.gl && this.extensions["WEBGL_lose_context"]) { + this.extensions["WEBGL_lose_context"].loseContext(); + } - // clear canvas state - this.canvas.width = this.canvas.width; + // clear canvas state + this.canvas.width = this.canvas.width; - this.gl = null; + this.gl = null; - // remove canvas from DOM - this.container.removeChild(this.canvas); + // remove canvas from DOM + this.container.removeChild(this.canvas); - this.container = null; - this.canvas = null; + this.container = null; + this.canvas = null; - this.onDisposed && this.onDisposed(); - } - }, true); - } -} \ No newline at end of file + this.onDisposed && this.onDisposed(); + } + }, true); + } +} diff --git a/src/core/Texture.js b/src/core/Texture.js index 3743eb0..f4b54be 100644 --- a/src/core/Texture.js +++ b/src/core/Texture.js @@ -1,7 +1,12 @@ -import {Mat4} from '../math/Mat4.js'; -import {Vec2} from '../math/Vec2.js'; -import {Vec3} from '../math/Vec3.js'; -import {generateUUID, throwError, throwWarning, isPowerOf2} from '../utils/utils.js'; +import { Mat4 } from "../math/Mat4.js"; +import { Vec2 } from "../math/Vec2.js"; +import { Vec3 } from "../math/Vec3.js"; +import { + generateUUID, + throwError, + throwWarning, + isPowerOf2, +} from "../utils/utils.js"; /*** Texture class objects used by render targets, shader passes and planes. @@ -38,1168 +43,1383 @@ const tempVec3 = new Vec3(); const textureTranslation = new Mat4(); export class Texture { - constructor(renderer, { - isFBOTexture = false, - fromTexture = false, - loader, - - // texture sampler name - sampler, - - // floating point textures - floatingPoint = "none", - - // texture parameters - premultiplyAlpha = false, - anisotropy = 1, - generateMipmap = null, - - wrapS, - wrapT, - minFilter, - magFilter, - } = {}) { - this.type = "Texture"; - - // we could pass our curtains object OR our curtains renderer object - renderer = renderer && renderer.renderer || renderer; - - if(!renderer || renderer.type !== "Renderer") { - throwError(this.type + ": Renderer not passed as first argument", renderer); - } - else if(!renderer.gl) { - if(!renderer.production) throwError(this.type + ": Unable to create a " + this.type + " because the Renderer WebGL context is not defined"); - - // return if no gl context - return; - } - this.renderer = renderer; - this.gl = this.renderer.gl; - - this.uuid = generateUUID(); - - // texture parameters - this._globalParameters = { - // global gl context parameters - unpackAlignment: 4, - flipY: !isFBOTexture, - premultiplyAlpha: false, - shouldPremultiplyAlpha: premultiplyAlpha, - - // texImage2D properties - floatingPoint: floatingPoint, - type: this.gl.UNSIGNED_BYTE, - internalFormat: this.gl.RGBA, - format: this.gl.RGBA, - }; - - this.parameters = { - // per texture parameters - anisotropy, - generateMipmap: generateMipmap, - - wrapS: wrapS || this.gl.CLAMP_TO_EDGE, - wrapT: wrapT || this.gl.CLAMP_TO_EDGE, - minFilter: minFilter || this.gl.LINEAR, - magFilter: magFilter || this.gl.LINEAR, - - _shouldUpdate: true, - }; - - // per texture state - this._initState(); - - // is it a frame buffer object texture? - // if it's not, type will change when the source will be loaded - this.sourceType = isFBOTexture ? "fbo" : "empty"; - - // whether to use cache for image textures - this._useCache = true; - - this._samplerName = sampler; - - // prepare texture sampler - this._sampler = { - isActive: false, - isTextureBound: false, - texture: this.gl.createTexture(), // always create a gl texture - }; - - // we will always declare a texture matrix - this._textureMatrix = { - matrix: new Mat4(), - isActive: false - }; - - // actual size will be set later on - this._size = { - width: 1, - height: 1, - }; - - this.scale = new Vec2(1); - this.scale.onChange(() => this.resize()); - - this.offset = new Vec2(); - this.offset.onChange(() => this.resize()); - - // source loading and GPU uploading flags - this._loader = loader; - this._sourceLoaded = false; - this._uploaded = false; - - // _willUpdate and shouldUpdate property are set to false by default - // we will handle that in the setSource() method for videos and canvases - this._willUpdate = false; - this.shouldUpdate = false; - - // if we need to force a texture update - this._forceUpdate = false; - - // custom user properties - this.userData = {}; - - // useful flag to avoid binding texture that does not belong to current context - this._canDraw = false; - - // is it set from an existing texture? - if(fromTexture) { - this._copyOnInit = true; - this._copiedFrom = fromTexture; - - // everything else will be done when adding a parent to that texture - return; - } - - this._copyOnInit = false; + constructor( + renderer, + { + isFBOTexture = false, + fromTexture = false, + loader, + + // texture sampler name + sampler, + + // floating point textures + floatingPoint = "none", + + // texture parameters + premultiplyAlpha = false, + anisotropy = 1, + generateMipmap = null, + + wrapS, + wrapT, + minFilter, + magFilter, + } = {} + ) { + this.type = "Texture"; + + // we could pass our curtains object OR our curtains renderer object + renderer = (renderer && renderer.renderer) || renderer; + + if (!renderer || renderer.type !== "Renderer") { + throwError( + this.type + ": Renderer not passed as first argument", + renderer + ); + } else if (!renderer.gl) { + if (!renderer.production) + throwError( + this.type + + ": Unable to create a " + + this.type + + " because the Renderer WebGL context is not defined" + ); - // init our texture - this._initTexture(); + // return if no gl context + return; + } + this.renderer = renderer; + this.gl = this.renderer.gl; + + this.uuid = generateUUID(); + + // texture parameters + this._globalParameters = { + // global gl context parameters + unpackAlignment: 4, + flipY: !isFBOTexture, + premultiplyAlpha: false, + shouldPremultiplyAlpha: premultiplyAlpha, + + // texImage2D properties + floatingPoint: floatingPoint, + type: this.gl.UNSIGNED_BYTE, + internalFormat: this.gl.RGBA, + format: this.gl.RGBA, + }; + + this.parameters = { + // per texture parameters + anisotropy, + generateMipmap: generateMipmap, + + wrapS: wrapS || this.gl.CLAMP_TO_EDGE, + wrapT: wrapT || this.gl.CLAMP_TO_EDGE, + minFilter: minFilter || this.gl.LINEAR, + magFilter: magFilter || this.gl.LINEAR, + + _shouldUpdate: true, + }; + + // per texture state + this._initState(); + + // is it a frame buffer object texture? + // if it's not, type will change when the source will be loaded + this.sourceType = isFBOTexture ? "fbo" : "empty"; + + // whether to use cache for image textures + this._useCache = true; + + this._samplerName = sampler; + + // prepare texture sampler + this._sampler = { + isActive: false, + isTextureBound: false, + texture: this.gl.createTexture(), // always create a gl texture + }; + + // we will always declare a texture matrix + this._textureMatrix = { + matrix: new Mat4(), + isActive: false, + }; + + // actual size will be set later on + this._size = { + width: 1, + height: 1, + }; + + this.scale = new Vec2(1); + this.scale.onChange(() => this.resize()); + + this.offset = new Vec2(); + this.offset.onChange(() => this.resize()); + + // source loading and GPU uploading flags + this._loader = loader; + this._sourceLoaded = false; + this._uploaded = false; + + // _willUpdate and shouldUpdate property are set to false by default + // we will handle that in the setSource() method for videos and canvases + this._willUpdate = false; + this.shouldUpdate = false; + + // if we need to force a texture update + this._forceUpdate = false; + + // custom user properties + this.userData = {}; + + // useful flag to avoid binding texture that does not belong to current context + this._canDraw = false; + + // is it set from an existing texture? + if (fromTexture) { + this._copyOnInit = true; + this._copiedFrom = fromTexture; + + // everything else will be done when adding a parent to that texture + return; } + this._copyOnInit = false; - /*** + // init our texture + this._initTexture(); + } + + /*** Init per-texture parameters state Called on init and on context restoration to force parameters settings ***/ - _initState() { - this._state = { - anisotropy: 1, - generateMipmap: false, - - wrapS: null, - wrapT: null, - minFilter: null, - magFilter: this.gl.LINEAR, // default to gl.LINEAR - }; - } - - /*** + _initState() { + this._state = { + anisotropy: 1, + generateMipmap: false, + + wrapS: null, + wrapT: null, + minFilter: null, + magFilter: this.gl.LINEAR, // default to gl.LINEAR + }; + } + + /*** Init our texture object ***/ - _initTexture() { - // bind the texture the target (TEXTURE_2D) of the active texture unit. - this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); - - if(this.sourceType === "empty") { - // avoid flipY on non DOM elements - this._globalParameters.flipY = false; - // update global parameters before drawing an empty texture - this._updateGlobalTexParameters(); - - // draw a black plane before the real texture's content has been loaded - this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, 1, 1, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255])); - - this._canDraw = true; - } + _initTexture() { + // bind the texture the target (TEXTURE_2D) of the active texture unit. + this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); + + if (this.sourceType === "empty") { + // avoid flipY on non DOM elements + this._globalParameters.flipY = false; + // update global parameters before drawing an empty texture + this._updateGlobalTexParameters(); + + // draw a black plane before the real texture's content has been loaded + this.gl.texImage2D( + this.gl.TEXTURE_2D, + 0, + this.gl.RGBA, + 1, + 1, + 0, + this.gl.RGBA, + this.gl.UNSIGNED_BYTE, + new Uint8Array([0, 0, 0, 255]) + ); + + this._canDraw = true; } + } + /*** RESTORING CONTEXT ***/ - /*** RESTORING CONTEXT ***/ - - /*** + /*** Restore a WebGL texture that is a copy Depending on whether it's a copy from start or not, just reset its uniforms or run the full init And finally copy our original texture back again ***/ - _restoreFromTexture() { - // init again if needed - if(!this._copyOnInit) { - this._initTexture(); - } - - // a texture shouldn't be restored if it does not have a parent - // since it's always the parent that calls the _restoreContext() method - if(this._parent) { - // set uniforms again - this._setTextureUniforms(); - - // update the texture matrix uniform as well - this._setSize(); - } + _restoreFromTexture() { + // init again if needed + if (!this._copyOnInit) { + this._initTexture(); + } - // copy our texture again - this.copy(this._copiedFrom); + // a texture shouldn't be restored if it does not have a parent + // since it's always the parent that calls the _restoreContext() method + if (this._parent) { + // set uniforms again + this._setTextureUniforms(); - this._canDraw = true; + // update the texture matrix uniform as well + this._setSize(); } + // copy our texture again + this.copy(this._copiedFrom); + + this._canDraw = true; + } - /*** + /*** Restore our WebGL texture If it is an original texture, just re run the init function and eventually reset its source If it is a texture set from another texture, wait for the original texture to be ready first ***/ - _restoreContext() { - // avoid binding that texture before reseting it - this._canDraw = false; + _restoreContext() { + // avoid binding that texture before reseting it + this._canDraw = false; - // reinit sampler and texture matrix - this._sampler.texture = this.gl.createTexture(); - this._sampler.isActive = false; - this._sampler.isTextureBound = false; + // reinit sampler and texture matrix + this._sampler.texture = this.gl.createTexture(); + this._sampler.isActive = false; + this._sampler.isTextureBound = false; - this._textureMatrix.isActive = false; + this._textureMatrix.isActive = false; - this._initState(); + this._initState(); - // force mip map regeneration if needed - this._state.generateMipmap = false; - this.parameters._shouldUpdate = true; - - // this is an original texture, reset it right away - if(!this._copiedFrom) { - this._initTexture(); - - if(this._parent) { - this._setParent(); - } - - if(this.source) { - this.setSource(this.source); - - // cache again if it is an image - // also since it's an image it has been uploaded in setSource() - if(this.sourceType === "image") { - this.renderer.cache.addTexture(this); - } - else { - // force update - this.needUpdate(); - } - } - - this._canDraw = true; + // force mip map regeneration if needed + this._state.generateMipmap = false; + this.parameters._shouldUpdate = true; + + // this is an original texture, reset it right away + if (!this._copiedFrom) { + this._initTexture(); + + if (this._parent) { + this._setParent(); + } + + if (this.source) { + this.setSource(this.source); + + // cache again if it is an image + // also since it's an image it has been uploaded in setSource() + if (this.sourceType === "image") { + this.renderer.cache.addTexture(this); + } else { + // force update + this.needUpdate(); } - else { - // wait for the original texure to be ready before attempting to restore the copy - const queue = this.renderer.nextRender.add(() => { - if(this._copiedFrom._canDraw) { - this._restoreFromTexture(); - // remove from callback queue - queue.keep = false; - } - }, true); + } + + this._canDraw = true; + } else { + // wait for the original texure to be ready before attempting to restore the copy + const queue = this.renderer.nextRender.add(() => { + if (this._copiedFrom._canDraw) { + this._restoreFromTexture(); + // remove from callback queue + queue.keep = false; } + }, true); } + } + /*** ADD PARENT ***/ - /*** ADD PARENT ***/ - - /*** + /*** Adds a parent to a texture Sets its index, its parent and add it to the parent textures array as well Then runs _setParent() to set the size and uniforms if needed ***/ - addParent(parent) { - if(!parent || (parent.type !== "Plane" && parent.type !== "PingPongPlane" && parent.type !== "ShaderPass" && parent.type !== "RenderTarget")) { - if(!this.renderer.production) { - throwWarning(this.type + ": cannot add texture as a child of ", parent, " because it is not a valid parent"); - } - - return; - } - - // add parent property - this._parent = parent; - // update parent textures array - this.index = this._parent.textures.length; - this._parent.textures.push(this); + addParent(parent) { + if ( + !parent || + (parent.type !== "Plane" && + parent.type !== "PingPongPlane" && + parent.type !== "ShaderPass" && + parent.type !== "RenderTarget") + ) { + if (!this.renderer.production) { + throwWarning( + this.type + ": cannot add texture as a child of ", + parent, + " because it is not a valid parent" + ); + } - // now set its parent for real - this._setParent(); + return; } + // add parent property + this._parent = parent; + // update parent textures array + this.index = this._parent.textures.length; + this._parent.textures.push(this); - /*** + // now set its parent for real + this._setParent(); + } + + /*** Sets the parent Basically sets the uniforms names and locations and sizes ***/ - _setParent() { - // prepare texture sampler - this._sampler.name = this._samplerName || "uSampler" + this.index; - - // we will always declare a texture matrix - this._textureMatrix.name = this._samplerName ? this._samplerName + "Matrix" : "uTextureMatrix" + this.index; - - // if the parent has a program it means its not a render target texture - if(this._parent._program) { - if(!this._parent._program.compiled) { - if(!this.renderer.production) { - throwWarning(this.type + ": Unable to create the texture because the program is not valid"); - } - - return; - } - - // set uniform - this._setTextureUniforms(); - - if(this._copyOnInit) { - // wait for original texture to be ready before copying it - const waitForOriginalTexture = this.renderer.nextRender.add(() => { - if(this._copiedFrom._canDraw && this._copiedFrom._uploaded) { - this.copy(this._copiedFrom); - waitForOriginalTexture.keep = false; - } - }, true); - - // we're done! - return; - } - - if(!this.source) { - // set its size based on parent element size for now - this._size = { - width: this._parent._boundingRect.document.width, - height: this._parent._boundingRect.document.height, - }; - } - else if(this._parent.loader) { - // we're adding a parent to a texture that already has a source - // it means the source should have been loaded before the parent was set - // add it to the right asset array if needed - this._parent.loader._addSourceToParent(this.source, this.sourceType); - } - - this._setSize(); + _setParent() { + // prepare texture sampler + this._sampler.name = this._samplerName || "uSampler" + this.index; + + // we will always declare a texture matrix + this._textureMatrix.name = this._samplerName + ? this._samplerName + "Matrix" + : "uTextureMatrix" + this.index; + + // if the parent has a program it means its not a render target texture + if (this._parent._program) { + if (!this._parent._program.compiled) { + if (!this.renderer.production) { + throwWarning( + this.type + + ": Unable to create the texture because the program is not valid" + ); } - else if(this._parent.type === "RenderTarget") { - // its a render target texture, it has no uniform location and no texture matrix - this._size = { - width: this._parent._size && this._parent._size.width || this.renderer._boundingRect.width, - height: this._parent._size && this._parent._size.height || this.renderer._boundingRect.height, - }; - // updload to gpu - this._upload(); + return; + } - // update render texture parameters because it will never be drawn (hence not called) - this._updateTexParameters(); + // set uniform + this._setTextureUniforms(); - this._canDraw = true; - } - } + if (this._copyOnInit) { + // wait for original texture to be ready before copying it + const waitForOriginalTexture = this.renderer.nextRender.add(() => { + if (this._copiedFrom._canDraw && this._copiedFrom._uploaded) { + this.copy(this._copiedFrom); + waitForOriginalTexture.keep = false; + } + }, true); + // we're done! + return; + } - /*** + if (!this.source) { + // set its size based on parent element size for now + this._size = { + width: this._parent._boundingRect.document.width, + height: this._parent._boundingRect.document.height, + }; + } else if (this._parent.loader) { + // we're adding a parent to a texture that already has a source + // it means the source should have been loaded before the parent was set + // add it to the right asset array if needed + this._parent.loader._addSourceToParent(this.source, this.sourceType); + } + + this._setSize(); + } else if (this._parent.type === "RenderTarget") { + // its a render target texture, it has no uniform location and no texture matrix + this._size = { + width: + (this._parent._size && this._parent._size.width) || + this.renderer._boundingRect.width, + height: + (this._parent._size && this._parent._size.height) || + this.renderer._boundingRect.height, + }; + + // updload to gpu + this._upload(); + + // update render texture parameters because it will never be drawn (hence not called) + this._updateTexParameters(); + + this._canDraw = true; + } + } + + /*** Checks if this texture has a parent return: @hasParent (bool): whether this texture has a parent or not ***/ - hasParent() { - return !!this._parent; - } - + hasParent() { + return !!this._parent; + } - /*** SEND DATA TO THE GPU ***/ + /*** SEND DATA TO THE GPU ***/ - /*** + /*** Check if our textures is effectively used in our shaders If so, set it to active, get its uniform locations and bind it to our texture unit ***/ - _setTextureUniforms() { - // check if our texture is used in our program shaders - // if so, get its uniform locations and bind it to our program - const activeUniforms = this._parent._program.activeUniforms; - - for(let i = 0; i < activeUniforms.textures.length; i++) { - if(activeUniforms.textures[i] === this._sampler.name) { - // this texture is active - this._sampler.isActive = true; - - // use the program and get our sampler and texture matrices uniforms - this.renderer.useProgram(this._parent._program); - - // set our texture sampler uniform - this._sampler.location = this.gl.getUniformLocation(this._parent._program.program, this._sampler.name); - - // set texture matrix uniform location only if active - const isTextureMatrixActive = activeUniforms.textureMatrices.find(textureMatrix => - textureMatrix === this._textureMatrix.name - ); - - if(isTextureMatrixActive) { - this._textureMatrix.isActive = true; - this._textureMatrix.location = this.gl.getUniformLocation(this._parent._program.program, this._textureMatrix.name); - } - - // tell the shader we bound the texture to our indexed texture unit - this.gl.uniform1i(this._sampler.location, this.index); - } + _setTextureUniforms() { + // check if our texture is used in our program shaders + // if so, get its uniform locations and bind it to our program + const activeUniforms = this._parent._program.activeUniforms; + + for (let i = 0; i < activeUniforms.textures.length; i++) { + if (activeUniforms.textures[i] === this._sampler.name) { + // this texture is active + this._sampler.isActive = true; + + // use the program and get our sampler and texture matrices uniforms + this.renderer.useProgram(this._parent._program); + + // set our texture sampler uniform + this._sampler.location = this.gl.getUniformLocation( + this._parent._program.program, + this._sampler.name + ); + + // set texture matrix uniform location only if active + const isTextureMatrixActive = activeUniforms.textureMatrices.find( + (textureMatrix) => textureMatrix === this._textureMatrix.name + ); + + if (isTextureMatrixActive) { + this._textureMatrix.isActive = true; + this._textureMatrix.location = this.gl.getUniformLocation( + this._parent._program.program, + this._textureMatrix.name + ); } + + // tell the shader we bound the texture to our indexed texture unit + this.gl.uniform1i(this._sampler.location, this.index); + } } + } - /*** + /*** This copies an already existing Texture object to our texture params: @texture (Texture): texture to set from ***/ - copy(texture) { - if(!texture || texture.type !== "Texture") { - if(!this.renderer.production) { - throwWarning(this.type + ": Unable to set the texture from texture:", texture); - } - return; - } - - // copy states - this._globalParameters = Object.assign({}, texture._globalParameters); - this._state = Object.assign({}, texture._state); + copy(texture) { + if (!texture || texture.type !== "Texture") { + if (!this.renderer.production) { + throwWarning( + this.type + ": Unable to set the texture from texture:", + texture + ); + } + return; + } - // regenerate mips if needed - this.parameters.generateMipmap = texture.parameters.generateMipmap; - this._state.generateMipmap = null; + // copy states + this._globalParameters = Object.assign({}, texture._globalParameters); + this._state = Object.assign({}, texture._state); - // copy source - this._size = texture._size; + // regenerate mips if needed + this.parameters.generateMipmap = texture.parameters.generateMipmap; + this._state.generateMipmap = null; - // trigger loaded callback if needed - if(!this._sourceLoaded && texture._sourceLoaded) { - this._onSourceLoadedCallback && this._onSourceLoadedCallback(); - } + // copy source + this._size = texture._size; - this._sourceLoaded = texture._sourceLoaded; + // trigger loaded callback if needed + if (!this._sourceLoaded && texture._sourceLoaded) { + this._onSourceLoadedCallback && this._onSourceLoadedCallback(); + } - // trigger uploaded callback if needed - if(!this._uploaded && texture._uploaded) { - this._onSourceUploadedCallback && this._onSourceUploadedCallback(); - } + this._sourceLoaded = texture._sourceLoaded; - this._uploaded = texture._uploaded; + // trigger uploaded callback if needed + if (!this._uploaded && texture._uploaded) { + this._onSourceUploadedCallback && this._onSourceUploadedCallback(); + } - this.sourceType = texture.sourceType; - this.source = texture.source; - this._videoFrameCallbackID = texture._videoFrameCallbackID; + this._uploaded = texture._uploaded; - // copy texture - this._sampler.texture = texture._sampler.texture; + this.sourceType = texture.sourceType; + this.source = texture.source; + this._videoFrameCallbackID = texture._videoFrameCallbackID; - // keep a track from the original one - this._copiedFrom = texture; + // copy texture + this._sampler.texture = texture._sampler.texture; - // update its texture matrix if needed and we're good to go! - if(this._parent && this._parent._program && (!this._canDraw || !this._textureMatrix.matrix)) { - this._setSize(); + // keep a track from the original one + this._copiedFrom = texture; - this._canDraw = true; - } + // update its texture matrix if needed and we're good to go! + if ( + this._parent && + this._parent._program && + (!this._canDraw || !this._textureMatrix.matrix) + ) { + this._setSize(); - this._updateTexParameters(); - - // force rendering - this.renderer.needRender(); + this._canDraw = true; } + this._updateTexParameters(); + + // force rendering + this.renderer.needRender(); + } - /*** LOADING SOURCES ***/ + /*** LOADING SOURCES ***/ - /*** + /*** This uses our source as texture params: @source (images/video/canvas): either an image, a video or a canvas ***/ - setSource(source) { - // fire callback during load (useful for a loader) - if(!this._sourceLoaded) { - // texture source loaded callback - this.renderer.nextRender.add(() => this._onSourceLoadedCallback && this._onSourceLoadedCallback()); - } - - // get new source type based on source tag - const sourceType = source.tagName.toUpperCase() === "IMG" ? "image" : source.tagName.toLowerCase(); - - // somehow if the texture type changes from image to video or canvas, the cache won't work anymore - if(sourceType === "video" || sourceType === "canvas") { - this._useCache = false; - } - - // check for cache - if(this._useCache) { - const cachedTexture = this.renderer.cache.getTextureFromSource(source); - - // if we have a cached texture, just copy it - if (cachedTexture && cachedTexture.uuid !== this.uuid) { - // force texture uploaded callback - if (!this._uploaded) { - // GPU uploading callback - this.renderer.nextRender.add(() => this._onSourceUploadedCallback && this._onSourceUploadedCallback()); - - this._uploaded = true; - } - - this.copy(cachedTexture); + setSource(source) { + // fire callback during load (useful for a loader) + if (!this._sourceLoaded) { + // texture source loaded callback + this.renderer.nextRender.add( + () => this._onSourceLoadedCallback && this._onSourceLoadedCallback() + ); + } - this.resize(); + // get new source type based on source tag + const sourceType = + source.tagName.toUpperCase() === "IMG" + ? "image" + : source.tagName.toLowerCase(); - return; - } - } + // somehow if the texture type changes from image to video or canvas, the cache won't work anymore + if (sourceType === "video" || sourceType === "canvas") { + this._useCache = false; + } - if(this.sourceType === "empty" || this.sourceType !== sourceType) { - if(sourceType === "video") { - // a video should be updated by default - this._willUpdate = false; - this.shouldUpdate = true; - } - else if(sourceType === "canvas") { - // a canvas could change each frame so we need to update it by default - this._willUpdate = true; - this.shouldUpdate = true; - } - else if(sourceType === "image") { - this._willUpdate = false; - this.shouldUpdate = false; - } - else { - if(!this.renderer.production) { - throwWarning(this.type + ": this HTML tag could not be converted into a texture:", source.tagName); - } - - return; - } + // check for cache + if (this._useCache) { + const cachedTexture = this.renderer.cache.getTextureFromSource(source); + + // if we have a cached texture, just copy it + if (cachedTexture && cachedTexture.uuid !== this.uuid) { + // force texture uploaded callback + if (!this._uploaded) { + // GPU uploading callback + this.renderer.nextRender.add( + () => + this._onSourceUploadedCallback && this._onSourceUploadedCallback() + ); + + this._uploaded = true; } - // set new source - this.source = source; - this.sourceType = sourceType; - - this._size = { - width: this.source.naturalWidth || this.source.width || this.source.videoWidth, - height: this.source.naturalHeight || this.source.height || this.source.videoHeight, - }; - - // our source is loaded now - this._sourceLoaded = true; - - // no need to set WebGL active texture unit here, we'll do it at run time for each texture - // binding the texture is enough - this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); + this.copy(cachedTexture); this.resize(); - this._globalParameters.flipY = true; - this._globalParameters.premultiplyAlpha = this._globalParameters.shouldPremultiplyAlpha; - - // upload our webgl texture only if it is an image - // canvas and video textures will be updated anyway in the rendering loop - // thanks to the shouldUpdate and _willUpdate flags - if(this.sourceType === "image") { - // generate mip maps if they have not been explicitly disabled - this.parameters.generateMipmap = this.parameters.generateMipmap || this.parameters.generateMipmap === null; - this.parameters._shouldUpdate = this.parameters.generateMipmap; - this._state.generateMipmap = false; + return; + } + } - this._upload(); + if (this.sourceType === "empty" || this.sourceType !== sourceType) { + if (sourceType === "video") { + // a video should be updated by default + this._willUpdate = false; + this.shouldUpdate = true; + } else if (sourceType === "canvas") { + // a canvas could change each frame so we need to update it by default + this._willUpdate = true; + this.shouldUpdate = true; + } else if (sourceType === "image") { + this._willUpdate = false; + this.shouldUpdate = false; + } else { + if (!this.renderer.production) { + throwWarning( + this.type + + ": this HTML tag could not be converted into a texture:", + source.tagName + ); } - // update scene - this.renderer.needRender(); + return; + } + } + + // set new source + this.source = source; + this.sourceType = sourceType; + + this._size = { + width: + this.source.naturalWidth || this.source.width || this.source.videoWidth, + height: + this.source.naturalHeight || + this.source.height || + this.source.videoHeight, + }; + + // our source is loaded now + this._sourceLoaded = true; + + // no need to set WebGL active texture unit here, we'll do it at run time for each texture + // binding the texture is enough + this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); + + this.resize(); + + this._globalParameters.flipY = true; + this._globalParameters.premultiplyAlpha = + this._globalParameters.shouldPremultiplyAlpha; + + // upload our webgl texture only if it is an image + // canvas and video textures will be updated anyway in the rendering loop + // thanks to the shouldUpdate and _willUpdate flags + if (this.sourceType === "image") { + // generate mip maps if they have not been explicitly disabled + this.parameters.generateMipmap = + this.parameters.generateMipmap || + this.parameters.generateMipmap === null; + this.parameters._shouldUpdate = this.parameters.generateMipmap; + this._state.generateMipmap = false; + + this._upload(); } + // update scene + this.renderer.needRender(); + } - /*** TEXTURE PARAMETERS ***/ + /*** TEXTURE PARAMETERS ***/ - /*** + /*** Updates textures parameters that depends on global WebGL context state Typically unpacking, flipY and premultiplied alpha Usually called before uploading a texture to the GPU ***/ - _updateGlobalTexParameters() { - // unpack alignment - if(this.renderer.state.unpackAlignment !== this._globalParameters.unpackAlignment) { - this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT, this._globalParameters.unpackAlignment); - this.renderer.state.unpackAlignment = this._globalParameters.unpackAlignment; - } + _updateGlobalTexParameters() { + // unpack alignment + if ( + this.renderer.state.unpackAlignment !== + this._globalParameters.unpackAlignment + ) { + this.gl.pixelStorei( + this.gl.UNPACK_ALIGNMENT, + this._globalParameters.unpackAlignment + ); + this.renderer.state.unpackAlignment = + this._globalParameters.unpackAlignment; + } - // flip Y only if source is not empty - if(this.renderer.state.flipY !== this._globalParameters.flipY) { - this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, this._globalParameters.flipY); - this.renderer.state.flipY = this._globalParameters.flipY; - } + // flip Y only if source is not empty + if (this.renderer.state.flipY !== this._globalParameters.flipY) { + this.gl.pixelStorei( + this.gl.UNPACK_FLIP_Y_WEBGL, + this._globalParameters.flipY + ); + this.renderer.state.flipY = this._globalParameters.flipY; + } - // premultiplied alpha only if source is not empty - if(this.renderer.state.premultiplyAlpha !== this._globalParameters.premultiplyAlpha) { - this.gl.pixelStorei(this.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this._globalParameters.premultiplyAlpha); - this.renderer.state.premultiplyAlpha = this._globalParameters.premultiplyAlpha; - } + // premultiplied alpha only if source is not empty + if ( + this.renderer.state.premultiplyAlpha !== + this._globalParameters.premultiplyAlpha + ) { + this.gl.pixelStorei( + this.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, + this._globalParameters.premultiplyAlpha + ); + this.renderer.state.premultiplyAlpha = + this._globalParameters.premultiplyAlpha; + } - // floating point textures - if(this._globalParameters.floatingPoint === "half-float") { - if(this.renderer._isWebGL2 && this.renderer.extensions['EXT_color_buffer_float']) { - this._globalParameters.internalFormat = this.gl.RGBA16F; - this._globalParameters.type = this.gl.HALF_FLOAT; - } - else if(this.renderer.extensions['OES_texture_half_float']) { - this._globalParameters.type = this.renderer.extensions['OES_texture_half_float'].HALF_FLOAT_OES; - } - else if(!this.renderer.production) { - throwWarning(this.type + ": could not use half-float textures because the extension is not available"); - } - } - else if(this._globalParameters.floatingPoint === "float") { - if(this.renderer._isWebGL2 && this.renderer.extensions['EXT_color_buffer_float']) { - this._globalParameters.internalFormat = this.gl.RGBA16F; - this._globalParameters.type = this.gl.FLOAT; - } - else if(this.renderer.extensions['OES_texture_float']) { - this._globalParameters.type = this.renderer.extensions['OES_texture_half_float'].FLOAT; - } - else if(!this.renderer.production) { - throwWarning(this.type + ": could not use float textures because the extension is not available"); - } - } + // floating point textures + if (this._globalParameters.floatingPoint === "half-float") { + if ( + this.renderer._isWebGL2 && + this.renderer.extensions["EXT_color_buffer_float"] + ) { + this._globalParameters.internalFormat = this.gl.RGBA16F; + this._globalParameters.type = this.gl.HALF_FLOAT; + } else if (this.renderer.extensions["OES_texture_half_float"]) { + this._globalParameters.type = + this.renderer.extensions["OES_texture_half_float"].HALF_FLOAT_OES; + } else if (!this.renderer.production) { + throwWarning( + this.type + + ": could not use half-float textures because the extension is not available" + ); + } + } else if (this._globalParameters.floatingPoint === "float") { + if ( + this.renderer._isWebGL2 && + this.renderer.extensions["EXT_color_buffer_float"] + ) { + this._globalParameters.internalFormat = this.gl.RGBA16F; + this._globalParameters.type = this.gl.FLOAT; + } else if (this.renderer.extensions["OES_texture_float"]) { + this._globalParameters.type = + this.renderer.extensions["OES_texture_half_float"].FLOAT; + } else if (!this.renderer.production) { + throwWarning( + this.type + + ": could not use float textures because the extension is not available" + ); + } } + } - /*** + /*** Updates per-textures parameters Wrapping, filters, anisotropy and mipmaps generation Usually called after uploading a texture to the GPU ***/ - _updateTexParameters() { - // be sure we're updating the right texture - if(this.index && this.renderer.state.activeTexture !== this.index) { - this._bindTexture(); - } - - // wrapS - if(this.parameters.wrapS !== this._state.wrapS) { - if(!this.renderer._isWebGL2 && (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height))) { - this.parameters.wrapS = this.gl.CLAMP_TO_EDGE; - } - - // handle wrong wrapS values - if( - this.parameters.wrapS !== this.gl.REPEAT - && this.parameters.wrapS !== this.gl.CLAMP_TO_EDGE - && this.parameters.wrapS !== this.gl.MIRRORED_REPEAT - ) { - if(!this.renderer.production) { - throwWarning(this.type + ": Wrong wrapS value", this.parameters.wrapS, "for this texture:", this, "\ngl.CLAMP_TO_EDGE wrapping will be used instead"); - } - this.parameters.wrapS = this.gl.CLAMP_TO_EDGE; - } - - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.parameters.wrapS); - this._state.wrapS = this.parameters.wrapS; - } + _updateTexParameters() { + // be sure we're updating the right texture + if (this.index && this.renderer.state.activeTexture !== this.index) { + this._bindTexture(); + } - // wrapT - if(this.parameters.wrapT !== this._state.wrapT) { - if(!this.renderer._isWebGL2 && (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height))) { - this.parameters.wrapT = this.gl.CLAMP_TO_EDGE; - } - - // handle wrong wrapT values - if( - this.parameters.wrapT !== this.gl.REPEAT - && this.parameters.wrapT !== this.gl.CLAMP_TO_EDGE - && this.parameters.wrapT !== this.gl.MIRRORED_REPEAT - ) { - if(!this.renderer.production) { - throwWarning(this.type + ": Wrong wrapT value", this.parameters.wrapT, "for this texture:", this, "\ngl.CLAMP_TO_EDGE wrapping will be used instead"); - } - this.parameters.wrapT = this.gl.CLAMP_TO_EDGE; - } - - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.parameters.wrapT); - this._state.wrapT = this.parameters.wrapT; + // wrapS + if (this.parameters.wrapS !== this._state.wrapS) { + if ( + !this.renderer._isWebGL2 && + (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height)) + ) { + this.parameters.wrapS = this.gl.CLAMP_TO_EDGE; + } + + // handle wrong wrapS values + if ( + this.parameters.wrapS !== this.gl.REPEAT && + this.parameters.wrapS !== this.gl.CLAMP_TO_EDGE && + this.parameters.wrapS !== this.gl.MIRRORED_REPEAT + ) { + if (!this.renderer.production) { + throwWarning( + this.type + ": Wrong wrapS value", + this.parameters.wrapS, + "for this texture:", + this, + "\ngl.CLAMP_TO_EDGE wrapping will be used instead" + ); } + this.parameters.wrapS = this.gl.CLAMP_TO_EDGE; + } + + this.gl.texParameteri( + this.gl.TEXTURE_2D, + this.gl.TEXTURE_WRAP_S, + this.parameters.wrapS + ); + this._state.wrapS = this.parameters.wrapS; + } - // generate mip map only if it has a source - if(this.parameters.generateMipmap && !this._state.generateMipmap && this.source) { - if(!this.renderer._isWebGL2 && (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height))) { - this.parameters.generateMipmap = false; - } - else { - this.gl.generateMipmap(this.gl.TEXTURE_2D); - } - - this._state.generateMipmap = this.parameters.generateMipmap; + // wrapT + if (this.parameters.wrapT !== this._state.wrapT) { + if ( + !this.renderer._isWebGL2 && + (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height)) + ) { + this.parameters.wrapT = this.gl.CLAMP_TO_EDGE; + } + + // handle wrong wrapT values + if ( + this.parameters.wrapT !== this.gl.REPEAT && + this.parameters.wrapT !== this.gl.CLAMP_TO_EDGE && + this.parameters.wrapT !== this.gl.MIRRORED_REPEAT + ) { + if (!this.renderer.production) { + throwWarning( + this.type + ": Wrong wrapT value", + this.parameters.wrapT, + "for this texture:", + this, + "\ngl.CLAMP_TO_EDGE wrapping will be used instead" + ); } + this.parameters.wrapT = this.gl.CLAMP_TO_EDGE; + } + + this.gl.texParameteri( + this.gl.TEXTURE_2D, + this.gl.TEXTURE_WRAP_T, + this.parameters.wrapT + ); + this._state.wrapT = this.parameters.wrapT; + } - // min filter - if(this.parameters.minFilter !== this._state.minFilter) { - // WebGL1 and non PO2 - if(!this.renderer._isWebGL2 && (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height))) { - this.parameters.minFilter = this.gl.LINEAR; - } - - // at this point if generateMipmap is null it means we will generate them later on - if(!this.parameters.generateMipmap && this.parameters.generateMipmap !== null) { - this.parameters.minFilter = this.gl.LINEAR; - } - - // handle wrong minFilter values - if( - this.parameters.minFilter !== this.gl.LINEAR - && this.parameters.minFilter !== this.gl.NEAREST - && this.parameters.minFilter !== this.gl.NEAREST_MIPMAP_NEAREST - && this.parameters.minFilter !== this.gl.LINEAR_MIPMAP_NEAREST - && this.parameters.minFilter !== this.gl.NEAREST_MIPMAP_LINEAR - && this.parameters.minFilter !== this.gl.LINEAR_MIPMAP_LINEAR - ) { - if(!this.renderer.production) { - throwWarning(this.type + ": Wrong minFilter value", this.parameters.minFilter, "for this texture:", this, "\ngl.LINEAR filtering will be used instead"); - } - this.parameters.minFilter = this.gl.LINEAR; - } - - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.parameters.minFilter); - this._state.minFilter = this.parameters.minFilter; - } + // generate mip map only if it has a source + if ( + this.parameters.generateMipmap && + !this._state.generateMipmap && + this.source + ) { + if ( + !this.renderer._isWebGL2 && + (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height)) + ) { + this.parameters.generateMipmap = false; + } else { + this.gl.generateMipmap(this.gl.TEXTURE_2D); + } + + this._state.generateMipmap = this.parameters.generateMipmap; + } - // mag filter - if(this.parameters.magFilter !== this._state.magFilter) { - if(!this.renderer._isWebGL2 && (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height))) { - this.parameters.magFilter = this.gl.LINEAR; - } - - // handle wrong magFilter values - if( - this.parameters.magFilter !== this.gl.LINEAR - && this.parameters.magFilter !== this.gl.NEAREST - ) { - if(!this.renderer.production) { - throwWarning(this.type + ": Wrong magFilter value", this.parameters.magFilter, "for this texture:", this, "\ngl.LINEAR filtering will be used instead"); - } - this.parameters.magFilter = this.gl.LINEAR; - } - - this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.parameters.magFilter); - this._state.magFilter = this.parameters.magFilter; + // min filter + if (this.parameters.minFilter !== this._state.minFilter) { + // WebGL1 and non PO2 + if ( + !this.renderer._isWebGL2 && + (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height)) + ) { + this.parameters.minFilter = this.gl.LINEAR; + } + + // at this point if generateMipmap is null it means we will generate them later on + if ( + !this.parameters.generateMipmap && + this.parameters.generateMipmap !== null + ) { + this.parameters.minFilter = this.gl.LINEAR; + } + + // handle wrong minFilter values + if ( + this.parameters.minFilter !== this.gl.LINEAR && + this.parameters.minFilter !== this.gl.NEAREST && + this.parameters.minFilter !== this.gl.NEAREST_MIPMAP_NEAREST && + this.parameters.minFilter !== this.gl.LINEAR_MIPMAP_NEAREST && + this.parameters.minFilter !== this.gl.NEAREST_MIPMAP_LINEAR && + this.parameters.minFilter !== this.gl.LINEAR_MIPMAP_LINEAR + ) { + if (!this.renderer.production) { + throwWarning( + this.type + ": Wrong minFilter value", + this.parameters.minFilter, + "for this texture:", + this, + "\ngl.LINEAR filtering will be used instead" + ); } + this.parameters.minFilter = this.gl.LINEAR; + } + + this.gl.texParameteri( + this.gl.TEXTURE_2D, + this.gl.TEXTURE_MIN_FILTER, + this.parameters.minFilter + ); + this._state.minFilter = this.parameters.minFilter; + } - // anisotropy - const anisotropyExt = this.renderer.extensions['EXT_texture_filter_anisotropic']; - if(anisotropyExt && this.parameters.anisotropy !== this._state.anisotropy) { - const max = this.gl.getParameter(anisotropyExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT); - this.parameters.anisotropy = Math.max(1, Math.min(this.parameters.anisotropy, max)); - - this.gl.texParameterf(this.gl.TEXTURE_2D, anisotropyExt.TEXTURE_MAX_ANISOTROPY_EXT, this.parameters.anisotropy); - this._state.anisotropy = this.parameters.anisotropy; + // mag filter + if (this.parameters.magFilter !== this._state.magFilter) { + if ( + !this.renderer._isWebGL2 && + (!isPowerOf2(this._size.width) || !isPowerOf2(this._size.height)) + ) { + this.parameters.magFilter = this.gl.LINEAR; + } + + // handle wrong magFilter values + if ( + this.parameters.magFilter !== this.gl.LINEAR && + this.parameters.magFilter !== this.gl.NEAREST + ) { + if (!this.renderer.production) { + throwWarning( + this.type + ": Wrong magFilter value", + this.parameters.magFilter, + "for this texture:", + this, + "\ngl.LINEAR filtering will be used instead" + ); } + this.parameters.magFilter = this.gl.LINEAR; + } + + this.gl.texParameteri( + this.gl.TEXTURE_2D, + this.gl.TEXTURE_MAG_FILTER, + this.parameters.magFilter + ); + this._state.magFilter = this.parameters.magFilter; } + // anisotropy + const anisotropyExt = + this.renderer.extensions["EXT_texture_filter_anisotropic"]; + if ( + anisotropyExt && + this.parameters.anisotropy !== this._state.anisotropy + ) { + const max = this.gl.getParameter( + anisotropyExt.MAX_TEXTURE_MAX_ANISOTROPY_EXT + ); + this.parameters.anisotropy = Math.max( + 1, + Math.min(this.parameters.anisotropy, max) + ); + + this.gl.texParameterf( + this.gl.TEXTURE_2D, + anisotropyExt.TEXTURE_MAX_ANISOTROPY_EXT, + this.parameters.anisotropy + ); + this._state.anisotropy = this.parameters.anisotropy; + } + } - /*** + /*** Sets the texture wrapping for the texture coordinate S params: @wrapS (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate S ***/ - setWrapS(wrapS) { - if(this.parameters.wrapS !== wrapS) { - this.parameters.wrapS = wrapS; - this.parameters._shouldUpdate = true; - } + setWrapS(wrapS) { + if (this.parameters.wrapS !== wrapS) { + this.parameters.wrapS = wrapS; + this.parameters._shouldUpdate = true; } + } - - /*** + /*** Sets the texture wrapping for the texture coordinate T params: @wrapT (GLenum): WebGL constant specifying the texture wrapping function for the texture coordinate T ***/ - setWrapT(wrapT) { - if(this.parameters.wrapT !== wrapT) { - this.parameters.wrapT = wrapT; - this.parameters._shouldUpdate = true; - } + setWrapT(wrapT) { + if (this.parameters.wrapT !== wrapT) { + this.parameters.wrapT = wrapT; + this.parameters._shouldUpdate = true; } + } - /*** + /*** Sets the texture minifaction filter value params: @minFilter (GLenum): WebGL constant specifying the texture minification filter ***/ - setMinFilter(minFilter) { - if(this.parameters.minFilter !== minFilter) { - this.parameters.minFilter = minFilter; - this.parameters._shouldUpdate = true; - } + setMinFilter(minFilter) { + if (this.parameters.minFilter !== minFilter) { + this.parameters.minFilter = minFilter; + this.parameters._shouldUpdate = true; } + } - /*** + /*** Sets the texture magnifaction filter value params: @magFilter (GLenum): WebGL constant specifying the texture magnifaction filter ***/ - setMagFilter(magFilter) { - if(this.parameters.magFilter !== magFilter) { - this.parameters.magFilter = magFilter; - this.parameters._shouldUpdate = true; - } + setMagFilter(magFilter) { + if (this.parameters.magFilter !== magFilter) { + this.parameters.magFilter = magFilter; + this.parameters._shouldUpdate = true; } + } - /*** + /*** Sets the texture anisotropy params: @anisotropy (int): Texture anisotropy value ***/ - setAnisotropy(anisotropy) { - anisotropy = isNaN(anisotropy) ? this.parameters.anisotropy : anisotropy; + setAnisotropy(anisotropy) { + anisotropy = isNaN(anisotropy) ? this.parameters.anisotropy : anisotropy; - if(this.parameters.anisotropy !== anisotropy) { - this.parameters.anisotropy = anisotropy; - this.parameters._shouldUpdate = true; - } + if (this.parameters.anisotropy !== anisotropy) { + this.parameters.anisotropy = anisotropy; + this.parameters._shouldUpdate = true; } + } - - /*** + /*** This forces a texture to be updated on the next draw call ***/ - needUpdate() { - this._forceUpdate = true; - } - + needUpdate() { + this._forceUpdate = true; + } - /*** + /*** This uses the requestVideoFrameCallback API to update the texture each time a new frame is displayed ***/ - _videoFrameCallback() { - this._willUpdate = true; - if(!this.source) { - // wait for source to load - const waitForSource = this.renderer.nextRender.add(() => { - if(this.source) { - // source is ready, stop executing the callback - waitForSource.keep = false; - - this.source.requestVideoFrameCallback(() => this._videoFrameCallback()); - } - }, true); - } else { - this.source.requestVideoFrameCallback(() => this._videoFrameCallback()); + _videoFrameCallback() { + this._willUpdate = true; + if (!this.source) { + // wait for source to load + const waitForSource = this.renderer.nextRender.add(() => { + if (this.source) { + // source is ready, stop executing the callback + waitForSource.keep = false; + + this.source.requestVideoFrameCallback(() => + this._videoFrameCallback() + ); } + }, true); + } else { + this.source.requestVideoFrameCallback(() => this._videoFrameCallback()); } + } - - /*** + /*** This updloads our texture to the GPU Called on init or inside our drawing loop if shouldUpdate property is set to true Typically used by videos or canvas ***/ - _upload() { - // set parameters that need to be set before texture uploading - this._updateGlobalTexParameters(); - - if(this.source) { - this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this._globalParameters.internalFormat, this._globalParameters.format, this._globalParameters.type, this.source); - } - else if(this.sourceType === "fbo") { - this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this._globalParameters.internalFormat, this._size.width, this._size.height, 0, this._globalParameters.format, this._globalParameters.type, this.source || null); - } - - // texture has been uploaded - if(!this._uploaded) { - // GPU uploading callback - this.renderer.nextRender.add(() => this._onSourceUploadedCallback && this._onSourceUploadedCallback()); - - this._uploaded = true; - } + _upload() { + // set parameters that need to be set before texture uploading + this._updateGlobalTexParameters(); + + if (this.source) { + this.gl.texImage2D( + this.gl.TEXTURE_2D, + 0, + this._globalParameters.internalFormat, + this._globalParameters.format, + this._globalParameters.type, + this.source + ); + } else if (this.sourceType === "fbo") { + this.gl.texImage2D( + this.gl.TEXTURE_2D, + 0, + this._globalParameters.internalFormat, + this._size.width, + this._size.height, + 0, + this._globalParameters.format, + this._globalParameters.type, + this.source || null + ); } + // texture has been uploaded + if (!this._uploaded) { + // GPU uploading callback + this.renderer.nextRender.add( + () => this._onSourceUploadedCallback && this._onSourceUploadedCallback() + ); - /*** TEXTURE SIZINGS ***/ + this._uploaded = true; + } + } + /*** TEXTURE SIZINGS ***/ - /*** + /*** This is used to calculate how to crop/center an texture returns: @sizes (obj): an object containing plane sizes, source sizes and x and y offset to center the source in the plane ***/ - _getSizes() { - // if this is a fbo texture, its size is the same as its parent - if(this.sourceType === "fbo") { - return { - parentWidth: this._parent._boundingRect.document.width, - parentHeight: this._parent._boundingRect.document.height, - sourceWidth: this._parent._boundingRect.document.width, - sourceHeight: this._parent._boundingRect.document.height, - xOffset: 0, - yOffset: 0, - }; - } + _getSizes() { + // if this is a fbo texture, its size is the same as its parent + if (this.sourceType === "fbo") { + return { + parentWidth: this._parent._boundingRect.document.width, + parentHeight: this._parent._boundingRect.document.height, + sourceWidth: this._parent._boundingRect.document.width, + sourceHeight: this._parent._boundingRect.document.height, + xOffset: 0, + yOffset: 0, + }; + } - // remember our ShaderPass objects don't have a scale property - const scale = this._parent.scale ? tempVec2.set(this._parent.scale.x, this._parent.scale.y) : tempVec2.set(1, 1); + // remember our ShaderPass objects don't have a scale property + const scale = this._parent.scale + ? tempVec2.set(this._parent.scale.x, this._parent.scale.y) + : tempVec2.set(1, 1); - const parentWidth = this._parent._boundingRect.document.width * scale.x; - const parentHeight = this._parent._boundingRect.document.height * scale.y; + const parentWidth = this._parent._boundingRect.document.width * scale.x; + const parentHeight = this._parent._boundingRect.document.height * scale.y; - const sourceWidth = this._size.width; - const sourceHeight = this._size.height; + const sourceWidth = this._size.width; + const sourceHeight = this._size.height; - const sourceRatio = sourceWidth / sourceHeight; - const parentRatio = parentWidth / parentHeight; + const sourceRatio = sourceWidth / sourceHeight; + const parentRatio = parentWidth / parentHeight; - // center image in its container - let xOffset = 0; - let yOffset = 0; + // center image in its container + let xOffset = 0; + let yOffset = 0; - if(parentRatio > sourceRatio) { // means parent is larger - yOffset = Math.min(0, parentHeight - (parentWidth * (1 / sourceRatio))); - } - else if(parentRatio < sourceRatio) { // means parent is taller - xOffset = Math.min(0, parentWidth - (parentHeight * sourceRatio)); - } - - return { - parentWidth: parentWidth, - parentHeight: parentHeight, - sourceWidth: sourceWidth, - sourceHeight: sourceHeight, - xOffset: xOffset, - yOffset: yOffset, - }; + if (parentRatio > sourceRatio) { + // means parent is larger + yOffset = Math.min(0, parentHeight - parentWidth * (1 / sourceRatio)); + } else if (parentRatio < sourceRatio) { + // means parent is taller + xOffset = Math.min(0, parentWidth - parentHeight * sourceRatio); } - - /*** + return { + parentWidth: parentWidth, + parentHeight: parentHeight, + sourceWidth: sourceWidth, + sourceHeight: sourceHeight, + xOffset: xOffset, + yOffset: yOffset, + }; + } + + /*** Set the texture scale and then update its matrix params: @scale (Vec2 object): scale to apply on X and Y axes ***/ - setScale(scale) { - if(!scale.type || scale.type !== "Vec2") { - if(!this.renderer.production) { - throwWarning(this.type + ": Cannot set scale because the parameter passed is not of Vec2 type:", scale); - } + setScale(scale) { + if (!scale.type || scale.type !== "Vec2") { + if (!this.renderer.production) { + throwWarning( + this.type + + ": Cannot set scale because the parameter passed is not of Vec2 type:", + scale + ); + } - return; - } + return; + } - scale.sanitizeNaNValuesWith(this.scale).max(tempVec2.set(0.001, 0.001)); + scale.sanitizeNaNValuesWith(this.scale).max(tempVec2.set(0.001, 0.001)); - if(!scale.equals(this.scale)) { - this.scale.copy(scale); + if (!scale.equals(this.scale)) { + this.scale.copy(scale); - this.resize(); - } + this.resize(); } + } + + setOffset(offset) { + if (!offset.type || offset.type !== "Vec2") { + if (!this.renderer.production) { + throwWarning( + this.type + + ": Cannot set offset because the parameter passed is not of Vec2 type:", + scale + ); + } - setOffset(offset) { - if(!offset.type || offset.type !== "Vec2") { - if(!this.renderer.production) { - throwWarning(this.type + ": Cannot set offset because the parameter passed is not of Vec2 type:", scale); - } - - return; - } + return; + } - offset.sanitizeNaNValuesWith(this.offset); + offset.sanitizeNaNValuesWith(this.offset); - if(!offset.equals(this.offset)) { - this.offset.copy(offset); + if (!offset.equals(this.offset)) { + this.offset.copy(offset); - this.resize(); - } + this.resize(); } + } - - /*** + /*** Gets our texture and parent sizes and tells our texture matrix to update based on those values ***/ - _setSize() { - // if we need to update the texture matrix uniform - if(this._parent && this._parent._program) { - const sizes = this._getSizes(); + _setSize() { + // if we need to update the texture matrix uniform + if (this._parent && this._parent._program) { + const sizes = this._getSizes(); - // always update texture matrix anyway - this._updateTextureMatrix(sizes); - } + // always update texture matrix anyway + this._updateTextureMatrix(sizes); } + } - - /*** + /*** This is used to crop/center a texture If the texture is using texture matrix then we just have to update its matrix If it is a render pass texture we also upload the texture with its new size on the GPU ***/ - resize() { - if(this.sourceType === "fbo") { - // update size based on parent sizes (RenderTarget or ShaderPass) - this._size = { - width: this._parent._size && this._parent._size.width || this._parent._boundingRect.document.width, - height: this._parent._size && this._parent._size.height || this._parent._boundingRect.document.height, - }; - - // reupload only if its not a texture set from another texture (means its a RenderTarget texture) - if(!this._copiedFrom) { - this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); - this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this._globalParameters.internalFormat, this._size.width, this._size.height, 0, this._globalParameters.format, this._globalParameters.type, null); - } - } - else if(this.source) { - // reset texture sizes (useful for canvas because their dimensions might change on resize) - this._size = { - width: this.source.naturalWidth || this.source.width || this.source.videoWidth, - height: this.source.naturalHeight || this.source.height || this.source.videoHeight, - }; - } - - this._setSize(); + resize() { + if (this.sourceType === "fbo") { + // update size based on parent sizes (RenderTarget or ShaderPass) + this._size = { + width: + (this._parent._size && this._parent._size.width) || + this._parent._boundingRect.document.width, + height: + (this._parent._size && this._parent._size.height) || + this._parent._boundingRect.document.height, + }; + + // reupload only if its not a texture set from another texture (means its a RenderTarget texture) + if (!this._copiedFrom) { + this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); + this.gl.texImage2D( + this.gl.TEXTURE_2D, + 0, + this._globalParameters.internalFormat, + this._size.width, + this._size.height, + 0, + this._globalParameters.format, + this._globalParameters.type, + null + ); + } + } else if (this.source) { + // reset texture sizes (useful for canvas because their dimensions might change on resize) + this._size = { + width: + this.source.naturalWidth || + this.source.width || + this.source.videoWidth, + height: + this.source.naturalHeight || + this.source.height || + this.source.videoHeight, + }; } - /*** + this._setSize(); + } + + /*** This updates our textures matrix uniform based on plane and sources sizes params: @sizes (object): object containing plane sizes, source sizes and x and y offset to center the source in the plane ***/ - _updateTextureMatrix(sizes) { - // calculate scale to apply to the matrix - const textureScale = tempVec3.set( - sizes.parentWidth / (sizes.parentWidth - sizes.xOffset), - sizes.parentHeight / (sizes.parentHeight - sizes.yOffset), - 1 - ); - - // apply texture scale - textureScale.x /= this.scale.x; - textureScale.y /= this.scale.y; - - // translate and scale texture to center it - // equivalent (but faster) than applying those steps to an identity matrix: - // translate from [(1 - textureScale.x) / 2 + this.offset.x, (1 - textureScale.y) / 2 + this.offset.y, 0] - // then apply a scale of [textureScale.x, textureScale.y, 1] - this._textureMatrix.matrix = textureTranslation.setFromArray([ - textureScale.x, 0, 0, 0, - 0, textureScale.y, 0, 0, - 0, 0, 1, 0, - (1 - textureScale.x) / 2 + this.offset.x, (1 - textureScale.y) / 2 + this.offset.y, 0, 1 - ]); - - // update the texture matrix uniform - this._updateMatrixUniform(); - } - - - /*** + _updateTextureMatrix(sizes) { + // calculate scale to apply to the matrix + const textureScale = tempVec3.set( + sizes.parentWidth / (sizes.parentWidth - sizes.xOffset), + sizes.parentHeight / (sizes.parentHeight - sizes.yOffset), + 1 + ); + + // apply texture scale + textureScale.x /= this.scale.x; + textureScale.y /= this.scale.y; + + // translate and scale texture to center it + // equivalent (but faster) than applying those steps to an identity matrix: + // translate from [(1 - textureScale.x) / 2 + this.offset.x, (1 - textureScale.y) / 2 + this.offset.y, 0] + // then apply a scale of [textureScale.x, textureScale.y, 1] + this._textureMatrix.matrix = textureTranslation.setFromArray([ + textureScale.x, + 0, + 0, + 0, + 0, + textureScale.y, + 0, + 0, + 0, + 0, + 1, + 0, + (1 - textureScale.x) / 2 + this.offset.x, + (1 - textureScale.y) / 2 + this.offset.y, + 0, + 1, + ]); + + // update the texture matrix uniform + this._updateMatrixUniform(); + } + + /*** This updates our textures matrix GL uniform ***/ - _updateMatrixUniform() { - if(this._textureMatrix.isActive) { - this.renderer.useProgram(this._parent._program); - this.gl.uniformMatrix4fv(this._textureMatrix.location, false, this._textureMatrix.matrix.elements); - } + _updateMatrixUniform() { + if (this._textureMatrix.isActive) { + this.renderer.useProgram(this._parent._program); + this.gl.uniformMatrix4fv( + this._textureMatrix.location, + false, + this._textureMatrix.matrix.elements + ); } + } - - /*** + /*** This calls our loading callback and set our media as texture source ***/ - _onSourceLoaded(source) { - // set the media as our texture source - this.setSource(source); + _onSourceLoaded(source) { + // set the media as our texture source + this.setSource(source); - // add to the cache if needed - if(this.sourceType === "image") { - this.renderer.cache.addTexture(this); - } + // add to the cache if needed + if (this.sourceType === "image") { + this.renderer.cache.addTexture(this); } + } + /*** DRAWING ***/ - /*** DRAWING ***/ - - /*** + /*** This is used to set the WebGL context active texture and bind it params: @texture (texture object): Our texture object containing our WebGL texture and its index ***/ - _bindTexture() { - if(this._canDraw) { - if(this.renderer.state.activeTexture !== this.index) { - // tell WebGL we want to affect the texture at the plane's index unit - this.gl.activeTexture(this.gl.TEXTURE0 + this.index); - this.renderer.state.activeTexture = this.index; - } - - // bind the texture to the plane's index unit - this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); - - // check for texture binding until we got one - if(!this._sampler.isTextureBound) { - this._sampler.isTextureBound = !!this.gl.getParameter(this.gl.TEXTURE_BINDING_2D); - - // force render - this._sampler.isTextureBound && this.renderer.needRender(); - } - } - } + _bindTexture() { + if (this._canDraw) { + if (this.renderer.state.activeTexture !== this.index) { + // tell WebGL we want to affect the texture at the plane's index unit + this.gl.activeTexture(this.gl.TEXTURE0 + this.index); + this.renderer.state.activeTexture = this.index; + } + + // bind the texture to the plane's index unit + this.gl.bindTexture(this.gl.TEXTURE_2D, this._sampler.texture); + + // check for texture binding until we got one + if (!this._sampler.isTextureBound) { + this._sampler.isTextureBound = !!this.gl.getParameter( + this.gl.TEXTURE_BINDING_2D + ); + // force render + this._sampler.isTextureBound && this.renderer.needRender(); + } + } + } - /*** + /*** This is called to draw the texture ***/ - _draw() { - // only draw if the texture is active (used in the shader) - if(this._sampler.isActive) { - // bind the texture - this._bindTexture(); - - // if no videoFrameCallback check if the video is actually really playing - if(this.sourceType === "video" && this.source && !this._videoFrameCallbackID && this.source.readyState >= this.source.HAVE_CURRENT_DATA && !this.source.paused) { - this._willUpdate = true; - } - - if(this._forceUpdate || (this._willUpdate && this.shouldUpdate)) { - // force mipmaps regeneration if needed - this._state.generateMipmap = false; - this._upload(); - } - - // reset the video willUpdate flag - if(this.sourceType === "video") { - this._willUpdate = false; - } - - this._forceUpdate = false; - } + _draw() { + // only draw if the texture is active (used in the shader) + if (this._sampler.isActive) { + // bind the texture + this._bindTexture(); + + // if no videoFrameCallback check if the video is actually really playing + if ( + this.sourceType === "video" && + this.source && + !this._videoFrameCallbackID && + this.source.readyState >= this.source.HAVE_CURRENT_DATA && + !this.source.paused + ) { + this._willUpdate = true; + } - // set parameters that need to be set after texture uploading - if(this.parameters._shouldUpdate) { - this._updateTexParameters(); - this.parameters._shouldUpdate = false; - } + if (this._forceUpdate || (this._willUpdate && this.shouldUpdate)) { + // force mipmaps regeneration if needed + this._state.generateMipmap = false; + this._upload(); + } + + // reset the video willUpdate flag + if (this.sourceType === "video") { + this._willUpdate = false; + } + + this._forceUpdate = false; } + // set parameters that need to be set after texture uploading + if (this.parameters._shouldUpdate) { + this._updateTexParameters(); + this.parameters._shouldUpdate = false; + } + } - /*** EVENTS ***/ + /*** EVENTS ***/ - /*** + /*** This is called each time a source has been loaded for the first time TODO useless? @@ -1209,15 +1429,15 @@ export class Texture { returns : @this: our texture to handle chaining ***/ - onSourceLoaded(callback) { - if(callback) { - this._onSourceLoadedCallback = callback; - } - - return this; + onSourceLoaded(callback) { + if (callback) { + this._onSourceLoadedCallback = callback; } - /*** + return this; + } + + /*** This is called each time a texture has been uploaded to the GPU for the first time params : @@ -1226,57 +1446,61 @@ export class Texture { returns : @this: our texture to handle chaining ***/ - onSourceUploaded(callback) { - if(callback) { - this._onSourceUploadedCallback = callback; - } - - return this; + onSourceUploaded(callback) { + if (callback) { + this._onSourceUploadedCallback = callback; } + return this; + } - /*** DESTROYING ***/ + /*** DESTROYING ***/ - /*** + /*** This is used to destroy a texture and free the memory space Usually used on a plane/shader pass/render target removal params: @force (bool, optional): force the texture to be deleted even if cached ***/ - _dispose(force = false) { - if(this.sourceType === "video" || this.sourceType === "image" && !this.renderer.state.isActive) { - // remove event listeners - if(this._loader) { - this._loader._removeSource(this); - } - - // clear source - this.source = null; - } - else if(this.sourceType === "canvas") { - // clear all canvas states - this.source.width = this.source.width; - - // clear source - this.source = null; - } + _dispose(force = false) { + if ( + this.sourceType === "video" || + (this.sourceType === "image" && !this.renderer.state.isActive) + ) { + // remove event listeners + if (this._loader) { + this._loader._removeSource(this); + } + + // clear source + this.source = null; + } else if (this.sourceType === "canvas" && this.source) { + // clear all canvas states + this.source.width = this.source?.width; + + // clear source + this.source = null; + } - // remove its parent - this._parent = null; + // remove its parent + this._parent = null; - // do not delete original texture if this texture is a copy, or image texture if we're not destroying the context - const shouldDelete = this.gl && !this._copiedFrom && (force || this.sourceType !== "image" || !this.renderer.state.isActive); + // do not delete original texture if this texture is a copy, or image texture if we're not destroying the context + const shouldDelete = + this.gl && + !this._copiedFrom && + (force || this.sourceType !== "image" || !this.renderer.state.isActive); - if(shouldDelete) { - this._canDraw = false; + if (shouldDelete) { + this._canDraw = false; - // if the texture is in our textures cache array, remove it - this.renderer.cache.removeTexture(this); + // if the texture is in our textures cache array, remove it + this.renderer.cache.removeTexture(this); - this.gl.activeTexture(this.gl.TEXTURE0 + this.index); - this.gl.bindTexture(this.gl.TEXTURE_2D, null); - this.gl.deleteTexture(this._sampler.texture); - } + this.gl.activeTexture(this.gl.TEXTURE0 + this.index); + this.gl.bindTexture(this.gl.TEXTURE_2D, null); + this.gl.deleteTexture(this._sampler.texture); } -} \ No newline at end of file + } +} From 0de9aaa9d28ecdac9501a4fd9338b95d0cb70180 Mon Sep 17 00:00:00 2001 From: George Hastings Date: Thu, 27 Jun 2024 08:26:42 -0400 Subject: [PATCH 2/7] update --- dist/curtains.umd.js | 3 ++- dist/curtains.umd.min.js | 2 +- src/core/Curtains.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dist/curtains.umd.js b/dist/curtains.umd.js index 47cfa71..9adfe19 100644 --- a/dist/curtains.umd.js +++ b/dist/curtains.umd.js @@ -2189,10 +2189,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi value: function _initScroll() { var _this9 = this; + console.log("hi"); this._scrollManager = new ScrollManager({ // init values xOffset: window.pageXOffset, - yOffset: window.pageYOffset, + yOffset: 0, lastXDelta: 0, lastYDelta: 0, shouldWatch: this._watchScroll, diff --git a/dist/curtains.umd.min.js b/dist/curtains.umd.min.js index ff62188..6445715 100644 --- a/dist/curtains.umd.min.js +++ b/dist/curtains.umd.min.js @@ -1 +1 @@ -function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:window.pageYOffset,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,V=new w,B=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); +function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;console.log("hi"),this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,V=new w,B=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/src/core/Curtains.js b/src/core/Curtains.js index 30ca12d..2d845c2 100644 --- a/src/core/Curtains.js +++ b/src/core/Curtains.js @@ -398,7 +398,7 @@ export class Curtains { this._scrollManager = new ScrollManager({ // init values xOffset: window.pageXOffset, - yOffset: window.pageYOffset, + yOffset: 0, lastXDelta: 0, lastYDelta: 0, shouldWatch: this._watchScroll, From 5388ba1f0d7d831c13b151f32b40597ab63e553c Mon Sep 17 00:00:00 2001 From: George Hastings Date: Mon, 1 Jul 2024 12:19:46 -0400 Subject: [PATCH 3/7] adds extrudedgeo --- dist/curtains.umd.js | 402 +++++++++++++++---------- dist/curtains.umd.min.js | 2 +- package-lock.json | 29 ++ package.json | 3 + src/core/Geometry.js | 616 +++++++++++++++++++++++---------------- src/index.mjs | 25 +- 6 files changed, 667 insertions(+), 410 deletions(-) diff --git a/dist/curtains.umd.js b/dist/curtains.umd.js index 9adfe19..629749d 100644 --- a/dist/curtains.umd.js +++ b/dist/curtains.umd.js @@ -25,8 +25,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } (function (global, factory) { - (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.window = global.window || {})); -})(this, function (exports) { + (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory(exports, require('geometry-extrude')) : typeof define === 'function' && define.amd ? define(['exports', 'geometry-extrude'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.window = global.window || {}, global.geometryExtrude)); +})(this, function (exports, geometryExtrude) { 'use strict'; /*** Throw a console warning with the passed arguments @@ -2189,7 +2189,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi value: function _initScroll() { var _this9 = this; - console.log("hi"); this._scrollManager = new ScrollManager({ // init values xOffset: window.pageXOffset, @@ -3194,9 +3193,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** CONTEXT RESTORATION ***/ /*** - Used internally to handle context restoration after the program has been successfully compiled again - Reset the default attributes, the vertices and UVs and the program - ***/ + Used internally to handle context restoration after the program has been successfully compiled again + Reset the default attributes, the vertices and UVs and the program + ***/ _createClass(Geometry, [{ @@ -3210,9 +3209,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi /*** SET DEFAULT ATTRIBUTES ***/ /*** - Our geometry default attributes that will handle the buffers - We're just using vertices positions and texture coordinates - ***/ + Our geometry default attributes that will handle the buffers + We're just using vertices positions and texture coordinates + ***/ }, { key: "setDefaultAttributes", @@ -3233,9 +3232,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }; } /*** - Set our vertices and texture coordinates array - Get them from the cache if possible - ***/ + Set our vertices and texture coordinates array + Get them from the cache if possible + ***/ }, { key: "setVerticesUVs", @@ -3253,9 +3252,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - Called on init and on context restoration to set up the attribute buffers - Use VertexArrayObjects whenever possible - ***/ + Called on init and on context restoration to set up the attribute buffers + Use VertexArrayObjects whenever possible + ***/ }, { key: "setProgram", @@ -3266,16 +3265,16 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (this.renderer._isWebGL2) { this._vao = this.gl.createVertexArray(); this.gl.bindVertexArray(this._vao); - } else if (this.renderer.extensions['OES_vertex_array_object']) { - this._vao = this.renderer.extensions['OES_vertex_array_object'].createVertexArrayOES(); - this.renderer.extensions['OES_vertex_array_object'].bindVertexArrayOES(this._vao); + } else if (this.renderer.extensions["OES_vertex_array_object"]) { + this._vao = this.renderer.extensions["OES_vertex_array_object"].createVertexArrayOES(); + this.renderer.extensions["OES_vertex_array_object"].bindVertexArrayOES(this._vao); } this.initializeBuffers(); } /*** - This creates our mesh attributes and buffers by looping over it - ***/ + This creates our mesh attributes and buffers by looping over it + ***/ }, { key: "initAttributes", @@ -3295,10 +3294,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This method is used internally to create our vertices coordinates and texture UVs - we first create our UVs on a grid from [0, 0, 0] to [1, 1, 0] - then we use the UVs to create our vertices coords - ***/ + This method is used internally to create our vertices coordinates and texture UVs + we first create our UVs on a grid from [0, 0, 0] to [1, 1, 0] + then we use the UVs to create our vertices coords + ***/ }, { key: "computeVerticesUVs", @@ -3358,8 +3357,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } } /*** - This method enables and binds our attributes buffers - ***/ + This method enables and binds our attributes buffers + ***/ }, { key: "initializeBuffers", @@ -3380,8 +3379,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.state.currentGeometryID = this.definition.id; } /*** - Used inside our draw call to set the correct plane buffers before drawing it - ***/ + Used inside our draw call to set the correct plane buffers before drawing it + ***/ }, { key: "bindBuffers", @@ -3390,7 +3389,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (this.renderer._isWebGL2) { this.gl.bindVertexArray(this._vao); } else { - this.renderer.extensions['OES_vertex_array_object'].bindVertexArrayOES(this._vao); + this.renderer.extensions["OES_vertex_array_object"].bindVertexArrayOES(this._vao); } } else { // loop through our attributes to bind the buffers and set the attribute pointer @@ -3406,8 +3405,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.state.currentGeometryID = this.definition.id; } /*** - Draw a geometry - ***/ + Draw a geometry + ***/ }, { key: "draw", @@ -3415,8 +3414,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.gl.drawArrays(this.gl.TRIANGLES, 0, this.attributes.vertexPosition.numberOfItems); } /*** - Dispose a geometry (ie delete its vertex array objects and buffers) - ***/ + Dispose a geometry (ie delete its vertex array objects and buffers) + ***/ }, { key: "dispose", @@ -3427,7 +3426,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (this.renderer._isWebGL2) { this.gl.deleteVertexArray(this._vao); } else { - this.renderer.extensions['OES_vertex_array_object'].deleteVertexArrayOES(this._vao); + this.renderer.extensions["OES_vertex_array_object"].deleteVertexArrayOES(this._vao); } } @@ -8833,6 +8832,104 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return Plane; }(DOMMesh); + + var ExtrudedGeometry = /*#__PURE__*/function (_Geometry) { + _inherits(ExtrudedGeometry, _Geometry); + + var _super4 = _createSuper(ExtrudedGeometry); + + function ExtrudedGeometry(renderer) { + var _this34; + + var _ref12 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref12$program = _ref12.program, + program = _ref12$program === void 0 ? null : _ref12$program, + _ref12$width = _ref12.width, + width = _ref12$width === void 0 ? 1 : _ref12$width, + _ref12$height = _ref12.height, + height = _ref12$height === void 0 ? 1 : _ref12$height, + _ref12$svgData = _ref12.svgData, + svgData = _ref12$svgData === void 0 ? [] : _ref12$svgData, + _ref12$depth = _ref12.depth, + depth = _ref12$depth === void 0 ? 2 : _ref12$depth, + _ref12$bevelSize = _ref12.bevelSize, + bevelSize = _ref12$bevelSize === void 0 ? 0 : _ref12$bevelSize, + _ref12$bevelSegments = _ref12.bevelSegments, + bevelSegments = _ref12$bevelSegments === void 0 ? 2 : _ref12$bevelSegments; + + _classCallCheck(this, ExtrudedGeometry); + + _this34 = _super4.call(this, renderer, { + program: program, + width: width, + height: height + }); + _this34.svgData = svgData; + _this34.depth = depth; + _this34.bevelSize = bevelSize; + _this34.bevelSegments = bevelSegments; + + _this34.setExtrudedVerticesUVs(); + + return _this34; + } + + _createClass(ExtrudedGeometry, [{ + key: "setExtrudedVerticesUVs", + value: function setExtrudedVerticesUVs() { + var _geometryExtrude$extr = geometryExtrude.extrudePolygon(this.svgData, { + depth: this.depth, + bevelSize: this.bevelSize, + bevelSegments: this.bevelSegments + }), + indices = _geometryExtrude$extr.indices, + position = _geometryExtrude$extr.position, + uv = _geometryExtrude$extr.uv, + normal = _geometryExtrude$extr.normal; + + this.attributes.vertexPosition.array = position; + this.attributes.textureCoord.array = uv; // Optionally store other data such as indices and normals if needed + + this.indices = indices; + this.normals = normal; + this.initializeBuffers(); + } + }, { + key: "initializeBuffers", + value: function initializeBuffers() { + if (!this.attributes) return; // Bind vertex attributes and buffers + + for (var key in this.attributes) { + if (!this.attributes[key].isActive) return; + this.gl.enableVertexAttribArray(this.attributes[key].location); + this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); + this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.attributes[key].array), this.gl.STATIC_DRAW); + this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); + } // Bind indices if available + + + if (this.indices) { + this.indexBuffer = this.gl.createBuffer(); + this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); + this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), this.gl.STATIC_DRAW); + } // Update current buffers ID + + + this.renderer.state.currentGeometryID = this.definition.id; + } + }, { + key: "draw", + value: function draw() { + if (this.indices) { + this.gl.drawElements(this.gl.TRIANGLES, this.indices.length, this.gl.UNSIGNED_SHORT, 0); + } else { + _get(_getPrototypeOf(ExtrudedGeometry.prototype), "draw", this).call(this); + } + } + }]); + + return ExtrudedGeometry; + }(Geometry); /*** Here we create a RenderTarget class object params : @@ -8850,20 +8947,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var RenderTarget = /*#__PURE__*/function () { function RenderTarget(renderer) { - var _ref12 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - shaderPass = _ref12.shaderPass, - _ref12$depth = _ref12.depth, - depth = _ref12$depth === void 0 ? false : _ref12$depth, - _ref12$clear = _ref12.clear, - clear = _ref12$clear === void 0 ? true : _ref12$clear, - maxWidth = _ref12.maxWidth, - maxHeight = _ref12.maxHeight, - _ref12$minWidth = _ref12.minWidth, - minWidth = _ref12$minWidth === void 0 ? 1024 : _ref12$minWidth, - _ref12$minHeight = _ref12.minHeight, - minHeight = _ref12$minHeight === void 0 ? 1024 : _ref12$minHeight, - _ref12$texturesOption = _ref12.texturesOptions, - texturesOptions = _ref12$texturesOption === void 0 ? {} : _ref12$texturesOption; + var _ref13 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + shaderPass = _ref13.shaderPass, + _ref13$depth = _ref13.depth, + depth = _ref13$depth === void 0 ? false : _ref13$depth, + _ref13$clear = _ref13.clear, + clear = _ref13$clear === void 0 ? true : _ref13$clear, + maxWidth = _ref13.maxWidth, + maxHeight = _ref13.maxHeight, + _ref13$minWidth = _ref13.minWidth, + minWidth = _ref13$minWidth === void 0 ? 1024 : _ref13$minWidth, + _ref13$minHeight = _ref13.minHeight, + minHeight = _ref13$minHeight === void 0 ? 1024 : _ref13$minHeight, + _ref13$texturesOption = _ref13.texturesOptions, + texturesOptions = _ref13$texturesOption === void 0 ? {} : _ref13$texturesOption; _classCallCheck(this, RenderTarget); @@ -9121,29 +9218,29 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var ShaderPass = /*#__PURE__*/function (_DOMMesh2) { _inherits(ShaderPass, _DOMMesh2); - var _super4 = _createSuper(ShaderPass); + var _super5 = _createSuper(ShaderPass); function ShaderPass(renderer) { - var _this34; + var _this35; - var _ref13 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - widthSegments = _ref13.widthSegments, - heightSegments = _ref13.heightSegments, - renderOrder = _ref13.renderOrder, - depthTest = _ref13.depthTest, - cullFace = _ref13.cullFace, - uniforms = _ref13.uniforms, - vertexShaderID = _ref13.vertexShaderID, - fragmentShaderID = _ref13.fragmentShaderID, - vertexShader = _ref13.vertexShader, - fragmentShader = _ref13.fragmentShader, - texturesOptions = _ref13.texturesOptions, - crossOrigin = _ref13.crossOrigin, - _ref13$depth = _ref13.depth, - depth = _ref13$depth === void 0 ? false : _ref13$depth, - _ref13$clear = _ref13.clear, - clear = _ref13$clear === void 0 ? true : _ref13$clear, - renderTarget = _ref13.renderTarget; + var _ref14 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + widthSegments = _ref14.widthSegments, + heightSegments = _ref14.heightSegments, + renderOrder = _ref14.renderOrder, + depthTest = _ref14.depthTest, + cullFace = _ref14.cullFace, + uniforms = _ref14.uniforms, + vertexShaderID = _ref14.vertexShaderID, + fragmentShaderID = _ref14.fragmentShaderID, + vertexShader = _ref14.vertexShader, + fragmentShader = _ref14.fragmentShader, + texturesOptions = _ref14.texturesOptions, + crossOrigin = _ref14.crossOrigin, + _ref14$depth = _ref14.depth, + depth = _ref14$depth === void 0 ? false : _ref14$depth, + _ref14$clear = _ref14.clear, + clear = _ref14$clear === void 0 ? true : _ref14$clear, + renderTarget = _ref14.renderTarget; _classCallCheck(this, ShaderPass); @@ -9153,7 +9250,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi cullFace = "back"; // use the renderer container as our HTML element to create a DOMMesh object - _this34 = _super4.call(this, renderer, renderer.container, "ShaderPass", { + _this35 = _super5.call(this, renderer, renderer.container, "ShaderPass", { widthSegments: widthSegments, heightSegments: heightSegments, renderOrder: renderOrder, @@ -9168,38 +9265,38 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi crossOrigin: crossOrigin }); // return if no gl context - if (!_this34.gl) { - return _possibleConstructorReturn(_this34); + if (!_this35.gl) { + return _possibleConstructorReturn(_this35); } // default to scene pass - _this34._isScenePass = true; - _this34.index = _this34.renderer.shaderPasses.length; - _this34._depth = depth; - _this34._shouldClear = clear; - _this34.target = renderTarget; + _this35._isScenePass = true; + _this35.index = _this35.renderer.shaderPasses.length; + _this35._depth = depth; + _this35._shouldClear = clear; + _this35.target = renderTarget; - if (_this34.target) { + if (_this35.target) { // if there's a target defined it's not a scene pass - _this34._isScenePass = false; // inherit clear param + _this35._isScenePass = false; // inherit clear param - _this34._shouldClear = _this34.target._shouldClear; + _this35._shouldClear = _this35.target._shouldClear; } // if the program is valid, go on - if (_this34._program.compiled) { - _this34._initShaderPass(); // add shader pass to our renderer shaderPasses array + if (_this35._program.compiled) { + _this35._initShaderPass(); // add shader pass to our renderer shaderPasses array - _this34.renderer.shaderPasses.push(_assertThisInitialized(_this34)); // wait one tick before adding our shader pass to the scene to avoid flickering black screen for one frame + _this35.renderer.shaderPasses.push(_assertThisInitialized(_this35)); // wait one tick before adding our shader pass to the scene to avoid flickering black screen for one frame - _this34.renderer.nextRender.add(function () { - _this34.renderer.scene.addShaderPass(_assertThisInitialized(_this34)); + _this35.renderer.nextRender.add(function () { + _this35.renderer.scene.addShaderPass(_assertThisInitialized(_this35)); }); } - return _this34; + return _this35; } /*** RESTORING CONTEXT ***/ @@ -9330,33 +9427,33 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var PingPongPlane = /*#__PURE__*/function (_Plane) { _inherits(PingPongPlane, _Plane); - var _super5 = _createSuper(PingPongPlane); + var _super6 = _createSuper(PingPongPlane); function PingPongPlane(curtains, htmlElement) { - var _this35; + var _this36; - var _ref14 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref14$sampler = _ref14.sampler, - sampler = _ref14$sampler === void 0 ? "uPingPongTexture" : _ref14$sampler, - widthSegments = _ref14.widthSegments, - heightSegments = _ref14.heightSegments, - renderOrder = _ref14.renderOrder, - depthTest = _ref14.depthTest, - cullFace = _ref14.cullFace, - uniforms = _ref14.uniforms, - vertexShaderID = _ref14.vertexShaderID, - fragmentShaderID = _ref14.fragmentShaderID, - vertexShader = _ref14.vertexShader, - fragmentShader = _ref14.fragmentShader, - texturesOptions = _ref14.texturesOptions, - crossOrigin = _ref14.crossOrigin, - alwaysDraw = _ref14.alwaysDraw, - visible = _ref14.visible, - transparent = _ref14.transparent, - drawCheckMargins = _ref14.drawCheckMargins, - autoloadSources = _ref14.autoloadSources, - watchScroll = _ref14.watchScroll, - fov = _ref14.fov; + var _ref15 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref15$sampler = _ref15.sampler, + sampler = _ref15$sampler === void 0 ? "uPingPongTexture" : _ref15$sampler, + widthSegments = _ref15.widthSegments, + heightSegments = _ref15.heightSegments, + renderOrder = _ref15.renderOrder, + depthTest = _ref15.depthTest, + cullFace = _ref15.cullFace, + uniforms = _ref15.uniforms, + vertexShaderID = _ref15.vertexShaderID, + fragmentShaderID = _ref15.fragmentShaderID, + vertexShader = _ref15.vertexShader, + fragmentShader = _ref15.fragmentShader, + texturesOptions = _ref15.texturesOptions, + crossOrigin = _ref15.crossOrigin, + alwaysDraw = _ref15.alwaysDraw, + visible = _ref15.visible, + transparent = _ref15.transparent, + drawCheckMargins = _ref15.drawCheckMargins, + autoloadSources = _ref15.autoloadSources, + watchScroll = _ref15.watchScroll, + fov = _ref15.fov; _classCallCheck(this, PingPongPlane); @@ -9364,7 +9461,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi depthTest = false; autoloadSources = false; // create our plane - _this35 = _super5.call(this, curtains, htmlElement, { + _this36 = _super6.call(this, curtains, htmlElement, { widthSegments: widthSegments, heightSegments: heightSegments, renderOrder: renderOrder, @@ -9386,30 +9483,30 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi fov: fov }); // return if no gl context - if (!_this35.gl) { - return _possibleConstructorReturn(_this35); + if (!_this36.gl) { + return _possibleConstructorReturn(_this36); } // remove from stack, update type to PingPongPlane and then stack again - _this35.renderer.scene.removePlane(_assertThisInitialized(_this35)); + _this36.renderer.scene.removePlane(_assertThisInitialized(_this36)); - _this35.type = "PingPongPlane"; + _this36.type = "PingPongPlane"; - _this35.renderer.scene.addPlane(_assertThisInitialized(_this35)); // create 2 render targets + _this36.renderer.scene.addPlane(_assertThisInitialized(_this36)); // create 2 render targets - _this35.readPass = new RenderTarget(curtains, { + _this36.readPass = new RenderTarget(curtains, { depth: false, clear: false, texturesOptions: texturesOptions }); - _this35.writePass = new RenderTarget(curtains, { + _this36.writePass = new RenderTarget(curtains, { depth: false, clear: false, texturesOptions: texturesOptions }); // create a texture where we'll draw - _this35.createTexture({ + _this36.createTexture({ sampler: sampler }); // wait for both render targets textures to be ready and force a copy of the current target texture // even if the swap already began @@ -9418,41 +9515,41 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var nbPassesReady = 0; - _this35.readPass.getTexture().onSourceUploaded(function () { + _this36.readPass.getTexture().onSourceUploaded(function () { nbPassesReady++; - _this35._checkIfReady(nbPassesReady); + _this36._checkIfReady(nbPassesReady); }); - _this35.writePass.getTexture().onSourceUploaded(function () { + _this36.writePass.getTexture().onSourceUploaded(function () { nbPassesReady++; - _this35._checkIfReady(nbPassesReady); + _this36._checkIfReady(nbPassesReady); }); // directly assign a render target - _this35.setRenderTarget(_this35.readPass); // override onRender and onAfterRender callbacks + _this36.setRenderTarget(_this36.readPass); // override onRender and onAfterRender callbacks - _this35._onRenderCallback = function () { + _this36._onRenderCallback = function () { // update the render target - if (_this35.readPass && _this35.writePass && _this35.textures[0] && _this35.textures[0]._uploaded) { - _this35.setRenderTarget(_this35.writePass); + if (_this36.readPass && _this36.writePass && _this36.textures[0] && _this36.textures[0]._uploaded) { + _this36.setRenderTarget(_this36.writePass); } - _this35._onPingPongRenderCallback && _this35._onPingPongRenderCallback(); + _this36._onPingPongRenderCallback && _this36._onPingPongRenderCallback(); }; - _this35._onAfterRenderCallback = function () { + _this36._onAfterRenderCallback = function () { // swap FBOs and update texture - if (_this35.readPass && _this35.writePass && _this35.textures[0] && _this35.textures[0]._uploaded) { - _this35._swapPasses(); + if (_this36.readPass && _this36.writePass && _this36.textures[0] && _this36.textures[0]._uploaded) { + _this36._swapPasses(); } - _this35._onPingPongAfterRenderCallback && _this35._onPingPongAfterRenderCallback(); + _this36._onPingPongAfterRenderCallback && _this36._onPingPongAfterRenderCallback(); }; - return _this35; + return _this36; } /*** Copy the current target texture once both render targets textures have been uploaded @@ -9463,11 +9560,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi _createClass(PingPongPlane, [{ key: "_checkIfReady", value: function _checkIfReady(loadedTextures) { - var _this36 = this; + var _this37 = this; if (loadedTextures === 2) { this.renderer.nextRender.add(function () { - _this36.textures[0].copy(_this36.target.getTexture()); + _this37.textures[0].copy(_this37.target.getTexture()); }); } } @@ -9574,19 +9671,19 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var FXAAPass = /*#__PURE__*/function (_ShaderPass) { _inherits(FXAAPass, _ShaderPass); - var _super6 = _createSuper(FXAAPass); + var _super7 = _createSuper(FXAAPass); function FXAAPass(curtains) { - var _this37; + var _this38; - var _ref15 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - renderOrder = _ref15.renderOrder, - depthTest = _ref15.depthTest, - texturesOptions = _ref15.texturesOptions, - crossOrigin = _ref15.crossOrigin, - depth = _ref15.depth, - clear = _ref15.clear, - renderTarget = _ref15.renderTarget; + var _ref16 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + renderOrder = _ref16.renderOrder, + depthTest = _ref16.depthTest, + texturesOptions = _ref16.texturesOptions, + crossOrigin = _ref16.crossOrigin, + depth = _ref16.depth, + clear = _ref16.clear, + renderTarget = _ref16.renderTarget; _classCallCheck(this, FXAAPass); @@ -9600,7 +9697,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } }; - _this37 = _super6.call(this, curtains, { + _this38 = _super7.call(this, curtains, { fragmentShader: fragmentShader, uniforms: uniforms, // Mesh params @@ -9613,20 +9710,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi renderTarget: renderTarget }); // return if no gl context - if (!_this37.gl) { - return _possibleConstructorReturn(_this37); + if (!_this38.gl) { + return _possibleConstructorReturn(_this38); } // update the resolution uniform - _this37.uniforms.resolution.value = [_this37.renderer._boundingRect.width, _this37.renderer._boundingRect.height]; // override onAfterResize callback + _this38.uniforms.resolution.value = [_this38.renderer._boundingRect.width, _this38.renderer._boundingRect.height]; // override onAfterResize callback - _this37._onAfterResizeCallback = function () { + _this38._onAfterResizeCallback = function () { // update the resolution uniform - _this37.uniforms.resolution.value = [_this37.renderer._boundingRect.width, _this37.renderer._boundingRect.height]; - _this37._onFXAAPassAfterResizeCallback && _this37._onFXAAPassAfterResizeCallback(); + _this38.uniforms.resolution.value = [_this38.renderer._boundingRect.width, _this38.renderer._boundingRect.height]; + _this38._onFXAAPassAfterResizeCallback && _this38._onFXAAPassAfterResizeCallback(); }; - return _this37; + return _this38; } /*** This is called each time the FXAAPass has been resized @@ -9652,6 +9749,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }(ShaderPass); exports.Curtains = Curtains; + exports.ExtrudedGeometry = ExtrudedGeometry; exports.FXAAPass = FXAAPass; exports.Mat4 = Mat4; exports.PingPongPlane = PingPongPlane; diff --git a/dist/curtains.umd.min.js b/dist/curtains.umd.min.js index 6445715..924fc6a 100644 --- a/dist/curtains.umd.min.js +++ b/dist/curtains.umd.min.js @@ -1 +1 @@ -function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;console.log("hi"),this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,V=new w,B=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); +function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===i)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}i++}}function s(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function a(e){return 0==(e&e-1)}var o=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),u=function(){function e(t){var i=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=i,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||r(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new l}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new h,this.scene=new o(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||r(this.type+": Could not restore the context because the restore context extension is not defined"):r(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),c=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,i?this.setContainer(i):this.production||r(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var i=document.createElement("div");i.setAttribute("id","curtains-canvas"),document.body.appendChild(i),this.container=i,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new u({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new d({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=i.parent,a=i.vertexShader,o=i.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?m:y,this.defaultFsCode="Plane"===this.parent.type?v:x,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||r(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||r(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var i=this.gl.createShader(t);if(this.gl.shaderSource(i,e),this.gl.compileShader(i),!this.renderer.production&&!this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(i).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},r=(i.program,i.width),n=void 0===r?1:r,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),S=new w,C=new T,E=new P,A=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=r.isFBOTexture,o=void 0!==a&&a,h=r.fromTexture,l=void 0!==h&&h,u=r.loader,d=r.sampler,c=r.floatingPoint,p=void 0===c?"none":c,f=r.premultiplyAlpha,g=void 0!==f&&f,_=r.anisotropy,m=void 0===_?1:_,v=r.generateMipmap,y=void 0===v?null:v,x=r.wrapS,b=r.wrapT,k=r.minFilter,R=r.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=n(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:R||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new P,isActive:!1},this._size={width:1,height:1},this.scale=new w(1),this.scale.onChange((function(){return i.resize()})),this.offset=new w,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||r(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||r(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new A(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new A(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new A(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new A(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,i),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(r(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(i,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),i}(M),O=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,b=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=r,(t=t&&t.renderer||t)&&"Renderer"===t.type||(s(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=b,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new R(this.renderer,{width:p,height:g}),this._program=new k(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=n(),this.loader=new F(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new k(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||r(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new A(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||r(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,i)}))}},{key:"loadImage",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this image:\n",e),n&&n(e,i)}))}},{key:"loadVideo",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this video:\n",e),n&&n(e,i)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,i),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||r(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(i,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new T,this.projectionMatrix=new P,this.worldMatrix=new P,this.viewMatrix=new P,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),N=new w,B=new T,V=new T,W=new T,G=new T,X=new T,j=new T,H=new T,Y=new T,q=new I,Q=new T(.5,.5,0),Z=new T,K=new T,J=new T,$=new T,ee=new w,te=function(e){_inherits(i,e);var t=_createSuper(i);function i(e,r){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,A=n.fov,M=void 0===A?50:A;return _classCallCheck(this,i),(s=t.call(this,e,r,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new U({fov:M,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(i,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],Y.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],Y.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],Y.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],Y.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(q.setAxisOrder(this.quaternion.axisOrder),q.equals(this.quaternion)&&Q.equals(this.transformOrigin))return _get(_getPrototypeOf(i.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},r=this.camera.position.clone(),s=Z.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(r).normalize();var n=K.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=$.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=J.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(r))/o;a.copy(r.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return ee.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),i}(L),ie=function(e){_inherits(r,e);var i=_createSuper(r);function r(e){var t,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.program,a=void 0===n?null:n,o=s.width,h=void 0===o?1:o,l=s.height,u=void 0===l?1:l,d=s.svgData,c=void 0===d?[]:d,p=s.depth,f=void 0===p?2:p,g=s.bevelSize,_=void 0===g?0:g,m=s.bevelSegments,v=void 0===m?2:m;return _classCallCheck(this,r),(t=i.call(this,e,{program:a,width:h,height:u})).svgData=c,t.depth=f,t.bevelSize=_,t.bevelSegments=v,t.setExtrudedVerticesUVs(),t}return _createClass(r,[{key:"setExtrudedVerticesUVs",value:function(){var e=t.extrudePolygon(this.svgData,{depth:this.depth,bevelSize:this.bevelSize,bevelSegments:this.bevelSegments}),i=e.indices,r=e.position,s=e.uv,n=e.normal;this.attributes.vertexPosition.array=r,this.attributes.textureCoord.array=s,this.indices=i,this.normals=n,this.initializeBuffers()}},{key:"initializeBuffers",value:function(){if(this.attributes){for(var e in this.attributes){if(!this.attributes[e].isActive)return;this.gl.enableVertexAttribArray(this.attributes[e].location),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.attributes[e].buffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.attributes[e].array),this.gl.STATIC_DRAW),this.gl.vertexAttribPointer(this.attributes[e].location,this.attributes[e].size,this.gl.FLOAT,!1,0,0)}this.indices&&(this.indexBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),this.gl.STATIC_DRAW)),this.renderer.state.currentGeometryID=this.definition.id}}},{key:"draw",value:function(){this.indices?this.gl.drawElements(this.gl.TRIANGLES,this.indices.length,this.gl.UNSIGNED_SHORT,0):_get(_getPrototypeOf(r.prototype),"draw",this).call(this)}}]),r}(R),re=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=r,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=n(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new A(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||r(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new re(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new re(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(te),ae=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(se);e.Curtains=c,e.ExtrudedGeometry=ie,e.FXAAPass=ae,e.Mat4=P,e.PingPongPlane=ne,e.Plane=te,e.Quat=I,e.RenderTarget=re,e.ShaderPass=se,e.Texture=A,e.TextureLoader=M,e.Vec2=w,e.Vec3=T,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/package-lock.json b/package-lock.json index 631c355..a8f4a91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "curtainsjs", "version": "8.1.6", "license": "MIT", + "dependencies": { + "geometry-extrude": "^0.2.1" + }, "devDependencies": { "@babel/core": "^7.15.5", "@babel/preset-env": "^7.15.6", @@ -2121,6 +2124,11 @@ "node": ">= 0.4" } }, + "node_modules/earcut": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/earcut/-/earcut-2.2.4.tgz", + "integrity": "sha512-/pjZsA1b4RPHbeWZQn66SWS8nZZWLQQ23oE3Eam7aroEFGEvwKAsJfZ9ytiEMycfzXWpca4FA9QIOehf7PocBQ==" + }, "node_modules/electron-to-chromium": { "version": "1.3.845", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.845.tgz", @@ -2189,6 +2197,14 @@ "node": ">=6.9.0" } }, + "node_modules/geometry-extrude": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/geometry-extrude/-/geometry-extrude-0.2.1.tgz", + "integrity": "sha512-mvOzSYpQE7oleGZnqAGK57Lstzbr4f65wa3eGpX5osP9ZCuvPBcte7SVhZ39Ubdfwj75kAXLjbyMBK2bV3ngTQ==", + "dependencies": { + "earcut": "^2.1.3" + } + }, "node_modules/get-intrinsic": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", @@ -4158,6 +4174,11 @@ "object-keys": "^1.0.12" } }, + "earcut": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/earcut/-/earcut-2.2.4.tgz", + "integrity": "sha512-/pjZsA1b4RPHbeWZQn66SWS8nZZWLQQ23oE3Eam7aroEFGEvwKAsJfZ9ytiEMycfzXWpca4FA9QIOehf7PocBQ==" + }, "electron-to-chromium": { "version": "1.3.845", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.845.tgz", @@ -4207,6 +4228,14 @@ "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", "dev": true }, + "geometry-extrude": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/geometry-extrude/-/geometry-extrude-0.2.1.tgz", + "integrity": "sha512-mvOzSYpQE7oleGZnqAGK57Lstzbr4f65wa3eGpX5osP9ZCuvPBcte7SVhZ39Ubdfwj75kAXLjbyMBK2bV3ngTQ==", + "requires": { + "earcut": "^2.1.3" + } + }, "get-intrinsic": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", diff --git a/package.json b/package.json index 26c5825..f7f194e 100644 --- a/package.json +++ b/package.json @@ -35,5 +35,8 @@ "scripts": { "build": "rollup -c", "prepare": "npm run build" + }, + "dependencies": { + "geometry-extrude": "^0.2.1" } } diff --git a/src/core/Geometry.js b/src/core/Geometry.js index a74527e..347cba8 100644 --- a/src/core/Geometry.js +++ b/src/core/Geometry.js @@ -1,4 +1,5 @@ -import {throwError} from '../utils/utils.js'; +import { throwError } from "../utils/utils.js"; +import { extrudePolygon } from "geometry-extrude"; /*** Geometry class handles attributes, VertexArrayObjects (if available) and vertices/UVs set up @@ -15,299 +16,424 @@ import {throwError} from '../utils/utils.js'; @this: our newly created Geometry ***/ export class Geometry { - constructor(renderer, { - program = null, - width = 1, - height = 1, - } = {}) { - this.type = "Geometry"; - if(!renderer || renderer.type !== "Renderer") { - throwError(this.type + ": Renderer not passed as first argument", renderer); - } - else if(!renderer.gl) { - throwError(this.type + ": Renderer WebGL context is undefined", renderer); - - // return if no gl context - return; - } - this.renderer = renderer; - this.gl = this.renderer.gl; - - // unique plane buffers id based on width and height - // used to get a geometry from cache - this.definition = { - id: width * height + width, - width: width, - height: height, - }; - - this.setDefaultAttributes(); - this.setVerticesUVs(); + constructor(renderer, { program = null, width = 1, height = 1 } = {}) { + this.type = "Geometry"; + if (!renderer || renderer.type !== "Renderer") { + throwError( + this.type + ": Renderer not passed as first argument", + renderer + ); + } else if (!renderer.gl) { + throwError(this.type + ": Renderer WebGL context is undefined", renderer); + + // return if no gl context + return; } + this.renderer = renderer; + this.gl = this.renderer.gl; + // unique plane buffers id based on width and height + // used to get a geometry from cache + this.definition = { + id: width * height + width, + width: width, + height: height, + }; - /*** CONTEXT RESTORATION ***/ + this.setDefaultAttributes(); + this.setVerticesUVs(); + } - /*** + /*** CONTEXT RESTORATION ***/ + + /*** Used internally to handle context restoration after the program has been successfully compiled again Reset the default attributes, the vertices and UVs and the program ***/ - restoreContext(program) { - this.program = null; - this.setDefaultAttributes(); - this.setVerticesUVs(); - - this.setProgram(program); - } + restoreContext(program) { + this.program = null; + this.setDefaultAttributes(); + this.setVerticesUVs(); + this.setProgram(program); + } - /*** SET DEFAULT ATTRIBUTES ***/ + /*** SET DEFAULT ATTRIBUTES ***/ - /*** + /*** Our geometry default attributes that will handle the buffers We're just using vertices positions and texture coordinates ***/ - setDefaultAttributes() { - // our plane default attributes - // if we'd want to introduce custom attributes we'd merge them with those - this.attributes = { - vertexPosition: { - name: "aVertexPosition", - size: 3, - isActive: false, - }, - textureCoord: { - name: "aTextureCoord", - size: 3, - isActive: false, - } - }; - } - - - /*** + setDefaultAttributes() { + // our plane default attributes + // if we'd want to introduce custom attributes we'd merge them with those + this.attributes = { + vertexPosition: { + name: "aVertexPosition", + size: 3, + isActive: false, + }, + textureCoord: { + name: "aTextureCoord", + size: 3, + isActive: false, + }, + }; + } + + /*** Set our vertices and texture coordinates array Get them from the cache if possible ***/ - setVerticesUVs() { - // we need to create our geometry and material objects - const cachedGeometry = this.renderer.cache.getGeometryFromID(this.definition.id); - - if(cachedGeometry) { - this.attributes.vertexPosition.array = cachedGeometry.vertices; - this.attributes.textureCoord.array = cachedGeometry.uvs; - } - else { - this.computeVerticesUVs(); - // TODO better caching? We could pass all attributes to cache and handle arrays in there - this.renderer.cache.addGeometry(this.definition.id, this.attributes.vertexPosition.array, this.attributes.textureCoord.array); - } + setVerticesUVs() { + // we need to create our geometry and material objects + const cachedGeometry = this.renderer.cache.getGeometryFromID( + this.definition.id + ); + + if (cachedGeometry) { + this.attributes.vertexPosition.array = cachedGeometry.vertices; + this.attributes.textureCoord.array = cachedGeometry.uvs; + } else { + this.computeVerticesUVs(); + // TODO better caching? We could pass all attributes to cache and handle arrays in there + this.renderer.cache.addGeometry( + this.definition.id, + this.attributes.vertexPosition.array, + this.attributes.textureCoord.array + ); } + } - /*** + /*** Called on init and on context restoration to set up the attribute buffers Use VertexArrayObjects whenever possible ***/ - setProgram(program) { - this.program = program; - this.initAttributes(); - - // use vertex array objects if available - if(this.renderer._isWebGL2) { - this._vao = this.gl.createVertexArray(); - this.gl.bindVertexArray(this._vao); - } - else if(this.renderer.extensions['OES_vertex_array_object']) { - this._vao = this.renderer.extensions['OES_vertex_array_object'].createVertexArrayOES(); - this.renderer.extensions['OES_vertex_array_object'].bindVertexArrayOES(this._vao); - } - - this.initializeBuffers(); + setProgram(program) { + this.program = program; + this.initAttributes(); + + // use vertex array objects if available + if (this.renderer._isWebGL2) { + this._vao = this.gl.createVertexArray(); + this.gl.bindVertexArray(this._vao); + } else if (this.renderer.extensions["OES_vertex_array_object"]) { + this._vao = + this.renderer.extensions[ + "OES_vertex_array_object" + ].createVertexArrayOES(); + this.renderer.extensions["OES_vertex_array_object"].bindVertexArrayOES( + this._vao + ); } - /*** + this.initializeBuffers(); + } + + /*** This creates our mesh attributes and buffers by looping over it ***/ - initAttributes() { - // loop through our attributes and create buffers and attributes locations - for(const key in this.attributes) { - // is this attribute active in our program? - this.attributes[key].isActive = this.program.activeAttributes.includes(this.attributes[key].name); - - // if attribute is not active, no need to go further - if(!this.attributes[key].isActive) { - return; - } - - this.attributes[key].location = this.gl.getAttribLocation(this.program.program, this.attributes[key].name); - this.attributes[key].buffer = this.gl.createBuffer(); - this.attributes[key].numberOfItems = this.definition.width * this.definition.height * this.attributes[key].size * 2; - } + initAttributes() { + // loop through our attributes and create buffers and attributes locations + for (const key in this.attributes) { + // is this attribute active in our program? + this.attributes[key].isActive = this.program.activeAttributes.includes( + this.attributes[key].name + ); + + // if attribute is not active, no need to go further + if (!this.attributes[key].isActive) { + return; + } + + this.attributes[key].location = this.gl.getAttribLocation( + this.program.program, + this.attributes[key].name + ); + this.attributes[key].buffer = this.gl.createBuffer(); + this.attributes[key].numberOfItems = + this.definition.width * + this.definition.height * + this.attributes[key].size * + 2; } + } - /*** + /*** This method is used internally to create our vertices coordinates and texture UVs we first create our UVs on a grid from [0, 0, 0] to [1, 1, 0] then we use the UVs to create our vertices coords ***/ - computeVerticesUVs() { - // geometry vertices and UVs - this.attributes.vertexPosition.array = []; - this.attributes.textureCoord.array = []; - - const vertices = this.attributes.vertexPosition.array; - const uvs = this.attributes.textureCoord.array; - - for(let y = 0; y < this.definition.height; y++) { - const v = y / this.definition.height; - - for(let x = 0; x < this.definition.width; x++) { - const u = x / this.definition.width; - - // uvs and vertices - // our uvs are ranging from 0 to 1, our vertices range from -1 to 1 - - // first triangle - uvs.push(u); - uvs.push(v); - uvs.push(0); - - vertices.push((u - 0.5) * 2); - vertices.push((v - 0.5) * 2); - vertices.push(0); - - uvs.push(u + (1 / this.definition.width)); - uvs.push(v); - uvs.push(0); - - vertices.push(((u + (1 / this.definition.width)) - 0.5) * 2); - vertices.push((v - 0.5) * 2); - vertices.push(0); - - uvs.push(u); - uvs.push(v + (1 / this.definition.height)); - uvs.push(0); - - vertices.push((u - 0.5) * 2); - vertices.push(((v + (1 / this.definition.height)) - 0.5) * 2); - vertices.push(0); - - // second triangle - uvs.push(u); - uvs.push(v + (1 / this.definition.height)); - uvs.push(0); - - vertices.push((u - 0.5) * 2); - vertices.push(((v + (1 / this.definition.height)) - 0.5) * 2); - vertices.push(0); - - uvs.push(u + (1 / this.definition.width)); - uvs.push(v); - uvs.push(0); - - vertices.push(((u + (1 / this.definition.width)) - 0.5) * 2); - vertices.push((v - 0.5) * 2); - vertices.push(0); - - uvs.push(u + (1 / this.definition.width)); - uvs.push(v + (1 / this.definition.height)); - uvs.push(0); - - vertices.push(((u + (1 / this.definition.width)) - 0.5) * 2); - vertices.push(((v + (1 / this.definition.height)) - 0.5) * 2); - vertices.push(0); - } - } - } + computeVerticesUVs() { + // geometry vertices and UVs + this.attributes.vertexPosition.array = []; + this.attributes.textureCoord.array = []; + const vertices = this.attributes.vertexPosition.array; + const uvs = this.attributes.textureCoord.array; - /*** - This method enables and binds our attributes buffers - ***/ - initializeBuffers() { - if(!this.attributes) return; + for (let y = 0; y < this.definition.height; y++) { + const v = y / this.definition.height; + + for (let x = 0; x < this.definition.width; x++) { + const u = x / this.definition.width; + + // uvs and vertices + // our uvs are ranging from 0 to 1, our vertices range from -1 to 1 + + // first triangle + uvs.push(u); + uvs.push(v); + uvs.push(0); + + vertices.push((u - 0.5) * 2); + vertices.push((v - 0.5) * 2); + vertices.push(0); + + uvs.push(u + 1 / this.definition.width); + uvs.push(v); + uvs.push(0); + + vertices.push((u + 1 / this.definition.width - 0.5) * 2); + vertices.push((v - 0.5) * 2); + vertices.push(0); + + uvs.push(u); + uvs.push(v + 1 / this.definition.height); + uvs.push(0); - // loop through our attributes - for(const key in this.attributes) { - if(!this.attributes[key].isActive) return; + vertices.push((u - 0.5) * 2); + vertices.push((v + 1 / this.definition.height - 0.5) * 2); + vertices.push(0); - // bind attribute buffer - this.gl.enableVertexAttribArray(this.attributes[key].location); + // second triangle + uvs.push(u); + uvs.push(v + 1 / this.definition.height); + uvs.push(0); - this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); - this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.attributes[key].array), this.gl.STATIC_DRAW); + vertices.push((u - 0.5) * 2); + vertices.push((v + 1 / this.definition.height - 0.5) * 2); + vertices.push(0); - // set where the attribute gets its data - this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); - } + uvs.push(u + 1 / this.definition.width); + uvs.push(v); + uvs.push(0); - // update current buffers ID - this.renderer.state.currentGeometryID = this.definition.id; + vertices.push((u + 1 / this.definition.width - 0.5) * 2); + vertices.push((v - 0.5) * 2); + vertices.push(0); + + uvs.push(u + 1 / this.definition.width); + uvs.push(v + 1 / this.definition.height); + uvs.push(0); + + vertices.push((u + 1 / this.definition.width - 0.5) * 2); + vertices.push((v + 1 / this.definition.height - 0.5) * 2); + vertices.push(0); + } + } + } + + /*** + This method enables and binds our attributes buffers + ***/ + initializeBuffers() { + if (!this.attributes) return; + + // loop through our attributes + for (const key in this.attributes) { + if (!this.attributes[key].isActive) return; + + // bind attribute buffer + this.gl.enableVertexAttribArray(this.attributes[key].location); + + this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); + this.gl.bufferData( + this.gl.ARRAY_BUFFER, + new Float32Array(this.attributes[key].array), + this.gl.STATIC_DRAW + ); + + // set where the attribute gets its data + this.gl.vertexAttribPointer( + this.attributes[key].location, + this.attributes[key].size, + this.gl.FLOAT, + false, + 0, + 0 + ); } + // update current buffers ID + this.renderer.state.currentGeometryID = this.definition.id; + } - /*** + /*** Used inside our draw call to set the correct plane buffers before drawing it ***/ - bindBuffers() { - if(this._vao) { - if(this.renderer._isWebGL2) { - this.gl.bindVertexArray(this._vao); - } - else { - this.renderer.extensions['OES_vertex_array_object'].bindVertexArrayOES(this._vao); - } - } - else { - // loop through our attributes to bind the buffers and set the attribute pointer - for(const key in this.attributes) { - if(!this.attributes[key].isActive) return; - - this.gl.enableVertexAttribArray(this.attributes[key].location); - this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); - this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); - } - } - - // update current buffers ID - this.renderer.state.currentGeometryID = this.definition.id; + bindBuffers() { + if (this._vao) { + if (this.renderer._isWebGL2) { + this.gl.bindVertexArray(this._vao); + } else { + this.renderer.extensions["OES_vertex_array_object"].bindVertexArrayOES( + this._vao + ); + } + } else { + // loop through our attributes to bind the buffers and set the attribute pointer + for (const key in this.attributes) { + if (!this.attributes[key].isActive) return; + + this.gl.enableVertexAttribArray(this.attributes[key].location); + this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); + this.gl.vertexAttribPointer( + this.attributes[key].location, + this.attributes[key].size, + this.gl.FLOAT, + false, + 0, + 0 + ); + } } + // update current buffers ID + this.renderer.state.currentGeometryID = this.definition.id; + } - /*** + /*** Draw a geometry ***/ - draw() { - this.gl.drawArrays(this.gl.TRIANGLES, 0, this.attributes.vertexPosition.numberOfItems); + draw() { + this.gl.drawArrays( + this.gl.TRIANGLES, + 0, + this.attributes.vertexPosition.numberOfItems + ); + } + + /*** + Dispose a geometry (ie delete its vertex array objects and buffers) + ***/ + dispose() { + // delete buffers + // each time we check for existing properties to avoid errors + if (this._vao) { + if (this.renderer._isWebGL2) { + this.gl.deleteVertexArray(this._vao); + } else { + this.renderer.extensions[ + "OES_vertex_array_object" + ].deleteVertexArrayOES(this._vao); + } } + for (const key in this.attributes) { + if (!this.attributes[key].isActive) return; - /*** - Dispose a geometry (ie delete its vertex array objects and buffers) - ***/ - dispose() { - // delete buffers - // each time we check for existing properties to avoid errors - if(this._vao) { - if(this.renderer._isWebGL2) { - this.gl.deleteVertexArray(this._vao); - } - else { - this.renderer.extensions['OES_vertex_array_object'].deleteVertexArrayOES(this._vao); - } - } - - for(const key in this.attributes) { - if(!this.attributes[key].isActive) return; - - this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); - this.gl.bufferData(this.gl.ARRAY_BUFFER, 1, this.gl.STATIC_DRAW); - this.gl.deleteBuffer(this.attributes[key].buffer); - } - - this.attributes = null; - - // update current buffers ID - this.renderer.state.currentGeometryID = null; + this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); + this.gl.bufferData(this.gl.ARRAY_BUFFER, 1, this.gl.STATIC_DRAW); + this.gl.deleteBuffer(this.attributes[key].buffer); + } + + this.attributes = null; + + // update current buffers ID + this.renderer.state.currentGeometryID = null; + } +} + +export class ExtrudedGeometry extends Geometry { + constructor( + renderer, + { + program = null, + width = 1, + height = 1, + svgData = [], + depth = 2, + bevelSize = 0, + bevelSegments = 2, + } = {} + ) { + super(renderer, { program, width, height }); + + this.svgData = svgData; + this.depth = depth; + this.bevelSize = bevelSize; + this.bevelSegments = bevelSegments; + + this.setExtrudedVerticesUVs(); + } + + setExtrudedVerticesUVs() { + const { indices, position, uv, normal } = extrudePolygon(this.svgData, { + depth: this.depth, + bevelSize: this.bevelSize, + bevelSegments: this.bevelSegments, + }); + + this.attributes.vertexPosition.array = position; + this.attributes.textureCoord.array = uv; + + // Optionally store other data such as indices and normals if needed + this.indices = indices; + this.normals = normal; + + this.initializeBuffers(); + } + + initializeBuffers() { + if (!this.attributes) return; + + // Bind vertex attributes and buffers + for (const key in this.attributes) { + if (!this.attributes[key].isActive) return; + + this.gl.enableVertexAttribArray(this.attributes[key].location); + this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); + this.gl.bufferData( + this.gl.ARRAY_BUFFER, + new Float32Array(this.attributes[key].array), + this.gl.STATIC_DRAW + ); + this.gl.vertexAttribPointer( + this.attributes[key].location, + this.attributes[key].size, + this.gl.FLOAT, + false, + 0, + 0 + ); + } + + // Bind indices if available + if (this.indices) { + this.indexBuffer = this.gl.createBuffer(); + this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); + this.gl.bufferData( + this.gl.ELEMENT_ARRAY_BUFFER, + new Uint16Array(this.indices), + this.gl.STATIC_DRAW + ); + } + + // Update current buffers ID + this.renderer.state.currentGeometryID = this.definition.id; + } + + draw() { + if (this.indices) { + this.gl.drawElements( + this.gl.TRIANGLES, + this.indices.length, + this.gl.UNSIGNED_SHORT, + 0 + ); + } else { + super.draw(); } -} \ No newline at end of file + } +} diff --git a/src/index.mjs b/src/index.mjs index e760e5d..0e6a58f 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -1,22 +1,23 @@ // core -export {Curtains} from './core/Curtains.js'; -export {Plane} from './core/Plane.js'; -export {Texture} from './core/Texture.js'; +export { Curtains } from "./core/Curtains.js"; +export { Plane } from "./core/Plane.js"; +export { Texture } from "./core/Texture.js"; +export { Geometry } from "./core/Geometry.js"; // frame buffer objects -export {RenderTarget} from './framebuffers/RenderTarget.js'; -export {ShaderPass} from './framebuffers/ShaderPass.js'; +export { RenderTarget } from "./framebuffers/RenderTarget.js"; +export { ShaderPass } from "./framebuffers/ShaderPass.js"; // loader -export {TextureLoader} from './loaders/TextureLoader.js'; +export { TextureLoader } from "./loaders/TextureLoader.js"; // math -export {Vec2} from './math/Vec2.js'; -export {Vec3} from './math/Vec3.js'; -export {Mat4} from './math/Mat4.js'; -export {Quat} from './math/Quat.js'; +export { Vec2 } from "./math/Vec2.js"; +export { Vec3 } from "./math/Vec3.js"; +export { Mat4 } from "./math/Mat4.js"; +export { Quat } from "./math/Quat.js"; // extras // TODO TextTexture class? -export {PingPongPlane} from './extras/PingPongPlane.js'; -export {FXAAPass} from './extras/FXAAPass.js'; \ No newline at end of file +export { PingPongPlane } from "./extras/PingPongPlane.js"; +export { FXAAPass } from "./extras/FXAAPass.js"; From 4178f7b60c73911240c38a5ef057cf7ca02e8f23 Mon Sep 17 00:00:00 2001 From: George Hastings Date: Tue, 2 Jul 2024 12:19:58 -0400 Subject: [PATCH 4/7] rever --- dist/curtains.umd.js | 385 +++++++++++++++++---------------------- dist/curtains.umd.min.js | 2 +- package.json | 3 - src/core/Geometry.js | 128 +++---------- 4 files changed, 193 insertions(+), 325 deletions(-) diff --git a/dist/curtains.umd.js b/dist/curtains.umd.js index 629749d..dde599b 100644 --- a/dist/curtains.umd.js +++ b/dist/curtains.umd.js @@ -3366,13 +3366,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (!this.attributes) return; // loop through our attributes for (var key in this.attributes) { - if (!this.attributes[key].isActive) return; // bind attribute buffer + if (!this.attributes[key].isActive) continue; // bind attribute buffer this.gl.enableVertexAttribArray(this.attributes[key].location); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.attributes[key].array), this.gl.STATIC_DRAW); // set where the attribute gets its data this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); + } // bind indices if available + + + if (this.indices) { + this.indexBuffer = this.gl.createBuffer(); + this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); + this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), this.gl.STATIC_DRAW); } // update current buffers ID @@ -3394,7 +3401,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } else { // loop through our attributes to bind the buffers and set the attribute pointer for (var key in this.attributes) { - if (!this.attributes[key].isActive) return; + if (!this.attributes[key].isActive) continue; this.gl.enableVertexAttribArray(this.attributes[key].location); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); @@ -3411,7 +3418,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }, { key: "draw", value: function draw() { - this.gl.drawArrays(this.gl.TRIANGLES, 0, this.attributes.vertexPosition.numberOfItems); + if (this.indices) { + this.gl.drawElements(this.gl.TRIANGLES, this.indices.length, this.gl.UNSIGNED_SHORT, 0); + } else { + this.gl.drawArrays(this.gl.TRIANGLES, 0, this.attributes.vertexPosition.numberOfItems); + } } /*** Dispose a geometry (ie delete its vertex array objects and buffers) @@ -3441,6 +3452,38 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.state.currentGeometryID = null; } + /*** + Add extrusion to the geometry + ***/ + + }, { + key: "addExtrusion", + value: function addExtrusion(svgData) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var _options$depth = options.depth, + depth = _options$depth === void 0 ? 2 : _options$depth, + _options$bevelSize = options.bevelSize, + bevelSize = _options$bevelSize === void 0 ? 0 : _options$bevelSize, + _options$bevelSegment = options.bevelSegments, + bevelSegments = _options$bevelSegment === void 0 ? 2 : _options$bevelSegment; + + var _geometryExtrude$extr = geometryExtrude.extrudePolygon(svgData, { + depth: depth, + bevelSize: bevelSize, + bevelSegments: bevelSegments + }), + indices = _geometryExtrude$extr.indices, + position = _geometryExtrude$extr.position, + uv = _geometryExtrude$extr.uv, + normal = _geometryExtrude$extr.normal; + + this.attributes.vertexPosition.array = position; + this.attributes.textureCoord.array = uv; // Store other data such as indices and normals if needed + + this.indices = indices; + this.normals = normal; + this.initializeBuffers(); + } }]); return Geometry; @@ -8832,104 +8875,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return Plane; }(DOMMesh); - - var ExtrudedGeometry = /*#__PURE__*/function (_Geometry) { - _inherits(ExtrudedGeometry, _Geometry); - - var _super4 = _createSuper(ExtrudedGeometry); - - function ExtrudedGeometry(renderer) { - var _this34; - - var _ref12 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref12$program = _ref12.program, - program = _ref12$program === void 0 ? null : _ref12$program, - _ref12$width = _ref12.width, - width = _ref12$width === void 0 ? 1 : _ref12$width, - _ref12$height = _ref12.height, - height = _ref12$height === void 0 ? 1 : _ref12$height, - _ref12$svgData = _ref12.svgData, - svgData = _ref12$svgData === void 0 ? [] : _ref12$svgData, - _ref12$depth = _ref12.depth, - depth = _ref12$depth === void 0 ? 2 : _ref12$depth, - _ref12$bevelSize = _ref12.bevelSize, - bevelSize = _ref12$bevelSize === void 0 ? 0 : _ref12$bevelSize, - _ref12$bevelSegments = _ref12.bevelSegments, - bevelSegments = _ref12$bevelSegments === void 0 ? 2 : _ref12$bevelSegments; - - _classCallCheck(this, ExtrudedGeometry); - - _this34 = _super4.call(this, renderer, { - program: program, - width: width, - height: height - }); - _this34.svgData = svgData; - _this34.depth = depth; - _this34.bevelSize = bevelSize; - _this34.bevelSegments = bevelSegments; - - _this34.setExtrudedVerticesUVs(); - - return _this34; - } - - _createClass(ExtrudedGeometry, [{ - key: "setExtrudedVerticesUVs", - value: function setExtrudedVerticesUVs() { - var _geometryExtrude$extr = geometryExtrude.extrudePolygon(this.svgData, { - depth: this.depth, - bevelSize: this.bevelSize, - bevelSegments: this.bevelSegments - }), - indices = _geometryExtrude$extr.indices, - position = _geometryExtrude$extr.position, - uv = _geometryExtrude$extr.uv, - normal = _geometryExtrude$extr.normal; - - this.attributes.vertexPosition.array = position; - this.attributes.textureCoord.array = uv; // Optionally store other data such as indices and normals if needed - - this.indices = indices; - this.normals = normal; - this.initializeBuffers(); - } - }, { - key: "initializeBuffers", - value: function initializeBuffers() { - if (!this.attributes) return; // Bind vertex attributes and buffers - - for (var key in this.attributes) { - if (!this.attributes[key].isActive) return; - this.gl.enableVertexAttribArray(this.attributes[key].location); - this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); - this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.attributes[key].array), this.gl.STATIC_DRAW); - this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); - } // Bind indices if available - - - if (this.indices) { - this.indexBuffer = this.gl.createBuffer(); - this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), this.gl.STATIC_DRAW); - } // Update current buffers ID - - - this.renderer.state.currentGeometryID = this.definition.id; - } - }, { - key: "draw", - value: function draw() { - if (this.indices) { - this.gl.drawElements(this.gl.TRIANGLES, this.indices.length, this.gl.UNSIGNED_SHORT, 0); - } else { - _get(_getPrototypeOf(ExtrudedGeometry.prototype), "draw", this).call(this); - } - } - }]); - - return ExtrudedGeometry; - }(Geometry); /*** Here we create a RenderTarget class object params : @@ -8947,20 +8892,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var RenderTarget = /*#__PURE__*/function () { function RenderTarget(renderer) { - var _ref13 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - shaderPass = _ref13.shaderPass, - _ref13$depth = _ref13.depth, - depth = _ref13$depth === void 0 ? false : _ref13$depth, - _ref13$clear = _ref13.clear, - clear = _ref13$clear === void 0 ? true : _ref13$clear, - maxWidth = _ref13.maxWidth, - maxHeight = _ref13.maxHeight, - _ref13$minWidth = _ref13.minWidth, - minWidth = _ref13$minWidth === void 0 ? 1024 : _ref13$minWidth, - _ref13$minHeight = _ref13.minHeight, - minHeight = _ref13$minHeight === void 0 ? 1024 : _ref13$minHeight, - _ref13$texturesOption = _ref13.texturesOptions, - texturesOptions = _ref13$texturesOption === void 0 ? {} : _ref13$texturesOption; + var _ref12 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + shaderPass = _ref12.shaderPass, + _ref12$depth = _ref12.depth, + depth = _ref12$depth === void 0 ? false : _ref12$depth, + _ref12$clear = _ref12.clear, + clear = _ref12$clear === void 0 ? true : _ref12$clear, + maxWidth = _ref12.maxWidth, + maxHeight = _ref12.maxHeight, + _ref12$minWidth = _ref12.minWidth, + minWidth = _ref12$minWidth === void 0 ? 1024 : _ref12$minWidth, + _ref12$minHeight = _ref12.minHeight, + minHeight = _ref12$minHeight === void 0 ? 1024 : _ref12$minHeight, + _ref12$texturesOption = _ref12.texturesOptions, + texturesOptions = _ref12$texturesOption === void 0 ? {} : _ref12$texturesOption; _classCallCheck(this, RenderTarget); @@ -9218,29 +9163,29 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var ShaderPass = /*#__PURE__*/function (_DOMMesh2) { _inherits(ShaderPass, _DOMMesh2); - var _super5 = _createSuper(ShaderPass); + var _super4 = _createSuper(ShaderPass); function ShaderPass(renderer) { - var _this35; + var _this34; - var _ref14 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - widthSegments = _ref14.widthSegments, - heightSegments = _ref14.heightSegments, - renderOrder = _ref14.renderOrder, - depthTest = _ref14.depthTest, - cullFace = _ref14.cullFace, - uniforms = _ref14.uniforms, - vertexShaderID = _ref14.vertexShaderID, - fragmentShaderID = _ref14.fragmentShaderID, - vertexShader = _ref14.vertexShader, - fragmentShader = _ref14.fragmentShader, - texturesOptions = _ref14.texturesOptions, - crossOrigin = _ref14.crossOrigin, - _ref14$depth = _ref14.depth, - depth = _ref14$depth === void 0 ? false : _ref14$depth, - _ref14$clear = _ref14.clear, - clear = _ref14$clear === void 0 ? true : _ref14$clear, - renderTarget = _ref14.renderTarget; + var _ref13 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + widthSegments = _ref13.widthSegments, + heightSegments = _ref13.heightSegments, + renderOrder = _ref13.renderOrder, + depthTest = _ref13.depthTest, + cullFace = _ref13.cullFace, + uniforms = _ref13.uniforms, + vertexShaderID = _ref13.vertexShaderID, + fragmentShaderID = _ref13.fragmentShaderID, + vertexShader = _ref13.vertexShader, + fragmentShader = _ref13.fragmentShader, + texturesOptions = _ref13.texturesOptions, + crossOrigin = _ref13.crossOrigin, + _ref13$depth = _ref13.depth, + depth = _ref13$depth === void 0 ? false : _ref13$depth, + _ref13$clear = _ref13.clear, + clear = _ref13$clear === void 0 ? true : _ref13$clear, + renderTarget = _ref13.renderTarget; _classCallCheck(this, ShaderPass); @@ -9250,7 +9195,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi cullFace = "back"; // use the renderer container as our HTML element to create a DOMMesh object - _this35 = _super5.call(this, renderer, renderer.container, "ShaderPass", { + _this34 = _super4.call(this, renderer, renderer.container, "ShaderPass", { widthSegments: widthSegments, heightSegments: heightSegments, renderOrder: renderOrder, @@ -9265,38 +9210,38 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi crossOrigin: crossOrigin }); // return if no gl context - if (!_this35.gl) { - return _possibleConstructorReturn(_this35); + if (!_this34.gl) { + return _possibleConstructorReturn(_this34); } // default to scene pass - _this35._isScenePass = true; - _this35.index = _this35.renderer.shaderPasses.length; - _this35._depth = depth; - _this35._shouldClear = clear; - _this35.target = renderTarget; + _this34._isScenePass = true; + _this34.index = _this34.renderer.shaderPasses.length; + _this34._depth = depth; + _this34._shouldClear = clear; + _this34.target = renderTarget; - if (_this35.target) { + if (_this34.target) { // if there's a target defined it's not a scene pass - _this35._isScenePass = false; // inherit clear param + _this34._isScenePass = false; // inherit clear param - _this35._shouldClear = _this35.target._shouldClear; + _this34._shouldClear = _this34.target._shouldClear; } // if the program is valid, go on - if (_this35._program.compiled) { - _this35._initShaderPass(); // add shader pass to our renderer shaderPasses array + if (_this34._program.compiled) { + _this34._initShaderPass(); // add shader pass to our renderer shaderPasses array - _this35.renderer.shaderPasses.push(_assertThisInitialized(_this35)); // wait one tick before adding our shader pass to the scene to avoid flickering black screen for one frame + _this34.renderer.shaderPasses.push(_assertThisInitialized(_this34)); // wait one tick before adding our shader pass to the scene to avoid flickering black screen for one frame - _this35.renderer.nextRender.add(function () { - _this35.renderer.scene.addShaderPass(_assertThisInitialized(_this35)); + _this34.renderer.nextRender.add(function () { + _this34.renderer.scene.addShaderPass(_assertThisInitialized(_this34)); }); } - return _this35; + return _this34; } /*** RESTORING CONTEXT ***/ @@ -9427,33 +9372,33 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var PingPongPlane = /*#__PURE__*/function (_Plane) { _inherits(PingPongPlane, _Plane); - var _super6 = _createSuper(PingPongPlane); + var _super5 = _createSuper(PingPongPlane); function PingPongPlane(curtains, htmlElement) { - var _this36; + var _this35; - var _ref15 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref15$sampler = _ref15.sampler, - sampler = _ref15$sampler === void 0 ? "uPingPongTexture" : _ref15$sampler, - widthSegments = _ref15.widthSegments, - heightSegments = _ref15.heightSegments, - renderOrder = _ref15.renderOrder, - depthTest = _ref15.depthTest, - cullFace = _ref15.cullFace, - uniforms = _ref15.uniforms, - vertexShaderID = _ref15.vertexShaderID, - fragmentShaderID = _ref15.fragmentShaderID, - vertexShader = _ref15.vertexShader, - fragmentShader = _ref15.fragmentShader, - texturesOptions = _ref15.texturesOptions, - crossOrigin = _ref15.crossOrigin, - alwaysDraw = _ref15.alwaysDraw, - visible = _ref15.visible, - transparent = _ref15.transparent, - drawCheckMargins = _ref15.drawCheckMargins, - autoloadSources = _ref15.autoloadSources, - watchScroll = _ref15.watchScroll, - fov = _ref15.fov; + var _ref14 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref14$sampler = _ref14.sampler, + sampler = _ref14$sampler === void 0 ? "uPingPongTexture" : _ref14$sampler, + widthSegments = _ref14.widthSegments, + heightSegments = _ref14.heightSegments, + renderOrder = _ref14.renderOrder, + depthTest = _ref14.depthTest, + cullFace = _ref14.cullFace, + uniforms = _ref14.uniforms, + vertexShaderID = _ref14.vertexShaderID, + fragmentShaderID = _ref14.fragmentShaderID, + vertexShader = _ref14.vertexShader, + fragmentShader = _ref14.fragmentShader, + texturesOptions = _ref14.texturesOptions, + crossOrigin = _ref14.crossOrigin, + alwaysDraw = _ref14.alwaysDraw, + visible = _ref14.visible, + transparent = _ref14.transparent, + drawCheckMargins = _ref14.drawCheckMargins, + autoloadSources = _ref14.autoloadSources, + watchScroll = _ref14.watchScroll, + fov = _ref14.fov; _classCallCheck(this, PingPongPlane); @@ -9461,7 +9406,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi depthTest = false; autoloadSources = false; // create our plane - _this36 = _super6.call(this, curtains, htmlElement, { + _this35 = _super5.call(this, curtains, htmlElement, { widthSegments: widthSegments, heightSegments: heightSegments, renderOrder: renderOrder, @@ -9483,30 +9428,30 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi fov: fov }); // return if no gl context - if (!_this36.gl) { - return _possibleConstructorReturn(_this36); + if (!_this35.gl) { + return _possibleConstructorReturn(_this35); } // remove from stack, update type to PingPongPlane and then stack again - _this36.renderer.scene.removePlane(_assertThisInitialized(_this36)); + _this35.renderer.scene.removePlane(_assertThisInitialized(_this35)); - _this36.type = "PingPongPlane"; + _this35.type = "PingPongPlane"; - _this36.renderer.scene.addPlane(_assertThisInitialized(_this36)); // create 2 render targets + _this35.renderer.scene.addPlane(_assertThisInitialized(_this35)); // create 2 render targets - _this36.readPass = new RenderTarget(curtains, { + _this35.readPass = new RenderTarget(curtains, { depth: false, clear: false, texturesOptions: texturesOptions }); - _this36.writePass = new RenderTarget(curtains, { + _this35.writePass = new RenderTarget(curtains, { depth: false, clear: false, texturesOptions: texturesOptions }); // create a texture where we'll draw - _this36.createTexture({ + _this35.createTexture({ sampler: sampler }); // wait for both render targets textures to be ready and force a copy of the current target texture // even if the swap already began @@ -9515,41 +9460,41 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var nbPassesReady = 0; - _this36.readPass.getTexture().onSourceUploaded(function () { + _this35.readPass.getTexture().onSourceUploaded(function () { nbPassesReady++; - _this36._checkIfReady(nbPassesReady); + _this35._checkIfReady(nbPassesReady); }); - _this36.writePass.getTexture().onSourceUploaded(function () { + _this35.writePass.getTexture().onSourceUploaded(function () { nbPassesReady++; - _this36._checkIfReady(nbPassesReady); + _this35._checkIfReady(nbPassesReady); }); // directly assign a render target - _this36.setRenderTarget(_this36.readPass); // override onRender and onAfterRender callbacks + _this35.setRenderTarget(_this35.readPass); // override onRender and onAfterRender callbacks - _this36._onRenderCallback = function () { + _this35._onRenderCallback = function () { // update the render target - if (_this36.readPass && _this36.writePass && _this36.textures[0] && _this36.textures[0]._uploaded) { - _this36.setRenderTarget(_this36.writePass); + if (_this35.readPass && _this35.writePass && _this35.textures[0] && _this35.textures[0]._uploaded) { + _this35.setRenderTarget(_this35.writePass); } - _this36._onPingPongRenderCallback && _this36._onPingPongRenderCallback(); + _this35._onPingPongRenderCallback && _this35._onPingPongRenderCallback(); }; - _this36._onAfterRenderCallback = function () { + _this35._onAfterRenderCallback = function () { // swap FBOs and update texture - if (_this36.readPass && _this36.writePass && _this36.textures[0] && _this36.textures[0]._uploaded) { - _this36._swapPasses(); + if (_this35.readPass && _this35.writePass && _this35.textures[0] && _this35.textures[0]._uploaded) { + _this35._swapPasses(); } - _this36._onPingPongAfterRenderCallback && _this36._onPingPongAfterRenderCallback(); + _this35._onPingPongAfterRenderCallback && _this35._onPingPongAfterRenderCallback(); }; - return _this36; + return _this35; } /*** Copy the current target texture once both render targets textures have been uploaded @@ -9560,11 +9505,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi _createClass(PingPongPlane, [{ key: "_checkIfReady", value: function _checkIfReady(loadedTextures) { - var _this37 = this; + var _this36 = this; if (loadedTextures === 2) { this.renderer.nextRender.add(function () { - _this37.textures[0].copy(_this37.target.getTexture()); + _this36.textures[0].copy(_this36.target.getTexture()); }); } } @@ -9671,19 +9616,19 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var FXAAPass = /*#__PURE__*/function (_ShaderPass) { _inherits(FXAAPass, _ShaderPass); - var _super7 = _createSuper(FXAAPass); + var _super6 = _createSuper(FXAAPass); function FXAAPass(curtains) { - var _this38; + var _this37; - var _ref16 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - renderOrder = _ref16.renderOrder, - depthTest = _ref16.depthTest, - texturesOptions = _ref16.texturesOptions, - crossOrigin = _ref16.crossOrigin, - depth = _ref16.depth, - clear = _ref16.clear, - renderTarget = _ref16.renderTarget; + var _ref15 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + renderOrder = _ref15.renderOrder, + depthTest = _ref15.depthTest, + texturesOptions = _ref15.texturesOptions, + crossOrigin = _ref15.crossOrigin, + depth = _ref15.depth, + clear = _ref15.clear, + renderTarget = _ref15.renderTarget; _classCallCheck(this, FXAAPass); @@ -9697,7 +9642,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } }; - _this38 = _super7.call(this, curtains, { + _this37 = _super6.call(this, curtains, { fragmentShader: fragmentShader, uniforms: uniforms, // Mesh params @@ -9710,20 +9655,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi renderTarget: renderTarget }); // return if no gl context - if (!_this38.gl) { - return _possibleConstructorReturn(_this38); + if (!_this37.gl) { + return _possibleConstructorReturn(_this37); } // update the resolution uniform - _this38.uniforms.resolution.value = [_this38.renderer._boundingRect.width, _this38.renderer._boundingRect.height]; // override onAfterResize callback + _this37.uniforms.resolution.value = [_this37.renderer._boundingRect.width, _this37.renderer._boundingRect.height]; // override onAfterResize callback - _this38._onAfterResizeCallback = function () { + _this37._onAfterResizeCallback = function () { // update the resolution uniform - _this38.uniforms.resolution.value = [_this38.renderer._boundingRect.width, _this38.renderer._boundingRect.height]; - _this38._onFXAAPassAfterResizeCallback && _this38._onFXAAPassAfterResizeCallback(); + _this37.uniforms.resolution.value = [_this37.renderer._boundingRect.width, _this37.renderer._boundingRect.height]; + _this37._onFXAAPassAfterResizeCallback && _this37._onFXAAPassAfterResizeCallback(); }; - return _this38; + return _this37; } /*** This is called each time the FXAAPass has been resized @@ -9749,8 +9694,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }(ShaderPass); exports.Curtains = Curtains; - exports.ExtrudedGeometry = ExtrudedGeometry; exports.FXAAPass = FXAAPass; + exports.Geometry = Geometry; exports.Mat4 = Mat4; exports.PingPongPlane = PingPongPlane; exports.Plane = Plane; diff --git a/dist/curtains.umd.min.js b/dist/curtains.umd.min.js index 924fc6a..9e113c5 100644 --- a/dist/curtains.umd.min.js +++ b/dist/curtains.umd.min.js @@ -1 +1 @@ -function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===i)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}i++}}function s(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function a(e){return 0==(e&e-1)}var o=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),u=function(){function e(t){var i=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=i,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||r(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new l}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new h,this.scene=new o(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||r(this.type+": Could not restore the context because the restore context extension is not defined"):r(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),c=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,i?this.setContainer(i):this.production||r(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var i=document.createElement("div");i.setAttribute("id","curtains-canvas"),document.body.appendChild(i),this.container=i,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new u({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new d({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=i.parent,a=i.vertexShader,o=i.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?m:y,this.defaultFsCode="Plane"===this.parent.type?v:x,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||r(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||r(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var i=this.gl.createShader(t);if(this.gl.shaderSource(i,e),this.gl.compileShader(i),!this.renderer.production&&!this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(i).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},r=(i.program,i.width),n=void 0===r?1:r,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),S=new w,C=new T,E=new P,A=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=r.isFBOTexture,o=void 0!==a&&a,h=r.fromTexture,l=void 0!==h&&h,u=r.loader,d=r.sampler,c=r.floatingPoint,p=void 0===c?"none":c,f=r.premultiplyAlpha,g=void 0!==f&&f,_=r.anisotropy,m=void 0===_?1:_,v=r.generateMipmap,y=void 0===v?null:v,x=r.wrapS,b=r.wrapT,k=r.minFilter,R=r.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=n(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:R||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new P,isActive:!1},this._size={width:1,height:1},this.scale=new w(1),this.scale.onChange((function(){return i.resize()})),this.offset=new w,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||r(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||r(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new A(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new A(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new A(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new A(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,i),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(r(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(i,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),i}(M),O=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,b=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=r,(t=t&&t.renderer||t)&&"Renderer"===t.type||(s(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=b,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new R(this.renderer,{width:p,height:g}),this._program=new k(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=n(),this.loader=new F(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new k(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||r(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new A(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||r(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,i)}))}},{key:"loadImage",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this image:\n",e),n&&n(e,i)}))}},{key:"loadVideo",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this video:\n",e),n&&n(e,i)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,i),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||r(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(i,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new T,this.projectionMatrix=new P,this.worldMatrix=new P,this.viewMatrix=new P,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),N=new w,B=new T,V=new T,W=new T,G=new T,X=new T,j=new T,H=new T,Y=new T,q=new I,Q=new T(.5,.5,0),Z=new T,K=new T,J=new T,$=new T,ee=new w,te=function(e){_inherits(i,e);var t=_createSuper(i);function i(e,r){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,A=n.fov,M=void 0===A?50:A;return _classCallCheck(this,i),(s=t.call(this,e,r,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new U({fov:M,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(i,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],Y.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],Y.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],Y.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],Y.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(q.setAxisOrder(this.quaternion.axisOrder),q.equals(this.quaternion)&&Q.equals(this.transformOrigin))return _get(_getPrototypeOf(i.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},r=this.camera.position.clone(),s=Z.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(r).normalize();var n=K.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=$.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=J.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(r))/o;a.copy(r.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return ee.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),i}(L),ie=function(e){_inherits(r,e);var i=_createSuper(r);function r(e){var t,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.program,a=void 0===n?null:n,o=s.width,h=void 0===o?1:o,l=s.height,u=void 0===l?1:l,d=s.svgData,c=void 0===d?[]:d,p=s.depth,f=void 0===p?2:p,g=s.bevelSize,_=void 0===g?0:g,m=s.bevelSegments,v=void 0===m?2:m;return _classCallCheck(this,r),(t=i.call(this,e,{program:a,width:h,height:u})).svgData=c,t.depth=f,t.bevelSize=_,t.bevelSegments=v,t.setExtrudedVerticesUVs(),t}return _createClass(r,[{key:"setExtrudedVerticesUVs",value:function(){var e=t.extrudePolygon(this.svgData,{depth:this.depth,bevelSize:this.bevelSize,bevelSegments:this.bevelSegments}),i=e.indices,r=e.position,s=e.uv,n=e.normal;this.attributes.vertexPosition.array=r,this.attributes.textureCoord.array=s,this.indices=i,this.normals=n,this.initializeBuffers()}},{key:"initializeBuffers",value:function(){if(this.attributes){for(var e in this.attributes){if(!this.attributes[e].isActive)return;this.gl.enableVertexAttribArray(this.attributes[e].location),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.attributes[e].buffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.attributes[e].array),this.gl.STATIC_DRAW),this.gl.vertexAttribPointer(this.attributes[e].location,this.attributes[e].size,this.gl.FLOAT,!1,0,0)}this.indices&&(this.indexBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.indexBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),this.gl.STATIC_DRAW)),this.renderer.state.currentGeometryID=this.definition.id}}},{key:"draw",value:function(){this.indices?this.gl.drawElements(this.gl.TRIANGLES,this.indices.length,this.gl.UNSIGNED_SHORT,0):_get(_getPrototypeOf(r.prototype),"draw",this).call(this)}}]),r}(R),re=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=r,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=n(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new A(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||r(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new re(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new re(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(te),ae=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(se);e.Curtains=c,e.ExtrudedGeometry=ie,e.FXAAPass=ae,e.Mat4=P,e.PingPongPlane=ne,e.Plane=te,e.Quat=I,e.RenderTarget=re,e.ShaderPass=se,e.Texture=A,e.TextureLoader=M,e.Vec2=w,e.Vec3=T,Object.defineProperty(e,"__esModule",{value:!0})})); +function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===i)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}i++}}function s(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function a(e){return 0==(e&e-1)}var o=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),u=function(){function e(t){var i=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=i,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||r(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new l}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new h,this.scene=new o(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||r(this.type+": Could not restore the context because the restore context extension is not defined"):r(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),c=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,i?this.setContainer(i):this.production||r(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var i=document.createElement("div");i.setAttribute("id","curtains-canvas"),document.body.appendChild(i),this.container=i,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new u({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new d({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=i.parent,a=i.vertexShader,o=i.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?m:y,this.defaultFsCode="Plane"===this.parent.type?v:x,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||r(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||r(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var i=this.gl.createShader(t);if(this.gl.shaderSource(i,e),this.gl.compileShader(i),!this.renderer.production&&!this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(i).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},r=(i.program,i.width),n=void 0===r?1:r,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i1&&void 0!==arguments[1]?arguments[1]:{},r=i.depth,s=void 0===r?2:r,n=i.bevelSize,a=void 0===n?0:n,o=i.bevelSegments,h=void 0===o?2:o,l=t.extrudePolygon(e,{depth:s,bevelSize:a,bevelSegments:h}),u=l.indices,d=l.position,c=l.uv,p=l.normal;this.attributes.vertexPosition.array=d,this.attributes.textureCoord.array=c,this.indices=u,this.normals=p,this.initializeBuffers()}}]),e}(),P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),S=new w,C=new T,E=new P,M=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=r.isFBOTexture,o=void 0!==a&&a,h=r.fromTexture,l=void 0!==h&&h,u=r.loader,d=r.sampler,c=r.floatingPoint,p=void 0===c?"none":c,f=r.premultiplyAlpha,g=void 0!==f&&f,_=r.anisotropy,m=void 0===_?1:_,v=r.generateMipmap,y=void 0===v?null:v,x=r.wrapS,b=r.wrapT,k=r.minFilter,R=r.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=n(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:R||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new P,isActive:!1},this._size={width:1,height:1},this.scale=new w(1),this.scale.onChange((function(){return i.resize()})),this.offset=new w,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||r(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||r(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),A=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new M(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new M(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new M(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new M(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,i),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(r(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(i,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),i}(A),O=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,b=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=r,(t=t&&t.renderer||t)&&"Renderer"===t.type||(s(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=b,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new R(this.renderer,{width:p,height:g}),this._program=new k(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=n(),this.loader=new F(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new k(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||r(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new M(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||r(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,i)}))}},{key:"loadImage",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this image:\n",e),n&&n(e,i)}))}},{key:"loadVideo",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this video:\n",e),n&&n(e,i)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,i),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||r(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(i,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new T,this.projectionMatrix=new P,this.worldMatrix=new P,this.viewMatrix=new P,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),N=new w,B=new T,V=new T,W=new T,G=new T,X=new T,j=new T,H=new T,Y=new T,q=new I,Q=new T(.5,.5,0),Z=new T,K=new T,J=new T,$=new T,ee=new w,te=function(e){_inherits(i,e);var t=_createSuper(i);function i(e,r){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,i),(s=t.call(this,e,r,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new U({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(i,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],Y.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],Y.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],Y.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],Y.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(q.setAxisOrder(this.quaternion.axisOrder),q.equals(this.quaternion)&&Q.equals(this.transformOrigin))return _get(_getPrototypeOf(i.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},r=this.camera.position.clone(),s=Z.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(r).normalize();var n=K.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=$.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=J.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(r))/o;a.copy(r.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return ee.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),i}(L),ie=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=r,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=n(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new M(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||r(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),re=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new ie(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new ie(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(te),ne=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(re);e.Curtains=c,e.FXAAPass=ne,e.Geometry=R,e.Mat4=P,e.PingPongPlane=se,e.Plane=te,e.Quat=I,e.RenderTarget=ie,e.ShaderPass=re,e.Texture=M,e.TextureLoader=A,e.Vec2=w,e.Vec3=T,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/package.json b/package.json index f7f194e..26c5825 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,5 @@ "scripts": { "build": "rollup -c", "prepare": "npm run build" - }, - "dependencies": { - "geometry-extrude": "^0.2.1" } } diff --git a/src/core/Geometry.js b/src/core/Geometry.js index 347cba8..f38cd69 100644 --- a/src/core/Geometry.js +++ b/src/core/Geometry.js @@ -1,5 +1,4 @@ import { throwError } from "../utils/utils.js"; -import { extrudePolygon } from "geometry-extrude"; /*** Geometry class handles attributes, VertexArrayObjects (if available) and vertices/UVs set up @@ -242,7 +241,7 @@ export class Geometry { // loop through our attributes for (const key in this.attributes) { - if (!this.attributes[key].isActive) return; + if (!this.attributes[key].isActive) continue; // bind attribute buffer this.gl.enableVertexAttribArray(this.attributes[key].location); @@ -265,6 +264,17 @@ export class Geometry { ); } + // bind indices if available + if (this.indices) { + this.indexBuffer = this.gl.createBuffer(); + this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); + this.gl.bufferData( + this.gl.ELEMENT_ARRAY_BUFFER, + new Uint16Array(this.indices), + this.gl.STATIC_DRAW + ); + } + // update current buffers ID this.renderer.state.currentGeometryID = this.definition.id; } @@ -284,7 +294,7 @@ export class Geometry { } else { // loop through our attributes to bind the buffers and set the attribute pointer for (const key in this.attributes) { - if (!this.attributes[key].isActive) return; + if (!this.attributes[key].isActive) continue; this.gl.enableVertexAttribArray(this.attributes[key].location); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); @@ -307,11 +317,20 @@ export class Geometry { Draw a geometry ***/ draw() { - this.gl.drawArrays( - this.gl.TRIANGLES, - 0, - this.attributes.vertexPosition.numberOfItems - ); + if (this.indices) { + this.gl.drawElements( + this.gl.TRIANGLES, + this.indices.length, + this.gl.UNSIGNED_SHORT, + 0 + ); + } else { + this.gl.drawArrays( + this.gl.TRIANGLES, + 0, + this.attributes.vertexPosition.numberOfItems + ); + } } /*** @@ -344,96 +363,3 @@ export class Geometry { this.renderer.state.currentGeometryID = null; } } - -export class ExtrudedGeometry extends Geometry { - constructor( - renderer, - { - program = null, - width = 1, - height = 1, - svgData = [], - depth = 2, - bevelSize = 0, - bevelSegments = 2, - } = {} - ) { - super(renderer, { program, width, height }); - - this.svgData = svgData; - this.depth = depth; - this.bevelSize = bevelSize; - this.bevelSegments = bevelSegments; - - this.setExtrudedVerticesUVs(); - } - - setExtrudedVerticesUVs() { - const { indices, position, uv, normal } = extrudePolygon(this.svgData, { - depth: this.depth, - bevelSize: this.bevelSize, - bevelSegments: this.bevelSegments, - }); - - this.attributes.vertexPosition.array = position; - this.attributes.textureCoord.array = uv; - - // Optionally store other data such as indices and normals if needed - this.indices = indices; - this.normals = normal; - - this.initializeBuffers(); - } - - initializeBuffers() { - if (!this.attributes) return; - - // Bind vertex attributes and buffers - for (const key in this.attributes) { - if (!this.attributes[key].isActive) return; - - this.gl.enableVertexAttribArray(this.attributes[key].location); - this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); - this.gl.bufferData( - this.gl.ARRAY_BUFFER, - new Float32Array(this.attributes[key].array), - this.gl.STATIC_DRAW - ); - this.gl.vertexAttribPointer( - this.attributes[key].location, - this.attributes[key].size, - this.gl.FLOAT, - false, - 0, - 0 - ); - } - - // Bind indices if available - if (this.indices) { - this.indexBuffer = this.gl.createBuffer(); - this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - this.gl.bufferData( - this.gl.ELEMENT_ARRAY_BUFFER, - new Uint16Array(this.indices), - this.gl.STATIC_DRAW - ); - } - - // Update current buffers ID - this.renderer.state.currentGeometryID = this.definition.id; - } - - draw() { - if (this.indices) { - this.gl.drawElements( - this.gl.TRIANGLES, - this.indices.length, - this.gl.UNSIGNED_SHORT, - 0 - ); - } else { - super.draw(); - } - } -} From 79798c1d46b3e38d900c35bcc5cd8b09003d5b51 Mon Sep 17 00:00:00 2001 From: George Hastings Date: Tue, 2 Jul 2024 12:20:13 -0400 Subject: [PATCH 5/7] revert --- dist/curtains.umd.js | 36 ++---------------------------------- dist/curtains.umd.min.js | 2 +- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/dist/curtains.umd.js b/dist/curtains.umd.js index dde599b..0816093 100644 --- a/dist/curtains.umd.js +++ b/dist/curtains.umd.js @@ -25,8 +25,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } (function (global, factory) { - (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory(exports, require('geometry-extrude')) : typeof define === 'function' && define.amd ? define(['exports', 'geometry-extrude'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.window = global.window || {}, global.geometryExtrude)); -})(this, function (exports, geometryExtrude) { + (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.window = global.window || {})); +})(this, function (exports) { 'use strict'; /*** Throw a console warning with the passed arguments @@ -3452,38 +3452,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi this.renderer.state.currentGeometryID = null; } - /*** - Add extrusion to the geometry - ***/ - - }, { - key: "addExtrusion", - value: function addExtrusion(svgData) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var _options$depth = options.depth, - depth = _options$depth === void 0 ? 2 : _options$depth, - _options$bevelSize = options.bevelSize, - bevelSize = _options$bevelSize === void 0 ? 0 : _options$bevelSize, - _options$bevelSegment = options.bevelSegments, - bevelSegments = _options$bevelSegment === void 0 ? 2 : _options$bevelSegment; - - var _geometryExtrude$extr = geometryExtrude.extrudePolygon(svgData, { - depth: depth, - bevelSize: bevelSize, - bevelSegments: bevelSegments - }), - indices = _geometryExtrude$extr.indices, - position = _geometryExtrude$extr.position, - uv = _geometryExtrude$extr.uv, - normal = _geometryExtrude$extr.normal; - - this.attributes.vertexPosition.array = position; - this.attributes.textureCoord.array = uv; // Store other data such as indices and normals if needed - - this.indices = indices; - this.normals = normal; - this.initializeBuffers(); - } }]); return Geometry; diff --git a/dist/curtains.umd.min.js b/dist/curtains.umd.min.js index 9e113c5..d1b2ddb 100644 --- a/dist/curtains.umd.min.js +++ b/dist/curtains.umd.min.js @@ -1 +1 @@ -function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===i)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}i++}}function s(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function a(e){return 0==(e&e-1)}var o=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),u=function(){function e(t){var i=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=i,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||r(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new l}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new h,this.scene=new o(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||r(this.type+": Could not restore the context because the restore context extension is not defined"):r(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),c=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,i?this.setContainer(i):this.production||r(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var i=document.createElement("div");i.setAttribute("id","curtains-canvas"),document.body.appendChild(i),this.container=i,this.production||r('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new u({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new d({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=i.parent,a=i.vertexShader,o=i.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?m:y,this.defaultFsCode="Plane"===this.parent.type?v:x,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||r(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||r(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var i=this.gl.createShader(t);if(this.gl.shaderSource(i,e),this.gl.compileShader(i),!this.renderer.production&&!this.gl.getShaderParameter(i,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(i).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},r=(i.program,i.width),n=void 0===r?1:r,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i1&&void 0!==arguments[1]?arguments[1]:{},r=i.depth,s=void 0===r?2:r,n=i.bevelSize,a=void 0===n?0:n,o=i.bevelSegments,h=void 0===o?2:o,l=t.extrudePolygon(e,{depth:s,bevelSize:a,bevelSegments:h}),u=l.indices,d=l.position,c=l.uv,p=l.normal;this.attributes.vertexPosition.array=d,this.attributes.textureCoord.array=c,this.indices=u,this.normals=p,this.initializeBuffers()}}]),e}(),P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),S=new w,C=new T,E=new P,M=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=r.isFBOTexture,o=void 0!==a&&a,h=r.fromTexture,l=void 0!==h&&h,u=r.loader,d=r.sampler,c=r.floatingPoint,p=void 0===c?"none":c,f=r.premultiplyAlpha,g=void 0!==f&&f,_=r.anisotropy,m=void 0===_?1:_,v=r.generateMipmap,y=void 0===v?null:v,x=r.wrapS,b=r.wrapT,k=r.minFilter,R=r.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=n(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:R||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new P,isActive:!1},this._size={width:1,height:1},this.scale=new w(1),this.scale.onChange((function(){return i.resize()})),this.offset=new w,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||r(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||r(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),A=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void s(this.type+": Renderer WebGL context is undefined",t)}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new M(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new M(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new M(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new M(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,i),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(r(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(i,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),i}(A),O=function(){function e(t){var i=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,b=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=r,(t=t&&t.renderer||t)&&"Renderer"===t.type||(s(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=b,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new R(this.renderer,{width:p,height:g}),this._program=new k(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=n(),this.loader=new F(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new k(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||r(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new M(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||r(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,i)}))}},{key:"loadImage",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this image:\n",e),n&&n(e,i)}))}},{key:"loadVideo",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(i,this._texturesOptions),(function(e){s&&s(e)}),(function(e,i){t.renderer.production||r(t.type+": There has been an error:\n",i,"\nwhile loading this video:\n",e),n&&n(e,i)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,i),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||r(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(i,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new T,this.projectionMatrix=new P,this.worldMatrix=new P,this.viewMatrix=new P,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),N=new w,B=new T,V=new T,W=new T,G=new T,X=new T,j=new T,H=new T,Y=new T,q=new I,Q=new T(.5,.5,0),Z=new T,K=new T,J=new T,$=new T,ee=new w,te=function(e){_inherits(i,e);var t=_createSuper(i);function i(e,r){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,i),(s=t.call(this,e,r,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new U({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(i,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],Y.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],Y.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],Y.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],H.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],Y.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],Y.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],H.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],Y.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(q.setAxisOrder(this.quaternion.axisOrder),q.equals(this.quaternion)&&Q.equals(this.transformOrigin))return _get(_getPrototypeOf(i.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},r=this.camera.position.clone(),s=Z.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(r).normalize();var n=K.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=$.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=J.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(r))/o;a.copy(r.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return ee.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),i}(L),ie=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||s(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else s(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=r,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=n(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new M(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||r(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),re=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new ie(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new ie(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(te),ne=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(re);e.Curtains=c,e.FXAAPass=ne,e.Geometry=R,e.Mat4=P,e.PingPongPlane=se,e.Plane=te,e.Quat=I,e.RenderTarget=ie,e.ShaderPass=re,e.Texture=M,e.TextureLoader=A,e.Vec2=w,e.Vec3=T,Object.defineProperty(e,"__esModule",{value:!0})})); +function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,B=new w,V=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Geometry=k,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); From 29476d34314154c7ce8dcc4ba7615b9525ee805d Mon Sep 17 00:00:00 2001 From: George Hastings Date: Tue, 2 Jul 2024 14:25:49 -0400 Subject: [PATCH 6/7] fix geo --- src/core/Geometry.js | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/core/Geometry.js b/src/core/Geometry.js index f38cd69..e4da475 100644 --- a/src/core/Geometry.js +++ b/src/core/Geometry.js @@ -241,7 +241,7 @@ export class Geometry { // loop through our attributes for (const key in this.attributes) { - if (!this.attributes[key].isActive) continue; + if (!this.attributes[key].isActive) return; // bind attribute buffer this.gl.enableVertexAttribArray(this.attributes[key].location); @@ -264,17 +264,6 @@ export class Geometry { ); } - // bind indices if available - if (this.indices) { - this.indexBuffer = this.gl.createBuffer(); - this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - this.gl.bufferData( - this.gl.ELEMENT_ARRAY_BUFFER, - new Uint16Array(this.indices), - this.gl.STATIC_DRAW - ); - } - // update current buffers ID this.renderer.state.currentGeometryID = this.definition.id; } @@ -294,7 +283,7 @@ export class Geometry { } else { // loop through our attributes to bind the buffers and set the attribute pointer for (const key in this.attributes) { - if (!this.attributes[key].isActive) continue; + if (!this.attributes[key].isActive) return; this.gl.enableVertexAttribArray(this.attributes[key].location); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); @@ -317,20 +306,11 @@ export class Geometry { Draw a geometry ***/ draw() { - if (this.indices) { - this.gl.drawElements( - this.gl.TRIANGLES, - this.indices.length, - this.gl.UNSIGNED_SHORT, - 0 - ); - } else { - this.gl.drawArrays( - this.gl.TRIANGLES, - 0, - this.attributes.vertexPosition.numberOfItems - ); - } + this.gl.drawArrays( + this.gl.TRIANGLES, + 0, + this.attributes.vertexPosition.numberOfItems + ); } /*** From 84a9f6bea763713588aec894acd38e3b8e777d66 Mon Sep 17 00:00:00 2001 From: George Hastings Date: Tue, 13 Aug 2024 09:18:43 -0400 Subject: [PATCH 7/7] tree shake --- dist/curtains.umd.js | 420 +++++---------------------------------- dist/curtains.umd.min.js | 2 +- src/index.mjs | 4 - 3 files changed, 54 insertions(+), 372 deletions(-) diff --git a/dist/curtains.umd.js b/dist/curtains.umd.js index 0816093..d404a34 100644 --- a/dist/curtains.umd.js +++ b/dist/curtains.umd.js @@ -3366,20 +3366,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi if (!this.attributes) return; // loop through our attributes for (var key in this.attributes) { - if (!this.attributes[key].isActive) continue; // bind attribute buffer + if (!this.attributes[key].isActive) return; // bind attribute buffer this.gl.enableVertexAttribArray(this.attributes[key].location); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(this.attributes[key].array), this.gl.STATIC_DRAW); // set where the attribute gets its data this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); - } // bind indices if available - - - if (this.indices) { - this.indexBuffer = this.gl.createBuffer(); - this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), this.gl.STATIC_DRAW); } // update current buffers ID @@ -3401,7 +3394,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi } else { // loop through our attributes to bind the buffers and set the attribute pointer for (var key in this.attributes) { - if (!this.attributes[key].isActive) continue; + if (!this.attributes[key].isActive) return; this.gl.enableVertexAttribArray(this.attributes[key].location); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.attributes[key].buffer); this.gl.vertexAttribPointer(this.attributes[key].location, this.attributes[key].size, this.gl.FLOAT, false, 0, 0); @@ -3418,11 +3411,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi }, { key: "draw", value: function draw() { - if (this.indices) { - this.gl.drawElements(this.gl.TRIANGLES, this.indices.length, this.gl.UNSIGNED_SHORT, 0); - } else { - this.gl.drawArrays(this.gl.TRIANGLES, 0, this.attributes.vertexPosition.numberOfItems); - } + this.gl.drawArrays(this.gl.TRIANGLES, 0, this.attributes.vertexPosition.numberOfItems); } /*** Dispose a geometry (ie delete its vertex array objects and buffers) @@ -9111,215 +9100,6 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return RenderTarget; }(); - /*** SHADERPASS CLASS ***/ - - /*** - Here we create our ShaderPass object - We will extend our DOMMesh class that handles all the WebGL part and basic HTML sizings - ShaderPass class will add the frame buffer by creating a new RenderTarget class object - params : - @renderer (Curtains renderer or Renderer class object): our curtains object OR our curtains renderer object - @Meshparams (object): see Mesh class object - @depth (boolean, optionnal): whether the shader pass render target should use a depth buffer (see RenderTarget class object). Default to false. - @clear (boolean, optional): whether the shader pass render target content should be cleared before being drawn (see RenderTarget class object). Default to true. - @renderTarget (RenderTarget class object, optional): an already existing render target to use. Default to null. - returns : - @this: our ShaderPass element - ***/ - - - var ShaderPass = /*#__PURE__*/function (_DOMMesh2) { - _inherits(ShaderPass, _DOMMesh2); - - var _super4 = _createSuper(ShaderPass); - - function ShaderPass(renderer) { - var _this34; - - var _ref13 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - widthSegments = _ref13.widthSegments, - heightSegments = _ref13.heightSegments, - renderOrder = _ref13.renderOrder, - depthTest = _ref13.depthTest, - cullFace = _ref13.cullFace, - uniforms = _ref13.uniforms, - vertexShaderID = _ref13.vertexShaderID, - fragmentShaderID = _ref13.fragmentShaderID, - vertexShader = _ref13.vertexShader, - fragmentShader = _ref13.fragmentShader, - texturesOptions = _ref13.texturesOptions, - crossOrigin = _ref13.crossOrigin, - _ref13$depth = _ref13.depth, - depth = _ref13$depth === void 0 ? false : _ref13$depth, - _ref13$clear = _ref13.clear, - clear = _ref13$clear === void 0 ? true : _ref13$clear, - renderTarget = _ref13.renderTarget; - - _classCallCheck(this, ShaderPass); - - // force plane defintion to 1x1 - widthSegments = 1; - heightSegments = 1; // always cull back face - - cullFace = "back"; // use the renderer container as our HTML element to create a DOMMesh object - - _this34 = _super4.call(this, renderer, renderer.container, "ShaderPass", { - widthSegments: widthSegments, - heightSegments: heightSegments, - renderOrder: renderOrder, - depthTest: depthTest, - cullFace: cullFace, - uniforms: uniforms, - vertexShaderID: vertexShaderID, - fragmentShaderID: fragmentShaderID, - vertexShader: vertexShader, - fragmentShader: fragmentShader, - texturesOptions: texturesOptions, - crossOrigin: crossOrigin - }); // return if no gl context - - if (!_this34.gl) { - return _possibleConstructorReturn(_this34); - } // default to scene pass - - - _this34._isScenePass = true; - _this34.index = _this34.renderer.shaderPasses.length; - _this34._depth = depth; - _this34._shouldClear = clear; - _this34.target = renderTarget; - - if (_this34.target) { - // if there's a target defined it's not a scene pass - _this34._isScenePass = false; // inherit clear param - - _this34._shouldClear = _this34.target._shouldClear; - } // if the program is valid, go on - - - if (_this34._program.compiled) { - _this34._initShaderPass(); // add shader pass to our renderer shaderPasses array - - - _this34.renderer.shaderPasses.push(_assertThisInitialized(_this34)); // wait one tick before adding our shader pass to the scene to avoid flickering black screen for one frame - - - _this34.renderer.nextRender.add(function () { - _this34.renderer.scene.addShaderPass(_assertThisInitialized(_this34)); - }); - } - - return _this34; - } - /*** RESTORING CONTEXT ***/ - - /*** - Used internally to handle context restoration after the program has been successfully compiled again - ***/ - - - _createClass(ShaderPass, [{ - key: "_programRestored", - value: function _programRestored() { - // add the shader pass to our draw stack again as it have been emptied - this.renderer.scene.addShaderPass(this); // restore the textures - - for (var i = 0; i < this.textures.length; i++) { - this.textures[i]._parent = this; - - this.textures[i]._restoreContext(); - } - - this._canDraw = true; - } - /*** - Here we init additionnal shader pass planes properties - This mainly consists in creating our render texture and add a frame buffer object - ***/ - - }, { - key: "_initShaderPass", - value: function _initShaderPass() { - // create our frame buffer - if (!this.target) { - this._createFrameBuffer(); - } else { - // set the render target - this.setRenderTarget(this.target); - this.target._shaderPass = this; - } // create a texture from the render target texture - - - var texture = new Texture(this.renderer, { - sampler: "uRenderTexture", - isFBOTexture: true, - fromTexture: this.target.getTexture() - }); - texture.addParent(this); // onReady callback - - this.loader._setLoaderSize(0); - - this._canDraw = true; // be sure we'll update the scene even if drawing is disabled - - this.renderer.needRender(); - } - /*** - Here we create our frame buffer object - We're also adding a render buffer object to handle depth inside our shader pass - ***/ - - }, { - key: "_createFrameBuffer", - value: function _createFrameBuffer() { - var target = new RenderTarget(this.renderer, { - shaderPass: this, - clear: this._shouldClear, - depth: this._depth, - texturesOptions: this._texturesOptions - }); - this.setRenderTarget(target); - } - /*** DRAWING ***/ - - /*** - Specific instructions for the Shader pass class to execute before drawing it - ***/ - - }, { - key: "_startDrawing", - value: function _startDrawing() { - // check if our plane is ready to draw - if (this._canDraw) { - // even if our plane should not be drawn we still execute its onRender callback and update its uniforms - if (this._onRenderCallback) { - this._onRenderCallback(); - } // to improve webgl pipeline performance, we might want to update each texture that needs an update here - // see https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#texImagetexSubImage_uploads_particularly_with_videos_can_cause_pipeline_flushes - - - if (this._isScenePass) { - // if this is a scene pass, check if theres one more coming next and eventually bind it - if (this.renderer.state.scenePassIndex + 1 < this.renderer.scene.stacks.scenePasses.length) { - this.renderer.bindFrameBuffer(this.renderer.scene.stacks.scenePasses[this.renderer.state.scenePassIndex + 1].target); - this.renderer.state.scenePassIndex++; - } else { - this.renderer.bindFrameBuffer(null); - } - } else if (this.renderer.state.scenePassIndex === null) { - // we are rendering a bunch of planes inside a render target, unbind it - this.renderer.bindFrameBuffer(null); - } // force attribute buffer bindings update - - - this.renderer.state.forceBufferUpdate = true; // now check if we really need to draw it and its textures - - this._draw(); - } - } - }]); - - return ShaderPass; - }(DOMMesh); /*** FBO PING PONG PLANE CLASS ***/ /*** @@ -9340,33 +9120,33 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var PingPongPlane = /*#__PURE__*/function (_Plane) { _inherits(PingPongPlane, _Plane); - var _super5 = _createSuper(PingPongPlane); + var _super4 = _createSuper(PingPongPlane); function PingPongPlane(curtains, htmlElement) { - var _this35; - - var _ref14 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - _ref14$sampler = _ref14.sampler, - sampler = _ref14$sampler === void 0 ? "uPingPongTexture" : _ref14$sampler, - widthSegments = _ref14.widthSegments, - heightSegments = _ref14.heightSegments, - renderOrder = _ref14.renderOrder, - depthTest = _ref14.depthTest, - cullFace = _ref14.cullFace, - uniforms = _ref14.uniforms, - vertexShaderID = _ref14.vertexShaderID, - fragmentShaderID = _ref14.fragmentShaderID, - vertexShader = _ref14.vertexShader, - fragmentShader = _ref14.fragmentShader, - texturesOptions = _ref14.texturesOptions, - crossOrigin = _ref14.crossOrigin, - alwaysDraw = _ref14.alwaysDraw, - visible = _ref14.visible, - transparent = _ref14.transparent, - drawCheckMargins = _ref14.drawCheckMargins, - autoloadSources = _ref14.autoloadSources, - watchScroll = _ref14.watchScroll, - fov = _ref14.fov; + var _this34; + + var _ref13 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref13$sampler = _ref13.sampler, + sampler = _ref13$sampler === void 0 ? "uPingPongTexture" : _ref13$sampler, + widthSegments = _ref13.widthSegments, + heightSegments = _ref13.heightSegments, + renderOrder = _ref13.renderOrder, + depthTest = _ref13.depthTest, + cullFace = _ref13.cullFace, + uniforms = _ref13.uniforms, + vertexShaderID = _ref13.vertexShaderID, + fragmentShaderID = _ref13.fragmentShaderID, + vertexShader = _ref13.vertexShader, + fragmentShader = _ref13.fragmentShader, + texturesOptions = _ref13.texturesOptions, + crossOrigin = _ref13.crossOrigin, + alwaysDraw = _ref13.alwaysDraw, + visible = _ref13.visible, + transparent = _ref13.transparent, + drawCheckMargins = _ref13.drawCheckMargins, + autoloadSources = _ref13.autoloadSources, + watchScroll = _ref13.watchScroll, + fov = _ref13.fov; _classCallCheck(this, PingPongPlane); @@ -9374,7 +9154,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi depthTest = false; autoloadSources = false; // create our plane - _this35 = _super5.call(this, curtains, htmlElement, { + _this34 = _super4.call(this, curtains, htmlElement, { widthSegments: widthSegments, heightSegments: heightSegments, renderOrder: renderOrder, @@ -9396,30 +9176,30 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi fov: fov }); // return if no gl context - if (!_this35.gl) { - return _possibleConstructorReturn(_this35); + if (!_this34.gl) { + return _possibleConstructorReturn(_this34); } // remove from stack, update type to PingPongPlane and then stack again - _this35.renderer.scene.removePlane(_assertThisInitialized(_this35)); + _this34.renderer.scene.removePlane(_assertThisInitialized(_this34)); - _this35.type = "PingPongPlane"; + _this34.type = "PingPongPlane"; - _this35.renderer.scene.addPlane(_assertThisInitialized(_this35)); // create 2 render targets + _this34.renderer.scene.addPlane(_assertThisInitialized(_this34)); // create 2 render targets - _this35.readPass = new RenderTarget(curtains, { + _this34.readPass = new RenderTarget(curtains, { depth: false, clear: false, texturesOptions: texturesOptions }); - _this35.writePass = new RenderTarget(curtains, { + _this34.writePass = new RenderTarget(curtains, { depth: false, clear: false, texturesOptions: texturesOptions }); // create a texture where we'll draw - _this35.createTexture({ + _this34.createTexture({ sampler: sampler }); // wait for both render targets textures to be ready and force a copy of the current target texture // even if the swap already began @@ -9428,41 +9208,41 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi var nbPassesReady = 0; - _this35.readPass.getTexture().onSourceUploaded(function () { + _this34.readPass.getTexture().onSourceUploaded(function () { nbPassesReady++; - _this35._checkIfReady(nbPassesReady); + _this34._checkIfReady(nbPassesReady); }); - _this35.writePass.getTexture().onSourceUploaded(function () { + _this34.writePass.getTexture().onSourceUploaded(function () { nbPassesReady++; - _this35._checkIfReady(nbPassesReady); + _this34._checkIfReady(nbPassesReady); }); // directly assign a render target - _this35.setRenderTarget(_this35.readPass); // override onRender and onAfterRender callbacks + _this34.setRenderTarget(_this34.readPass); // override onRender and onAfterRender callbacks - _this35._onRenderCallback = function () { + _this34._onRenderCallback = function () { // update the render target - if (_this35.readPass && _this35.writePass && _this35.textures[0] && _this35.textures[0]._uploaded) { - _this35.setRenderTarget(_this35.writePass); + if (_this34.readPass && _this34.writePass && _this34.textures[0] && _this34.textures[0]._uploaded) { + _this34.setRenderTarget(_this34.writePass); } - _this35._onPingPongRenderCallback && _this35._onPingPongRenderCallback(); + _this34._onPingPongRenderCallback && _this34._onPingPongRenderCallback(); }; - _this35._onAfterRenderCallback = function () { + _this34._onAfterRenderCallback = function () { // swap FBOs and update texture - if (_this35.readPass && _this35.writePass && _this35.textures[0] && _this35.textures[0]._uploaded) { - _this35._swapPasses(); + if (_this34.readPass && _this34.writePass && _this34.textures[0] && _this34.textures[0]._uploaded) { + _this34._swapPasses(); } - _this35._onPingPongAfterRenderCallback && _this35._onPingPongAfterRenderCallback(); + _this34._onPingPongAfterRenderCallback && _this34._onPingPongAfterRenderCallback(); }; - return _this35; + return _this34; } /*** Copy the current target texture once both render targets textures have been uploaded @@ -9473,11 +9253,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi _createClass(PingPongPlane, [{ key: "_checkIfReady", value: function _checkIfReady(loadedTextures) { - var _this36 = this; + var _this35 = this; if (loadedTextures === 2) { this.renderer.nextRender.add(function () { - _this36.textures[0].copy(_this36.target.getTexture()); + _this35.textures[0].copy(_this35.target.getTexture()); }); } } @@ -9570,106 +9350,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi return PingPongPlane; }(Plane); - /*** FXAAPASS CLASS ***/ - - /*** - Here we create our FXAAPass object - This is just a regular ShaderPass with preset shaders and a resolution uniform - params: see ShaderPas class object - returns : - @this: our FXAAPass element - ***/ - - - var FXAAPass = /*#__PURE__*/function (_ShaderPass) { - _inherits(FXAAPass, _ShaderPass); - - var _super6 = _createSuper(FXAAPass); - - function FXAAPass(curtains) { - var _this37; - - var _ref15 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - renderOrder = _ref15.renderOrder, - depthTest = _ref15.depthTest, - texturesOptions = _ref15.texturesOptions, - crossOrigin = _ref15.crossOrigin, - depth = _ref15.depth, - clear = _ref15.clear, - renderTarget = _ref15.renderTarget; - - _classCallCheck(this, FXAAPass); - - // taken from https://github.com/spite/Wagner/blob/master/fragment-shaders/fxaa-fs.glsl - var fragmentShader = "\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n "; - var uniforms = { - resolution: { - name: "uResolution", - type: "2f", - value: [0, 0] // will be updated after having called super() - - } - }; - _this37 = _super6.call(this, curtains, { - fragmentShader: fragmentShader, - uniforms: uniforms, - // Mesh params - renderOrder: renderOrder, - depthTest: depthTest, - texturesOptions: texturesOptions, - crossOrigin: crossOrigin, - depth: depth, - clear: clear, - renderTarget: renderTarget - }); // return if no gl context - - if (!_this37.gl) { - return _possibleConstructorReturn(_this37); - } // update the resolution uniform - - - _this37.uniforms.resolution.value = [_this37.renderer._boundingRect.width, _this37.renderer._boundingRect.height]; // override onAfterResize callback - - _this37._onAfterResizeCallback = function () { - // update the resolution uniform - _this37.uniforms.resolution.value = [_this37.renderer._boundingRect.width, _this37.renderer._boundingRect.height]; - _this37._onFXAAPassAfterResizeCallback && _this37._onFXAAPassAfterResizeCallback(); - }; - - return _this37; - } - /*** - This is called each time the FXAAPass has been resized - params : - @callback (function) : a function to execute - returns : - @this: our FXAAPass to handle chaining - ***/ - - - _createClass(FXAAPass, [{ - key: "onAfterResize", - value: function onAfterResize(callback) { - if (callback) { - this._onFXAAPassAfterResizeCallback = callback; - } - - return this; - } - }]); - - return FXAAPass; - }(ShaderPass); exports.Curtains = Curtains; - exports.FXAAPass = FXAAPass; exports.Geometry = Geometry; - exports.Mat4 = Mat4; exports.PingPongPlane = PingPongPlane; exports.Plane = Plane; - exports.Quat = Quat; exports.RenderTarget = RenderTarget; - exports.ShaderPass = ShaderPass; exports.Texture = Texture; exports.TextureLoader = TextureLoader; exports.Vec2 = Vec2; diff --git a/dist/curtains.umd.min.js b/dist/curtains.umd.min.js index d1b2ddb..03de3e9 100644 --- a/dist/curtains.umd.min.js +++ b/dist/curtains.umd.min.js @@ -1 +1 @@ -function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,P=t.pixelRatio,w=void 0===P?window.devicePixelRatio||1:P,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=w,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),w=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new P,S=new w,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,w=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:w||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new P(1),this.scale.onChange((function(){return i.resize()})),this.offset=new P,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,P=n.texturesOptions,w=void 0===P?{}:P,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},w),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new w,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new P,N=new w,B=new w,V=new w,W=new w,G=new w,X=new w,j=new w,H=new w,Y=new U,q=new w(.5,.5,0),Q=new w,Z=new w,K=new w,J=new w,$=new P,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,P=n.drawCheckMargins,w=void 0===P?{top:0,right:0,bottom:0,left:0}:P,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=w,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new L({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Q.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Z.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(z),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.widthSegments,a=s.heightSegments,o=s.renderOrder,h=s.depthTest,l=s.cullFace,u=s.uniforms,d=s.vertexShaderID,c=s.fragmentShaderID,p=s.vertexShader,f=s.fragmentShader,g=s.texturesOptions,_=s.crossOrigin,m=s.depth,v=void 0!==m&&m,y=s.clear,x=void 0===y||y,b=s.renderTarget;return _classCallCheck(this,i),n=1,a=1,l="back",(r=t.call(this,e,e.container,"ShaderPass",{widthSegments:n,heightSegments:a,renderOrder:o,depthTest:h,cullFace:l,uniforms:u,vertexShaderID:d,fragmentShaderID:c,vertexShader:p,fragmentShader:f,texturesOptions:g,crossOrigin:_})).gl?(r._isScenePass=!0,r.index=r.renderer.shaderPasses.length,r._depth=v,r._shouldClear=x,r.target=b,r.target&&(r._isScenePass=!1,r._shouldClear=r.target._shouldClear),r._program.compiled&&(r._initShaderPass(),r.renderer.shaderPasses.push(_assertThisInitialized(r)),r.renderer.nextRender.add((function(){r.renderer.scene.addShaderPass(_assertThisInitialized(r))}))),r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"_programRestored",value:function(){this.renderer.scene.addShaderPass(this);for(var e=0;e2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,P=n.autoloadSources,w=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,P=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:P,watchScroll:w,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee),se=function(e){_inherits(i,e);var t=_createSuper(i);function i(e){var r,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=s.renderOrder,a=s.depthTest,o=s.texturesOptions,h=s.crossOrigin,l=s.depth,u=s.clear,d=s.renderTarget;_classCallCheck(this,i);var c="\n precision mediump float;\n \n varying vec3 vVertexPosition;\n varying vec2 vTextureCoord;\n \n uniform sampler2D uRenderTexture;\n \n uniform vec2 uResolution;\n \n #define FXAA_REDUCE_MIN (1.0/128.0)\n #define FXAA_REDUCE_MUL (1.0/8.0)\n #define FXAA_SPAN_MAX 8.0\n \n void main() {\n vec2 res = 1.0 / uResolution;\n \n vec3 rgbNW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, -1.0) * res)).xyz;\n vec3 rgbNE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, -1.0) * res)).xyz;\n vec3 rgbSW = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(-1.0, 1.0) * res)).xyz;\n vec3 rgbSE = texture2D(uRenderTexture, (vTextureCoord.xy + vec2(1.0, 1.0) * res)).xyz;\n vec4 rgbaM = texture2D(uRenderTexture, vTextureCoord.xy * res);\n vec3 rgbM = rgbaM.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n \n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE) , max(lumaSW, lumaSE)));\n \n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * res;\n vec4 rgbA = (1.0/2.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (1.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (2.0/3.0 - 0.5)));\n vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (0.0/3.0 - 0.5)) +\n texture2D(uRenderTexture, vTextureCoord.xy + dir * (3.0/3.0 - 0.5)));\n float lumaB = dot(rgbB, vec4(luma, 0.0));\n \n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n } else {\n gl_FragColor = rgbB;\n }\n }\n ",p={resolution:{name:"uResolution",type:"2f",value:[0,0]}};return(r=t.call(this,e,{fragmentShader:c,uniforms:p,renderOrder:n,depthTest:a,texturesOptions:o,crossOrigin:h,depth:l,clear:u,renderTarget:d})).gl?(r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onAfterResizeCallback=function(){r.uniforms.resolution.value=[r.renderer._boundingRect.width,r.renderer._boundingRect.height],r._onFXAAPassAfterResizeCallback&&r._onFXAAPassAfterResizeCallback()},r):_possibleConstructorReturn(r)}return _createClass(i,[{key:"onAfterResize",value:function(e){return e&&(this._onFXAAPassAfterResizeCallback=e),this}}]),i}(ie);e.Curtains=d,e.FXAAPass=se,e.Geometry=k,e.Mat4=R,e.PingPongPlane=re,e.Plane=ee,e.Quat=U,e.RenderTarget=te,e.ShaderPass=ie,e.Texture=E,e.TextureLoader=M,e.Vec2=P,e.Vec3=w,Object.defineProperty(e,"__esModule",{value:!0})})); +function _get(e,t,i){return(_get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=_superPropBase(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(i):s.value}})(e,t,i||e)}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf(e)););return e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,r=_getPrototypeOf(e);if(t){var s=_getPrototypeOf(this).constructor;i=Reflect.construct(r,arguments,s)}else i=r.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _possibleConstructorReturn(e,t){if(t&&("object"===_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i100)){if(100===t)console.warn("Curtains: too many warnings thrown, stop logging.");else{var e=Array.prototype.slice.call(arguments);console.warn.apply(console,e)}t++}}function r(){var e=Array.prototype.slice.call(arguments);console.error.apply(console,e)}function s(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16).toUpperCase()}))}function n(e){return 0==(e&e-1)}var a=function(){function e(t){if(_classCallCheck(this,e),this.type="Scene",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=t.gl,this.initStacks()}return _createClass(e,[{key:"initStacks",value:function(){this.stacks={pingPong:[],renderTargets:[],opaque:[],transparent:[],renderPasses:[],scenePasses:[]}}},{key:"resetPlaneStacks",value:function(){this.stacks.pingPong=[],this.stacks.renderTargets=[],this.stacks.opaque=[],this.stacks.transparent=[];for(var e=0;e=0;r--)if(t[r].target.uuid===e.target.uuid){i=r+1;break}}else i=t.findIndex((function(t){return t.target.uuid===e.target.uuid}));i=Math.max(0,i),t.splice(i,0,e),e.target._depth?(t.sort((function(e,t){return e.index-t.index})),t.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(t.sort((function(e,t){return t.index-e.index})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))),t.sort((function(e,t){return e.target.index-t.target.index})),this.stacks.renderTargets=t}},{key:"addToRegularPlaneStack",value:function(e){for(var t=this.renderer.planes.filter((function(t){return"PingPongPlane"!==t.type&&!t.target&&t._transparent===e._transparent&&t.uuid!==e.uuid})),i=-1,r=t.length-1;r>=0;r--)if(t[r]._geometry.definition.id===e._geometry.definition.id){i=r+1;break}return i=Math.max(0,i),t.splice(i,0,e),t.sort((function(e,t){return e.index-t.index})),t}},{key:"addPlane",value:function(e){if("PingPongPlane"===e.type)this.stacks.pingPong.push(e);else if(e.target)this.addToRenderTargetsStack(e);else if(e._transparent){var t=this.addToRegularPlaneStack(e);t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.transparent=t}else{var i=this.addToRegularPlaneStack(e);i.sort((function(e,t){return t.renderOrder-e.renderOrder})),this.stacks.opaque=i}}},{key:"removePlane",value:function(e){"PingPongPlane"===e.type?this.stacks.pingPong=this.stacks.pingPong.filter((function(t){return t.uuid!==e.uuid})):e.target?this.stacks.renderTargets=this.stacks.renderTargets.filter((function(t){return t.uuid!==e.uuid})):e._transparent?this.stacks.transparent=this.stacks.transparent.filter((function(t){return t.uuid!==e.uuid})):this.stacks.opaque=this.stacks.opaque.filter((function(t){return t.uuid!==e.uuid}))}},{key:"setPlaneRenderOrder",value:function(e){if("ShaderPass"===e.type)this.sortShaderPassStack(e._isScenePass?this.stacks.scenePasses:this.stacks.renderPasses);else if("PingPongPlane"===e.type)return;if(e.target)e.target._depth?(this.stacks.renderTargets.sort((function(e,t){return e.index-t.index})),this.stacks.renderTargets.sort((function(e,t){return t.renderOrder-e.renderOrder}))):(this.stacks.renderTargets.sort((function(e,t){return t.index-e.index})),this.stacks.renderTargets.sort((function(e,t){return e.renderOrder-t.renderOrder}))),this.stacks.renderTargets.sort((function(e,t){return e.target.index-t.target.index}));else{var t=e._transparent?this.stacks.transparent:this.stacks.opaque,i=this.stacks.scenePasses.find((function(e,t){return e._isScenePass&&!e._depth&&0===t}));!this.renderer.depth||i?(t.sort((function(e,t){return t.index-e.index})),e._transparent&&t.sort((function(e,t){return e.relativeTranslation.z-t.relativeTranslation.z})),t.sort((function(e,t){return e.renderOrder-t.renderOrder}))):(t.sort((function(e,t){return e.index-t.index})),e._transparent&&t.sort((function(e,t){return t.relativeTranslation.z-e.relativeTranslation.z})),t.sort((function(e,t){return t.renderOrder-e.renderOrder})))}}},{key:"addShaderPass",value:function(e){e._isScenePass?(this.stacks.scenePasses.push(e),this.sortShaderPassStack(this.stacks.scenePasses)):(this.stacks.renderPasses.push(e),this.sortShaderPassStack(this.stacks.renderPasses))}},{key:"removeShaderPass",value:function(e){this.resetShaderPassStacks()}},{key:"sortShaderPassStack",value:function(e){e.sort((function(e,t){return e.index-t.index})),e.sort((function(e,t){return e.renderOrder-t.renderOrder}))}},{key:"enableShaderPass",value:function(){this.stacks.scenePasses.length&&0===this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target))}},{key:"drawRenderPasses",value:function(){this.stacks.scenePasses.length&&this.stacks.renderPasses.length&&this.renderer.planes.length&&(this.renderer.state.scenePassIndex=0,this.renderer.bindFrameBuffer(this.stacks.scenePasses[0].target));for(var e=0;e1&&void 0!==arguments[1]&&arguments[1],r={callback:e,keep:i,timeout:null};return r.timeout=setTimeout((function(){t.queue.push(r)}),0),r}},{key:"execute",value:function(){var e=this;this.queue.map((function(t){t.callback&&t.callback(),clearTimeout(e.queue.timeout)})),this.queue=this.queue.filter((function(e){return e.keep}))}}]),e}(),l=function(){function e(t){var r=t.alpha,s=t.antialias,n=t.premultipliedAlpha,a=t.depth,o=t.failIfMajorPerformanceCaveat,h=t.preserveDrawingBuffer,l=t.stencil,u=t.container,d=t.pixelRatio,c=t.renderingScale,p=t.production,f=t.onError,g=t.onSuccess,_=t.onContextLost,m=t.onContextRestored,v=t.onDisposed,y=t.onSceneChange;_classCallCheck(this,e),this.type="Renderer",this.alpha=r,this.antialias=s,this.premultipliedAlpha=n,this.depth=a,this.failIfMajorPerformanceCaveat=o,this.preserveDrawingBuffer=h,this.stencil=l,this.container=u,this.pixelRatio=d,this._renderingScale=c,this.production=p,this.onError=f,this.onSuccess=g,this.onContextLost=_,this.onContextRestored=m,this.onDisposed=v,this.onSceneChange=y,this.initState(),this.canvas=document.createElement("canvas");var x={alpha:this.alpha,premultipliedAlpha:this.premultipliedAlpha,antialias:this.antialias,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil};if(this.gl=this.canvas.getContext("webgl2",x),this._isWebGL2=!!this.gl,this.gl||(this.gl=this.canvas.getContext("webgl",x)||this.canvas.getContext("experimental-webgl",x)),!this.gl)return this.production||i(this.type+": WebGL context could not be created"),this.state.isActive=!1,void(this.onError&&this.onError());this.onSuccess&&this.onSuccess(),this.initRenderer()}return _createClass(e,[{key:"initState",value:function(){this.state={isActive:!0,isContextLost:!0,drawingEnabled:!0,forceRender:!1,currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,scenePassIndex:null,activeTexture:null,unpackAlignment:null,flipY:null,premultiplyAlpha:null}}},{key:"initCallbackQueueManager",value:function(){this.nextRender=new h}},{key:"initRenderer",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this.state.isContextLost=!1,this.state.maxTextureSize=this.gl.getParameter(this.gl.MAX_TEXTURE_SIZE),this.initCallbackQueueManager(),this.setBlendFunc(),this.setDepthFunc(),this.setDepthTest(!0),this.cache=new o,this.scene=new a(this),this.getExtensions(),this._contextLostHandler=this.contextLost.bind(this),this.canvas.addEventListener("webglcontextlost",this._contextLostHandler,!1),this._contextRestoredHandler=this.contextRestored.bind(this),this.canvas.addEventListener("webglcontextrestored",this._contextRestoredHandler,!1)}},{key:"getExtensions",value:function(){this.extensions=[],this._isWebGL2?(this.extensions.EXT_color_buffer_float=this.gl.getExtension("EXT_color_buffer_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context")):(this.extensions.OES_vertex_array_object=this.gl.getExtension("OES_vertex_array_object"),this.extensions.OES_texture_float=this.gl.getExtension("OES_texture_float"),this.extensions.OES_texture_float_linear=this.gl.getExtension("OES_texture_float_linear"),this.extensions.OES_texture_half_float=this.gl.getExtension("OES_texture_half_float"),this.extensions.OES_texture_half_float_linear=this.gl.getExtension("OES_texture_half_float_linear"),this.extensions.EXT_texture_filter_anisotropic=this.gl.getExtension("EXT_texture_filter_anisotropic"),this.extensions.OES_element_index_uint=this.gl.getExtension("OES_element_index_uint"),this.extensions.OES_standard_derivatives=this.gl.getExtension("OES_standard_derivatives"),this.extensions.EXT_sRGB=this.gl.getExtension("EXT_sRGB"),this.extensions.WEBGL_depth_texture=this.gl.getExtension("WEBGL_depth_texture"),this.extensions.WEBGL_draw_buffers=this.gl.getExtension("WEBGL_draw_buffers"),this.extensions.WEBGL_lose_context=this.gl.getExtension("WEBGL_lose_context"))}},{key:"contextLost",value:function(e){var t=this;this.state.isContextLost=!0,this.state.isActive&&(e.preventDefault(),this.nextRender.add((function(){return t.onContextLost&&t.onContextLost()})))}},{key:"restoreContext",value:function(){this.state.isActive&&(this.initState(),this.gl&&this.extensions.WEBGL_lose_context?this.extensions.WEBGL_lose_context.restoreContext():(this.gl||this.production?this.extensions.WEBGL_lose_context||this.production||i(this.type+": Could not restore the context because the restore context extension is not defined"):i(this.type+": Could not restore the context because the context is not defined"),this.onError&&this.onError()))}},{key:"isContextexFullyRestored",value:function(){for(var e=!0,t=0;t0&&void 0!==arguments[0]&&arguments[0];e&&!this.state.blending?(this.state.blending=e,this.gl.enable(this.gl.BLEND)):!e&&this.state.blending&&(this.state.blending=e,this.gl.disable(this.gl.BLEND))}},{key:"setBlendFunc",value:function(){this.gl.enable(this.gl.BLEND),this.premultipliedAlpha?this.gl.blendFuncSeparate(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}},{key:"setFaceCulling",value:function(e){if(this.state.cullFace!==e)if(this.state.cullFace=e,"none"===e)this.gl.disable(this.gl.CULL_FACE);else{var t="front"===e?this.gl.FRONT:this.gl.BACK;this.gl.enable(this.gl.CULL_FACE),this.gl.cullFace(t)}}},{key:"useProgram",value:function(e){null!==this.state.currentProgramID&&this.state.currentProgramID===e.id||(this.gl.useProgram(e.program),this.state.currentProgramID=e.id)}},{key:"removePlane",value:function(e){this.gl&&(this.planes=this.planes.filter((function(t){return t.uuid!==e.uuid})),this.scene.removePlane(e),e=null,this.gl&&this.clear(),this.onSceneChange())}},{key:"removeRenderTarget",value:function(e){if(this.gl){for(var t=this.planes.find((function(t){return"PingPongPlane"!==t.type&&t.target&&t.target.uuid===e.uuid})),i=0;i0;)this.removePlane(this.planes[0]);for(;this.shaderPasses.length>0;)this.removeShaderPass(this.shaderPasses[0]);for(;this.renderTargets.length>0;)this.removeRenderTarget(this.renderTargets[0]);var t=this.nextRender.add((function(){0===e.planes.length&&0===e.shaderPasses.length&&0===e.renderTargets.length&&(t.keep=!1,e.deletePrograms(),e.clear(),e.canvas.removeEventListener("webgllost",e._contextLostHandler,!1),e.canvas.removeEventListener("webglrestored",e._contextRestoredHandler,!1),e.gl&&e.extensions.WEBGL_lose_context&&e.extensions.WEBGL_lose_context.loseContext(),e.canvas.width=e.canvas.width,e.gl=null,e.container.removeChild(e.canvas),e.container=null,e.canvas=null,e.onDisposed&&e.onDisposed())}),!0)}}}]),e}(),u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.xOffset,r=void 0===i?0:i,s=t.yOffset,n=void 0===s?0:s,a=t.lastXDelta,o=void 0===a?0:a,h=t.lastYDelta,l=void 0===h?0:h,u=t.shouldWatch,d=void 0===u||u,c=t.onScroll,p=void 0===c?function(){}:c;_classCallCheck(this,e),this.xOffset=r,this.yOffset=n,this.lastXDelta=o,this.lastYDelta=l,this.shouldWatch=d,this.onScroll=p,this.handler=this.scroll.bind(this,!0),this.shouldWatch&&window.addEventListener("scroll",this.handler,{passive:!0})}return _createClass(e,[{key:"scroll",value:function(){this.updateScrollValues(window.pageXOffset,window.pageYOffset)}},{key:"updateScrollValues",value:function(e,t){var i=this.xOffset;this.xOffset=e,this.lastXDelta=i-this.xOffset;var r=this.yOffset;this.yOffset=t,this.lastYDelta=r-this.yOffset,this.onScroll&&this.onScroll(this.lastXDelta,this.lastYDelta)}},{key:"dispose",value:function(){this.shouldWatch&&window.removeEventListener("scroll",this.handler,{passive:!0})}}]),e}(),d=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.container,s=t.alpha,n=void 0===s||s,a=t.premultipliedAlpha,o=void 0!==a&&a,h=t.antialias,l=void 0===h||h,u=t.depth,d=void 0===u||u,c=t.failIfMajorPerformanceCaveat,p=void 0===c||c,f=t.preserveDrawingBuffer,g=void 0!==f&&f,_=t.stencil,m=void 0!==_&&_,v=t.autoResize,y=void 0===v||v,x=t.autoRender,b=void 0===x||x,k=t.watchScroll,R=void 0===k||k,w=t.pixelRatio,P=void 0===w?window.devicePixelRatio||1:w,T=t.renderingScale,S=void 0===T?1:T,C=t.production,E=void 0!==C&&C;_classCallCheck(this,e),this.type="Curtains",this._autoResize=y,this._autoRender=b,this._watchScroll=R,this.pixelRatio=P,S=isNaN(S)?1:parseFloat(S),this._renderingScale=Math.max(.25,Math.min(1,S)),this.premultipliedAlpha=o,this.alpha=n,this.antialias=l,this.depth=d,this.failIfMajorPerformanceCaveat=p,this.preserveDrawingBuffer=g,this.stencil=m,this.production=E,this.errors=!1,r?this.setContainer(r):this.production||i(this.type+": no container provided in the initial parameters. Use setContainer() method to set one later and initialize the WebGL context")}return _createClass(e,[{key:"setContainer",value:function(e){if(e)if("string"==typeof e)if(e=document.getElementById(e))this.container=e;else{var t=document.createElement("div");t.setAttribute("id","curtains-canvas"),document.body.appendChild(t),this.container=t,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}else e instanceof Element&&(this.container=e);else{var r=document.createElement("div");r.setAttribute("id","curtains-canvas"),document.body.appendChild(r),this.container=r,this.production||i('Curtains: no valid container HTML element or ID provided, created a div with "curtains-canvas" ID instead')}this._initCurtains()}},{key:"_initCurtains",value:function(){this.planes=[],this.renderTargets=[],this.shaderPasses=[],this._initRenderer(),this.gl&&(this._initScroll(),this._setSize(),this._addListeners(),this.container.appendChild(this.canvas),this._animationFrameID=null,this._autoRender&&this._animate())}},{key:"_initRenderer",value:function(){var e=this;this.renderer=new l({alpha:this.alpha,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,depth:this.depth,failIfMajorPerformanceCaveat:this.failIfMajorPerformanceCaveat,preserveDrawingBuffer:this.preserveDrawingBuffer,stencil:this.stencil,container:this.container,pixelRatio:this.pixelRatio,renderingScale:this._renderingScale,production:this.production,onError:function(){return e._onRendererError()},onSuccess:function(){return e._onRendererSuccess()},onContextLost:function(){return e._onRendererContextLost()},onContextRestored:function(){return e._onRendererContextRestored()},onDisposed:function(){return e._onRendererDisposed()},onSceneChange:function(){return e._keepSync()}}),this.gl=this.renderer.gl,this.canvas=this.renderer.canvas}},{key:"restoreContext",value:function(){this.renderer.restoreContext()}},{key:"_animate",value:function(){this.render(),this._animationFrameID=window.requestAnimationFrame(this._animate.bind(this))}},{key:"enableDrawing",value:function(){this.renderer.enableDrawing()}},{key:"disableDrawing",value:function(){this.renderer.disableDrawing()}},{key:"needRender",value:function(){this.renderer.needRender()}},{key:"nextRender",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return this.renderer.nextRender.add(e,t)}},{key:"clear",value:function(){this.renderer&&this.renderer.clear()}},{key:"clearDepth",value:function(){this.renderer&&this.renderer.clearDepth()}},{key:"clearColor",value:function(){this.renderer&&this.renderer.clearColor()}},{key:"isWebGL2",value:function(){return!!this.gl&&this.renderer._isWebGL2}},{key:"render",value:function(){this.renderer.nextRender.execute(),(this.renderer.state.drawingEnabled||this.renderer.state.forceRender)&&(this.renderer.state.forceRender&&(this.renderer.state.forceRender=!1),this._onRenderCallback&&this._onRenderCallback(),this.renderer.render())}},{key:"_addListeners",value:function(){this._resizeHandler=null,this._autoResize&&(this._resizeHandler=this.resize.bind(this,!0),window.addEventListener("resize",this._resizeHandler,!1))}},{key:"setPixelRatio",value:function(e,t){this.pixelRatio=parseFloat(Math.max(e,1))||1,this.renderer.setPixelRatio(e),this.resize(t)}},{key:"_setSize",value:function(){this.renderer.setSize(),this._scrollManager.shouldWatch&&(this._scrollManager.xOffset=window.pageXOffset,this._scrollManager.yOffset=window.pageYOffset)}},{key:"getBoundingRect",value:function(){return this.renderer._boundingRect}},{key:"resize",value:function(e){var t=this;this.gl&&(this._setSize(),this.renderer.resize(),this.nextRender((function(){t._onAfterResizeCallback&&e&&t._onAfterResizeCallback()})))}},{key:"_initScroll",value:function(){var e=this;this._scrollManager=new u({xOffset:window.pageXOffset,yOffset:0,lastXDelta:0,lastYDelta:0,shouldWatch:this._watchScroll,onScroll:function(t,i){return e._updateScroll(t,i)}})}},{key:"_updateScroll",value:function(e,t){for(var i=0;i1&&void 0!==arguments[1]?arguments[1]:{},n=s.parent,a=s.vertexShader,o=s.fragmentShader;if(_classCallCheck(this,e),this.type="Program",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.parent=n,this.defaultVsCode="Plane"===this.parent.type?_:v,this.defaultFsCode="Plane"===this.parent.type?m:y,a?this.vsCode=a:(this.renderer.production||"Plane"!==this.parent.type||i(this.parent.type+": No vertex shader provided, will use a default one"),this.vsCode=this.defaultVsCode),o?this.fsCode=o:(this.renderer.production||i(this.parent.type+": No fragment shader provided, will use a default one"),this.fsCode=this.defaultFsCode),this.compiled=!0,this.setupProgram()}return _createClass(e,[{key:"createShader",value:function(e,t){var s=this.gl.createShader(t);if(this.gl.shaderSource(s,e),this.gl.compileShader(s),!this.renderer.production&&!this.gl.getShaderParameter(s,this.gl.COMPILE_STATUS)){for(var n=t===this.gl.VERTEX_SHADER?"vertex shader":"fragment shader",a=this.gl.getShaderSource(s).split("\n"),o=0;o1&&void 0!==arguments[1]?arguments[1]:{},s=(i.program,i.width),n=void 0===s?1:s,a=i.height,o=void 0===a?1:a;if(_classCallCheck(this,e),this.type="Geometry",t&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.definition={id:n*o+n,width:n,height:o},this.setDefaultAttributes(),this.setVerticesUVs()}return _createClass(e,[{key:"restoreContext",value:function(e){this.program=null,this.setDefaultAttributes(),this.setVerticesUVs(),this.setProgram(e)}},{key:"setDefaultAttributes",value:function(){this.attributes={vertexPosition:{name:"aVertexPosition",size:3,isActive:!1},textureCoord:{name:"aTextureCoord",size:3,isActive:!1}}}},{key:"setVerticesUVs",value:function(){var e=this.renderer.cache.getGeometryFromID(this.definition.id);e?(this.attributes.vertexPosition.array=e.vertices,this.attributes.textureCoord.array=e.uvs):(this.computeVerticesUVs(),this.renderer.cache.addGeometry(this.definition.id,this.attributes.vertexPosition.array,this.attributes.textureCoord.array))}},{key:"setProgram",value:function(e){this.program=e,this.initAttributes(),this.renderer._isWebGL2?(this._vao=this.gl.createVertexArray(),this.gl.bindVertexArray(this._vao)):this.renderer.extensions.OES_vertex_array_object&&(this._vao=this.renderer.extensions.OES_vertex_array_object.createVertexArrayOES(),this.renderer.extensions.OES_vertex_array_object.bindVertexArrayOES(this._vao)),this.initializeBuffers()}},{key:"initAttributes",value:function(){for(var e in this.attributes){if(this.attributes[e].isActive=this.program.activeAttributes.includes(this.attributes[e].name),!this.attributes[e].isActive)return;this.attributes[e].location=this.gl.getAttribLocation(this.program.program,this.attributes[e].name),this.attributes[e].buffer=this.gl.createBuffer(),this.attributes[e].numberOfItems=this.definition.width*this.definition.height*this.attributes[e].size*2}}},{key:"computeVerticesUVs",value:function(){this.attributes.vertexPosition.array=[],this.attributes.textureCoord.array=[];for(var e=this.attributes.vertexPosition.array,t=this.attributes.textureCoord.array,i=0;i0&&void 0!==arguments[0]?arguments[0]:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);_classCallCheck(this,e),this.type="Mat4",this.elements=t}return _createClass(e,[{key:"setFromArray",value:function(e){for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;_classCallCheck(this,e),this.type="Vec2",this._x=t,this._y=i}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t){return this._x=e,this._y=t,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this}},{key:"clone",value:function(){return new e(this._x,this._y)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y}}]),e}(),P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;_classCallCheck(this,e),this.type="Vec3",this._x=t,this._y=i,this._z=r}return _createClass(e,[{key:"x",get:function(){return this._x},set:function(e){var t=e!==this._x;this._x=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"y",get:function(){return this._y},set:function(e){var t=e!==this._y;this._y=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"z",get:function(){return this._z},set:function(e){var t=e!==this._z;this._z=e,t&&this._onChangeCallback&&this._onChangeCallback()}},{key:"onChange",value:function(e){return e&&(this._onChangeCallback=e),this}},{key:"set",value:function(e,t,i){return this._x=e,this._y=t,this._z=i,this}},{key:"add",value:function(e){return this._x+=e.x,this._y+=e.y,this._z+=e.z,this}},{key:"addScalar",value:function(e){return this._x+=e,this._y+=e,this._z+=e,this}},{key:"sub",value:function(e){return this._x-=e.x,this._y-=e.y,this._z-=e.z,this}},{key:"subScalar",value:function(e){return this._x-=e,this._y-=e,this._z-=e,this}},{key:"multiply",value:function(e){return this._x*=e.x,this._y*=e.y,this._z*=e.z,this}},{key:"multiplyScalar",value:function(e){return this._x*=e,this._y*=e,this._z*=e,this}},{key:"copy",value:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this}},{key:"clone",value:function(){return new e(this._x,this._y,this._z)}},{key:"sanitizeNaNValuesWith",value:function(e){return this._x=isNaN(this._x)?e.x:parseFloat(this._x),this._y=isNaN(this._y)?e.y:parseFloat(this._y),this._z=isNaN(this._z)?e.z:parseFloat(this._z),this}},{key:"max",value:function(e){return this._x=Math.max(this._x,e.x),this._y=Math.max(this._y,e.y),this._z=Math.max(this._z,e.z),this}},{key:"min",value:function(e){return this._x=Math.min(this._x,e.x),this._y=Math.min(this._y,e.y),this._z=Math.min(this._z,e.z),this}},{key:"equals",value:function(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}},{key:"normalize",value:function(){var e=this._x*this._x+this._y*this._y+this._z*this._z;return e>0&&(e=1/Math.sqrt(e)),this._x*=e,this._y*=e,this._z*=e,this}},{key:"dot",value:function(e){return this._x*e.x+this._y*e.y+this._z*e.z}},{key:"applyMat4",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements,n=s[3]*t+s[7]*i+s[11]*r+s[15];return n=n||1,this._x=(s[0]*t+s[4]*i+s[8]*r+s[12])/n,this._y=(s[1]*t+s[5]*i+s[9]*r+s[13])/n,this._z=(s[2]*t+s[6]*i+s[10]*r+s[14])/n,this}},{key:"applyQuat",value:function(e){var t=this._x,i=this._y,r=this._z,s=e.elements[0],n=e.elements[1],a=e.elements[2],o=e.elements[3],h=o*t+n*r-a*i,l=o*i+a*t-s*r,u=o*r+s*i-n*t,d=-s*t-n*i-a*r;return this._x=h*o+d*-s+l*-a-u*-n,this._y=l*o+d*-n+u*-s-h*-a,this._z=u*o+d*-a+h*-n-l*-s,this}},{key:"project",value:function(e){return this.applyMat4(e.viewMatrix).applyMat4(e.projectionMatrix),this}},{key:"unproject",value:function(e){return this.applyMat4(e.projectionMatrix.getInverse()).applyMat4(e.worldMatrix),this}}]),e}(),T=new w,S=new P,C=new R,E=function(){function e(t){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.isFBOTexture,o=void 0!==a&&a,h=n.fromTexture,l=void 0!==h&&h,u=n.loader,d=n.sampler,c=n.floatingPoint,p=void 0===c?"none":c,f=n.premultiplyAlpha,g=void 0!==f&&f,_=n.anisotropy,m=void 0===_?1:_,v=n.generateMipmap,y=void 0===v?null:v,x=n.wrapS,b=n.wrapT,k=n.minFilter,P=n.magFilter;if(_classCallCheck(this,e),this.type="Texture",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);if(this.renderer=t,this.gl=this.renderer.gl,this.uuid=s(),this._globalParameters={unpackAlignment:4,flipY:!o,premultiplyAlpha:!1,shouldPremultiplyAlpha:g,floatingPoint:p,type:this.gl.UNSIGNED_BYTE,internalFormat:this.gl.RGBA,format:this.gl.RGBA},this.parameters={anisotropy:m,generateMipmap:y,wrapS:x||this.gl.CLAMP_TO_EDGE,wrapT:b||this.gl.CLAMP_TO_EDGE,minFilter:k||this.gl.LINEAR,magFilter:P||this.gl.LINEAR,_shouldUpdate:!0},this._initState(),this.sourceType=o?"fbo":"empty",this._useCache=!0,this._samplerName=d,this._sampler={isActive:!1,isTextureBound:!1,texture:this.gl.createTexture()},this._textureMatrix={matrix:new R,isActive:!1},this._size={width:1,height:1},this.scale=new w(1),this.scale.onChange((function(){return i.resize()})),this.offset=new w,this.offset.onChange((function(){return i.resize()})),this._loader=u,this._sourceLoaded=!1,this._uploaded=!1,this._willUpdate=!1,this.shouldUpdate=!1,this._forceUpdate=!1,this.userData={},this._canDraw=!1,l)return this._copyOnInit=!0,void(this._copiedFrom=l);this._copyOnInit=!1,this._initTexture()}return _createClass(e,[{key:"_initState",value:function(){this._state={anisotropy:1,generateMipmap:!1,wrapS:null,wrapT:null,minFilter:null,magFilter:this.gl.LINEAR}}},{key:"_initTexture",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture),"empty"===this.sourceType&&(this._globalParameters.flipY=!1,this._updateGlobalTexParameters(),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this._canDraw=!0)}},{key:"_restoreFromTexture",value:function(){this._copyOnInit||this._initTexture(),this._parent&&(this._setTextureUniforms(),this._setSize()),this.copy(this._copiedFrom),this._canDraw=!0}},{key:"_restoreContext",value:function(){var e=this;if(this._canDraw=!1,this._sampler.texture=this.gl.createTexture(),this._sampler.isActive=!1,this._sampler.isTextureBound=!1,this._textureMatrix.isActive=!1,this._initState(),this._state.generateMipmap=!1,this.parameters._shouldUpdate=!0,this._copiedFrom)var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&(e._restoreFromTexture(),t.keep=!1)}),!0);else this._initTexture(),this._parent&&this._setParent(),this.source&&(this.setSource(this.source),"image"===this.sourceType?this.renderer.cache.addTexture(this):this.needUpdate()),this._canDraw=!0}},{key:"addParent",value:function(e){!e||"Plane"!==e.type&&"PingPongPlane"!==e.type&&"ShaderPass"!==e.type&&"RenderTarget"!==e.type?this.renderer.production||i(this.type+": cannot add texture as a child of ",e," because it is not a valid parent"):(this._parent=e,this.index=this._parent.textures.length,this._parent.textures.push(this),this._setParent())}},{key:"_setParent",value:function(){var e=this;if(this._sampler.name=this._samplerName||"uSampler"+this.index,this._textureMatrix.name=this._samplerName?this._samplerName+"Matrix":"uTextureMatrix"+this.index,this._parent._program){if(!this._parent._program.compiled)return void(this.renderer.production||i(this.type+": Unable to create the texture because the program is not valid"));if(this._setTextureUniforms(),this._copyOnInit){var t=this.renderer.nextRender.add((function(){e._copiedFrom._canDraw&&e._copiedFrom._uploaded&&(e.copy(e._copiedFrom),t.keep=!1)}),!0);return}this.source?this._parent.loader&&this._parent.loader._addSourceToParent(this.source,this.sourceType):this._size={width:this._parent._boundingRect.document.width,height:this._parent._boundingRect.document.height},this._setSize()}else"RenderTarget"===this._parent.type&&(this._size={width:this._parent._size&&this._parent._size.width||this.renderer._boundingRect.width,height:this._parent._size&&this._parent._size.height||this.renderer._boundingRect.height},this._upload(),this._updateTexParameters(),this._canDraw=!0)}},{key:"hasParent",value:function(){return!!this._parent}},{key:"_setTextureUniforms",value:function(){for(var e=this,t=this._parent._program.activeUniforms,i=0;in?h=Math.min(0,i-t*(1/n)):a=this.source.HAVE_CURRENT_DATA&&!this.source.paused&&(this._willUpdate=!0),(this._forceUpdate||this._willUpdate&&this.shouldUpdate)&&(this._state.generateMipmap=!1,this._upload()),"video"===this.sourceType&&(this._willUpdate=!1),this._forceUpdate=!1),this.parameters._shouldUpdate&&(this._updateTexParameters(),this.parameters._shouldUpdate=!1)}},{key:"onSourceLoaded",value:function(e){return e&&(this._onSourceLoadedCallback=e),this}},{key:"onSourceUploaded",value:function(e){return e&&(this._onSourceUploadedCallback=e),this}},{key:"_dispose",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if("video"===this.sourceType||"image"===this.sourceType&&!this.renderer.state.isActive)this._loader&&this._loader._removeSource(this),this.source=null;else if("canvas"===this.sourceType&&this.source){var t;this.source.width=null===(t=this.source)||void 0===t?void 0:t.width,this.source=null}this._parent=null;var i=this.gl&&!this._copiedFrom&&(e||"image"!==this.sourceType||!this.renderer.state.isActive);i&&(this._canDraw=!1,this.renderer.cache.removeTexture(this),this.gl.activeTexture(this.gl.TEXTURE0+this.index),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.gl.deleteTexture(this._sampler.texture))}}]),e}(),M=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"anonymous";if(_classCallCheck(this,e),this.type="TextureLoader",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void r(this.type+": Renderer WebGL context is undefined",t)}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.crossOrigin=i,this.elements=[]}return _createClass(e,[{key:"_addElement",value:function(e,t,i,r){var s={source:e,texture:t,load:this._sourceLoaded.bind(this,e,t,i),error:this._sourceLoadError.bind(this,e,r)};return this.elements.push(s),s}},{key:"_sourceLoadError",value:function(e,t,i){t&&t(e,i)}},{key:"_sourceLoaded",value:function(e,t,i){var r=this;t._sourceLoaded||(t._onSourceLoaded(e),this._parent&&(this._increment&&this._increment(),this.renderer.nextRender.add((function(){return r._parent._onLoadingCallback&&r._parent._onLoadingCallback(t)}))),i&&i(t))}},{key:"_getSourceType",value:function(e){var t;return"string"==typeof e?null!==e.match(/\.(jpeg|jpg|jfif|pjpeg|pjp|gif|bmp|png|webp|svg|avif|apng)$/)?t="image":null!==e.match(/\.(webm|mp4|mpg|mpeg|avi|ogg|ogm|ogv|mov|av1)$/)&&(t="video"):"IMG"===e.tagName.toUpperCase()?t="image":"VIDEO"===e.tagName.toUpperCase()?t="video":"CANVAS"===e.tagName.toUpperCase()&&(t="canvas"),t}},{key:"_createImage",value:function(e){if("string"!=typeof e&&e.hasAttribute("crossOrigin"))return e;var t=new Image;return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}},{key:"_createVideo",value:function(e){if("string"==typeof e||null===e.getAttribute("crossOrigin")){var t=document.createElement("video");return t.crossOrigin=this.crossOrigin,"string"==typeof e?t.src=e:(t.src=e.src,e.hasAttribute("data-sampler")&&t.setAttribute("data-sampler",e.getAttribute("data-sampler"))),t}return e}},{key:"loadSource",value:function(e,t,i,r){switch(this._getSourceType(e)){case"image":this.loadImage(e,t,i,r);break;case"video":this.loadVideo(e,t,i,r);break;case"canvas":this.loadCanvas(e,t,i);break;default:this._sourceLoadError(e,r,"this source could not be converted into a texture: "+e)}}},{key:"loadSources",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this.renderer.cache.getTextureFromSource(e),n=Object.assign({},t);if(this._parent&&(n=Object.assign(n,this._parent._texturesOptions)),n.loader=this,s){n.sampler="string"!=typeof e&&e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):n.sampler,n.fromTexture=s;var a=new E(this.renderer,n);return this._sourceLoaded(s.source,a,i),void(this._parent&&this._addToParent(a,s.source,"image"))}var o=this._createImage(e);n.sampler=o.hasAttribute("data-sampler")?o.getAttribute("data-sampler"):n.sampler;var h=new E(this.renderer,n),l=this._addElement(o,h,i,r);o.complete?this._sourceLoaded(o,h,i):o.decode?o.decode().then(this._sourceLoaded.bind(this,o,h,i)).catch((function(){o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)})):(o.addEventListener("load",l.load,!1),o.addEventListener("error",l.error,!1)),this._parent&&this._addToParent(h,o,"image")}},{key:"loadImages",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=this._createVideo(e);s.preload=!0,s.muted=!0,s.loop=!0,s.setAttribute("playsinline",""),s.crossOrigin=this.crossOrigin;var n=Object.assign({},t);this._parent&&(n=Object.assign(t,this._parent._texturesOptions)),n.loader=this,n.sampler=s.hasAttribute("data-sampler")?s.getAttribute("data-sampler"):n.sampler;var a=new E(this.renderer,n),o=this._addElement(s,a,i,r);s.addEventListener("canplaythrough",o.load,!1),s.addEventListener("error",o.error,!1),s.readyState>=s.HAVE_FUTURE_DATA&&i&&this._sourceLoaded(s,a,i),s.load(),this._addToParent&&this._addToParent(a,s,"video"),"requestVideoFrameCallback"in HTMLVideoElement.prototype&&(o.videoFrameCallback=a._videoFrameCallback.bind(a),a._videoFrameCallbackID=s.requestVideoFrameCallback(o.videoFrameCallback))}},{key:"loadVideos",value:function(e,t,i,r){for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=Object.assign({},t);this._parent&&(r=Object.assign(t,this._parent._texturesOptions)),r.loader=this,r.sampler=e.hasAttribute("data-sampler")?e.getAttribute("data-sampler"):r.sampler;var s=new E(this.renderer,r);this._addElement(e,s,i,null),this._sourceLoaded(e,s,i),this._parent&&this._addToParent(s,e,"canvas")}},{key:"loadCanvases",value:function(e,t,i){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:{},o=a.sourcesLoaded,h=void 0===o?0:o,l=a.sourcesToLoad,u=void 0===l?0:l,d=a.complete,c=void 0!==d&&d,p=a.onComplete,f=void 0===p?function(){}:p;return _classCallCheck(this,r),(n=t.call(this,e,s.crossOrigin)).type="PlaneTextureLoader",n._parent=s,"Plane"!==n._parent.type&&"PingPongPlane"!==n._parent.type&&"ShaderPass"!==n._parent.type&&(i(n.type+": Wrong parent type assigned to this loader"),n._parent=null),n.sourcesLoaded=h,n.sourcesToLoad=u,n.complete=c,n.onComplete=f,n}return _createClass(r,[{key:"_setLoaderSize",value:function(e){var t=this;this.sourcesToLoad=e,0===this.sourcesToLoad&&(this.complete=!0,this.renderer.nextRender.add((function(){return t.onComplete&&t.onComplete()})))}},{key:"_increment",value:function(){var e=this;this.sourcesLoaded++,this.sourcesLoaded>=this.sourcesToLoad&&!this.complete&&(this.complete=!0,this.renderer.nextRender.add((function(){return e.onComplete&&e.onComplete()})))}},{key:"_addSourceToParent",value:function(e,t){if("image"===t){var i=this._parent.images;!i.find((function(t){return t.src===e.src}))&&i.push(e)}else if("video"===t){var r=this._parent.videos;!r.find((function(t){return t.src===e.src}))&&r.push(e)}else if("canvas"===t){var s=this._parent.canvases;!s.find((function(t){return t.isSameNode(e)}))&&s.push(e)}}},{key:"_addToParent",value:function(e,t,i){this._addSourceToParent(t,i),this._parent&&e.addParent(this._parent)}}]),r}(M),F=function(){function e(t){var i=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Mesh",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.vertexShaderID,o=n.fragmentShaderID,h=n.vertexShader,l=n.fragmentShader,u=n.uniforms,d=void 0===u?{}:u,c=n.widthSegments,p=void 0===c?1:c,f=n.heightSegments,g=void 0===f?1:f,_=n.renderOrder,m=void 0===_?0:_,v=n.depthTest,y=void 0===v||v,x=n.cullFace,R=void 0===x?"back":x,w=n.texturesOptions,P=void 0===w?{}:w,T=n.crossOrigin,S=void 0===T?"anonymous":T;if(_classCallCheck(this,e),this.type=s,(t=t&&t.renderer||t)&&"Renderer"===t.type||(r(this.type+": Curtains not passed as first argument or Curtains Renderer is missing",t),setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0)),this.renderer=t,this.gl=this.renderer.gl,!this.gl)return this.renderer.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"),void setTimeout((function(){i._onErrorCallback&&i._onErrorCallback()}),0);this._canDraw=!1,this.renderOrder=m,this._depthTest=y,this.cullFace=R,"back"!==this.cullFace&&"front"!==this.cullFace&&"none"!==this.cullFace&&(this.cullFace="back"),this.textures=[],this._texturesOptions=Object.assign({premultiplyAlpha:!1,anisotropy:1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},P),this.crossOrigin=S,!h&&a&&document.getElementById(a)&&(h=document.getElementById(a).innerHTML),!l&&o&&document.getElementById(o)&&(l=document.getElementById(o).innerHTML),this._initMesh(),p=parseInt(p),g=parseInt(g),this._geometry=new k(this.renderer,{width:p,height:g}),this._program=new b(this.renderer,{parent:this,vertexShader:h,fragmentShader:l}),this._program.compiled?(this._program.createUniforms(d),this.uniforms=this._program.uniformsManager.uniforms,this._geometry.setProgram(this._program),this.renderer.onSceneChange()):this.renderer.nextRender.add((function(){return i._onErrorCallback&&i._onErrorCallback()}))}return _createClass(e,[{key:"_initMesh",value:function(){var e=this;this.uuid=s(),this.loader=new A(this.renderer,this,{sourcesLoaded:0,initSourcesToLoad:0,complete:!1,onComplete:function(){e._onReadyCallback&&e._onReadyCallback(),e.renderer.needRender()}}),this.images=[],this.videos=[],this.canvases=[],this.userData={},this._canDraw=!0}},{key:"_restoreContext",value:function(){this._canDraw=!1,this._matrices&&(this._matrices=null),this._program=new b(this.renderer,{parent:this,vertexShader:this._program.vsCode,fragmentShader:this._program.fsCode}),this._program.compiled&&(this._geometry.restoreContext(this._program),this._program.createUniforms(this.uniforms),this.uniforms=this._program.uniformsManager.uniforms,this._programRestored())}},{key:"setRenderTarget",value:function(e){e&&"RenderTarget"===e.type?("Plane"===this.type&&this.renderer.scene.removePlane(this),this.target=e,"Plane"===this.type&&this.renderer.scene.addPlane(this)):this.renderer.production||i(this.type+": Could not set the render target because the argument passed is not a RenderTarget class object",e)}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;(e=isNaN(e)?this.renderOrder:parseInt(e))!==this.renderOrder&&(this.renderOrder=e,this.renderer.scene.setPlaneRenderOrder(this))}},{key:"createTexture",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=new E(this.renderer,Object.assign(e,this._texturesOptions));return t.addParent(this),t}},{key:"addTexture",value:function(e){e&&"Texture"===e.type?e.addParent(this):this.renderer.production||i(this.type+": cannot add ",e," to this "+this.type+" because it is not a valid texture")}},{key:"loadSources",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadSource(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": this HTML tag could not be converted into a texture:",e.tagName),n&&n(e,r)}))}},{key:"loadImage",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadImage(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this image:\n",e),n&&n(e,r)}))}},{key:"loadVideo",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;this.loader.loadVideo(e,Object.assign(r,this._texturesOptions),(function(e){s&&s(e)}),(function(e,r){t.renderer.production||i(t.type+": There has been an error:\n",r,"\nwhile loading this video:\n",e),n&&n(e,r)}))}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;this.loader.loadCanvas(e,Object.assign(t,this._texturesOptions),(function(e){i&&i(e)}))}},{key:"loadImages",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,s=0;s1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=0;r2&&void 0!==arguments[2]?arguments[2]:"DOMMesh",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},h=o.widthSegments,l=o.heightSegments,u=o.renderOrder,d=o.depthTest,c=o.cullFace,p=o.uniforms,f=o.vertexShaderID,g=o.fragmentShaderID,_=o.vertexShader,m=o.fragmentShader,v=o.texturesOptions,y=o.crossOrigin;return _classCallCheck(this,r),f=f||s&&s.getAttribute("data-vs-id"),g=g||s&&s.getAttribute("data-fs-id"),(n=t.call(this,e,a,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y})).gl?(n.htmlElement=s,n.htmlElement&&0!==n.htmlElement.length||n.renderer.production||i(n.type+": The HTML element you specified does not currently exists in the DOM"),n._setDocumentSizes(),n):_possibleConstructorReturn(n)}return _createClass(r,[{key:"_setDocumentSizes",value:function(){var e=this.htmlElement.getBoundingClientRect();this._boundingRect||(this._boundingRect={}),this._boundingRect.document={width:e.width*this.renderer.pixelRatio,height:e.height*this.renderer.pixelRatio,top:e.top*this.renderer.pixelRatio,left:e.left*this.renderer.pixelRatio}}},{key:"getBoundingRect",value:function(){return{width:this._boundingRect.document.width,height:this._boundingRect.document.height,top:this._boundingRect.document.top,left:this._boundingRect.document.left,right:this._boundingRect.document.left+this._boundingRect.document.width,bottom:this._boundingRect.document.top+this._boundingRect.document.height}}},{key:"resize",value:function(){var e=this;this._setDocumentSizes(),"Plane"===this.type&&(this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions());for(var t=0;t0&&void 0!==arguments[0]?arguments[0]:{},i=t.fov,r=void 0===i?50:i,s=t.near,n=void 0===s?.1:s,a=t.far,o=void 0===a?150:a,h=t.width,l=t.height,u=t.pixelRatio,d=void 0===u?1:u;_classCallCheck(this,e),this.position=new P,this.projectionMatrix=new R,this.worldMatrix=new R,this.viewMatrix=new R,this._shouldUpdate=!1,this.setSize(),this.setPerspective(r,n,o,h,l,d)}return _createClass(e,[{key:"setFov",value:function(e){e=isNaN(e)?this.fov:parseFloat(e),(e=Math.max(1,Math.min(e,179)))!==this.fov&&(this.fov=e,this.setPosition(),this._shouldUpdate=!0),this.setCSSPerspective()}},{key:"setNear",value:function(e){e=isNaN(e)?this.near:parseFloat(e),(e=Math.max(e,.01))!==this.near&&(this.near=e,this._shouldUpdate=!0)}},{key:"setFar",value:function(e){e=isNaN(e)?this.far:parseFloat(e),(e=Math.max(e,50))!==this.far&&(this.far=e,this._shouldUpdate=!0)}},{key:"setPixelRatio",value:function(e){e!==this.pixelRatio&&(this._shouldUpdate=!0),this.pixelRatio=e}},{key:"setSize",value:function(e,t){e===this.width&&t===this.height||(this._shouldUpdate=!0),this.width=e,this.height=t}},{key:"setPerspective",value:function(e,t,i,r,s,n){this.setPixelRatio(n),this.setSize(r,s),this.setFov(e),this.setNear(t),this.setFar(i),this._shouldUpdate&&this.updateProjectionMatrix()}},{key:"setPosition",value:function(){this.position.set(0,0,1),this.worldMatrix.setFromArray([1,0,0,0,0,1,0,0,0,0,1,0,this.position.x,this.position.y,this.position.z,1]),this.viewMatrix=this.viewMatrix.copy(this.worldMatrix).getInverse()}},{key:"setCSSPerspective",value:function(){this.CSSPerspective=Math.pow(Math.pow(this.width/(2*this.pixelRatio),2)+Math.pow(this.height/(2*this.pixelRatio),2),.5)/Math.tan(.5*this.fov*Math.PI/180)}},{key:"getScreenRatiosFromFov",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.position.z;e0&&void 0!==arguments[0]?arguments[0]:new Float32Array([0,0,0,1]),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"XYZ";_classCallCheck(this,e),this.type="Quat",this.elements=t,this.axisOrder=i}return _createClass(e,[{key:"setFromArray",value:function(e){return this.elements[0]=e[0],this.elements[1]=e[1],this.elements[2]=e[2],this.elements[3]=e[3],this}},{key:"setAxisOrder",value:function(e){switch(e=e.toUpperCase()){case"XYZ":case"YXZ":case"ZXY":case"ZYX":case"YZX":case"XZY":this.axisOrder=e;break;default:this.axisOrder="XYZ"}return this}},{key:"copy",value:function(e){return this.elements=e.elements,this.axisOrder=e.axisOrder,this}},{key:"clone",value:function(){return(new e).copy(this)}},{key:"equals",value:function(e){return this.elements[0]===e.elements[0]&&this.elements[1]===e.elements[1]&&this.elements[2]===e.elements[2]&&this.elements[3]===e.elements[3]&&this.axisOrder===e.axisOrder}},{key:"setFromVec3",value:function(e){var t=.5*e.x,i=.5*e.y,r=.5*e.z,s=Math.cos(t),n=Math.cos(i),a=Math.cos(r),o=Math.sin(t),h=Math.sin(i),l=Math.sin(r);return"XYZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"YXZ"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"ZXY"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a-o*h*l):"ZYX"===this.axisOrder?(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a+o*h*l):"YZX"===this.axisOrder?(this.elements[0]=o*n*a+s*h*l,this.elements[1]=s*h*a+o*n*l,this.elements[2]=s*n*l-o*h*a,this.elements[3]=s*n*a-o*h*l):"XZY"===this.axisOrder&&(this.elements[0]=o*n*a-s*h*l,this.elements[1]=s*h*a-o*n*l,this.elements[2]=s*n*l+o*h*a,this.elements[3]=s*n*a+o*h*l),this}}]),e}(),I=new w,V=new P,B=new P,N=new P,W=new P,G=new P,X=new P,j=new P,H=new P,Y=new U,q=new P(.5,.5,0),Z=new P,Q=new P,K=new P,J=new P,$=new w,ee=function(e){_inherits(r,e);var t=_createSuper(r);function r(e,i){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.widthSegments,o=n.heightSegments,h=n.renderOrder,l=n.depthTest,u=n.cullFace,d=n.uniforms,c=n.vertexShaderID,p=n.fragmentShaderID,f=n.vertexShader,g=n.fragmentShader,_=n.texturesOptions,m=n.crossOrigin,v=n.alwaysDraw,y=void 0!==v&&v,x=n.visible,b=void 0===x||x,k=n.transparent,R=void 0!==k&&k,w=n.drawCheckMargins,P=void 0===w?{top:0,right:0,bottom:0,left:0}:w,T=n.autoloadSources,S=void 0===T||T,C=n.watchScroll,E=void 0===C||C,M=n.fov,A=void 0===M?50:M;return _classCallCheck(this,r),(s=t.call(this,e,i,"Plane",{widthSegments:a,heightSegments:o,renderOrder:h,depthTest:l,cullFace:u,uniforms:d,vertexShaderID:c,fragmentShaderID:p,vertexShader:f,fragmentShader:g,texturesOptions:_,crossOrigin:m})).gl?(s.index=s.renderer.planes.length,s.target=null,s.alwaysDraw=y,s._shouldDraw=!0,s.visible=b,s._transparent=R,s.drawCheckMargins=P,s.autoloadSources=S,s.watchScroll=E,s._updateMVMatrix=!1,s.camera=new z({fov:A,width:s.renderer._boundingRect.width,height:s.renderer._boundingRect.height,pixelRatio:s.renderer.pixelRatio}),s._program.compiled&&(s._initPlane(),s.renderer.scene.addPlane(_assertThisInitialized(s)),s.renderer.planes.push(_assertThisInitialized(s))),s):_possibleConstructorReturn(s)}return _createClass(r,[{key:"_programRestored",value:function(){this.target&&this.setRenderTarget(this.renderer.renderTargets[this.target.index]),this._initMatrices(),this.setPerspective(this.camera.fov,this.camera.near,this.camera.far),this._setWorldSizes(),this._applyWorldPositions(),this.renderer.scene.addPlane(this);for(var e=0;e-1;)r.add(i);return r}},{key:"_getNearPlaneIntersections",value:function(e,t,i){var r=this._matrices.modelViewProjection.matrix;if(1===i.length)0===i[0]?(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[3],H.set(-1,-.95,0).applyMat4(r)))):1===i[0]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t.push(this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r)))):2===i[0]?(t[2]=this._getIntersection(t[3],j.set(-.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[1],H.set(1,.95,0).applyMat4(r)))):3===i[0]&&(t[3]=this._getIntersection(t[2],j.set(.95,-1,0).applyMat4(r)),t.push(this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))));else if(2===i.length)0===i[0]&&1===i[1]?(t[0]=this._getIntersection(t[3],j.set(-1,-.95,0).applyMat4(r)),t[1]=this._getIntersection(t[2],H.set(1,-.95,0).applyMat4(r))):1===i[0]&&2===i[1]?(t[1]=this._getIntersection(t[0],j.set(-.95,1,0).applyMat4(r)),t[2]=this._getIntersection(t[3],H.set(-.95,-1,0).applyMat4(r))):2===i[0]&&3===i[1]?(t[2]=this._getIntersection(t[1],j.set(1,.95,0).applyMat4(r)),t[3]=this._getIntersection(t[0],H.set(-1,.95,0).applyMat4(r))):0===i[0]&&3===i[1]&&(t[0]=this._getIntersection(t[1],j.set(.95,1,0).applyMat4(r)),t[3]=this._getIntersection(t[2],H.set(.95,-1,0).applyMat4(r)));else if(3===i.length){for(var s=0,n=0;n1&&i.push(r)}i.length&&(t=this._getNearPlaneIntersections(e,t,i));for(var n=1/0,a=-1/0,o=1/0,h=-1/0,l=0;la&&(a=u.x),u.yh&&(h=u.y)}return{top:h,right:a,bottom:o,left:n}}},{key:"_computeWebGLBoundingRect",value:function(){var e=this._getWorldCoords(),t={top:1-(e.top+1)/2,right:(e.right+1)/2,bottom:1-(e.bottom+1)/2,left:(e.left+1)/2};t.width=t.right-t.left,t.height=t.bottom-t.top,this._boundingRect.worldToDocument={width:t.width*this.renderer._boundingRect.width,height:t.height*this.renderer._boundingRect.height,top:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top,left:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left,right:t.left*this.renderer._boundingRect.width+this.renderer._boundingRect.left+t.width*this.renderer._boundingRect.width,bottom:t.top*this.renderer._boundingRect.height+this.renderer._boundingRect.top+t.height*this.renderer._boundingRect.height}}},{key:"getWebGLBoundingRect",value:function(){return this._matrices.modelViewProjection?(this._boundingRect.worldToDocument&&!this.alwaysDraw||this._computeWebGLBoundingRect(),this._boundingRect.worldToDocument):this._boundingRect.document}},{key:"_getWebGLDrawRect",value:function(){return this._computeWebGLBoundingRect(),{top:this._boundingRect.worldToDocument.top-this.drawCheckMargins.top,right:this._boundingRect.worldToDocument.right+this.drawCheckMargins.right,bottom:this._boundingRect.worldToDocument.bottom+this.drawCheckMargins.bottom,left:this._boundingRect.worldToDocument.left-this.drawCheckMargins.left}}},{key:"_shouldDrawCheck",value:function(){var e=this,t=this._getWebGLDrawRect();Math.round(t.right)<=this.renderer._boundingRect.left||Math.round(t.left)>=this.renderer._boundingRect.left+this.renderer._boundingRect.width||Math.round(t.bottom)<=this.renderer._boundingRect.top||Math.round(t.top)>=this.renderer._boundingRect.top+this.renderer._boundingRect.height?this._shouldDraw&&(this._shouldDraw=!1,this.renderer.nextRender.add((function(){return e._onLeaveViewCallback&&e._onLeaveViewCallback()}))):(this._shouldDraw||this.renderer.nextRender.add((function(){return e._onReEnterViewCallback&&e._onReEnterViewCallback()})),this._shouldDraw=!0)}},{key:"isDrawn",value:function(){return this._canDraw&&this.visible&&(this._shouldDraw||this.alwaysDraw)}},{key:"enableDepthTest",value:function(e){this._depthTest=e}},{key:"_initSources",value:function(){var e=0;if(this.autoloadSources){var t=this.htmlElement.getElementsByTagName("img"),i=this.htmlElement.getElementsByTagName("video"),r=this.htmlElement.getElementsByTagName("canvas");t.length&&this.loadImages(t),i.length&&this.loadVideos(i),r.length&&this.loadCanvases(r),e=t.length+i.length+r.length}this.loader._setLoaderSize(e),this._canDraw=!0}},{key:"_startDrawing",value:function(){this._canDraw&&(this._onRenderCallback&&this._onRenderCallback(),this.target?this.renderer.bindFrameBuffer(this.target):null===this.renderer.state.scenePassIndex&&this.renderer.bindFrameBuffer(null),this._setPerspectiveMatrix(),this._setMVMatrix(),(this.alwaysDraw||this._shouldDraw)&&this.visible&&this._draw())}},{key:"mouseToPlaneCoords",value:function(e){if(Y.setAxisOrder(this.quaternion.axisOrder),Y.equals(this.quaternion)&&q.equals(this.transformOrigin))return _get(_getPrototypeOf(r.prototype),"mouseToPlaneCoords",this).call(this,e);var t={x:e.x/(this.renderer._boundingRect.width/this.renderer.pixelRatio)*2-1,y:2*(1-e.y/(this.renderer._boundingRect.height/this.renderer.pixelRatio))-1},i=this.camera.position.clone(),s=Z.set(t.x,t.y,-.5);s.unproject(this.camera),s.sub(i).normalize();var n=Q.set(0,0,-1);n.applyQuat(this.quaternion).normalize();var a=J.set(0,0,0),o=n.dot(s);if(Math.abs(o)>=1e-4){var h=this._matrices.world.matrix.getInverse().multiply(this.camera.viewMatrix),l=this._boundingRect.world.transformOrigin.clone().add(this._translation),u=K.set(this._translation.x-l.x,this._translation.y-l.y,this._translation.z-l.z);u.applyQuat(this.quaternion),l.add(u);var d=n.dot(l.clone().sub(i))/o;a.copy(i.add(s.multiplyScalar(d))),a.applyMat4(h)}else a.set(1/0,1/0,1/0);return $.set(a.x,a.y)}},{key:"onReEnterView",value:function(e){return e&&(this._onReEnterViewCallback=e),this}},{key:"onLeaveView",value:function(e){return e&&(this._onLeaveViewCallback=e),this}}]),r}(L),te=function(){function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i.shaderPass,a=i.depth,o=void 0!==a&&a,h=i.clear,l=void 0===h||h,u=i.maxWidth,d=i.maxHeight,c=i.minWidth,p=void 0===c?1024:c,f=i.minHeight,g=void 0===f?1024:f,_=i.texturesOptions,m=void 0===_?{}:_;if(_classCallCheck(this,e),this.type="RenderTarget",(t=t&&t.renderer||t)&&"Renderer"===t.type){if(!t.gl)return void(t.production||r(this.type+": Unable to create a "+this.type+" because the Renderer WebGL context is not defined"))}else r(this.type+": Renderer not passed as first argument",t);this.renderer=t,this.gl=this.renderer.gl,this.index=this.renderer.renderTargets.length,this._shaderPass=n,this._depth=o,this._shouldClear=l,this._maxSize={width:u?Math.min(this.renderer.state.maxTextureSize/4,u):this.renderer.state.maxTextureSize/4,height:d?Math.min(this.renderer.state.maxTextureSize/4,d):this.renderer.state.maxTextureSize/4},this._minSize={width:p*this.renderer.pixelRatio,height:g*this.renderer.pixelRatio},m=Object.assign({sampler:"uRenderTexture",isFBOTexture:!0,premultiplyAlpha:!1,anisotropy:1,generateMipmap:!1,floatingPoint:"none",wrapS:this.gl.CLAMP_TO_EDGE,wrapT:this.gl.CLAMP_TO_EDGE,minFilter:this.gl.LINEAR,magFilter:this.gl.LINEAR},m),this._texturesOptions=m,this.userData={},this.uuid=s(),this.renderer.renderTargets.push(this),this.renderer.onSceneChange(),this._initRenderTarget()}return _createClass(e,[{key:"_initRenderTarget",value:function(){this._setSize(),this.textures=[],this._createFrameBuffer()}},{key:"_restoreContext",value:function(){this._setSize(),this._createFrameBuffer()}},{key:"_setSize",value:function(){this._shaderPass&&this._shaderPass._isScenePass?this._size={width:this.renderer._boundingRect.width,height:this.renderer._boundingRect.height}:this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,this.renderer._boundingRect.width)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,this.renderer._boundingRect.height))}}},{key:"resize",value:function(){this._shaderPass&&(this._setSize(),this.textures[0].resize(),this.renderer.bindFrameBuffer(this,!0),this._depth&&this._bindDepthBuffer(),this.renderer.bindFrameBuffer(null))}},{key:"_bindDepthBuffer",value:function(){this._depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this._depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,this._size.width,this._size.height),this.gl.framebufferRenderbuffer(this.gl.FRAMEBUFFER,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this._depthBuffer))}},{key:"_createFrameBuffer",value:function(){(this._frameBuffer=this.gl.createFramebuffer(),this.renderer.bindFrameBuffer(this,!0),this.textures.length)?(this.textures[0]._parent=this,this.textures[0]._restoreContext()):new E(this.renderer,this._texturesOptions).addParent(this);this.gl.framebufferTexture2D(this.gl.FRAMEBUFFER,this.gl.COLOR_ATTACHMENT0,this.gl.TEXTURE_2D,this.textures[0]._sampler.texture,0),this._depth&&(this._depthBuffer=this.gl.createRenderbuffer(),this._bindDepthBuffer()),this.renderer.bindFrameBuffer(null)}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"remove",value:function(){this._shaderPass?this.renderer.production||i(this.type+": You're trying to remove a RenderTarget attached to a ShaderPass. You should remove that ShaderPass instead:",this._shaderPass):(this._dispose(),this.renderer.removeRenderTarget(this))}},{key:"_dispose",value:function(){this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this.textures[0]._dispose(),this.textures=[]}}]),e}(),ie=function(e){_inherits(i,e);var t=_createSuper(i);function i(e,r){var s,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=n.sampler,o=void 0===a?"uPingPongTexture":a,h=n.widthSegments,l=n.heightSegments,u=n.renderOrder,d=n.depthTest,c=n.cullFace,p=n.uniforms,f=n.vertexShaderID,g=n.fragmentShaderID,_=n.vertexShader,m=n.fragmentShader,v=n.texturesOptions,y=n.crossOrigin,x=n.alwaysDraw,b=n.visible,k=n.transparent,R=n.drawCheckMargins,w=n.autoloadSources,P=n.watchScroll,T=n.fov;if(_classCallCheck(this,i),d=!1,w=!1,!(s=t.call(this,e,r,{widthSegments:h,heightSegments:l,renderOrder:u,depthTest:d,cullFace:c,uniforms:p,vertexShaderID:f,fragmentShaderID:g,vertexShader:_,fragmentShader:m,texturesOptions:v,crossOrigin:y,alwaysDraw:x,visible:b,transparent:k,drawCheckMargins:R,autoloadSources:w,watchScroll:P,fov:T})).gl)return _possibleConstructorReturn(s);s.renderer.scene.removePlane(_assertThisInitialized(s)),s.type="PingPongPlane",s.renderer.scene.addPlane(_assertThisInitialized(s)),s.readPass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.writePass=new te(e,{depth:!1,clear:!1,texturesOptions:v}),s.createTexture({sampler:o});var S=0;return s.readPass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.writePass.getTexture().onSourceUploaded((function(){S++,s._checkIfReady(S)})),s.setRenderTarget(s.readPass),s._onRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s.setRenderTarget(s.writePass),s._onPingPongRenderCallback&&s._onPingPongRenderCallback()},s._onAfterRenderCallback=function(){s.readPass&&s.writePass&&s.textures[0]&&s.textures[0]._uploaded&&s._swapPasses(),s._onPingPongAfterRenderCallback&&s._onPingPongAfterRenderCallback()},s}return _createClass(i,[{key:"_checkIfReady",value:function(e){var t=this;2===e&&this.renderer.nextRender.add((function(){t.textures[0].copy(t.target.getTexture())}))}},{key:"_swapPasses",value:function(){var e=this.readPass;this.readPass=this.writePass,this.writePass=e,this.textures[0].copy(this.readPass.getTexture())}},{key:"getTexture",value:function(){return this.textures[0]}},{key:"onRender",value:function(e){return e&&(this._onPingPongRenderCallback=e),this}},{key:"onAfterRender",value:function(e){return e&&(this._onPingPongAfterRenderCallback=e),this}},{key:"remove",value:function(){this.target=null,this.renderer.bindFrameBuffer(null),this.writePass&&(this.writePass.remove(),this.writePass=null),this.readPass&&(this.readPass.remove(),this.readPass=null),_get(_getPrototypeOf(i.prototype),"remove",this).call(this)}}]),i}(ee);e.Curtains=d,e.Geometry=k,e.PingPongPlane=ie,e.Plane=ee,e.RenderTarget=te,e.Texture=E,e.TextureLoader=M,e.Vec2=w,e.Vec3=P,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/src/index.mjs b/src/index.mjs index 0e6a58f..ee45da6 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -6,7 +6,6 @@ export { Geometry } from "./core/Geometry.js"; // frame buffer objects export { RenderTarget } from "./framebuffers/RenderTarget.js"; -export { ShaderPass } from "./framebuffers/ShaderPass.js"; // loader export { TextureLoader } from "./loaders/TextureLoader.js"; @@ -14,10 +13,7 @@ export { TextureLoader } from "./loaders/TextureLoader.js"; // math export { Vec2 } from "./math/Vec2.js"; export { Vec3 } from "./math/Vec3.js"; -export { Mat4 } from "./math/Mat4.js"; -export { Quat } from "./math/Quat.js"; // extras // TODO TextTexture class? export { PingPongPlane } from "./extras/PingPongPlane.js"; -export { FXAAPass } from "./extras/FXAAPass.js";