Matrix, Merge, geometry not an instance

I am working with matrixes.

I really badly need them to become more efficient with the cpu.

The main method to achieve that. Appears to be merge.
Which is explained in Learn 3js, 3rd edition, page 269.

The code is the following:

var geometry=new THREE.Geometry();
for(var line=0; line<100; line++){
    var mesh=new THREE.Mesh();


    geometry.merge(mesh.geometry, mesh.matrix);

But when I run this code, I get error:

THREE.Geometry.merge(): geometry not an instance of THREE.Geometry. 

In the original code there is function addcube(), instead of new THREE.Mesh().
But then author says later in on the page that it’s just new Mesh.

Can anybody see why this error is?

Here’s my code sample, by the way:
buttons are wasdeq, 1, 2 and z.

I figure with merge I can make much bigger landscape matrixes.

This code does not work with latest three.js versions anymore. Instead of sticking to an old three.js release, I suggest you upgrade and use the approach from webgl_geometry_minecraft.

  • Instead of creating a mesh per iteration, you create a geometry instead, transform it (e.g. via BufferGeometry.applyMatrix4()) and the push it to an array.
  • The merge happens after all geometries are ready via BufferGeometryUtils.mergeBufferGeometries(). You use the resulting geometry to create the final mesh.
1 Like