mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

How can threejs layers and mapboxgl layers have the correct layering relationship?

Open xiaxiangfeng opened this issue 2 years ago • 2 comments

mapbox-gl-js version: ^2.15.0

Question

I added two layers using threejs in mapboxgl. The expected rendering order of the layers is layerA - background - layerB, but the actual order is background - layerA - layerB.

code

layers: [
          {
            id: "background",
            name: "背景",
            category: "背景",
            type: "background",
            paint: {
              "background-color": "rgba(9, 26, 56, 0.71)",
            },
          },
        ],

map.on("style.load", function () {
      // instantiate threebox
      window.tb = new Threebox(map, map.getCanvas().getContext("webgl"), {
        defaultLights: true,
        enableSelectingObjects: true,
      });

      map.addLayer(
        {
          id: "layerA",
          type: "custom",
          renderingMode: "3d",
          onAdd: function (map, mbxContext) {
            //instantiate a red sphere and position it at the origin lnglat
            var sphere = tb
              .sphere({ color: "red", material: "MeshToonMaterial" })
              .setCoords(origin);
            // add sphere to the scene
            tb.add(sphere);
          },
          render: function (gl, matrix) {
            tb.update();
          },
        },
        "background"
      );

      map.addLayer({
        id: "layerB",
        type: "custom",
        renderingMode: "3d",
        onAdd: function (map, mbxContext) {
          //instantiate a red sphere and position it at the origin lnglat
          var sphere = tb
            .sphere({ color: "red", material: "MeshToonMaterial" })
            .setCoords([-122.434, 37.7453, 1]);

          // add sphere to the scene
          tb.add(sphere);
        },
        render: function (gl, matrix) {
          tb.update();
        },
      });
    });

mapboxgl order

image

rendered results

image

xiaxiangfeng avatar Aug 23 '23 06:08 xiaxiangfeng

All custom layers are rendered in a translucent queue, which is why your threejs layers are rendered last

wcwcwcwc avatar Dec 20 '23 08:12 wcwcwcwc

All custom layers are rendered in a translucent queue, which is why your threejs layers are rendered last

Can there be a normal order

xiaxiangfeng avatar Dec 21 '23 11:12 xiaxiangfeng