1

javascript3dライブラリであるthree.jsライブラリを使用しようとしています...

したがって、コードスニペットは次のとおりです。

var segments = 16, rings = 16;
//var radius = 50;  <-- original

// create a new mesh with sphere geometry -
// we will cover the sphereMaterial next!
var scene = new THREE.Scene();
// My read from file snippet.
$.getJSON('sample.json', function(data) {  
     var radius = data.circles.r;
     console.log(radius);


    var sphere = new THREE.Mesh(
       new THREE.SphereGeometry(radius, segments, rings),
       sphereMaterial);

    // add the sphere to the scene
    scene.add(sphere);
});
// and the camera
scene.add(camera);

したがって、基本的に以前のこのコード..半径はハードコーディングされていました(2行目)が、半径をハードコーディングする代わりに..次のjsonファイルから読み取っていますか?

{
 "circles":

{"x":14,"y":2,"z":4,"r":20}
}

しかし、それは何も表示しませんか?また、firebugにもエラーは表示されません。何か提案はありますか?ありがとう

4

1 に答える 1

1

の呼び出し$.getJSON(...)は非同期です。したがって、ステートメントの順序はおそらく

  1. varscene = new THREE.Scene();
  2. scene.add(カメラ);
  3. var sphere = new THREE.Mesh(...);
  4. scene.add(sphere);

成功関数に移動scene.add(camera);すると、以前と同じように機能するはずです。

于 2013-02-23T21:31:59.150 に答える