-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiPos.html
282 lines (238 loc) · 7.92 KB
/
multiPos.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
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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" http-equiv="content-type" content="text/html" charset="UTF-8" />
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico">
<!--OL6-->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/css/ol.css" type="text/css">
<!--jQuery-->
<link rel="stylesheet" type="text/css" href="../TR3-pack/jquery/jquery-ui-1.12.1.css">
<link rel="stylesheet" type="text/css" href="../TR3-pack/jquery/miniColors/jquery.minicolors.css">
<!--OWN-->
<style>
body,
html {
margin: 0;
padding: 0;
}
.map {
height: 600px;
width: 600px;
float: left;
}
.TR3 {
height: 600px;
width: 600px;
float: left;
}
.tools {
font: 0.7em verdana;
}
</style>
<!--jQuery-->
<script type="text/javascript" src="../TR3-pack/jquery/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="../TR3-pack/jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="../TR3-pack/jquery/miniColors/jquery.minicolors.min.js"></script>
<!--OL6-->
<script type="text/javascript"
src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/build/ol.js"></script>
<!--TR3-->
<script type="text/javascript" src="../TR3-pack/TR3.min.js"></script>
<script type='text/javascript' src='../TR3-pack/TWEEN/tween.min.js'></script>
<script type='text/javascript' src='../TR3-pack/AMMO/ammo.js'></script>
<!--proj4-->
<script type="text/javascript" src="../TR3-pack/proj4js/proj4.js"></script>
<title>TR3 - Multiposition example</title>
</head>
<body style="display:table">
<h1>TR3 - Multipos</h1>
<p>Función para cargar una serie de objetos idénticos clonándolos por el mapa.</p>
<p><strong>GitHub</strong> <a target="blank" href="https://github.com/terre3/TR3-examples/blob/main/multiPos.html">https://github.com/terre3/TR3-examples/blob/main/multiPos.html</a></p>
<div id="map" class="map"></div>
<div id="TR3" class="TR3"></div>
<div id="tools" class="tools"></div>
<div id="progress" style="display:none"></div>
<script type="module">
import * as THREE from '../TR3-pack/THREE/build/three.module.js';
import { OrbitControls } from '../TR3-pack/THREE/controls/OrbitControls.js';
import { TransformControls } from '../TR3-pack/THREE/controls/TransformControls.js';
import { clone } from '../TR3-pack/THREE/utils/SkeletonUtils.js';
import { GLTFExporter } from '../TR3-pack/THREE/exporters/GLTFExporter.js';
import { GLTFLoader } from '../TR3-pack/THREE/loaders/GLTFLoader.js';
import { IFCLoader } from '../TR3-pack/THREE/loaders/IFCLoader.js';
import { FontLoader } from '../TR3-pack/THREE/loaders/FontLoader.js';
import { TextGeometry } from '../TR3-pack/THREE/geometries/TextGeometry.js';
import { Sky } from '../TR3-pack/THREE/objects/Sky.js';
var threeTR3 = new Array();
threeTR3.THREE = THREE;
threeTR3.OrbitControls = OrbitControls;
threeTR3.TransformControls = TransformControls;
threeTR3.SkeletonUtilsClone = clone;
threeTR3.GLTFExporter = GLTFExporter;
threeTR3.GLTFLoader = GLTFLoader;
threeTR3.IFCLoader = IFCLoader;
threeTR3.FontLoader = FontLoader;
threeTR3.TextGeometry = TextGeometry;
threeTR3.Sky = Sky;
const osmLayer = new ol.layer.Tile({
source: new ol.source.OSM({ crossOrigin: 'anonymous' })
})
const map = new ol.Map({
target: 'map',
layers: [
osmLayer
],
view: new ol.View({
center: [-630404, 5395748],
zoom: 17
})
});
TR3.setLoader('../TR3-pack/', threeTR3);
document.getElementById('tools').innerHTML = TR3.setPanel();
TR3.setOpts({ imgControl: false, autoRotate: true });
$("#tools").dialog({ position: { my: "right top", at: "right top", of: window }, width: 215 });
function setTR3() {
const bbox = map.getView().calculateExtent(map.getSize());
const code = map.getView().getProjection().getCode();
const desty = document.getElementById('TR3');
const oriAux = document.getElementsByTagName('CANVAS');
const ori = oriAux[0];
const TR3pms = {
oriImg: ori,
desty: desty,
bbox: bbox,
projCode: code
};
TR3.setStart(TR3pms).then(function () {
TR3.setLookAtini(70, 20);
});
const OBJ1pms = {
src: "obj3d/tree.glb", // Ruta al elemento 3D
pos: [ [-630404, 5395748, false],[-630161.857,5395866.173,false],[-630598.508,5395991.250,false],[-630366.868,5395747.871,false],
[-630213.286,5395725.259,false],[-630544.337,5395788.275,false],[-630501.772,5395834.672,false],[-630575.240,5395910.555,false]], // Ubicación, con Z false, se coloca sobre el terreno
animation: true, // Permite ejecutar animación
scale: [[10, 10, 10],[10, 10, 10],[10, 10, 10],[10, 10, 10][10, 10, 10],[10, 10, 10],[10, 10, 10],[10, 10, 10]], // Escalar elemento 3D
slctItem: [true,true,true,true,true,true,true,true], // Elemento interactivo
aRotate: false, // En true el elemento 3D rota entorno al eje Z, si es un número gira un tramo en radianes
transform: false, // Asigna manejador 3D al elemento 3D transformcontrols
isPixSize: false, // Los valores de escala son medidas en tamaño pixel
persist2Scene: false // El elemento 3D permanece siempre en la escena
};
TR3.loadFile(OBJ1pms).then(function (obj) {
for(let i=0;i<obj.length;i++){
TR3.scene.add(obj[i].scene);
TR3.transCtrlsEnabled(obj[i].scene);
}
});
TR3.map.addEventListener("TR3-onIntersectEvClick",
function (req) {
console.log(req);
var det = req.detail;
if (det.intersect[0]) {
var obj = det.intersect[0].object.scene || det.intersect[0].object;
while (!obj.TR3) {
obj = obj.parent;
}
TR3.transCtrlsEnabled(obj);
}
}
);
TR3.map.addEventListener("TR3-onIntersectEvOver",
function (req) {
console.log(req);
}
);
}
setTimeout(function () {
map.on('moveend', setTR3);
}, 500);
// https://openlayers.org/en/latest/examples/tile-load-events.html
/**
* Renders a progress bar.
* @param {HTMLElement} el The target element.
* @constructor
*/
function Progress(el) {
this.el = el;
this.loading = 0;
this.loaded = 0;
}
/**
* Increment the count of loading tiles.
*/
Progress.prototype.addLoading = function () {
if (this.loading === 0) {
this.show();
}
++this.loading;
this.update();
};
/**
* Increment the count of loaded tiles.
*/
Progress.prototype.addLoaded = function () {
const this_ = this;
setTimeout(function () {
++this_.loaded;
this_.update();
}, 100);
};
/**
* Update the progress bar.
*/
Progress.prototype.update = function () {
const width = ((this.loaded / this.loading) * 100).toFixed(1) + '%';
this.el.style.width = width;
if (this.loading === this.loaded) {
this.loading = 0;
this.loaded = 0;
const this_ = this;
setTimeout(function () {
this_.hide();
}, 500);
}
};
/**
* Show the progress bar.
*/
Progress.prototype.show = function () {
this.el.style.visibility = 'visible';
};
/**
* Hide the progress bar.
*/
Progress.prototype.hide = function () {
if (this.loading === this.loaded) {
this.el.style.visibility = 'hidden';
this.el.style.width = 0;
}
};
/**
* Update the progress bar.
*/
Progress.prototype.update = function () {
const width = ((this.loaded / this.loading) * 100).toFixed(1) + '%';
this.el.style.width = width;
if (this.loading === this.loaded) {
this.loading = 0;
this.loaded = 0;
const this_ = this;
setTimeout(function () {
setTR3();
}, 500);
}
};
const progress = new Progress(document.getElementById('progress'));
osmLayer.getSource().on('tileloadstart', function () {
progress.addLoading();
});
osmLayer.getSource().on('tileloadend', function () {
progress.addLoaded();
});
osmLayer.getSource().on('tileloaderror', function () {
progress.addLoaded();
});
</script>
</body>
</html>