|
@@ -114,24 +114,29 @@
|
|
|
function round(value){
|
|
|
return Math.round(value * 100) / 100;
|
|
|
}
|
|
|
+
|
|
|
+ var stlMesh = undefined;
|
|
|
function init() {
|
|
|
|
|
|
container = document.createElement( 'div' );
|
|
|
document.body.appendChild( container );
|
|
|
|
|
|
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 1500 );
|
|
|
- camera.position.set( 0, 0, 30 );
|
|
|
- cameraTarget = new THREE.Vector3( 0, 0, 0 );
|
|
|
+ camera.position.set( 0, 30, 30 );
|
|
|
+ //cameraTarget = new THREE.Vector3( 0, 0, 0 );
|
|
|
|
|
|
+
|
|
|
scene = new THREE.Scene();
|
|
|
scene.background = new THREE.Color( 0xf7f7f7 );
|
|
|
//scene.fog = new THREE.Fog( 0xc9c9c9, 2, 15 );
|
|
|
|
|
|
var loader = new THREE.STLLoader();
|
|
|
+
|
|
|
loader.load( filename, function ( geometry ) {
|
|
|
|
|
|
var material = new THREE.MeshPhongMaterial( { color: 0x70721e, specular: 0x0c0c0c, shininess: 100 } );
|
|
|
var mesh = new THREE.Mesh( geometry, material );
|
|
|
+ stlMesh = mesh;
|
|
|
const center = new THREE.Vector3();
|
|
|
|
|
|
//Scsale it down to original's 10%
|
|
@@ -141,12 +146,14 @@
|
|
|
//Move the mesh to scene center
|
|
|
console.log(bbox);
|
|
|
mesh.updateMatrixWorld();
|
|
|
- console.log(-1 * (bbox.max.x + bbox.min.x));
|
|
|
- mesh.position.set(-1 * (bbox.max.x + bbox.min.x) / 2, -1 * (bbox.max.y + bbox.min.y) / 2, -1 * (bbox.max.z + bbox.min.z) / 2);
|
|
|
+ console.log((bbox.max.x - bbox.min.x));
|
|
|
+ mesh.rotateOnAxis(new THREE.Vector3( 1, 0, 0 ), -1.57079633);
|
|
|
+ //mesh.position.set(-1 * (bbox.max.x + bbox.min.x) / 2, -1 * (bbox.max.y + bbox.min.y) / 2, -1 * (bbox.max.z + bbox.min.z) / 2);
|
|
|
+ mesh.geometry.center()
|
|
|
+
|
|
|
mesh.updateMatrixWorld();
|
|
|
console.log("Setting mesh world position: ", mesh.getWorldPosition())
|
|
|
- mesh.rotation.set( 0, 0, 0);
|
|
|
-
|
|
|
+ //mesh.rotation.set( 0, 0, 0);
|
|
|
render();
|
|
|
|
|
|
var box = new THREE.Box3().setFromObject(mesh);
|
|
@@ -160,6 +167,9 @@
|
|
|
mesh.castShadow = true;
|
|
|
mesh.receiveShadow = true;
|
|
|
scene.add( mesh );
|
|
|
+
|
|
|
+ controls.target = mesh.getWorldPosition();
|
|
|
+
|
|
|
} );
|
|
|
|
|
|
|
|
@@ -167,8 +177,8 @@
|
|
|
scene.add( new THREE.HemisphereLight( 0x898989, 0x3f3f3f ) );
|
|
|
addShadowedLight( 1, 1, 1, 0x898989, 1.35 );
|
|
|
addShadowedLight( 0.5, 1, - 1, 0xcccccc, 1 );
|
|
|
- // renderer
|
|
|
|
|
|
+ //Create renderer
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
@@ -184,6 +194,7 @@
|
|
|
controls = new THREE.OrbitControls( camera, renderer.domElement );
|
|
|
controls.minDistance = 3;
|
|
|
controls.maxDistance = 100;
|
|
|
+ controls.update();
|
|
|
}
|
|
|
|
|
|
function addShadowedLight( x, y, z, color, intensity ) {
|
|
@@ -220,9 +231,7 @@
|
|
|
}
|
|
|
|
|
|
function animate() {
|
|
|
-
|
|
|
requestAnimationFrame( animate );
|
|
|
-
|
|
|
render();
|
|
|
|
|
|
}
|
|
@@ -234,7 +243,8 @@
|
|
|
//camera.position.x = Math.cos( timer ) * 3;
|
|
|
//camera.position.z = Math.sin( timer ) * 3;
|
|
|
|
|
|
- camera.lookAt( cameraTarget );
|
|
|
+ //camera.lookAt( cameraTarget );
|
|
|
+ controls.update();
|
|
|
renderer.render( scene, camera );
|
|
|
|
|
|
}
|