# Duplicating meshes without binding their geometry

**URL:** <https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567>\
**Category:** Questions\
**Created:** [June 9, 2020, 4:03pm UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567 "2020-06-09T16:03:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brewcrew-MJ](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Brewcrew-MJ](https://forum.babylonjs.com/u/Brewcrew-MJ)\
**Post date:** [June 9, 2020, 4:03pm UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/1 "2020-06-09T16:03:40Z")

</div>

Hello there,  
I am new to babylon.js and got a question: is there any way to duplicate a mesh (similar to createInstance() or clone()), but without letting it’s geometry being effected by changes to the “original” mesh?  
Example: I clone a mesh and want it to be independent from the “original” mesh. But every time i change the original mesh, my new mesh also changes its geometry.  
Is there any way to break this link between the two meshes?

Thanks a lot, have a nice day!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 9, 2020, 4:15pm UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/2 "2020-06-09T16:15:02Z")

</div>

Welcome aboard!

You can use:

```auto
mesh.makeGeometryUnique();

```

That’s for meshes. I don’t think something similar exist for instances…

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tibotiber/32/26735_2.png) [@tibotiber](https://forum.babylonjs.com/u/tibotiber)\
**Post date:** [August 26, 2021, 11:15am UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/3 "2021-08-26T11:15:23Z")

</div>

Super useful, thanks! How would I go about doing something similar for thin instances?

My use-case: I have a scene with thin instances, I pick one, hide it (using thinInstanceCount) and replace it by a clone to attach gizmos on it. However if I change the colour of another instance (on hover), the cloned mesh seems to share the color buffer and its color gets changed as well. I’d like to call `makeGeometryUnique` on the clone mesh but it crashes with `RangeError: Offset is outside the bounds of the DataView`, I’m guessing because it’s instantiated now, not just a mesh (?). Any prescribed method to get around this?

PS: Let me know if I should open a new topic instead of commenting on this old existing one that’s related. 🤔

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 26, 2021, 11:44am UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/4 "2021-08-26T11:44:34Z")

</div>

> [@tibotiber](#):
>
> replace it by a clone to attach gizmos on it

Are you cloning the mesh that has thin instances? If yes, you should make sure this clone has no thin instances (`thinInstanceCount = 0` should be enough). The thin instance picking sample from the doc is basically doing what you are doing: when you click on a thin instance it “selects” it by moving a pre-existing copy of the mesh to this thin instance location.

> **[Babylon.js Playground](https://playground.babylonjs.com/#RC2IAH%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tibotiber/32/26735_2.png) [@tibotiber](https://forum.babylonjs.com/u/tibotiber)\
**Post date:** [August 26, 2021, 2:05pm UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/5 "2021-08-26T14:05:50Z")

</div>

Thank you @Evgeni_Popov. This PG link was super handy as a base to repro my issue. I’ve edited it to match what I’m doing: [https://playground.babylonjs.com/#RC2IAH#11](https://playground.babylonjs.com/#RC2IAH#11).

The box is now cloned after the picking happens, so after the instances are set on the mesh. That’s because I have many different meshes and don’t want to keep many clones just in case. Then I call `makeGeometryUnique` on the cloned mesh, because in my app I can hover another instance and change its color so I don’t want the color buffer to be shared.

It seems to work here, although the white color is not working anymore. In my app calling `makeGeometryUnique` leads to the error below:

```auto
RangeError: Offset is outside the bounds of the DataView
    at DataView.getFloat32 (<anonymous>)
    at Function.VertexBuffer._GetFloatValue (buffer.js:741)
    at Function.VertexBuffer.ForEach (buffer.js:672)
    at VertexBuffer.forEach (buffer.js:578)
    at VertexBuffer.getFloatData (buffer.js:423)
    at Geometry.getVerticesData (geometry.js:444)
    at Geometry.copy (geometry.js:1050)
    at Mesh.makeGeometryUnique (mesh.js:1625)

```

Any idea what might be happening?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 26, 2021, 3:00pm UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/6 "2021-08-26T15:00:23Z")

</div>

`makeGeometryUnique` is not really compatible with meshes that have thin instances.

In your case, simply setting `thinInstanceCount = 0` should work. In your modified PG, you need to set `useVertexColors = false` on the cloned mesh:

[https://playground.babylonjs.com/#RC2IAH#12](https://playground.babylonjs.com/#RC2IAH#12)

---

<div class="post-metadata">

**Author:** ![tibotiber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tibotiber/32/26735_2.png) [@tibotiber](https://forum.babylonjs.com/u/tibotiber)\
**Post date:** [August 27, 2021, 2:16am UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/7 "2021-08-27T02:16:39Z")

</div>

Thank you! Setting `thinInstanceCount = 0` did not have any effect, however `useVertexColors = false` efficiently cuts the color buffer leaking onto my cloned mesh. Problem solved! 🍻

Not sure why thinInstanceCount isn’t doing anything, but seems cleaner so I’ll leave it there in case I think.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 27, 2021, 9:13am UTC](https://forum.babylonjs.com/t/duplicating-meshes-without-binding-their-geometry/11567/8 "2021-08-27T09:13:30Z")

</div>

In fact you don’t need to set `thinInstanceCount` to 0 because when cloning a mesh with thin instances, the thin instance data are not copied to the cloned mesh, so the cloned mesh has no thin instances defined for it.
