-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridge.html
More file actions
289 lines (226 loc) · 9.62 KB
/
Bridge.html
File metadata and controls
289 lines (226 loc) · 9.62 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bridge</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="container"></div>
<div class="control">
<label id="label">H_pier</label>
<input id="height_slider" name="timelength" value="5.267" min="0" max="10" type="range" step="0.1">
<label id="value">5.2</label>
</div>
<div>
<a id="download_image">To Image</a>
</div>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<!-- <script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script> -->
<script src="three143.js"></script>
<script src="OrbitControls.js"></script>
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three/addons/": "./jsm/"
}
}
</script>
<script type="module">
let renderer, scene, camera, clock, orbitcontrol,shape_pier, mesh_pier;
const height_slider = document.getElementById("height_slider");
const value_label = document.getElementById( 'value' );
const label = document.getElementById( 'label' );
const container = document.getElementById( 'container' );
const btn_saveimage = document.getElementById("download_image");
init();
animate();
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
clock = new THREE.Clock();
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.set( 30, 30, 30 );
camera.lookAt( scene.position );
camera.updateMatrix();
renderer = new THREE.WebGLRenderer( {
preserveDrawingBuffer: true
} );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
container.appendChild( renderer.domElement );
const x1 = -14.1475, y1 = 0;
const shape_road = new THREE.Shape();
shape_road.moveTo( x1, y1 );
shape_road.lineTo( x1, y1+4.5 );
shape_road.lineTo( x1+28.275, y1+4.5);
shape_road.lineTo( x1+28.275, y1 );
shape_road.lineTo( x1+26.475, y1 );
shape_road.bezierCurveTo( x1+20.475 , y1+8.34 , x1+14.875, y1, x1+14.875, y1 );
shape_road.lineTo(x1+13.4, y1);
shape_road.bezierCurveTo( x1+13.4, y1, x1+7.6, y1+8.34, x1+1.8, y1 );
shape_road.lineTo(x1, y1);
const shape_abutment = new THREE.Shape();
const x2 = -14.1475, y2 = 0, x3 = 14.1475, y3 = 0;
shape_abutment.moveTo( x2, y2 );
shape_abutment.lineTo( x2, y2-2.554 );
shape_abutment.lineTo( x2-0.6, y2-2.554 );
shape_abutment.lineTo( x2-0.6, y2-3.154 );
shape_abutment.lineTo( x2-0.7, y2-3.154 );
shape_abutment.lineTo( x2-0.7, y2-3.254 );
shape_abutment.lineTo( x2+2.997, y2-3.254 );
shape_abutment.lineTo( x2+2.997, y2-3.154 );
shape_abutment.lineTo( x2+ 2.897, y2-3.154 );
shape_abutment.lineTo( x2+ 2.897, y2-2.554 );
shape_abutment.lineTo( x2+2.297, y2-2.554 );
shape_abutment.lineTo( x2+2.17, y2 );
shape_abutment.lineTo( x2, y2 );
const shape_abutment_2 = new THREE.Shape();
shape_abutment_2.moveTo( x3, y3 );
shape_abutment_2.lineTo( x3, y3-2.554 );
shape_abutment_2.lineTo( x3+0.6, y3-2.554 );
shape_abutment_2.lineTo( x3+0.6, y3-3.154 );
shape_abutment_2.lineTo( x3+0.7, y3-3.154 );
shape_abutment_2.lineTo( x3+0.7, y3-3.254 );
shape_abutment_2.lineTo( x3-2.997, y3-3.254 );
shape_abutment_2.lineTo( x3-2.997, y3-3.154 );
shape_abutment_2.lineTo( x3-2.897, y3-3.154 );
shape_abutment_2.lineTo( x3-2.897, y3-2.554 );
shape_abutment_2.lineTo( x3-2.297, y3-2.554 );
shape_abutment_2.lineTo( x3-2.17, y3 );
shape_abutment_2.lineTo( x3, y3 );
shape_pier = new THREE.Shape();
const x4 = 0, y4 = 0;
shape_pier.moveTo( x4, y4 );
shape_pier.lineTo( x4-1.1595, y4 );
shape_pier.lineTo( x4-1.4225, y4-5.267 );
shape_pier.lineTo( x4-2.0225, y4-5.267 );
shape_pier.lineTo( x4-2.0225, y4-5.867 );
shape_pier.lineTo( x4-2.1225, y4-5.867 );
shape_pier.lineTo( x4-2.1225, y4-5.967 );
shape_pier.lineTo( x4+2.1225, y4-5.967 );
shape_pier.lineTo( x4+2.1225, y4-5.867 );
shape_pier.lineTo( x4+2.0225, y4-5.867 );
shape_pier.lineTo( x4+2.0225, y4-5.267 );
shape_pier.lineTo( x4+1.4225, y4-5.267 );
shape_pier.lineTo( x4+1.15595, y4 );
shape_pier.lineTo( x4, y4 );
const extrudeSettings = {
depth: 5,
steps: 10,
// bevelSegments: 1
};
const geometry_road = new THREE.ExtrudeGeometry( shape_road, extrudeSettings );
// const material1 = new THREE.MeshLambertMaterial( { color: 0xb00000, wireframe: false } );
const geometry = new THREE.ShapeGeometry( shape_road );
// const material_road = new THREE.MeshBasicMaterial( { color: 0x808040 } );
const material_road = new THREE.MeshLambertMaterial( { color: 0x666666, emissive: 0x808f80 } );
//material_road.reflectivity = 0.5
// const material_text = new THREE.MeshBasicMaterial({ color: 0x000000, opacity: 0.8, wireframe: true, transparent: true });
const material_text = new THREE.MeshBasicMaterial({ color: 0x000000, opacity: 1, wireframe: false, transparent: true });
const mesh_road = new THREE.Mesh( geometry_road, material_road ) ;
const mesh_road1 = new THREE.Mesh( geometry_road, material_road ) ;
mesh_road.castShadow = true;
mesh_road.recieveShadow = true;
scene.add( mesh_road );
const geometry_abutment = new THREE.ExtrudeGeometry( shape_abutment, extrudeSettings) ;
// const material_abutment = new THREE.MeshBasicMaterial( { color: 0x808080 } );
const material_abutment = new THREE.MeshLambertMaterial( { color: 0x666666, emissive: 0x808080 } );
const mesh_abutment = new THREE.Mesh( geometry_abutment, material_abutment );
mesh_abutment.castShadow = true;
mesh_abutment.recieveShadow = true;
scene.add( mesh_abutment );
const geometry_abutment_2 = new THREE.ExtrudeGeometry( shape_abutment_2, extrudeSettings) ;
const mesh_abutment_2 = new THREE.Mesh( geometry_abutment_2, material_abutment );
mesh_abutment_2.castShadow = true;
mesh_abutment_2.recieveShadow = true;
scene.add( mesh_abutment_2 );
const geometry_pier = new THREE.ExtrudeGeometry( shape_pier, extrudeSettings) ;
const material_pier = new THREE.MeshBasicMaterial( { color: 0x808080 } );
mesh_pier = new THREE.Mesh( geometry_pier, material_abutment );
mesh_pier.castShadow = true;
mesh_pier.recieveShadow = true;
scene.add( mesh_pier );
// const light = new THREE.SpotLight( 0xffffff );
// light.position.set( 30,30,30 );
// scene.add( light );
// scene.add( new THREE.AmbientLight( 0x222222 ) );
const light = new THREE.SpotLight( 0xffffff );
// light.position.copy( camera.position );
light.position.set(30,50,30)
light.intensity = 1;
light.castShadow = true;
console.log(light)
scene.add( light );
orbitcontrol = new THREE.OrbitControls( camera, renderer.domElement );
orbitcontrol.update();
// const dataURL = renderer.domElement.toDataURL();
// var link = document.createElement("a");
// link.href = dataURL;
// link.download = 'Bridge.png';
// link.click();
// console.log(dataURL);
orbitcontrol.addEventListener( 'change', render );
window.addEventListener( 'resize', onWindowResize );
height_slider.addEventListener( "input", heightchange_pier );
btn_saveimage.addEventListener("click", saveImage );
}
function heightchange_pier(){
var height = height_slider.value;
//height = height.toFixed(1);
height = Number(height).toFixed(1);
console.log(typeof(height))
value_label.innerHTML = height;
const x4 = 0, y4 = 0;
scene.remove(mesh_pier)
const shape_pier_modify = new THREE.Shape();
shape_pier_modify.moveTo( x4, y4 );
shape_pier_modify.lineTo( x4-1.1595, y4 );
shape_pier_modify.lineTo( x4-1.4225, y4-height );
shape_pier_modify.lineTo( x4-2.0225, y4-height );
shape_pier_modify.lineTo( x4-2.0225, y4-height-0.6 );
shape_pier_modify.lineTo( x4-2.1225, y4-height-0.6 );
shape_pier_modify.lineTo( x4-2.1225, y4-height-0.7 );
shape_pier_modify.lineTo( x4+2.1225, y4-height-0.7 );
shape_pier_modify.lineTo( x4+2.1225, y4-height-0.6 );
shape_pier_modify.lineTo( x4+2.0225, y4-height-0.6 );
shape_pier_modify.lineTo( x4+2.0225, y4-height );
shape_pier_modify.lineTo( x4+1.4225, y4-height );
shape_pier_modify.lineTo( x4+1.15595, y4 );
shape_pier_modify.lineTo( x4, y4 );
const extrudeSettings = {
depth: 5,
steps: 10,
// bevelSegments: 1
};
const geometry_pier = new THREE.ExtrudeGeometry( shape_pier_modify, extrudeSettings) ;
const material_pier = new THREE.MeshLambertMaterial( { color: 0x666666, emissive: 0x808080 } );
mesh_pier = new THREE.Mesh( geometry_pier, material_pier );
scene.add(mesh_pier);
}
function saveImage(){
const dataURL = renderer.domElement.toDataURL('image/jpeg', 1.0);
btn_saveimage.download = "Bridge.png";
btn_saveimage.href = dataURL;
console.log(renderer)
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
camera.updateMatrixWorld();
renderer.render( scene, camera );
}
</script>
</body>
</html>