BBC's guide to development
  • General

    • About
    • Tools
    • Git(hub)
    • Showpad
    • Hosting
    • Maintenance
    • Security
    • Go live checklist
  • Front-end development

    • Bundlers
    • CSS/SCSS
    • Javascript
    • Vue
    • PHP
    • Mails
    • Dev Faq
  • Functions
  • Mixins
  • General

    • OOP Structure
  • Component Classes

    • Accordion
    • App
    • Component
    • HighwayApp
    • Popup
    • PNG Sequencer
    • Tab
  • Manager Classes

    • BountListenerMgr
    • Cache
    • Configuration
    • InViewStateMgr
    • Instance Manager
    • Event dispatcher
  • Factories

    • SwiperFactory
  • PDF

    • AssetLoader
    • BasePdfDoc
    • TemplatePdfDoc
    • CustomPdfDoc
  • Utility functions

    • canvas
    • Connection Status
    • css
    • dev
    • placeholder
    • dom
    • fetch
    • json
    • object
    • scroll
    • scrollbar
    • spreadsheets
    • string
    • url
  • General

    • ComponentMgr
    • ThreeJsViewer
  • Components

    • ComponentMgr
    • GltfModel
    • Snappable
    • Socket
    • ThreeJsViewer
    • ThreeJsViewerCamera
  • Loaders

    • ConfigurationSerializer
    • GltfBlockParser
  • Utils

    • CanvasInputAdapter
    • CollisionManager
    • SocketGridExpander
    • blender
    • headless
  • General

    • Troubleshooting
    • Legacy
  • Components

    • AssetBar
    • ConfigGenerator
    • ShowpadApp
  • Managers

    • Assets
    • AppsDb
    • Config
  • Utils

    • Connection Status
    • general
    • showpad-interactive
    • showpad-upload
  • Components

    • Accordion
    • BackButton
    • Breadcrumb
    • ByltButton
    • Hamburger
    • Icon
    • Logo
    • Loader
    • Modal
    • Popup
    • Prompt
    • ProgressBar
    • TextLoader
  • Composables

    • useDebugMode
    • useConnectionStatus
  • Utils

    • dom
    • props
  • General

    • General
    • Tracking
  • Components

    • Accordion
    • ActionButton
    • AssetItem
    • AssetList
    • BackButton
    • ConfigGenButton
    • Logo
    • Media
    • Modal
    • Popup
    • Prompt
    • SPButton
    • SPRouterView
    • SPTrackedRouterLink
    • TextLoader
    • View
  • Composables

    • useConnectionStatus
  • Stores

    • useAppsDbStore
    • useBreadcrumbStore
    • useShowpadAPIStore
    • useShowpadSDKStore
    • useSpConfigStore
    • useSpStore
    • useSpTrackingStore
  • The New Kit

    • General
    • Installation & Usage
    • ACF Blocks
    • PHPCS
    • Functions
    • Vite
    • WP Config
    • Staging Deployment
  • Best Practices

    • Page Structure
    • Fonts/Typography
  • Todo
GitHub
  • General

    • About
    • Tools
    • Git(hub)
    • Showpad
    • Hosting
    • Maintenance
    • Security
    • Go live checklist
  • Front-end development

    • Bundlers
    • CSS/SCSS
    • Javascript
    • Vue
    • PHP
    • Mails
    • Dev Faq
  • Functions
  • Mixins
  • General

    • OOP Structure
  • Component Classes

    • Accordion
    • App
    • Component
    • HighwayApp
    • Popup
    • PNG Sequencer
    • Tab
  • Manager Classes

    • BountListenerMgr
    • Cache
    • Configuration
    • InViewStateMgr
    • Instance Manager
    • Event dispatcher
  • Factories

    • SwiperFactory
  • PDF

    • AssetLoader
    • BasePdfDoc
    • TemplatePdfDoc
    • CustomPdfDoc
  • Utility functions

    • canvas
    • Connection Status
    • css
    • dev
    • placeholder
    • dom
    • fetch
    • json
    • object
    • scroll
    • scrollbar
    • spreadsheets
    • string
    • url
  • General

    • ComponentMgr
    • ThreeJsViewer
  • Components

    • ComponentMgr
    • GltfModel
    • Snappable
    • Socket
    • ThreeJsViewer
    • ThreeJsViewerCamera
  • Loaders

    • ConfigurationSerializer
    • GltfBlockParser
  • Utils

    • CanvasInputAdapter
    • CollisionManager
    • SocketGridExpander
    • blender
    • headless
  • General

    • Troubleshooting
    • Legacy
  • Components

    • AssetBar
    • ConfigGenerator
    • ShowpadApp
  • Managers

    • Assets
    • AppsDb
    • Config
  • Utils

    • Connection Status
    • general
    • showpad-interactive
    • showpad-upload
  • Components

    • Accordion
    • BackButton
    • Breadcrumb
    • ByltButton
    • Hamburger
    • Icon
    • Logo
    • Loader
    • Modal
    • Popup
    • Prompt
    • ProgressBar
    • TextLoader
  • Composables

    • useDebugMode
    • useConnectionStatus
  • Utils

    • dom
    • props
  • General

    • General
    • Tracking
  • Components

    • Accordion
    • ActionButton
    • AssetItem
    • AssetList
    • BackButton
    • ConfigGenButton
    • Logo
    • Media
    • Modal
    • Popup
    • Prompt
    • SPButton
    • SPRouterView
    • SPTrackedRouterLink
    • TextLoader
    • View
  • Composables

    • useConnectionStatus
  • Stores

    • useAppsDbStore
    • useBreadcrumbStore
    • useShowpadAPIStore
    • useShowpadSDKStore
    • useSpConfigStore
    • useSpStore
    • useSpTrackingStore
  • The New Kit

    • General
    • Installation & Usage
    • ACF Blocks
    • PHPCS
    • Functions
    • Vite
    • WP Config
    • Staging Deployment
  • Best Practices

    • Page Structure
    • Fonts/Typography
  • Todo
