移动几何体的顶点后,我遇到了raycaster.intersectObjects()的问题。它不与新几何体相交,它只与重叠原始区域的部分相交。该对象在视图中看起来已正确修改。我一直在努力寻找答案,但没有一个解决方案似乎有效。我不确定有什么问题。
//move parts/vertices
for(var p=0; p<latticeModel.selected.length; p++){
var partNum = latticeModel.selected[p];
if(latticeModel.part[partNum].children[1].visible==true){
latticeModel.part[partNum].position.add(vector);
latticeCloud.tiles.part[partNum].position.add(vector);
}else{
var localVector = vector.clone();
localVector.add(latticeCloud.tiles.part[partNum].position);
latticeCloud.tiles.part[partNum].worldToLocal(localVector);
for(var v=0; v<4; v++){
if( latticeCloud.tiles.colors[partNum][v].getHex() == 0xfe0000 ||
latticeCloud.tiles.colors[partNum][v].getHex() == 0xff00ff ){
latticeCloud.tiles.part[partNum].geometry.vertices[v].add(localVector);
latticeCloud.tiles.part[partNum].geometry.verticesNeedUpdate = true;
latticeModel.part[partNum].children[0].geometry.vertices[v].add(localVector);
latticeModel.part[partNum].children[0].geometry.verticesNeedUpdate = true;
//added these below to try and debug, but still won't help
latticeModel.part[partNum].children[0].geometry.normalsNeedUpdate = true;
latticeModel.part[partNum].children[0].geometry.elementsNeedUpdate = true;
latticeModel.part[partNum].children[0].geometry.tangentsNeedUpdate = true;
latticeModel.part[partNum].children[0].geometry.computeFaceNormals = true;
latticeModel.part[partNum].children[0].geometry.computeVertexNormals = true;
latticeModel.part[partNum].children[0].geometry.computeBoundingBox = true;
latticeModel.part[partNum].children[0].geometry.computeBoundingSphere = true;
}
}
}
}
这是交叉部分:
mouse.x = 2 * (e.clientX / window.innerWidth) - 1;
mouse.y = 1 - 2 * (e.clientY / window.innerHeight);
var vector = new THREE.Vector3(mouse.x, mouse.y, 0.5).unproject(camera);
var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
scene.updateMatrixWorld();
//find the part mouse is overlapping and highlight it.
mouse.intersects = raycaster.intersectObjects(latticeModel.part, true);
if(mouse.intersects.length){
var foundPart = latticeModel.part.indexOf(mouse.intersects[0].object.parent);
if(foundPart!=mouse.selectedPart){
if(latticeModel.part.length>mouse.selectedPart && mouse.selectedPart!=-1){
latticeModel.part[mouse.selectedPart].children[2].visible = false;
}
mouse.selectedPart = foundPart;
latticeModel.part[mouse.selectedPart].children[2].visible = true;
}
}else{
if(latticeModel.part.length>mouse.selectedPart && mouse.selectedPart!=-1){
latticeModel.part[mouse.selectedPart].children[2].visible = false;
mouse.selectedPart = -1;
}
}
答案 0 :(得分:3)
如果修改几何体的顶点,几何体的边界球体和边界框可能会变为无效。
光线投射代码会为您重新计算它们,但您需要设置以下内容:
geometry.boundingSphere = null;
geometry.boundingBox = null;
three.js r.71