1.0.6 • Published 12 months ago

react-stl-viewer-improved v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-stl-viewer

React component for visualizing STLs using Three.js.

Install

npm install --save react-stl-viewer

or

yarn add react-stl-viewer

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import {StlViewer} from "react-stl-viewer";

const url = "https://storage.googleapis.com/ucloud-v3/ccab50f18fb14c91ccca300a.stl"

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

function App() {
    return (
        <StlViewer
            style={style}
            orbitControls
            shadows
            url={url}
        />
    );
}

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

Demo

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

Props

PropTypeRequiredNotes
urlstringtrueurl of the Stl file
modelPropsModelPropsfalse3d model properties, see below
floorPropsFloorPropsfalsefloor properties, see below
shadowsbooleanfalserender shadows projected by the model on the ground
showAxesbooleanfalseshow x y z axis
orbitControlsbooleanfalseenable camera orbit controls
extraHeadersRecord<string, string>falsecustom headers for making the http query
onFinishLoading(ev: ModelDimensions) => anyfalsecallback triggered when Stl is fully loaded
onError(err: Error) => anyfalsecallback triggered when an error occurred while loading Stl
canvasIdstringfalseid of the canvas element used for rendering the model

The component also accepts <div/> props

Interfaces

ModelProps

PropTypeRequiredNotes
ref{current: ModelRef}falsereference of the 3d model for accessing it's properties
scalenumberfalsescale of the 3d model, defaults to 1
positionXnumberfalsex coordinate in the world of the 3d model
positionYnumberfalsey coordinate in the world of the 3d model
rotationXnumberfalserotation in x axis of the model
rotationYnumberfalserotation in y axis of the model
rotationYnumberfalserotation in z axis of the model
colorCSSProperties['color']falsecolor of the 3d model, defaults to "grey"

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

ModelDimensions

PropTypeNotes
boundingRadiusnumberthe radius of the bounding sphere of the 3d model before scaling
widthnumberwidth of the 3d object
heightnumberheight of the 3d object
lengthnumberlength of the 3d object
1.0.2

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago