[SOLVED] Strange issue with cloning a Geometry

Ok… I found out that cloning of a geometry results in just a shallow geometry. The new geometry references to the same data as the original.

So I created the copy I need by loading the same model from disk. I now would have thought that whenever I mess with the data of the original, the second geometry would not change. But it turns out I was wrong.

The relevant parts of the code:

//Icosphere import base for globe terrain
//The icosphere is just a smooth sphere. No mountains yet!
globe = (Node) app.getAssetManager().loadModel("Models/icosphere.glb");
Geometry globeGeo = (Geometry) globe.getChild("polymesh");
vertBuffer = globeMesh.getBuffer(VertexBuffer.Type.Position);
vertData = (FloatBuffer) vertBuffer.getData();

Node waterNode = (Node) app.getAssetManager().loadModel("Models/icosphere.glb");
water= (Geometry) waterNode.getChild("polymesh");


// Creating terrain by messing with vertData (which is the data of the globe, not of the water
vertData.put(pos, vec.x);
vertData.put(pos + 1, vec.y);
vertData.put(pos + 2, vec.z);

I now end up with this:

The water got mountains too! Why?

1 Like

What you search is deepClone.

The reason behind this is that in 99% of the cases you want a unmodifiable copy. For performance reasons they share the same data.

I you edit the mesh data, then you have to update the world bounds or you will get culling errors. just in case you missed that

1 Like

a… that worked, tnx

1 Like