-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex_plyLoader.html
235 lines (203 loc) · 7.71 KB
/
index_plyLoader.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
<!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">
<link type="text/css" rel="stylesheet" href="css/main.css">
<style>
body {
color: #000;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #fff;
margin: 0px;
overflow: hidden;
height: 100%;
}
#menu {
position: relative;
color:#000;
width: 100%;
padding: 5px;
}
#info {
position: absolute;
width: 500px;
right: 0px;
top: 40px;
color:#000;
padding: 5px;
opacity: 0.9;
}
#container {
width: 100%;
height: 800px;
}
.measurement_info {
border: 1px solid #aaa;
padding: 5px;
margin 5px;
}
.measurement_description {
overflow: auto;
width: 450px;
padding: 2px;
}
</style>
</head>
<body>
<div id="header">
3DView.Measurements control sample
</div>
<div id="menu">
<button id="distancebutton">Measure Distance</button>
<button id="infobutton">Point Info</button>
<button id="clearbutton">Clear</button>
</div>
<div id="info"></div>
<div id="container"></div>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "./js/dependencies/three.module.js"
}
}
</script>
<script src="js/dependencies/ui.js"></script>
<script type="module">
import * as THREE from 'three';
import {
PerspectiveCamera,
WebGLRenderer,
sRGBEncoding,
HemisphereLight
} from 'three';
import {OrbitControls} from './js/dependencies/OrbitControls.js';
import {TrackballControls} from './js/dependencies/TrackballControls.js';
import {STLLoader} from './js/dependencies/STLLoader.js';
import {PLYLoader} from './js/dependencies/PLYLoader.js';
import {View3D} from './js/3DView/3DView.Measurements.js';
import {MeasurementInfo} from './js/3DView/measurements/Measurement.Info.js';
import {MeasurementDistance} from './js/3DView/measurements/Measurement.Distance.js';
let container, stats, camera, scene, renderer, controls;
container = document.createElement('div');
document.body.appendChild(container);
camera = new PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 15);
camera.position.set(3, 0.15, 3);
// renderer
renderer = new WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = sRGBEncoding;
renderer.shadowMap.enabled = true;
container.appendChild(renderer.domElement);
//you can use the type of controls you want TrackballControls,OrbitControls...
const control = new OrbitControls(camera, renderer.domElement);
control.enableDamping = true;
control.dampingFactor = 0.25;
control.enableZoom = true;
// const control = new TrackballControls( camera, renderer.domElement );
// control.rotateSpeed = 10.0;
// control.zoomSpeed = 3.0;
// control.panSpeed = 0.8;
// control.noZoom = false;
// control.noPan = false;
// control.staticMoving = true;
// control.dynamicDampingFactor = 0.3;
// control.keys = [ 65, 83, 68 ];
var view = new View3D(document.getElementById( 'container' ), renderer, control,camera);
var loader = new PLYLoader();
loader.load(
"./models/dolphins.ply",
function(geometry) {
geometry.computeVertexNormals();
var material = new THREE.MeshStandardMaterial({
color: 0x0055ff,
flatShading: true
});
var mesh = new THREE.Mesh(geometry, material);
mesh.position.y = -0.7;
mesh.position.z = 0.3;
mesh.rotation.x = -Math.PI / 2;
mesh.scale.multiplyScalar(0.01);
view.scene.add( mesh );
}
);
//Lights
view.scene.add(new HemisphereLight(0x443333, 0x111122));
addShadowedLight(1, 1, 1, 0xffffff, 1.35);
addShadowedLight(0.5, 1, -1, 0xffaa00, 1);
var element=document.getElementById("infobutton");
var listener=element.addEventListener('click',function(event){
view.addMeasurement(new MeasurementInfo());
});
var element=document.getElementById("clearbutton");
var listener=element.addEventListener('click',function(event){
view.clearMeasurements();
});
var element=document.getElementById("distancebutton");
var listener=element.addEventListener('click',function(event){
view.addMeasurement(new MeasurementDistance());
});
//on measurement added
view.addEventListener( 'measurementAdded', function (event) {
var measurement = event.object;
if (measurement) {
var infoDiv = document.getElementById( 'info' );
var measurementDiv = document.createElement('div');
measurementDiv.id = 'measurement_' + measurement.id;
measurementDiv.className = 'measurement_info';
infoDiv.appendChild(measurementDiv);
var descriptionDiv = document.createElement('div');
descriptionDiv.id = 'description_' + measurement.id;
descriptionDiv.className = 'measurement_description';
descriptionDiv.innerHTML = measurement.getType() + " = " + measurement.getValue() + " " + JSON.stringify(measurement.getInfo());
measurementDiv.appendChild(descriptionDiv);
var removeButton = document.createElement('button');
removeButton.className = 'measurement_remove';
removeButton.innerHTML = 'Remove';
removeButton.onclick = function() {
view.removeMeasurement(measurement);
}
measurementDiv.appendChild(removeButton);
}
} );
//on measurement changed
view.addEventListener( 'measurementChanged', function (event) {
var measurement = event.object;
if (measurement) {
var descriptionDiv = document.getElementById('description_' + measurement.id);
if (descriptionDiv)
descriptionDiv.innerHTML = measurement.getType() + " = " + measurement.getValue() + " " + JSON.stringify(measurement.getInfo());
}
} );
//on measurement removed
view.addEventListener( 'measurementRemoved', function (event) {
var measurement = event.object;
if (measurement) {
var measurementDiv = document.getElementById('measurement_' + measurement.id);
measurementDiv.parentNode.removeChild(measurementDiv);
}
} );
function addShadowedLight(x, y, z, color, intensity) {
const directionalLight = new THREE.DirectionalLight(color, intensity);
directionalLight.position.set(x, y, z);
view.scene.add(directionalLight);
directionalLight.castShadow = true;
const d = 1;
directionalLight.shadow.camera.left = -d;
directionalLight.shadow.camera.right = d;
directionalLight.shadow.camera.top = d;
directionalLight.shadow.camera.bottom = -d;
directionalLight.shadow.camera.near = 1;
directionalLight.shadow.camera.far = 4;
directionalLight.shadow.bias = -0.002;
}
</script>
</body>
</html>