stlviewer.html

Mon, 03 Apr 2017 19:40:06 +0200

author
mdd
date
Mon, 03 Apr 2017 19:40:06 +0200
changeset 9
a01a3fd32073
parent 8
63b6f80e09ef
child 11
098335a1d510
permissions
-rw-r--r--

precompile STL files with openscad

8
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
1 <!DOCTYPE html>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
2 <html lang="en"><head>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
3 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
4 <title>ScubaTools Object Viewer</title>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
5 <meta charset="utf-8">
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
6 <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
7 <style>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
8 body {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
9 font-family: Monospace;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
10 background-color: #000000;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
11 margin: 0px;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
12 overflow: hidden;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
13 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
14
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
15 #info {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
16 color: #fff;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
17 position: absolute;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
18 top: 10px;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
19 width: 100%;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
20 text-align: center;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
21 z-index: 100;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
22 display:block;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
23
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
24 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
25
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
26 a { color: skyblue }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
27 .button { background:#999; color:#eee; padding:0.2em 0.5em; cursor:pointer }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
28 .highlight { background:orange; color:#fff; }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
29
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
30 span {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
31 display: inline-block;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
32 width: 60px;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
33 float: left;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
34 text-align: center;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
35 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
36
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
37 </style>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
38 </head>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
39 <body>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
40 <div id="info">
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
41 <a href="https://neo-soft.org" target="_blank">NeoSoft</a> ScubaTools -
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
42 <a href="https://threejs.org/" target="_blank">three.js</a> -
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
43 STL loader by <a href="https://github.com/aleeper" target="_blank">aleeper</a>.
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
44 <br/>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
45 Left mouse: rotate camera, right mouse: move camera, middle mouse or wheel: zoom
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
46 </div>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
47
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
48 <script src="https://threejs.org/build/three.js"></script>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
49 <script src="https://threejs.org/examples/js/loaders/STLLoader.js"></script>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
50 <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
51 <script>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
52 var container;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
53 var camera, cameraTarget, scene, renderer;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
54
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
55 init();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
56 animate();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
57
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
58 function init() {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
59 container = document.createElement( 'div' );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
60 document.body.appendChild( container );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
61
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
62 camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 15 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
63 camera.position.set( 3, 0.35, 3 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
64
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
65 cameraTarget = new THREE.Vector3( 0, -0.25, 0 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
66
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
67 scene = new THREE.Scene();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
68 scene.fog = new THREE.Fog( 0x72645b, 2, 15 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
69
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
70 var controls = new THREE.OrbitControls(camera);
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
71
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
72 // Ground
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
73
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
74 var plane = new THREE.Mesh(
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
75 new THREE.PlaneBufferGeometry( 40, 40 ),
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
76 new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
77 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
78 plane.rotation.x = -Math.PI/2;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
79 plane.position.y = -0.5;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
80 scene.add( plane );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
81
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
82 plane.receiveShadow = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
83
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
84 // ASCII file
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
85
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
86 var loader = new THREE.STLLoader();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
87 loader.load( './test.stl', function ( geometry ) {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
88
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
89 var material = new THREE.MeshPhongMaterial( { color: 0xff5533, specular: 0x111111, shininess: 200 } );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
90 var mesh = new THREE.Mesh( geometry, material );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
91
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
92 mesh.position.set( 0, -0.25, 0 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
93 mesh.rotation.set( 0, Math.PI / 2, 0 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
94 mesh.scale.set( 0.01, 0.01, 0.01 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
95
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
96 mesh.castShadow = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
97 //mesh.receiveShadow = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
98
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
99 scene.add( mesh );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
100
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
101 } );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
102
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
103 // Lights
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
104
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
105 scene.add( new THREE.HemisphereLight( 0x443333, 0x111122 ) );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
106
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
107 addShadowedLight( 1, 1, 1, 0xffffff, 1.35 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
108 //addShadowedLight( 0.5, 1, -1, 0xffaa00, 1 );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
109 // renderer
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
110
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
111 renderer = new THREE.WebGLRenderer( { antialias: true } );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
112 renderer.setClearColor( scene.fog.color );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
113 renderer.setPixelRatio( window.devicePixelRatio );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
114 renderer.setSize( window.innerWidth, window.innerHeight );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
115
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
116 renderer.gammaInput = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
117 renderer.gammaOutput = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
118
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
119 renderer.shadowMap.enabled = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
120 renderer.shadowMap.renderReverseSided = false;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
121
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
122 container.appendChild( renderer.domElement );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
123
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
124 window.addEventListener( 'resize', onWindowResize, false );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
125
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
126 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
127
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
128 function addShadowedLight( x, y, z, color, intensity ) {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
129
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
130 var directionalLight = new THREE.DirectionalLight( color, intensity );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
131 directionalLight.position.set( x, y, z );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
132 scene.add( directionalLight );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
133
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
134 directionalLight.castShadow = true;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
135
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
136 var d = 1;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
137 directionalLight.shadow.camera.left = -d;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
138 directionalLight.shadow.camera.right = d;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
139 directionalLight.shadow.camera.top = d;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
140 directionalLight.shadow.camera.bottom = -d;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
141
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
142 directionalLight.shadow.camera.near = 1;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
143 directionalLight.shadow.camera.far = 4;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
144
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
145 directionalLight.shadow.mapSize.width = 1024;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
146 directionalLight.shadow.mapSize.height = 1024;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
147
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
148 directionalLight.shadow.bias = -0.005;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
149
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
150 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
151
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
152 function onWindowResize() {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
153
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
154 camera.aspect = window.innerWidth / window.innerHeight;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
155 camera.updateProjectionMatrix();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
156
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
157 renderer.setSize( window.innerWidth, window.innerHeight );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
158
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
159 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
160
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
161 function animate() {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
162
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
163 requestAnimationFrame( animate );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
164
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
165 //render();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
166 renderer.render( scene, camera );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
167 //stats.update();
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
168
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
169 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
170
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
171 function render() {
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
172 var timer = Date.now() * 0.0005;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
173 camera.position.x = Math.cos( timer ) * 3;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
174 camera.position.z = Math.sin( timer ) * 3;
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
175 camera.lookAt( cameraTarget );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
176 renderer.render( scene, camera );
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
177 }
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
178
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
179 </script><div><canvas style="width: 1589px; height: 711px;" height="711" width="1589"></canvas><div style="position: fixed; top: 0px; left: 0px; cursor: pointer; opacity: 0.9; z-index: 10000;"><canvas style="width: 80px; height: 48px; display: block;" height="48" width="80"></canvas><canvas style="width: 80px; height: 48px; display: none;" height="48" width="80"></canvas></div></div>
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
180
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
181
63b6f80e09ef added threejs stl viewer html testing
mdd
parents:
diff changeset
182 </body></html>

mercurial