peterqliu / threebox

A three.js plugin for Mapbox GL JS, with support for basic animation and advanced 3D rendering.
MIT License
526 stars 320 forks source link

Directly using .obj with lat/long coordinates #76

Open josephwh opened 5 years ago

josephwh commented 5 years ago

Would this be possible? I am trying to do it like this:

My code:

    if(!config) console.error("Config not set! Make a copy of 'config_template.js', add in your access token, and save the file as 'config.js'.");

  mapboxgl.accessToken = config.accessToken;

        //starting location for both map and eventual sphere
        var origin = [6.867934468, 53.1164273309];

        var map = new mapboxgl.Map({
            container: 'map',
            style: 'mapbox://styles/mapbox/light-v9',
            center: origin,
            zoom: 16,
            pitch: 60
        });

        map.on('style.load', function() {

            map.addLayer({
                id: 'custom_layer',
        type: 'custom',
                onAdd: function(map, mbxContext){

                    tb = new Threebox(
                        map, 
                        mbxContext,
                        {defaultLights: true}
                    );
                    var options = {
                      obj: 'building.obj',
                      units: 'meters'
                    }

                    tb.loadObj(options, function(model){
                      house = model.setCoords(origin);
                      tb.add(house);
                    })
                },

                render: function(gl, matrix){
                    tb.update();
                }
            })

        });

The .obj:

v 6.867934468 53.1164303555 0
v 6.8680061099 53.1164273309 0
v 6.8680061099 53.1164273309 2.230000138282776
v 6.867934468 53.1164303555 2.230000138282776
v 6.8680111787 53.1164707752 0
v 6.8680111787 53.1164707752 2.230000138282776
v 6.8679395367 53.1164737998 0
v 6.8679395367 53.1164737998 2.230000138282776
o 47100000268544
f 3 4 1
f 1 2 3
f 6 3 2
f 2 5 6
f 8 6 5
f 5 7 8
f 4 8 7
f 7 1 4
f 6 8 4
f 4 3 6
f 2 1 7
f 7 5 2

Thanks.