GitHub
  • CanvasInputAdapter

CanvasInputAdapter

Bridges DOM canvas pointer events (pointermove, pointerdown, pointerup) to ComponentMgr's headless pointer methods, so both mouse and touch work. Converts screen pixel coordinates to Normalised Device Coordinates (NDC) before forwarding.

Pointer down is registered with capture so that block-drag detection runs before other listeners (e.g. camera or orbit controls).

Warning

Meant to be used with ComponentMgr only.

Getting started

const inputAdapter = new CanvasInputAdapter({
  $el: renderer.domElement,
  componentMgr,
});

// Later, when tearing down:
inputAdapter.dispose();

Disabling Camera Controls During Block Drag

Optional: pass onBlockDragStart and onBlockDragEnd to disable camera controls during block drag so the user can move a placed block without rotating the view:

const inputAdapter = new CanvasInputAdapter({
  $el: renderer.domElement,
  componentMgr,
  onBlockDragStart: () => { orbitControls.enabled = false; },
  onBlockDragEnd: () => { orbitControls.enabled = true; },
});

NDC Conversion Formula

Screen coordinates are converted to NDC using the canvas's bounding rect:

x=clientX−rect.leftrect.width×2−1x = \frac{clientX - rect.left}{rect.width} \times 2 - 1 x=rect.widthclientX−rect.left​×2−1

y=−clientY−rect.toprect.height×2+1y = -\frac{clientY - rect.top}{rect.height} \times 2 + 1 y=−rect.heightclientY−rect.top​×2+1

E=mc2E = mc^2E=mc2

x = ((clientX - rect.left) / rect.width)  * 2 - 1
y = -((clientY - rect.top)  / rect.height) * 2 + 1

NDC range: X ∈ [-1, 1] (left to right), Y ∈ [-1, 1] (bottom to top, Y-flipped from CSS).

When NOT to Use CanvasInputAdapter

CanvasInputAdapter is a convenience wrapper. Do not use it if:

  • You are handling touch events or custom pointer events
  • You are embedding the canvas inside a framework component that manages events
  • You need fine-grained control over which events trigger snapping (e.g. right-click drag to pan)

In these cases, call ComponentMgr's pointer methods directly:

// On pointermove
componentMgr.updatePointer(ndcX, ndcY);

// On pointerdown
componentMgr.onPointerDown(ndcX, ndcY, event.clientX, event.clientY);

// On pointerup
componentMgr.onPointerUp(ndcX, ndcY, event.clientX, event.clientY);

Where ndcX and ndcY are computed using the formula above (or your equivalent for the coordinate space you are working in).

API

Constructor (args = {})

The constructor method initialises the new CanvasInputAdapter instance

It immediately attaches pointermove, pointerdown (with capture), and pointerup listeners to $el. It uses setPointerCapture / releasePointerCapture so that move and up events are delivered to the canvas during touch drag.

Parameters

  • $el: The canvas element to listen on
  • componentMgr: The ComponentMgr instance to forward events to
  • onBlockDragStart: Optional. Called when a block drag has started (pointer down on selected block). Use e.g. to disable camera/orbit controls.
  • onBlockDragEnd: Optional. Called when a block drag has ended (pointer up after drag). Use e.g. to re-enable camera controls.

Methods

dispose()

Removes all pointer event listeners from $el and nulls internal references. Call when the canvas is unmounted or the configurator is torn down.

Edit this page
Last Updated: 4/27/26, 12:56 PM
Contributors: Nicolas Jaenen