New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@react-three/csg

Package Overview
Dependencies
Maintainers
19
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-three/csg

non gratum anus rodentum

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
849
decreased by-81.83%
Maintainers
19
Weekly downloads
 
Created
Source

Demo Demo

yarn add @react-three/csg

A small, abstraction around https://github.com/gkjohnson/three-bvh-csg. It is not feature complete!

You have 4 operations:

  • Subtraction
  • Addition
  • Difference
  • Intersection

Each can take a <Brush>, which is like a THREE.Mesh, it needs a geometry. A brush must be either slot a or b (first & second operand), which you need to define as a prop.

If you nest operations, the operation itself becomes a brush and must also define a slot.

The outmost operation will yield a buffergeometry, so you can use it in a mesh, an instancedMesh, or whatever needs a goemetry to function.

import { Brush, Subtraction, Addition, Difference, Intersection } from '@react-three/csg'

function Model() {
  return (
    <mesh>
      <Subtraction>
        <Subtraction a>
          <Brush a scale={1.5} position={[0, -1.04, 0]} geometry={nodes.bunny.geometry} />
          <Brush b position={[0.5, -0.75, 1]}>
            <sphereGeometry />
          </Brush>
        </Subtraction>
        <Brush b position={[-1, 1, 1]}>
          <sphereGeometry />
        </Brush>
      </Subtraction>
      <meshNormalMaterial />
    </mesh>
  )
}
Updating the operations

If you update a brush, or an operation, set needsUpdate on it, it will bubble up to its base operation. Keep in mind that although the base CSG implementation is fast, this is something you may want to avoid doing often or runtime, depending on the complexity of your geometry.

function Shape() {
  const brush = useRef()
  useFrame((state, delta) => {
    brush.current.rotation.x += 0.025
    brush.current.needsUpdate = true
  })
  return (
    <mesh>
      <Subtraction castShadow receiveShadow>
        <Brush a rotation={[0, Math.PI / 2, 0]} position={[-0.35, 0.4, 0.4]}>
          <boxGeometry />
        </Brush>
        <Brush b ref={brush} position={[-0.35, 0.4, 0.4]}>
          <boxGeometry />
        </Brush>

Keywords

FAQs

Package last updated on 28 Jul 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc