Reputation: 161
I am trying to use three.js library which is a javascript 3d library...
So the code snippet is this:
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);
So basically earlier this code .. the radius was hardcoded (second line) but instead of hardcoding radius.. I am reading it from json file which is following?
{
"circles":
{"x":14,"y":2,"z":4,"r":20}
}
But it doesnt show anything? And I dont see any error in firebug as well Any suggestions? Thanks
Upvotes: 1
Views: 142
Reputation: 74028
The call to $.getJSON(...)
is asynchronous. So the order of statements is most likely
If you move scene.add(camera);
into your success function, it should work as before.
Upvotes: 1