How to replace InstancedMesh with a Mesh

I am loading a GLTF and it is creating meshes of type InstancedMesh.
I would like to make them blink - I can’t - Can not make a mesh blink because it is an InstancedMesh
I would like to make them glow - I can’t - Why can't I add an InstancedMesh to HighlightLayer

Is there a way to tell GTLF Loader not to load them as InstancedMesh or to somehow replace the InstancedMeshes on my scene with objects of type Mesh.

Thanks.

Update

Cloning the instancedMesh and copying properties from the source is not working

if(mesh.getClassName() == "InstancedMesh") {
	const newMesh = mesh.sourceMesh.clone(mesh.name, mesh.parent)
	newMesh.position = mesh.position.clone();
	newMesh.rotation = mesh.rotation.clone();
	newMesh.scaling = mesh.scaling.clone();
	mesh.dispose()
}

It results in a broken geometry and orientation of the newMesh
It

1 Like

You are close:

if(mesh.getClassName() == "InstancedMesh") {
	const newMesh = mesh.sourceMesh.clone(mesh.name, mesh.parent)
	newMesh.position = mesh.position.clone();
	newMesh.rotation = mesh.rotation.clone(); // Make sure this is not rotationQuaternion instead
	newMesh.scaling = mesh.scaling.clone();
        newMesh.parent = mesh.parent;
	mesh.dispose()
}

Isn’t

mesh.sourceMesh.clone(mesh.name, mesh.parent)

supposed to assign the parent. Why pass the parent in the clone if we have to set it later?

oh yeah I missed that. maybe the rotationQuaternion then?

Yes this was it for my scene and it seems to work now

const newMesh = mesh.sourceMesh.clone(mesh.name+"blink_tmp", mesh.parent)
newMesh.position = mesh.position.clone();
if(mesh.rotationQuaternion)
	newMesh.rotationQuaternion = mesh.rotationQuaternion.clone();
newMesh.scaling = mesh.scaling.clone();

It is working as expected for 3-4 of my meshes.

But performance wise it is slow. Sometimes I have to clone and create 734 new meshes on a mouse click.

Yeah I think instances will be better. I replied on your other topic