I am adding multiple instances of the same GLTF model to a scene using Mapbox-gl (2.2.0) and the excellent Threebox (2.2.3) plugin.
The first model renders correctly, the second model exists in the scene, but loses textures and/or shapes.
Different models can be loaded and they do not conflict with each other, however the same behaviour occurs where the second and consecutive instances of each model lose textures and/or shapes.
Pre-Mapbox 2.0 release this was working ok, so I presume it's either a bug or a feature I've misunderstood. It would be great to get this working with 3D terrain on the newest version.
Below is the relevant code, stripped right back:
let map = new mapboxgl.Map({
style: "mapbox://styles/mapbox/satellite-v9?optimize=true",
center: [7.059806068014609, 46.058219779837316],
zoom: 9.848554211380023,
pitch: 85,
bearing: -154.1,
container: 'map',
antialias: true,
hash: true
});
map.on('style.load', function () {
map.addLayer({
id: '3D-overlay',
type: 'custom',
renderingMode: '3d',
onAdd: function (map, mbxContext) {
window.tb = new Threebox(
map,
map.getCanvas().getContext('webgl'),{});
},
render: function (gl, matrix) {
tb.update();
}
});
addBike(1);
addBike(2);
});
function addBike(num){
var options = {
obj: "./gltf/cyclist/scene.gltf",
type: 'gltf',
scale: 10,
units: 'meters',
rotation: {x: 90, y:177, z:0},
anchor: 'auto'
}
tb.loadObj(options, function (model) {
tb.add(model);
model.setCoords([6.927566+(num/10), 45.984111 + (num/10), 4000]);
model.traverse(function (object) {
object.frustumCulled = false;
});
model.playAnimation({ animation: 0, duration: 1000000000 });
model.selected = true;
})
}
Here is a github repo with the files:
https://github.com/nickshreck/threebox-mapbox-gltf-issue.git
Run npm i
, put a mapbox token into main.js and then npm run dev
Many thanks