I have been attempting to duplicate an object within Forge Viewer. Despite my efforts using THREE.js to create a clone, the resulting structure does not match the original object.
sceneBuilder = viewer.loadExtension("Autodesk.Viewing.SceneBuilder");
let modelBuilder = await sceneBuilder.addNewModel({
conserveMemory: false,
modelNameOverride: `Custom model`,
});
let renderProxy = viewer.impl.getRenderProxy(viewer.model, fragId);
let geom = new THREE.Geometry();
let VE = Autodesk.Viewing.Private.VertexEnumerator;
VE.enumMeshVertices(renderProxy.geometry, (v, i) => {
geom.vertices.push(new THREE.Vector3(v.x, v.y, v.z));
});
VE.enumMeshIndices(renderProxy.geometry, (a, b, c) => {
geom.faces.push(new THREE.Face3(a, b, c));
});
geom.computeFaceNormals();
let mesh = new THREE.Mesh(
new THREE.BufferGeometry().fromGeometry(geom),
renderProxy.material
);
(mesh as any).dbId = dbId;
modelBuilder.addMesh(mesh);
After discovering that renderProxy is also a THREE.Mesh
, my attempt to clone it using
let clone = renderProxy.clone(); modelBuilder.addMesh(clone)
was unsuccessful. Is there a way to properly clone an object in Viewer?
Furthermore, when I add a mesh using modelBuilder, I notice that the created object is added to the browser tree, but I am still unable to utilize Viewer functions with it (such as
Viewer.select(dbId); Viewer.fitToView();
)