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

GTLF Loader #37

Open lmd3coder opened 6 years ago

lmd3coder commented 6 years ago

Is threebox compatible with GTLF loader. I cannot seem to get it to work.

peterpolman commented 5 years ago

Got it working in my application. I use this loader, make sure to load the script before loading your app: https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/GLTFLoader.js

Implementation should work like this:

const tb = new Threebox(map, mbxContext);
const position = { lat: 52.00, lng: 7.2 };
const loader = new THREE.GLTFLoader();
console.log(loader); // Check your browser console to see if this function is available.
loader.load(`./objects/test/test.gltf`, (gltf) => {
  const mesh = tb.Object3D({obj: gltf.scene, units:'meters' }).setCoords([position.lng, position.lat]);
  tb.add(this.mesh);
});
gisonjourney commented 4 years ago

Got it working in my application. I use this loader, make sure to load the script before loading your app: https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/GLTFLoader.js Implementation should work like this:

const tb = new Threebox(map, mbxContext);
const position = { lat: 52.00, lng: 7.2 };
const loader = new THREE.GLTFLoader();
console.log(loader); // Check your browser console to see if this function is available.
loader.load(`./objects/test/test.gltf`, (gltf) => {
  const mesh = tb.Object3D({obj: gltf.scene, units:'meters' }).setCoords([position.lng, position.lat]);
  tb.add(this.mesh);
});

Hello,how can i set scale and rotation?I used obj.set(options) ,but this can't work.

anton-ax commented 4 years ago

Got it working in my application. I use this loader, make sure to load the script before loading your app: https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/GLTFLoader.js Implementation should work like this:

const tb = new Threebox(map, mbxContext);
const position = { lat: 52.00, lng: 7.2 };
const loader = new THREE.GLTFLoader();
console.log(loader); // Check your browser console to see if this function is available.
loader.load(`./objects/test/test.gltf`, (gltf) => {
  const mesh = tb.Object3D({obj: gltf.scene, units:'meters' }).setCoords([position.lng, position.lat]);
  tb.add(this.mesh);
});

Hello,how can i set scale and rotation?I used obj.set(options) ,but this can't work. Use scale and rotation modification on gltf.scene object not Object3d:

gltf.scene.scale.set(1, 1,  1);
gltf.scene.rotation.x = Math.PI / 2;