简体   繁体   中英

How do I hide json objects on a scene with three.js loader.load function?

i have a lot of json files that i load with loader.load using three.js. They get displayed when i click on the text content that corresponds to json file name.

How do I unload or hide an object with a second click?

Here is my code:

document.getElementById("dest").getElementsByTagName("span").onclick = function(element, key) {myFunction()};
    function myFunction() {
        document.getElementById("dest").getElementsByTagName("span").height = "100%";
        var t = event.target.textContent;
        var a = t.slice(1,t.length-1);
        path = 'examples/brain_parts/' + groupNames[a] + '.json';

                loader.load( path, 
                        function ( geometry, materials, data ) {
                        var material = new THREE.MultiMaterial( materials );
                        var object = new THREE.Mesh( geometry, material );
                        object.scale.set(5,5,5);
                        object.position.set( 0, 0, 0 );
                        scene.add( object );
                        render();

                })

    }
var a = t.slice(1,t.length-1);
var objName = "groupNames" + a;

then to traverse the scene, looking for the object which has an attibute "name" equal to the objName value. Or you can do

var obj = scene.getObjectByName( objName );

If you found one then remove it, if you didn't find it then call

loader.load(...
    var object = new THREE.Mesh( geometry, material );
    object.name = objName;
    ...
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM