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

threedgizmo

v0.6.0

Published

A React component for integrating a 3D Gizmo control with Three.js scenes, supporting both `OrbitControls` and `MapControls`. It's a "clone" of "Fusion 360" gizmo control in the sense of using the same approach with active corners, edges and faces for bet

Downloads

3,024

Readme

ThreeDGizmo

A React component for integrating a 3D Gizmo control with Three.js scenes, supporting both OrbitControls and MapControls. It's a "clone" of "Fusion 360" gizmo control in the sense of using the same approach with active corners, edges and faces for better navigation. This control will align the camera with the appropriate "direction" vector by click at the active area. The "direction" vector is a vector from the center of the cube to the center of the active area.

ThreeDGizmo Preview

Table of Contents

Installation

You can install the package via npm:

npm install threedgizmo three react react-dom

Or with yarn:

yarn add threedgizmo three react react-dom

Note: This library has peer dependencies on three, react, and react-dom. Ensure they are installed in your project.

Features

  • Integrates a 3D Gizmo control into your Three.js scene.
  • Supports both OrbitControls and MapControls.
  • Synchronizes the Gizmo with your main camera and controls.
  • Written in TypeScript for type safety and IntelliSense support.

Usage

Basic Setup

Here's a basic example of how to use the Gizmo component in your React application.

import React, { useRef, useCallback } from 'react';
import * as THREE from 'three';
import { MapControls } from 'three/examples/jsm/controls/MapControls';
import Gizmo from 'threedgizmo';

const ThreeDViewer = () => {
  const mountRef = useRef(null);
  const rendererRef = useRef(null);
  const cameraRef = useRef(null);
  const sceneRef = useRef(null);
  const controlsRef = useRef(null);

  const renderScene = useCallback(() => {
    if (rendererRef.current && sceneRef.current && cameraRef.current) {
      rendererRef.current.render(sceneRef.current, cameraRef.current);
    }
  }, []);

  React.useEffect(() => {
    if (!mountRef.current) return;

    // Initialize renderer
    rendererRef.current = new THREE.WebGLRenderer({ antialias: true });
    rendererRef.current.setSize(window.innerWidth, window.innerHeight);
    mountRef.current.appendChild(rendererRef.current.domElement);

    // Initialize scene
    sceneRef.current = new THREE.Scene();

    // Initialize camera
    cameraRef.current = new THREE.PerspectiveCamera(
      75,
      window.innerWidth / window.innerHeight,
      0.1,
      1000
    );
    cameraRef.current.position.z = 5;

    // Initialize controls
    controlsRef.current = new MapControls(
      cameraRef.current,
      rendererRef.current.domElement
    );
    controlsRef.current.update();

    // Render loop
    const animate = () => {
      requestAnimationFrame(animate);
      controlsRef.current.update();
      renderScene();
    };
    animate();

    // Cleanup on unmount
    return () => {
      if (rendererRef.current) {
        rendererRef.current.dispose();
      }
    };
  }, [renderScene]);

  return (
    <>
      <Gizmo
        camera={cameraRef.current}
        controls={controlsRef.current}
        render={renderScene}
      />
      <div ref={mountRef} />
    </>
  );
};

export default ThreeDViewer;

Using with MapControls

The Gizmo component supports MapControls out of the box. Ensure you import and use MapControls when initializing your controls.

import { MapControls } from 'three/examples/jsm/controls/MapControls';

// ... inside your component initialization
controlsRef.current = new MapControls(
  cameraRef.current,
  rendererRef.current.domElement
);

API

Gizmo Props

| Prop | Type | Description | |------|------|-------------| | camera | THREE.Camera \| null | The main camera of your scene. | | controls | MapControls \| OrbitControls \| null | The controls used in your scene (MapControls or OrbitControls). | | render | () => void | A function that triggers the rendering of your main scene. | | className | string | Optional CSS class for styling the Gizmo container. |

Examples

You can find a working example in the examples directory of the repository.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

To set up the project locally:

  1. Clone the repository:
git clone https://github.com/LEMing/ThreeDGizmo.git
  1. Install dependencies:
cd ThreeDGizmo
npm install
  1. Run the development server:
npm run dev

License

This project is licensed under the MIT License.