cables DocumentationHow To UseWorking with filesKeyboard ShortcutsUser Interface WalkthroughBeginner TutorialBeginner 1: Drawing A CircleBeginner 2: TransformationsBeginner 3: ColorMore TransformationsIntermediateImage CompositionsPost-Processing 3D ScenesExporting And EmbeddingHow to serve files externally and fix CORS headersExporting PatchesExport using the cables command line interfaceExport via IframeExport creating a standalone executableExport to github (pages)Export and deploy to netlifyExport full PatchHTML ExportExternal triggers / functionsUsing variablesPreviewing / uploading exported cables patchesExamples for EmbeddingImporting patchesBackupsPermissionsUsersPatchesTeamsOpsMultiplayerPatchlistsCoding OpsUsing Op AttachmentsGeneral op/Port CallbacksPortsMultiPortsArray PortsBoolean portsInteger Number PortsObject PortsString portsTrigger PortsFloating Point Number PortsGUI/UI attributesHello Op - Part 1LibrariesDeveloping OpsRenaming / Creating a new versionCreating Viz OpsGuidelinesObject PortsPatching Ops / SubPatchOpsWriting ShadersWeb Audio Op DevelopmentDeveloping CablesRepositoriesSet up local environmentScriptsHow to work with forksGenerated DocumentationUsing standalone to develop cablesCables StandaloneGeneralCoding OpsSharing opsUsing NPMImport/ExportStandalone - FAQLightingLightsShadowsWorking With AudioBasic Audio SetupWorking with EffectsReal-Time Audio Analyzation & Audio VisualizationOffline Audio Visualization & AnalyzationCommunicationCables APIOptimizing Performance In PatchesTools for debugging your patchHow to optimize cables patches with the Performance opHow to optimize cables patches with the ProfilerCommon pitfalls with the "usual suspects"Optimizing arraysDebugging Shaders with ShaderInfoFAQAudio in web browsersHow to make demoscene demos with cables.glEmbeddingHow to integrate my cables patch into my CMS (webflow/wix/squarespace/...)?How to remove grey rectangles on touch (mobile)?Why doesn't the DownloadTexture op work on iOS?How to disable page scrolling on mobile?Mobile tippsHow to run exported patches on your local machineTransparent CanvasFeatures and SupportHow to contribute code to cablesWill there be support for (animated) GIFs?Can i use a website as a texture?Screenshots and Video recordingHow to report a bug in cablesHow can I share a patch to get help?How can I support cables?Video playback in cablesGeneral questionsWhat is dev.cables.glHTML And CSS In CablesJavascript Frameworkscordova / phonegapelectronreactvuejsLicenses and paymentWhat license do i need to use cables?Will I have to pay for it in the future?How is my work licensed when using cables?Does cables support midi and OSC?Patch PermissionsMy User Profile & Social MediaShadertoyCables at schools and universitiesTechnical questionsWebGL1 and WebGL2

Libraries

How can I use external libraries in cables?

You can add external libraries to your own ops.
These can be either uploaded to cables.gl, or be loaded from an external source (be aware of CORS-Issues).

Add them to the Op via "Manage Op" and then "Add Dependencies". From there you have several options to load a library for your op:

Upload File

This option let's you upload any javascript file to your Op and use it as a library. Any code that is in the file will be loaded by cables and be included in any export. Libraries are loaded before the Op is executed.

Pick a type for your library. If unsure, read on below. You can now use all the new functionality in your Op.

From URL

Pick any library from any source, your own server or a CDN (e.g. jsDelivr or cdnjs) and start using the functionality in your Op.

Pick a type for your library. If unsure, read on below.

This is a great way to quickly test libraries in cables, there are a few caveats though:

  • If the library is no longer available at the given URL, your Op will no longer work.
  • Sometimes you will run into CORS-Issues that might not be fixable by you, if you do not control the "other side".
  • The loading of your patch will now need access to the internet, even in exports.

From Npm (Standalone only)

In the standalone version of cables you can add npm packages via this tab. Simply enter the name of the package (as you would do when running npm install) and cables will try to install and load the npm.

Be aware that the NPM ecosystem is shared between browsers and "backend systems" (nodejs) and some packages cannot be used by cables, at all. Other packages might be architecture dependent and will not work on all operating systems. You will have to consult the documentation of the module to find this kind of information.

Op

Enter a name of any Op to load it's libraries when using your Op. This is useful when you are creating a collection of Ops that all need to load the same library, but you don't want to add it to every individual op.

All libraries are loaded globally and all Ops have access to the global variables provided. This function just makes sure that you do not need a "LoadMyLibraryOp" before using other ops in your collection. These references to ops will fail if/once the op is deleted and they will also not automatically update to a newer version, if available.

Core-Lib

Core-Libs are specific functions of the cables core that went into single modules, small libraries. Since we do not want to load a lot of code that is not needed for every patch, some ops use these libraries to enhance their functionality with features from cables core (lights, shadows and physics are some examples).

Pick any core-lib from the list to give your Op the additional functionality.

Managing dependencies

Once you added a library to an op you can start using it right away. The list of dependencies will show options to delete or download any custom library added.

Library types

By picking the type of the library ("Common JS" or "JS Module") you tell cables how your library needs to be loaded (sadly you need to know this before, cables cannot guess this from the sourcecode).

By picking "Common JS" your library will be loaded via adding <script src="mysuperlib.js"/> to the DOM and letting the browser decide what to do. This will add your library to the global scope then. You will the be able to use that variable of the library in your Op (e.g. handlebars adds Handlebars to the global scope for you to use).

If you pick "JS Module" you will be able to define the name of the imported variable, your library will be loaded by calling import * as YourName from "mysuperlib.js" and you will then be able to use YourName in your Op.

How to best-guess the library type?

  • Check the documentation of the library, especially the examples on how to import the lib
    • if it says something like <script src="mylib.js"> it is most likely "Common JS"
    • if it says something like import MyLib from "mylib.js" you have a "JS Module"
  • Check the sourcecode
    • search for module.exports or require, if this is present you will most likely have a "Common JS" library
    • if you find something like class or export const or export default, you have a "JS Module"
  • Simply try both, you will see errors in the console that might indicate the type of your library
    • export declarations may only appear at top level of a module means you loaded a "JS Module" but have your type as "Common Js"
    • loading a "Common JS" as a "JS Module" might work, but will not have the right contents in your YourLib variable and fail when using it

Found a problem? Edit this file on github and contribute to cables!