简体   繁体   中英

react mapbox-gl custom layer with three js unexpected ordering

i am working on mapbox gl to show gltf buildings using custom layer and also i am showing the default 3d-buildings provided by mapbox like this:

  export default {
  id: '3d-buildings',
  source: 'composite',
  'source-layer': 'building',

  filter: [
    'all',
    ['!=', ['id'], 59],
    ['!=', ['id'], 88],
    ['!=', ['id'], 79],
    ['!=', ['id'], 78],
    ['!=', ['id'], 80],
    ['!=', ['id'], 32],
    ['!=', ['id'], 8],
    ['!=', ['id'], 2],
    ['!=', ['id'], 4],
    ['!=', ['id'], 22],
    ['!=', ['id'], 3],
    ['!=', ['id'], 5],
    ['!=', ['id'], 60]
  ],
  type: 'fill-extrusion',
  minzoom: 1,
  paint: {
    'fill-extrusion-color': '#aaa',
    'fill-extrusion-height': ['interpolate', ['linear'], ['zoom'], 15, 0, 15.05, ['get', 'height']],
    'fill-extrusion-base': ['interpolate', ['linear'], ['zoom'], 15, 0, 15.05, ['get', 'min_height']],
    'fill-extrusion-opacity': 1
  }
};

i am using filter to remove some buildings from the map. here how i show the custom layer using threebox :

import Threebox from '../../../../../threebox/Threebox';

export default (buildings) => {
  return {
    id: '3d-layer',
    type: 'custom',
    renderingMode: '3d',
    onAdd: function(map, gl) {
      map.moveLayer('3d-buildings', '3d-layer');
      this.tb = new Threebox(map, gl);
      let allBuildings = buildings;
      this.tb.defaultLights();
      for (let i = 0; i < allBuildings.length; i++) {
        this.tb.loadObj({obj: allBuildings[i].url, scale: 0.08, rotation: allBuildings[i].rotation, building: allBuildings[i].id}, obj => {
          obj.setCoords(allBuildings[i].coordinates);
          this.tb.add(obj);
        });
      }
    },
    render: function(map, gl) {
      map.clear(map.DEPTH_BUFFER_BIT);
      this.tb.update();
    }
  };
};

here what is look like when rendering the layers: 在此处输入图像描述

在此处输入图像描述

as you can see the custom layer buildings are showing on top of the 3d-buildings layer. i have searched the web to solve the problem no result. i apperciate if someone can help me solve it. thanks

I have solved this problem at my [Threebox fork] fine tuning the CameraSync object, changing the calculations for nearest and furthest.

自定义层 3D 模型和填充挤出层一起

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM