Just wondering, can anyone help me to understand what does this function do exactly?
For example if we apply it to a cloned or instanced mesh. What’s happening in the backend?
Does it duplicate only vertex? or doing something else too? Is it expensive to use? or anything we should be aware of when we use this function.
Just trying to understand it so I can have better ideas when to use it.
It is doing a full copy of all the vertex buffers so that the mesh for which you called makeGeometryUnique has unique geometries, not shared with any other meshes.
You should normally not call this method, except if for some reasons you first cloned a mesh (which share geometries) and you need at some point to have unique geometries for the mesh.
So can we say, for an imported .obj mesh (or other format), turning on makeGeomertryUnique() is equivalent to importing another brand new mesh (even same content) all over again?
I’m not sure I understand. mesh.makeGeomertryUnique() will create unique geometry for the mesh it is called on. But if the geometry is already unique (meaning, not shared with other meshes), there’s no purpose to call makeGeomertryUnique.
The only context I ever see makeGeomertryUnique called by user code was when a mesh was created with mesh2 = mesh.clone() and at some point mesh2 needed unique geometry.
Option 1 is less cpu usage than 2, as 2 will require the browser to check http cache. As for uniqueness… im not sure, and it could even be different behavior between file types since the loaders are implemented differently. If you can freely choose between 1 and 2, do 1 for sure.
Tangential opinion here. Personally, i try to avoid babylons hidden http abstractions where possible because they are a bit dated and because they only emulate xhr on the native engine, so i think updating the browser impl is prob off the table. Its not xhr vs fetch, that doesnt really matter - its that browsers make user of threads in service workers, so its possible to do prefetching and transforms off the main thread but you cant do it directly within the loaders. There is, however, a worker pool you can use within the loaders.
In process #1, meshA and meshB1 will be two separate meshes with no shared geometry, and in process #2, meshA and meshB2 will also be two separate meshes with no shared geometry.
So, the result is the same in both cases, but #1 is faster because it does not require to read and parse the .obj file a second time: cloning + calling makeGeometryUnique is faster.