threejs给物体添加选中效果

const scene = new THREE.Scene(); 
const sceneHelpers = new THREE.Scene();
const helper = new THREE.BoxHelper();

renderer.autoClear = false;


sceneHelpers.add( helper ); //不要将helper直接添加到scene中, 有可能导致选中物体时意外选中helper;

function selectedObjectChanged ( object ){

    if(object === undefined) object = null;
    if(object === null){
        helper.visible = false;
    } else{
        helper.setFromObject( object );
        helper.visible = true;
    }

}


function render(){

    renderer.render(scene, camera);
    renderer.render(sceneHelpers, camera);

}

 

你可能感兴趣的:(threejs)