2016-04-02 8 views
0

Ich versuche, lat/long Daten zu einer Kugel abzubilden. Ich bin in der Lage, Vektoren mit verschiedenen Positionen zu erhalten und die Position des Würfelgewebes auf diese zu setzen. Nach dem Zusammenführen und Anzeigen scheint es, dass nur ein Würfel vorhanden ist. Ich nehme an, dass alle Würfel in der gleichen Position sind. Ich frage mich, wo ich hier falsch liege. (latLongToSphere gibt einen Vektor zurück);Three.js Netzposition ändert sich nicht am Set

// simple function that converts the data to the markers on screen 
function renderData() { 

    // the geometry that will contain all the cubes 
    var geom = new THREE.Geometry(); 

    // add non reflective material to cube 
    var cubeMat = new THREE.MeshLambertMaterial({color: 0xffffff,opacity:0.6, emissive:0xffffff}); 

    for (var i = quakes.length - 1; i >= 0; i--) { 

     var objectCache = quakes[i]["geometry"]["coordinates"]; 

     // calculate the position where we need to start the cube 
     var position = latLongToSphere(objectCache[0], objectCache[1], 600); 

     // create the cube 
     var cubeGeom = new THREE.BoxGeometry(2,2,2000,1,1,1), 
      cube = new THREE.Mesh(cubeGeom, cubeMat); 

     // position the cube correctly 
     cube.position.set(position.x, position.y, position.z); 
     cube.lookAt(new THREE.Vector3(0,0,0)); 

     // merge with main model 
     geom.merge(cube.geometry, cube.matrix); 
    } 

    // create a new mesh, containing all the other meshes. 
    var combined = new THREE.Mesh(geom, cubeMat); 

    // and add the total mesh to the scene 
    scene.add(combined); 
} 

Antwort

1

Sie müssen die Mesh Matrix aktualisieren, bevor seine Geometrie verschmelzen:

cube.updateMatrix(); 
geom.merge(cube.geometry, cube.matrix); 

jsfiddle: http://jsfiddle.net/L0rdzbej/222/

+0

Das war 100% richtig. Ich bin neu bei three.js und ich hatte das schon früher eingestellt und dann habe ich es rausgenommen, weil ich dachte, es wäre automatisch. Vielen Dank! –