Importing threex.domevents

Hello. I’m using VS code with three.js. I would like to implement a library that has mouse clicks etc. and use it with Three.js. I’ve found threex.domevents to be a good option. I’ve typed npm install threex.domevents and it installed the threex.domevents.js file in the threex.domevents folder in the node_modules folder. However I’m confused how to import the library so it can be used. I’ve tried:
import * as THREEx from ‘threex.domevents/threex.domevents.js’
or
import { threex } from ‘threex.domevents/threex.domevents.js’.
I’ve also tried
let threex = require(‘threex.domevents’).
Can someone please clarify the correct way to import Threex?

Looking at the source code of the project, there is definitely no ES6 module support. The npm page suggest this:

var THREE = require('three') // require peer dependency
var initializeDomEvents = require('threex.domevents')
var THREEx = {}
initializeDomEvents(THREE, THREEx)

However, I would not recommend to use threex.domevents since the project is not maintained anymore. The last commit was six years ago.

I suggest you implement your interaction based on the official three.js examples like webgl_interactive_cubes or the controls classes. All this code is based on the Pointer Events API which is more or less the latest standard for event handling and processing.

1 Like

Thanks for explaining. I appreciate it!