dbond
dbond

Reputation: 11

Threejs - Loading models and unique id

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!

Upvotes: 1

Views: 1607

Answers (1)

M -
M -

Reputation: 28492

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.

Upvotes: 1

Related Questions