0
votes

I want to load a model and maintain the same unique id whenever loaded. When I unload a model, I remove it and dispose of the mesh geometry and mesh material and call localStorage.clear(). But when I reload the model the unique ids for all the meshes are different. The only way I can get the same id on each load is to also call location.reload(true). But I don't want to reload because in angular the entire application will restart. Any suggestions on how to clear the memory threejs uses in order to get reusable ids? Thanks in advance!

1
What 3D format are you using for loading your models? - Mugen87
I'm loading FBX or glTF models. - dbond
If you really need same UUIDs, you can try something different than overwriting. After loading your objects as FBX or glTF, export them via Object3D.toJSON() to three.js's JSON format. When you use ObjectLoader for loading, the same UUIDs are restored. - Mugen87
Thanks Mugen87. I think I will take your advise on exporting to three.js JSON format. Maybe they will even load faster in native JSON format. - dbond

1 Answers

1
votes

Three.js automatically assigns UUIDs to objects. However, there's no reason why you cannot overwrite this value:

const staticID = "9B60F750-C64F-433A-8C1E-9E88639DC503";

onLoad(object) {
    object.uuid = staticID;
}

That way, each time you load your Object3D, it'll have the same "unique" ID as last time.