Curtains class

Basic usage

You will have to create a Curtains object first that will handle the scene containing all your planes. It will also create the WebGL context, append the canvas and handle the requestAnimationFrame loop. You just have to pass the HTML element (or its ID) that will wrap the canvas :

// "canvas" is the ID of our HTML container element
const curtains = new Curtains({
container: document.getElementById("canvas") // we could have just pass "canvas" instead
});

There are other options that you can pass as parameters. For example, you can specify whether you want to use the library in production mode:

const curtains = new Curtains({
container: "canvas",
production: true // use the library in "production" mode
});

Parameters

Here is a complete list of all the parameters:

  • container HTML Element or string, optional the HTML Element or ID of the HTML Element that will wrap the canvas. If not specified, the WebGL context will not be set until you call setContainer() with a valid HTML element or ID.
  • alpha bool, optional Whether the WebGL context should handle transparency. Default to true.
  • 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.
  • premultipliedAlpha bool, optional Whether the WebGL context should handle premultiplied alpha. Default to false.
  • depth bool, optional Whether the WebGL context should handle depth. Default to true.
  • preserveDrawingBuffer bool, optional Whether the WebGL context should preserve the drawing buffer. Default to false.
  • failIfMajorPerformanceCaveat bool, optional Whether the WebGL context creation should fail in case of major performance caveat. Default to true.
  • stencil bool, optional Whether the WebGL context should handle stencil. Default to false.
  • 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.
  • 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.
  • 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 (minimum: 0.25, maximum: 1) Use it to downscale your rendering canvas. May improve performance but will decrease quality. Default to 1.
  • 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.
  • production bool, optional Whether the library should throw useful console warnings or not. Default to false.

Properties

  • alpha (bool) v5.0read only

    Whether the WebGL context handles transparency or not.

  • antialias (bool) v6.1read only

    Whether the WebGL context should use antialiasing.

  • canvas (HTML canvas element) v7.0

    The WebGL canvas being created and that contains our scene.

  • container (HTML element) v1.0

    The container that will hold our WebGL canvas. The canvas will be sized according to this container. For performance reason, the smaller your container the better. Most of the time you'll set it to cover the window.

  • depth (bool) v7.0read only

    Whether the WebGL context handles depth or not.

  • failIfMajorPerformanceCaveat (bool) v7.0read only

    Whether the WebGL context creation should fail in case of major performance caveat.

  • gl (WebGL context) v5.0read only

    Our WebGL context.

  • pixelRatio (float) v1.0 read only

    The current device pixel ratio.
    Use the setPixelRatio() method to change this value at runtime.

  • planes (array) v1.0

    An array containing all your current Plane elements.

  • premultipliedAlpha (bool) v5.0 read only

    Whether the WebGL context handles premultiplied alpha or not.

  • preserveDrawingBuffer (bool) v7.0read only

    Whether the WebGL context should preserve the drawing buffer.

  • production (bool) v7.0

    If set to true, will remove all helpful warnings displayed by the library.

  • renderTargets (array) v5.0

    An array containing all your current RenderTarget elements (including the one used by your shader passes).

  • shaderPasses (array) v3.0

    An array containing all your current ShaderPass elements.

  • stencil (bool) v7.0read only

    Whether the WebGL context should handle stencil.

Methods

Events

  • onAfterResize(callback): v3.0

    This function will be called each time the window has been resized, after everything has been updated.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.

  • onContextLost(callback): v2.0

    This function will be called each time the WebGL context has been lost.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.

    Examples: used in all examples.

  • onContextRestored(callback): v2.0

    This function will be called each time the WebGL context has been successfully restored.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.

  • onError(callback): v1.7

    This function will be called if there's an error during the initialisation, or if the WebGL context could not be created.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.

    Examples: used in all examples.

  • onRender(callback): v2.0

    This function is called once at each request animation frame call. Useful if you need to update stats or tweening engine.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.

    Examples: used in Multiple planes, Multiple planes scroll effect : rotation, scale and parallax examples.

  • onScroll(callback): v4.0

    This function is called each time a window scroll event is fired and scroll watching is active.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.

    Examples: used in Multiple planes, Multiple planes scroll effect : rotation, scale and parallax, Post processing displacement effect and Post processing multiple passes examples.

  • onSuccess(callback): v8.1

    This function will be called when the WebGL has been successfully created.

    • callback function function to execute.

    returns: your Curtains object, allowing it to be chainable.