Note that there are some explanatory texts on larger screens.

plurals
  1. POThree.js merge geometry very slow
    text
    copied!<p>I am just learning Three.js, and find the documentation somewhat difficult to work with (there's a lot of "todos" all over the place).</p> <p>I am simply trying to display 50,000 to 500,000 red spheres on the screen. This code is kind of modeled after Mr. Doob's city example (<a href="http://www.mrdoob.com/lab/javascript/webgl/city/01/" rel="nofollow">http://www.mrdoob.com/lab/javascript/webgl/city/01/</a>). The only difference is that mine is very slow, or actually hangs Chrome in some instances (on a MBP retina):</p> <pre><code>moleculeGeometry = new THREE.Geometry() sphereGeometry = new THREE.SphereGeometry 0.7, 6, 6 sphereMaterial = new THREE.MeshLambertMaterial {color: 'red'} sphere = new THREE.Mesh sphereGeometry, sphereMaterial alert 'start merging' for i in [0...90000] sphere.position.x = atoms.coords[i][0] sphere.position.y = atoms.coords[i][1] sphere.position.z = atoms.coords[i][2] THREE.GeometryUtils.merge moleculeGeometry, sphere alert 'finished merging' mesh = new THREE.Mesh moleculeGeometry, sphereMaterial scene.add mesh render() </code></pre> <p>Any ideas here? The time between the 'start merging' alert and 'finished merging' alerts is very long, if it even finishes at all instead of hanging.</p> <p>Possible ideas include</p> <ul> <li><p>Preallocating an array of vertices for the geometry. I imagine each time I merge the sphere into the overall geometry more memory is allocated</p></li> <li><p>Merging sets of two spheres at a time, then merging two of those sets at a time, then repeating this process until the whole "scene" is merged. (There's a name for this technique, but I can't remember what it's called.) That seems like overkill. 90,000 merges should not be a bottleneck for anything on a modern computer.</p></li> </ul> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload