2.2.4 • Published 2 years ago

react-gcode-viewer v2.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-gcode-viewer

React component for visualizing GCodes using Three.js.

Install

npm install --save react-gcode-viewer

or

yarn add react-gcode-viewer

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import {GCodeViewer} from "react-gcode-viewer";

const url = "https://storage.googleapis.com/ucloud-v3/6127a7f9aa32f718b8c1ab4f.gcode"

const style = {
    top: 0,
    left: 0,
    width: '100vw',
    height: '100vh',
}

function App() {
    return (
        <GCodeViewer
            orbitControls
            showAxes
            style={style}
            url={url}
        />
    );
}

ReactDOM.render(<App />, document.getElementById('root'));

Demos

You can see working the examples from .storybook/stories here

Props

PropTypeRequiredNotes
urlstringtrueurl of the GCode file
qualitynumberfalse(default 1) number between 0 and 1 specifying the render quality, for larger models it's recommended to lower this number, as it consumes a lot of resources
visiblenumberfalse(default 1) number between 0 and 1 specifying the percentage of visible layers
layerColorstringfalse(default "grey") layer color
topLayerColorstringfalse(default "hotpink") top layer color
showAxesbooleanfalseshow x y z axis
orbitControlsbooleanfalseenable camera orbit controls
cameraInitialPositionCameraInitialPositionfalseset the initial position of the camera in geographic coordinates. The coordinates origin is the object itself
floorPropsFloorPropsfalsefloor properties, see below
reqOptionsRequestInitfalsefetch options for customizing the http query made for retrieving the GCode file, only valid if "url" is specified
onProgress(p: GCodeParseProgress) => anyfalsecallback triggered on parsing progress
onFinishLoading(p: GCodeParseProgress) => anyfalsecallback triggered when GCode is fully loaded
onError(err: Error) => anyfalsecallback triggered when an error occurred while loading GCode
canvasIdstringfalseid of the canvas element used for rendering the model

The component also accepts <div/> props

Interfaces

FloorProps

PropTypeRequiredNotes
gridWidthnumberfalseif specified, a grid will be drawn in the floor with this width
gridLengthnumberfalseif specified, a grid will be drawn in the floor with this length

GCodeParseProgress

PropTypeNotes
readnumbernumber of bytes read from the url
baseCenter{x: number, y: number}x, y center of the rendered gcode model
max{x: number, y: number, z: number}maximum coordinates of the gcode model
min{x: number, y: number, z: number}minimum coordinates of the gcode model
filamentLengthnumberlength of the filament used in mm

CameraInitialPosition

PropTypeRequiredNotes
latitudenumbertruecamera's position latitude, it should be a number between - Math.PI / 2 and Math.PI / 2, if the number exceeds the limits it will be clamped
longitudenumbertruecamera's position longitude, it should be a number between - Math.PI and Math.PI, if the number exceeds the limits it will be clamped
distancenumbertruethe distance between the object and the camera
2.2.1

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.4

2 years ago

2.0.15

2 years ago

2.0.3

2 years ago

2.2.0

2 years ago

2.0.16

2 years ago

2.0.2

2 years ago

2.0.13

2 years ago

2.0.5

2 years ago

2.0.14

2 years ago

2.0.4

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.12

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.1.0

2 years ago

2.0.18

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago