0.0.168 • Published 10 months ago

@tscircuit/3d-viewer v0.0.168

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

@tscircuit/3d-viewer

!NOTE We are working on a new vanilla THREE version of the 3d viewer, it's on the v01 branch

A 3D printed circuit board viewer for Circuit JSON and tscircuit

npm version License: MIT

Documentation · Website · Twitter · Discord · Quickstart · Online Playground

image

Features

  • 3D visualization of PCB layouts
  • Interactive camera controls (pan, zoom, rotate)
  • Support for various PCB components (resistors, capacitors, Chips, etc.)
  • Customizable board and component rendering

Installation

npm install @tscircuit/3d-viewer

Usage

Basic Example

import React from "react"
import { CadViewer } from "@tscircuit/3d-viewer"

const MyPCBViewer = () => {
  return (
    <CadViewer>
      <board width="20mm" height="20mm">
        <resistor
          name="R1"
          footprint="0805"
          resistance="10k"
          pcbX={5}
          pcbY={5}
        />
        <capacitor
          name="C1"
          footprint="0603"
          capacitance="1uF"
          pcbX={-4}
          pcbY={0}
        />
      </board>
    </CadViewer>
  )
}

export default MyPCBViewer

Using with circuitJson Data

import React from "react"
import { CadViewer } from "@tscircuit/3d-viewer"
import mycircuitJsonData from "./mycircuitJsonpData.json"

const MyPCBViewer = () => {
  return <CadViewer circuitJson={mycircuitJsonData} />
}

export default MyPCBViewer

Converting to SVG (Node.js)

When using the SVG converter in Node.js environments, you'll need to provide JSDOM:

import { JSDOM } from 'jsdom'
import { convert3dCircuitToSvg } from '@tscircuit/3d-viewer/3d'
import { applyJsdomShim } from '@tscircuit/3d-viewer/utils'

// Setup JSDOM environment
const dom = new JSDOM()
applyJsdomShim(dom)

// Convert circuit to SVG
const options = {
  width: 800,
  height: 600,
  backgroundColor: "#ffffff",
  padding: 20,
  zoom: 50,
  camera: {
    position: { x: 0, y: 0, z: 100 },
    lookAt: { x: 0, y: 0, z: 0 }
  }
}

const svgString = await convert3dCircuitToSvg(circuitJson, options)

The convert3dCircuitToSvg function accepts the following options:

  • width: Width of the output SVG (default: 800)
  • height: Height of the output SVG (default: 600)
  • backgroundColor: Background color in hex format (default: "#ffffff")
  • padding: Padding around the board (default: 20)
  • zoom: Zoom level (default: 1.5)
  • camera: Camera position and lookAt configuration
    • position: {x, y, z} coordinates for camera position
    • lookAt: {x, y, z} coordinates for camera target

API Reference

<CadViewer>

Main component for rendering the 3D PCB viewer.

Props:

  • circuit-json: (optional) An array of AnyCircuitElement objects representing the PCB layout.
  • children: (optional) React children elements describing the PCB layout (alternative to using circuit-json).

<board>

Defines the PCB board dimensions.

Props:

  • width: Width of the board (e.g., "20mm").
  • height: Height of the board (e.g., "20mm").

Component Elements

Various component elements can be used as children of the <board> element:

  • <resistor>
  • <capacitor>
  • <chip>
  • <bug> (for ICs)

Each component has specific props for defining its characteristics and position on the board.

Advanced Usage

Custom Component Models

You can define custom 3D models for components using the cadModel prop:

<chip
  name="U1"
  footprint="soic8"
  cadModel={{
    objUrl: "/path/to/custom-model.obj",
    mtlUrl: "/path/to/custom-material.mtl",
  }}
/>

JSCAD Models

For more complex or programmatically defined models, you can use JSCAD:

<bug
  footprint="soic8"
  name="U1"
  cadModel={{
    jscad: {
      type: "cube",
      size: 5,
    },
  }}
/>

Contributing

We welcome contributions! Please see our Contributing Guide for more details.

Related Projects

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.0.168

10 months ago

0.0.164

10 months ago

0.0.163

10 months ago

0.0.162

10 months ago

0.0.167

10 months ago

0.0.166

10 months ago

0.0.165

10 months ago

0.0.159

10 months ago

0.0.158

10 months ago

0.0.153

10 months ago

0.0.157

10 months ago

0.0.156

10 months ago

0.0.155

10 months ago

0.0.154

10 months ago

0.0.161

10 months ago

0.0.160

10 months ago

0.0.152

10 months ago

0.0.151

10 months ago

0.0.150

10 months ago

0.0.149

10 months ago

0.0.148

10 months ago

0.0.147

10 months ago

0.0.146

10 months ago

0.0.145

10 months ago

0.0.144

10 months ago

0.0.139

10 months ago

0.0.138

10 months ago

0.0.137

10 months ago

0.0.136

10 months ago

0.0.131

11 months ago

0.0.130

11 months ago

0.0.135

11 months ago

0.0.134

11 months ago

0.0.133

11 months ago

0.0.132

11 months ago

0.0.142

10 months ago

0.0.141

10 months ago

0.0.140

10 months ago

0.0.143

10 months ago

0.0.106

11 months ago

0.0.105

11 months ago

0.0.109

11 months ago

0.0.108

11 months ago

0.0.107

11 months ago

0.0.117

11 months ago

0.0.116

11 months ago

0.0.115

11 months ago

0.0.114

11 months ago

0.0.119

11 months ago

0.0.118

11 months ago

0.0.113

11 months ago

0.0.112

11 months ago

0.0.111

11 months ago

0.0.110

11 months ago

0.0.128

11 months ago

0.0.127

11 months ago

0.0.126

11 months ago

0.0.125

11 months ago

0.0.129

11 months ago

0.0.120

11 months ago

0.0.124

11 months ago

0.0.123

11 months ago

0.0.122

11 months ago

0.0.121

11 months ago

0.0.104

11 months ago

0.0.103

11 months ago

0.0.102

11 months ago

0.0.101

11 months ago

0.0.100

11 months ago

0.0.95

12 months ago

0.0.96

11 months ago

0.0.97

11 months ago

0.0.98

11 months ago

0.0.99

11 months ago

0.0.94

12 months ago

0.0.85

12 months ago

0.0.86

12 months ago

0.0.87

12 months ago

0.0.88

12 months ago

0.0.89

12 months ago

0.0.90

12 months ago

0.0.91

12 months ago

0.0.92

12 months ago

0.0.93

12 months ago

0.0.84

12 months ago

0.0.80

12 months ago

0.0.81

12 months ago

0.0.82

12 months ago

0.0.83

12 months ago

0.0.75

12 months ago

0.0.76

12 months ago

0.0.77

12 months ago

0.0.78

12 months ago

0.0.79

12 months ago

0.0.73

12 months ago

0.0.74

12 months ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

12 months ago

0.0.67

1 year ago

0.0.68

1 year ago

0.0.69

1 year ago

0.0.62

1 year ago

0.0.63

1 year ago

0.0.64

1 year ago

0.0.65

1 year ago

0.0.66

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.59

1 year ago

0.0.47

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.58

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.40

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.33

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.29

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.16

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago