question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

THREE.BufferGeometryUtils.mergeBufferGeometries

See original GitHub issue

I tried to merge a lot of cylinders, but the result was not expected. I didn’t know where the problem came out. Maybe it was a bug, but when I lowered the number of creation to 600 times code, who could help me, thank you very much!

var geos = [];
for (var i = 0; i < 1000; i++) {
    var geo = new THREE.CylinderBufferGeometry(1, 1, 20, 16);
    var pos = new THREE.Vector3();
    pos.x = Math.random() * 800 - 400;
    pos.z = Math.random() * 800 - 400;
    geo.translate(pos.x, pos.y, pos.z);
    geos.push(geo);
}
var bf_geo = THREE.BufferGeometryUtils.mergeBufferGeometries(geos);
var mergeMesh = new THREE.Mesh(bf_geo, new THREE.MeshLambertMaterial({ color: 0xff0000 }));
scene.add(mergeMesh);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
takahiroxcommented, Jun 19, 2018

And I think you can remove if ( indexOffset > 0 ) {

if ( isIndexed ) {

    var indexOffset = 0;
    var mergedIndex = [];

    for ( var i = 0; i < geometries.length; ++ i ) {

        var index = geometries[ i ].index;

        for ( var j = 0; j < index.count; ++ j ) {

            mergedIndex.push( index.getX( j ) + indexOffset );

        }

        indexOffset += geometries[ i ].attributes.position.count;

    }

    mergedGeometry.setIndex( mergedIndex );

}
1reaction
takahiroxcommented, Jun 19, 2018

I think you can remove

	if ( ! mergedIndex ) return null;
Read more comments on GitHub >

github_iconTop Results From Across the Web

BufferGeometryUtils#mergeBufferGeometries – three.js docs
A class containing utility functions for BufferGeometry instances. Methods. # .computeMikkTSpaceTangents ( geometry : BufferGeometry, MikkTSpace : Object, ...
Read more >
How to use the "BufferGeometryUtils.js" for three.js?
THREE.BufferGeometryUtils is no part of the core but you can easily ... mergeBufferGeometries([geometry1, geometry2]); console.log(merged);
Read more >
14b How to merge BufferGeometries three.js - YouTube
Learn how to merge different buffer geometries into a single buffer geometry to increase performance and treat different buffer geometries ...
Read more >
MergeBufferGometry - CodePen
console.error( 'THREE.BufferGeometryUtils: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );.
Read more >
Improve your Threejs performances with BufferGeometryUtils
MergeBufferGeometries put every Buffergeometries with the sames attributes together. Basically, if we use the same material twice in our scene ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found