stl-viewer
Advanced tools
Comparing version 0.10.1 to 0.11.0
@@ -19,2 +19,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -53,5 +55,3 @@ | ||
this.rotationSpeeds = context.props.rotationSpeeds; | ||
this.lightX = context.props.lightX; | ||
this.lightY = context.props.lightY; | ||
this.lightZ = context.props.lightZ; | ||
this.lights = context.props.lights; | ||
this.lightColor = context.props.lightColor; | ||
@@ -75,10 +75,13 @@ | ||
this.distance = 10000; | ||
var directionalLight = new _Three2.default.DirectionalLight(this.lightColor); | ||
directionalLight.position.x = this.lightX; | ||
directionalLight.position.y = this.lightY; | ||
directionalLight.position.z = this.lightZ; | ||
directionalLight.position.normalize(); | ||
directionalLight.name = DIRECTIONAL_LIGHT; | ||
this.scene.add(directionalLight); | ||
// lights processing | ||
var hasMultipleLights = this.lights.reduce(function (acc, item) { | ||
return acc && Array.isArray(item); | ||
}, true); | ||
if (hasMultipleLights) { | ||
this.lights.forEach(this.addLight.bind(this)); | ||
} else { | ||
this.addLight(this.lights); | ||
} | ||
this.reqNumber += 1; | ||
@@ -88,2 +91,15 @@ this.addSTLToScene(this.reqNumber); | ||
}, { | ||
key: 'addLight', | ||
value: function addLight(lights) { | ||
var _directionalLight$pos; | ||
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var directionalLight = new _Three2.default.DirectionalLight(this.lightColor); | ||
(_directionalLight$pos = directionalLight.position).set.apply(_directionalLight$pos, _toConsumableArray(lights)); | ||
directionalLight.name = DIRECTIONAL_LIGHT + index; | ||
directionalLight.position.normalize(); | ||
this.scene.add(directionalLight); | ||
} | ||
}, { | ||
key: 'addSTLToScene', | ||
@@ -90,0 +106,0 @@ value: function addSTLToScene(reqId) { |
@@ -108,5 +108,3 @@ 'use strict'; | ||
cameraZ: _propTypes2.default.number, | ||
lightX: _propTypes2.default.number, | ||
lightY: _propTypes2.default.number, | ||
lightZ: _propTypes2.default.number, | ||
lights: _propTypes2.default.array, | ||
lightColor: _propTypes2.default.string, | ||
@@ -125,5 +123,3 @@ rotationSpeeds: _propTypes2.default.arrayOf(_propTypes2.default.number) | ||
cameraZ: null, | ||
lightX: 0, | ||
lightY: 0, | ||
lightZ: 1, | ||
lights: [0, 0, 1], | ||
lightColor: '#ffffff', | ||
@@ -130,0 +126,0 @@ rotationSpeeds: [0, 0, 0.02] |
{ | ||
"name": "stl-viewer", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "A component for viewing an STL object from a given URL by utilizing Three.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/STLViewer.js", |
@@ -6,19 +6,19 @@ import React, { Component } from 'react'; | ||
constructor(props) { | ||
super(props) | ||
super(props); | ||
this.state = { | ||
color: '#FF0000' | ||
} | ||
}; | ||
this.clickBlue = this.clickBlue.bind(this) | ||
this.clickRed = this.clickRed.bind(this) | ||
this.clickBlue = this.clickBlue.bind(this); | ||
this.clickRed = this.clickRed.bind(this); | ||
} | ||
clickBlue(e) { | ||
e.preventDefault() | ||
this.setState({ color: '#0000FF' }) | ||
e.preventDefault(); | ||
this.setState({ color: '#0000FF' }); | ||
} | ||
clickRed(e) { | ||
e.preventDefault() | ||
this.setState({ color: '#FF0000' }) | ||
e.preventDefault(); | ||
this.setState({ color: '#FF0000' }); | ||
} | ||
@@ -29,9 +29,13 @@ | ||
<div> | ||
<STLViewer url="dist/static/crazy-thing.stl" modelColor={this.state.color}/> | ||
<STLViewer | ||
url="dist/static/crazy-thing.stl" | ||
modelColor={this.state.color} | ||
lights={[[0.5, 1, -1], [1, 1, 1]]} | ||
/> | ||
<button onClick={this.clickRed}>red</button> | ||
<button onClick={this.clickBlue}>blue</button> | ||
</div> | ||
); | ||
); | ||
} | ||
} | ||
}; | ||
export default App; |
@@ -30,5 +30,3 @@ import THREE from './Three'; | ||
this.rotationSpeeds = context.props.rotationSpeeds; | ||
this.lightX = context.props.lightX; | ||
this.lightY = context.props.lightY; | ||
this.lightZ = context.props.lightZ; | ||
this.lights = context.props.lights; | ||
this.lightColor = context.props.lightColor; | ||
@@ -52,10 +50,14 @@ | ||
this.distance = 10000; | ||
let directionalLight = new THREE.DirectionalLight(this.lightColor); | ||
directionalLight.position.x = this.lightX; | ||
directionalLight.position.y = this.lightY; | ||
directionalLight.position.z = this.lightZ; | ||
directionalLight.position.normalize(); | ||
directionalLight.name = DIRECTIONAL_LIGHT; | ||
this.scene.add(directionalLight); | ||
// lights processing | ||
const hasMultipleLights = this.lights.reduce( | ||
(acc, item) => acc && Array.isArray(item), | ||
true | ||
); | ||
if (hasMultipleLights) { | ||
this.lights.forEach(this.addLight.bind(this)); | ||
} else { | ||
this.addLight(this.lights); | ||
} | ||
this.reqNumber += 1; | ||
@@ -65,2 +67,10 @@ this.addSTLToScene(this.reqNumber); | ||
addLight(lights, index = 0) { | ||
const directionalLight = new THREE.DirectionalLight(this.lightColor); | ||
directionalLight.position.set(...lights); | ||
directionalLight.name = DIRECTIONAL_LIGHT + index; | ||
directionalLight.position.normalize(); | ||
this.scene.add(directionalLight); | ||
} | ||
addSTLToScene(reqId) { | ||
@@ -67,0 +77,0 @@ this.loader.crossOrigin = ''; |
@@ -19,5 +19,3 @@ import React, { Component } from 'react'; | ||
cameraZ: PropTypes.number, | ||
lightX: PropTypes.number, | ||
lightY: PropTypes.number, | ||
lightZ: PropTypes.number, | ||
lights: PropTypes.array, | ||
lightColor: PropTypes.string, | ||
@@ -37,5 +35,3 @@ rotationSpeeds: PropTypes.arrayOf(PropTypes.number) | ||
cameraZ: null, | ||
lightX: 0, | ||
lightY: 0, | ||
lightZ: 1, | ||
lights: [0, 0, 1], | ||
lightColor: '#ffffff', | ||
@@ -42,0 +38,0 @@ rotationSpeeds: [0, 0, 0.02] |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
5731853
3612