forked from johnhckuo/3D_Modeling_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewThree.html
More file actions
306 lines (228 loc) · 7.67 KB
/
newThree.html
File metadata and controls
306 lines (228 loc) · 7.67 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<html>
<head>
<title>My first Three.js app</title>
<style>
canvas {
width: 100%; height: 100%
}
#div1{
position:absolute;
}
#attribute{
position:absolute;
top:10px;
left:10px;
color:#ffffff;
font-size:20;
font-family:Times New Roman;
position:absolute;
margin-top:20px;
margin-left:20px;
border-style:dashed;
padding-top:15px;
padding-bottom:15px;
padding-right:15px;
padding-left:15px;
}
#loading{
position:absolute;
-webkit-transition: all 1s;
width:100%;
height:100%;
display:none;
}
#img1{
position:relative;
left:-15px;
top:50%;
width:100%;
height:200px;
margin-top:-100px;
}
</style>
</head>
<body>
<script src="js/drag.js"></script>
<script src="js/THREEx.GeometryUtils.js"></script>
<script src="js/ThreeText.js"></script>
<script src="js/three.js"></script>
<script src="js/csg.js"></script>
<script src="js/ThreeCSG.js"></script>
<script src="js/TrackballControls.js"></script>
<script src="js/drag.js"></script>
<script src="js/Stats.js"></script>
<script src="fonts/helvetiker_bold.typeface.js"></script>
<script src="fonts/helvetiker_regular.typeface.js"></script>
<script src="fonts/optimer_bold.typeface.js"></script>
<script src="fonts/optimer_regular.typeface.js"></script>
<script src="fonts/gentilis_bold.typeface.js"></script>
<script src="fonts/gentilis_regular.typeface.js"></script>
<script src="js/FileSaver.js"></script>
<script src="js/axes.js"></script>
<script src="js/STLcreator.js"></script>
<script src="js/customize.js"></script>
<script src="js/STLLoader.js"></script>
<script src="js/STLreader.js"></script>
<div id='div1'>
<div id='loading'>
<img id="img1" src='img/loading.png' />
</div>
<div id = "attribute">
<h1> 3D Text Attribute</h1>
Text:<input type='text' id='custom' onKeyPress="customize('text')" onKeyUp="customize('text')" value='Hello'/><p>
Size:<input type='text' id='textSize' onKeyPress="customize('size')" onKeyUp="customize('size')" value='50' /><p>
Thickness:<input type='text' id='textHeight' onKeyPress="customize('height')" onKeyUp="customize('height')" value='50'/><p>
Font-Family:<form name='myfont'>
<input type="radio" name='font' onclick="customize('font');" value='gentilis' />Gentilis
<input type="radio" name='font' onclick="customize('font');" value='helvetiker' checked />Helvetiker
<input type="radio" name='font' onclick="customize('font');" value='optimer' />Optimer
</form><p>
Model Creator:<br />
<input type='button' value='Cube' onclick='cubeCreator();'/>
<input type='button' value='Circle' onclick='sphereCreator();'/><p>
<input type='button' value='Cylinder' onclick='cylinder();'/><p>
RingText:<input type='text' id='ringText'/><p>
<input type='button' value='Ring Creator' onclick='ringCreator();'/><p>
<input type='button' value='STL' onclick='save();'/><p>
<input type='button' value='Paint' onclick='reStart();'/><p>
</div>
</div>
<script>
// standard global variables
var container, scene,sceneCube, camera, plane, renderer, controls , textMesh, textColor=0xdddddd,custom="Hello", textSize=50,textHeight=30 ,textFont='helvetiker';
var currentObject;
function $(id){
return document.getElementById(id);
}
function init() {
// SCENE
scene = new THREE.Scene();
// CAMERA
var VIEW_ANGLE = 45, ASPECT = window.innerWidth/window.innerHeight, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
scene.add(camera);
camera.position.set(0,0,500);
// camera.lookAt(scene.position);
renderer = new THREE.WebGLRenderer( {antialias:true, alpha: true } );
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor( 0x000000, 1 );
container = document.getElementById( 'div1' );
container.appendChild( renderer.domElement );
// CONTROLS
controls = new THREE.TrackballControls( camera, renderer.domElement );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.2;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = false;
controls.dynamicDampingFactor = 0.3;
controls.minDistance = 0.1;
controls.maxDistance = 20000;
controls.keys = [ 16, 17, 18 ]; // [ rotateKey, zoomKey, panKey ]
//stat
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.right = '0px';
stats.domElement.style.top = '0px';
container.appendChild(stats.domElement);
// LIGHT
var light = new THREE.PointLight(0xffffff,2);
light.position.set(0,500,500);
scene.add(light);
// add 3D text default
var material = new THREE.MeshPhongMaterial({
color: textColor,
shininess: 30,
specular: 0x555555
});
var textGeom = new THREE.TextGeometry( custom, {
font: textFont,
size: textSize,
height: textHeight,
curveSegments: 10,
bend:true
});
textMesh = new THREE.Mesh( textGeom, material );
textGeom.computeBoundingBox();
var textWidth = textGeom.boundingBox.max.x - textGeom.boundingBox.min.x;
//textMesh[i].rotation.x=Math.PI*1.5;
textMesh.position.set( 0, 0,-100 );
currentObject = textMesh;
scene.add( textMesh );
// THREE.GeometryUtils.merge(geometryMerge, textMesh[0]); // --------------------STL converter modified
//fog
scene.fog = new THREE.Fog(0xffffff,100,20000);
//skybox
/*var imagePrefix = "img/";
var imageSuffix = ".jpg";
var skyGeometry = new THREE.BoxGeometry( 5000, 5000, 5000 );
var materialArray = [];
for (var i = 0; i < 6; i++)
materialArray.push( new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture( imagePrefix + 'back' + imageSuffix ),
side: THREE.BackSide
}));
var skyBox = new THREE.Mesh( skyGeometry, materialArray );
scene.add( skyBox );*/
//================================
var geometry = new THREE.CubeGeometry( 1000, 1000, 1000 );
var texture = THREE.ImageUtils.loadTexture( "img/back.jpg" );
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 10, 10 );
var material = new THREE.MeshBasicMaterial( {
color: 0xffffff,
map: texture,
side: THREE.BackSide
} );
var mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
//axes
// axes = buildAxes( 2500 );
// scene.add(axes);
// EventListener
// renderer.domElement.addEventListener( 'mousemove', onDocumentMouseMove, false );
// renderer.domElement.addEventListener( 'mousedown', onDocumentMouseDown, false );
// renderer.domElement.addEventListener( 'mouseup', onDocumentMouseUp, false );
// renderer.domElement.addEventListener('dblclick', lockDown , false);
window.addEventListener( 'resize', onWindowResize, false );
}
function loading(flag){
// background.style.opacity = 0;
var div = document.getElementById("loading");
if (flag == 1){
div.style.display='inline';
}else if (flag == 0 ){
div.style.display='none';
}
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function save() {
loading(1);
var stl = startExport();
var blob = new Blob([stl], {type: 'text/plain'});
saveAs(blob, 'test.stl');
}
function startExport(){
exportGeo = removeDuplicateFaces( geometryMerge );
//THREE.GeometryUtils.triangulateQuads( geometryMerge );
var stl = generateSTL();
if (convertFlag)
loading(0);
return stl;
}
function animate() {
window.requestAnimationFrame( animate );
stats.update();
controls.update(); //for cameras
renderer.render( scene, camera );
}
init();
animate();
</script>
</body>
</html>