-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpx121.html
223 lines (169 loc) · 6.89 KB
/
px121.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
<!-- @MrEranwe @EliasHasle -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Ship visualization with specification</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery Version 1.11.1 -->
<script src="js/libs/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/libs/bootstrap.min.js"></script>
<!-- D3JavaScript -->
<script src="js/libs/d3_v4.9.1.js"></script>
<!-- Three script -->
<script src="js/libs/three.js"></script>
<script src="js/libs/STLLoader.js"></script>
<script src='js/libs/OrbitControls.js'></script>
<!--Import library-->
<script src="Vessel.js"></script>
<!-- Prettyprinting of JSON data -->
<script type="text/javascript" src="js/libs/renderjson.js"></script>
<!--Ship3D class for three.js-->
<script src="js/Ship3D.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/js/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/js/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse">
<div class="container">
<!-- Add the <div>[Something]</div> structure for each header in the navbar-->
<div class="navbar-header">
<a class="navbar-brand" href="https://github.com/shiplab/vesseljs">Github project page</a>
</div>
<!-- This is for the right part of the navbar. Reserved for Shiplab logo-->
<div class="nav navbar-nav navbar-right">
<div class="navbar-header">
<a class="navbar-brand" href="http://www.shiplab.hials.org/"><img src="images/barquinho.png" alt="Shiplab logo" style="height:150%">
</a>
</div>
</div>
</div>
</nav>
<!-- Container creates the space -->
<div class="container">
<!-- Row creates horizontal groups of columns -->
<div class="row">
<!-- choose horizontal layout in https://www.w3schools.com/bootstrap/bootstrap_grid_examples.asp-->
<!-- No divisions in page. Only 1 column. -->
<div class="col-md-12 text-center">
<h2>Ship as object</h2>
</div>
<div class="col-md-12 text-center">
<!-- Link the GitHub page if you have one. Add a pdf of how the project works if necessary. Just put it inside the same folder and call it how_to.pdf -->
<!--<h1>Ship as Object</h1>-->
<p>This app asks for a JSON file
and gives back the pretty form of the JSON element. It also plots a 3D image of the ship. Sample data is loaded at startup.</p>
<p>Developed by: Elias Hasle, Vicente Alejandro Iváñez Encinas and Henrique M. Gaspar. Visualization made using three.js.</p>
</div>
<div class="col-md-12 text-left">
<h2>Input</h2>
<input type="file" id="file-input" />
<h3>Contents of the file:</h3>
<pre id="file-content"></pre>
<br>
</div>
<div class="col-md-12 text-left">
<h2>3D orbit view of hull and parts</h2>
</div>
<div id="3d" class="col-md-12 text-left" style="min-height: 80vh">
</div>
</div>
</div>
<script>
"use strict";
// Create scene+
var renderer, scene, camera, controls, ship3D;
//Ready renderer and scene
(function (){
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setClearColor(0xA9CCE3, 1);
// get the div that will hold the renderer
var container = document.getElementById('3d');
//renderer.setSize(container.clientWidth, container.clientHeight);
// add the renderer to the div
container.appendChild(renderer.domElement);
scene = new THREE.Scene();
//Camera and controls:
camera = new THREE.PerspectiveCamera(50);
camera.up.set(0,0,1);
scene.add(camera);
controls = new THREE.OrbitControls(camera, renderer.domElement);
//Respond to window resize:
function onResize() {
renderer.setSize(container.clientWidth, container.clientHeight);
camera.aspect = container.clientWidth / container.clientHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", onResize);
onResize(); //Ensure the initial setup is good too
//Add lights:
scene.add(new THREE.AmbientLight(0xffffff,0.3));
scene.add(function() {
let sun = new THREE.DirectionalLight(0xffffff,1);
sun.position.set(1,1,1);
return sun;
}());
})();
// read file from user
function readSingleFile(e){
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
//call common function for user files and server files
useFileData(contents);
}
reader.readAsText(file);
}
//Load sample file:
new THREE.FileLoader().load("px121.json", useFileData);
function useFileData(contents) {
var shipspec = JSON.parse(contents);
displayContents(shipspec);
var ship = new Vessel.Ship(shipspec);
if (ship3D !== undefined) {
scene.remove(ship3D);
}
ship3D = new Ship3D(ship, "stl/");
scene.add(ship3D);
let LOA = ship.structure.hull.attributes.LOA;
camera.position.set(0.7*LOA, 0.7*LOA, 0.7*LOA);
controls.target = new THREE.Vector3(LOA/2,0,0);
controls.update();
animate();
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
// display pretty JSON
function displayContents(jsonData) {
let fileCont = document.getElementById("file-content");
fileCont.innerHTML = "";
fileCont.appendChild(
renderjson(jsonData)
);
}
// Catch file browse
document.getElementById('file-input')
.addEventListener('change', readSingleFile, false)
</script>
<!-- /.container -->
<!-- Insert own scripts here -->
</body>
</html>