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

@react-vertex/scene-helpers

v3.0.0

Published

Scene helpers for React Vertex

Downloads

8

Readme

@react-vertex/scene-helpers

license npm version bundlephobia

Documentation and Examples

This package contains some tools to help make React Vertex development easier. These tools are meant for development only and are not intended for use in a production application.

Install via npm:
npm install @react-vertex/scene-helpers
Importing:
import {
  useValueSlider,
  useColorPicker,
  useSelectControl,
  AxesHelper,
  useAxesHelperProgram,
  useAxesHelperGeometry,
  useAxesHelperElements,
} from '@react-vertex/scene-helpers'

useValueSlider(label, value, min, max, step) => number

React hook to create a value slider in a React Vertex component tree. You can use this hook anywhere in the component tree and it will be added to the list of controls in the upper right of the screen. The order of controls across different parts of the tree is determined by render order and is not customizable.

Arguments:

label: String label for the slider.

value: Number for the initial value of the slider.

min: Number for the min value of the slider.

max: Number for the max value of the slider.

step: Number for step value of the slider.

Return Values:

number: The value of the slider. This updates as the slider is moved.

Example Usage:
import React, { memo, useMemo } from 'react'
import { useVector3 } from '@react-vertex/math-hooks'
import { useBoxElements } from '@react-vertex/geometry-hooks'
import { useValueSlider } from '@react-vertex/scene-helpers'

function Example() {
  const boxElements = useBoxElements(10, 10, 10)

  const scaleX = useValueSlider('Geometry Scale X:', 1, 1, 5, 0.1)
  const scaleY = useValueSlider('Geometry Scale Y:', 1, 1, 5, 0.1)
  const scaleZ = useValueSlider('Geometry Scale Z:', 1, 1, 5, 0.1)

  const scale = useVector3(scaleX, scaleY, scaleZ)

  return (
    <geometry scale={scale} {..boxElements} />
  )
}

useColorPicker(label, hexColor, noAlpha?) => array

React hook to create a color picker in a React Vertex component tree. You can use this hook anywhere in the component tree and it will be added to the list of controls in the upper right of the screen. The order of controls across different parts of the tree is determined by render order and is not customizable.

Arguments:

label: String label for the picker.

hexColor: String hex color for initial color.

noAlpha: Boolean for whether the alpha value should be in the returned array (defaults to false).

Return Values:

array: Array of values between 0 and 1. Array is 4 elements by default and 3 elements if no alpha is set to true.

Example Usage:
import React from 'react'
import { useCanvasSize } from '@react-vertex/core'
import { useOrbitCamera, useOrbitControls } from '@react-vertex/orbit-camera'
import { useBasicSolid } from '@react-vertex/material-hooks'
import { useColorPicker } from '@react-vertex/scene-helpers'

function Example() {
  const { width, height } = useCanvasSize()

  const camera = useOrbitCamera(55, width / height, 1, 5000, c => {
    c.setPosition([0, 0, 25])
  })
  useOrbitControls(camera)

  const diffuse = useColorPicker('Wireframe Color: ', '#A9E6E3', true)
  const program = useBasicSolid(diffuse)

  return (
    <camera view={camera.view} projection={camera.projection}>
      <material program={program}>
        ...
      </material>
    </camera>
  )
}

useSelectControl(label, options) => value

React hook to create a select control in a React Vertex component tree. You can use this hook anywhere in the component tree and it will be added to the list of controls in the upper right of the screen. The order of controls across different parts of the tree is determined by render order and is not customizable.

Arguments:

label: String label for the slider.

options: An array of { label, value } objects. The hook will not update when this argument changes so you can provide the options inline.

Return Values:

value: The selected value. The first item in the array will be returned on the initial render.

Example Usage:
import React from 'react'
import { useCanvasSize } from '@react-vertex/core'
import { useOrbitCamera, useOrbitControls } from '@react-vertex/orbit-camera'
import { useBasicSolid } from '@react-vertex/material-hooks'
import { useColorPicker } from '@react-vertex/scene-helpers'

function Example() {

  const showWireframe  = useSelectControl('Show Wireframe?', [
    { value: true, label: 'True' },
    { value: false, label: 'False' },
  ])

  const Material = useSelectControl('Material: ', [
    { value: PhongTextured, label: 'Phong Textured' },
    { value: PhongSolid, label: 'Phong Solid' },
  ])
  ...

AxesHelper

React Vertex component that renders x, y and z axes.

Props:

size (optional): Number for the length of the axes (defaults to 100).

Example Usage:
import React from 'react'
import { useOrbitCamera, useOrbitControls } from '@react-vertex/orbit-camera'
import { useCanvasSize } from '@react-vertex/core'
import { AxesHelper } from '@react-vertex/scene-helpers'

function Scene({ showAxes }) {
  const { width, height } = useCanvasSize()

  const camera = useOrbitCamera(55, width / height, 1, 5000, c => {
    c.setPosition([0, 0, 30])
  })
  useOrbitControls(camera)

  return (
    <camera view={camera.view} projection={camera.projection}>
      <AxesHelper size={10} />
    </camera>
  )
}

useAxesHelperProgram() => WebGLProgram

React hook for working with Axes Helper program.

Arguments:
  • None.
Return Values:

program: A WebGL program that can be applied to axes helper geometry.

useAxesHelperGeometry(size?) => object

useAxesHelperElements(size?) => object

React hooks for working with Axes Helper.

Arguments:

size: Number for the length of the axes (defaults to 100).

Return Values:

useAxesHelperGeometry => { colors, positions }

useAxesHelperElements => { index, count, attributes, drawElements }