2.5.0 • Published 4 months ago

react-stl-viewer v2.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 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
cameraPropsCameraPropsfalsecamera properties, see below
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

CameraProps

PropTypeRequiredNotes
ref{current: CameraRef}falsereference of the camera for accessing it's properties
initialPositionCameraPositionfalseset the position of the camera in geographic coordinates. The origin of coordinates is the object itself

CameraRef

PropTypeRequiredNotes
setCameraPosition(position: CameraPosition) => anytrueimperatively sets the camera position based on the provided geographic coordinates

setCameraPosition:

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"
geometryProps(geometry: BufferGeometry) => BufferGeometryfalsePerform some processing to the models geometry

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

CameraPosition

PropTypeRequiredNotes
latitudenumberfalsecamera'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
longitudenumberfalsecamera's position longitude, it should be a number between - Math.PI and Math.PI, if the number exceeds the limits it will be clamped
distancenumberfalsethe distance factor between the object and the camera. This is a factor relative to the object size or the grid size if it's specified
2.5.0

4 months ago

2.4.1

4 months ago

2.4.0

5 months ago

2.3.2

7 months ago

2.3.1

7 months ago

2.3.0

8 months ago

2.2.5

1 year ago

2.2.1

2 years ago

2.2.0

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.4

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.0.5

2 years ago

2.1.0

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

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