簡體   English   中英

Three.js網格位置未更改

[英]Three.js Mesh position not changing on set

我正在嘗試將經/緯度數據映射到一個球體。 我能夠獲得具有不同位置的向量,並將立方體網格的位置設置為那些。 合並並顯示后,似乎只有一個多維數據集。 我假設所有的多維數據集都在同一位置。 想知道我在哪里錯了。 (latLongToSphere返回一個向量);

// 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);
}

您必須在合並其幾何形狀之前更新網格矩陣:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM