@jdultra/threedtiles 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,8 +87,7 @@ ogc3DTile.rotateOnAxis(new THREE.Vector3(1,0,0), -Math.PI*0.5);
87
87
  ```
88
88
 
89
89
  # Displaying meshes on a globe
90
- I'm working on this project in parallel https://github.com/ebeaufay/UltraGlobe which allows displaying a globe with multi resolution imagery and elevation.
91
- I'll soon add a layer for 3DTiles.
90
+ I'm working on this project in parallel https://github.com/ebeaufay/UltraGlobe which allows displaying a globe with multi resolution imagery, elevation and 3DTiles.
92
91
 
93
92
  # Mesh to 3DTiles Converter
94
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jdultra/threedtiles",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "An OGC 3DTiles viewer for Three.js",
5
5
  "main": "tileset.js",
6
6
  "scripts": {
@@ -26,7 +26,8 @@
26
26
  "gltf-validator": ">=2.0.0-dev.3.3",
27
27
  "lodash": ">=4.17.20",
28
28
  "regenerator-runtime": ">=0.13.7",
29
- "three": "0.131.0"
29
+ "three": "0.131.0",
30
+ "js-utils-z": "1.2.1"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@babel/core": "^7.12.9",
@@ -38,7 +39,7 @@
38
39
  "html-webpack-plugin": "^4.5.0",
39
40
  "mini-css-extract-plugin": "^1.3.1",
40
41
  "webpack": "4.44.2",
41
- "webpack-cli": "3.3.12",
42
+ "webpack-cli": "^3.3.12",
42
43
  "webpack-dev-server": "3.11.0",
43
44
  "whatwg-fetch": "^3.5.0"
44
45
  }
package/skybox/back.png CHANGED
Binary file
package/skybox/bottom.png CHANGED
Binary file
package/skybox/front.png CHANGED
Binary file
package/skybox/left.png CHANGED
Binary file
package/skybox/right.png CHANGED
Binary file
package/skybox/top.png CHANGED
Binary file
@@ -0,0 +1,44 @@
1
+
2
+ import { LinkedHashMap } from 'js-utils-z';
3
+
4
+ class Cache {
5
+ constructor(loader, counter, dispose, max) {
6
+ this.loader = loader;
7
+ this.counter = counter;
8
+ this.dispose = dispose;
9
+ this.max = max;
10
+ this.currentSize = 0;
11
+ this.objects = new LinkedHashMap();
12
+ }
13
+
14
+ get(name){
15
+ if(this.objects.has(name)){
16
+ const item = this.objects.remove(name);
17
+ item.users++;
18
+ this.objects.put(name, item, false);
19
+ return new Promise.resolve({dispose:()=>item.users--,content:item.content});
20
+ }else{
21
+ return this.loader(name).then(content=>{
22
+ const item = { users: 1, content: content };
23
+ this.objects.put(name, item, false);
24
+ currentSize+=this.counter(item);
25
+ checkSize();
26
+ return {dispose:()=>item.users--,content:item.content};
27
+ });
28
+ }
29
+ }
30
+
31
+ checkSize(){
32
+ let object = this.objects.head();
33
+ while(this.currentSize > this.max && !!object){
34
+ if(object.value.users <=0){
35
+ const item = this.objects.remove(object.key);
36
+ this.currentSize -= this.counter(item.content);
37
+ this.dispose(item.content);
38
+ }
39
+ object = object.next();
40
+ }
41
+ }
42
+ }
43
+
44
+ export{Cache};
package/src/index.js CHANGED
@@ -62,14 +62,14 @@ function initLODMultiplierSlider(tileset) {
62
62
  function initScene() {
63
63
  const scene = new THREE.Scene();
64
64
  scene.background = new THREE.Color(0xFF0000);
65
- scene.add(new THREE.AmbientLight(0xFFFFFF, 1.0));
65
+ scene.add(new THREE.AmbientLight(0xFFFFFF, 0.5));
66
66
 
67
- /*var dirLight = new THREE.DirectionalLight(0xffffff, 0.5);
67
+ var dirLight = new THREE.DirectionalLight(0xffffff, 0.5);
68
68
  dirLight.position.set(-400, 500, -100);
69
69
  dirLight.target.position.set(0, 0, 0);
70
70
 
71
71
  scene.add(dirLight);
72
- scene.add(dirLight.target);*/
72
+ scene.add(dirLight.target);
73
73
  return scene;
74
74
  }
75
75
 
@@ -116,7 +116,7 @@ function initStats(dom) {
116
116
 
117
117
 
118
118
  function initCamera() {
119
- const camera = new THREE.PerspectiveCamera(30, window.offsetWidth / window.offsetHeight, 1, 10000);
119
+ const camera = new THREE.PerspectiveCamera(70, window.offsetWidth / window.offsetHeight, 1, 10000);
120
120
  camera.position.set(-60, 5, -30);
121
121
  camera.lookAt(-100, 0, 0);
122
122
 
@@ -128,8 +128,8 @@ function initTileset(scene) {
128
128
  const ogc3DTile = new OGC3DTile({
129
129
  url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
130
130
  //url: "https://storage.googleapis.com/ogc-3d-tiles/castleX/tileset.json",
131
- //url: "./yamato/tileset.json",
132
- //url: "./castle/tileset.json",
131
+ //url: "./apartment/tileset.json",
132
+ //url: "https://storage.googleapis.com/ogc-3d-tiles/berlinSubsetTiled/tileset.json",
133
133
  //url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
134
134
  //url: "https://s3.us-east-2.wasabisys.com/construkted-assets/arkcnfuk9fw/tileset.json",
135
135
  //url: "https://s3.us-east-2.wasabisys.com/construkted-assets/a73faxnydqk/tileset.json",
@@ -141,12 +141,14 @@ function initTileset(scene) {
141
141
  meshCallback: mesh => {
142
142
  //// Insert code to be called on every newly decoded mesh e.g.:
143
143
  mesh.material.wireframe = false;
144
- mesh.material.side = THREE.FrontSide;
144
+ mesh.material.side = THREE.DoubleSide;
145
145
  }
146
146
  });
147
147
 
148
148
  //// The OGC3DTile object is a threejs Object3D so you may do all the usual opperations like transformations e.g.:
149
- //ogc3DTile.translateOnAxis(new THREE.Vector3(1,0,0), 100)
149
+ //ogc3DTile.translateOnAxis(new THREE.Vector3(0,1,0), -10)
150
+ //ogc3DTile.translateOnAxis(new THREE.Vector3(1,0,0), -65)
151
+ //ogc3DTile.translateOnAxis(new THREE.Vector3(0,0,1), -80)
150
152
  //ogc3DTile.scale.set(0.01,0.01,0.01);
151
153
  //ogc3DTile.rotateOnAxis(new THREE.Vector3(1, 0, 0), -Math.PI * 0.5) // Z-UP to Y-UP
152
154
  //// It's up to the user to call updates on the tileset. You might call them whenever the camera moves or at regular time intervals like here
@@ -1,6 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { OBB } from "../geometry/obb";
3
3
  import { B3DMDecoder } from "../decoder/B3DMDecoder";
4
+ import {Cache} from "../cache/Cache";
4
5
  const path = require('path');
5
6
 
6
7
  const tilesToLoad = [];
@@ -11,7 +12,7 @@ function scheduleLoadTile(tile) {
11
12
  setInterval(() => {
12
13
  const tile = tilesToLoad.shift();
13
14
  if (!!tile) tile.load();
14
- }, 0)
15
+ }, 5)
15
16
 
16
17
  const tempSphere = new THREE.Sphere(new THREE.Vector3(0, 0, 0, 1));
17
18
 
@@ -28,7 +29,8 @@ class OGC3DTile extends THREE.Object3D {
28
29
  * parentBoundingVolume: optional,
29
30
  * parentRefinement: optional,
30
31
  * geometricErrorMultiplier: Double,
31
- * loadOutsideView: Boolean
32
+ * loadOutsideView: Boolean,
33
+ * cache : Cache
32
34
  * } properties
33
35
  */
34
36
  constructor(properties) {
@@ -49,7 +51,7 @@ class OGC3DTile extends THREE.Object3D {
49
51
  this.json; // the json corresponding to this tile
50
52
  this.materialVisibility = false;
51
53
  this.inFrustum = true;
52
-
54
+ this.level = properties.level? properties.level : 0;
53
55
  this.hasMeshContent = false; // true when the provided json has a content field pointing to a B3DM file
54
56
  this.hasUnloadedJSONContent = false; // true when the provided json has a content field pointing to a JSON file that is not yet loaded
55
57
 
@@ -239,7 +241,7 @@ class OGC3DTile extends THREE.Object3D {
239
241
  function updateTree(metric) {
240
242
  // If this tile does not have mesh content but it has children
241
243
  if(metric<0 && self.hasMeshContent) return;
242
- if (!self.hasMeshContent || metric < self.geometricError) {
244
+ if (!self.hasMeshContent || (metric < self.geometricError && !!self.meshContent)) {
243
245
  if (!!self.json && !!self.json.children && self.childrenTiles.length != self.json.children.length) {
244
246
  loadJsonChildren();
245
247
  return;
@@ -289,6 +291,8 @@ class OGC3DTile extends THREE.Object3D {
289
291
  });
290
292
  if (allChildrenReady) {
291
293
  self.changeContentVisibility(false);
294
+ }else{
295
+ self.changeContentVisibility(true);
292
296
  }
293
297
  }
294
298
  }
@@ -318,7 +322,8 @@ class OGC3DTile extends THREE.Object3D {
318
322
  rootPath: self.rootPath,
319
323
  geometricErrorMultiplier: self.geometricErrorMultiplier,
320
324
  meshCallback: self.meshCallback,
321
- loadOutsideView: self.loadOutsideView
325
+ loadOutsideView: self.loadOutsideView,
326
+ level:self.level+1
322
327
  });
323
328
  self.childrenTiles.push(childTile);
324
329
  self.add(childTile);
@@ -448,4 +453,28 @@ class OGC3DTile extends THREE.Object3D {
448
453
  this.childrenTiles.forEach(child => child.setGeometricErrorMultiplier(geometricErrorMultiplier));
449
454
  }
450
455
  }
451
- export { OGC3DTile };
456
+
457
+ /**
458
+ *
459
+ * @param {Integer} size a number of vertices
460
+ */
461
+ function createMeshCache(size = 5000000, meshCallback = ()=>{}){
462
+ /* return new Cache(
463
+ (url, self)=>{
464
+ fetch(url, { signal: self.controller.signal }).then(result => {
465
+ if (!result.ok) {
466
+ throw new Error(`couldn't load "${properties.url}". Request failed with status ${result.status} : ${result.statusText}`);
467
+ }
468
+ result.arrayBuffer().then(buffer => B3DMDecoder.parseB3DM(buffer, self.meshCallback)).then(mesh => {
469
+ mesh.traverse((o) => {
470
+ if (o.isMesh) {
471
+ o.material.visible = false;
472
+ }
473
+ });
474
+ return mesh;
475
+ }).catch(error => { });
476
+ }
477
+ }
478
+ ) */
479
+ }
480
+ export { OGC3DTile, createMeshCache };