2016-05-26 11 views
0

私はthree.js/editorでシーンを構築して、今使っているJSONファイルにそのシーンをエクスポートしました。私はカメラと軌道のコントロールをプログラムすることができますが、JSON構造から特定のオブジェクトを選択する方法はわかりません。それを行うには離れていますか?もしそうなら、私はどのようにして特定のオブジェクトを「ターゲットする」ことができますか? 「uuid」を使うことはできますか? は、ここに私のJSONコードです:json構造体から特定のオブジェクトを回転させるにはどうすればよいですか?

{ 
"metadata": { 
    "version": 4.4, 
    "type": "Object", 
    "generator": "Object3D.toJSON" 
}, 
"geometries": [ 
    { 
     "uuid": "DEB90436-B316-4E49-83A6-323712AA3A78", 
     "type": "TorusGeometry", 
     "radius": 1, 
     "tube": 0.34, 
     "radialSegments": 42, 
     "tubularSegments": 44, 
     "arc": 6.32, 
    }, 
    { 
     "uuid": "0F8E3492-4B1B-436A-973C-7F8433AA7582", 
     "type": "PlaneGeometry", 
     "width": 2, 
     "height": 2 
    }     /...and so on... 
] 

そして、これは私のJavaScriptのである:

var scene, camera, renderer; 

init(); 
animate(); 

function init() { 

    // Creating the scene and set the scene size. 
    scene = new THREE.Scene(); 
    var WIDTH = window.innerWidth, 
     HEIGHT = window.innerHeight; 

    // Creating a renderer and add it to the DOM. 
    renderer = new THREE.WebGLRenderer({antialias:true}); 
    renderer.setSize(WIDTH, HEIGHT); 
    document.body.appendChild(renderer.domElement); 

    // Create a camera, zoom it out from the model a bit, and add it to the scene. 
     camera = new THREE.OrthographicCamera(window.innerWidth/- 2, window.innerWidth/2, window.innerHeight/2, window.innerHeight/- 2, - 2000, 1000); 
     camera.position.x = 200; 
     camera.position.y = 100; 
     camera.position.z = 200; 
    scene.add(camera); 



// Loading in the mesh and add it to the scene. THIS is were I get the JSON structure in... 
var loader = new THREE.ObjectLoader(); 
loader.load("scene.json",function (obj) { 
scene.add(obj); 
}); 

// OrbitControls 
controls = new THREE.OrbitControls(camera, renderer.domElement); 
controls.enablePan = false; 
      controls.minDistance = 6 ; // how far can you zoom in 
controls.maxDistance = 71; // how far can you zoom out 

    } 

function animate() { 


    // Render the scene. 
    renderer.render(scene, camera); 
    controls.update(); 

    } 

Object3D class

答えて

0

する方法があるgetObjectByNameと呼ばれる方法があります。使用例:

loader.load("scene.json",function (obj) { 
    scene.add(obj); 
    var targetObject = obj.getObjectByName('name of object from scene.json'); 
    // Use targetObject here... 
}); 

オブジェクト名は、scene.jsonファイルでさらに見つけることができます。 "object": ...の部分を探します。

+0

多くの方に感謝します。 –

関連する問題