-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWireframeGenerator.html
245 lines (171 loc) · 7.13 KB
/
WireframeGenerator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - STL</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="lib/three.min.js"></script>
<script src="lib/loaders/STLLoader.js"></script>
<script src="lib/Detector.js"></script>
<script script src="lib/libs/stats.min.js"></script>
<script src="WireframeGenerator.js"></script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, cameraTarget, scene, renderer;
var lastLoadedGeometry = null;
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 15 );
camera.position.set( 3, 0.15, 3 );
cameraTarget = new THREE.Vector3( 0, -0.25, 0 );
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x72645b, 2, 15 );
// Ground
var plane = new THREE.Mesh( new THREE.PlaneGeometry( 40, 40 ), new THREE.MeshPhongMaterial( { ambient: 0x999999, color: 0x999999, specular: 0x101010 } ) );
plane.rotation.x = -Math.PI/2;
plane.position.y = -0.5;
scene.add( plane );
plane.receiveShadow = true;
// ASCII file
var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function ( event ) {
var geometry = event.content;
lastLoadedGeometry = geometry;
var material;
//material = new THREE.MeshPhongMaterial( { ambient: 0xff5533, color: 0xff5533, specular: 0x111111, shininess: 200 } );
//material = new THREE.LineBasicMaterial({linewidth:0.1, color:0x00FF00, vertexColors:true});
material = new THREE.MeshBasicMaterial( { color: 0x00ee00, wireframe: true, transparent: true } );
/*
var cubeMaterial1 = new THREE.MeshBasicMaterial( { color: 0xccccdd, side: THREE.DoubleSide, depthTest: true, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } );
var dashMaterial = new THREE.LineDashedMaterial( { color: 0xff0000, dashSize: 2, gapSize: 3, depthTest: false, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 } );
var cubeMaterial3 = new THREE.MeshBasicMaterial( { color: 0x000000, depthTest: true, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1, wireframe: true } );
mesh = new THREE.Mesh( geometry.clone(), cubeMaterial1 );
mesh.scale.set( 0.5, 0.5, 0.5 );
scene.add(mesh);
mesh = new THREE.Line( geo2line(geometry.clone()), dashMaterial, THREE.LinePieces );
mesh.scale.set( 0.5, 0.5, 0.5 );
scene.add(mesh);
mesh = new THREE.Mesh( geometry.clone(), cubeMaterial3 );
mesh.scale.set( 0.5, 0.5, 0.5 );
scene.add(mesh);
*/
var mesh = new THREE.Mesh( geometry, material );
mesh.scale.set( 0.5, 0.5, 0.5 );
mesh.scale.set( 0.5, 0.5, 0.5 );
mesh.scale.set( 0.01, 0.01, 0.01 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
var s = CreatePolyOutlineSCAD(lastLoadedGeometry);
document.getElementById('dump').innerHTML = s;
} );
var stlFile;
stlFile = "./models/convextest2.stl";
//stlFile = "./models/platonic/tetrahedron_4er.stl";
//stlFile = "./models/platonic/umj_02_octahedron.stl";
//stlFile = "./models/diamondnormalsfixed.stl";
//stlFile = "./models/invader.stl";
//stlFile = "./models/platonic/tetrahedron_4er.stl";
//stlFile = "./models/platonic/icosahedron_20er.stl";
loader.load(stlFile);
//loader.load( './models/stl/ascii/slotted_disk.stl' );
//loader.load( './models/stl/cube1mm.stl' );
//loader.load( './models/stl/simple.stl' );
//loader.load("./models/platonic/dodecahedron_12er_5er.stl");
//loader.load("./models/platonic/icosahedron_20er.stl");
//loader.load("./models/platonic/tetrahedron_4er.stl");
//loader.load("./models/triatest.stl");
//loader.load("./models/convextest2.stl");
// Lights
scene.add( new THREE.AmbientLight( 0x777777 ) );
addShadowedLight( 1, 1, 1, 0xffffff, 1.35 );
addShadowedLight( 0.5, 1, -1, 0xffaa00, 1 );
// renderer
renderer = new THREE.WebGLRenderer( { antialias: true, alpha: false } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( scene.fog.color, 1 );
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.physicallyBasedShading = true;
renderer.shadowMapEnabled = true;
renderer.shadowMapCullFace = THREE.CullFaceBack;
container.appendChild( renderer.domElement );
///*
// stats
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
//container.appendChild( stats.domElement );
//*/
//
window.addEventListener( 'resize', onWindowResize, false );
}
function addShadowedLight( x, y, z, color, intensity ) {
var directionalLight = new THREE.DirectionalLight( color, intensity );
directionalLight.position.set( x, y, z )
scene.add( directionalLight );
directionalLight.castShadow = true;
// directionalLight.shadowCameraVisible = true;
var d = 1;
directionalLight.shadowCameraLeft = -d;
directionalLight.shadowCameraRight = d;
directionalLight.shadowCameraTop = d;
directionalLight.shadowCameraBottom = -d;
directionalLight.shadowCameraNear = 1;
directionalLight.shadowCameraFar = 4;
directionalLight.shadowMapWidth = 1024;
directionalLight.shadowMapHeight = 1024;
directionalLight.shadowBias = -0.005;
directionalLight.shadowDarkness = 0.15;
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var timer = Date.now() * 0.0005;
camera.position.x = Math.cos( timer ) * (3+Math.cos( timer /3));
camera.position.z = Math.sin( timer ) * (3+Math.cos( timer /3));
camera.position.x = Math.cos( timer ) * 3;
camera.position.z = Math.sin( timer ) * 3;
camera.lookAt( cameraTarget );
renderer.render( scene, camera );
}
function handleGenerateClick()
{
if (lastLoadedGeometry != null)
{
var s = CreatePolyOutlineSCAD(lastLoadedGeometry);
document.getElementById('dump').innerHTML = s;
//copyToClipboard(s);
}
}
</script>
<style>
body {
font-family: Monospace;
}
</style>
</head>
<body onload="init();animate();">
<div id="info">
/* based on <a href="http://threejs.org" target="_blank">three.js</a> -
STL loader test by <a href="https://github.com/aleeper">aleeper</a>. PR2 head from <a href="http://www.ros.org/wiki/pr2_description">www.ros.org */</a>
</div>
<div>
<form name="controls" action="">
<input type="button" value="Generate Polygon Outline!" onclick="handleGenerateClick();">
<input type="file" value="inputFile" id="inputFile" />
</form>
</div>
<div id="dump">SCAD gets dumped here</div>
</body>
</html>