@mcolabs/threebox-plugin 4.0.1 → 4.0.3

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/dist/threebox.js CHANGED
@@ -498,7 +498,7 @@ CameraSync.prototype = {
498
498
  }
499
499
  this.cameraTranslateZ = new THREE.Matrix4().makeTranslation(0, 0, this.cameraToCenterDistance);
500
500
  const nz = t.height / 50;
501
- const nearZ = Math.max(nz * pitchAngle, nz);
501
+ let nearZ = Math.max(nz * pitchAngle, nz);
502
502
  const h = t.height;
503
503
  const w = t.width;
504
504
  if (this.camera instanceof THREE.OrthographicCamera) {
@@ -906,7 +906,7 @@ AnimationManager.prototype = {
906
906
  parameters: options2
907
907
  };
908
908
  this.animationQueue.push(entry);
909
- tb.map.repaint = true;
909
+ this.threebox.map.repaint = true;
910
910
  } else {
911
911
  this.stop();
912
912
  options2.rotation = utils.radify(options2.rotation);
@@ -940,7 +940,7 @@ AnimationManager.prototype = {
940
940
  }
941
941
  );
942
942
  this.animationQueue.push(entry);
943
- tb.map.repaint = true;
943
+ this.threebox.map.repaint = true;
944
944
  return this;
945
945
  };
946
946
  obj._setObject = function(options2) {
@@ -990,7 +990,7 @@ AnimationManager.prototype = {
990
990
  this.setBoundingBoxShadowFloor();
991
991
  this.setReceiveShadowFloor();
992
992
  this.updateMatrixWorld();
993
- tb.map.repaint = true;
993
+ this.threebox.map.repaint = true;
994
994
  let e2 = { type: "ObjectChanged", detail: { object: this, action: { position: options2.position, rotation: options2.rotation, scale: options2.scale } } };
995
995
  this.dispatchEvent(e2);
996
996
  };
@@ -1008,7 +1008,7 @@ AnimationManager.prototype = {
1008
1008
  parameters: options2
1009
1009
  };
1010
1010
  this.animationQueue.push(entry);
1011
- tb.map.repaint = true;
1011
+ this.threebox.map.repaint = true;
1012
1012
  return this;
1013
1013
  }
1014
1014
  };
@@ -1052,7 +1052,7 @@ AnimationManager.prototype = {
1052
1052
  if (obj.mixer) {
1053
1053
  obj.mixer.update(0.01);
1054
1054
  }
1055
- tb.map.repaint = true;
1055
+ this.threebox.map.repaint = true;
1056
1056
  return this;
1057
1057
  };
1058
1058
  },
@@ -1113,9 +1113,8 @@ AnimationManager.prototype = {
1113
1113
  if (item.type === "playDefault") {
1114
1114
  object.activateAllActions();
1115
1115
  object.isPlaying = true;
1116
- object.animationMethod = requestAnimationFrame(this.update);
1117
1116
  object.mixer.update(object.clock.getDelta());
1118
- tb.map.repaint = true;
1117
+ object.threebox.map.repaint = true;
1119
1118
  }
1120
1119
  }
1121
1120
  }
@@ -1310,7 +1309,7 @@ Objects.prototype = {
1310
1309
  model.position.applyAxisAngle(axis, theta);
1311
1310
  model.position.add(point);
1312
1311
  model.rotateOnAxis(axis, theta);
1313
- tb.map.repaint = true;
1312
+ obj.threebox.map.repaint = true;
1314
1313
  }, zoomScale = function(zoom) {
1315
1314
  return Math.pow(2, zoom);
1316
1315
  };
@@ -1921,10 +1920,11 @@ Objects.prototype = {
1921
1920
  if (m.dispose) m.dispose();
1922
1921
  });
1923
1922
  obj.scaleGroup.remove(o2);
1924
- tb.map.repaint = true;
1923
+ obj.threebox.map.repaint = true;
1925
1924
  };
