Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
@pmndrs/pointer-events
Advanced tools
framework agnostic pointer-events implementation for three.js
based on 🎯 Designing Pointer-events for 3D & XR
import * as THREE from 'three';
import { forwardHtmlEvents } from '@pmndrs/pointer-events';
const canvas = document.getElementById("canvas")
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 70, width / height, 0.01, 10 );
camera.position.z = 1;
forwardHtmlEvents(canvas, camera, scene)
const width = window.innerWidth, height = window.innerHeight;
const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshBasicMaterial({ color: new THREE.Color("red") });
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
mesh.addEventListener("pointerover", () => material.color.set("blue"))
mesh.addEventListener("pointerout", () => material.color.set("red"))
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( width, height );
renderer.setAnimationLoop(() => renderer.render( scene, camera ));
Based on the css pointer-events
property, the behavior of pointer events can be configured with the values none
, listener
, or auto
.
object.pointerEvents = "none";
The values none
and auto
correspond to the css properties, where none
means that an object is not directly targetted and auto
means the object is always targetted for events. The additional value listener
, which is the default value, expresses that the object is only targetted by events if the object has any listeners. In 3D scenes this default is more reasonable than auto
, which is the default in the web, because 3D scenes often contain semi-transparent content, such as particles, that should not catch pointer events by default.
In addition to the pointerEvents
property, each 3D object can also filter events based on the pointerType
with the pointerEventsType
property. This property defaults to the value all
, which expresses that pointer events from pointers of all types should be accepted. To filter specific pointer types, such as screen-mouse
, which represents a normal mouse used through a 2D screen, pointerEventsType
can be set to { allow: "screen-mouse" }
or { deny: "screen-touch" }
. pointerEventsType
's allow
and deny
accept strings and array of strings. In case more custom logic is needed, pointerEventsType
also accepts a function. In general the pointer types screen-touch
, screen-pen
, ray
, grab
, and touch
are used by default. For pointer events that were forwarded through a portal using forwardObjectEvents
, their pointerType
is prefixed with forward-
, while events forwarded from the dom to the scene are prefixed with screen-
.
Create your own Pointer
that can represent a WebXR controller or something else. These Pointer
can use a normal Ray
for intersection, or a set of Lines
, or even a Sphere
, for grab and touch events.
FAQs
framework agnostic pointer-events implementation for threejs
The npm package @pmndrs/pointer-events receives a total of 1,752 weekly downloads. As such, @pmndrs/pointer-events popularity was classified as popular.
We found that @pmndrs/pointer-events demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.