Loading several instances from OBJ file

Hi everyone!

I’m trying to instantiate the same geometry more than once (I’m using a local OBJ file atm). Currently, each node belonging to the meshes are actually shown and can be manipulated, however, their individual parent node share the exact same id (matching the file path), which ofc gives some issues later down the line. I have tried to change the id in several ways. Is there a way to do this?

Or even better, is there a way to instantiate/ copy a geometry more than once without the additional overhead of loading from file?

The last thing I tried was to follow this example from the docs:

const objData:string | ArrayBuffer = '<your OBJ resource data>'
/** Create a loader for the .obj data */
const loader = new ObjLoader(viewer.getWorldTree(), '<user defined id>', objData);
/** Load the obj data */
await viewer.loadObject(loader, true);

It seems adding the ‘user defined Id’ will cause an error in the loader, since no geometries are being shown.

Hi @Idavill

There is no explicit way of cloning or duplicating object or trees, however loading the same thing multiple times is possible. I’ve made this live example that shows the approach to it.

We load the .obj contents once, then load it with the viewer twice under different ids. I’ve added an extension that allows you to drag objects around so you can see there are two dice objects loaded. The only gotcha is that the ObjLoader can only take .obj data as string and not ArrayBuffer since the underlying three.js parse method only takes string as input data.

Initially the models are stacked on top of each other, but I’ve added the ExtendedSelection extension that allows you drag objects around after selecting them

Depending on your use case, duplicating data can be done more efficiently. Let me know if you want to discuss this further

Cheers