I am looking to create a viewer forge that can be linked to BIM 360. I want to incorporate a new feature using THREE.js where an object can dynamically follow GPS coordinates for model positioning. I have successfully integrated it into the FORGE viewer, but I'm unsure of which method to use to display the custom model:
- viewer.impl.scene.add(model)
- viewer.overlays.addMesh(model)
- modelBuilder.addMesh(model)
Could you advise on the best approach for this scenario?
Additionally, I encountered an issue when trying to group the mesh with the sceneBuilder. It didn't work as expected, but when I utilized overlays, it worked seamlessly.
this.viewer.loadExtension("Autodesk.Viewing.SceneBuilder").then(() => {
this.sceneBuilder = this.viewer.getExtension(
"Autodesk.Viewing.SceneBuilder"
);
this.sceneBuilder.addNewModel({}).then((modelBuilder) => {
this.modelBuilder = modelBuilder;
window.modelBuilder = modelBuilder;
const geometry = new THREE.BufferGeometry().fromGeometry(
new THREE.SphereGeometry(5, 8, 8)
);
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const head = new THREE.Mesh(geometry, material);
mesh.matrix = new THREE.Matrix4().compose(
new THREE.Vector3(0, 0, 5),
new THREE.Quaternion(0, 0, 0, 1),
new THREE.Vector3(1, 1, 2)
);
const body = new THREE.Mesh(geometry, material);
body.matrix = new THREE.Matrix4().compose(
new THREE.Vector3(0, 0, 0),
new THREE.Quaternion(0, 0, 0, 1),
new THREE.Vector3(1, 1, 2)
);
const human = new THREE.Group();
human.add(head);
human.add(body);
human.dbId = 100; // Set the database id for the mesh
modelBuilder.addMesh(human);
});
});