Currently, I am utilizing a GLTFLoader in threejs along with a glb model initialization. My main objective is to extract the model from the loader for use outside of it. Despite researching numerous topics on this matter, none have provided a solution to my issue.
For reference, I am following this example: sculpt.js
Below is the relevant code snippet:
init();
render();
// reset the sculpt mesh
function reset() {
// clear the existing mesh
if (targetMesh) {
targetMesh.geometry.dispose();
targetMesh.material.dispose();
scene.remove(targetMesh);
}
// combine vertices as needed
const loader = new GLTFLoader();
// Load a glTF resource
loader.load(
// resource URL
"teeth.glb",
// handle loaded resource
function (glb) {
scene.add(glb.scene);
glb.animations; // Array<THREE.AnimationClip>
glb.scene; // THREE.Group
glb.scenes; // Array<THREE.Group>
glb.cameras; // Array<THREE.Camera>
glb.asset; // Object
},
// track loading progress
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
},
// report loading errors
function (error) {
console.log("An error occurred");
}
);
geometry.deleteAttribute("uv");
geometry = BufferGeometryUtils.mergeVertices(geometry);
geometry.attributes.position.setUsage(THREE.DynamicDrawUsage);
geometry.attributes.normal.setUsage(THREE.DynamicDrawUsage);
geometry.computeBoundsTree({ setBoundingBox: false });
// disable frustum culling for vertex updates
targetMesh = new THREE.Mesh(geometry, material);
targetMesh.frustumCulled = false;
scene.add(targetMesh);
// initialize bvh helper
if (!bvhHelper) {
bvhHelper = new MeshBVHHelper(targetMesh, params.depth);
if (params.displayHelper) {
scene.add(bvhHelper);
}
}
bvhHelper.mesh = targetMesh;
bvhHelper.update();
}
I specifically require assistance within the reset function to enable the loader to export the model outside its boundaries as geometry.
Your help and insights are greatly appreciated.