1926
1925
  obj.duplicate = function(options2) {
1927
1926
  let dupe = obj.clone(true);
1927
+ dupe.threebox = obj.threebox;
1928
1928
  dupe.getObjectByName("model").animations = obj.animations;
1929
1929
  if (dupe.userData.feature) {
1930
1930
  if (options2 && options2.feature) dupe.userData.feature = options2.feature;
@@ -2324,15 +2324,15 @@ function loadObj(options2, cb, promise) {
2324
2324
  let specularColor;
2325
2325
  if (c.material.type == "MeshStandardMaterial") {
2326
2326
  if (c.material.metalness) {
2327
- c.material.metalness *= 0.1;
2327
+ c.material.metalness *= 0.3;
2328
2328
  }
2329
2329
  if (c.material.glossiness) {
2330
- c.material.glossiness *= 0.25;
2330
+ c.material.glossiness *= 0.5;
2331
2331
  }
2332
- specularColor = new THREE.Color(12, 12, 12);
2332
+ specularColor = new THREE.Color(789516);
2333
2333
  } else if (c.material.type == "MeshPhongMaterial") {
2334
- c.material.shininess = 0.1;
2335
- specularColor = new THREE.Color(20, 20, 20);
2334
+ c.material.shininess = 0.3;
2335
+ specularColor = new THREE.Color(1315860);
2336
2336
  }
2337
2337
  if (c.material.specular && c.material.specular.isColor) {
2338
2338
  c.material.specular = specularColor;
@@ -2436,11 +2436,13 @@ class BuildingShadows {
2436
2436
  this.tb = threebox;
2437
2437
  }
2438
2438
  onAdd(map, gl) {
2439
+ var _a2, _b2, _c;
2439
2440
  this.map = map;
2440
2441
  const sourceName = this.map.getLayer(this.buildingsLayerId).source;
2441
- this.source = (this.map.style.sourceCaches || this.map.style._otherSourceCaches)[sourceName];
2442
+ const style = this.map.style;
2443
+ this.source = ((_a2 = style.sourceCaches) == null ? void 0 : _a2[sourceName]) || ((_b2 = style._otherSourceCaches) == null ? void 0 : _b2[sourceName]) || ((_c = style._sourceCaches) == null ? void 0 : _c[sourceName]);
2442
2444
  if (!this.source) {
2443
- console.warn(`Can't find layer ${this.buildingsLayerId}'s source.`);
2445
+ console.warn(`BuildingShadows: Can't find layer ${this.buildingsLayerId}'s source.`);
2444
2446
  }
2445
2447
  const vertexSource = this._getVertexSource();
2446
2448
  const fragmentSource = `
@@ -2451,13 +2453,22 @@ class BuildingShadows {
2451
2453
  const vertexShader = gl.createShader(gl.VERTEX_SHADER);
2452
2454
  gl.shaderSource(vertexShader, vertexSource);
2453
2455
  gl.compileShader(vertexShader);
2456
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
2457
+ console.error("BuildingShadows vertex shader error:", gl.getShaderInfoLog(vertexShader));
2458
+ }
2454
2459
  const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
2455
2460
  gl.shaderSource(fragmentShader, fragmentSource);
2456
2461
  gl.compileShader(fragmentShader);
2462
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
2463
+ console.error("BuildingShadows fragment shader error:", gl.getShaderInfoLog(fragmentShader));
2464
+ }
2457
2465
  this.program = gl.createProgram();
2458
2466
  gl.attachShader(this.program, vertexShader);
2459
2467
  gl.attachShader(this.program, fragmentShader);
2460
2468
  gl.linkProgram(this.program);
2469
+ if (!gl.getProgramParameter(this.program, gl.LINK_STATUS)) {
2470
+ console.error("BuildingShadows program link error:", gl.getProgramInfoLog(this.program));
2471
+ }
2461
2472
  gl.validateProgram(this.program);
2462
2473
  this.uMatrix = gl.getUniformLocation(this.program, "u_matrix");
2463
2474
  this.uHeightFactor = gl.getUniformLocation(this.program, "u_height_factor");
@@ -2473,6 +2484,7 @@ class BuildingShadows {
2473
2484
  this.aHeight = gl.getAttribLocation(this.program, "a_height");
2474
2485
  }
2475
2486
  render(gl, matrix) {
2487
+ var _a2, _b2;
2476
2488
  if (!this.source) return;
2477
2489
  gl.useProgram(this.program);
2478
2490
  const coords = this.source.getVisibleCoordinates().reverse();
@@ -2484,13 +2496,25 @@ class BuildingShadows {
2484
2496
  gl.uniform1f(this.uAzimuth, pos.azimuth + 3 * Math.PI / 2);
2485
2497
  gl.enable(gl.BLEND);
2486
2498
  gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
2487
- gl.getExtension("EXT_blend_minmax");
2488
2499
  gl.disable(gl.DEPTH_TEST);
2489
2500
  for (const coord of coords) {
2490
2501
  const tile = this.source.getTile(coord);
2491
- const bucket = tile.getBucket(buildingsLayer);
2502
+ let bucket = tile.getBucket(buildingsLayer);
2503
+ if (!bucket && tile.buckets) {
2504
+ bucket = tile.buckets[this.buildingsLayerId];
2505
+ }
2492
2506
  if (!bucket) continue;
2493
- const [heightBuffer, baseBuffer] = bucket.programConfigurations.programConfigurations[this.buildingsLayerId]._buffers;
2507
+ let heightBuffer, baseBuffer;
2508
+ const programConfig = (_b2 = (_a2 = bucket.programConfigurations) == null ? void 0 : _a2.programConfigurations) == null ? void 0 : _b2[this.buildingsLayerId];
2509
+ if (programConfig == null ? void 0 : programConfig._buffers) {
2510
+ [heightBuffer, baseBuffer] = programConfig._buffers;
2511
+ } else if (programConfig == null ? void 0 : programConfig.getBuffers) {
2512
+ const buffers = programConfig.getBuffers();
2513
+ heightBuffer = buffers[0];
2514
+ baseBuffer = buffers[1];
2515
+ } else {
2516
+ continue;
2517
+ }
2494
2518
  gl.uniformMatrix4fv(this.uMatrix, false, coord.posMatrix || coord.projMatrix);
2495
2519
  gl.uniform1f(this.uHeightFactor, Math.pow(2, coord.overscaledZ) / tile.tileSize / 8);
2496
2520
  for (const segment of bucket.segments.get()) {
@@ -2638,10 +2662,17 @@ Threebox.prototype = {
2638
2662
  this.enableHelpTooltips = this.options.enableHelpTooltips || false;
2639
2663
  this.map.on("style.load", function() {
2640
2664
  this.tb.zoomLayers = [];
2641
- if (this.tb.options.multiLayer) this.addLayer({ id: "threebox_layer", type: "custom", renderingMode: "3d", map: this, onAdd: function(map2, gl) {
2642
- }, render: function(gl, matrix) {
2643
- this.map.tb.update();
2644
- } });
2665
+ if (this.tb.options.multiLayer) this.addLayer({
2666
+ id: "threebox_layer",
2667
+ type: "custom",
2668
+ renderingMode: "3d",
2669
+ map: this,
2670
+ onAdd: function(map2, gl) {
2671
+ },
2672
+ render: function(gl, matrix) {
2673
+ this.map.tb.update();
2674
+ }
2675
+ });
2645
2676
  this.once("idle", () => {
2646
2677
  this.tb.setObjectsScale();
2647
2678
  });
@@ -3086,29 +3117,51 @@ Threebox.prototype = {
3086
3117
  // Objects
3087
3118
  sphere: function(options2) {
3088
3119
  this.setDefaultView(options2, this.options);
3089
- return Sphere(options2, this.world);
3120
+ let obj = Sphere(options2, this.world);
3121
+ obj.threebox = this;
3122
+ return obj;
3123
+ },
3124
+ line: function(options2) {
3125
+ let obj = line(options2);
3126
+ obj.threebox = this;
3127
+ return obj;
3128
+ },
3129
+ label: function(options2) {
3130
+ let obj = Label(options2);
3131
+ obj.threebox = this;
3132
+ return obj;
3133
+ },
3134
+ tooltip: function(options2) {
3135
+ let obj = Tooltip(options2);
3136
+ obj.threebox = this;
3137
+ return obj;
3090
3138
  },
3091
- line,
3092
- label: Label,
3093
- tooltip: Tooltip,
3094
3139
  tube: function(options2) {
3095
3140
  this.setDefaultView(options2, this.options);
3096
- return tube(options2, this.world);
3141
+ let obj = tube(options2, this.world);
3142
+ obj.threebox = this;
3143
+ return obj;
3097
3144
  },
3098
3145
  extrusion: function(options2) {
3099
3146
  this.setDefaultView(options2, this.options);
3100
- return extrusion(options2);
3147
+ let obj = extrusion(options2);
3148
+ obj.threebox = this;
3149
+ return obj;
3101
3150
  },
3102
3151
  Object3D: function(options2) {
3103
3152
  this.setDefaultView(options2, this.options);
3104
- return Object3D(options2);
3153
+ let obj = Object3D(options2);
3154
+ obj.threebox = this;
3155
+ return obj;
3105
3156
  },
3106
3157
  loadObj: async function loadObj$1(options2, cb) {
3107
3158
  this.setDefaultView(options2, this.options);
3159
+ const tb = this;
3108
3160
  if (options2.clone === false) {
3109
3161
  return new Promise(
3110
3162
  async (resolve) => {
3111
3163
  loadObj(options2, cb, async (obj) => {
3164
+ obj.threebox = tb;
3112
3165
  resolve(obj);
3113
3166
  });
3114
3167
  }
@@ -3117,7 +3170,9 @@ Threebox.prototype = {
3117
3170
  let cache = this.objectsCache.get(options2.obj);
3118
3171
  if (cache) {
3119
3172
  cache.promise.then((obj) => {
3120
- cb(obj.duplicate(options2));
3173
+ let dupe = obj.duplicate(options2);
3174
+ dupe.threebox = tb;
3175
+ cb(dupe);
3121
3176
  }).catch((err) => {
3122
3177
  this.objectsCache.delete(options2.obj);
3123
3178
  console.error("Could not load model file: " + options2.obj);
@@ -3127,6 +3182,7 @@ Threebox.prototype = {
3127
3182
  promise: new Promise(
3128
3183
  async (resolve, reject) => {
3129
3184
  loadObj(options2, cb, async (obj) => {
3185
+ obj.threebox = tb;
3130
3186
  if (obj.duplicate) {
3131
3187
  resolve(obj.duplicate());
3132
3188
  } else {
@@ -3267,12 +3323,20 @@ Threebox.prototype = {
3267
3323
  this.setLayoutProperty(layerId, "visibility", visible ? "visible" : "none");
3268
3324
  this.labelRenderer.toggleLabels(layerId, visible);
3269
3325
  },
3270
- update: function() {
3326
+ update: function(matrix) {
3271
3327
  if (this.map.repaint) this.map.repaint = false;
3272
3328
  var timestamp = Date.now();
3273
3329
  this.objects.animationManager.update(timestamp);
3274
3330
  this.updateLightHelper();
3275
3331
  this.renderer.resetState();
3332
+ const gl = this.renderer.getContext();
3333
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
3334
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
3335
+ if (this.mapboxVersion >= 3) {
3336
+ gl.enable(gl.DEPTH_TEST);
3337
+ gl.depthFunc(gl.LESS);
3338
+ gl.depthMask(true);
3339
+ }
3276
3340
  this.renderer.render(this.scene, this.camera);
3277
3341
  this.labelRenderer.render(this.scene, this.camera);
3278
3342
  if (this.options.passiveRendering === false) this.map.triggerRepaint();
@@ -3281,6 +3345,7 @@ Threebox.prototype = {
3281
3345
  if (!this.enableTooltips && obj.tooltip) {
3282
3346
  obj.tooltip.visibility = false;
3283
3347
  }
3348
+ obj.threebox = this;
3284
3349
  this.world.add(obj);
3285
3350
  if (layerId) {
3286
3351
  obj.layer = layerId;
@@ -3380,8 +3445,8 @@ Threebox.prototype = {
3380
3445
  let azSin = Math.sin(azimuth2) * altRadius;
3381
3446
  this.lights.dirLight.position.set(azSin, azCos, alt);
3382
3447
  this.lights.dirLight.position.multiplyScalar(radius);
3383
- this.lights.dirLight.intensity = Math.max(alt, 0);
3384
- this.lights.hemiLight.intensity = Math.max(alt * 1, 0.1);
3448
+ this.lights.dirLight.intensity = Math.max(alt, 0) * 5;
3449
+ this.lights.hemiLight.intensity = Math.max(alt * 1, 0.1) * 3;
3385
3450
  this.lights.dirLight.updateMatrixWorld();
3386
3451
  this.updateLightHelper();
3387
3452
  if (this.map.loaded()) {
@@ -3449,18 +3514,18 @@ Threebox.prototype = {
3449
3514
  });
3450
3515
  },
3451
3516
  defaultLights: function() {
3452
- this.lights.ambientLight = new THREE.AmbientLight(new THREE.Color("hsl(0, 0%, 100%)"), 0.75);
3517
+ this.lights.ambientLight = new THREE.AmbientLight(new THREE.Color("hsl(0, 0%, 100%)"), 3);
3453
3518
  this.scene.add(this.lights.ambientLight);
3454
- this.lights.dirLightBack = new THREE.DirectionalLight(new THREE.Color("hsl(0, 0%, 100%)"), 0.25);
3519
+ this.lights.dirLightBack = new THREE.DirectionalLight(new THREE.Color("hsl(0, 0%, 100%)"), 1);
3455
3520
  this.lights.dirLightBack.position.set(30, 100, 100);
3456
3521
  this.scene.add(this.lights.dirLightBack);
3457
- this.lights.dirLight = new THREE.DirectionalLight(new THREE.Color("hsl(0, 0%, 100%)"), 0.25);
3522
+ this.lights.dirLight = new THREE.DirectionalLight(new THREE.Color("hsl(0, 0%, 100%)"), 1);
3458
3523
  this.lights.dirLight.position.set(-30, 100, -100);
3459
3524
  this.scene.add(this.lights.dirLight);
3460
3525
  },
3461
3526
  realSunlight: function(helper = false) {
3462
3527
  this.renderer.shadowMap.enabled = true;
3463
- this.lights.dirLight = new THREE.DirectionalLight(16777215, 1);
3528
+ this.lights.dirLight = new THREE.DirectionalLight(16777215, 5);
3464
3529
  this.scene.add(this.lights.dirLight);
3465
3530
  if (helper) {
3466
3531
  this.lights.dirLightHelper = new THREE.DirectionalLightHelper(this.lights.dirLight, 5);
@@ -3478,7 +3543,7 @@ Threebox.prototype = {
3478
3543
  this.lights.dirLight.shadow.camera.near = 1;
3479
3544
  this.lights.dirLight.shadow.camera.visible = true;
3480
3545
  this.lights.dirLight.shadow.camera.far = 4e8;
3481
- this.lights.hemiLight = new THREE.HemisphereLight(new THREE.Color(16777215), new THREE.Color(16777215), 0.6);
3546
+ this.lights.hemiLight = new THREE.HemisphereLight(new THREE.Color(16777215), new THREE.Color(16777215), 3);
3482
3547
  this.lights.hemiLight.color.setHSL(0.661, 0.96, 0.12);
3483
3548
  this.lights.hemiLight.groundColor.setHSL(0.11, 0.96, 0.14);
3484
3549
  this.lights.hemiLight.position.set(0, 0, 50);