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

jscad-fiber

v0.0.76

Published

[View examples](https://tscircuit.github.io/jscad-fiber/) · [jscad](https://github.com/jscad/OpenJSCAD.org) · [tscircuit](https://github.com/tscircuit/tscircuit) · [jscad-electronics](https://github.com/tscircuit/jscad-electronics)

Downloads

5,691

Readme

jscad-fiber

View examples · jscad · tscircuit · jscad-electronics

This package allows you to create 3D CAD objects with React and JSCAD.

Table of Contents

Example CAD Model

Installation

npm install jscad-fiber @jscad/modeling three @react-three/fiber

Usage

Create JSCAD components with React:

import { JsCadView } from "jscad-fiber"
import { Cube, Sphere, Subtract } from "jscad-fiber"

export default () => (
  <JsCadView>
    <Subtract>
      <Cube size={10} />
      <Sphere radius={6.8} />
    </Subtract>
  </JsCadView>
)

Common Props

All components support these common props:

| Prop | Type | Description | |------|------|-------------| | color | string \| [number,number,number] | CSS color string or RGB array | | center | [number,number,number] \| {x,y,z} | Position in 3D space | | offset | [number,number,number] \| {x,y,z} | Alternative to center |

Components

Basic Shapes

Cube

| Prop | Type | Description | |------|------|-------------| | size | number \| [number,number,number] | Single number for all dimensions or [width, height, depth] |

<Cube size={10} /> // Single number for all dimensions
<Cube size={[width, height, depth]} /> // Array for different dimensions

Sphere

| Prop | Type | Description | |------|------|-------------| | radius | number | Sphere radius | | segments | number | Optional detail level (default: 32) |

<Sphere radius={10} segments={32} />

Cylinder

| Prop | Type | Description | |------|------|-------------| | radius | number | Cylinder radius | | height | number | Cylinder height |

<Cylinder radius={5} height={10} />

Torus

| Prop | Type | Description | |------|------|-------------| | innerRadius | number | Inner ring radius | | outerRadius | number | Outer ring radius | | innerSegments | number | Optional inner detail level (default: 32) | | outerSegments | number | Optional outer detail level (default: 32) |

<Torus 
  innerRadius={10}
  outerRadius={15}
  innerSegments={32}
  outerSegments={32}
/>

Boolean Operations

Subtract

| Prop | Type | Description | |------|------|-------------| | children | React.ReactNode[] | First child is base shape, others are subtracted |

<Subtract>
  <Cube size={10} /> {/* Base shape */}
  <Sphere radius={6} /> {/* Subtracted from base */}
</Subtract>

Union

| Prop | Type | Description | |------|------|-------------| | children | React.ReactNode[] | Shapes to combine |

<Union>
  <Cube size={10} />
  <Sphere radius={6} center={[0,0,10]} />
</Union>

Hull

| Prop | Type | Description | |------|------|-------------| | children | React.ReactNode[] | Shapes to create hull from |

<Hull>
  <Cube size={10} />
  <Sphere radius={6} center={[0,0,10]} />
</Hull>

Transformations

Translate

| Prop | Type | Description | |------|------|-------------| | offset | [number,number,number] | Translation in [x,y,z] |

<Translate offset={[x,y,z]}>
  <Cube size={10} />
</Translate>

Rotate

| Prop | Type | Description | |------|------|-------------| | angles | [number,number,number] | Rotation angles in radians [x,y,z] |

<Rotate angles={[x,y,z]}>
  <Cube size={10} />
</Rotate>

Extrusions

ExtrudeLinear

| Prop | Type | Description | |------|------|-------------| | height | number | Extrusion height | | twistAngle | number | Optional twist during extrusion |

<ExtrudeLinear height={10}>
  <Polygon points={[[0,0], [10,0], [5,10]]} />
</ExtrudeLinear>

ExtrudeRotate

| Prop | Type | Description | |------|------|-------------| | angle | number | Rotation angle in radians | | segments | number | Optional number of segments |

<ExtrudeRotate angle={Math.PI * 2}>
  <Polygon points={[[0,0], [10,0], [5,10]]} />
</ExtrudeRotate>

Component Props Reference

| Component | Props | Description | |-----------|-------|-------------| | Cube | size: number \| [number,number,number] | Size in each dimension | | Sphere | radius: number, segments?: number | Radius and detail level | | Cylinder | radius: number, height: number | Basic cylinder dimensions | | Torus | innerRadius: number, outerRadius: number, segments?: number | Ring dimensions | | ExtrudeLinear | height: number, twistAngle?: number | Linear extrusion with optional twist | | ExtrudeRotate | angle: number, segments?: number | Rotational sweep | | Polygon | points: [number,number][] | 2D points array | | Translate | offset: [number,number,number] | 3D translation | | Rotate | angles: [number,number,number] | Rotation angles in radians | | Hull | children: React.ReactNode | Convex hull of children | | Union | children: React.ReactNode | Boolean union of children | | Subtract | children: React.ReactNode | Boolean subtraction |

Why?

Example Circuit

JSCAD allows you to create detailed 3D objects using boolean operations. This is how modern CAD tools create precise 3D models. jscad-fiber is used to create the 3D electronics library for tscircuit called jscad-electronics

Example Wrapper

The library includes an ExampleWrapper component that provides a convenient way to display both the rendered 3D object and its source code: ExampleWrapper

import { ExampleWrapper } from "jscad-fiber"

export default () => (
  <ExampleWrapper fileName={import.meta.url}>
    <JsCadView>
      <Sphere radius={10} color="orange" />
    </JsCadView>
  </ExampleWrapper>
)

This wrapper:

  • Shows the rendered 3D object
  • Provides a "Show Code" button that reveals the source code
  • Automatically syntax highlights the code
  • Makes examples more interactive and educational

Contributing

See the examples directory for more usage examples.

Pull requests welcome! Please check existing issues or create a new one to discuss major changes.