npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

three.synergy

v1.1.0

Published

Fast and simple Synergy manager for THREE.js

Downloads

10

Readme

THREE.synergy

NPM Package

Fast and simple interaction manager for THREE.js for enabling mouse and touch events on 3D objects.

Hot it works:

Intersections are sorted by distance to the camera and the events are dispatched in that order (closest first). If InteractiveEvent.stopPropagation() is called, the event won't fire again on other objects.

Alternative to three.interaction. & Alternative to three.interactive.

Usage

  1. Include script:
import { InteractionManager } from "three.Synergy";
  1. Create an InteractionManager instance
const interactionManager = new InteractionManager(
  renderer,
  camera,
  renderer.domElement
);
  1. Add object to InteractionManager
interactionManager.add(cube);
  1. Add event listener to object
cube.addEventListener("click", (event) => {
});
  1. Call InteractionManager.update() on each render
interactionManager.update();

Simple example

import * as THREE from "three";
import { InteractionManager } from "three.synergy";

const container = document.createElement("div");
container.setAttribute("id", "container");
document.body.appendChild(container);

const renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);

const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0.0, 0.0, 10.0);

const interactionManager = new InteractionManager(
  renderer,
  camera,
  renderer.domElement
);

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial();

const cube = new THREE.Mesh(geometry, material);
cube.addEventListener("mouseover", (event) => {
  event.target.material.color.set(0xff0000);
  document.body.style.cursor = "pointer";
});
cube.addEventListener("mouseout", (event) => {
  event.target.material.color.set(0xffffff);
  document.body.style.cursor = "default";
});
cube.addEventListener("mousedown", (event) => {
  event.target.scale.set(1.1, 1.1, 1.1);
});
cube.addEventListener("click", (event) => {
  event.target.scale.set(1.0, 1.0, 1.0);
});
scene.add(cube);
interactionManager.add(cube);

const animate = (time) => {
  requestAnimationFrame(animate);

  interactionManager.update();

  renderer.render(scene, camera);
};

animate();

API

InteractionManager class

new InteractionManager(renderer, camera, renderer.domElement) – constructor InteractionManager instance

Members:

treatTouchEventsAsMouseEvents (boolean) – wether touch events should fire as mouse events, default: true

Methods:

interactionManager.add(object, childNames = []) – add object(s), optionally select only child objects by names

interactionManager.remove(object, childNames = []) – remove object(s)

interactionManager.update() – update InteractionManager on each render

interactionManager.dispose() – dispose InteractionManager

InteractiveEvent class

Members:

cancelBubble (boolean) – wether events should continue to bubble, default: false

coords (THREE.Vector2) – Mouse/touch coords

distance (number) – Distance of intersected point from camera

intersected (boolean) – Whether object is still intersected

originalEvent (Event object) – Original event, if available (mouse, touch)

target (THREE.Object3D) – Target object

type (string) – event type: 'click', 'mousedown', 'mousemove', 'mouseup', 'touchstart', 'touchmove', 'touchend'

Methods:

stopPropagation – stop bubbling of event (cancelBubble), e.g. when only the object closest to the camera is supposed to fire an event

License

MIT Licensed