1.0.1 • Published 2 years ago

ddbcn-viewer v1.0.1

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

ddybcn-viewer

React component for visualizing STLs using Three.js.

Install

npm install --save ddybcn-viewer

or

yarn add ddybcn-viewer

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import {StlViewer} from "ddybcn-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'));

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